浏览代码

fixed 分佣提成功能迭代

fushengqian 10 月之前
父节点
当前提交
2ead6a6e2e

+ 3 - 2
fuint-application/src/main/java/com/fuint/common/service/CommissionRelationService.java

@@ -5,6 +5,7 @@ import com.fuint.framework.pagination.PaginationRequest;
 import com.fuint.framework.pagination.PaginationResponse;
 import com.fuint.framework.exception.BusinessCheckException;
 import com.fuint.repository.model.MtCommissionRelation;
+import com.fuint.repository.model.MtUser;
 
 /**
  * 分销提成关系业务接口
@@ -25,10 +26,10 @@ public interface CommissionRelationService extends IService<MtCommissionRelation
     /**
      * 设置分销提成关系
      *
-     * @param  userId 会员ID
+     * @param  userInfo 会员信息
      * @param  shareId 分享者ID
      * @throws BusinessCheckException
      * @retrurn
      */
-    void setCommissionRelation(Integer userId, String shareId);
+    void setCommissionRelation(MtUser userInfo, String shareId) throws BusinessCheckException;
 }

+ 56 - 2
fuint-application/src/main/java/com/fuint/common/service/impl/CommissionRelationServiceImpl.java

@@ -4,12 +4,16 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fuint.common.service.CommissionRelationService;
+import com.fuint.common.service.MemberService;
+import com.fuint.common.util.CommonUtil;
 import com.fuint.framework.exception.BusinessCheckException;
 import com.fuint.framework.pagination.PaginationRequest;
 import com.fuint.framework.pagination.PaginationResponse;
 import com.fuint.repository.mapper.MtCommissionRelationMapper;
 import com.fuint.common.enums.StatusEnum;
 import com.fuint.repository.model.MtCommissionRelation;
+import com.fuint.repository.model.MtUser;
+import com.fuint.utils.StringUtil;
 import com.github.pagehelper.PageHelper;
 import lombok.AllArgsConstructor;
 import org.apache.commons.lang.StringUtils;
@@ -35,6 +39,11 @@ public class CommissionRelationServiceImpl extends ServiceImpl<MtCommissionRelat
 
     private MtCommissionRelationMapper mtCommissionRelationMapper;
 
+    /**
+     * 会员服务接口
+     */
+    private MemberService memberService;
+
     /**
      * 分页查询关系列表
      *
@@ -79,13 +88,58 @@ public class CommissionRelationServiceImpl extends ServiceImpl<MtCommissionRelat
     /**
      * 设置分销提成关系
      *
-     * @param userId  会员ID
+     * @param userInfo 会员信息
      * @param shareId 分享者ID
      * @throws BusinessCheckException
      * @retrurn
      */
     @Override
