gc-core/src/main/java/com/xzx/gc/common/constant/CommonEnum.java
@@ -98,7 +98,12 @@ 首单后返利数量("order_num_first"), 返利固定积分("regular_point"), 返利环保币比例("regular_money_percent"), 完成数量后返积分("point_reward") 完成数量后返积分("point_reward"), 推荐首单奖励("first_score"), 朋友圈分享奖励("share_score"), 朋友圈分享限次("share_score_time"), 邀请奖励("register_score") ;//枚举结束 private String value; gc-core/src/main/java/com/xzx/gc/entity/ScoreDetails.java
@@ -16,7 +16,7 @@ //用户ID private String userId; //交易类型 1-用户充值2-集物员支付3-用户兑换所得4-用户消费5-消费退回6-管理员充值7-其他 //交易类型 1-用户充值2-集物员支付3-用户兑换所得4-用户消费5-消费退回6-管理员充值7-其他 8-邀请后首单返利 9-分享朋友圈 10-邀请奖励 private Integer type; public static final Integer SCORE_TYPE_USER_RECHARGE = 1; public static final Integer SCORE_TYPE_PAY = 2; @@ -25,6 +25,9 @@ public static final Integer SCORE_TYPE_SHOPPING_RETURN = 5; public static final Integer SCORE_TYPE_ADMIN_RECHARGE = 6; public static final Integer SCORE_TYPE_OTHER = 7; public static final Integer SCORE_TYPE_INVITE_FIRST_ORDER = 8; public static final Integer SCORE_TYPE_SHARE_MOMENTS = 9; public static final Integer SCORE_TYPE_INVITE = 10; //原始积分 private BigDecimal originalScore; gc-order/src/main/java/com/xzx/gc/order/mapper/AccountMapper.java
@@ -36,4 +36,6 @@ void updateUserAccount(@Param("accountId") String accountId, @Param("money") String money, @Param("overdraftLimit") String overdraftLimit); AccountInfo selectAccountInfoByUserId(@Param("userId") String userId); AccountInfo selectAccountInfoByPhone(@Param("phone") String phone); } gc-order/src/main/java/com/xzx/gc/order/mapper/JhyOrderMapper.java
@@ -19,4 +19,6 @@ List<JhyStatusCountVo> selectOrderStatusCount(@Param("type") Integer type, @Param("userId") String userId); List<JhyOrder> selectJhyOrderListByStatus(@Param("list") List<String> list, @Param("userId") String userId); List<JhyOrder> selectJhyOrderNoWaitAndCancel(@Param("userId") String userId); } gc-order/src/main/java/com/xzx/gc/order/mapper/OrderMapper.java
@@ -221,5 +221,7 @@ List<OrderInfo> findListOrderReceiveTime(@Param("receiver")String receiver); List<OrderInfo> selectOrderNoWaitAndCancel(@Param("userId") String userId); } gc-order/src/main/java/com/xzx/gc/order/mapper/RedPaperRuleMapper.java
@@ -59,4 +59,6 @@ List<XzxUserRedpaperRuleModel> queryRoyalty(@Param("partnerIds")List<String> partnerIds, @Param("partnerId")String partnerId); RedPaperRule selectDistribRule(); List<RedPaperRule> selectRuleByType(@Param("type") Integer type); } gc-order/src/main/java/com/xzx/gc/order/mapper/UserShareInfoMapper.java
@@ -26,6 +26,8 @@ List<Map<String, Object>> queryPackageGoods(@Param("packageId") String packageId, @Param("partnerId") String partnerId); UserShareInfo selectUserShareInfoByInvited(@Param("phone") String phone); } gc-order/src/main/java/com/xzx/gc/order/service/DistribService.java
@@ -44,7 +44,17 @@ private UserMapper userMapper; @Autowired private ScoreDetailsMapper scoreDetailsMapper; @Autowired private UserShareInfoMapper userShareInfoMapper; @Autowired private OrderMapper orderMapper; /** * 团长积分/环保币返利规则 * * @param orderId * @param userId */ public void distribRecord(Long orderId, String userId) { UserHeadRelate userHeadRelate = userHeadRelateMapper.selectRelateByUserId(userId); if (userHeadRelate == null) { @@ -160,6 +170,92 @@ sysMessageMapper.insert(sysMessage); } /** * 普通用户邀请用户并下单返利规则 * */ public void inviteAddOrderScore(String userId, String orderId) { UserInfo userInfo = userMapper.selectByPrimaryKey(userId); UserShareInfo userShareInfo = userShareInfoMapper.selectUserShareInfoByInvited(userInfo.getMobilePhone()); if (userShareInfo == null) { return; } // 查询当前用户邀请人信息,判断是否为团长,如果是团长,则不返利 AccountInfo accountInfo = accountMapper.selectAccountInfoByPhone(userShareInfo.getMobilePhone()); if (AccountInfo.IS_HEAD_Y.equals(accountInfo.getIsHead())) { log.info("邀请人为团长, 不执行返利"); return; } if (AccountInfo.IS_PROHIBIT_Y.equals(accountInfo.getIsProhibit())) { return; } List<RedPaperRule> rules = redPaperRuleMapper.selectRuleByType(10); if (CollUtil.isEmpty(rules)) { log.info("没有具体规则"); return; } RedPaperRule rule = rules.get(0); if (rule.getStatus() == 0) { log.info("规则被禁用, 不执行返利"); return; } List<OrderInfo> riderOrders = orderMapper.selectOrderNoWaitAndCancel(userId); int riderCnt = 0; if (CollUtil.isNotEmpty(riderOrders)) { riderCnt = riderOrders.size(); } List<JhyOrder> jhyOrders = jhyOrderMapper.selectJhyOrderNoWaitAndCancel(userId); int jhyCnt = 0; if (CollUtil.isNotEmpty(jhyOrders)) { jhyCnt = jhyOrders.size(); } // 仅首单返利 if (jhyCnt + riderCnt > 1) { return; } String value = getRuleValue(rule, CommonEnum.推荐首单奖励.getValue()); BigDecimal returnScore = BigDecimal.ZERO; if (StrUtil.isNotBlank(value)) { returnScore = new BigDecimal(value); } BigDecimal collectScore = StrUtil.isNotBlank(accountInfo.getCollectScore()) ? new BigDecimal(accountInfo.getCollectScore()) : BigDecimal.ZERO; accountInfo.setCollectScore(collectScore.add(returnScore).setScale(0, BigDecimal.ROUND_DOWN).toString()); accountMapper.updateByPrimaryKey(accountInfo); if (returnScore.compareTo(BigDecimal.ZERO) > 0) { ScoreDetails scoreDetails = new ScoreDetails(); scoreDetails.setCurrentScore(new BigDecimal(accountInfo.getCollectScore())); scoreDetails.setOriginalScore(collectScore); scoreDetails.setChangeScore(returnScore); scoreDetails.setCreatedTime(new Date()); scoreDetails.setType(ScoreDetails.SCORE_TYPE_INVITE_FIRST_ORDER); scoreDetails.setUserId(accountInfo.getUserId()); scoreDetails.setOrderNo(orderId.toString()); scoreDetailsMapper.insert(scoreDetails); } SysMessage sysMessage = new SysMessage(); sysMessage.setCreateTime(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss")); sysMessage.setCreateUserId(accountInfo.getUserId()); sysMessage.setUserId(accountInfo.getUserId()); sysMessage.setMessageType("4"); sysMessage.setMessageSubTypeName("返利消息"); sysMessage.setMessage("收到用户:" + userInfo.getMobilePhone().replaceAll("(\\w{3})\\w*(\\w{4})", "$1****$2") + "的订单返利, 积分:" + returnScore); sysMessage.setFlag("2"); sysMessageMapper.insert(sysMessage); } private String getRuleValue(RedPaperRule redPaperRule, String key) { List<String> rules = StrUtil.split(redPaperRule.getSharingProfitType(), ','); List<String> values = StrUtil.split(redPaperRule.getShareRatio(), ','); gc-order/src/main/java/com/xzx/gc/order/service/JhyOrderService.java
@@ -7,9 +7,11 @@ import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.xzx.gc.common.constant.Constants; import com.xzx.gc.common.constant.RedisKeyConstant; import com.xzx.gc.common.exception.RestException; import com.xzx.gc.common.utils.IdUtils; import com.xzx.gc.common.utils.LocationUtils; import com.xzx.gc.common.utils.RedisUtil; import com.xzx.gc.entity.*; import com.xzx.gc.order.dto.AddJhyOrderDto; import com.xzx.gc.order.dto.JhyOrderConfirmDto; @@ -59,6 +61,9 @@ @Autowired private DistribService distribService; @Autowired private RedisUtil redisUtil; public void addJhyOrder(AddJhyOrderDto orderDto) { JhyInfo jhyInfo = jhyInfoMapper.selectJhyInfoByUserId(orderDto.getUserId()); @@ -200,6 +205,9 @@ } public void confirmOrder(JhyOrderConfirmDto confirmDto) { String key = RedisKeyConstant.ORDER_PAY + confirmDto.getOrderId(); if (redisUtil.setnx(key, "0")) { try { JhyInfo jhyInfo = jhyInfoMapper.selectJhyInfoByUserId(confirmDto.getUserId()); if (jhyInfo == null || !JhyInfo.CHECK_PASS.equals(jhyInfo.getStatus())) { throw new RestException(-3, "不是集物员"); @@ -267,7 +275,20 @@ userAccount.setCollectScore(userScore.add(totalScore).setScale( 0, BigDecimal.ROUND_DOWN ).toString()); accountMapper.updateByPrimaryKey(userAccount); // 团长返利 distribService.distribRecord(order.getId(), order.getUserId()); // 推荐返利 distribService.inviteAddOrderScore(order.getUserId(), order.getId().toString()); } catch (Exception e) { log.error("异常", e); throw new RestException("支付失败"); } finally { redisUtil.del(key); } } else { throw new RestException("支付中"); } } public Map<Integer, Integer> orderStatusCount(Integer type, String userId) { gc-order/src/main/java/com/xzx/gc/order/service/OrderService.java
@@ -226,6 +226,8 @@ @Autowired private OrderHomeApplianceService orderHomeApplianceService; @Autowired private DistribService distribService; @@ -1150,6 +1152,7 @@ traceIds = getTrace(orderInfoReq); } distribService.inviteAddOrderScore(orderInfoReq.getCreateUserId(), orderId); } } } catch (RestException e) { @@ -3291,6 +3294,8 @@ //更新账户余额 accountService.updateMoneyByUserId(receiver, Convert.toBigDecimal(payMoney.toString())); distribService.inviteAddOrderScore(createUserId, orderId); return Result.success(byUserId.getAccountName()); } catch (Exception e) { ExceptionUtils.err("支付失败", e); gc-order/src/main/resources/mapper/order/AccountMapper.xml
@@ -92,4 +92,9 @@ <select id="selectAccountInfoByUserId" resultType="com.xzx.gc.entity.AccountInfo"> select * from xzx_account_info where user_id=#{userId} </select> <select id="selectAccountInfoByPhone" resultType="com.xzx.gc.entity.AccountInfo"> select a.* from xzx_account_info a, xzx_user_info b where a.user_id=b.user_id and b.mobile_phone=#{phone} </select> </mapper> gc-order/src/main/resources/mapper/order/JhyOrderMapper.xml
@@ -79,4 +79,9 @@ #{id} </foreach> </select> <select id="selectJhyOrderNoWaitAndCancel" resultType="com.xzx.gc.entity.JhyOrder"> select * from xzx_jhy_order where status not in (1, 2, 5) and user_id=#{userId} </select> </mapper> gc-order/src/main/resources/mapper/order/OrderMapper.xml
@@ -1523,5 +1523,8 @@ b.receive_time ASC </select> <select id="selectOrderNoWaitAndCancel" resultType="com.xzx.gc.entity.OrderInfo"> select * from xzx_order_info where order_status not in ('1', '2', '6') and create_user_id=#{userId} </select> </mapper> gc-order/src/main/resources/mapper/order/RedPaperRuleMapper.xml
@@ -321,4 +321,8 @@ <select id="selectDistribRule" resultType="com.xzx.gc.entity.RedPaperRule"> select * from xzx_user_redpaper_rule where rule_type=9 </select> <select id="selectRuleByType" resultType="com.xzx.gc.entity.RedPaperRule"> select * from xzx_user_redpaper_rule where rule_type=#{type} </select> </mapper> gc-order/src/main/resources/mapper/order/UserShareInfoMapper.xml
@@ -165,5 +165,7 @@ </if> </select> <select id="selectUserShareInfoByInvited" resultType="com.xzx.gc.entity.UserShareInfo"> select * from xzx_user_share_info where register_mobile_phone=#{phone}; </select> </mapper> gc-user/src/main/java/com/xzx/gc/user/controller/ApiDistribController.java
@@ -70,4 +70,11 @@ return JsonResult.success(distribService.findHeadTeamListInPage(headTeamDto)); } @ApiOperation("分享到朋友圈") @PostMapping(value = "/distrib/shareMoments") public JsonResult<String> shareMoments(HttpServletRequest request) { distribService.shareToMoments(getUserId(request)); return JsonResult.success("分享成功"); } } gc-user/src/main/java/com/xzx/gc/user/mapper/AccountMapper.java
@@ -78,5 +78,7 @@ String selectJDSLExportByHeadUserId(@Param("accountId")String id, @Param("record")ExportDistribDataListDto distribDataListDto); List<AccountInfo> selectAccountInfoByIds(@Param("list") List<String> list); AccountInfo selectAccountInfoByPhone(@Param("phone") String phone); } gc-user/src/main/java/com/xzx/gc/user/mapper/RedPaperRuleMapper.java
@@ -4,9 +4,13 @@ import com.xzx.gc.util.GcMapper; import org.apache.ibatis.annotations.Param; import java.util.List; public interface RedPaperRuleMapper extends GcMapper<RedPaperRule> { RedPaperRule getOne(@Param("now") String now, @Param("ruleType") String ruleType, @Param("partnerId") String partnerId); RedPaperRule selectByRuleName(@Param("ruleStr")String ruleStr); List<RedPaperRule> selectByRuleType(@Param("type") String type); } gc-user/src/main/java/com/xzx/gc/user/mapper/ScoreDetailsMapper.java
New file @@ -0,0 +1,7 @@ package com.xzx.gc.user.mapper; import com.xzx.gc.entity.ScoreDetails; import com.xzx.gc.util.GcMapper; public interface ScoreDetailsMapper extends GcMapper<ScoreDetails> { } gc-user/src/main/java/com/xzx/gc/user/service/DistribService.java
@@ -6,7 +6,9 @@ import cn.hutool.core.date.DateUtil; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.xzx.gc.common.constant.CommonEnum; import com.xzx.gc.common.exception.RestException; import com.xzx.gc.common.utils.RedisUtil; import com.xzx.gc.common.utils.StringUtils; import com.xzx.gc.entity.*; import com.xzx.gc.user.dto.*; @@ -30,6 +32,7 @@ import javax.annotation.Resource; import java.math.BigDecimal; import java.math.RoundingMode; import java.util.HashMap; import java.util.List; @@ -55,6 +58,10 @@ private UserShareInfoMapper userShareInfoMapper; @Autowired private SysMessageMapper sysMessageMapper; @Autowired private RedisUtil redisUtil; @Autowired private ScoreDetailsMapper scoreDetailsMapper; public ViewSettingVo viewSetting(String ruleStr) { ViewSettingVo viewSettingVo = new ViewSettingVo(); @@ -468,4 +475,104 @@ redPaperRuleMapper.updateByPrimaryKey(redPaperRule); } } public void shareToMoments(String userId) { List<RedPaperRule> redPaperRules = redPaperRuleMapper.selectByRuleType("10"); if (CollUtil.isEmpty(redPaperRules)) { return; } RedPaperRule rule = redPaperRules.get(0); String shareTimes = getRuleValue(rule, CommonEnum.朋友圈分享限次.getValue()); String shareScore = getRuleValue(rule, CommonEnum.朋友圈分享奖励.getValue()); String key = "moments:times:" + userId; Integer times = redisUtil.getAsInt("moments:times:" + userId); times = times == null ? 1 : times + 1; if (StrUtil.isNotBlank(shareTimes)) { if (times > Integer.parseInt(shareTimes)) { throw new RestException("达到24小时内最大分享次数"); } if (StrUtil.isBlank(shareScore)) { return; } AccountInfo accountInfo = accountMapper.selectOneByUserId(userId); BigDecimal returnScore = new BigDecimal(shareScore); BigDecimal collectScore = StrUtil.isNotBlank(accountInfo.getCollectScore()) ? new BigDecimal(accountInfo.getCollectScore()) : BigDecimal.ZERO; accountInfo.setCollectScore(collectScore.add(returnScore).setScale(0, RoundingMode.DOWN).toString()); accountMapper.updateByPrimaryKey(accountInfo); ScoreDetails scoreDetails = new ScoreDetails(); scoreDetails.setCurrentScore(new BigDecimal(accountInfo.getCollectScore())); scoreDetails.setOriginalScore(collectScore); scoreDetails.setChangeScore(returnScore); scoreDetails.setCreatedTime(new Date()); scoreDetails.setType(ScoreDetails.SCORE_TYPE_SHARE_MOMENTS); scoreDetails.setUserId(accountInfo.getUserId()); scoreDetailsMapper.insert(scoreDetails); SysMessage sysMessage = new SysMessage(); sysMessage.setCreateTime(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss")); sysMessage.setCreateUserId(accountInfo.getUserId()); sysMessage.setUserId(accountInfo.getUserId()); sysMessage.setMessageType("4"); sysMessage.setMessageSubTypeName("朋友圈分享"); sysMessage.setMessage("朋友圈分享, 积分:" + returnScore); sysMessage.setFlag("2"); sysMessageMapper.insert(sysMessage); redisUtil.setex(key, times.toString(), 84400); } } public void inviteAward(String phone) { AccountInfo accountInfo = accountMapper.selectAccountInfoByPhone(phone); List<RedPaperRule> redPaperRules = redPaperRuleMapper.selectByRuleType("10"); if (CollUtil.isEmpty(redPaperRules)) { return; } RedPaperRule rule = redPaperRules.get(0); String invite = getRuleValue(rule, CommonEnum.邀请奖励.getValue()); if (StrUtil.isBlank(invite)) { return; } BigDecimal returnScore = new BigDecimal(invite); BigDecimal collectScore = StrUtil.isNotBlank(accountInfo.getCollectScore()) ? new BigDecimal(accountInfo.getCollectScore()) : BigDecimal.ZERO; accountInfo.setCollectScore(collectScore.add(returnScore).setScale(0, RoundingMode.DOWN).toString()); accountMapper.updateByPrimaryKey(accountInfo); ScoreDetails scoreDetails = new ScoreDetails(); scoreDetails.setCurrentScore(new BigDecimal(accountInfo.getCollectScore())); scoreDetails.setOriginalScore(collectScore); scoreDetails.setChangeScore(returnScore); scoreDetails.setCreatedTime(new Date()); scoreDetails.setType(ScoreDetails.SCORE_TYPE_INVITE); scoreDetails.setUserId(accountInfo.getUserId()); scoreDetailsMapper.insert(scoreDetails); SysMessage sysMessage = new SysMessage(); sysMessage.setCreateTime(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss")); sysMessage.setCreateUserId(accountInfo.getUserId()); sysMessage.setUserId(accountInfo.getUserId()); sysMessage.setMessageType("4"); sysMessage.setMessageSubTypeName("邀请奖励"); sysMessage.setMessage("邀请奖励, 积分:" + returnScore); sysMessage.setFlag("2"); sysMessageMapper.insert(sysMessage); } private String getRuleValue(RedPaperRule redPaperRule, String key) { List<String> rules = StrUtil.split(redPaperRule.getSharingProfitType(), ','); List<String> values = StrUtil.split(redPaperRule.getShareRatio(), ','); int i = rules.indexOf(key); return values.get(i); } } gc-user/src/main/java/com/xzx/gc/user/service/UserLoginService.java
@@ -93,6 +93,8 @@ @Autowired private AccountService accountService; @Autowired private DistribService distribService; @@ -166,6 +168,7 @@ public int login(UserReq userReq) { log.info("邀请人手机号:{}", userReq.getRegisterMobilePhone()); int notCheckLoginFlag = userReq.getNotCheckLoginFlag(); if(StringUtils.isBlank(userReq.getOpenId())){ return -4; @@ -246,6 +249,8 @@ userShareInfo.setRegisterTime(DateUtil.now()); userShareInfoMapper.insertSelective(userShareInfo); log.info("用户绑定成功,邀请人:{},被邀请人:{}", userShareInfo.getMobilePhone(), userShareInfo.getRegisterMobilePhone()); distribService.inviteAward(userShareInfo.getMobilePhone()); }else{ log.warn("邀请人:{}不是普通用户",userShareInfo.getMobilePhone()); } gc-user/src/main/resources/mapper/user/AccountMapper.xml
@@ -554,4 +554,9 @@ #{id} </foreach> </select> <select id="selectAccountInfoByPhone" resultType="com.xzx.gc.entity.AccountInfo"> select a.* from xzx_account_info a, xzx_user_info b where a.user_id=b.user_id and b.mobile_phone=#{phone} </select> </mapper> gc-user/src/main/resources/mapper/user/RedPaperRuleMapper.xml
@@ -21,4 +21,8 @@ <select id="selectByRuleName" resultType="com.xzx.gc.entity.RedPaperRule"> select * from xzx_user_redpaper_rule where rule_name = #{ruleStr} </select> <select id="selectByRuleType" resultType="com.xzx.gc.entity.RedPaperRule"> select * from xzx_user_redpaper_rule where rule_type=#{type} </select> </mapper> gc-user/src/main/resources/mapper/user/ScoreDetailsMapper.xml
New file @@ -0,0 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.xzx.gc.user.mapper.ScoreDetailsMapper"> </mapper>