|
@@ -7,16 +7,21 @@ import com.kuaishou.merchant.open.api.client.AccessTokenKsMerchantClient;
|
|
|
import com.kuaishou.merchant.open.api.common.utils.GsonUtils;
|
|
|
import com.kuaishou.merchant.open.api.request.order.OpenOrderCursorListRequest;
|
|
|
import com.kuaishou.merchant.open.api.request.order.OpenOrderDetailRequest;
|
|
|
+import com.kuaishou.merchant.open.api.request.refund.OpenSellerOrderRefundDetailRequest;
|
|
|
+import com.kuaishou.merchant.open.api.request.refund.OpenSellerOrderRefundPcursorListRequest;
|
|
|
import com.kuaishou.merchant.open.api.request.shop.OpenScoreMasterGetRequest;
|
|
|
import com.kuaishou.merchant.open.api.request.shop.OpenScoreShopGetRequest;
|
|
|
import com.kuaishou.merchant.open.api.response.order.OpenOrderCursorListResponse;
|
|
|
import com.kuaishou.merchant.open.api.response.order.OpenOrderDetailResponse;
|
|
|
+import com.kuaishou.merchant.open.api.response.refund.OpenSellerOrderRefundDetailResponse;
|
|
|
+import com.kuaishou.merchant.open.api.response.refund.OpenSellerOrderRefundPcursorListResponse;
|
|
|
import com.kuaishou.merchant.open.api.response.shop.OpenScoreMasterGetResponse;
|
|
|
import com.kuaishou.merchant.open.api.response.shop.OpenScoreShopGetResponse;
|
|
|
import com.ruixuan.common.utils.Check;
|
|
|
import com.ruixuan.common.utils.DateUtils;
|
|
|
import com.ruixuan.isc.constants.KuaiShouConstants;
|
|
|
import com.ruixuan.isc.entity.KuaishouAccessToken;
|
|
|
+import com.ruixuan.isc.entity.KwaixiaodianOrderAftersalesList;
|
|
|
import com.ruixuan.isc.entity.KwaixiaodianOrderCursorList;
|
|
|
import com.ruixuan.isc.entity.KwaixiaodianShopScore;
|
|
|
import com.ruixuan.isc.mapper.KwaixiaodianOrderCursorListMapper;
|
|
@@ -105,6 +110,7 @@ public class KwaixiaodianOrderCursorListServiceImpl implements IKwaixiaodianOrde
|
|
|
log.error("===kwaixiaodian获取订单列表(open.order.cursor.list)失败,shopId:{},信息:{}", shopId, jsonObject.getString("error_msg"));
|
|
|
}
|
|
|
if (!"nomore".equals(cursor)) {
|
|
|
+ Thread.sleep(500);
|
|
|
querykwaiOrderList(shopId, queryType, beginDate, endDate, cursor);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
@@ -113,6 +119,9 @@ public class KwaixiaodianOrderCursorListServiceImpl implements IKwaixiaodianOrde
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /*
|
|
|
+ 新增2小时内的订单
|
|
|
+ */
|
|
|
@Override
|
|
|
public void queryNowdayKWaiOrderList(String shopId, String cursor) {
|
|
|
try {
|
|
@@ -171,6 +180,7 @@ public class KwaixiaodianOrderCursorListServiceImpl implements IKwaixiaodianOrde
|
|
|
log.error("===kwaixiaodian当天获取订单列表(open.order.cursor.list)失败,shopId:{},信息:{}", shopId, jsonObject.getString("error_msg"));
|
|
|
}
|
|
|
if (!"nomore".equals(cursor)) {
|
|
|
+ Thread.sleep(500);
|
|
|
queryNowdayKWaiOrderList(shopId, cursor);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
@@ -247,6 +257,197 @@ public class KwaixiaodianOrderCursorListServiceImpl implements IKwaixiaodianOrde
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增2小时内的售后单
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void queryNowdayafterSalesList(String shopId, String cursor) {
|
|
|
+ try {
|
|
|
+ //2小时前 时间戳
|
|
|
+ Long beginTime = DateUtils.getTimeStamp(DateUtils.getHourTime(-2));
|
|
|
+ //当前时间
|
|
|
+ Long endTime = DateUtils.getTimeStamp(DateUtils.getTime());
|
|
|
+ KuaishouAccessToken token = accessTokenService.getKWaiAccessToken(shopId);
|
|
|
+ if (Check.isNull(token)) {
|
|
|
+ log.error("----kwaixiaodian当天获取订单列表,shopId:{} 没有token信息", shopId);
|
|
|
+ }
|
|
|
+
|
|
|
+ AccessTokenKsMerchantClient client = new AccessTokenKsMerchantClient(KuaiShouConstants.KFX_URL, token.getAppKey(), token.getSignSecret());
|
|
|
+ OpenSellerOrderRefundPcursorListRequest request = new OpenSellerOrderRefundPcursorListRequest();
|
|
|
+ request.setAccessToken(token.getAccessToken());
|
|
|
+ request.setApiMethodVersion(1L);
|
|
|
+
|
|
|
+ //订单生成的开始时间(单位毫秒),在当前时间的近90天内,不能大于90天,且小于截止时间
|
|
|
+ request.setBeginTime(beginTime);
|
|
|
+ request.setEndTime(endTime);
|
|
|
+ //退款单请求类型,8 等待退款 9 全部退款订单
|
|
|
+ request.setType(9);
|
|
|
+ request.setPageSize(5);
|
|
|
+ request.setCurrentPage(1L);
|
|
|
+ //排序方式,1时间降序 2时间升序 ,默认降序
|
|
|
+ request.setSort(1);
|
|
|
+ //查找方式,1按创建时间查找 2按更新时间查找 ,默认创建时间
|
|
|
+ request.setQueryType(1);
|
|
|
+ request.setPcursor(cursor);
|
|
|
+ OpenSellerOrderRefundPcursorListResponse response = null;
|
|
|
+ try {
|
|
|
+ response = client.execute(request);
|
|
|
+ } catch (KsMerchantApiException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(GsonUtils.toJSON(response));
|
|
|
+ String code = jsonObject.getString("code");
|
|
|
+ if ("1".equals(code)) {
|
|
|
+ JSONObject data = jsonObject.getJSONObject("data");
|
|
|
+ cursor = data.getString("pcursor");
|
|
|
+ JSONArray infoList = data.getJSONArray("refundOrderInfoList");
|
|
|
+ List<KwaixiaodianOrderAftersalesList> aftersalesList = new ArrayList<>();
|
|
|
+ for (int i = 0; i < infoList.size(); i++) {
|
|
|
+ JSONObject object = infoList.getJSONObject(i);
|
|
|
+ KwaixiaodianOrderAftersalesList order = new KwaixiaodianOrderAftersalesList(token, object);
|
|
|
+ aftersalesList.add(order);
|
|
|
+ }
|
|
|
+ if (Check.isNotNull(aftersalesList)) {
|
|
|
+ mapper.replaceBatchKwaixiaodianOrderAftersalesList(aftersalesList);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.error("===kwaixiaodian获取售后单列表失败,shopId:{},信息:{}", shopId, jsonObject.getString("error_msg"));
|
|
|
+ }
|
|
|
+ if (!"nomore".equals(cursor)) {
|
|
|
+ Thread.sleep(500);
|
|
|
+ queryNowdayafterSalesList(shopId, cursor);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("===kwaixiaodian当天获取售后单列表异常 queryNowdayafterSalesList");
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void afterSalesList(String shopId, Integer queryType, String beginDate, String endDate, String cursor) {
|
|
|
+ try {
|
|
|
+ Long beginTime = DateUtils.getStartLongTime(beginDate);
|
|
|
+ Long endTime = DateUtils.getEndLongTime(endDate);
|
|
|
+ KuaishouAccessToken token = accessTokenService.getKWaiAccessToken(shopId);
|
|
|
+ if (Check.isNull(token)) {
|
|
|
+ log.error("----kwaixiaodian获取售后单列表,shopId:{} 没有token信息", shopId);
|
|
|
+ }
|
|
|
+
|
|
|
+ AccessTokenKsMerchantClient client = new AccessTokenKsMerchantClient(KuaiShouConstants.KFX_URL, token.getAppKey(), token.getSignSecret());
|
|
|
+ OpenSellerOrderRefundPcursorListRequest request = new OpenSellerOrderRefundPcursorListRequest();
|
|
|
+ request.setAccessToken(token.getAccessToken());
|
|
|
+ request.setApiMethodVersion(1L);
|
|
|
+
|
|
|
+ //订单生成的开始时间(单位毫秒),在当前时间的近90天内,不能大于90天,且小于截止时间
|
|
|
+ request.setBeginTime(beginTime);
|
|
|
+ request.setEndTime(endTime);
|
|
|
+ //退款单请求类型,8 等待退款 9 全部退款订单
|
|
|
+ request.setType(9);
|
|
|
+ request.setPageSize(100);
|
|
|
+ request.setCurrentPage(1L);
|
|
|
+ //排序方式,1时间降序 2时间升序 ,默认降序
|
|
|
+ request.setSort(1);
|
|
|
+ //查找方式,1按创建时间查找 2按更新时间查找 ,默认创建时间
|
|
|
+ request.setQueryType(queryType);
|
|
|
+ request.setPcursor(cursor);
|
|
|
+ OpenSellerOrderRefundPcursorListResponse response = null;
|
|
|
+ try {
|
|
|
+ response = client.execute(request);
|
|
|
+ } catch (KsMerchantApiException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(GsonUtils.toJSON(response));
|
|
|
+// System.out.println("返还结果\n" + GsonUtils.toJSON(response));
|
|
|
+ String code = jsonObject.getString("code");
|
|
|
+ if ("1".equals(code)) {
|
|
|
+ JSONObject data = jsonObject.getJSONObject("data");
|
|
|
+ cursor = data.getString("pcursor");
|
|
|
+ JSONArray infoList = data.getJSONArray("refundOrderInfoList");
|
|
|
+ List<KwaixiaodianOrderAftersalesList> aftersalesList = new ArrayList<>();
|
|
|
+ for (int i = 0; i < infoList.size(); i++) {
|
|
|
+ JSONObject object = infoList.getJSONObject(i);
|
|
|
+ KwaixiaodianOrderAftersalesList order = new KwaixiaodianOrderAftersalesList(token, object);
|
|
|
+ aftersalesList.add(order);
|
|
|
+ }
|
|
|
+ if (Check.isNotNull(aftersalesList)) {
|
|
|
+ mapper.replaceBatchKwaixiaodianOrderAftersalesList(aftersalesList);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.error("===kwaixiaodian获取售后单列表失败,shopId:{},信息:{}", shopId, jsonObject.getString("error_msg"));
|
|
|
+ }
|
|
|
+ if (!"nomore".equals(cursor)) {
|
|
|
+ Thread.sleep(500);
|
|
|
+ afterSalesList(shopId, queryType, beginDate, endDate, cursor);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("===kwaixiaodian获取售后单列表异常 afterSalesList");
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void afterSales(JSONObject eventJSon) {
|
|
|
+ try {
|
|
|
+ JSONObject info = eventJSon.getJSONObject("info");
|
|
|
+ String openId = eventJSon.getString("openId");
|
|
|
+ if (!Check.isNull(info)) {
|
|
|
+ String type = eventJSon.getString("event");
|
|
|
+ //售后单新增消息
|
|
|
+ if ("kwaishop_aftersales_addRefund".equals(type)) {
|
|
|
+ aftersalesAddRefund(info, openId);
|
|
|
+ //售后单更新消息
|
|
|
+ } else if ("kwaishop_aftersales_updateRefund".equals(type)) {
|
|
|
+ aftersalesUpdateRefund(info);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void aftersalesAddRefund(JSONObject info, String openId) throws Exception {
|
|
|
+ //售后单id
|
|
|
+ Long refundId = info.getLong("refundId");
|
|
|
+
|
|
|
+ KuaishouAccessToken token = accessTokenService.getKWaiAccessTokenByOpenId(openId);
|
|
|
+ AccessTokenKsMerchantClient client = new AccessTokenKsMerchantClient(KuaiShouConstants.KFX_URL, token.getAppKey(), token.getSignSecret());
|
|
|
+
|
|
|
+ OpenSellerOrderRefundDetailRequest request = new OpenSellerOrderRefundDetailRequest();
|
|
|
+ request.setAccessToken(token.getAccessToken());
|
|
|
+ request.setApiMethodVersion(1L);
|
|
|
+
|
|
|
+ request.setRefundId(refundId);
|
|
|
+ OpenSellerOrderRefundDetailResponse response = null;
|
|
|
+ try {
|
|
|
+ response = client.execute(request);
|
|
|
+ } catch (KsMerchantApiException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(GsonUtils.toJSON(response));
|
|
|
+ String code = jsonObject.getString("code");
|
|
|
+ if ("1".equals(code)) {
|
|
|
+ JSONObject data = jsonObject.getJSONObject("data");
|
|
|
+ KwaixiaodianOrderAftersalesList order = new KwaixiaodianOrderAftersalesList(token, data);
|
|
|
+ List<KwaixiaodianOrderAftersalesList> list = new ArrayList<>();
|
|
|
+ list.add(order);
|
|
|
+ mapper.replaceBatchKwaixiaodianOrderAftersalesList(list);
|
|
|
+ } else {
|
|
|
+ log.error("===kwaixiaodian新增售后单详情(open.seller.order.refund.detail)失败,refundId:{},信息:{}", refundId, jsonObject.getString("error_msg"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void aftersalesUpdateRefund(JSONObject info) throws Exception {
|
|
|
+ //售后单id
|
|
|
+ Long refundId = info.getLong("refundId");
|
|
|
+ info.put("updateTime", DateUtils.timestamptoMinutesAndSecondsStr(info.getLong("updateTime")));
|
|
|
+ int i = mapper.updateKWaiOrderAftersalesStatus(info);
|
|
|
+ if (i <= 0) {
|
|
|
+ log.error("---KWai售后单ID:{},状态:{} 修改失败", refundId, info.getInteger("status"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
public void queryMaster(String shopId) {
|
|
|
KuaishouAccessToken token = accessTokenService.getKWaiAccessToken(shopId);
|