浏览代码

存在文化代码提交

yjwang 5 天之前
父节点
当前提交
f2adb16d06

+ 1 - 1
fs-service/src/main/java/com/fs/company/service/impl/CompanyServiceImpl.java

@@ -411,7 +411,7 @@ public class CompanyServiceImpl implements ICompanyService
                 orderMap.setOrderId(order.getId());
                 orderMap.setTuiMoneyStatus(1);
                 storeOrderMapper.updateFsStoreOrder(orderMap);
-                BigDecimal money = order.getPayMoney().add(order.getPayRemain());
+                BigDecimal money = order.getPayMoney().add(order.getPayRemain()==null?new BigDecimal("0"):order.getPayRemain());
                 company.setMoney(company.getMoney().add(money));
                 companyMapper.updateCompany(company);
                 CompanyMoneyLogs log=new CompanyMoneyLogs();

+ 3 - 0
fs-service/src/main/java/com/fs/hisStore/domain/FsStoreOrderScrm.java

@@ -351,4 +351,7 @@ public class FsStoreOrderScrm extends BaseEntity
     private BigDecimal billPrice;
     private String erpPhone;
 
+    @TableField(exist = false)
+    private String bankTransactionId;
+
 }

+ 6 - 0
fs-service/src/main/java/com/fs/hisStore/mapper/FsStorePaymentScrmMapper.java

@@ -352,4 +352,10 @@ public interface FsStorePaymentScrmMapper
 
     @Select("select * from fs_store_payment_scrm where pay_code=#{payCode}")
     FsStorePaymentScrm selectFsStorePaymentByPaymentCode(String payCode);
+
+    @Select("select * from fs_store_payment_scrm where business_type=2 and order_id=#{orderId}")
+    FsStorePaymentScrm queryFsStorePaymentByOrderId(@Param("orderId") Long orderId);
+
+    @Select("select * from fs_store_payment_scrm where business_type=2 and bank_transaction_id=#{bankTransactionId}")
+    FsStorePaymentScrm queryFsStorePaymentByBusinessOrderId(@Param("bankTransactionId") String bankTransactionId);
 }

+ 3 - 0
fs-service/src/main/java/com/fs/hisStore/param/FsStoreOrderFinishParam.java

@@ -11,5 +11,8 @@ public class FsStoreOrderFinishParam implements Serializable
     @ApiModelProperty(value = "orderId")
     private Long orderId;
 
+    @ApiModelProperty(value = "transactionId")
+    private String transactionId;
+
 
 }

+ 6 - 0
fs-service/src/main/java/com/fs/hisStore/service/IFsStoreOrderScrmService.java

@@ -293,4 +293,10 @@ public interface IFsStoreOrderScrmService
      * 刷新订单结算状态
      * **/
     void refreshOrderSettlementStatus();
+
+    /**
+     * 代付金额计算方法
+     * @param order 订单信息
+     * **/
+    void calculateAgentPayment(FsStoreOrderScrm order);
 }

+ 55 - 58
fs-service/src/main/java/com/fs/hisStore/service/impl/FsStoreOrderScrmServiceImpl.java

@@ -1,7 +1,9 @@
 package com.fs.hisStore.service.impl;
 
+import cn.binarywang.wx.miniapp.api.WxMaOrderShippingService;
 import cn.binarywang.wx.miniapp.bean.shop.request.shipping.*;
 import cn.binarywang.wx.miniapp.bean.shop.response.WxMaOrderShippingInfoGetListResponse;
+import cn.binarywang.wx.miniapp.bean.shop.response.WxMaOrderShippingInfoGetResponse;
 import cn.hutool.core.date.DateTime;
 import cn.binarywang.wx.miniapp.api.WxMaService;
 import cn.hutool.core.net.URLDecoder;
@@ -91,6 +93,7 @@ import com.github.binarywang.wxpay.exception.WxPayException;
 import com.github.binarywang.wxpay.service.WxPayService;
 import lombok.Synchronized;
 import lombok.extern.slf4j.Slf4j;
+import me.chanjar.weixin.common.error.WxErrorException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.aop.framework.AopContext;
@@ -3701,70 +3704,64 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
 
     @Override
     @Transactional(rollbackFor = Throwable.class, propagation = Propagation.REQUIRED)
