1
0
Эх сурвалжийг харах

fixed 商户数据隔离问题

fushengqian 1 жил өмнө
parent
commit
482a56869d
15 өөрчлөгдсөн 203 нэмэгдсэн , 10 устгасан
  1. 52 0
      fuint-application/src/main/java/com/fuint/common/service/OrderService.java
  2. 5 5
      fuint-application/src/main/java/com/fuint/common/service/impl/AccountServiceImpl.java
  3. 9 0
      fuint-application/src/main/java/com/fuint/common/service/impl/CommissionRuleServiceImpl.java
  4. 3 3
      fuint-application/src/main/java/com/fuint/common/service/impl/GoodsServiceImpl.java
  5. 11 0
      fuint-application/src/main/java/com/fuint/common/service/impl/OrderServiceImpl.java
  6. 3 0
      fuint-application/src/main/java/com/fuint/module/backendApi/controller/BackendCouponController.java
  7. 10 1
      fuint-application/src/main/java/com/fuint/module/backendApi/controller/BackendCouponGroupController.java
  8. 3 1
      fuint-application/src/main/java/com/fuint/module/backendApi/controller/BackendGoodsController.java
  9. 3 0
      fuint-application/src/main/java/com/fuint/module/backendApi/controller/BackendMemberController.java
  10. 7 0
      fuint-application/src/main/java/com/fuint/module/backendApi/controller/BackendOpenGiftController.java
  11. 8 0
      fuint-application/src/main/java/com/fuint/module/backendApi/controller/BackendSendLogController.java
  12. 6 0
      fuint-application/src/main/java/com/fuint/module/merchantApi/controller/MerchantMemberController.java
  13. 76 0
      fuint-application/src/main/java/com/fuint/module/schedule/CommissionJob.java
  14. 3 0
      fuint-repository/src/main/java/com/fuint/repository/mapper/MtOrderMapper.java
  15. 4 0
      fuint-repository/src/main/resources/mapper/MtOrderMapper.xml

+ 52 - 0
fuint-application/src/main/java/com/fuint/common/service/OrderService.java