-    public void setCommissionRelation(Integer userId, String shareId) {
+    public void setCommissionRelation(MtUser userInfo, String shareId) throws BusinessCheckException {
+        if (userInfo == null || StringUtil.isEmpty(shareId) || Integer.parseInt(shareId) <= 0) {
+            return;
+        }
+
+        MtUser shareUserInfo = memberService.queryMemberById(Integer.parseInt(shareId));
+        if (shareUserInfo == null) {
+            return;
+        }
+
+        Map<String, Object> param = new HashMap();
+        param.put("USER_ID", Integer.parseInt(shareId));
+        param.put("SUB_USER_ID", userInfo.getId());
+        param.put("STATUS", StatusEnum.ENABLED.getKey());
+        List<MtCommissionRelation> dataList = mtCommissionRelationMapper.selectByMap(param);
+        if (dataList == null || dataList.size() <= 0) {
+            MtCommissionRelation mtCommissionRelation = new MtCommissionRelation();
+            mtCommissionRelation.setCreateTime(new Date());
+            mtCommissionRelation.setUpdateTime(new Date());
+            mtCommissionRelation.setStatus(StatusEnum.ENABLED.getKey());
+            mtCommissionRelation.setUserId(Integer.parseInt(shareId));
+            mtCommissionRelation.setSubUserId(userInfo.getId());
+            mtCommissionRelation.setMerchantId(userInfo.getMerchantId());
+            mtCommissionRelation.setInviteCode(shareUserInfo.getUserNo());
+            mtCommissionRelation.setLevel(1);
+            mtCommissionRelationMapper.insert(mtCommissionRelation);
+        }
+
+        Map<String, Object> params = new HashMap();
+        params.put("SUB_USER_ID", Integer.parseInt(shareId));
+        params.put("LEVEL", 1);
+        params.put("STATUS", StatusEnum.ENABLED.getKey());
+        List<MtCommissionRelation> data = mtCommissionRelationMapper.selectByMap(params);
+        if (data != null && data.size() > 0) {
+            MtCommissionRelation mtCommissionRelation = new MtCommissionRelation();
+            mtCommissionRelation.setCreateTime(new Date());
+            mtCommissionRelation.setUpdateTime(new Date());
+            mtCommissionRelation.setStatus(StatusEnum.ENABLED.getKey());
+            mtCommissionRelation.setUserId(data.get(0).getUserId());
+            mtCommissionRelation.setSubUserId(userInfo.getId());
+            mtCommissionRelation.setMerchantId(userInfo.getMerchantId());
+            mtCommissionRelation.setInviteCode(data.get(0).getInviteCode());
+            mtCommissionRelation.setLevel(2);
+            mtCommissionRelationMapper.insert(mtCommissionRelation);
+        }
+
         return;
     }
 }

+ 9 - 4
fuint-application/src/main/java/com/fuint/common/service/impl/MemberServiceImpl.java

@@ -25,6 +25,8 @@ import com.github.pagehelper.Page;
 import com.github.pagehelper.PageHelper;
 import lombok.AllArgsConstructor;
 import org.apache.commons.lang.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.BeanUtils;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.data.domain.PageImpl;
