Przeglądaj źródła

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	ruixuan-live/src/main/java/com/ruixuan/isc/service/impl/KwaiJSTServiceImpl.java
yumeng 6 miesięcy temu
rodzic
commit
80ebe64900

+ 87 - 10
ruixuan-live/src/main/java/com/ruixuan/isc/controller/KwaixiaodianItemGetController.java

@@ -11,7 +11,6 @@ import com.ruixuan.common.utils.Check;
 import com.ruixuan.common.utils.DateUtils;
 import com.ruixuan.data.utils.ExportExcelUtils;
 import com.ruixuan.isc.entity.KuaishouAccessToken;
-import com.ruixuan.isc.entity.KuaishouRewardBaseInfo;
 import com.ruixuan.isc.entity.KwaixiaodianItemGet;
 import com.ruixuan.isc.service.IAccessTokenService;
 import com.ruixuan.isc.service.IKwaixiaodianItemGetService;
@@ -22,21 +21,31 @@ import com.ruixuan.system.service.ISysUserService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
-import io.swagger.models.auth.In;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.UnsupportedEncodingException;
-import java.math.BigDecimal;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 /**
  * kwaixiaodian商品详情Controller
@@ -509,19 +518,68 @@ public class KwaixiaodianItemGetController extends BaseController {
         os.close();
     }
 
+    /**
+     * https://open.kwaixiaodian.com/zone/new/docs/api?name=open.seller.order.refund.pcursor.list&version=1
+     * 新增2小时内的售后单
+     * kwaixiaodian_order_aftersales_list
+     */
+    @GetMapping("/queryNowdayafterSalesList")
+    @ApiOperation(value = "获当天售后单列表")
+    public void queryNowdayafterSalesList(@ApiParam("店铺ID") @RequestParam(value = "shopId", required = false) String shopId) {
+        try {
+            orderCursorListService.queryNowdayafterSalesList(shopId.trim(), "");
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
 
-    @GetMapping("/querykwaiOrderList")
-    @ApiOperation(value = "获kwai订单列表")
-    public void querykwaiOrderList(@ApiParam("店铺ID") @RequestParam(value = "shopId", required = false) String shopId, @ApiParam("1按创建时间查找 2按更新时间查找") @RequestParam(value = "queryType", required = false) Integer queryType, @ApiParam("开始日期") @RequestParam(value = "beginDate", required = false) String beginDate, @ApiParam("结束日期(间隔不大于7天)") @RequestParam(value = "endDate", required = false) String endDate
-
+    /**
+     * https://open.kwaixiaodian.com/zone/new/docs/api?name=open.seller.order.refund.pcursor.list&version=1
+     * 获取售后单列表
+     * kwaixiaodian_order_aftersales_list
+     */
+    @PostMapping(value = "/afterSalesList")
+    @ApiOperation(value = "获取售后单列表")
+    public void afterSalesList(@ApiParam("店铺ID") @RequestParam(value = "shopId", required = false) String shopId,
+                               @ApiParam("1按创建时间查找 2按更新时间查找") @RequestParam(value = "queryType", required = false) Integer queryType,
+                               @ApiParam("开始日期") @RequestParam(value = "beginDate", required = false) String beginDate,
+                               @ApiParam("结束日期(间隔不大于7天)") @RequestParam(value = "endDate", required = false) String endDate
     ) {
+        Map<String, Object> result = new HashMap<>();
         try {
-            orderCursorListService.querykwaiOrderList(shopId.trim(), queryType, beginDate, endDate, "");
+            orderCursorListService.afterSalesList(shopId.trim(), queryType, beginDate, endDate, "");
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * https://open.kwaixiaodian.com/zone/new/docs/api?name=open.seller.order.refund.pcursor.list&version=1
+     * 获取售后单列表
+     * kwaixiaodian_order_aftersales_list
+     */
+    @GetMapping("/queryAfterSalesListMonth")
+    @ApiOperation(value = "获取售后单列表月度数据")
+    public void queryAfterSalesListMonth(@ApiParam("店铺ID") @RequestParam(value = "shopId", required = false) String shopId) {
+        try {
+            String date1 = DateUtils.getDate();
+            String date0 = DateUtils.getSubtractTime(new Date(), 89);
+            List<String> allDatesOfTwoTimes = DateUtils.getAllDatesOfTwoTimes(date0, date1);
+            for (String date : allDatesOfTwoTimes) {
+                Thread.sleep(1000);
+                orderCursorListService.afterSalesList(shopId.trim(), 1, date, date, "");
+                logger.info("shopId:{},日期:{} 执行-----ok", shopId, date);
+            }
         } catch (Exception e) {
             e.printStackTrace();
         }
     }
 
+
+    /**
+     * 获取订单列表(open.order.cursor.list)
+     * https://open.kwaixiaodian.com/zone/new/docs/api?name=open.order.cursor.list&version=1
+     */
     @GetMapping("/queryNowdayKWaiOrderList")
     @ApiOperation(value = "获当天kwai订单")
     public void queryNowdayKWaiOrderList(@ApiParam("店铺ID") @RequestParam(value = "shopId", required = false) String shopId) {
@@ -536,6 +594,25 @@ public class KwaixiaodianItemGetController extends BaseController {
      * 获取订单列表(open.order.cursor.list)
      * https://open.kwaixiaodian.com/zone/new/docs/api?name=open.order.cursor.list&version=1
      */
+    @GetMapping("/querykwaiOrderList")
+    @ApiOperation(value = "获kwai订单列表")
+    public void querykwaiOrderList(@ApiParam("店铺ID") @RequestParam(value = "shopId", required = false) String shopId,
+                                   @ApiParam("1按创建时间查找 2按更新时间查找") @RequestParam(value = "queryType", required = false) Integer queryType,
+                                   @ApiParam("开始日期") @RequestParam(value = "beginDate", required = false) String beginDate,
+                                   @ApiParam("结束日期(间隔不大于7天)") @RequestParam(value = "endDate", required = false) String endDate
+
+    ) {
+        try {
+            orderCursorListService.querykwaiOrderList(shopId.trim(), queryType, beginDate, endDate, "");
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 获取订单列表(open.order.cursor.list)
+     * https://open.kwaixiaodian.com/zone/new/docs/api?name=open.order.cursor.list&version=1
+     */
     @GetMapping("/querykwaiOrderListMonth")
     @ApiOperation(value = "获kwai订单列表月度数据")
     public void querykwaiOrderListMonth(@ApiParam("店铺ID") @RequestParam(value = "shopId", required = false) String shopId) {

+ 3 - 2
ruixuan-live/src/main/java/com/ruixuan/isc/controller/SupplyChainController.java

@@ -32,7 +32,6 @@ import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-import java.io.File;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.UnsupportedEncodingException;
@@ -2235,7 +2234,6 @@ public class SupplyChainController extends BaseController {
                     "kwaishop_order_orderFail",//交易失败消息
                     "kwaishop_order_orderSuccess",//交易成功消息
                     "kwaishop_order_delivering"//已发货消息
-
             ));
 
     @PostMapping(value = "/ruixuanKWaiShopOrderAccept")
@@ -2258,6 +2256,9 @@ public class SupplyChainController extends BaseController {
 //                                logger.info("-KWaiShop----报文------------\n{}",eventJSon);
                                 //状态变更以及对应状态时间 kwaixiaodian_order_cursor_list
                                 orderCursorListService.updateKWaiShopOrderStatus(eventJSon);
+                            } else if (Check.isNotNull(event) && event.contains("kwaishop_aftersales")) {
+                                //售后单 报文 新增和修改状态
+                                orderCursorListService.afterSales(eventJSon);
                             }
                         }
                     } catch (Exception e) {

+ 275 - 0
ruixuan-live/src/main/java/com/ruixuan/isc/entity/KwaixiaodianOrderAftersalesList.java

@@ -0,0 +1,275 @@
+package com.ruixuan.isc.entity;
+
+import com.alibaba.fastjson.JSONObject;
+import com.ruixuan.common.utils.DateUtils;
+import lombok.Data;
+
+/**
+ * kwai售后单信息对象 kwaixiaodian_order_aftersales_list
+ */
+@Data
+public class KwaixiaodianOrderAftersalesList {
+    /**
+     * 公司ID
+     */
+    private Long companyId;
+
+
+    /**
+     * 公司名称
+     */
+    private String companyName;
+
+    /**
+     * 店铺ID
+     */
+    private Long shopId;
+
+    /**
+     * 店铺名称
+     */
+    private String shopName;
+    /**
+     * 售后单id
+     */
+    private Long refundId;
+
+    /**
+     * 订单ID
+     */
+    private Long oid;
+
+    /**
+     * 快手商品id
+     */
+    private Long itemId;
+
+    /**
+     * 快手商品skuid
+     */
+    private Long skuId;
+
+    /**
+     * 商家实退金额,包括退回给买家的现金/消费金/宠爱红包/平台补贴的所有资金,不包括主播红包退还金额
+     */
+    private Long refundFee;
+
+    /**
+     * 退款状态,枚举:[10, "买家已经申请退款,等待卖家同意"] [12, "卖家已拒绝,等待买家处理"] [20, "协商纠纷,等待平台处理"] [30, "卖家已经同意退款,等待买家退货"] [40, "买家已经退货,等待卖家确认收货"] [45, "卖家已经发货,等待买家确认收货"] [50, "卖家已经同意退款,等待系统执行退款"] [60, "退款成功"] [70, "退款关闭"]
+     */
+    private Long status;
+
+    /**
+     * 退款原因,数值格式,文案描述见refundReasonDesc
+     */
+    private Long refundReason;
+
+    /**
+     * 卖家快手id
+     */
+    private Long sellerId;
+
+    /**
+     * 退款类型,枚举: [1, "买家申请退款"] [2, "卖家主动退款"]
+     */
+    private Long refundType;
+
+    /**
+     * 退款方式,枚举: [1, "退货退款"] [10, "仅退款"] [3, "换货"]
+     */
+    private Long handlingWay;
+
+    /**
+     * 退款描述
+     */
+    private String refundDesc;
+
+    /**
+     * 物流id
+     */
+    private Long logisticsId;
+
+    /**
+     * 物流id
+     */
+    private String pictures;
+
+    /**
+     * 协商状态,枚举:[0, "未知状态"] [1, "待商家处理"] [2, "商家同意"] [3, "商家驳回,等待买家修改"]
+     */
+    private Long negotiateStatus;
+
+    /**
+     * 买家修改商家不同意的退款单时限
+     */
+    private Long validNegotiateBuyerModifyTimeStamp;
+
+    /**
+     * 服务商skuid
+     */
+    private Long relSkuId;
+
+    /**
+     * 服务商商品id
+     */
+    private Long relItemId;
+
+    /**
+     * 商家拒绝图片凭证
+     */
+    private String sellerDisagreeImages;
+
+    /**
+     * 退货单物流-快递单号
+     */
+    private String expressNo;
+
+    /**
+     * 退货单物流-快递公司编号
+     */
+    private String expressCode;
+
+    /**
+     * 商家拒绝文字说明
+     */
+    private String sellerDisagreeDesc;
+
+    /**
+     * 商家拒绝原因,枚举值可通过获取售后拒绝原因列表API(open.refund.reject.reason)获取
+     */
+    private Long sellerDisagreeReason;
+
+    /**
+     * 买家能修改WAIT_MODIFY的时间限制
+     */
+    private Long timeLimitNegotiateChange;
+
+    /**
+     * 协商状态变更原因。枚举值0:未知;10008:修改退款申请;10013:买家同意商家修改退款;10033:同意退款;10036:返回修改
+     */
+    private String negotiateReason;
+
+    /**
+     * 协商相关核心信息变更时间
+     */
+    private String negotiateUpdateTime;
+
+    /**
+     * 退货申请时间
+     */
+    private String submitTime;
+
+    /**
+     * 超期时间(商家处理的截止时间)
+     */
+    private String expireTime;
+
+    /**
+     * 结束时间(退款成功或退款失败时间)
+     */
+    private String endTime;
+
+    /**
+     * 加密后的买家id,同一个开发主体ISV下唯一,识别快手用户的唯一标识
+     */
+    private String buyerOpenId;
+
+    /**
+     * 卖家退货地址
+     */
+    private String address;
+
+    /**
+     * 特殊退款类型[0, "非特殊退款"] [1, "价保"]
+     */
+    private Long specialRefundType;
+
+    /**
+     * 退货包裹异常信息
+     */
+    private String logisticsRiskInfos;
+
+    /**
+     * 买家换货地址
+     */
+    private String buyerExchangeAddress;
+
+    /**
+     * 换货信息
+     */
+    private String exchangeInfo;
+
+    /**
+     * 商责运费信息
+     */
+    private String returnFreightInfo;
+    /**
+     * 订单创建时间
+     */
+    private String createTime;
+    /**
+     * 订单更新时间
+     */
+    private String updateTime;
+
+    /**
+     * 售后事件类型(类型枚举值后续可能会新增)
+     * [0 "未知"], [2 "卖家拒绝退款"], [3 "卖家同意退款"], [4 "平台或买家修改退款记录"], [5 "卖家编辑后买家同意修改"], [6 "提交退货信息"], [7 "卖家确认收货"], [50 "退款打款中"], [60 "退款成功"], [70 "退款失败"]
+     */
+    private String eventType;
+
+    public KwaixiaodianOrderAftersalesList() {
+    }
+
+    public KwaixiaodianOrderAftersalesList(KuaishouAccessToken token, JSONObject object) {
+        KwaixiaodianOrderAftersalesList aftersales = JSONObject.parseObject(object.toJSONString(), KwaixiaodianOrderAftersalesList.class);
+        aftersales.setCreateTime(DateUtils.timestamptoMinutesAndSecondsStr(object.getLong("createTime")));
+        aftersales.setUpdateTime(DateUtils.timestamptoMinutesAndSecondsStr(object.getLong("updateTime")));
+        aftersales.setNegotiateUpdateTime(DateUtils.timestamptoMinutesAndSecondsStr(object.getLong("negotiateUpdateTime")));
+        aftersales.setSubmitTime(DateUtils.timestamptoMinutesAndSecondsStr(object.getLong("submitTime")));
+        aftersales.setExpireTime(DateUtils.timestamptoMinutesAndSecondsStr(object.getLong("expireTime")));
+        aftersales.setEndTime(DateUtils.timestamptoMinutesAndSecondsStr(object.getLong("endTime")));
+        this.refundId = aftersales.refundId;
+        this.oid = aftersales.oid;
+        this.itemId = aftersales.itemId;
+        this.skuId = aftersales.skuId;
+        this.refundFee = aftersales.refundFee;
+        this.status = aftersales.status;
+        this.refundReason = aftersales.refundReason;
+        this.sellerId = aftersales.sellerId;
+        this.refundType = aftersales.refundType;
+        this.handlingWay = aftersales.handlingWay;
+        this.refundDesc = aftersales.refundDesc;
+        this.logisticsId = aftersales.logisticsId;
+        this.pictures = aftersales.pictures;
+        this.negotiateStatus = aftersales.negotiateStatus;
+        this.validNegotiateBuyerModifyTimeStamp = aftersales.validNegotiateBuyerModifyTimeStamp;
+        this.relSkuId = aftersales.relSkuId;
+        this.relItemId = aftersales.relItemId;
+        this.sellerDisagreeImages = aftersales.sellerDisagreeImages;
+        this.expressNo = aftersales.expressNo;
+        this.expressCode = aftersales.expressCode;
+        this.sellerDisagreeDesc = aftersales.sellerDisagreeDesc;
+        this.sellerDisagreeReason = aftersales.sellerDisagreeReason;
+        this.timeLimitNegotiateChange = aftersales.timeLimitNegotiateChange;
+        this.negotiateReason = aftersales.negotiateReason;
+        this.negotiateUpdateTime = aftersales.negotiateUpdateTime;
+        this.submitTime = aftersales.submitTime;
+        this.expireTime = aftersales.expireTime;
+        this.endTime = aftersales.endTime;
+        this.buyerOpenId = aftersales.buyerOpenId;
+        this.address = aftersales.address;
+        this.specialRefundType = aftersales.specialRefundType;
+        this.logisticsRiskInfos = aftersales.logisticsRiskInfos;
+        this.buyerExchangeAddress = aftersales.buyerExchangeAddress;
+        this.exchangeInfo = aftersales.exchangeInfo;
+        this.returnFreightInfo = aftersales.returnFreightInfo;
+        this.createTime = aftersales.createTime;
+        this.updateTime = aftersales.updateTime;
+        this.eventType = aftersales.eventType;
+        this.setShopId(Long.valueOf(token.getId()));
+        this.setShopName(token.getShopName());
+        this.setCompanyId(token.getCompanyId());
+        this.setCompanyName(token.getCompanyName());
+    }
+}

+ 6 - 0
ruixuan-live/src/main/java/com/ruixuan/isc/mapper/KwaixiaodianOrderCursorListMapper.java

@@ -1,6 +1,7 @@
 package com.ruixuan.isc.mapper;
 
 import com.alibaba.fastjson.JSONObject;
+import com.ruixuan.isc.entity.KwaixiaodianOrderAftersalesList;
 import com.ruixuan.isc.entity.KwaixiaodianOrderCursorList;
 import com.ruixuan.isc.entity.KwaixiaodianShopScore;
 import org.apache.ibatis.annotations.Param;
@@ -29,4 +30,9 @@ public interface KwaixiaodianOrderCursorListMapper {
     void updateKwaixiaodianShopScore(KwaixiaodianShopScore shopScore);
 
     List<JSONObject> queryItemReport(Map<String, Object> requestMap);
+
+    void replaceBatchKwaixiaodianOrderAftersalesList(@Param("list") List<KwaixiaodianOrderAftersalesList> order);
+
+    int updateKWaiOrderAftersalesStatus(Map<String, Object> map);
+
 }

+ 0 - 1
ruixuan-live/src/main/java/com/ruixuan/isc/service/IAccessTokenService.java

@@ -34,5 +34,4 @@ public interface IAccessTokenService {
 
     List<KuaishouAccessToken> getRocketTokenInfos();
 
-
 }

+ 10 - 0
ruixuan-live/src/main/java/com/ruixuan/isc/service/IKwaixiaodianOrderCursorListService.java

@@ -14,6 +14,7 @@ import java.util.Map;
 public interface IKwaixiaodianOrderCursorListService {
     void querykwaiOrderList(String shopId, Integer queryType, String beginDate, String endDate, String cursor);
 
+    /*新增2小时内的订单*/
     void queryNowdayKWaiOrderList(String shopId, String cursor);
 
     /*新增kwaixiaodian_order_cursor_list*/
@@ -22,9 +23,18 @@ public interface IKwaixiaodianOrderCursorListService {
     /*修改 新增kwaixiaodian_order_cursor_list status*/
     void updateKWaiShopOrderStatus(JSONObject eventJSon);
 
+    /*售后 kwaixiaodian_order_cursor_list status*/
+    void afterSales(JSONObject eventJSon);
+
+    /*新增2小时内的售后单*/
+    void queryNowdayafterSalesList(String trim, String s);
+
+    void afterSalesList(String shopId, Integer queryType, String beginDate, String endDate, String cursor);
+
     void queryMaster(String shopId);
 
     void queryShop(String shopId);
 
     List<JSONObject> queryItemReport(Map<String, Object> requestMap);
+
 }

+ 1 - 1
ruixuan-live/src/main/java/com/ruixuan/isc/service/impl/KwaiJSTServiceImpl.java

@@ -459,7 +459,7 @@ public class KwaiJSTServiceImpl implements IKwaiJSTService {
                             KwaixiaodianJstPurchase jst = JSONObject.parseObject(skuInfo.toJSONString(), KwaixiaodianJstPurchase.class);
                             jstList.add(jst);
                             if (!Check.isNull(skuInfo.getJSONArray("items"))) {
-                                addPurchaseItems(jst.getPoDate(), skuInfo.getJSONArray("items"));
+                                addPurchaseItems(skuInfo.getString("po_date"),skuInfo.getJSONArray("items"));
                             }
                         }
                     }

+ 201 - 0
ruixuan-live/src/main/java/com/ruixuan/isc/service/impl/KwaixiaodianOrderCursorListServiceImpl.java

@@ -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);

+ 103 - 0
ruixuan-live/src/main/resources/mapper/isc/KwaixiaodianOrderCursorListMapper.xml

@@ -584,4 +584,107 @@
         where shop_id = #{shopId}
     </update>
 
+
+    <insert id="replaceBatchKwaixiaodianOrderAftersalesList">
+        replace into `ruixuan`.kwaixiaodian_order_aftersales_list(
+        company_id,
+        company_name,
+        shop_id,
+        shop_name,
+        refund_id,
+        oid,
+        item_id,
+        sku_id,
+        refund_fee,
+        status,
+        refund_reason,
+        seller_id,
+        refund_type,
+        handling_way,
+        refund_desc,
+        logistics_id,
+        pictures,
+        negotiate_status,
+        valid_negotiate_buyer_modify_time_stamp,
+        update_time,
+        rel_sku_id,
+        rel_item_id,
+        seller_disagree_images,
+        express_no,
+        express_code,
+        seller_disagree_desc,
+        seller_disagree_reason,
+        time_limit_negotiate_change,
+        negotiate_reason,
+        create_time,
+        negotiate_update_time,
+        submit_time,
+        expire_time,
+        end_time,
+        buyer_open_id,
+        address,
+        special_refund_type,
+        logistics_risk_infos,
+        buyer_exchange_address,
+        exchange_info,
+        return_freight_info
+        )
+        values
+        <foreach collection="list" item="li" separator=",">
+            (
+            #{li.companyId},
+            #{li.companyName},
+            #{li.shopId},
+            #{li.shopName},
+            #{li.refundId},
+            #{li.oid},
+            #{li.itemId},
+            #{li.skuId},
+            #{li.refundFee},
+            #{li.status},
+            #{li.refundReason},
+            #{li.sellerId},
+            #{li.refundType},
+            #{li.handlingWay},
+            #{li.refundDesc},
+            #{li.logisticsId},
+            #{li.pictures},
+            #{li.negotiateStatus},
+            #{li.validNegotiateBuyerModifyTimeStamp},
+            #{li.updateTime},
+            #{li.relSkuId},
+            #{li.relItemId},
+            #{li.sellerDisagreeImages},
+            #{li.expressNo},
+            #{li.expressCode},
+            #{li.sellerDisagreeDesc},
+            #{li.sellerDisagreeReason},
+            #{li.timeLimitNegotiateChange},
+            #{li.negotiateReason},
+            #{li.createTime},
+            #{li.negotiateUpdateTime},
+            #{li.submitTime},
+            #{li.expireTime},
+            #{li.endTime},
+            #{li.buyerOpenId},
+            #{li.address},
+            #{li.specialRefundType},
+            #{li.logisticsRiskInfos},
+            #{li.buyerExchangeAddress},
+            #{li.exchangeInfo},
+            #{li.returnFreightInfo}
+            )
+        </foreach>
+    </insert>
+
+
+    <update id="updateKWaiOrderAftersalesStatus">
+        UPDATE `ruixuan`.kwaixiaodian_order_aftersales_list
+        SET status              = #{status}
+          , handling_way        =#{handlingWay}
+          , special_refund_type =#{specialRefundType}
+          , update_time         =#{updateTime}
+          , event_type=#{eventType}
+        WHERE refund_id = #{refundId}
+    </update>
 </mapper>