Prechádzať zdrojové kódy

数据表增加字段:fs_integral_order表的login_account;
DDL语句:ALTER TABLE `fs_integral_order`
ADD COLUMN `login_account` VARCHAR(20) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '代服物流查询账号';
1.积分商城查询物流bugfix;2.积分商品申请退款;3.积分商品确认收货。

dengweize 1 týždeň pred
rodič
commit
6077c989b6

+ 49 - 9
fs-admin/src/main/java/com/fs/his/controller/FsIntegralOrderController.java

@@ -1,13 +1,13 @@
 package com.fs.his.controller;
 
 import cn.hutool.core.util.StrUtil;
-import com.alibaba.fastjson.JSONObject;
 import com.fs.common.annotation.Log;
 import com.fs.common.core.controller.BaseController;
 import com.fs.common.core.domain.AjaxResult;
 import com.fs.common.core.domain.R;
 import com.fs.common.core.page.TableDataInfo;
 import com.fs.common.enums.BusinessType;
+import com.fs.common.utils.CloudHostUtils;
 import com.fs.common.utils.StringUtils;
 import com.fs.common.utils.poi.ExcelUtil;
 import com.fs.his.domain.FsIntegralOrder;
@@ -17,7 +17,8 @@ import com.fs.his.enums.ShipperCodeEnum;
 import com.fs.his.param.FsIntegralOrderParam;
 import com.fs.his.service.IFsExpressService;
 import com.fs.his.service.IFsIntegralOrderService;
-import com.fs.his.utils.PhoneUtil;
+import com.fs.his.service.IFsStoreOrderService;
+import com.fs.utils.OrderContextHolder;
 import com.fs.his.vo.*;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
@@ -44,6 +45,9 @@ public class FsIntegralOrderController extends BaseController
     private IFsIntegralOrderService fsIntegralOrderService;
     @Autowired
     private IFsExpressService expressService;
+
+    @Autowired
+    private IFsStoreOrderService fsStoreOrderService;
     /**
      * 查询积分商品订单列表
      */