@@ -45,6 +47,8 @@ import java.util.*;
 @AllArgsConstructor(onConstructor_= {@Lazy})
 public class MemberServiceImpl extends ServiceImpl<MtUserMapper, MtUser> implements MemberService {
 
+    private static final Logger logger = LoggerFactory.getLogger(MemberServiceImpl.class);
+
     private MtUserMapper mtUserMapper;
 
     private MtUserGradeMapper mtUserGradeMapper;
@@ -140,6 +144,7 @@ public class MemberServiceImpl extends ServiceImpl<MtUserMapper, MtUser> impleme
 
     /**
      * 获取当前操作会员信息
+     *
      * @param userId 会员ID
      * @param token 登录token
      * @return
@@ -401,7 +406,7 @@ public class MemberServiceImpl extends ServiceImpl<MtUserMapper, MtUser> impleme
         openGiftService.openGift(mtUser.getId(), Integer.parseInt(mtUser.getGradeId()), true);
 
         // 分佣关系
-        commissionRelationService.setCommissionRelation(mtUser.getId(), shareId);
+        commissionRelationService.setCommissionRelation(mtUser, shareId);
 
         // 新增用户发短信通知
         if (mtUser.getId() > 0 && mtUser.getStatus().equals(StatusEnum.ENABLED.getKey())) {
@@ -413,7 +418,7 @@ public class MemberServiceImpl extends ServiceImpl<MtUserMapper, MtUser> impleme
                 Map<String, String> params = new HashMap<>();
                 sendSmsService.sendSms(mtUser.getMerchantId(), "register-sms", mobileList, params);
             } catch (BusinessCheckException e) {
-                // empty
+                logger.error(e.getMessage());
             }
         }
 
@@ -516,7 +521,7 @@ public class MemberServiceImpl extends ServiceImpl<MtUserMapper, MtUser> impleme
         openGiftService.openGift(mtUser.getId(), Integer.parseInt(mtUser.getGradeId()), true);
 
         // 分佣关系
-        commissionRelationService.setCommissionRelation(mtUser.getId(), shareId);
+        commissionRelationService.setCommissionRelation(mtUser, shareId);
 
         return mtUser;
     }
@@ -736,7 +741,7 @@ public class MemberServiceImpl extends ServiceImpl<MtUserMapper, MtUser> impleme
             openGiftService.openGift(user.getId(), Integer.parseInt(user.getGradeId()), true);
 
             // 分佣关系
-            commissionRelationService.setCommissionRelation(mtUser.getId(), shareId);
+            commissionRelationService.setCommissionRelation(mtUser, shareId);
         } else {
             // 已被禁用
             if (user.getStatus().equals(StatusEnum.DISABLE.getKey())) {

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

@@ -23,6 +23,8 @@ import com.github.pagehelper.Page;
 import com.github.pagehelper.PageHelper;
 import lombok.AllArgsConstructor;
 import org.apache.commons.lang.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.data.domain.PageImpl;
 import org.springframework.data.domain.PageRequest;
 import org.springframework.stereotype.Service;
@@ -40,6 +42,8 @@ import java.util.*;
 @AllArgsConstructor
 public class OpenGiftServiceImpl extends ServiceImpl<MtOpenGiftMapper, MtOpenGift> implements OpenGiftService {
 
+    private static final Logger logger = LoggerFactory.getLogger(OpenGiftServiceImpl.class);
+
     private MtOpenGiftMapper mtOpenGiftMapper;
 
     private MtUserMapper mtUserMapper;
@@ -293,7 +297,7 @@ public class OpenGiftServiceImpl extends ServiceImpl<MtOpenGiftMapper, MtOpenGif
                            totalAmount = totalAmount.add(mtCoupon.getAmount());
                        }
                    } catch (Exception e) {
-                       throw new BusinessCheckException(e.getMessage());
+                       logger.error(e.getMessage());
                    }
                }
             }

+ 1 - 0
fuint-application/src/main/java/com/fuint/module/backendApi/controller/BackendCashierController.java

@@ -399,6 +399,7 @@ public class BackendCashierController extends BaseController {
              Map<String, Object> param = new HashMap<>();
              param.put("hangNo", hangNo);
              param.put("merchantId", accountInfo.getMerchantId());
+             param.put("storeId", accountInfo.getStoreId());
              List<MtCart> cartList = cartService.queryCartListByParams(param);
              HangUpDto dto = new HangUpDto();
              dto.setIsEmpty(true);

+ 2 - 2
fuint-application/src/main/resources/application.properties

@@ -1,7 +1,7 @@
 # \u57FA\u672C\u914D\u7F6E
 server.port=8080
-env.profile=dev
-env.properties.path=C:/Code/fuint/fuint-backend/configure/
+env.profile=prod
+env.properties.path=/usr/local/fuint/configure/
 
 # \u6570\u636E\u5E93\u914D\u7F6E
 spring.datasource.type=com.zaxxer.hikari.HikariDataSource

+ 3 - 0
fuint-repository/src/main/java/com/fuint/repository/model/MtCommissionRelation.java

@@ -40,6 +40,9 @@ public class MtCommissionRelation implements Serializable {
     @ApiModelProperty("被邀请会员ID")
     private Integer subUserId;
 
+    @ApiModelProperty("等级")
+    private Integer level;
+
     @ApiModelProperty("备注")
     private String description;
 

+ 1 - 1
fuint-repository/src/main/resources/mapper/MtCommissionRelationMapper.xml

@@ -3,7 +3,7 @@
 <mapper namespace="com.fuint.repository.mapper.MtCommissionRelationMapper">
 
     <select id="getCommissionUserId" resultType="java.lang.Integer">
-        select `USER_ID` from mt_commission_relation r where r.MERCHANT_ID = #{merchantId} and r.SUB_USER_ID = #{userId} and `STATUS` = 'A';
+        select `USER_ID` from mt_commission_relation r where r.MERCHANT_ID = #{merchantId} and r.SUB_USER_ID = #{userId} and `LEVEL` = 1 and `STATUS` = 'A' LIMIT 1;
     </select>
 
 </mapper>