|
@@ -7,6 +7,7 @@ import cn.hutool.core.util.ObjUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
import cn.hutool.extra.spring.SpringUtil;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
import cn.newfeifan.mall.framework.common.core.KeyValue;
|
|
|
import cn.newfeifan.mall.framework.common.enums.UserTypeEnum;
|
|
|
import cn.newfeifan.mall.framework.common.exception.ErrorCode;
|
|
@@ -33,6 +34,7 @@ import cn.newfeifan.mall.module.distri.service.ptprofitlog.PtProfitLogService;
|
|
|
import cn.newfeifan.mall.module.distri.service.sharepath.SharePathService;
|
|
|
import cn.newfeifan.mall.module.member.api.address.MemberAddressApi;
|
|
|
import cn.newfeifan.mall.module.member.api.address.dto.MemberAddressRespDTO;
|
|
|
+import cn.newfeifan.mall.module.member.dal.dataobject.user.MemberUserDO;
|
|
|
import cn.newfeifan.mall.module.member.service.user.MemberUserService;
|
|
|
import cn.newfeifan.mall.module.pay.api.order.PayOrderApi;
|
|
|
import cn.newfeifan.mall.module.pay.api.order.dto.PayOrderCreateReqDTO;
|
|
@@ -1247,6 +1249,9 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
//20240604 推荐人(上级用户ID)
|
|
|
Long ancesterUserId = tradeOrderMapper.selectAncesterByMemberUserId(memberUserIdOfTradeOrder);
|
|
|
|
|
|
+ // 当前订单用户
|
|
|
+ MemberUserDO user = memberUserService.getUser(memberUserIdOfTradeOrder);
|
|
|
+
|
|
|
for (TradeOrderDO tradeOrderDO : TradeOrderDOList) {
|
|
|
|
|
|
Long tradeOrderId = tradeOrderDO.getId();
|
|
@@ -1353,8 +1358,22 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
//修改购物者本人获得的冻结积分
|
|
|
integralService.updateUserIntegral(tradeOrderDO.getUserId(), tradeOrderDO.getUserId(), CaclEnum.ORDER_PAY_INTEGRAL_CONSUMER, 0L, totalFreezeAmount, tradeOrderId, OrderNum);
|
|
|
|
|
|
- //修改推荐人(上级)获得的冻结积分
|
|
|
- integralService.updateUserIntegral(tradeOrderDO.getUserId(), ancesterUserId, CaclEnum.ORDER_PAY_INTEGRAL_ANCESTER, 0L, totalAncestorFreezeAmount, tradeOrderId, OrderNum);
|
|
|
+ // 如果用户不是游客才会分配直推将,否者是计算到游客收益中的
|
|
|
+ if (!user.getVisitor()) {
|
|
|
+ //修改推荐人(上级)获得的冻结积分
|
|
|
+ integralService.updateUserIntegral(tradeOrderDO.getUserId(), ancesterUserId, CaclEnum.ORDER_PAY_INTEGRAL_ANCESTER, 0L, totalAncestorFreezeAmount, tradeOrderId, OrderNum);
|
|
|
+ } else {
|
|
|
+ // 游客收益
|
|
|
+ PtProfitDO ptProfitDO = ptProfitService.getPtProfit();
|
|
|
+
|
|
|
+ ptProfitDO.setVisitorEarnings(ptProfitDO.getVisitorEarnings() + totalAncestorFreezeAmount);
|
|
|
+ ptProfitDO.setPtTotalAdd(ptProfitDO.getPtTotalAdd() + totalAncestorFreezeAmount);
|
|
|
+ ptProfitService.updatePtProfit(cn.newfeifan.mall.framework.common.util.object.BeanUtils.toBean(ptProfitDO, PtProfitSaveReqVO.class));
|
|
|
+
|
|
|
+ // 记录日志
|
|
|
+ ptProfitLogService.addMessage(user.getId(), null, CaclEnum.RECOMMENDED_PERSON_QUOTA, totalAncestorFreezeAmount,
|
|
|
+ ptProfitDO.getVisitorEarnings(), null, null, JSONUtil.toJsonStr(orderPercentageDO), tradeOrderId, OrderNum);
|
|
|
+ }
|
|
|
|
|
|
//修改购物者本人获得的冻结峰值
|
|
|
integralService.updateIntegralFreezeHighQuota(tradeOrderDO.getUserId(), tradeOrderDO.getUserId(), CaclEnum.ORDER_PAY_FREEZE_HIGH_QUOTA, totalFreezeHighQuota, tradeOrderId, OrderNum);
|
|
@@ -1380,9 +1399,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
rs.add(newSocialStatus);
|
|
|
|
|
|
// 七天获得变为即算即得,后续如果恢复把这里注释即可,并打开平台定时任务得订单结算
|
|
|
-// CompletableFuture.runAsync(() -> {
|
|
|
calc(TradeOrderDOList, orderPercentageDO, JsonUtils.toJsonString(orderPercentageDO));
|
|
|
-// });
|
|
|
|
|
|
return rs;
|
|
|
}
|
|
@@ -1494,6 +1511,17 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
|
|
|
// ========== 修改用户钱包 =================
|
|
|
|
|
|
+ // 每个订单计算的过程
|
|
|
+ // 增加平台收益
|
|
|
+ // 平台服务费
|
|
|
+ PtProfitSaveReqVO ptProfitSaveReqVO =
|
|
|
+ PtProfitSaveReqVO.builder()
|
|
|
+ .ptAdd(platformQuotaInt)
|
|
|
+ .ptGrossAdd(grossProfitAfterBonusInt)
|
|
|
+ .ptTotalAdd(platformQuotaInt + grossProfitAfterBonusInt).build();
|
|
|
+
|
|
|
+ MemberUserDO user = memberUserService.getUser(k.getUserId());
|
|
|
+
|
|
|
//直推奖也要限制额度
|
|
|
Long ancestorHighQuota = integralDOAncestor.getHighQuota() + new BigDecimal(orderPercentageDO.getBaseMaxQuota()).longValue();//加上基础的最大额度值
|
|
|
|
|
@@ -1517,25 +1545,35 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
}
|
|
|
}
|
|
|
changeUserWallet(integralDO, integralDOAncestor, ptIntegral, amount,
|
|
|
- descendantQuotaInt, highQuotaInt, grossProfitAfterBonusInt, platformQuotaInt, ptReplenish);
|
|
|
+ descendantQuotaInt, highQuotaInt, grossProfitAfterBonusInt, platformQuotaInt, ptReplenish, user.getVisitor());
|
|
|
|
|
|
// ========== 修改平台信息 =================
|
|
|
- // 每个订单计算的过程
|
|
|
- // 增加平台收益
|
|
|
- // 平台服务费
|
|
|
- PtProfitSaveReqVO ptProfitSaveReqVO =
|
|
|
- PtProfitSaveReqVO.builder()
|
|
|
- .ptAdd(platformQuotaInt)
|
|
|
- .ptGrossAdd(grossProfitAfterBonusInt)
|
|
|
- .ptTotalAdd(platformQuotaInt + grossProfitAfterBonusInt).build();
|
|
|
+ if (!user.getVisitor()) {
|
|
|
+ // 当直推人获取的积分额度不足时,平台收益要加回来,并生成log
|
|
|
+ if (ptReplenish.compareTo(0L) > 0) {
|
|
|
+ calcIntegral(ptProfitSaveReqVOS, ptProfitSaveReqVO, ptReplenish,
|
|
|
+ k.getId(), k.getNo());
|
|
|
+ }
|
|
|
|
|
|
|
|
|
- // 当直推人获取的积分额度不足时,平台收益要加回来,并生成log
|
|
|
- if (ptReplenish.compareTo(0L) > 0) {
|
|
|
- calcIntegral(ptProfitSaveReqVOS, ptProfitSaveReqVO, ptReplenish,
|
|
|
- k.getId(), k.getNo());
|
|
|
+ // 直推奖记录
|
|
|
+ PtProfitLogSaveReqVO tjrLog = PtProfitLogSaveReqVO.builder()
|
|
|
+ .orderId(k.getId())
|
|
|
+ .profitStatus(CaclEnum.RECOMMENDED_PERSON_QUOTA.getType())
|
|
|
+ .orderNo(k.getNo())
|
|
|
+ .userId(sharePath.getAncestor())
|
|
|
+ .amount(amount)
|
|
|
+ .afterAmount(integralDOAncestor.getCurrentQuota())
|
|
|
+ .freezeAmount(-amount)
|
|
|
+ .afterFreezeAmount(integralDOAncestor.getFreezeQuota())
|
|
|
+ .ancestorQuotaAmount(ptReplenish)
|
|
|
+ .maxAvailablePointsAmount(-amount)
|
|
|
+ .afterMaxAvailablePointsAmount(ancestorHighQuota - amount)
|
|
|
+ .percentTemplate(percentTemplate)
|
|
|
+ .generateUserId(integralDO.getUserId())
|
|
|
+ .build();
|
|
|
+ ptProfitLogSaveReqVOS.add(tjrLog);
|
|
|
}
|
|
|
-
|
|
|
ptProfitSaveReqVOS.add(ptProfitSaveReqVO);
|
|
|
// ========== 增加日志记录 =================
|
|
|
|
|
@@ -1574,24 +1612,6 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
.build();
|
|
|
|
|
|
|
|
|
- // 直推奖记录
|
|
|
- PtProfitLogSaveReqVO tjrLog = PtProfitLogSaveReqVO.builder()
|
|
|
- .orderId(k.getId())
|
|
|
- .profitStatus(CaclEnum.RECOMMENDED_PERSON_QUOTA.getType())
|
|
|
- .orderNo(k.getNo())
|
|
|
- .userId(sharePath.getAncestor())
|
|
|
- .amount(amount)
|
|
|
- .afterAmount(integralDOAncestor.getCurrentQuota())
|
|
|
- .freezeAmount(-amount)
|
|
|
- .afterFreezeAmount(integralDOAncestor.getFreezeQuota())
|
|
|
- .ancestorQuotaAmount(ptReplenish)
|
|
|
- .maxAvailablePointsAmount(-amount)
|
|
|
- .afterMaxAvailablePointsAmount(ancestorHighQuota - amount)
|
|
|
- .percentTemplate(percentTemplate)
|
|
|
- .generateUserId(integralDO.getUserId())
|
|
|
- .build();
|
|
|
-
|
|
|
-
|
|
|
// 用户自得记录 + 户冻结积分转化成可用 + 扣减最高可用额度记录
|
|
|
PtProfitLogSaveReqVO ztrLog = PtProfitLogSaveReqVO.builder()
|
|
|
.orderId(k.getId())
|
|
@@ -1613,7 +1633,6 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
ptProfitLogSaveReqVOS.add(ptTotal);
|
|
|
ptProfitLogSaveReqVOS.add(ptGrossAddLog);
|
|
|
ptProfitLogSaveReqVOS.add(ptAddLog);
|
|
|
- ptProfitLogSaveReqVOS.add(tjrLog);
|
|
|
ptProfitLogSaveReqVOS.add(ztrLog);
|
|
|
|
|
|
|
|
@@ -1667,9 +1686,10 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
* @param ptA pt收益
|
|
|
* @param ptB pt服务费
|
|
|
* @param ptReplenish 超出没有获取到的积分
|
|
|
+ * @param visitor 游客标识
|
|
|
*/
|
|
|
private void changeUserWallet(IntegralDO integralDO, IntegralDO integralDOAncestor, IntegralDO pt,
|
|
|
- Long ancestorQuota, Long descendantQuota, Long highQuota, Long ptA, Long ptB, Long ptReplenish) {
|
|
|
+ Long ancestorQuota, Long descendantQuota, Long highQuota, Long ptA, Long ptB, Long ptReplenish, Boolean visitor) {
|
|
|
// 修改用户钱包
|
|
|
// 增加直推人额度
|
|
|
integralDO.setHighQuota(integralDO.getHighQuota() + highQuota);
|
|
@@ -1679,13 +1699,17 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
|
|
|
integralDO.setCurrentQuota(integralDO.getCurrentQuota() + descendantQuota);
|
|
|
integralDO.setFreezeQuota(integralDO.getFreezeQuota() - descendantQuota);
|
|
|
- // 增加推荐人额度
|
|
|
- integralDOAncestor.setCurrentQuota(integralDOAncestor.getCurrentQuota() + ancestorQuota);
|
|
|
- // 减少推荐人的可获取额度
|
|
|
- integralDOAncestor.setHighQuota(integralDOAncestor.getHighQuota() - ancestorQuota);
|
|
|
- integralDOAncestor.setAncestorQuota(integralDOAncestor.getAncestorQuota() + ancestorQuota);
|
|
|
- integralDOAncestor.setFreezeQuota(integralDOAncestor.getFreezeQuota() - ancestorQuota - ptReplenish);
|
|
|
- integralService.updateIntegral(cn.newfeifan.mall.framework.common.util.object.BeanUtils.toBean(integralDOAncestor, IntegralSaveReqVO.class));
|
|
|
+
|
|
|
+ // 如果直推人是游客就没有直推奖
|
|
|
+ if (!visitor) {
|
|
|
+ // 增加推荐人额度
|
|
|
+ integralDOAncestor.setCurrentQuota(integralDOAncestor.getCurrentQuota() + ancestorQuota);
|
|
|
+ // 减少推荐人的可获取额度
|
|
|
+ integralDOAncestor.setHighQuota(integralDOAncestor.getHighQuota() - ancestorQuota);
|
|
|
+ integralDOAncestor.setAncestorQuota(integralDOAncestor.getAncestorQuota() + ancestorQuota);
|
|
|
+ integralDOAncestor.setFreezeQuota(integralDOAncestor.getFreezeQuota() - ancestorQuota - ptReplenish);
|
|
|
+ integralService.updateIntegral(cn.newfeifan.mall.framework.common.util.object.BeanUtils.toBean(integralDOAncestor, IntegralSaveReqVO.class));
|
|
|
+ }
|
|
|
|
|
|
// 增加平台额度
|
|
|
pt.setCurrentQuota(pt.getCurrentQuota() + ptA + ptB);
|
|
@@ -1748,7 +1772,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
/**
|
|
|
* 发送极光推送消息
|
|
|
*
|
|
|
- * @param order 订单
|
|
|
+ * @param order 订单
|
|
|
*/
|
|
|
private void sentJPush(TradeOrderDO order) {
|
|
|
String title = WcChatMessageTemplateIdEnum.ORDER_NO_DELIVERY2.getName();
|
|
@@ -1773,7 +1797,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
for (Long adminUser : adminUsers) {
|
|
|
// 如果没有权限就不用发送了
|
|
|
Boolean havePermission = jPushUtils.isHavePermission(adminUser, title);
|
|
|
- if(!havePermission){
|
|
|
+ if (!havePermission) {
|
|
|
continue;
|
|
|
}
|
|
|
List<String> userRsgIds = memberUserService.getUserRsgIds(adminUser, null);
|
|
@@ -2025,7 +2049,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
integralService.updateUserIntegral(userId, userId, CaclEnum.ORDER_CANCEL_BY_USER_REFUND_INTEGRAL, payIntegral, 0L, tradeOrderId, orderNum);
|
|
|
}
|
|
|
|
|
|
- if(order.getPayConsumptionPoints() > 0){
|
|
|
+ if (order.getPayConsumptionPoints() > 0) {
|
|
|
integralService.updateUserConsumptionPoints(userId, ConsumptionEnum.CANCEL_ORDER_BACK_CONSUMPTION_POINTS, order.getPayConsumptionPoints(), tradeOrderId, orderNum);
|
|
|
}
|
|
|
}
|
|
@@ -2061,7 +2085,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
if (payIntegral > 0) {
|
|
|
integralService.updateUserIntegral(userId, CaclEnum.ORDER_CANCEL_BY_SYSTEM_REFUND_INTEGRAL, payIntegral, tradeOrderId, orderNum);
|
|
|
}
|
|
|
- if(order.getPayConsumptionPoints() > 0){
|
|
|
+ if (order.getPayConsumptionPoints() > 0) {
|
|
|
integralService.updateUserConsumptionPoints(userId, ConsumptionEnum.ORDER_CANCEL_BY_SYSTEM_REFUND_INTEGRAL, order.getPayConsumptionPoints(), tradeOrderId, orderNum);
|
|
|
}
|
|
|
|
|
@@ -2155,8 +2179,10 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
if (ObjectUtil.notEqual(order.getStatus(), TradeOrderStatusEnum.CANCELED.getStatus())) {
|
|
|
throw exception(ORDER_DELETE_FAIL_STATUS_NOT_CANCEL);
|
|
|
}
|
|
|
+ // 用户删除作为给用户看的订单
|
|
|
+ order.setUserDeleted(true);
|
|
|
// 2. 删除订单
|
|
|
- tradeOrderMapper.deleteById(id);
|
|
|
+ tradeOrderMapper.updateById(order);
|
|
|
|
|
|
// 3. 记录日志
|
|
|
TradeOrderLogUtils.setOrderInfo(order.getId(), order.getStatus(), order.getStatus());
|