@@ -98,18 +102,33 @@ public class FsIntegralOrderController extends BaseController
     @GetMapping(value = "/getExpress/{id}")
     public R getExpress(@PathVariable("id") Long id)
     {
+        /**
+         * selectFsIntegralOrderByOrderId查询的数据表:fs_integral_order
+         * 需要执行添加字段的DDL语句
+         * ALTER TABLE `fs_integral_order`
+         * ADD COLUMN `login_account` VARCHAR(20) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '代服物流查询账号';
+         * */
         FsIntegralOrder fsIntegralOrder = fsIntegralOrderService.selectFsIntegralOrderByOrderId(id);
         ExpressInfoDTO expressInfoDTO=null;
-        if(StringUtils.isNotEmpty(fsIntegralOrder.getDeliverySn())){
-            String lastFourNumber = "";
-            if (fsIntegralOrder.getDeliveryCode().equals(ShipperCodeEnum.SF.getValue())) {
+        //代服管家 查询自己的物流
+        if (CloudHostUtils.hasCloudHostName("金牛明医")) {
+            FsStoreOrder fsStoreOrder = new FsStoreOrder();
+            fsStoreOrder.setOrderCode(fsIntegralOrder.getOrderCode());
+            //线程携带订单信息
+            OrderContextHolder.setIntegralOrder(fsIntegralOrder);
+            expressInfoDTO = fsStoreOrderService.getDfExpressInfoDTO(fsStoreOrder);
+        }else {
+            if (StringUtils.isNotEmpty(fsIntegralOrder.getDeliverySn())) {
+                String lastFourNumber = "";
+                if (fsIntegralOrder.getDeliveryCode().equals(ShipperCodeEnum.SF.getValue())) {
 
-                lastFourNumber = fsIntegralOrder.getUserPhone();
-                if (lastFourNumber.length() == 11) {
-                    lastFourNumber = StrUtil.sub(lastFourNumber, lastFourNumber.length(), -4);
+                    lastFourNumber = fsIntegralOrder.getUserPhone();
+                    if (lastFourNumber.length() == 11) {
+                        lastFourNumber = StrUtil.sub(lastFourNumber, lastFourNumber.length(), -4);
+                    }
                 }
+                expressInfoDTO = expressService.getExpressInfo(fsIntegralOrder.getOrderCode(), fsIntegralOrder.getDeliveryCode(), fsIntegralOrder.getDeliverySn(), lastFourNumber);
             }
-            expressInfoDTO=expressService.getExpressInfo(fsIntegralOrder.getOrderCode(),fsIntegralOrder.getDeliveryCode(),fsIntegralOrder.getDeliverySn(),lastFourNumber);
         }
         return R.ok().put("data",expressInfoDTO);
     }
@@ -178,4 +197,25 @@ public class FsIntegralOrderController extends BaseController
         String orderCode = requestBody.get("orderCode");
         return toAjax(fsIntegralOrderService.cancelOrder(orderCode));
     }
+    /**
+     * 申请退款
+     * 接口不校验是否发货
+     * */
+    @PreAuthorize("@ss.hasPermi('his:integralOrder:cancel')")
+    @Log(title = "积分商品订单", businessType = BusinessType.UPDATE)
+    @PostMapping("/mandatoryRefunds")
+    public AjaxResult mandatoryRefunds(@RequestBody Map<String, String> requestBody){
+        String orderCode = requestBody.get("orderCode");
+        return toAjax(fsIntegralOrderService.mandatoryRefunds(orderCode));
+    }
+
+    /**
+     * 确认收货
+     * todo:权限标识符待定
+     */
+    @Log(title = "积分商品订单", businessType = BusinessType.UPDATE)
+    @GetMapping("/finishOrder/{orderCode}")
+    public AjaxResult finishOrder(@PathVariable("orderCode") String orderCode) {
+        return toAjax(fsIntegralOrderService.finishOrder(orderCode));
+    }
 }

+ 12 - 0
fs-service/src/main/java/com/fs/erp/service/impl/DfOrderServiceImpl.java

@@ -47,6 +47,7 @@ import com.fs.hisStore.service.IFsStoreOrderScrmService;
 import com.fs.hisStore.vo.FsStoreOrderItemVO;
 import com.fs.system.domain.SysConfig;
 import com.fs.system.mapper.SysConfigMapper;
+import com.fs.utils.OrderContextHolder;
 import com.hc.openapi.tool.util.StringUtils;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.http.util.Asserts;
@@ -255,9 +256,20 @@ public class DfOrderServiceImpl implements IErpOrderService {
         String orderCode = request.getCode();
         if (StrUtil.isNotBlank(orderCode)) {
             FsStoreOrder order = fsStoreOrderMapper.selectFsStoreOrderByOrderCode(orderCode);
+            if (OrderContextHolder.hasIntegralOrder())
+                order = new FsStoreOrder();
             if (order != null) {
                 String mailNumber = order.getDeliverySn();
                 Long dfAccountId = getSFAccountIndex(order.getOrderId());
+                //积分商城逻辑
+                if (OrderContextHolder.hasIntegralOrder()){
+                    FsIntegralOrder integralOrder = OrderContextHolder.getIntegralOrder();
+                    mailNumber = integralOrder.getDeliverySn();
+                    FsDfAccount fsDfAccount = fsDfAccountMapper.selectFsDfAccountByAccount(integralOrder.getLoginAccount());
+                    if (fsDfAccount != null)
+                        dfAccountId = fsDfAccount.getId();
+                    OrderContextHolder.clear();//清理threadlocalmap引用。
+                }
                 if (StringUtils.isNotBlank(mailNumber) && dfAccountId != null) {
                     try {
                         Map<String, Object> map = new HashMap<>();

+ 1 - 1
fs-service/src/main/java/com/fs/his/domain/FsIntegralOrder.java

@@ -114,6 +114,6 @@ public class FsIntegralOrder extends BaseEntity
     @Excel(name = "销售公司ID")
     private Long companyId;
 
-
+    private String loginAccount;
 
 }

+ 2 - 0
fs-service/src/main/java/com/fs/his/mapper/FsIntegralOrderMapper.java

@@ -108,4 +108,6 @@ public interface FsIntegralOrderMapper
     FsIntegralOrderPVO selectFsIntegralOrderPVO(Long orderId);
 
     int cancelOrder(@Param("orderId") Long orderId);
+
+    int finishOrder(@Param("orderId") Long orderId,@Param("oldStatus") Integer status);
 }

+ 4 - 0
fs-service/src/main/java/com/fs/his/service/IFsIntegralOrderService.java

@@ -105,4 +105,8 @@ public interface IFsIntegralOrderService
     AjaxResult export(FsIntegralOrder fsIntegralOrder);
 
     int cancelOrder(String orderCode);
+
+    int mandatoryRefunds(String orderCode);
+
+    int finishOrder(String orderCode);
 }

+ 52 - 1
fs-service/src/main/java/com/fs/his/service/impl/FsIntegralOrderServiceImpl.java

@@ -44,6 +44,7 @@ import com.fs.ybPay.dto.OrderQueryDTO;
 import com.fs.ybPay.service.IPayService;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections.CollectionUtils;
+import org.redisson.api.RObjectAsync;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -192,7 +193,8 @@ public class FsIntegralOrderServiceImpl implements IFsIntegralOrderService
         o1.setDeliveryName(fsIntegralOrder.getDeliveryName());
         o1.setDeliverySn(fsIntegralOrder.getDeliverySn());
         o1.setDeliveryTime(DateUtils.getNowDate());
-
+        //增加字段,表示代服物流的账号,后续会使用该账号信息来查询物流。
+        o1.setLoginAccount(fsIntegralOrder.getLoginAccount());
         return fsIntegralOrderMapper.updateFsIntegralOrder(o1);
     }
 
@@ -652,6 +654,55 @@ public class FsIntegralOrderServiceImpl implements IFsIntegralOrderService
         return i;
     }
 
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public int mandatoryRefunds(String orderCode) {
+        //查询订单是否存在且是否未发货
+        FsIntegralOrder fsIntegralOrder = fsIntegralOrderMapper.selectFsIntegralOrderByOrderCode(orderCode);
+        if (null==fsIntegralOrder){
+            throw new ServiceException("订单不存在");
+        }
+        //用户说自己去对接物流,不必校验是否发货。
+//        if (fsIntegralOrder.getStatus()!=1){
+//            throw new ServiceException("订单已发货或已完成");
+//        }
+        int i = 0;
+        //修改订单状态
+        i = fsIntegralOrderMapper.cancelOrder(fsIntegralOrder.getOrderId());
+        if (i>0){
+            //原路退回积分
+            FsUser fsUser = fsUserMapper.selectFsUserByUserId(fsIntegralOrder.getUserId());
+            fsUser.setIntegral(fsUser.getIntegral()+Long.parseLong(fsIntegralOrder.getIntegral()));
+            i = fsUserMapper.updateFsUser(fsUser);
+            //新增积分记录
+            FsUserIntegralLogs fsUserIntegralLogs = new FsUserIntegralLogs();
+            fsUserIntegralLogs.setBalance(fsUser.getIntegral());
+            fsUserIntegralLogs.setBusinessId(fsIntegralOrder.getOrderId().toString());
+            fsUserIntegralLogs.setUserId(fsIntegralOrder.getUserId());
+            fsUserIntegralLogs.setLogType(20);
+            fsUserIntegralLogs.setIntegral(Long.parseLong(fsIntegralOrder.getIntegral()));
+            fsUserIntegralLogs.setBusinessType(2);
+            fsUserIntegralLogs.setStatus(0);
+            i = fsUserIntegralLogsMapper.insertFsUserIntegralLogs(fsUserIntegralLogs);
+            //todo:库存是否需要退还,待定
+        }
+        return i;
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public int finishOrder(String orderCode) {
+        //查询订单是否存在且是否未发货
+        FsIntegralOrder fsIntegralOrder = fsIntegralOrderMapper.selectFsIntegralOrderByOrderCode(orderCode);
+        if (null==fsIntegralOrder){
+            throw new ServiceException("订单不存在");
+        }
+        if (fsIntegralOrder.getStatus()!=2){
+            throw new ServiceException("订单未发货或者未支付,无法完成订单");
+        }
+        return fsIntegralOrderMapper.finishOrder(fsIntegralOrder.getOrderId(), fsIntegralOrder.getStatus());
+    }
+
     /**
      * 处理手机号脱敏
      */

+ 1 - 1
fs-service/src/main/java/com/fs/his/vo/FsIntegralOrderPVO.java

@@ -75,5 +75,5 @@ public class FsIntegralOrderPVO extends BaseEntity
 
     private String phone;
 
-
+    private String loginAccount;
 }

+ 23 - 0
fs-service/src/main/java/com/fs/utils/OrderContextHolder.java

@@ -0,0 +1,23 @@
+package com.fs.utils;
+
+import com.fs.his.domain.FsIntegralOrder;
+
+public class OrderContextHolder {
+    private static final ThreadLocal<FsIntegralOrder> CONTEXT = new ThreadLocal<>();
+
+    public static void setIntegralOrder(FsIntegralOrder order) {
+        CONTEXT.set(order);
+    }
+
+    public static FsIntegralOrder getIntegralOrder() {
+        return CONTEXT.get();
+    }
+
+    public static boolean hasIntegralOrder() {
+        return CONTEXT.get() != null;
+    }
+
+    public static void clear() {
+        CONTEXT.remove();
+    }
+}

+ 9 - 1
fs-service/src/main/resources/mapper/his/FsIntegralOrderMapper.xml

@@ -25,10 +25,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="createTime"    column="create_time"    />
         <result property="remark"    column="remark"    />
         <result property="barCode"    column="bar_code"    />
+        <result property="loginAccount"    column="login_account"    />
     </resultMap>
 
     <sql id="selectFsIntegralOrderVo">
-        select order_id, order_code, user_id,bar_code, user_name, user_phone, user_address, item_json, integral,pay_money,is_pay,pay_time,pay_type, status, delivery_code, delivery_name, delivery_sn, delivery_time, create_time,qw_user_id,company_user_id,company_id,remark from fs_integral_order
+        select order_id, order_code, user_id,bar_code, user_name, user_phone, user_address, item_json, integral,pay_money,is_pay,pay_time,pay_type, status, delivery_code, delivery_name, delivery_sn, delivery_time, create_time,qw_user_id,company_user_id,company_id,remark,login_account from fs_integral_order
     </sql>
 
     <select id="selectFsIntegralOrderList" parameterType="FsIntegralOrder" resultMap="FsIntegralOrderResult">
@@ -131,6 +132,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="createTime != null">create_time = #{createTime},</if>
             <if test="remark != null">remark = #{remark},</if>
             <if test="barCode != null">bar_code = #{barCode},</if>
+            <if test="loginAccount != '' and loginAccount != null">login_account = #{loginAccount},</if>
         </trim>
         where order_id = #{orderId}
     </update>
@@ -149,4 +151,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         update fs_integral_order set status = -1
         where order_id = #{orderId}
     </update>
+    <update id="finishOrder">
+        UPDATE fs_integral_order
+        SET status = 3
+        WHERE order_id = #{orderId}
+          AND status = #{oldStatus}
+    </update>
 </mapper>