Forráskód Böngészése

直播订单添加直播接口

yuhongqi 5 napja
szülő
commit
7278481a50

+ 9 - 0
fs-service/src/main/java/com/fs/hisStore/mapper/FsUserScrmMapper.java

@@ -21,6 +21,7 @@ import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
 import org.apache.ibatis.annotations.Update;
 
+import java.math.BigDecimal;
 import java.util.List;
 import java.util.Map;
 
@@ -319,4 +320,12 @@ public interface FsUserScrmMapper
     Map<String, Long> countCourseDetailsNew(UserStatisticsCommonParam param);
     @Select("select * from fs_user where mp_open_id=#{openId}")
     FsUserScrm selectFsUserByOpenId(String openId);
+
+    /**
+     * 更新用户下单次数和累计成交总额
+     * @param userId 用户ID
+     * @param amount 成交金额
+     */
+    @Update("update fs_user set order_count = order_count + 1, total_amount = IFNULL(total_amount, 0) + #{amount} where user_id = #{userId}")
+    void updateUserOrderCountAndAmount(@Param("userId") Long userId, @Param("amount") BigDecimal amount);
 }

+ 2 - 0
fs-service/src/main/java/com/fs/live/service/ILiveOrderService.java

@@ -234,4 +234,6 @@ public interface ILiveOrderService {
 
 
     List<LiveOrderVoZm> selectLiveOrderListZm(LiveOrder liveOrder);
+
+    R handleLiveOrderPay(LiveOrderPayParam param);
 }

+ 169 - 14
fs-service/src/main/java/com/fs/live/service/impl/LiveOrderServiceImpl.java

@@ -24,6 +24,7 @@ import cn.hutool.json.JSONUtil;
 import com.alibaba.fastjson.JSON;
 
 import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson.TypeReference;
 import com.fs.common.config.FSSysConfig;
 import com.fs.common.core.domain.R;
 import com.fs.common.core.redis.RedisCache;
@@ -33,6 +34,7 @@ import com.fs.common.event.TemplateListenEnum;
 import com.fs.common.exception.CustomException;
 import com.fs.common.exception.ServiceException;
 import com.fs.common.utils.*;
+import com.fs.common.utils.ip.IpUtils;
 import com.fs.company.domain.Company;
 import com.fs.company.domain.CompanyDept;
 import com.fs.company.domain.CompanyMoneyLogs;
@@ -67,6 +69,7 @@ import com.fs.hisStore.enums.OrderLogEnum;
 import com.fs.hisStore.enums.ShipperCodeEnum;
 import com.fs.hisStore.enums.SysConfigEnum;
 import com.fs.hisStore.mapper.FsStoreProductAttrValueScrmMapper;
+import com.fs.hisStore.mapper.FsUserScrmMapper;
 import com.fs.hisStore.param.FsStoreOrderAddTuiMoneyParam;
 import com.fs.hisStore.param.FsStoreOrderParam;
 import com.fs.hisStore.param.FsStoreOrderScrmSetErpPhoneParam;
@@ -75,6 +78,9 @@ import com.fs.hisStore.service.IFsStoreProductScrmService;
 import com.fs.hisStore.vo.FsMyStoreOrderListQueryVO;
 import com.fs.hisStore.vo.FsStoreOrderItemVO;
 import com.fs.hisStore.vo.FsStoreOrderVO;
+import com.fs.huifuPay.domain.HuiFuCreateOrder;
+import com.fs.huifuPay.domain.HuifuCreateOrderResult;
+import com.fs.huifuPay.service.HuiFuService;
 import com.fs.live.domain.*;
 import com.fs.live.dto.LiveOrderComputeDTO;
 import com.fs.live.dto.LiveOrderCustomerExportDTO;
@@ -85,6 +91,11 @@ import com.fs.live.service.*;
 import com.fs.live.vo.*;
 import com.fs.store.domain.*;
 import com.fs.system.service.ISysConfigService;
+import com.github.binarywang.wxpay.bean.order.WxPayMpOrderResult;
+import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest;
+import com.github.binarywang.wxpay.config.WxPayConfig;
+import com.github.binarywang.wxpay.exception.WxPayException;
+import com.github.binarywang.wxpay.service.WxPayService;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang.ObjectUtils;
@@ -120,6 +131,11 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
     @Autowired
     private LiveMapper liveMapper;
 
