From 55402cc48ecee2ac135624db4d31119b459a1be7 Mon Sep 17 00:00:00 2001
From: puhanshu <a9236326>
Date: 星期五, 14 一月 2022 15:59:51 +0800
Subject: [PATCH] 商业街bug修改

---
 springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/McsOrderServiceImpl.java |   36 +++++++++++++++++++++++++++++-------
 1 files changed, 29 insertions(+), 7 deletions(-)

diff --git a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/McsOrderServiceImpl.java b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/McsOrderServiceImpl.java
index 0719c85..3624ae3 100644
--- a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/McsOrderServiceImpl.java
+++ b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/McsOrderServiceImpl.java
@@ -1,5 +1,6 @@
 package com.panzhihua.service_community.service.impl;
 
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -14,6 +15,7 @@
 import com.panzhihua.service_community.dao.McsOrderDao;
 import com.panzhihua.service_community.service.McsMerchantService;
 import com.panzhihua.service_community.service.McsOrderService;
+import com.panzhihua.service_community.util.QRCodeUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.amqp.rabbit.core.RabbitTemplate;
 import org.springframework.beans.BeanUtils;
@@ -24,6 +26,8 @@
 import javax.annotation.Resource;
 import java.math.BigDecimal;
 import java.util.Date;
+
+import static java.util.Objects.nonNull;
 
 /**
  * 商业街订单表(McsOrder)表服务实现类
@@ -42,12 +46,14 @@
     private String payKey;
     @Value("${min.app.mchId}")
     private String mchId;
-    //@Value("${min.app.notifyUrl}")
-    private String notifyUrl="http://387405oo37.zicp.vip/mcsOrder/wxNotify";
+    @Value("${mcs.notifyUrl}")
+    private String notifyUrl;
     @Resource
     private RabbitTemplate rabbitTemplate;
     @Resource
     private McsMerchantService mcsMerchantService;
+
+    private static String H5_LOGIN_APPID="wx475fcd33c8030df8";
     @Override
     public R pageList(CommonPage commonPage) {
         return R.ok(this.baseMapper.pageList(new Page(commonPage.getPage(),commonPage.getSize()),commonPage));
@@ -70,7 +76,11 @@
 
     @Override
     public R detail(Long id) {
-        return R.ok(this.baseMapper.detail(id));
+        McsOrderVO detail = this.baseMapper.detail(id);
+        Date cancelAt = DateUtils.addMinutes(detail.getCreateTime(), 30);
+        Date nowDate = new Date();
+        detail.setCancelCountdown(cancelAt.getTime() - nowDate.getTime());
+        return R.ok(detail);
     }
 
     @Override
@@ -83,8 +93,16 @@
                     money = BigDecimal.valueOf(0.01);
                 }
                 // 调用wx支付
-                String result= WxPayUtils.h5pay(appid, mchId, payKey, notifyUrl, "点亮支付", mcsOrderVO.getOpenId(),
-                        mcsOrder.getOrderNo(), money,mcsOrderVO.getTradeType());
+                String realAppId=appid;
+                if(mcsOrderVO.getTradeType().equals("JSAPI")){
+                    realAppId=H5_LOGIN_APPID;
+                }
+                String result = WxPayUtils.h5pay(realAppId, mchId, payKey, notifyUrl, "点亮支付", mcsOrderVO.getOpenId(),
+                        mcsOrder.getOrderNo(), money,mcsOrderVO.getTradeType(), mcsOrderVO.getClientIp());
+                if (mcsOrderVO.getTradeType().equals("NATIVE")) {
+                    JSONObject jsonObjectResult = JSONObject.parseObject(result);
+                    result = QRCodeUtil.getBase64QRCode(jsonObjectResult.get("codeUrl").toString());
+                }
                 return R.ok(result);
             } catch (Exception e) {
                 log.error("调用微信支付异常,异常原因:" + e.getMessage());
@@ -110,12 +128,16 @@
     @Transactional
     public R notify(McsOrderVO mcsOrderVO) {
         McsOrder mcsOrderBase=this.baseMapper.selectOne(new QueryWrapper<McsOrder>().lambda().eq(McsOrder::getOrderNo,mcsOrderVO.getOrderNo()));
-        mcsOrderBase.setStatus(2);
+        mcsOrderBase.setStatus(1);
         mcsOrderBase.setPayNo(mcsOrderVO.getPayNo());
         mcsOrderBase.setPayTime(mcsOrderVO.getPayTime());
         int i=this.baseMapper.updateById(mcsOrderBase);
         if(i>0){
-            mcsMerchantService.updateOrAddMcsMerchantAfterOrder(mcsOrderBase.getMerchantName(),mcsOrderBase.getConfigId(),mcsOrderBase.getUserId());
+            R r = mcsMerchantService.updateOrAddMcsMerchantAfterOrder(mcsOrderBase.getMerchantName(), mcsOrderBase.getConfigId(), mcsOrderBase.getUserId());
+            if (R.isOk(r) && nonNull(r.getData())) {
+                mcsOrderBase.setMerchantId(JSONObject.parseObject(JSONObject.toJSONString(r.getData()), Long.class));
+                this.baseMapper.updateById(mcsOrderBase);
+            }
         }
         return R.ok();
     }

--
Gitblit v1.7.1