|
@@ -1,14 +1,34 @@
|
|
|
package com.zhongshu.card.server.core.service.payment;
|
|
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.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.org.UserCountDao;
|
|
|
import com.zhongshu.card.server.core.dao.payment.WalletDao;
|
|
import com.zhongshu.card.server.core.dao.payment.WalletDao;
|
|
|
import com.zhongshu.card.server.core.dao.payment.WalletRechargeDao;
|
|
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.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 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.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
|
|
+import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* @author TRX
|
|
* @author TRX
|
|
|
* @date 2024/6/29
|
|
* @date 2024/6/29
|
|
@@ -26,14 +46,116 @@ public class WalletService extends SuperService {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
UserCountDao userCountDao;
|
|
UserCountDao userCountDao;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ UserAccountServiceImpl userAccountService;
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 初始当前用户钱包
|
|
|
|
|
+ *
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public ResultContent<Wallet> initCurrentUserWallet() {
|
|
|
|
|
+ String userId = getCurrentUserId();
|
|
|
|
|
+ return initUserWallet(userId);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 初始用户钱包
|
|
* 初始用户钱包
|
|
|
*
|
|
*
|
|
|
* @param userId
|
|
* @param userId
|
|
|
* @return
|
|
* @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;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|