+    @Autowired
+    private HuiFuService huiFuService;
+    @Autowired
+    private WxPayService wxPayService;
+
 
     @Autowired
     private LiveGoodsMapper liveGoodsMapper;
@@ -134,7 +150,7 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
     private IFsStoreProductScrmService fsStoreProductService;
 
     @Autowired
-    FsUserMapper userMapper;
+    FsUserScrmMapper userMapper;
 
     @Autowired
     private IErpOrderService erpOrderService;
@@ -678,10 +694,10 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
     @Override
     public LiveOrder selectLiveOrderByOrderId(String orderId)
     {
-//        LiveOrder liveOrder = baseMapper.selectLiveOrderByOrderId(orderId);
-//        if(ObjectUtil.isNull(liveOrder)) {
-//            throw new RuntimeException("该订单没有找到!");
-//        }
+        LiveOrder liveOrder = baseMapper.selectLiveOrderByOrderId(orderId);
+        if(ObjectUtil.isNull(liveOrder)) {
+            throw new RuntimeException("该订单没有找到!");
+        }
 //        List<FsStoreDelivers> byOrderIdWithType = fsStoreDeliversMapper.findByOrderIdWithType(Long.valueOf(orderId), 1);
 //        if(CollectionUtils.isNotEmpty(byOrderIdWithType)) {
 //            FsStoreDelivers delivers = byOrderIdWithType.get(0);
@@ -693,15 +709,14 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
 //            liveOrder.setDeliveryStatus(delivers.getStatus());
 //            liveOrder.setDeliveryType(String.valueOf(delivers.getStateEx()));
 //        } else {
-//            liveOrder.setDeliveryCode(null);
-//            liveOrder.setDeliveryName(null);
-//            liveOrder.setDeliverySn(null);
-//
-//            liveOrder.setDeliveryStatus(null);
-//            liveOrder.setDeliveryType(null);
+            liveOrder.setDeliveryCode(null);
+            liveOrder.setDeliveryName(null);
+            liveOrder.setDeliverySn(null);
+
+            liveOrder.setDeliveryStatus(null);
+            liveOrder.setDeliveryType(null);
 //        }
-//        return liveOrder;
-        return null;
+        return liveOrder;
     }
 
     @Autowired
@@ -2408,7 +2423,7 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
             if(liveOrder==null || !liveOrder.getStatus().equals(1)){
                 throw new CustomException("当前订单未找到或者订单状态不为待支付! orderId:" + orderId);
             }
-            FsUser user = userMapper.selectFsUserByUserId(Long.valueOf(liveOrder.getUserId()));
+            FsUserScrm user = userMapper.selectFsUserById(Long.valueOf(liveOrder.getUserId()));
             if(user == null) return R.error("用户不存在");
             String json = configService.selectConfigByKey("store.pay");
             FsPayConfig fsPayConfig = JSON.parseObject(json, FsPayConfig.class);
@@ -2483,6 +2498,146 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
         return baseMapper.selectLiveOrderListZm(liveOrder);
     }
 
