TRX il y a 1 an
Parent
commit
c90e72e596

+ 3 - 0
FullCardClient/src/main/java/com/zhongshu/card/client/model/payment/WalletRechargeModel.java

@@ -20,6 +20,9 @@ public class WalletRechargeModel extends SuperModel {
     @Schema(description = "关联钱包信息")
     private WalletModel wallet;
 
+    @Schema(description = "用户userId")
+    private String userId;
+
     @Schema(description = "充值类型:")
     private RechargeType rechargeType;
 

+ 16 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/base/SuperService.java

@@ -160,4 +160,20 @@ public abstract class SuperService {
             param.setEndTime(endTime);
         }
     }
+
+    public void initOidSearchParamNoTip(SuperSearch param) {
+        String oid = param.getOid();
+        if (StringUtils.isEmpty(oid)) {
+            param.setOid(getCurrentOid());
+        }
+        List<Long> times = param.getTimes();
+        if (ObjectUtils.isNotEmpty(times) && times.size() == 2) {
+            Long startTime = times.get(0);
+            startTime = DateUtils.getDayStartTime(startTime);
+            Long endTime = times.get(1);
+            endTime = DateUtils.getDayEndTime(endTime);
+            param.setStartTime(startTime);
+            param.setEndTime(endTime);
+        }
+    }
 }

+ 124 - 2
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/payment/WalletService.java

@@ -1,14 +1,34 @@
 package com.zhongshu.card.server.core.service.payment;
 
+import com.github.microservice.components.data.base.util.PageEntityUtil;
+import com.zhongshu.card.client.model.payment.WalletModel;
+import com.zhongshu.card.client.model.payment.WalletRechargeModel;
+import com.zhongshu.card.client.model.payment.WalletRechargeSearch;
+import com.zhongshu.card.client.model.school.BookInfoModel;
+import com.zhongshu.card.client.model.school.BookInfoSearch;
 import com.zhongshu.card.client.ret.ResultContent;
+import com.zhongshu.card.client.service.org.UserAccountService;
+import com.zhongshu.card.client.utils.type.DataState;
 import com.zhongshu.card.server.core.dao.org.UserCountDao;
 import com.zhongshu.card.server.core.dao.payment.WalletDao;
 import com.zhongshu.card.server.core.dao.payment.WalletRechargeDao;
+import com.zhongshu.card.server.core.domain.org.UserAccount;
+import com.zhongshu.card.server.core.domain.payment.Wallet;
+import com.zhongshu.card.server.core.domain.payment.WalletRecharge;
+import com.zhongshu.card.server.core.domain.school.BookInfo;
 import com.zhongshu.card.server.core.service.base.SuperService;
+import com.zhongshu.card.server.core.service.org.UserAccountServiceImpl;
+import com.zhongshu.card.server.core.util.BeanUtils;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.ObjectUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
 import org.springframework.stereotype.Service;
 
+import java.math.BigDecimal;
+
 /**
  * @author TRX
  * @date 2024/6/29
@@ -26,14 +46,116 @@ public class WalletService extends SuperService {
     @Autowired
     UserCountDao userCountDao;
 
+    @Autowired
+    UserAccountServiceImpl userAccountService;
+
+    /**
+     * 初始当前用户钱包
+     *
+     * @return
+     */
+    public ResultContent<Wallet> initCurrentUserWallet() {
+        String userId = getCurrentUserId();
+        return initUserWallet(userId);
+    }
+
     /**
      * 初始用户钱包
      *
      * @param userId
      * @return
      */
-    public ResultContent initUserWallet(String userId) {
+    public ResultContent<Wallet> initUserWallet(String userId) {
+        if (StringUtils.isEmpty(userId)) {
+            return ResultContent.buildFail("userId不能为空");
+        }
+        UserAccount userAccount = userCountDao.findTopByUserId(userId);
+        if (ObjectUtils.isEmpty(userAccount)) {
+            return ResultContent.buildFail(String.format("用户不存在:%s", userId));
+        }
+        Wallet wallet = walletDao.findByUserId(userId);
+        if (ObjectUtils.isEmpty(wallet)) {
+            wallet = new Wallet();
+            wallet.setAmount(BigDecimal.ZERO);
+            wallet.setUserId(userId);
+            wallet.setUserAccount(userAccount);
+            wallet.setDataState(DataState.Enable);
+            walletDao.save(wallet);
+        }
+        return ResultContent.buildSuccess(wallet);
+    }
+
+    /**
+     * 通过用户userId得到钱包
+     *
+     * @param userId
+     * @return
+     */
+    public Wallet getUserWalletByUserId(String userId) {
+        Wallet wallet = walletDao.findByUserId(userId);
+        if (ObjectUtils.isEmpty(wallet)) {
+            ResultContent<Wallet> resultContent = initUserWallet(userId);
+            if (resultContent.isSuccess()) {
+                wallet = resultContent.getContent();
+            }
+        }
+        return wallet;
+    }
+
+
+    /**
+     * 得到用户钱包信息
+     *
+     * @param userId
+     * @return
+     */
+    public ResultContent<WalletModel> getUserWallet(String userId) {
+        Wallet wallet = walletDao.findByUserId(userId);
+        if (ObjectUtils.isEmpty(wallet)) {
+            ResultContent<Wallet> resultContent = initUserWallet(userId);
+            if (resultContent.isFailed()) {
+                return ResultContent.buildFail(resultContent.getMsg());
+            }
+            wallet = resultContent.getContent();
+        }
+        return ResultContent.buildSuccess(toModel(wallet));
+    }
+
+    //---------------------------充值 start------------------------
 
-        return ResultContent.buildSuccess();
+    /**
+     * 充值列表
+     *
+     * @param param
+     * @param pageable
+     * @return
+     */
+    public ResultContent<Page<WalletRechargeModel>> page(WalletRechargeSearch param, Pageable pageable) {
+        initOidSearchParamNoTip(param);
+        Page<WalletRecharge> page = walletRechargeDao.page(pageable, param);
+        return ResultContent.buildSuccess(PageEntityUtil.concurrent2PageModel(page, this::toModel));
     }
+
+
+
+    //---------------------------充值 end--------------------------
+
+    public WalletModel toModel(Wallet entity) {
+        WalletModel model = null;
+        if (ObjectUtils.isNotEmpty(entity)) {
+            model = new WalletModel();
+            BeanUtils.copyProperties(entity, model);
+        }
+        return model;
+    }
+
+    public WalletRechargeModel toModel(WalletRecharge entity) {
+        WalletRechargeModel model = null;
+        if (ObjectUtils.isNotEmpty(entity)) {
+            model = new WalletRechargeModel();
+            BeanUtils.copyProperties(entity, model);
+        }
+        return model;
+    }
+
 }