|
@@ -1,8 +1,84 @@
|
|
package com.zhongshu.reward.server.core.service.Impl;
|
|
package com.zhongshu.reward.server.core.service.Impl;
|
|
|
|
|
|
|
|
+import com.zhongshu.reward.client.model.param.GoodsReceiptsParam;
|
|
|
|
+import com.zhongshu.reward.client.ret.ResultContent;
|
|
|
|
+import com.zhongshu.reward.client.ret.ResultState;
|
|
|
|
+import com.zhongshu.reward.client.type.ReceiptsStatus;
|
|
|
|
+import com.zhongshu.reward.client.type.ReceiptsType;
|
|
|
|
+import com.zhongshu.reward.server.core.dao.WalletDao;
|
|
|
|
+import com.zhongshu.reward.server.core.dao.WalletReceiptsDao;
|
|
|
|
+import com.zhongshu.reward.server.core.domain.Wallet;
|
|
|
|
+import com.zhongshu.reward.server.core.domain.WalletReceipts;
|
|
|
|
+import com.zhongshu.reward.server.core.service.WalletService;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+
|
|
|
|
+import java.util.Date;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* @author wjf
|
|
* @author wjf
|
|
* @date 2024/8/5
|
|
* @date 2024/8/5
|
|
*/
|
|
*/
|
|
|
|
+@Service
|
|
public class WalletFeignServiceImpl {
|
|
public class WalletFeignServiceImpl {
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ WalletReceiptsDao walletReceiptsDao;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ WalletDao walletDao;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ WalletService walletService;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ public ResultContent<String> addWait(GoodsReceiptsParam param) {
|
|
|
|
+ Wallet wallet = walletService.getWalletByUserId(param.getUserId());
|
|
|
|
+
|
|
|
|
+ WalletReceipts walletReceipts = new WalletReceipts();
|
|
|
|
+ walletReceipts.setWallet(wallet);
|
|
|
|
+ walletReceipts.setEstimatedTime(param.getEstimatedTime());
|
|
|
|
+ walletReceipts.setReceiptsType(ReceiptsType.REBATE);
|
|
|
|
+ walletReceipts.setTotal(param.getTotal());
|
|
|
|
+ walletReceipts.setStatus(ReceiptsStatus.WAIT);
|
|
|
|
+ walletReceipts.setOutTradeNo(param.getOutTradeNo());
|
|
|
|
+ walletReceipts.setAttach(param.getAttach());
|
|
|
|
+
|
|
|
|
+ walletReceiptsDao.save(walletReceipts);
|
|
|
|
+ wallet.setWaitAmount(wallet.getWaitAmount().add(param.getTotal()));
|
|
|
|
+ walletDao.save(wallet);
|
|
|
|
+
|
|
|
|
+ return ResultContent.buildContent(walletReceipts.getId());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public ResultContent cancel(String outTradeNo) {
|
|
|
|
+ WalletReceipts walletReceipts = walletReceiptsDao.findTopByOutTradeNo(outTradeNo);
|
|
|
|
+
|
|
|
|
+ if (!walletReceipts.getStatus().equals(ReceiptsStatus.WAIT)){
|
|
|
|
+ return ResultContent.build(ResultState.Fail, "只有即将到账的入帐单可以取消");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ walletReceipts.setReceiptsTime(new Date().getTime());
|
|
|
|
+ walletReceipts.setStatus(ReceiptsStatus.RECEIPTS);
|
|
|
|
+ walletReceiptsDao.save(walletReceipts);
|
|
|
|
+
|
|
|
|
+ Wallet wallet = walletDao.findTop1ById(walletReceipts.getWallet().getId());
|
|
|
|
+ wallet.setAmount(wallet.getAmount().add(walletReceipts.getTotal()));
|
|
|
|
+ wallet.setWaitAmount(wallet.getWaitAmount().subtract(walletReceipts.getTotal()));
|
|
|
|
+ walletDao.save(wallet);
|
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public ResultContent receipts(String outTradeNo) {
|
|
|
|
+ WalletReceipts walletReceipts = walletReceiptsDao.findTopByOutTradeNo(outTradeNo);
|
|
|
|
+ walletReceipts.setReceiptsTime(new Date().getTime());
|
|
|
|
+ walletReceipts.setStatus(ReceiptsStatus.RECEIPTS);
|
|
|
|
+ walletReceiptsDao.save(walletReceipts);
|
|
|
|
+
|
|
|
|
+ Wallet wallet = walletDao.findTop1ById(walletReceipts.getWallet().getId());
|
|
|
|
+ wallet.setAmount(wallet.getAmount().add(walletReceipts.getTotal()));
|
|
|
|
+ wallet.setWaitAmount(wallet.getWaitAmount().subtract(walletReceipts.getTotal()));
|
|
|
|
+ walletDao.save(wallet);
|
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
|
+ }
|
|
}
|
|
}
|