+    @Override
+    @Transactional(rollbackFor = Throwable.class,propagation = Propagation.REQUIRED)
+    public R handleLiveOrderPay(LiveOrderPayParam param) {
+        LiveOrder order=baseMapper.selectLiveOrderByOrderId(String.valueOf(param.getOrderId()));
+        if(order==null){
+            return R.error("订单不存在");
+        }
+        if(order.getStatus()!= OrderInfoEnum.STATUS_0.getValue()){
+            return R.error("订单状态不正确");
+        }
+        String orderId=redisCache.getCacheObject("isPaying:"+order.getOrderId());
+        if(StringUtils.isNotEmpty(orderId)&&orderId.equals(order.getOrderId().toString())){
+            return R.error("正在支付中...");
+        }
+
+        FsUserScrm user=userMapper.selectFsUserById(Long.valueOf(order.getUserId()));
+        if(user!=null&& StringUtils.isNotEmpty(user.getMaOpenId())){
+            //已改价处理
+            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());
+                    order.setPayDelivery(BigDecimal.ZERO);
+                }
+                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(0, BigDecimal.ROUND_HALF_UP).longValue());
+                    order.setPayDelivery(order.getPayPrice().subtract(payMoney));
+                    order.setPayMoney(payMoney);
+                }
+                else if(param.getPayType().equals(3)){
+                    //货到付款
+                    order.setPayType("3");
+                    BigDecimal amount=redisCache.getCacheObject("orderAmount:"+order.getOrderId());
+                    BigDecimal payMoney = BigDecimal.ZERO;
+                    if (amount != null){
+                        payMoney=amount;
+                    }
+                    order.setPayMoney(payMoney);
+                    order.setPayDelivery(order.getPayPrice().subtract(payMoney) );
+//                    order.setPayMoney(BigDecimal.ZERO);
+                }
+                baseMapper.updateLiveOrder(order);
+            }
+            String payCode = IdUtil.getSnowflake(0, 0).nextIdStr();
+//            order.setOrderCode(orderCode);
+//            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){
+                String json = configService.selectConfigByKey("his.pay");
+                FsPayConfigScrm fsPayConfig = JSON.parseObject(json, FsPayConfigScrm.class);
+                LiveOrderPayment storePayment=new LiveOrderPayment();
+                storePayment.setCompanyId(order.getCompanyId());
+                storePayment.setCompanyUserId(order.getCompanyUserId());
+                storePayment.setPayMode(fsPayConfig.getType());
+                storePayment.setStatus(0);
+                storePayment.setPayCode(payCode);
+                storePayment.setPayMoney(order.getPayMoney());
+                storePayment.setCreateTime(new Date());
+                storePayment.setPayTypeCode("weixin");
+                storePayment.setBusinessType(2);
+                storePayment.setRemark("直播订单支付");
+                storePayment.setOpenId(user.getRealName());
+                storePayment.setUserId(user.getUserId());
+                storePayment.setBusinessId(String.valueOf(order.getOrderId()));
+                liveOrderPaymentMapper.insertLiveOrderPayment(storePayment);
+
+                if (fsPayConfig.getType().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("直播订单支付");
+                    if (param != null && StringUtils.isNotBlank(param.getAppId())) {
+                        o.setAppId(param.getAppId());
+                    }
+                    HuifuCreateOrderResult result = huiFuService.createOrder(o);
+                    if(result.getResp_code()!=null&&(result.getResp_code().equals("00000000")||result.getResp_code().equals("00000100"))){
+                        LiveOrderPayment mt=new LiveOrderPayment();
+                        mt.setPaymentId(storePayment.getPaymentId());
+                        mt.setTradeNo(result.getHf_seq_id());
+                        liveOrderPaymentMapper.updateLiveOrderPayment(mt);
+                        redisCache.setCacheObject("isPaying:"+order.getOrderId(),order.getOrderId().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 (fsPayConfig.getType().equals("wx")){
+                    WxPayConfig payConfig = new WxPayConfig();
+                    payConfig.setAppId(fsPayConfig.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.setTotalFee(WxPayUnifiedOrderRequest.yuanToFen(money));//测试
+                    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")){
+            else if(order.getPayType().equals("3") && order.getPayMoney().compareTo(new BigDecimal(0))<=0){
+                //货到付款
+                this.payConfirm(2,order.getOrderId(),null,null,null,null);
+                return R.ok().put("payType",param.getPayType());
+            }
+            return R.error();
+        }
+        else{
+            return R.error("用户OPENID不存在");
+        }
+
+    }
+
 
     @Override
     @Transactional(rollbackFor = Throwable.class,propagation = Propagation.REQUIRED)

+ 270 - 22
fs-user-app/src/main/java/com/fs/app/controller/live/LiveOrderController.java

@@ -67,6 +67,10 @@ import com.github.pagehelper.PageInfo;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
 import me.chanjar.weixin.common.error.WxErrorException;
+import org.redisson.api.RLock;
+import org.redisson.api.RedissonClient;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.transaction.annotation.Transactional;
@@ -79,6 +83,8 @@ import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.concurrent.TimeUnit;
 
+import static com.fs.hisStore.constants.UserAppsLockConstant.LOCK_KEY_PAY;
+
 /**
  * 订单Controller
  *
@@ -90,6 +96,9 @@ import java.util.concurrent.TimeUnit;
 @RequestMapping("/app/live/liveOrder")
 public class LiveOrderController extends AppBaseController
 {
+    Logger logger= LoggerFactory.getLogger(getClass());
+    @Autowired
+    private RedissonClient redissonClient;
     @Autowired
     private ILiveOrderService orderService;
 
@@ -118,26 +127,6 @@ public class LiveOrderController extends AppBaseController
     @Autowired
     private HuiFuService huiFuService;
 
-    @Autowired
-    @Qualifier("erpOrderServiceImpl")
-    private IErpOrderService gyOrderService;
-
-    @Autowired
-    @Qualifier("wdtErpOrderServiceImpl")
-    private IErpOrderService wdtOrderService;
-
-    @Autowired
-    @Qualifier("k9OrderScrmServiceImpl")
-    private IErpOrderService k9OrderService;
-
-    @Autowired
-    private ConfigUtil configUtil;
-
-
-    @Autowired
-    private IFsExpressService expressService;
-    @Autowired
-    private JwtUtils jwtUtils;
 
     /**
      * 查询订单列表
@@ -316,6 +305,151 @@ public class LiveOrderController extends AppBaseController
         return orderService.createLiveOrder(param);
     }
 
+//    @Login
+//    @ApiOperation("支付")
+//    @PostMapping("/pay")
+//    @Transactional
+//    //@Synchronized
+//    public R pay(HttpServletRequest request, @Validated @RequestBody LiveOrderPayParam param)
+//    {
+//        LiveOrder order=orderService.selectLiveOrderByOrderId(String.valueOf(param.getOrderId()));
+//        if(order==null){
+//            return R.error("订单不存在");
+//        }
+//        if(order.getStatus()!= OrderInfoEnum.STATUS_0.getValue()){
+//            return R.error("订单状态不正确");
+//        }
+//        String orderId=redisCache.getCacheObject("isPaying:"+order.getOrderId());
+//        if(StringUtils.isNotEmpty(orderId)&&orderId.equals(order.getOrderId().toString())){
+//            return R.error("正在支付中...");
+//        }
+//
+//        FsUserScrm user=userService.selectFsUserById(Long.valueOf(order.getUserId()));
+//        if(user!=null&& StringUtils.isNotEmpty(user.getMaOpenId())){
+//            //已改价处理
+//            if(order.getIsEditMoney()!=null&&order.getIsEditMoney()==1){
+//                //改过价不做处理
+//
+//            }
+//            else{
+//                String config=configService.selectConfigByKey("his.store");
+//                StoreConfig storeConfig= JSONUtil.toBean(config,StoreConfig.class);
+//                if(param.getPayType().equals(1)){
+//                    order.setPayType("1");
+//                    order.setPayMoney(order.getPayPrice());
+//                    order.setPayDelivery(BigDecimal.ZERO);
+//                }
+//                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(0, BigDecimal.ROUND_HALF_UP).longValue());
+//                    order.setPayDelivery(order.getPayPrice().subtract(payMoney));
+//                    order.setPayMoney(payMoney);
+//                }
+//                else if(param.getPayType().equals(3)){
+//                    //货到付款
+//                    order.setPayType("3");
+//                    BigDecimal amount=redisCache.getCacheObject("orderAmount:"+order.getOrderId());
+//                    BigDecimal payMoney = BigDecimal.ZERO;
+//                    if (amount != null){
+//                        payMoney=amount;
+//                    }
+//                    order.setPayMoney(payMoney);
+//                    order.setPayDelivery(order.getPayPrice().subtract(payMoney) );
+////                    order.setPayMoney(BigDecimal.ZERO);
+//                }
+//                orderService.updateLiveOrder(order);
+//            }
+//            String payCode = IdUtil.getSnowflake(0, 0).nextIdStr();
+////            order.setOrderCode(orderCode);
+////            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){
+//                String json = configService.selectConfigByKey("his.pay");
+//                FsPayConfigScrm fsPayConfig = JSON.parseObject(json, FsPayConfigScrm.class);
+//                LiveOrderPayment storePayment=new LiveOrderPayment();
+//                storePayment.setCompanyId(order.getCompanyId());
+//                storePayment.setCompanyUserId(order.getCompanyUserId());
+//                storePayment.setPayMode(fsPayConfig.getType());
+//                storePayment.setStatus(0);
+//                storePayment.setPayCode(payCode);
+//                storePayment.setPayMoney(order.getPayMoney());
+//                storePayment.setCreateTime(new Date());
+//                storePayment.setPayTypeCode("weixin");
+//                storePayment.setBusinessType(2);
+//                storePayment.setRemark("直播订单支付");
+//                storePayment.setOpenId(user.getRealName());
+//                storePayment.setUserId(user.getUserId());
+//                storePayment.setBusinessId(String.valueOf(order.getOrderId()));
+//                liveOrderPaymentMapper.insertLiveOrderPayment(storePayment);
+//
+//                if (fsPayConfig.getType().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("直播订单支付");
+//                    if (param != null && StringUtils.isNotBlank(param.getAppId())) {
+//                        o.setAppId(param.getAppId());
+//                    }
+//                    HuifuCreateOrderResult result = huiFuService.createOrder(o);
+//                    if(result.getResp_code()!=null&&(result.getResp_code().equals("00000000")||result.getResp_code().equals("00000100"))){
+//                        LiveOrderPayment mt=new LiveOrderPayment();
+//                        mt.setPaymentId(storePayment.getPaymentId());
+//                        mt.setTradeNo(result.getHf_seq_id());
+//                        liveOrderPaymentMapper.updateLiveOrderPayment(mt);
+//                        redisCache.setCacheObject("isPaying:"+order.getOrderId(),order.getOrderId().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 (fsPayConfig.getType().equals("wx")){
+//                    WxPayConfig payConfig = new WxPayConfig();
+//                    payConfig.setAppId(fsPayConfig.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.setTotalFee(WxPayUnifiedOrderRequest.yuanToFen(money));//测试
+//                    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")){
+//            else if(order.getPayType().equals("3") && order.getPayMoney().compareTo(new BigDecimal(0))<=0){
+//                //货到付款
+//                orderService.payConfirm(2,order.getOrderId(),null,null,null,null);
+//                return R.ok().put("payType",param.getPayType());
+//            }
+//            return R.error();
+//        }
+//        else{
+//            return R.error("用户OPENID不存在");
+//        }
+//
+//    }
+
+    /*
     @Login
     @ApiOperation("支付")
     @PostMapping("/pay")
@@ -323,6 +457,37 @@ public class LiveOrderController extends AppBaseController
     //@Synchronized
     public R pay(HttpServletRequest request, @Validated @RequestBody LiveOrderPayParam param)
     {
+        Long orderId = param.getOrderId();
+        logger.info("开始处理支付请求, 订单号: {}, 支付类型: {}", orderId, param.getPayType());
+
+        RLock lock = redissonClient.getLock(String.format(LOCK_KEY_PAY,orderId));
+        R result = null;
+
+        try {
+            boolean locked = lock.tryLock(100, 30000, TimeUnit.MILLISECONDS);
+
+            if (!locked) {
+                logger.warn("订单正在处理中,获取锁失败, 订单号: {}", orderId);
+                return R.error("订单正在处理中,请勿重复提交");
+            }
+
+            result = orderService.pay(param);
+
+        } catch (InterruptedException e) {
+            logger.error("获取支付锁的过程被中断, 订单号: {}", orderId, e);
+            Thread.currentThread().interrupt();
+            return R.error("支付处理被中断,请稍后重试");
+        } catch (Throwable e) {
+            logger.error("支付过程中发生异常, 订单号: {}", orderId, e);
+            throw e;
+        } finally {
+            if (lock.isHeldByCurrentThread()) {
+                lock.unlock();
+                logger.debug("支付锁已释放, 订单号: {}", orderId);
+            }
+        }
+
+        return result;
         LiveOrder order=orderService.selectLiveOrderByOrderId(String.valueOf(param.getOrderId()));
         if(order==null){
             return R.error("订单不存在");
@@ -459,7 +624,92 @@ public class LiveOrderController extends AppBaseController
         }
 
     }
+        /**
+     * 获取订单详细信息
+     */
+    @Login
+    @GetMapping(value = "/info/{orderId}")
+    public AjaxResult getInfo(@PathVariable("orderId") String orderId)
+    {
+        log.info("获取订单详细信息 参数: {}",orderId);
 
+        return AjaxResult.success(orderService.selectLiveOrderByOrderId(orderId));
+    }
+
+    @Login
+    @ApiOperation("支付")
+    @PostMapping("/pay")
+    @Transactional
+    public R pay(HttpServletRequest request, @Validated @RequestBody LiveOrderPayParam param)
+    {
+        Long orderId = param.getOrderId();
+        logger.info("开始处理支付请求, 订单号: {}, 支付类型: {}", orderId, param.getPayType());
+
+        RLock lock = redissonClient.getLock(String.format(LOCK_KEY_PAY,orderId));
+        R result = null;
+
+        try {
+            boolean locked = lock.tryLock(100, 30000, TimeUnit.MILLISECONDS);
+
+            if (!locked) {
+                logger.warn("订单正在处理中,获取锁失败, 订单号: {}", orderId);
+                return R.error("订单正在处理中,请勿重复提交");
+            }
+
+            result = orderService.handleLiveOrderPay(param);
+
+        } catch (InterruptedException e) {
+            logger.error("获取支付锁的过程被中断, 订单号: {}", orderId, e);
+            Thread.currentThread().interrupt();
+            return R.error("支付处理被中断,请稍后重试");
+        } catch (Throwable e) {
+            logger.error("支付过程中发生异常, 订单号: {}", orderId, e);
+            throw e;
+        } finally {
+            if (lock.isHeldByCurrentThread()) {
+                lock.unlock();
+                logger.debug("支付锁已释放, 订单号: {}", orderId);
+            }
+        }
+
+        return result;
+    }
+
+    @Login
+    @ApiOperation("取消支付")
+    @PostMapping("/cancelPay")
+    public R cancelPay(@Validated @RequestBody LiveOrderPayParam param) {
+        Long orderId = param.getOrderId();
+        logger.info("用户取消支付 订单号: {}, 支付类型: {}", orderId, param.getPayType());
+        RLock lock = redissonClient.getLock(String.format(LOCK_KEY_PAY,orderId));
+        try {
+            boolean locked = lock.tryLock(100, 30000, TimeUnit.MILLISECONDS);
+            if (!locked) {
+                logger.warn("订单正在处理中,获取锁失败, 订单号: {}", orderId);
+                return R.error("订单正在处理中,请稍后再试");
+            }
+            handleCancelLiveOrderPay(param);
+            return R.ok();
+        } catch (InterruptedException e) {
+            logger.error("获取取消支付锁的过程被中断, 订单号: {}", orderId, e);
+            Thread.currentThread().interrupt();
+            return R.error("取消支付处理被中断,请稍后重试");
+        } catch (Throwable e) {
+            logger.error("取消支付过程中发生异常, 订单号: {}", orderId, e);
+            throw e;
+        } finally {
+            if (lock.isHeldByCurrentThread()) {
+                lock.unlock();
+                logger.debug("取消支付锁已释放, 订单号: {}", orderId);
+            }
+        }
+    }
+
+
+
+    private void handleCancelLiveOrderPay(LiveOrderPayParam param) {
+        redisCache.deleteObject("isPaying:"+param.getOrderId());
+    }
 
 
 
@@ -519,8 +769,6 @@ public class LiveOrderController extends AppBaseController
                 else if(param.getPayType().equals(3)){
                     //货到付款
                     order.setPayType("3");
-//                    order.setPayDelivery(order.getPayPrice() );
-//                    order.setPayMoney(BigDecimal.ZERO);
                     BigDecimal amount=redisCache.getCacheObject("orderAmount:"+order.getOrderId());
                     BigDecimal payMoney = BigDecimal.ZERO;
                     if (amount != null){