|
@@ -2,21 +2,22 @@ package com.txz.cif.service.impl;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
-import cn.hutool.core.util.IdUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.txz.cif.constants.MyConstants;
|
|
|
-import com.txz.cif.core.ServiceException;
|
|
|
+import com.txz.cif.core.AbstractService;
|
|
|
import com.txz.cif.dao.RedEnvelopeMapper;
|
|
|
import com.txz.cif.dto.EarningsDTO;
|
|
|
import com.txz.cif.dto.Result;
|
|
|
import com.txz.cif.dubbo.client.NoticeDubboServiceClient;
|
|
|
import com.txz.cif.dubbo.client.OperatingConfigDubboServiceClient;
|
|
|
import com.txz.cif.enums.BizTypeEnum;
|
|
|
-import com.txz.cif.model.*;
|
|
|
+import com.txz.cif.model.Account;
|
|
|
+import com.txz.cif.model.ConfigMember;
|
|
|
+import com.txz.cif.model.RedEnvelope;
|
|
|
+import com.txz.cif.model.User;
|
|
|
import com.txz.cif.param.OrderParam;
|
|
|
-import com.txz.cif.param.SignRedEnvelopeParam;
|
|
|
import com.txz.cif.service.*;
|
|
|
-import com.txz.cif.core.AbstractService;
|
|
|
import com.txz.cif.web.bo.UserTopBo;
|
|
|
import com.txz.cif.web.para.RedEnvelopeParam;
|
|
|
import com.txz.mall.enums.NoticeEnum;
|
|
@@ -42,166 +43,178 @@ import java.util.List;
|
|
|
public class RedEnvelopeServiceImpl extends AbstractService<RedEnvelope> implements RedEnvelopeService {
|
|
|
@Resource
|
|
|
private RedEnvelopeMapper cRedEnvelopeMapper;
|
|
|
-
|
|
|
+
|
|
|
@Resource
|
|
|
private AccountService accountService;
|
|
|
-
|
|
|
+
|
|
|
@Resource
|
|
|
private FlowService flowService;
|
|
|
-
|
|
|
+
|
|
|
@Resource
|
|
|
private UserService userService;
|
|
|
-
|
|
|
+
|
|
|
@Resource
|
|
|
private OperatingConfigDubboServiceClient operatingConfigDubboServiceClient;
|
|
|
-
|
|
|
+
|
|
|
@Resource
|
|
|
private ConfigMemberService configMemberService;
|
|
|
-
|
|
|
+
|
|
|
@Resource
|
|
|
private NoticeDubboServiceClient noticeDubboServiceClient;
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 类型 1充值 2提现 3参团 4退款 5开团红包 6参团红包 7签到红包 8下级红包佣金 9下下级红包佣金
|
|
|
+ *
|
|
|
* @param param
|
|
|
+ *
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
public Result addRedEnvelope(RedEnvelopeParam param) {
|
|
|
- com.txz.operating.result.Result<ConfigDTO> redEnvelopeSettelDay = operatingConfigDubboServiceClient.getConfigByCode("red_envelope_settel_day_"+param.getBizType());
|
|
|
+ com.txz.operating.result.Result<ConfigDTO> redEnvelopeSettelDay = operatingConfigDubboServiceClient.getConfigByCode("red_envelope_settel_day_" + param.getBizType());
|
|
|
Integer settleDay = Integer.parseInt(redEnvelopeSettelDay.getData().getValueInfo());
|
|
|
- Date settleTime = DateUtil.offsetDay(param.getTransTime(),settleDay);
|
|
|
+ Date settleTime = DateUtil.offsetDay(param.getTransTime(), settleDay);
|
|
|
List<RedEnvelope> redEnvelopes = new ArrayList<>();
|
|
|
- if (BizTypeEnum.getByKey(param.getBizType()) == BizTypeEnum.OPEN_GROUP_RED_ENVELOPE){
|
|
|
- //开团红包
|
|
|
- redEnvelopes.addAll(bulidRedEnvelope(param.getUserIds().get(0),param,settleTime)) ;
|
|
|
- } else if (BizTypeEnum.getByKey(param.getBizType()) == BizTypeEnum.JOIN_GROUP_RED_ENVELOPE){
|
|
|
- //参团红包
|
|
|
- for (OrderParam userId:param.getUserIds()){
|
|
|
- redEnvelopes.addAll(bulidRedEnvelope(userId,param,settleTime)) ;
|
|
|
+ if (BizTypeEnum.getByKey(param.getBizType()) == BizTypeEnum.OPEN_GROUP_RED_ENVELOPE) {
|
|
|
+ // 开团红包
|
|
|
+ redEnvelopes.addAll(bulidRedEnvelope(param.getUserIds().get(0), param, settleTime));
|
|
|
+ } else if (BizTypeEnum.getByKey(param.getBizType()) == BizTypeEnum.JOIN_GROUP_RED_ENVELOPE) {
|
|
|
+ // 参团红包
|
|
|
+ for (OrderParam userId : param.getUserIds()) {
|
|
|
+ redEnvelopes.addAll(bulidRedEnvelope(userId, param, settleTime));
|
|
|
}
|
|
|
- } else if (BizTypeEnum.getByKey(param.getBizType()) == BizTypeEnum.SIGN_RED_ENVELOPE){
|
|
|
- //签到红包
|
|
|
- redEnvelopes.addAll(bulidRedEnvelope(param.getUserIds().get(0),param,settleTime)) ;
|
|
|
- }else if (BizTypeEnum.getByKey(param.getBizType()) == BizTypeEnum.PROMOTION_COMMISSION){
|
|
|
- //直推红包
|
|
|
- redEnvelopes.addAll(bulidRedEnvelope(param.getUserIds().get(0),param,settleTime)) ;
|
|
|
+ } else if (BizTypeEnum.getByKey(param.getBizType()) == BizTypeEnum.SIGN_RED_ENVELOPE) {
|
|
|
+ // 签到红包
|
|
|
+ redEnvelopes.addAll(bulidRedEnvelope(param.getUserIds().get(0), param, settleTime));
|
|
|
+ } else if (BizTypeEnum.getByKey(param.getBizType()) == BizTypeEnum.PROMOTION_COMMISSION) {
|
|
|
+ // 直推红包
|
|
|
+ redEnvelopes.addAll(bulidRedEnvelope(param.getUserIds().get(0), param, settleTime));
|
|
|
}
|
|
|
- if (CollUtil.isNotEmpty(redEnvelopes)){
|
|
|
+ if (CollUtil.isNotEmpty(redEnvelopes)) {
|
|
|
save(redEnvelopes);
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
- public BigDecimal sumWithDay(String day, Long userId,Integer type) {
|
|
|
- if (day == null){
|
|
|
- return cRedEnvelopeMapper.sumWithDay(null,userId,type);
|
|
|
+ public BigDecimal sumWithDay(String day, Long userId, Integer type) {
|
|
|
+ if (day == null) {
|
|
|
+ return cRedEnvelopeMapper.sumWithDay(null, userId, type);
|
|
|
} else {
|
|
|
- return cRedEnvelopeMapper.sumWithDay(day,userId,type);
|
|
|
+ return cRedEnvelopeMapper.sumWithDay(day, userId, type);
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public List<UserTopBo> top(Integer type, Integer page, Integer size) {
|
|
|
PageHelper.startPage(page, size);
|
|
|
- HashMap<String,Object> map = new HashMap<>();
|
|
|
- map.put("page",page);
|
|
|
- map.put("size",size);
|
|
|
- map.put("startTime",DateUtil.offsetDay(DateUtil.date(),-8));
|
|
|
- map.put("endTime",DateUtil.yesterday());
|
|
|
- return cRedEnvelopeMapper.top( map);
|
|
|
+ HashMap<String, Object> map = new HashMap<>();
|
|
|
+ map.put("page", page);
|
|
|
+ map.put("size", size);
|
|
|
+ map.put("startTime", DateUtil.offsetDay(DateUtil.date(), -8));
|
|
|
+ map.put("endTime", DateUtil.yesterday());
|
|
|
+ return cRedEnvelopeMapper.top(map);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public EarningsDTO sumWithOrderNo(String orderNo) {
|
|
|
return cRedEnvelopeMapper.sumWithOrderNo(orderNo);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public void settle(RedEnvelope redEnvelope) {
|
|
|
flowService.settle(redEnvelope);
|
|
|
update(RedEnvelope.builder().id(redEnvelope.getId()).status(2).build());
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public static void main(String[] args) {
|
|
|
System.out.println(DateUtil.now());
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 构建红包对象
|
|
|
+ *
|
|
|
* @param userId
|
|
|
* @param param
|
|
|
* @param settleTime
|
|
|
+ *
|
|
|
* @return
|
|
|
*/
|
|
|
private List<RedEnvelope> bulidRedEnvelope(OrderParam userId, RedEnvelopeParam param, Date settleTime) {
|
|
|
-
|
|
|
+
|
|
|
List<RedEnvelope> ret = new ArrayList<>();
|
|
|
- //红包
|
|
|
- ret.add(bulidRedEnvelope2(1,userId,param,settleTime)) ;
|
|
|
+ // 红包
|
|
|
+ RedEnvelope redEnvelope = bulidRedEnvelope2(1, userId, param, settleTime);
|
|
|
+ if (ObjectUtil.isNotNull(redEnvelope)) {
|
|
|
+ ret.add(redEnvelope);
|
|
|
+ }
|
|
|
// 开团、参团 才有 佣金红包
|
|
|
if (BizTypeEnum.getByKey(param.getBizType()) == BizTypeEnum.OPEN_GROUP_RED_ENVELOPE
|
|
|
- || BizTypeEnum.getByKey(param.getBizType()) == BizTypeEnum.JOIN_GROUP_RED_ENVELOPE ){
|
|
|
- //只有 开团、参团 有分佣
|
|
|
+ || BizTypeEnum.getByKey(param.getBizType()) == BizTypeEnum.JOIN_GROUP_RED_ENVELOPE) {
|
|
|
+ // 只有 开团、参团 有分佣
|
|
|
User user = userService.findById(userId.getUserId());
|
|
|
- if (user.getPid() != null){
|
|
|
- //找父亲 上级分佣
|
|
|
- ret.add(bulidRedEnvelope2(2, OrderParam.builder().orderNo(userId.getOrderNo()).userId(user.getPid()).build(),param,settleTime)) ;
|
|
|
- if (user.getPpid() != null){
|
|
|
- //找爷爷 上上级分佣
|
|
|
- ret.add(bulidRedEnvelope2(3,OrderParam.builder().orderNo(userId.getOrderNo()).userId(user.getPpid()).build(),param,settleTime)) ;
|
|
|
+ if (user.getPid() != null) {
|
|
|
+ // 找父亲 上级分佣
|
|
|
+ RedEnvelope pRedEnvelope = bulidRedEnvelope2(2, OrderParam.builder().orderNo(userId.getOrderNo()).userId(user.getPid()).build(), param, settleTime);
|
|
|
+ if (ObjectUtil.isNotNull(pRedEnvelope)) {
|
|
|
+ ret.add(pRedEnvelope);
|
|
|
+ }
|
|
|
+ if (user.getPpid() != null) {
|
|
|
+ // 找爷爷 上上级分佣
|
|
|
+ RedEnvelope ppRedEnvelope = bulidRedEnvelope2(3, OrderParam.builder().orderNo(userId.getOrderNo()).userId(user.getPpid()).build(), param, settleTime);
|
|
|
+ if (ObjectUtil.isNotNull(ppRedEnvelope)) {
|
|
|
+ ret.add(ppRedEnvelope);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
return ret;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
- *
|
|
|
- * @param type 1自己 2父亲 3爷爷
|
|
|
+ * @param type 1自己 2父亲 3爷爷
|
|
|
* @param userId
|
|
|
* @param param
|
|
|
* @param settleTime
|
|
|
+ *
|
|
|
* @return
|
|
|
*/
|
|
|
- private RedEnvelope bulidRedEnvelope2(Integer type , OrderParam userId, RedEnvelopeParam param, Date settleTime) {
|
|
|
+ private RedEnvelope bulidRedEnvelope2(Integer type, OrderParam userId, RedEnvelopeParam param, Date settleTime) {
|
|
|
Condition c = new Condition(Account.class);
|
|
|
c.createCriteria().andEqualTo("userId", userId.getUserId())
|
|
|
- .andEqualTo("bizType",2);
|
|
|
+ .andEqualTo("bizType", 2);
|
|
|
List<Account> accounts = accountService.findByCondition(c);
|
|
|
Account account = accounts.get(0);
|
|
|
- Integer bizType = type == 1?param.getBizType(): type==2? BizTypeEnum.FIRST_COMMISSION.getKey():BizTypeEnum.SECONDARY_COMMISSION.getKey();
|
|
|
+ Integer bizType = type == 1 ? param.getBizType() : type == 2 ? BizTypeEnum.FIRST_COMMISSION.getKey() : BizTypeEnum.SECONDARY_COMMISSION.getKey();
|
|
|
// 一级二级分佣重新计算结算时间
|
|
|
- if (type > 1){
|
|
|
- com.txz.operating.result.Result<ConfigDTO> redEnvelopeSettelDay = operatingConfigDubboServiceClient.getConfigByCode("red_envelope_settel_day_"+bizType);
|
|
|
+ if (type > 1) {
|
|
|
+ com.txz.operating.result.Result<ConfigDTO> redEnvelopeSettelDay = operatingConfigDubboServiceClient.getConfigByCode("red_envelope_settel_day_" + bizType);
|
|
|
Integer settleDay = Integer.parseInt(redEnvelopeSettelDay.getData().getValueInfo());
|
|
|
- settleTime = DateUtil.offsetDay(param.getTransTime(),settleDay);
|
|
|
+ settleTime = DateUtil.offsetDay(param.getTransTime(), settleDay);
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-// Long id = IdUtil.getSnowflake(1,1).nextId();
|
|
|
- //借:营销账户(负债类201)(贷) -100元
|
|
|
- //贷:个人账户(负债类202)(贷) +100元
|
|
|
+
|
|
|
+
|
|
|
+ // Long id = IdUtil.getSnowflake(1,1).nextId();
|
|
|
+ // 借:营销账户(负债类201)(贷) -100元
|
|
|
+ // 贷:个人账户(负债类202)(贷) +100元
|
|
|
BigDecimal amount = param.getAmount();
|
|
|
-
|
|
|
+
|
|
|
User user = userService.findById(userId.getUserId());
|
|
|
- if (type > 1 ){
|
|
|
+ if (type > 1) {
|
|
|
ConfigMember level = configMemberService.findBy("level", user.getVipLevel());
|
|
|
- if (type == 2){
|
|
|
- amount = amount.multiply(level.getDirectReferralReward()).divide(BigDecimal.valueOf(100),2, RoundingMode.DOWN);
|
|
|
+ if (type == 2) {
|
|
|
+ amount = amount.multiply(level.getDirectReferralReward()).divide(BigDecimal.valueOf(100), 2, RoundingMode.DOWN);
|
|
|
} else {
|
|
|
- amount = amount.multiply(level.getIndirectReferralReward()).divide(BigDecimal.valueOf(100),2, RoundingMode.DOWN);
|
|
|
+ amount = amount.multiply(level.getIndirectReferralReward()).divide(BigDecimal.valueOf(100), 2, RoundingMode.DOWN);
|
|
|
}
|
|
|
}
|
|
|
- if (amount.compareTo(BigDecimal.ZERO)>0){
|
|
|
+ if (amount.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
RedEnvelope redEnvelope = RedEnvelope.builder()
|
|
|
.amount(amount)
|
|
|
.createTime(DateUtil.date())
|
|
|
.orderNo(param.getUserIds().get(0).getOrderNo())
|
|
|
- //类型: 1(自己) 返回 1(开团)或2(参团) 2(父亲)返回4(上级分佣) 3(爷爷)返回5(上上级分佣)
|
|
|
+ // 类型: 1(自己) 返回 1(开团)或2(参团) 2(父亲)返回4(上级分佣) 3(爷爷)返回5(上上级分佣)
|
|
|
.bizType(bizType)
|
|
|
.name(user.getName())
|
|
|
.phoneNo(user.getPhoneNo())
|
|
@@ -212,22 +225,22 @@ public class RedEnvelopeServiceImpl extends AbstractService<RedEnvelope> impleme
|
|
|
.userId(param.getUserIds().get(0).getUserId())
|
|
|
.tranNo(param.getOrderNo())
|
|
|
.settleTime(settleTime)
|
|
|
- .createUser(param.getUserIds().get(0).getUserId()+"")
|
|
|
+ .createUser(param.getUserIds().get(0).getUserId() + "")
|
|
|
.build();
|
|
|
- try{
|
|
|
- noticeDubboServiceClient.addRewardNotice(getNoticeEunm(bizType),param.getUserIds().get(0).getOrderNo(),redEnvelope.getUserId());
|
|
|
- }catch (Exception e){
|
|
|
-
|
|
|
+ try {
|
|
|
+ noticeDubboServiceClient.addRewardNotice(getNoticeEunm(bizType), param.getUserIds().get(0).getOrderNo(), redEnvelope.getUserId());
|
|
|
+ } catch (Exception e) {
|
|
|
+
|
|
|
}
|
|
|
return redEnvelope;
|
|
|
} else {
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
private NoticeEnum getNoticeEunm(Integer bizType) {
|
|
|
NoticeEnum ret = null;
|
|
|
- switch (bizType){
|
|
|
+ switch (bizType) {
|
|
|
case 5001:
|
|
|
return NoticeEnum.REWARD_OPEN_GROUP_BUY;
|
|
|
case 5002:
|
|
@@ -243,5 +256,5 @@ public class RedEnvelopeServiceImpl extends AbstractService<RedEnvelope> impleme
|
|
|
}
|
|
|
return ret;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}
|