|
|
@@ -4,6 +4,7 @@ import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyV3Result;
|
|
|
import com.ylx.common.core.domain.model.WxLoginUser;
|
|
|
import com.ylx.common.exception.ServiceException;
|
|
|
import com.ylx.common.utils.DateUtils;
|
|
|
@@ -13,7 +14,11 @@ import com.ylx.giftCard.enums.GiftCardOrderStatusEnum;
|
|
|
import com.ylx.giftCard.mapper.GiftCardOrderMapper;
|
|
|
import com.ylx.giftCard.service.IGiftCardOrderService;
|
|
|
import com.ylx.massage.domain.TJs;
|
|
|
+import com.ylx.massage.domain.TWxUser;
|
|
|
import com.ylx.massage.service.TJsService;
|
|
|
+import com.ylx.massage.service.TWxUserService;
|
|
|
+import com.ylx.shopingfundsdetail.domain.vo.ShoppingFundsDetailAddDto;
|
|
|
+import com.ylx.shopingfundsdetail.service.ShoppingFundsDetailService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
@@ -28,6 +33,10 @@ public class GiftCardOrderServiceImpl extends ServiceImpl<GiftCardOrderMapper, G
|
|
|
|
|
|
@Resource
|
|
|
private TJsService jsService;
|
|
|
+ @Resource
|
|
|
+ private TWxUserService wxUserService;
|
|
|
+ @Resource
|
|
|
+ private ShoppingFundsDetailService shoppingFundsDetailService;
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@@ -96,6 +105,38 @@ public class GiftCardOrderServiceImpl extends ServiceImpl<GiftCardOrderMapper, G
|
|
|
log.info("订单取消成功,订单号:{},购物卡ID:{}", order.getOrderNo(), order.getGiftCardId());
|
|
|
}
|
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void processGiftCardPayment(WxPayOrderNotifyV3Result.DecryptNotifyResult result, TWxUser wxUser,GiftCardOrder cardOrder) {
|
|
|
+
|
|
|
+ // 更新订单状态
|
|
|
+ this.lambdaUpdate()
|
|
|
+ .set(GiftCardOrder::getStatus, GiftCardOrderStatusEnum.PAID.getCode())
|
|
|
+ .eq(GiftCardOrder::getId, cardOrder.getId())
|
|
|
+ .update();
|
|
|
+
|
|
|
+ // 计算充值金额
|
|
|
+ Integer totalCent = result.getAmount().getTotal();
|
|
|
+ BigDecimal payAmount = new BigDecimal(totalCent).divide(BigDecimal.valueOf(100), 2, BigDecimal.ROUND_HALF_UP);
|
|
|
+
|
|
|
+ // 更新用户余额
|
|
|
+ BigDecimal oldBalance = wxUser.getdBalance();
|
|
|
+ BigDecimal newBalance = oldBalance.add(payAmount);
|
|
|
+ this.wxUserService.lambdaUpdate()
|
|
|
+ .set(TWxUser::getdBalance, newBalance)
|
|
|
+ .eq(TWxUser::getId, wxUser.getId())
|
|
|
+ .update();
|
|
|
+
|
|
|
+ // 记录购物金明细
|
|
|
+ ShoppingFundsDetailAddDto dto = new ShoppingFundsDetailAddDto();
|
|
|
+ dto.setUserId(wxUser.getId());
|
|
|
+ dto.setAmount(payAmount);
|
|
|
+ dto.setOrderNo(result.getOutTradeNo());
|
|
|
+ dto.setExpenseType(0); // 充值
|
|
|
+ dto.setBalance(newBalance);
|
|
|
+ dto.setGiftCardId(cardOrder.getGiftCardId());
|
|
|
+ shoppingFundsDetailService.addShoppingFundsDetail(dto);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 生成唯一订单号
|
|
|
*/
|