This commit is contained in:
zengtao01
2024-10-09 18:22:27 +08:00
parent 833a83cc13
commit 2ae099b572
13 changed files with 55 additions and 26 deletions

View File

@ -9,5 +9,5 @@ import java.math.BigDecimal;
*/
public interface CardApi {
Boolean recharge(BigDecimal money);
Boolean recharge(BigDecimal money,Long userId);
}

View File

@ -24,13 +24,14 @@ public class CardApiImpl implements CardApi{
@Override
public Boolean recharge(BigDecimal money){
public Boolean recharge(BigDecimal money,Long userId){
money = money.divide(new BigDecimal("100"));
RechargeAmountDO recharge = rechargeAmountService.getRecharge(money);
BigDecimal giftMoney = BigDecimal.ZERO;
if(ObjectUtil.isNotEmpty(recharge.getDonateMoney())){
giftMoney = giftMoney.add(recharge.getDonateMoney());
}
money = money.divide(new BigDecimal("100"));
return cardService.recharge(money, CardDO.ADD,giftMoney);
return cardService.recharge(money, CardDO.ADD,giftMoney,userId);
}
}

View File

@ -6,6 +6,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.module.member.controller.admin.card.vo.CardPageReqVO;
import cn.iocoder.yudao.module.member.controller.admin.card.vo.CardRespVO;
import cn.iocoder.yudao.module.member.controller.admin.card.vo.CardSaveReqVO;
@ -144,7 +145,7 @@ public class CardController {
@Operation(summary = "充值")
//@PreAuthorize("@ss.hasPermission('member:card:update')")
public CommonResult<Boolean> recharge(BigDecimal money,BigDecimal giftMoney) {
return success(cardService.recharge(money, CardDO.ADD,giftMoney));
return success(cardService.recharge(money, CardDO.ADD,giftMoney, SecurityFrameworkUtils.getLoginUserId()));
}
@GetMapping("/getMoney")

View File

@ -28,9 +28,10 @@ import java.math.BigDecimal;
@AllArgsConstructor
public class DishOrderDO extends BaseDO {
public final static String COMPLETE = "1";
public final static String INCOMPLETE = "0";
public final static String TOCOMPLETE = "2";
public final static String COMPLETE = "1"; //完成
public final static String INCOMPLETE = "0"; //未完成
public final static String TOCOMPLETE = "2"; //未支付
public final static String LOSE_EFFICACY = "3"; //已失效
/**

View File

@ -150,6 +150,12 @@ public class BalanceDeductionJob implements JobHandler {
cardDO.setChangeMoney(total);
cardDO.setFlag(CardDO.MINUS);
cardService.insertOne(cardDO);
String redisData = stringRedisTemplate.opsForValue().get("DATA-money"+ userId);
if(StrUtil.isNotBlank(redisData)){
stringRedisTemplate.opsForValue().set("DATA-money"+userId, cardDO.getMoney().toString());
}
list.add(cardDO);
dishOrderDO.setTotalMoney(total);

View File

@ -69,7 +69,7 @@ public interface CardService {
/**
* 余额变动
*/
Boolean recharge(BigDecimal money, String flag,BigDecimal giftMoney);
Boolean recharge(BigDecimal money, String flag,BigDecimal giftMoney,Long userId);
/**
* 获取余额

View File

@ -123,11 +123,11 @@ public class CardServiceImpl implements CardService {
@Override
public Boolean recharge(BigDecimal money, String flag, BigDecimal giftMoney) {
public Boolean recharge(BigDecimal money, String flag, BigDecimal giftMoney,Long userId) {
//获取最新余额
CardDO lastCardDO = getLastCardDO();
CardDO cardDO = new CardDO();
cardDO.setUserId(SecurityFrameworkUtils.getLoginUserId());
cardDO.setUserId(userId);
cardDO.setFlag(flag);
cardDO.setChangeMoney(money);
cardDO.setType(CostTypeEnum.WX_PAY.getCode());

View File

@ -41,6 +41,7 @@ import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
@ -288,15 +289,30 @@ public class DiningPlatesServiceImpl implements DiningPlatesService {
if (diningPlatesDO == null || diningPlatesDO.getUserId() == null) {
throw exception(DINING_PLATES_NOT_BIND);
}
//刷新绑定时间
diningPlatesDO.setBindingTime(LocalDateTime.now());
diningPlatesMapper.updateById(diningPlatesDO);
AppUserInfoCardVO appUserInfoCardVO = new AppUserInfoCardVO();
String name = stringRedisTemplate.opsForValue().get("DATA-name" + diningPlatesDO.getUserId());
String money = stringRedisTemplate.opsForValue().get("DATA-money" + diningPlatesDO.getUserId());
if(StrUtil.isNotBlank(name)&& StrUtil.isNotBlank(money)){
appUserInfoCardVO.setName(name);
appUserInfoCardVO.setMoney(new BigDecimal(money));
return appUserInfoCardVO;
}
MemberUserDO memberUserDO = memberUserMapper.selectById(diningPlatesDO.getUserId());
AppUserInfoCardVO data = new AppUserInfoCardVO();
data.setName(memberUserDO.getNickname());
data.setMoney(cardService.getMoneyByUserId(memberUserDO.getId()));
return data;
stringRedisTemplate.opsForValue().set("DATA-name"+diningPlatesDO.getUserId(), memberUserDO.getNickname());
stringRedisTemplate.opsForValue().set("DATA-money"+diningPlatesDO.getUserId(), cardService.getMoneyByUserId(memberUserDO.getId()).toString());
//刷新绑定时间
CompletableFuture.supplyAsync(() -> {
int i = 0;
try {
// 模拟耗时操作,这里可以替换为实际的代码逻辑
diningPlatesDO.setBindingTime(LocalDateTime.now());
i = diningPlatesMapper.updateById(diningPlatesDO);
} catch (Exception e) {
e.printStackTrace();
}
return i>0;
});
return appUserInfoCardVO;
}
public void checkDiningPlates(DiningPlatesDO diningPlatesDO) {

View File

@ -458,9 +458,9 @@ public class OrderServiceImpl implements OrderService {
BigDecimal oldCashAmount = lastCardDO.getCashAmount();
BigDecimal oldGiftAmount = lastCardDO.getGiftAmount();
cardDO.setGiftAmount(oldWxAmount.add(wxAmount));
cardDO.setWxAmount(oldCashAmount.add(cashAmount));
cardDO.setWxAmount(oldGiftAmount.add(giftAmount));
cardDO.setWxAmount(oldWxAmount.add(wxAmount));
cardDO.setCashAmount(oldCashAmount.add(cashAmount));
cardDO.setGiftAmount(oldGiftAmount.add(giftAmount));
cardMapper.insert(cardDO);
}else{

View File

@ -109,7 +109,9 @@ public class PayNotifyController {
String re = notifyRedisTemplate.opsForValue().get("ADD" + notify.getOutTradeNo());
if(StringUtils.isNotBlank(re)){
log.info("开始进行余额增加,获取的金额:"+re);
cardApi.recharge(new BigDecimal(re));
int index = re.indexOf("-");
String userId = re.substring(index + 1);
cardApi.recharge(new BigDecimal(re.substring(0,index)),Long.valueOf(userId));
notifyRedisTemplate.delete("ADD" + notify.getOutTradeNo());
}
return "success";

View File

@ -50,6 +50,7 @@ import java.util.Objects;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.json.JsonUtils.toJsonString;
import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.getLoginUserId;
import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.*;
/**
@ -174,7 +175,8 @@ public class PayOrderServiceImpl implements PayOrderService {
// 订单相关字段
.setPrice(order.getPrice()).setExpireTime(order.getExpireTime());
PayOrderRespDTO unifiedOrderResp = client.unifiedOrder(unifiedOrderReqDTO);
payRedis.opsForValue().set("ADD"+unifiedOrderReqDTO.getOutTradeNo(),unifiedOrderReqDTO.getPrice().toString());
payRedis.opsForValue().set("ADD"+unifiedOrderReqDTO.getOutTradeNo()
,unifiedOrderReqDTO.getPrice().toString()+"-"+getLoginUserId());
log.info("REDISID:"+"ADD"+unifiedOrderReqDTO.getOutTradeNo()+" 总金额:"+unifiedOrderReqDTO.getPrice().toString());
// 4. 如果调用直接支付成功,则直接更新支付单状态为成功。例如说:付款码支付,免密支付时,就直接验证支付成功
if (unifiedOrderResp != null) {