|
@@ -42,6 +42,7 @@ import com.fs.common.event.TemplateListenEnum;
|
|
|
import com.fs.common.exception.CustomException;
|
|
import com.fs.common.exception.CustomException;
|
|
|
import com.fs.common.exception.ServiceException;
|
|
import com.fs.common.exception.ServiceException;
|
|
|
import com.fs.common.utils.*;
|
|
import com.fs.common.utils.*;
|
|
|
|
|
+import com.fs.common.utils.ServletUtils;
|
|
|
import com.fs.common.utils.ip.IpUtils;
|
|
import com.fs.common.utils.ip.IpUtils;
|
|
|
import com.fs.common.utils.spring.SpringUtils;
|
|
import com.fs.common.utils.spring.SpringUtils;
|
|
|
import com.fs.company.domain.Company;
|
|
import com.fs.company.domain.Company;
|
|
@@ -73,14 +74,23 @@ import com.fs.his.service.IFsUserService;
|
|
|
import com.fs.his.utils.ConfigUtil;
|
|
import com.fs.his.utils.ConfigUtil;
|
|
|
import com.fs.hisStore.config.FsErpConfig;
|
|
import com.fs.hisStore.config.FsErpConfig;
|
|
|
import com.fs.hisStore.config.StoreConfig;
|
|
import com.fs.hisStore.config.StoreConfig;
|
|
|
|
|
+import com.fs.hisStore.constants.StoreConstants;
|
|
|
import com.fs.hisStore.domain.*;
|
|
import com.fs.hisStore.domain.*;
|
|
|
import com.fs.hisStore.dto.*;
|
|
import com.fs.hisStore.dto.*;
|
|
|
import com.fs.hisStore.enums.*;
|
|
import com.fs.hisStore.enums.*;
|
|
|
|
|
+import com.fs.hisStore.mapper.FsStoreOrderItemScrmMapper;
|
|
|
|
|
+import com.fs.hisStore.mapper.FsStoreOrderScrmMapper;
|
|
|
|
|
+import com.fs.hisStore.mapper.FsStorePaymentScrmMapper;
|
|
|
import com.fs.hisStore.mapper.FsStoreProductAttrValueScrmMapper;
|
|
import com.fs.hisStore.mapper.FsStoreProductAttrValueScrmMapper;
|
|
|
import com.fs.hisStore.mapper.FsStoreProductScrmMapper;
|
|
import com.fs.hisStore.mapper.FsStoreProductScrmMapper;
|
|
|
import com.fs.hisStore.mapper.FsUserScrmMapper;
|
|
import com.fs.hisStore.mapper.FsUserScrmMapper;
|
|
|
import com.fs.hisStore.param.*;
|
|
import com.fs.hisStore.param.*;
|
|
|
import com.fs.hisStore.service.*;
|
|
import com.fs.hisStore.service.*;
|
|
|
|
|
+import com.fs.common.utils.SnowflakeUtil;
|
|
|
|
|
+import com.fs.huifuPay.sdk.opps.core.utils.HuiFuUtils;
|
|
|
|
|
+import com.fs.his.domain.MerchantAppConfig;
|
|
|
|
|
+import com.fs.his.domain.FsPayConfig;
|
|
|
|
|
+import org.springframework.aop.framework.AopContext;
|
|
|
import com.fs.hisStore.service.IFsStoreProductPurchaseLimitScrmService;
|
|
import com.fs.hisStore.service.IFsStoreProductPurchaseLimitScrmService;
|
|
|
import com.fs.hisStore.domain.FsStoreProductPurchaseLimitScrm;
|
|
import com.fs.hisStore.domain.FsStoreProductPurchaseLimitScrm;
|
|
|
import com.fs.hisStore.vo.*;
|
|
import com.fs.hisStore.vo.*;
|
|
@@ -296,8 +306,27 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
private FSSysConfig sysConfig;
|
|
private FSSysConfig sysConfig;
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private LiveOrderMapper liveOrderMapper;
|
|
private LiveOrderMapper liveOrderMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private FsStoreOrderScrmMapper fsStoreOrderScrmMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private FsStoreOrderItemScrmMapper fsStoreOrderItemScrmMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private IFsStoreOrderStatusScrmService orderStatusService;
|
|
|
|
|
+
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private ILiveGoodsService liveGoodsService;
|
|
private ILiveGoodsService liveGoodsService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private IFsStoreOrderScrmService fsStoreOrderScrmService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private FsStorePaymentScrmMapper fsStorePaymentScrmMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private CloudHostProper cloudHostProper;
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private ILiveUserFirstEntryService liveUserFirstEntryService;
|
|
private ILiveUserFirstEntryService liveUserFirstEntryService;
|
|
@@ -2171,7 +2200,7 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
liveOrder.setCompanyUserId(liveUserFirstEntry.getCompanyUserId());
|
|
liveOrder.setCompanyUserId(liveUserFirstEntry.getCompanyUserId());
|
|
|
liveOrder.setTuiUserId(liveUserFirstEntry.getCompanyUserId());
|
|
liveOrder.setTuiUserId(liveUserFirstEntry.getCompanyUserId());
|
|
|
|
|
|
|
|
- String orderSn = OrderCodeUtils.getOrderSn();
|
|
|
|
|
|
|
+ String orderSn = SnowflakeUtil.nextIdStr();
|
|
|
log.info("订单生成:" + orderSn);
|
|
log.info("订单生成:" + orderSn);
|
|
|
liveOrder.setOrderCode(orderSn);
|
|
liveOrder.setOrderCode(orderSn);
|
|
|
BigDecimal totalPrice = fsStoreProduct.getPrice().multiply(new BigDecimal(liveOrder.getTotalNum()));
|
|
BigDecimal totalPrice = fsStoreProduct.getPrice().multiply(new BigDecimal(liveOrder.getTotalNum()));
|
|
@@ -3155,7 +3184,7 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
MerchantAppConfig merchantAppConfig = merchantAppConfigMapper.selectMerchantAppConfigById(fsCoursePlaySourceConfig.getMerchantConfigId());
|
|
MerchantAppConfig merchantAppConfig = merchantAppConfigMapper.selectMerchantAppConfigById(fsCoursePlaySourceConfig.getMerchantConfigId());
|
|
|
|
|
|
|
|
|
|
|
|
|
- String payCode = OrderCodeUtils.getOrderSn();
|
|
|
|
|
|
|
+ String payCode = SnowflakeUtil.nextIdStr();
|
|
|
if (StringUtils.isEmpty(payCode)) {
|
|
if (StringUtils.isEmpty(payCode)) {
|
|
|
return R.error("订单生成失败,请重试");
|
|
return R.error("订单生成失败,请重试");
|
|
|
}
|
|
}
|
|
@@ -3239,6 +3268,183 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
return baseMapper.selectLiveOrderListZmNew(liveOrder);
|
|
return baseMapper.selectLiveOrderListZmNew(liveOrder);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public R handleStoreOrderPay(LiveOrderPayParam param) {
|
|
|
|
|
+ // 直播订单已合并到商城订单表:改为查询商城订单表
|
|
|
|
|
+ FsStoreOrderScrm order = fsStoreOrderScrmService.selectFsStoreOrderById(param.getOrderId());
|
|
|
|
|
+ if(order == null){
|
|
|
|
|
+ return R.error("订单不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ if(order.getStatus() != OrderInfoEnum.STATUS_0.getValue()){
|
|
|
|
|
+ return R.error("订单状态不正确");
|
|
|
|
|
+ }
|
|
|
|
|
+ String orderId = redisCache.getCacheObject("isPaying:" + param.getOrderId());
|
|
|
|
|
+ if(StringUtils.isNotEmpty(orderId) && orderId.equals(order.getId().toString())){
|
|
|
|
|
+ return R.error("正在支付中...");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ FsUserScrm user = userService.selectFsUserById(order.getUserId());
|
|
|
|
|
+ if(user != null){
|
|
|
|
|
+ //已改价处理
|
|
|
|
|
+ if(order.getIsEditMoney() != null && order.getIsEditMoney() == 1){
|
|
|
|
|
+ //改过价不做处理
|
|
|
|
|
+ }
|
|
|
|
|
+ else{
|
|
|
|
|
+ String config = configService.selectConfigByKey("his.store");
|
|
|
|
|
+ com.fs.store.config.StoreConfig storeConfig = JSONUtil.toBean(config, com.fs.store.config.StoreConfig.class);
|
|
|
|
|
+ if(param.getPayType().equals(1)){
|
|
|
|
|
+ order.setPayType("1");
|
|
|
|
|
+ order.setPayMoney(order.getPayPrice());
|
|
|
|
|
+ if(!"广州郑多燕".equals(cloudHostProper.getCompanyName())){
|
|
|
|
|
+ order.setPayDelivery(BigDecimal.ZERO);
|
|
|
|
|
+ }else {
|
|
|
|
|
+ // 郑多燕单独设置支付类型
|
|
|
|
|
+ order.setPayType(order.getPayPrice().compareTo(order.getTotalPrice()) == 0 ?"1":"5");
|
|
|
|
|
+ log.info("支付------------实际支付金额和总金额:{},{},", order.getPayPrice(), order.getTotalPrice());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ else if(param.getPayType().equals(2)){
|
|
|
|
|
+ order.setPayType("2");
|
|
|
|
|
+ BigDecimal payMoney = order.getPayPrice().multiply(new BigDecimal(storeConfig.getPayRate())).divide(new BigDecimal(100));
|
|
|
|
|
+ payMoney = new BigDecimal(payMoney.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
|
|
|
|
|
+ // 如果小程序需要支付的金额小于0.01元,不能走物流代收,让走货到付款 xgb
|
|
|
|
|
+ if (payMoney.compareTo(new BigDecimal("0.01")) < 0) {
|
|
|
|
|
+ return R.error("物流代收计算支付金额为0,不允许选择物流代收");
|
|
|
|
|
+ }
|
|
|
|
|
+ order.setPayDelivery(order.getPayPrice().subtract(payMoney));
|
|
|
|
|
+ order.setPayMoney(payMoney);
|
|
|
|
|
+ }
|
|
|
|
|
+ else if(param.getPayType().equals(3)){
|
|
|
|
|
+ //货到付款
|
|
|
|
|
+ order.setPayType("3");
|
|
|
|
|
+ BigDecimal amount = redisCache.getCacheObject("orderAmount:" + order.getId());
|
|
|
|
|
+ BigDecimal payMoney = BigDecimal.ZERO;
|
|
|
|
|
+ if (amount != null){
|
|
|
|
|
+ payMoney = amount;
|
|
|
|
|
+ }
|
|
|
|
|
+ //运费
|
|
|
|
|
+ BigDecimal payPostage = order.getPayPostage();
|
|
|
|
|
+ if (payPostage == null || payPostage.compareTo(BigDecimal.ZERO) <= 0){
|
|
|
|
|
+ payPostage = storeConfig.getPayPostage();
|
|
|
|
|
+ if (payPostage == null){
|
|
|
|
|
+ payPostage = BigDecimal.ZERO;
|
|
|
|
|
+ }
|
|
|
|
|
+ order.setPayPrice(order.getPayPrice().add(payPostage));
|
|
|
|
|
+ }
|
|
|
|
|
+ order.setPayPostage(payPostage);
|
|
|
|
|
+ payMoney = payMoney.add(payPostage);
|
|
|
|
|
+ order.setPayMoney(payMoney);
|
|
|
|
|
+ order.setPayDelivery(order.getPayPrice().subtract(payMoney));
|
|
|
|
|
+ }
|
|
|
|
|
+ fsStoreOrderScrmService.updateFsStoreOrder(order);
|
|
|
|
|
+ }
|
|
|
|
|
+ String payCode = SnowflakeUtil.nextIdStr();
|
|
|
|
|
+ if((order.getPayType().equals("1") || order.getPayType().equals("2") || order.getPayType().equals("3") || order.getPayType().equals("5")) && order.getPayMoney().compareTo(new BigDecimal(0)) > 0){
|
|
|
|
|
+ if (StringUtils.isBlank(param.getAppId())) {
|
|
|
|
|
+ throw new IllegalArgumentException("appId不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ FsCoursePlaySourceConfig fsCoursePlaySourceConfig = fsCoursePlaySourceConfigMapper.selectCoursePlaySourceConfigByAppId(param.getAppId());
|
|
|
|
|
+ if (fsCoursePlaySourceConfig == null) {
|
|
|
|
|
+ throw new CustomException("未找到appId对应的小程序配置: " + param.getAppId());
|
|
|
|
|
+ }
|
|
|
|
|
+ Long merchantConfigId = fsCoursePlaySourceConfig.getMerchantConfigId();
|
|
|
|
|
+ if (merchantConfigId == null || merchantConfigId <= 0) {
|
|
|
|
|
+ throw new CustomException("小程序没有配置商户信息");
|
|
|
|
|
+ }
|
|
|
|
|
+ MerchantAppConfig merchantAppConfig = merchantAppConfigMapper.selectMerchantAppConfigById(fsCoursePlaySourceConfig.getMerchantConfigId());
|
|
|
|
|
+ FsPayConfig fsPayConfig = JSON.parseObject(merchantAppConfig.getDataJson(), FsPayConfig.class);
|
|
|
|
|
+ FsStorePaymentScrm storePayment = new FsStorePaymentScrm();
|
|
|
|
|
+ storePayment.setCompanyId(order.getCompanyId());
|
|
|
|
|
+ storePayment.setCompanyUserId(order.getCompanyUserId());
|
|
|
|
|
+ storePayment.setPayMode(merchantAppConfig.getMerchantType());
|
|
|
|
|
+ storePayment.setStatus(0);
|
|
|
|
|
+ storePayment.setPayCode(payCode);
|
|
|
|
|
+ storePayment.setPayMoney(order.getPayMoney());
|
|
|
|
|
+ storePayment.setCreateTime(new Date());
|
|
|
|
|
+ storePayment.setPayTypeCode("weixin");
|
|
|
|
|
+ storePayment.setBusinessType(5); // 直播订单业务类型
|
|
|
|
|
+ storePayment.setRemark("直播订单支付");
|
|
|
|
|
+ storePayment.setOpenId(user.getRealName());
|
|
|
|
|
+ storePayment.setUserId(user.getUserId());
|
|
|
|
|
+ storePayment.setBusinessOrderId(order.getId().toString());
|
|
|
|
|
+ storePayment.setOrderId(order.getId());
|
|
|
|
|
+ storePayment.setAppId(fsCoursePlaySourceConfig.getAppid() == null ? "" : fsCoursePlaySourceConfig.getAppid());
|
|
|
|
|
+ storePayment.setMerConfigId(merchantAppConfig.getId());
|
|
|
|
|
+ storePayment.setBusinessCode(order.getOrderCode());
|
|
|
|
|
+ fsStorePaymentScrmMapper.insertFsStorePayment(storePayment);
|
|
|
|
|
+
|
|
|
|
|
+ if (merchantAppConfig.getMerchantType().equals("hf")){
|
|
|
|
|
+ HuiFuCreateOrder o = new HuiFuCreateOrder();
|
|
|
|
|
+ o.setTradeType("T_MINIAPP");
|
|
|
|
|
+ o.setOpenid(user.getMaOpenId());
|
|
|
|
|
+ o.setReqSeqId("live-" + storePayment.getPayCode());
|
|
|
|
|
+ o.setTransAmt(storePayment.getPayMoney().toString());
|
|
|
|
|
+ o.setGoodsDesc("直播订单支付");
|
|
|
|
|
+ o.setAppId(param.getAppId());
|
|
|
|
|
+ try {
|
|
|
|
|
+ HuiFuUtils.doDiv(o, order.getCompanyId(), storePayment.getMerConfigId());
|
|
|
|
|
+ //存储分账明细
|
|
|
|
|
+ HuiFuUtils.saveDivItem(o, order.getOrderCode(), storePayment.getPayCode());
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("-------------分账出错:{}", e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ HuifuCreateOrderResult result = huiFuService.createOrder(o);
|
|
|
|
|
+ if(result.getResp_code() != null && (result.getResp_code().equals("00000000") || result.getResp_code().equals("00000100"))){
|
|
|
|
|
+ FsStorePaymentScrm mt = new FsStorePaymentScrm();
|
|
|
|
|
+ mt.setPaymentId(storePayment.getPaymentId());
|
|
|
|
|
+ mt.setTradeNo(result.getHf_seq_id());
|
|
|
|
|
+ mt.setAppId(param.getAppId());
|
|
|
|
|
+ mt.setBusinessCode(order.getOrderCode());
|
|
|
|
|
+ fsStorePaymentScrmMapper.updateFsStorePayment(mt);
|
|
|
|
|
+ redisCache.setCacheObject("isPaying:" + order.getId(), order.getId().toString(), 1, TimeUnit.MINUTES);
|
|
|
|
|
+ Map<String, Object> resultMap = JSON.parseObject(result.getPay_info(), new TypeReference<Map<String, Object>>() {});
|
|
|
|
|
+ String s = (String) resultMap.get("package");
|
|
|
|
|
+ resultMap.put("packageValue", s);
|
|
|
|
|
+ return R.ok().put("payType", param.getPayType()).put("result", resultMap);
|
|
|
|
|
+ }
|
|
|
|
|
+ else{
|
|
|
|
|
+ return R.error(result.getResp_desc());
|
|
|
|
|
+ }
|
|
|
|
|
+ }else if (merchantAppConfig.getMerchantType().equals("wx")){
|
|
|
|
|
+ WxPayConfig payConfig = new WxPayConfig();
|
|
|
|
|
+ payConfig.setAppId(fsCoursePlaySourceConfig.getAppid());
|
|
|
|
|
+ payConfig.setMchId(fsPayConfig.getWxMchId());
|
|
|
|
|
+ payConfig.setMchKey(fsPayConfig.getWxMchKey());
|
|
|
|
|
+ payConfig.setSubAppId(org.apache.commons.lang3.StringUtils.trimToNull(null));
|
|
|
|
|
+ payConfig.setSubMchId(org.apache.commons.lang3.StringUtils.trimToNull(null));
|
|
|
|
|
+ payConfig.setKeyPath(fsPayConfig.getKeyPath());
|
|
|
|
|
+ payConfig.setNotifyUrl(fsPayConfig.getNotifyUrlScrm());
|
|
|
|
|
+ wxPayService.setConfig(payConfig);
|
|
|
|
|
+ WxPayUnifiedOrderRequest orderRequest = new WxPayUnifiedOrderRequest();
|
|
|
|
|
+ orderRequest.setOpenid(user.getMaOpenId());//公众号支付提供用户openid
|
|
|
|
|
+ orderRequest.setBody("直播订单支付");
|
|
|
|
|
+ orderRequest.setOutTradeNo("live-" + storePayment.getPayCode());
|
|
|
|
|
+ orderRequest.setTotalFee(WxPayUnifiedOrderRequest.yuanToFen(storePayment.getPayMoney().toString()));
|
|
|
|
|
+ orderRequest.setTradeType("JSAPI");
|
|
|
|
|
+ orderRequest.setSpbillCreateIp(IpUtils.getIpAddr(ServletUtils.getRequest()));
|
|
|
|
|
+ //调用统一下单接口,获取"预支付交易会话标识"
|
|
|
|
|
+ try {
|
|
|
|
|
+ WxPayMpOrderResult orderResult = wxPayService.createOrder(orderRequest);
|
|
|
|
|
+ return R.ok().put("result", orderResult).put("type", "wx").put("isPay", 0).put("payType", param.getPayType());
|
|
|
|
|
+ } catch (WxPayException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ throw new CustomException("支付失败" + e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ else if(order.getPayType().equals("3") && order.getPayMoney().compareTo(new BigDecimal(0)) <= 0){
|
|
|
|
|
+ //货到付款
|
|
|
|
|
+ IFsStoreOrderScrmService fsStoreOrderScrmService = (IFsStoreOrderScrmService) AopContext.currentProxy();
|
|
|
|
|
+ fsStoreOrderScrmService.payConfirm(2, order.getId(), null, null, null, null);
|
|
|
|
|
+ return R.ok().put("payType", param.getPayType());
|
|
|
|
|
+ }
|
|
|
|
|
+ return R.error();
|
|
|
|
|
+ }
|
|
|
|
|
+ else{
|
|
|
|
|
+ return R.error("用户OPENID不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
@Transactional(rollbackFor = Throwable.class, propagation = Propagation.REQUIRED)
|
|
@Transactional(rollbackFor = Throwable.class, propagation = Propagation.REQUIRED)
|
|
|
public R handleLiveOrderPay(LiveOrderPayParam param) {
|
|
public R handleLiveOrderPay(LiveOrderPayParam param) {
|
|
@@ -3334,7 +3540,7 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
}
|
|
}
|
|
|
baseMapper.updateLiveOrder(order);
|
|
baseMapper.updateLiveOrder(order);
|
|
|
}
|
|
}
|
|
|
- String payCode = OrderCodeUtils.getOrderSn();
|
|
|
|
|
|
|
+ String payCode = SnowflakeUtil.nextIdStr();
|
|
|
// order.setOrderCode(orderCode);
|
|
// order.setOrderCode(orderCode);
|
|
|
// if(order.getPayType().equals("1")||order.getPayType().equals("2")){
|
|
// if(order.getPayType().equals("1")||order.getPayType().equals("2")){
|
|
|
if ((order.getPayType().equals("1") || order.getPayType().equals("2") || order.getPayType().equals("3")) && order.getPayMoney().compareTo(new BigDecimal(0)) > 0) {
|
|
if ((order.getPayType().equals("1") || order.getPayType().equals("2") || order.getPayType().equals("3")) && order.getPayMoney().compareTo(new BigDecimal(0)) > 0) {
|
|
@@ -3768,6 +3974,252 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public R createStoreOrder(LiveOrder liveOrder) {
|
|
|
|
|
+ String orderKey= redisCache.getCacheObject("orderKey:"+liveOrder.getOrderKey());
|
|
|
|
|
+ if (StringUtils.isEmpty(orderKey)) {
|
|
|
|
|
+ return R.error("订单已过期");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (liveOrder.getLiveId() == null) return R.error("直播ID不能为空");
|
|
|
|
|
+ if (liveOrder.getProductId() == null) return R.error("购物商品ID不能为空");
|
|
|
|
|
+ if (liveOrder.getUserName() == null) return R.error("用户名不能为空");
|
|
|
|
|
+ if (liveOrder.getUserPhone() == null) return R.error("用户手机号不能为空");
|
|
|
|
|
+ if (liveOrder.getUserAddress() == null) return R.error("用户地址不能为空");
|
|
|
|
|
+ if (liveOrder.getTotalNum() == null) return R.error("商品数量不能为空");
|
|
|
|
|
+ LiveGoods goods = liveGoodsMapper.selectLiveGoodsByProductId(liveOrder.getLiveId(), liveOrder.getProductId());
|
|
|
|
|
+ if (goods == null) return R.error("当前商品不存在");
|
|
|
|
|
+ String configJson = configService.selectConfigByKey("his.store");
|
|
|
|
|
+ if (org.apache.commons.lang3.StringUtils.isNotEmpty(configJson)) {
|
|
|
|
|
+ com.fs.hisStore.config.StoreConfig config = com.alibaba.fastjson.JSON.parseObject(configJson, com.fs.hisStore.config.StoreConfig.class);
|
|
|
|
|
+ if (config != null && Boolean.TRUE.equals(config.getCheckStock())) {
|
|
|
|
|
+ CompletableFuture<Boolean> completableFuture = stockDeductService.deductStockAsync(liveOrder.getProductId(), liveOrder.getLiveId(), Integer.parseInt(liveOrder.getTotalNum()), Long.parseLong(liveOrder.getUserId()));
|
|
|
|
|
+ try {
|
|
|
|
|
+ log.info("{}, 商品REDIS 库存扣减成功!", goods.getLiveId());
|
|
|
|
|
+ if (!completableFuture.get()) {
|
|
|
|
|
+ return R.error("抱歉,这款商品已被抢光,暂时无库存~");
|
|
|
|
|
+ }
|
|
|
|
|
+ log.info("{}, 商品REDIS 库存扣减成功!", goods.getLiveId());
|
|
|
|
|
+ } catch (InterruptedException e) {
|
|
|
|
|
+ log.error("高并发处理失败", e);
|
|
|
|
|
+ return R.error("订单创建失败:" + e.getMessage());
|
|
|
|
|
+ } catch (ExecutionException e) {
|
|
|
|
|
+ log.error("高并发处理失败", e);
|
|
|
|
|
+ return R.error("订单创建失败:" + e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (goods.getStock() == null) return R.error("直播间商品库存不足");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ Live live = liveService.selectLiveByLiveId(liveOrder.getLiveId());
|
|
|
|
|
+ if (live == null) return R.error("当前直播不存在");
|
|
|
|
|
+ FsStoreProductScrm fsStoreProduct = fsStoreProductService.selectFsStoreProductById(liveOrder.getProductId());
|
|
|
|
|
+ if (fsStoreProduct == null) return R.error("商品不存在,购买失败");
|
|
|
|
|
+ if (fsStoreProduct.getIsShow() == 0 || goods.getStatus() == 0) return R.error("商品已下架,购买失败");
|
|
|
|
|
+ if (!"1".equals(fsStoreProduct.getIsAudit())) return R.error("商品已下架,购买失败");
|
|
|
|
|
+ if (liveOrder.getTotalNum() == null || StringUtils.isEmpty(liveOrder.getTotalNum())) liveOrder.setTotalNum("1");
|
|
|
|
|
+ FsStoreProductAttrValueScrm attrValue = fsStoreProductAttrValueMapper.selectFsStoreProductAttrValueById(liveOrder.getAttrValueId());
|
|
|
|
|
+// if(fsStoreProduct.getStock() < Integer.parseInt(liveOrder.getTotalNum()) || goods.getStock() < Integer.parseInt(liveOrder.getTotalNum()) || attrValue.getStock() < Integer.parseInt(liveOrder.getTotalNum())){
|
|
|
|
|
+// return R.error("抱歉,这款商品已被抢光,暂时无库存~");
|
|
|
|
|
+// }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ // 检查限购
|
|
|
|
|
+ Long userId = Long.parseLong(liveOrder.getUserId());
|
|
|
|
|
+ Integer purchaseNum = Integer.parseInt(liveOrder.getTotalNum());
|
|
|
|
|
+ checkPurchaseLimitForLiveOrder(userId, liveOrder.getProductId(), purchaseNum);
|
|
|
|
|
+ LiveGoodsUploadMqVo vo = LiveGoodsUploadMqVo.builder().goodsId(goods.getGoodsId()).goodsNum(Integer.parseInt(liveOrder.getTotalNum())).build();
|
|
|
|
|
+ try {
|
|
|
|
|
+ log.info("订单提交MQ:{}", vo);
|
|
|
|
|
+ rocketMQTemplate.syncSend("live-goods-upload", JSON.toJSONString(vo));
|
|
|
|
|
+ }catch (Exception e){
|
|
|
|
|
+ log.error("更新库存失败!{}", vo, e);
|
|
|
|
|
+ }
|
|
|
|
|
+ // 复制到商城订单
|
|
|
|
|
+ FsStoreOrderScrm storeOrder = new FsStoreOrderScrm();
|
|
|
|
|
+ copyLiveToStore(liveOrder, storeOrder);
|
|
|
|
|
+
|
|
|
|
|
+ //判断是否是三种特定产品
|
|
|
|
|
+ String storeHouseCode;
|
|
|
|
|
+ if (fsStoreProduct.getProductId() != null && (fsStoreProduct.getProductId().equals(3168L)
|
|
|
|
|
+ || fsStoreProduct.getProductId().equals(3184L)
|
|
|
|
|
+ || fsStoreProduct.getProductId().equals(3185L))) {
|
|
|
|
|
+ storeHouseCode = "YDSP001";
|
|
|
|
|
+ } else {
|
|
|
|
|
+ storeHouseCode = "CQDS001";
|
|
|
|
|
+ }
|
|
|
|
|
+ storeOrder.setStoreHouseCode(storeHouseCode);
|
|
|
|
|
+
|
|
|
|
|
+ LiveUserFirstEntry liveUserFirstEntry = liveUserFirstEntryService.selectEntityByLiveIdUserId(liveOrder.getLiveId(), Long.parseLong(liveOrder.getUserId()));
|
|
|
|
|
+ if (ObjectUtil.isNotEmpty(liveUserFirstEntry)) {
|
|
|
|
|
+ storeOrder.setCompanyId(liveUserFirstEntry.getCompanyId());
|
|
|
|
|
+ storeOrder.setCompanyUserId(liveUserFirstEntry.getCompanyUserId());
|
|
|
|
|
+ storeOrder.setTuiUserId(liveUserFirstEntry.getCompanyUserId());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+// String orderSn = SnowflakeUtil.nextIdStr();
|
|
|
|
|
+ String orderSn = SnowflakeUtil.nextIdStr();
|
|
|
|
|
+ log.info("订单生成:" + orderSn);
|
|
|
|
|
+ storeOrder.setOrderCode(orderSn);
|
|
|
|
|
+ // 注意:bizOrderType 字段需要在 FsStoreOrderScrm 实体类中添加
|
|
|
|
|
+ // storeOrder.setBizOrderType(1); // 设置为直播订单
|
|
|
|
|
+
|
|
|
|
|
+ BigDecimal payPrice = fsStoreProduct.getPrice().multiply(new BigDecimal(liveOrder.getTotalNum()));
|
|
|
|
|
+ if (attrValue != null) {
|
|
|
|
|
+ payPrice = attrValue.getPrice().multiply(new BigDecimal(liveOrder.getTotalNum()));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 计算运费
|
|
|
|
|
+ BigDecimal deliveryMoney = handleDeliveryMoney(liveOrder);
|
|
|
|
|
+ if (deliveryMoney.compareTo(BigDecimal.valueOf(-1)) == 0) {
|
|
|
|
|
+ return R.error("偏远地区暂不可购买");
|
|
|
|
|
+ }
|
|
|
|
|
+ payPrice = payPrice.add(deliveryMoney);
|
|
|
|
|
+ BigDecimal discountMoney = BigDecimal.ZERO;
|
|
|
|
|
+
|
|
|
|
|
+ //优惠券处理
|
|
|
|
|
+ if (liveOrder.getCouponUserId() != null) {
|
|
|
|
|
+ LiveCouponUser couponUser = liveCouponUserService.selectLiveCouponUserById(liveOrder.getCouponUserId());
|
|
|
|
|
+ if (couponUser != null && couponUser.getStatus() == 0) {
|
|
|
|
|
+ if (!couponUser.getUserId().toString().equals(liveOrder.getUserId())) {
|
|
|
|
|
+ return R.error("非法操作");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (couponUser.getUseMinPrice().compareTo(payPrice) < 1) {
|
|
|
|
|
+ discountMoney = couponUser.getCouponPrice();
|
|
|
|
|
+ storeOrder.setCouponId(couponUser.getId());
|
|
|
|
|
+ storeOrder.setCouponPrice(couponUser.getCouponPrice());
|
|
|
|
|
+ //更新优惠券状态
|
|
|
|
|
+ couponUser.setStatus(1);
|
|
|
|
|
+ couponUser.setUseTime(new Date());
|
|
|
|
|
+ liveCouponUserService.updateLiveCouponUser(couponUser);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 设置商城订单字段(按照 createOrder 的逻辑)
|
|
|
|
|
+ storeOrder.setUserId(Long.parseLong(liveOrder.getUserId()));
|
|
|
|
|
+ storeOrder.setTotalNum(Long.parseLong(liveOrder.getTotalNum()));
|
|
|
|
|
+ storeOrder.setTotalPrice(payPrice);
|
|
|
|
|
+ storeOrder.setTotalPostage(deliveryMoney);
|
|
|
|
|
+ storeOrder.setPayPostage(deliveryMoney);
|
|
|
|
|
+ storeOrder.setPayDelivery(deliveryMoney);
|
|
|
|
|
+ storeOrder.setCouponPrice(discountMoney);
|
|
|
|
|
+ storeOrder.setDeductionPrice(BigDecimal.ZERO);
|
|
|
|
|
+ storeOrder.setPaid(0);
|
|
|
|
|
+ storeOrder.setPayType(StringUtils.isEmpty(liveOrder.getPayType()) ? "1" :liveOrder.getPayType());
|
|
|
|
|
+ storeOrder.setUseIntegral(BigDecimal.ZERO);
|
|
|
|
|
+ storeOrder.setBackIntegral(BigDecimal.ZERO);
|
|
|
|
|
+ storeOrder.setGainIntegral(BigDecimal.ZERO);
|
|
|
|
|
+ storeOrder.setCost(BigDecimal.ZERO);
|
|
|
|
|
+ storeOrder.setIsChannel(1);
|
|
|
|
|
+ storeOrder.setShippingType(1);
|
|
|
|
|
+ storeOrder.setCreateTime(new Date());
|
|
|
|
|
+ storeOrder.setIsPrescribe(0);
|
|
|
|
|
+ storeOrder.setOrderType(2);
|
|
|
|
|
+
|
|
|
|
|
+ // 获取配置
|
|
|
|
|
+ String json = configService.selectConfigByKey("store.config");
|
|
|
|
|
+ StoreConfig config = JSONUtil.toBean(json, StoreConfig.class);
|
|
|
|
|
+ if (config != null && config.getServiceFee() != null) {
|
|
|
|
|
+ storeOrder.setServiceFee(config.getServiceFee());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 设置支付金额
|
|
|
|
|
+ storeOrder.setPayPrice(payPrice.subtract(discountMoney));
|
|
|
|
|
+ storeOrder.setPayMoney(storeOrder.getPayPrice());
|
|
|
|
|
+
|
|
|
|
|
+ // 设置订单状态
|
|
|
|
|
+ storeOrder.setStatus(0); // 待支付
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 插入商城订单
|
|
|
|
|
+ Integer flag = fsStoreOrderScrmMapper.insertFsStoreOrder(storeOrder);
|
|
|
|
|
+ if (flag == 0) {
|
|
|
|
|
+ return R.error("订单创建失败");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 保存订单明细
|
|
|
|
|
+ FsStoreCartDTO fsStoreCartDTO = new FsStoreCartDTO();
|
|
|
|
|
+ fsStoreCartDTO.setProductId(fsStoreProduct.getProductId());
|
|
|
|
|
+ fsStoreCartDTO.setPrice(attrValue != null ? attrValue.getPrice() : fsStoreProduct.getPrice());
|
|
|
|
|
+ fsStoreCartDTO.setSku(attrValue != null ? (attrValue.getSku() != null ? attrValue.getSku() : "") : "");
|
|
|
|
|
+ fsStoreCartDTO.setProductName(fsStoreProduct.getProductName());
|
|
|
|
|
+ fsStoreCartDTO.setNum(Integer.parseInt(liveOrder.getTotalNum()));
|
|
|
|
|
+ fsStoreCartDTO.setImage(fsStoreProduct.getImage());
|
|
|
|
|
+
|
|
|
|
|
+ if (attrValue != null) {
|
|
|
|
|
+ fsStoreCartDTO.setBarCode(attrValue.getBarCode());
|
|
|
|
|
+ fsStoreCartDTO.setGroupBarCode(attrValue.getGroupBarCode());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ FsStoreOrderItemScrm orderItem = new FsStoreOrderItemScrm();
|
|
|
|
|
+ orderItem.setOrderId(storeOrder.getId());
|
|
|
|
|
+ orderItem.setOrderCode(orderSn);
|
|
|
|
|
+ orderItem.setProductId(fsStoreProduct.getProductId());
|
|
|
|
|
+ orderItem.setProductAttrValueId(attrValue != null ? attrValue.getId() : null);
|
|
|
|
|
+ orderItem.setJsonInfo(JSONUtil.toJsonStr(fsStoreCartDTO));
|
|
|
|
|
+ orderItem.setNum(Integer.parseInt(liveOrder.getTotalNum()));
|
|
|
|
|
+ orderItem.setIsAfterSales(0);
|
|
|
|
|
+ orderItem.setIsPrescribe(0);
|
|
|
|
|
+ fsStoreOrderItemScrmMapper.insertFsStoreOrderItem(orderItem);
|
|
|
|
|
+
|
|
|
|
|
+ // 更新订单的 itemJson
|
|
|
|
|
+ List<FsStoreOrderItemScrm> listOrderItem = new ArrayList<>();
|
|
|
|
|
+ listOrderItem.add(orderItem);
|
|
|
|
|
+ String itemJson = JSONUtil.toJsonStr(listOrderItem);
|
|
|
|
|
+ storeOrder.setItemJson(itemJson);
|
|
|
|
|
+ fsStoreOrderScrmMapper.updateFsStoreOrder(storeOrder);
|
|
|
|
|
+
|
|
|
|
|
+ // 添加订单日志
|
|
|
|
|
+ orderStatusService.create(storeOrder.getId(), OrderLogEnum.CREATE_ORDER.getValue(),
|
|
|
|
|
+ OrderLogEnum.CREATE_ORDER.getDesc());
|
|
|
|
|
+
|
|
|
|
|
+ // 设置直播订单的 orderId 为商城订单的 id
|
|
|
|
|
+
|
|
|
|
|
+ // 加入redis,24小时自动取消
|
|
|
|
|
+ String redisKey = StoreConstants.REDIS_ORDER_OUTTIME_UNPAY + storeOrder.getId();
|
|
|
|
|
+ if (config != null && config.getUnPayTime() != null && config.getUnPayTime() > 0) {
|
|
|
|
|
+ redisCache.setCacheObject(redisKey, storeOrder.getId(), config.getUnPayTime(), TimeUnit.MINUTES);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ redisCache.setCacheObject(redisKey, storeOrder.getId(), 30, TimeUnit.MINUTES);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ redisCache.deleteObject("orderKey:" + liveOrder.getOrderKey());
|
|
|
|
|
+ //添加支付到期时间
|
|
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
|
|
+ calendar.setTime(storeOrder.getCreateTime());
|
|
|
|
|
+ if (config != null && config.getUnPayTime() != null) {
|
|
|
|
|
+ calendar.add(Calendar.MINUTE, config.getUnPayTime());
|
|
|
|
|
+ }
|
|
|
|
|
+ SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
+ String payLimitTime = format.format(calendar.getTime());
|
|
|
|
|
+ return R.ok("下单成功").put("order", storeOrder).put("payLimitTime", payLimitTime);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ // 异常处理
|
|
|
|
|
+ log.error("订单创建失败", e);
|
|
|
|
|
+ return R.error("订单创建失败:" + e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ private void copyLiveToStore(LiveOrder liveOrder, FsStoreOrderScrm storeOrder) {
|
|
|
|
|
+ // 复制基本信息
|
|
|
|
|
+ if (liveOrder.getUserId() != null) {
|
|
|
|
|
+ storeOrder.setUserId(Long.parseLong(liveOrder.getUserId()));
|
|
|
|
|
+ }
|
|
|
|
|
+ storeOrder.setRealName(liveOrder.getUserName());
|
|
|
|
|
+ storeOrder.setUserPhone(liveOrder.getUserPhone());
|
|
|
|
|
+ storeOrder.setUserAddress(liveOrder.getUserAddress());
|
|
|
|
|
+ if (liveOrder.getTotalNum() != null) {
|
|
|
|
|
+ storeOrder.setTotalNum(Long.parseLong(liveOrder.getTotalNum()));
|
|
|
|
|
+ }
|
|
|
|
|
+ storeOrder.setCompanyId(liveOrder.getCompanyId());
|
|
|
|
|
+ storeOrder.setCompanyUserId(liveOrder.getCompanyUserId());
|
|
|
|
|
+ storeOrder.setTuiUserId(liveOrder.getTuiUserId());
|
|
|
|
|
+ storeOrder.setStoreId(liveOrder.getStoreId());
|
|
|
|
|
+ storeOrder.setMark(liveOrder.getRemark());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public void deStockIncSale(List<FsStoreCartQueryVO> cartInfo) {
|
|
public void deStockIncSale(List<FsStoreCartQueryVO> cartInfo) {
|
|
|
for (FsStoreCartQueryVO storeCartVO : cartInfo) {
|
|
for (FsStoreCartQueryVO storeCartVO : cartInfo) {
|
|
|
fsStoreProductService.decProductStock(storeCartVO.getProductId(),
|
|
fsStoreProductService.decProductStock(storeCartVO.getProductId(),
|
|
@@ -3879,7 +4331,7 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
liveOrder.setCompanyUserId(liveUserFirstEntry.getCompanyUserId());
|
|
liveOrder.setCompanyUserId(liveUserFirstEntry.getCompanyUserId());
|
|
|
liveOrder.setTuiUserId(liveUserFirstEntry.getCompanyUserId());
|
|
liveOrder.setTuiUserId(liveUserFirstEntry.getCompanyUserId());
|
|
|
}
|
|
}
|
|
|
- String orderSn = OrderCodeUtils.getOrderSn();
|
|
|
|
|
|
|
+ String orderSn = SnowflakeUtil.nextIdStr();
|
|
|
// String orderSn = "123"; // todo yhq
|
|
// String orderSn = "123"; // todo yhq
|
|
|
log.info("订单生成:" + orderSn);
|
|
log.info("订单生成:" + orderSn);
|
|
|
liveOrder.setOrderCode(orderSn);
|
|
liveOrder.setOrderCode(orderSn);
|
|
@@ -4045,7 +4497,7 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
liveOrder.setCompanyUserId(liveUserFirstEntry.getCompanyUserId());
|
|
liveOrder.setCompanyUserId(liveUserFirstEntry.getCompanyUserId());
|
|
|
liveOrder.setTuiUserId(liveUserFirstEntry.getCompanyUserId());
|
|
liveOrder.setTuiUserId(liveUserFirstEntry.getCompanyUserId());
|
|
|
}
|
|
}
|
|
|
- String orderSn = OrderCodeUtils.getOrderSn();
|
|
|
|
|
|
|
+ String orderSn = SnowflakeUtil.nextIdStr();
|
|
|
// String orderSn = "123"; // todo yhq
|
|
// String orderSn = "123"; // todo yhq
|
|
|
log.info("订单生成:" + orderSn);
|
|
log.info("订单生成:" + orderSn);
|
|
|
liveOrder.setOrderCode(orderSn);
|
|
liveOrder.setOrderCode(orderSn);
|
|
@@ -4254,7 +4706,7 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public R confirmOrder(LiveOrderConfirmParam param) {
|
|
public R confirmOrder(LiveOrderConfirmParam param) {
|
|
|
- String uuid = OrderCodeUtils.getOrderSn();
|
|
|
|
|
|
|
+ String uuid = SnowflakeUtil.nextIdStr();
|
|
|
redisCache.setCacheObject("orderKey:" + uuid, uuid, 200, TimeUnit.MINUTES);
|
|
redisCache.setCacheObject("orderKey:" + uuid, uuid, 200, TimeUnit.MINUTES);
|
|
|
return R.ok().put("orderKey", uuid);
|
|
return R.ok().put("orderKey", uuid);
|
|
|
}
|
|
}
|