|
@@ -3,6 +3,7 @@ package com.fs.hisStore.service.impl;
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
|
|
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.time.ZoneId;
|
|
import java.time.ZoneId;
|
|
|
import java.time.ZonedDateTime;
|
|
import java.time.ZonedDateTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.time.format.DateTimeFormatter;
|
|
@@ -14,6 +15,7 @@ import cn.binarywang.wx.miniapp.api.WxMaService;
|
|
|
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
|
|
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
|
|
|
import cn.binarywang.wx.miniapp.bean.shop.request.shipping.*;
|
|
import cn.binarywang.wx.miniapp.bean.shop.request.shipping.*;
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.alibaba.fastjson.TypeReference;
|
|
import com.alibaba.fastjson.TypeReference;
|
|
@@ -56,6 +58,7 @@ import com.fs.his.service.IFsUserWxService;
|
|
|
import com.fs.his.utils.ConfigUtil;
|
|
import com.fs.his.utils.ConfigUtil;
|
|
|
import com.fs.hisStore.config.StoreConfig;
|
|
import com.fs.hisStore.config.StoreConfig;
|
|
|
import com.fs.hisStore.domain.FsStoreOrderScrm;
|
|
import com.fs.hisStore.domain.FsStoreOrderScrm;
|
|
|
|
|
+import com.fs.hisStore.enums.OrderInfoEnum;
|
|
|
import com.fs.hisStore.enums.SysConfigEnum;
|
|
import com.fs.hisStore.enums.SysConfigEnum;
|
|
|
import com.fs.hisStore.mapper.FsStoreOrderScrmMapper;
|
|
import com.fs.hisStore.mapper.FsStoreOrderScrmMapper;
|
|
|
import com.fs.hisStore.param.*;
|
|
import com.fs.hisStore.param.*;
|
|
@@ -1147,6 +1150,11 @@ public class FsStorePaymentScrmServiceImpl implements IFsStorePaymentScrmService
|
|
|
if (Objects.isNull(user)) {
|
|
if (Objects.isNull(user)) {
|
|
|
throw new CustomException("用户不存在");
|
|
throw new CustomException("用户不存在");
|
|
|
}
|
|
}
|
|
|
|
|
+ if (PaymentMethodEnum.CZ_PAY == payOrderParam.getPaymentMethod()) {
|
|
|
|
|
+ if (user.getRechargeBalance().compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
|
|
+ throw new CustomException("余额不足!请先充值。");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
String type = null;
|
|
String type = null;
|
|
|
FsPayConfig payConfig = new FsPayConfig();
|
|
FsPayConfig payConfig = new FsPayConfig();
|
|
|
if (PaymentMethodEnum.WX_APP == payOrderParam.getPaymentMethod()) {
|
|
if (PaymentMethodEnum.WX_APP == payOrderParam.getPaymentMethod()) {
|
|
@@ -1197,46 +1205,129 @@ public class FsStorePaymentScrmServiceImpl implements IFsStorePaymentScrmService
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
FsStorePaymentScrm storePayment = new FsStorePaymentScrm();
|
|
FsStorePaymentScrm storePayment = new FsStorePaymentScrm();
|
|
|
|
|
+
|
|
|
|
|
+ // 1. 根据业务类型创建对应的支付对象
|
|
|
if (payOrderParam.getBusinessType().getPrefix().equals("live")) {
|
|
if (payOrderParam.getBusinessType().getPrefix().equals("live")) {
|
|
|
|
|
+ // 处理直播业务支付
|
|
|
LiveOrderPayment liveOrderPayment = createLiveStorePayment(payConfig, user, payOrderParam);
|
|
LiveOrderPayment liveOrderPayment = createLiveStorePayment(payConfig, user, payOrderParam);
|
|
|
BeanUtils.copyProperties(liveOrderPayment, storePayment);
|
|
BeanUtils.copyProperties(liveOrderPayment, storePayment);
|
|
|
- if (PaymentMethodEnum.CZ_PAY == payOrderParam.getPaymentMethod()) {
|
|
|
|
|
- LiveOrder liveOrder = liveOrderMapper.selectLiveOrderByOrderId(liveOrderPayment.getBusinessId());
|
|
|
|
|
- Company company = companyService.selectCompanyById(liveOrder.getCompanyId());
|
|
|
|
|
- user.setRechargeBalance(user.getRechargeBalance().multiply(liveOrder.getPayMoney()));
|
|
|
|
|
- userService.updateFsUser(user);
|
|
|
|
|
- return R.ok().put("data",createConsumptionRecord(
|
|
|
|
|
- liveOrder.getOrderId(),
|
|
|
|
|
- liveOrder.getOrderCode(),
|
|
|
|
|
- user.getUserId(),
|
|
|
|
|
- user.getNickName(),
|
|
|
|
|
- storePayment.getPayMoney(),
|
|
|
|
|
- company.getCompanyId(),
|
|
|
|
|
- company.getCompanyName())
|
|
|
|
|
- );
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // 处理储值支付
|
|
|
|
|
+ if (isRechargePayment(payOrderParam)) {
|
|
|
|
|
+ return processLiveRechargePayment(liveOrderPayment, user);
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
|
|
+ // 处理商城业务支付
|
|
|
storePayment = createStorePaymentScrm(payConfig, user, payOrderParam);
|
|
storePayment = createStorePaymentScrm(payConfig, user, payOrderParam);
|
|
|
- if (PaymentMethodEnum.CZ_PAY == payOrderParam.getPaymentMethod()) {
|
|
|
|
|
- FsStoreOrderScrm fsStoreOrderScrm = storeOrderScrmMapper.selectFsStoreOrderById(storePayment.getOrderId());
|
|
|
|
|
- Company company = companyService.selectCompanyById(fsStoreOrderScrm.getCompanyId());
|
|
|
|
|
- user.setRechargeBalance(user.getRechargeBalance().multiply(storePayment.getPayMoney()));
|
|
|
|
|
- userService.updateFsUser(user);
|
|
|
|
|
- return R.ok().put("data",createConsumptionRecord(
|
|
|
|
|
- fsStoreOrderScrm.getId(),
|
|
|
|
|
- fsStoreOrderScrm.getOrderCode(),
|
|
|
|
|
- user.getUserId(),
|
|
|
|
|
- user.getNickName(),
|
|
|
|
|
- storePayment.getPayMoney(),
|
|
|
|
|
- company.getCompanyId(),
|
|
|
|
|
- company.getCompanyName())
|
|
|
|
|
- );
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // 处理储值支付
|
|
|
|
|
+ if (isRechargePayment(payOrderParam)) {
|
|
|
|
|
+ return processStoreRechargePayment(storePayment, user);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
// 根据配置类型创建第三方支付订单
|
|
// 根据配置类型创建第三方支付订单
|
|
|
return createThirdPartyPaymentScrm(payConfig, storePayment, user, payOrderParam);
|
|
return createThirdPartyPaymentScrm(payConfig, storePayment, user, payOrderParam);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 判断是否为储值支付
|
|
|
|
|
+ * @param payOrderParam 支付订单参数
|
|
|
|
|
+ * @return true:储值支付 false:其他支付方式
|
|
|
|
|
+ */
|
|
|
|
|
+ private boolean isRechargePayment(PayOrderParam payOrderParam) {
|
|
|
|
|
+ return PaymentMethodEnum.CZ_PAY == payOrderParam.getPaymentMethod();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 处理直播储值支付
|
|
|
|
|
+ * @param liveOrderPayment 直播订单支付信息
|
|
|
|
|
+ * @param user 用户信息
|
|
|
|
|
+ * @return 支付处理结果
|
|
|
|
|
+ */
|
|
|
|
|
+ private R processLiveRechargePayment(LiveOrderPayment liveOrderPayment, FsUserScrm user) {
|
|
|
|
|
+ // 查询直播订单信息
|
|
|
|
|
+ LiveOrder liveOrder = liveOrderMapper.selectLiveOrderByOrderId(liveOrderPayment.getBusinessId());
|
|
|
|
|
+ Company company = companyService.selectCompanyById(liveOrder.getCompanyId());
|
|
|
|
|
+
|
|
|
|
|
+ // 扣减用户储值余额
|
|
|
|
|
+ deductUserRechargeBalance(user, liveOrder.getPayMoney());
|
|
|
|
|
+
|
|
|
|
|
+ // 更新直播订单状态
|
|
|
|
|
+ updateLiveOrderStatus(liveOrder);
|
|
|
|
|
+
|
|
|
|
|
+ // 创建消费记录
|
|
|
|
|
+ return R.ok().put("data", createConsumptionRecord(
|
|
|
|
|
+ liveOrder.getOrderId(),
|
|
|
|
|
+ liveOrder.getOrderCode(),
|
|
|
|
|
+ user.getUserId(),
|
|
|
|
|
+ user.getNickName(),
|
|
|
|
|
+ liveOrderPayment.getPayMoney(),
|
|
|
|
|
+ company
|
|
|
|
|
+ ));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 处理商城储值支付
|
|
|
|
|
+ * @param storePayment 商城订单支付信息
|
|
|
|
|
+ * @param user 用户信息
|
|
|
|
|
+ * @return 支付处理结果
|
|
|
|
|
+ */
|
|
|
|
|
+ private R processStoreRechargePayment(FsStorePaymentScrm storePayment, FsUserScrm user) {
|
|
|
|
|
+ // 查询商城订单信息
|
|
|
|
|
+ FsStoreOrderScrm fsStoreOrderScrm = storeOrderScrmMapper.selectFsStoreOrderById(storePayment.getOrderId());
|
|
|
|
|
+ Company company = companyService.selectCompanyById(fsStoreOrderScrm.getCompanyId());
|
|
|
|
|
+
|
|
|
|
|
+ // 扣减用户储值余额
|
|
|
|
|
+ deductUserRechargeBalance(user, storePayment.getPayMoney());
|
|
|
|
|
+
|
|
|
|
|
+ // 更新商城订单状态
|
|
|
|
|
+ updateStoreOrderStatus(fsStoreOrderScrm);
|
|
|
|
|
+
|
|
|
|
|
+ // 创建消费记录
|
|
|
|
|
+ return R.ok().put("data", createConsumptionRecord(
|
|
|
|
|
+ fsStoreOrderScrm.getId(),
|
|
|
|
|
+ fsStoreOrderScrm.getOrderCode(),
|
|
|
|
|
+ user.getUserId(),
|
|
|
|
|
+ user.getNickName(),
|
|
|
|
|
+ storePayment.getPayMoney(),
|
|
|
|
|
+ company
|
|
|
|
|
+ ));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 扣减用户储值余额
|
|
|
|
|
+ * @param user 用户信息
|
|
|
|
|
+ * @param amount 扣减金额
|
|
|
|
|
+ */
|
|
|
|
|
+ private void deductUserRechargeBalance(FsUserScrm user, BigDecimal amount) {
|
|
|
|
|
+ user.setRechargeBalance(user.getRechargeBalance().subtract(amount));
|
|
|
|
|
+ userService.updateFsUser(user);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 更新直播订单状态
|
|
|
|
|
+ * @param liveOrder 直播订单
|
|
|
|
|
+ */
|
|
|
|
|
+ private void updateLiveOrderStatus(LiveOrder liveOrder) {
|
|
|
|
|
+ liveOrder.setStatus(OrderInfoEnum.STATUS_1.getValue());
|
|
|
|
|
+ liveOrder.setPayTime(LocalDateTime.now());
|
|
|
|
|
+ liveOrder.setIsPay("1");
|
|
|
|
|
+ liveOrderMapper.updateLiveOrder(liveOrder);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 更新商城订单状态
|
|
|
|
|
+ * @param storeOrder 商城订单
|
|
|
|
|
+ */
|
|
|
|
|
+ private void updateStoreOrderStatus(FsStoreOrderScrm storeOrder) {
|
|
|
|
|
+ storeOrder.setPaid(OrderInfoEnum.PAY_STATUS_1.getValue());
|
|
|
|
|
+ storeOrder.setStatus(OrderInfoEnum.STATUS_1.getValue());
|
|
|
|
|
+ storeOrder.setPayTime(new Date());
|
|
|
|
|
+ storeOrderScrmMapper.updateFsStoreOrder(storeOrder);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 订单支付成功后,增加消费记录
|
|
* 订单支付成功后,增加消费记录
|
|
|
* @param orderId 订单ID
|
|
* @param orderId 订单ID
|
|
@@ -1244,13 +1335,11 @@ public class FsStorePaymentScrmServiceImpl implements IFsStorePaymentScrmService
|
|
|
* @param userId 用户ID
|
|
* @param userId 用户ID
|
|
|
* @param userName 用户姓名
|
|
* @param userName 用户姓名
|
|
|
* @param amount 消费金额
|
|
* @param amount 消费金额
|
|
|
- * @param companyId 公司ID
|
|
|
|
|
- * @param companyName 公司名称
|
|
|
|
|
* @return 影响行数
|
|
* @return 影响行数
|
|
|
*/
|
|
*/
|
|
|
public int createConsumptionRecord(Long orderId, String orderNo, Long userId,
|
|
public int createConsumptionRecord(Long orderId, String orderNo, Long userId,
|
|
|
- String userName, BigDecimal amount,
|
|
|
|
|
- Long companyId, String companyName) {
|
|
|
|
|
|
|
+ String userName, BigDecimal amount,Company company
|
|
|
|
|
+ ) {
|
|
|
RechargeRecord record = new RechargeRecord();
|
|
RechargeRecord record = new RechargeRecord();
|
|
|
record.setUserId(userId);
|
|
record.setUserId(userId);
|
|
|
record.setUserName(userName);
|
|
record.setUserName(userName);
|
|
@@ -1259,9 +1348,13 @@ public class FsStorePaymentScrmServiceImpl implements IFsStorePaymentScrmService
|
|
|
record.setOrderId(orderId);
|
|
record.setOrderId(orderId);
|
|
|
record.setOrderNo(orderNo);
|
|
record.setOrderNo(orderNo);
|
|
|
record.setBusinessType(1); // 1-消费
|
|
record.setBusinessType(1); // 1-消费
|
|
|
- record.setCompanyId(companyId);
|
|
|
|
|
- record.setCompanyName(companyName);
|
|
|
|
|
- record.setRemark("订单消费");
|
|
|
|
|
|
|
+ if (ObjectUtil.isEmpty(company)){
|
|
|
|
|
+ record.setRemark("订单消费,自主下单没有归属公司");
|
|
|
|
|
+ }else {
|
|
|
|
|
+ record.setCompanyId(company.getCompanyId());
|
|
|
|
|
+ record.setCompanyName(company.getCompanyName());
|
|
|
|
|
+ record.setRemark("订单消费");
|
|
|
|
|
+ }
|
|
|
record.setCreateTime(new Date());
|
|
record.setCreateTime(new Date());
|
|
|
record.setDelFlag("0");
|
|
record.setDelFlag("0");
|
|
|
|
|
|
|
@@ -1273,7 +1366,7 @@ public class FsStorePaymentScrmServiceImpl implements IFsStorePaymentScrmService
|
|
|
* @return 交易流水号
|
|
* @return 交易流水号
|
|
|
*/
|
|
*/
|
|
|
private String generateTransactionId() {
|
|
private String generateTransactionId() {
|
|
|
- return "TXN" + System.currentTimeMillis() + UUID.randomUUID().toString().substring(0, 8).toUpperCase();
|
|
|
|
|
|
|
+ return "TXF" + System.currentTimeMillis() + UUID.randomUUID().toString().substring(0, 8).toUpperCase();
|
|
|
}
|
|
}
|
|
|
/**
|
|
/**
|
|
|
* 直播订单支付信息
|
|
* 直播订单支付信息
|