-    public void  refreshOrderSettlementStatus(){
+    public void refreshOrderSettlementStatus() {
         try {
-        //判断是否对接微信发货
-        String json = configService.selectConfigByKey("store.config");
-        StoreConfig config = JSONUtil.toBean(json, StoreConfig.class);
-        if(config != null && config.getIsWeChatShipping() != null && config.getIsWeChatShipping()){
-           //获取未结算订单
-            List<FsStoreOrderScrm> orderScrmList=fsStoreOrderMapper.getUnsettledOrder();
-            String payConfig=configService.selectConfigByKey("store.pay");
-            JSONObject js=JSON.parseObject(payConfig);
-            String appId=js.getString("hf");
-            if(ObjectUtil.isNotNull(appId) && !appId.equals("")){
-                //请求微信批量查询订单
-                final WxMaService wxService = WxMaConfiguration.getMaService(appId);
-                WxMaOrderShippingInfoGetListRequest request=new WxMaOrderShippingInfoGetListRequest();
-
-
-                WxMaOrderShippingInfoGetListResponse response=wxService.getWxMaOrderShippingService().getList(request);
-
-                logger.info("请求信息------------------------》{}",response);
-//                if(!orderScrmList.isEmpty()){
-//                    orderScrmList.forEach(order->{
-//                        if (order.getStatus() == OrderInfoEnum.STATUS_2.getValue()) {
-//                            order.setFinishTime(new Date());
-//                            order.setStatus(3);
-//                            fsStoreOrderMapper.updateFsStoreOrder(order);
-//                            orderStatusService.create(order.getId(), OrderLogEnum.FINISH_ORDER.getValue(),
-//                                    OrderLogEnum.FINISH_ORDER.getDesc());
-//                            //写入公司余额 条件是只有全款订单才分,非全款后台导入
-//                            if (order.getCompanyId() != null && order.getCompanyId() > 0 && order.getPayDelivery().compareTo(new BigDecimal(0)) == 0) {
-//                                if (order.getTuiMoneyStatus() == null || order.getTuiMoneyStatus() != 1) {
-//                                    companyService.addCompanyMoney(order);
-//                                }
-//                            }
-//
-//                            FsErpConfig erpConfig = configUtil.getErpConfig();
-//                            Integer erpType = erpConfig.getErpType();
-//                            Integer erpOpen = erpConfig.getErpOpen();
-//                            if (erpOpen != null && erpOpen == 1) {
-//                                if (erpType != null && erpType == 2) {
-//                                    // 如果是物流代收 或者 货到付款
-//                                    if ("2".equals(order.getPayType()) || "3".equals(order.getPayType())) {
-//                                        // 已结算
-//                                        if ("1".equals(order.getDeliveryPayStatus())) {
-//                                            FsErpFinishPush fsErpFinishPush = new FsErpFinishPush();
-//                                            fsErpFinishPush.setOrderId(order.getId());
-//                                            fsErpFinishPush.setTaskStatus(0);
-//                                            fsErpFinishPush.setRetryCount(0);
-//                                            fsErpFinishPush.setCreateTime(new Date());
-//                                            fsErpFinishPushMapper.insert(fsErpFinishPush);
-//                                        }
-//                                    }
-//                                }
-//                            }
-//                        }
-//                    });
-//                }
+            // 判断是否对接微信发货
+            String json = configService.selectConfigByKey("store.config");
+            StoreConfig config = JSONUtil.toBean(json, StoreConfig.class);
+            logger.info("进入微信结算订单定时任务--------------->{}","start");
+            if (config != null && config.getIsWeChatShipping() != null && config.getIsWeChatShipping()) {
+                // 获取未结算订单
+                List<FsStoreOrderScrm> orderScrmList = fsStoreOrderMapper.getUnsettledOrder();
+
+                String payConfig = configService.selectConfigByKey("store.pay");
+                JSONObject js = JSON.parseObject(payConfig);
+                String appId = js.getString("appId");
+
+                if (ObjectUtil.isNotNull(appId) && !appId.isEmpty()) {
+                    final WxMaService wxService = WxMaConfiguration.getMaService(appId);
+
+                    if (!orderScrmList.isEmpty()) {
+                        for (FsStoreOrderScrm order : orderScrmList) {
+                            WxMaOrderShippingInfoGetRequest request = new WxMaOrderShippingInfoGetRequest();
+                            request.setTransactionId(order.getBankTransactionId());
+                            WxMaOrderShippingInfoGetResponse response;
+
+                            try {
+                                response = wxService.getWxMaOrderShippingService().get(request);
+
+                                if (response.getErrCode().equals(0)) {
+                                    // 订单状态枚举:(1) 待发货;(2) 已发货;(3) 确认收货;(4) 交易完成;(5) 已退款
+                                    if (response.getOrder().getOrderState().equals(3) || response.getOrder().getOrderState().equals(4)) {
+                                        if (order.getStatus() == OrderInfoEnum.STATUS_2.getValue()) {
+                                            this.finishOrder(order.getId());
+                                        }
+                                    }
+                                    logger.info("请求信息------------------------》{}", response);
+                                }
+
+                            } catch (WxErrorException e) {
+                                logger.info("异常信息------------------------》{}", e.getMessage());
+                                continue;
+                            }
+                        }
+                    }
+                }
             }
-        }
-        }catch (Exception e){
+        } catch (Exception e) {
             e.getStackTrace();
+        }finally {
+            logger.info("进入微信结算订单定时任务--------------->{}","end");
         }
     }
 
+    @Override
+    public void calculateAgentPayment(FsStoreOrderScrm order) {
+        //通过订单获取关联商品信息
+
+
+    }
+
     private boolean uploadShippingInfoToWechat(WxMaService wxService,
                                                OrderOpenIdTransDTO orderInfo,
                                                List<FsStoreOrderCodeOpenIdVo> orderDetails,

+ 15 - 2
fs-service/src/main/resources/mapper/hisStore/FsStoreOrderScrmMapper.xml

@@ -913,7 +913,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             WHEN status = 1 THEN 2
             ELSE status
             END,
-
+            delivery_send_time = NOW(),
             <if test="list != null and list.size() > 0 and list[0].deliveryPayMoney != null">
                 delivery_pay_money = CASE
                 <foreach collection="list" item="item">
@@ -990,6 +990,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </select>
 
     <select id="getUnsettledOrder" resultType="com.fs.hisStore.domain.FsStoreOrderScrm">
-
+        SELECT
+            sos.*,
+            sps.bank_transaction_id
+        FROM
+            fs_store_order_scrm sos
+                INNER JOIN fs_store_payment_scrm sps ON sos.id = sps.order_id
+        WHERE
+            sos.paid = 1
+          AND sps.business_type = 2
+          AND sos.`status` = 2
+          AND DATEDIFF(
+                      NOW(),
+                      sos.delivery_send_time
+                  ) >= 3
     </select>
 </mapper>

+ 17 - 1
fs-user-app/src/main/java/com/fs/app/controller/store/StoreOrderScrmController.java

@@ -194,6 +194,12 @@ public class StoreOrderScrmController extends AppBaseController {
         order.setUserPhone(ParseUtils.parsePhone(order.getUserPhone()));
         order.setUserAddress(ParseUtils.parseIdCard(order.getUserAddress()));
         List<FsStoreOrderItemVO> list=itemService.selectFsStoreOrderItemListByOrderId(orderId);
+        //获取交易单号
+        FsStorePaymentScrm paymentScrm=fsStorePaymentMapper.queryFsStorePaymentByOrderId(orderId);
+        String transactionId = null;
+        if(paymentScrm != null){
+            transactionId=paymentScrm.getBankTransactionId();
+        }
         Calendar calendar = Calendar.getInstance();
         calendar.setTime(order.getCreateTime());
         String json=configService.selectConfigByKey("his.store");
@@ -225,7 +231,7 @@ public class StoreOrderScrmController extends AppBaseController {
         else if(order.getStatus()==1||order.getStatus()==2){
             isAfterSales=1;
         }
-        return R.ok().put("isAfterSales",isAfterSales).put("order",order).put("items",list).put("payLimitTime",payLimitTime).put("prescribe",prescribe);
+        return R.ok().put("isAfterSales",isAfterSales).put("order",order).put("items",list).put("payLimitTime",payLimitTime).put("prescribe",prescribe).put("transactionId",transactionId);
     }
 
     @Login
@@ -897,6 +903,16 @@ public class StoreOrderScrmController extends AppBaseController {
     @ApiOperation("完成订单")
     @PostMapping("/finishOrder")
     public R finishOrder( @Validated @RequestBody FsStoreOrderFinishParam param, HttpServletRequest request){
+        if(StringUtils.isNotEmpty(param.getTransactionId())){
+            if(param.getOrderId() == null || param.getOrderId() == 0){
+                //根据交易单号获取订单ID
+                FsStorePaymentScrm fsStorePaymentScrm=fsStorePaymentMapper.queryFsStorePaymentByBusinessOrderId(param.getTransactionId());
+                if(fsStorePaymentScrm == null){
+                    return R.error("操作失败,交易单号未找到订单信息!");
+                }
+                param.setOrderId(fsStorePaymentScrm.getOrderId());
+            }
+        }
         return orderService.finishOrder(param.getOrderId());
     }