@@ -94,6 +94,7 @@ public interface OrderService extends IService<MtOrder> {
 
     /**
      * 更新订单
+     *
      * @param  reqDto
      * @throws BusinessCheckException
      * */
@@ -101,6 +102,7 @@ public interface OrderService extends IService<MtOrder> {
 
     /**
      * 更新订单
+     *
      * @param mtOrder
      * @return
      * @throws BusinessCheckException
@@ -109,6 +111,7 @@ public interface OrderService extends IService<MtOrder> {
 
     /**
      * 把订单置为已支付
+     *
      * @param orderId
      * @param payAmount
      * @return
@@ -117,46 +120,95 @@ public interface OrderService extends IService<MtOrder> {
 
     /**
      * 根据条件搜索订单
+     *
+     * @param params
+     * @retyurn
      * */
     List<MtOrder> getOrderListByParams(Map<String, Object> params) throws BusinessCheckException;
 
     /**
      * 获取订单总数
+     *
+     * @param merchantId 商户ID
+     * @param storeId 店铺ID
+     * @return
      * */
     BigDecimal getOrderCount(Integer merchantId, Integer storeId) throws BusinessCheckException;
 
     /**
      * 获取订单数量
+     *
+     * @param merchantId 商户ID
+     * @param storeId 店铺ID
+     * @param beginTime 开始时间
+     * @param endTime 结束时间
+     * @return
      * */
     BigDecimal getOrderCount(Integer merchantId, Integer storeId, Date beginTime, Date endTime) throws BusinessCheckException;
 
     /**
      * 计算购物车
+     * @param merchantId 商户ID
+     * @param userId 会员ID
+     * @param cartList 购物车列表
+     * @param couponId 使用的卡券ID
+     * @param isUsePoint 是否使用积分抵扣
+     * @param platform 平台 h5
+     * @param orderMode 订单模式 自取或配送
+     * @return
      * */
     Map<String, Object> calculateCartGoods(Integer merchantId, Integer userId, List<MtCart> cartList, Integer couponId, boolean isUsePoint, String platform, String orderMode) throws BusinessCheckException;
 
     /**
      * 获取支付金额
+     *
+     * @param merchantId 商户ID
+     * @param storeId 店铺ID
+     * @param beginTime 开始时间
+     * @param endTime 结束时间
+     * @return
      * */
     BigDecimal getPayMoney(Integer merchantId, Integer storeId, Date beginTime, Date endTime) throws BusinessCheckException;
 
     /**
      * 获取支付人数
+     *
+     * @param merchantId 商户ID
+     * @param storeId 店铺ID
+     * @return
      * */
     Integer getPayUserCount(Integer merchantId, Integer storeId) throws BusinessCheckException;
 
     /**
      * 获取支付金额
+     *
+     * @param merchantId 商户ID
+     * @param storeId 店铺ID
+     * @return
      * */
     BigDecimal getPayMoney(Integer merchantId, Integer storeId) throws BusinessCheckException;
 
     /**
      * 获取会员支付金额
+     *
+     * @param userId 会员ID
+     * @return
      * */
     BigDecimal getUserPayMoney(Integer userId) throws BusinessCheckException;
 
     /**
      * 获取会员订单数
+     *
+     * @param userId 会员ID
+     * @return
      * */
     Integer getUserPayOrderCount(Integer userId) throws BusinessCheckException;
+
+     /**
+      * 获取待分佣订单列表
+      *
+      * @param dateTime
+      * @return
+      * */
+     List<MtOrder> getTobeCommissionOrderList(String dateTime) throws BusinessCheckException;
 }

+ 5 - 5
fuint-application/src/main/java/com/fuint/common/service/impl/AccountServiceImpl.java

@@ -65,23 +65,23 @@ public class AccountServiceImpl extends ServiceImpl<TAccountMapper, TAccount> im
         lambdaQueryWrapper.ne(TAccount::getAccountStatus, -1); // 1:启用;0:禁用;-1:删除
 
         String name = paginationRequest.getSearchParams().get("name") == null ? "" : paginationRequest.getSearchParams().get("name").toString();
-        if (StringUtils.isNotBlank(name)) {
+        if (StringUtils.isNotEmpty(name)) {
             lambdaQueryWrapper.like(TAccount::getAccountName, name);
         }
         String realName = paginationRequest.getSearchParams().get("realName") == null ? "" : paginationRequest.getSearchParams().get("realName").toString();
-        if (StringUtils.isNotBlank(realName)) {
+        if (StringUtils.isNotEmpty(realName)) {
             lambdaQueryWrapper.like(TAccount::getRealName, realName);
         }
         String status = paginationRequest.getSearchParams().get("status") == null ? "" : paginationRequest.getSearchParams().get("status").toString();
-        if (StringUtils.isNotBlank(status)) {
+        if (StringUtils.isNotEmpty(status)) {
             lambdaQueryWrapper.eq(TAccount::getAccountStatus, status);
         }
         String merchantId = paginationRequest.getSearchParams().get("merchantId") == null ? "" : paginationRequest.getSearchParams().get("merchantId").toString();
-        if (StringUtils.isNotBlank(merchantId)) {
+        if (StringUtils.isNotEmpty(merchantId)) {
             lambdaQueryWrapper.eq(TAccount::getMerchantId, merchantId);
         }
         String storeId = paginationRequest.getSearchParams().get("storeId") == null ? "" : paginationRequest.getSearchParams().get("storeId").toString();
-        if (StringUtils.isNotBlank(storeId)) {
+        if (StringUtils.isNotEmpty(storeId)) {
             lambdaQueryWrapper.eq(TAccount::getStoreId, storeId);
         }
 

+ 9 - 0
fuint-application/src/main/java/com/fuint/common/service/impl/CommissionRuleServiceImpl.java

@@ -231,6 +231,15 @@ public class CommissionRuleServiceImpl extends ServiceImpl<MtCommissionRuleMappe
             throw new BusinessCheckException("该数据状态异常");
         }
         mtCommissionRule.setId(commissionRule.getId());
+        if (commissionRule.getName() != null) {
+            mtCommissionRule.setName(commissionRule.getName());
+        }
+        if (commissionRule.getTarget() != null) {
+            mtCommissionRule.setTarget(commissionRule.getTarget());
+        }
+        if (commissionRule.getType() != null) {
+            mtCommissionRule.setType(commissionRule.getType());
+        }
         if (commissionRule.getStoreId() != null) {
             mtCommissionRule.setStoreId(commissionRule.getStoreId());
         }

+ 3 - 3
fuint-application/src/main/java/com/fuint/common/service/impl/GoodsServiceImpl.java

@@ -554,13 +554,13 @@ public class GoodsServiceImpl extends ServiceImpl<MtGoodsMapper, MtGoods> implem
     public PaginationResponse<GoodsDto> selectGoodsList(Map<String, Object> params) throws BusinessCheckException {
         Integer page = params.get("page") == null ? Constants.PAGE_NUMBER : Integer.parseInt(params.get("page").toString());
         Integer pageSize = params.get("pageSize") == null ? Constants.PAGE_SIZE : Integer.parseInt(params.get("pageSize").toString());
-        Integer storeId = (params.get("storeId") == null || StringUtil.isEmpty(params.get("storeId").toString()))? 0 : Integer.parseInt(params.get("storeId").toString());
+        Integer merchantId = (params.get("merchantId") == null || StringUtil.isEmpty(params.get("merchantId").toString())) ? 0 : Integer.parseInt(params.get("merchantId").toString());
+        Integer storeId = (params.get("storeId") == null || StringUtil.isEmpty(params.get("storeId").toString())) ? 0 : Integer.parseInt(params.get("storeId").toString());
         Integer cateId = (params.get("cateId") == null || StringUtil.isEmpty(params.get("cateId").toString())) ? 0 : Integer.parseInt(params.get("cateId").toString());
         String keyword = params.get("keyword") == null ? "" : params.get("keyword").toString();
 
-        Integer merchantId = 0;
         MtStore mtStore = storeService.queryStoreById(storeId);
-        if (mtStore != null) {
+        if (mtStore != null && mtStore.getMerchantId() != null) {
             merchantId = mtStore.getMerchantId();
         }
         Page<MtGoods> pageHelper = PageHelper.startPage(page, pageSize);

+ 11 - 0
fuint-application/src/main/java/com/fuint/common/service/impl/OrderServiceImpl.java

@@ -1988,4 +1988,15 @@ public class OrderServiceImpl extends ServiceImpl<MtOrderMapper, MtOrder> implem
     public Integer getUserPayOrderCount(Integer userId) {
         return mtOrderMapper.getUserPayOrderCount(userId);
     }
+
+    /**
+     * 获取待分佣订单列表
+     *
+     * @param dateTime
+     * @return
+     * */
+    @Override
+    public List<MtOrder> getTobeCommissionOrderList(String dateTime) {
+        return mtOrderMapper.getTobeCommissionOrderList(dateTime);
+    }
 }

+ 3 - 0
fuint-application/src/main/java/com/fuint/module/backendApi/controller/BackendCouponController.java

@@ -217,6 +217,9 @@ public class BackendCouponController extends BaseController {
         // 会员等级列表
         Map<String, Object> param = new HashMap<>();
         param.put("status", StatusEnum.ENABLED.getKey());
+        if (accountInfo.getMerchantId() != null && accountInfo.getMerchantId() > 0) {
+            param.put("MERCHANT_ID", accountInfo.getMerchantId());
+        }
         List<MtUserGrade> gradeList = memberService.queryMemberGradeByParams(param);
 
         String imagePath = settingService.getUploadBasePath();

+ 10 - 1
fuint-application/src/main/java/com/fuint/module/backendApi/controller/BackendCouponGroupController.java

@@ -327,7 +327,16 @@ public class BackendCouponGroupController extends BaseController {
         PaginationRequest paginationRequest = new PaginationRequest();
         paginationRequest.setCurrentPage(Constants.PAGE_NUMBER);
         paginationRequest.setPageSize(Constants.MAX_ROWS);
-        paginationRequest.setSearchParams(new HashMap<>());
+
+        Map<String, Object> param = new HashMap<>();
+        param.put("status", StatusEnum.ENABLED.getKey());
+        if (accountInfo.getMerchantId() != null && accountInfo.getMerchantId() > 0) {
+            param.put("merchantId", accountInfo.getMerchantId());
+        }
+        if (accountInfo.getStoreId() != null && accountInfo.getStoreId() > 0) {
+            param.put("storeId", accountInfo.getStoreId());
+        }
+        paginationRequest.setSearchParams(param);
         PaginationResponse<MtCouponGroup> paginationResponse = couponGroupService.queryCouponGroupListByPagination(paginationRequest);
 
         List<MtCouponGroup> groupList = paginationResponse.getContent();

+ 3 - 1
fuint-application/src/main/java/com/fuint/module/backendApi/controller/BackendGoodsController.java

@@ -801,7 +801,9 @@ public class BackendGoodsController extends BaseController {
         if (accountInfo == null) {
             return getFailureResult(1001, "请先登录");
         }
-
+        if (accountInfo.getMerchantId() != null && accountInfo.getMerchantId() > 0) {
+            params.put("merchantId", accountInfo.getMerchantId());
+        }
         PaginationResponse<GoodsDto> paginationResponse = goodsService.selectGoodsList(params);
         String imagePath = settingService.getUploadBasePath();
 

+ 3 - 0
fuint-application/src/main/java/com/fuint/module/backendApi/controller/BackendMemberController.java

@@ -346,6 +346,9 @@ public class BackendMemberController extends BaseController {
         }
 
         Map<String, Object> param = new HashMap<>();
+        if (accountInfo.getMerchantId() != null && accountInfo.getMerchantId() > 0) {
+            param.put("MERCHANT_ID", accountInfo.getMerchantId());
+        }
         List<MtUserGrade> userGradeList = memberService.queryMemberGradeByParams(param);
 
         Map<String, Object> result = new HashMap<>();

+ 7 - 0
fuint-application/src/main/java/com/fuint/module/backendApi/controller/BackendOpenGiftController.java

@@ -88,6 +88,9 @@ public class BackendOpenGiftController extends BaseController {
         ResponseObject response = openGiftService.getOpenGiftList(param);
 
         Map<String, Object> params = new HashMap<>();
+        if (accountInfo.getMerchantId() != null && accountInfo.getMerchantId() > 0) {
+            params.put("MERCHANT_ID", accountInfo.getMerchantId());
+        }
         List<MtUserGrade> userGradeList = memberService.queryMemberGradeByParams(params);
 
         Map<String, Object> result = new HashMap<>();
@@ -114,6 +117,10 @@ public class BackendOpenGiftController extends BaseController {
         }
 
         Map<String, Object> param = new HashMap<>();
+
+        if (accountInfo.getMerchantId() != null && accountInfo.getMerchantId() > 0) {
+            param.put("MERCHANT_ID", accountInfo.getMerchantId());
+        }
         List<MtUserGrade> userGradeMap = memberService.queryMemberGradeByParams(param);
 
         OpenGiftDto openGiftInfo = openGiftService.getOpenGiftDetail(id);

+ 8 - 0
fuint-application/src/main/java/com/fuint/module/backendApi/controller/BackendSendLogController.java

@@ -83,6 +83,14 @@ public class BackendSendLogController extends BaseController {
             searchParams.put("status", status);
         }
 
+        if (accountInfo.getMerchantId() != null && accountInfo.getMerchantId() > 0) {
+            searchParams.put("merchantId", accountInfo.getMerchantId());
+        }
+
+        if (accountInfo.getStoreId() != null && accountInfo.getStoreId() > 0) {
+            searchParams.put("storeId", accountInfo.getStoreId());
+        }
+
         if (StringUtil.isNotEmpty(userId)) {
             searchParams.put("userId", userId);
         }

+ 6 - 0
fuint-application/src/main/java/com/fuint/module/merchantApi/controller/MerchantMemberController.java

@@ -169,6 +169,9 @@ public class MerchantMemberController extends BaseController {
         // 会员等级列表
         Map<String, Object> param = new HashMap<>();
         param.put("status", StatusEnum.ENABLED.getKey());
+        if (staffInfo.getMerchantId() != null && staffInfo.getMerchantId() > 0) {
+            param.put("MERCHANT_ID", staffInfo.getMerchantId());
+        }
         List<MtUserGrade> userGradeList = memberService.queryMemberGradeByParams(param);
 
         Map<String, Object> result = new HashMap<>();
@@ -198,6 +201,9 @@ public class MerchantMemberController extends BaseController {
         MtUser mtUserInfo = memberService.queryMemberById(id);
 
         Map<String, Object> param = new HashMap<>();
+        if (accountInfo.getMerchantId() != null && accountInfo.getMerchantId() > 0) {
+            param.put("MERCHANT_ID", accountInfo.getMerchantId());
+        }
         List<MtUserGrade> userGradeList = memberService.queryMemberGradeByParams(param);
 
         Map<String, Object> result = new HashMap<>();

+ 76 - 0
fuint-application/src/main/java/com/fuint/module/schedule/CommissionJob.java

@@ -0,0 +1,76 @@
+package com.fuint.module.schedule;
+
+import com.fuint.common.enums.PayStatusEnum;
+import com.fuint.common.service.OrderService;
+import com.fuint.common.util.DateUtil;
+import com.fuint.framework.exception.BusinessCheckException;
+import com.fuint.repository.model.MtOrder;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.core.env.Environment;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 分销提成计算定时任务
+ *
+ * Created by FSQ
+ * CopyRight https://www.fuint.cn
+ */
+@EnableScheduling
+@Component("CommissionJob")
+public class CommissionJob {
+
+    private Logger logger = LoggerFactory.getLogger(CommissionJob.class);
+
+    /**
+     * 订单服务接口
+     */
+    @Autowired
+    private OrderService orderService;
+
+    @Autowired
+    private Environment environment;
+
+    /**
+     * 一次最多处理订单数量
+     **/
+    private int MAX_SEND_NUM = 50;
+
+    /**
+     * 订单超时分钟
+     * */
+    private int OVER_TIME = 30;
+
+    @Scheduled(cron = "${commission.job.time}")
+    @Transactional(rollbackFor = Exception.class)
+    public void dealOrder() throws BusinessCheckException {
+        String theSwitch = environment.getProperty("commission.job.switch");
+         if (theSwitch.equals("1")) {
+            logger.info("CommissionJobStart!!!");
+            Map<String, Object> param = new HashMap<>();
+            param.put("PAY_STATUS", PayStatusEnum.SUCCESS.getKey());
+            String dateTime = DateUtil.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss");
+            List<MtOrder> dataList = orderService.getTobeCommissionOrderList(dateTime);
+            if (dataList.size() > 0) {
+                int dealNum = 0;
+                for (MtOrder mtOrder : dataList) {
+                     Date overTime = new Date(mtOrder.getCreateTime().getTime() + (60000 * OVER_TIME));
+                     Date nowTime = new Date();
+                     // 处理订单
+                     if (dealNum <= MAX_SEND_NUM && (overTime.getTime() <= nowTime.getTime())) {
+                         dealNum++;
+                     }
+                }
+            }
+            logger.info("CommissionJobEnd!!!");
+        }
+    }
+}

+ 3 - 0
fuint-repository/src/main/java/com/fuint/repository/mapper/MtOrderMapper.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import org.apache.ibatis.annotations.Param;
 import java.math.BigDecimal;
 import java.util.Date;
+import java.util.List;
 
 /**
  * 订单表 Mapper 接口
@@ -40,4 +41,6 @@ public interface MtOrderMapper extends BaseMapper<MtOrder> {
 
     Integer getUserPayOrderCount(@Param("userId") Integer userId);
 
+    List<MtOrder> getTobeCommissionOrderList(@Param("dateTime") String dateTime);
+
 }

+ 4 - 0
fuint-repository/src/main/resources/mapper/MtOrderMapper.xml

@@ -64,4 +64,8 @@
     <select id="getUserPayOrderCount" resultType="java.lang.Integer">
         SELECT COUNT(DISTINCT t.ID) as num FROM mt_order t where t.USER_ID = #{userId} and t.PAY_STATUS='B' and t.STATUS != 'G'
     </select>
+
+    <select id="getTobeCommissionOrderList" resultType="com.fuint.repository.model.MtOrder">
+        SELECT t.* FROM `mt_order` t WHERE t.PAY_TIME > #{dateTime} AND t.ID NOT IN(SELECT ID FROM `mt_commission_log` c WHERE c.STATUS != 'D')
+    </select>
 </mapper>