chunping il y a 3 ans
Parent
commit
1d81ce9ec2

+ 1 - 1
mp-admin/src/main/java/com/qs/mp/web/controller/api/user/UserMineController.java

@@ -137,7 +137,7 @@ public class UserMineController extends BaseApiController {
             .select("IFNULL(goods_num,0) as total")
             .eq("user_id", userId).eq("status", PrizeStorageStatusEnum.NOT_DISTRIBUTED));
     JSONObject result = new JSONObject();
-    result.put("prizeNum", Integer.valueOf(String.valueOf(storageMap.get("total"))));
+    result.put("prizeNum", Integer.valueOf(String.valueOf(null != storageMap ? storageMap.get("total") : 0)));
 
     int ticketNum = userTicketOrderItemService.countMyTicket(userId, TicketStatusEnum.ACTIVATED);
     result.put("ticketNum", ticketNum);

+ 7 - 4
mp-service/src/main/java/com/qs/mp/channel/service/impl/ChannelMoneyLogServiceImpl.java

@@ -17,6 +17,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.Assert;
 
 /**
@@ -36,11 +37,12 @@ public class ChannelMoneyLogServiceImpl extends ServiceImpl<ChannelMoneyLogMappe
   private IChannelService channelService;
 
   @Override
+  @Transactional
   public boolean changeMoney(ChannelMoneyLog moneyLog) {
     //查询数据更新对象,用户做脏读乐观锁版本标识别
     Channel channel = channelService.getById(moneyLog.getChannelId());
 
-    boolean income = checkIncome(moneyLog.getRefType());
+    boolean income = checkIncome(moneyLog.getType());
     int money = 0;
     if (!income) {
       //根据收支方向,将金额转负,方便统一计算
@@ -77,11 +79,12 @@ public class ChannelMoneyLogServiceImpl extends ServiceImpl<ChannelMoneyLogMappe
     return true;
   }
 
-  private boolean checkIncome(ChannelMoneyBizTypeEnum refType){
+  private boolean checkIncome(ChannelMoneyEnum bizType){
     //判断收支类型是否符合预定义类型
-    if(ChannelMoneyBizTypeEnum.COMMISSION == refType){
+    if(ChannelMoneyEnum.COMMISSION == bizType){
       return true;
-    }else if(ChannelMoneyBizTypeEnum.WITHDRAW == refType){
+    }else if(ChannelMoneyEnum.WITHDRAW == bizType || ChannelMoneyEnum.WITHDRAW_FEE == bizType
+    || ChannelMoneyEnum.PURCHASE == bizType ){
       return false;
     } else {
       throw new DataOperationException(ErrorCodeEnum.ERROR_CODE_1007);

+ 30 - 2
mp-service/src/main/java/com/qs/mp/channel/service/impl/ChannelWithdrawServiceImpl.java

@@ -4,12 +4,17 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.qs.mp.channel.domain.Channel;
 import com.qs.mp.channel.domain.ChannelBankCard;
+import com.qs.mp.channel.domain.ChannelMoneyLog;
 import com.qs.mp.channel.domain.ChannelWithdraw;
 import com.qs.mp.channel.mapper.ChannelWithdrawMapper;
 import com.qs.mp.channel.service.IChannelBankCardService;
+import com.qs.mp.channel.service.IChannelMoneyLogService;
 import com.qs.mp.channel.service.IChannelService;
 import com.qs.mp.channel.service.IChannelWithdrawService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.qs.mp.common.enums.ChannelMoneyBizTypeEnum;
+import com.qs.mp.common.enums.ChannelMoneyEnum;
+import java.util.Date;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -31,6 +36,9 @@ public class ChannelWithdrawServiceImpl extends ServiceImpl<ChannelWithdrawMappe
   @Autowired
   private IChannelService channelService;
 
+  @Autowired
+  private IChannelMoneyLogService channelMoneyLogService;
+
   @Override
   @Transactional
   public boolean apply(Channel channel, ChannelWithdraw channelWithdraw) {
@@ -51,14 +59,34 @@ public class ChannelWithdrawServiceImpl extends ServiceImpl<ChannelWithdrawMappe
       bankCard.setUserName(channelWithdraw.getUserName());
       channelBankCardService.updateById(bankCard);
     }
-
+    boolean rst = save(channelWithdraw);
     // 冻结账户余额,乐观锁
     channelService.update(new LambdaUpdateWrapper<Channel>()
         .set(Channel::getFrozenMoney, channel.getFrozenMoney() + channelWithdraw.getMoney())
         .set(Channel::getMoney, channel.getMoney() - channelWithdraw.getMoney())
         .eq(Channel::getChannelId, channel.getChannelId()).eq(Channel::getMoney, channel.getMoney()));
 
+    ChannelMoneyLog moneyLog = new ChannelMoneyLog();
+    moneyLog.setChannelId(channel.getChannelId());
+    moneyLog.setType(ChannelMoneyEnum.WITHDRAW);
+    moneyLog.setLogMoney(channelWithdraw.getMoney());
+    moneyLog.setBizTime(new Date());
+    moneyLog.setRefType(ChannelMoneyBizTypeEnum.WITHDRAW);
+    moneyLog.setRefId(String.valueOf(channelWithdraw.getId()));
+    channelMoneyLogService.changeMoney(moneyLog);
+
+    if (channelWithdraw.getChargeAmt() > 0) {
+      // 手续费
+      ChannelMoneyLog feeMoneyLog = new ChannelMoneyLog();
+      feeMoneyLog.setChannelId(channel.getChannelId());
+      feeMoneyLog.setType(ChannelMoneyEnum.WITHDRAW_FEE);
+      feeMoneyLog.setLogMoney(channelWithdraw.getChargeAmt());
+      feeMoneyLog.setBizTime(new Date());
+      feeMoneyLog.setRefType(ChannelMoneyBizTypeEnum.WITHDRAW);
+      feeMoneyLog.setRefId(String.valueOf(channelWithdraw.getId()));
+      channelMoneyLogService.changeMoney(moneyLog);
+    }
     // 创建提现记录
-    return save(channelWithdraw);
+    return rst;
   }
 }