Browse Source

fixed 商户管理增加字段

fushengqian 1 year ago
parent
commit
157b701394

+ 3 - 3
fuint-application/src/main/java/com/fuint/common/enums/MerchantTypeEnum.java

@@ -7,9 +7,9 @@ package com.fuint.common.enums;
  * CopyRight https://www.fuint.cn
  */
 public enum MerchantTypeEnum {
-    RESTAURANT("restaurant", "餐饮"),
-    RETAIL("retail", "零售"),
-    SERVICE("service", "服务"),
+    RESTAURANT("restaurant", "餐饮:餐厅、奶茶、酒店等"),
+    RETAIL("retail", "零售:超市、生鲜、卖场等"),
+    SERVICE("service", "服务:美容、足浴、汽车4s店等"),
     OTHER("other", "其他");
 
     private String key;

+ 4 - 5
fuint-application/src/main/java/com/fuint/common/service/WeixinService.java

@@ -5,7 +5,6 @@ import com.fuint.framework.exception.BusinessCheckException;
 import com.fuint.framework.web.ResponseObject;
 import com.fuint.repository.model.MtOrder;
 import com.fuint.repository.model.MtUser;
-
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.math.BigDecimal;
@@ -20,7 +19,7 @@ import java.util.Date;
  */
 public interface WeixinService {
 
-    String getAccessToken(boolean useCache);
+    String getAccessToken(Integer merchantId, boolean useCache) throws BusinessCheckException ;
 
     ResponseObject createPrepayOrder(MtUser userInfo, MtOrder orderInfo, Integer payAmount, String authCode, Integer giveAmount, String ip, String platform) throws BusinessCheckException;
 
@@ -28,15 +27,15 @@ public interface WeixinService {
 
     void processRespXml(HttpServletResponse response, boolean flag);
 
-    JSONObject getWxProfile(String code);
+    JSONObject getWxProfile(Integer merchantId, String code) throws BusinessCheckException;
 
-    JSONObject getWxOpenId(String code);
+    JSONObject getWxOpenId(Integer merchantId, String code) throws BusinessCheckException;
 
     String getPhoneNumber(String encryptedData, String session_key, String iv);
 
     Boolean sendSubscribeMessage(Integer merchantId, Integer userId, String toUserOpenId, String key, String page, Map<String,Object> params, Date sendTime) throws BusinessCheckException;
 
-    Boolean doSendSubscribeMessage(String reqDataJsonStr);
+    Boolean doSendSubscribeMessage(Integer merchantId, String reqDataJsonStr);
 
     Map<String, String> queryPaidOrder(Integer storeId, String transactionId, String orderSn);
 

+ 4 - 1
fuint-application/src/main/java/com/fuint/common/service/impl/MerchantServiceImpl.java

@@ -111,7 +111,10 @@ public class MerchantServiceImpl extends ServiceImpl<MtMerchantMapper, MtMerchan
         if (merchant.getId() == null) {
             mtMerchant.setCreateTime(new Date());
         }
-
+        mtMerchant.setWxAppId(merchant.getWxAppId());
+        mtMerchant.setWxAppSecret(merchant.getWxAppSecret());
+        mtMerchant.setWxOfficialAppId(merchant.getWxOfficialAppId());
+        mtMerchant.setWxOfficialAppSecret(merchant.getWxOfficialAppSecret());
         mtMerchant.setDescription(merchant.getDescription());
         mtMerchant.setPhone(merchant.getPhone());
         mtMerchant.setAddress(merchant.getAddress());

+ 1 - 0
fuint-application/src/main/java/com/fuint/common/service/impl/OpenGiftServiceImpl.java

@@ -281,6 +281,7 @@ public class OpenGiftServiceImpl extends ServiceImpl<MtOpenGiftMapper, MtOpenGif
             }
             // 弹框消息
             MtMessage msg = new MtMessage();
+            msg.setMerchantId(user.getMerchantId());
             msg.setType(MessageEnum.POP_MSG.getKey());
             msg.setUserId(userId);
             msg.setTitle("温馨提示");

+ 60 - 10
fuint-application/src/main/java/com/fuint/common/service/impl/WeixinServiceImpl.java

@@ -71,6 +71,9 @@ public class WeixinServiceImpl implements WeixinService {
     @Autowired
     private PaymentService paymentService;
 
+    @Autowired
+    private MerchantService merchantService;
+
     @Autowired
     private Environment env;
 
@@ -81,22 +84,35 @@ public class WeixinServiceImpl implements WeixinService {
 
     private static final String REFUND_NOTIFY_URL = "/clientApi/pay/weixinRefundNotify";
 
+    private static final String FUINT_ACCESS_TOKEN_PRE = "FUINT_ACCESS_TOKEN";
+
     /**
      * 获取微信accessToken
-     * @param useCache 是否读取缓存
+     *
+     * @param merchantId 商户ID
+     * @param useCache   是否读取缓存
      * @return
      * */
     @Override
-    public String getAccessToken(boolean useCache) {
+    public String getAccessToken(Integer merchantId, boolean useCache) throws BusinessCheckException {
         String wxAppId = env.getProperty("wxpay.appId");
         String wxAppSecret = env.getProperty("wxpay.appSecret");
-        String wxTokenUrl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s";
+        String tokenKey = FUINT_ACCESS_TOKEN_PRE;
+        if (merchantId != null && merchantId > 0) {
+            MtMerchant mtMerchant = merchantService.queryMerchantById(merchantId);
+            if (mtMerchant != null && StringUtil.isNotEmpty(mtMerchant.getWxAppId()) && StringUtil.isNotEmpty(mtMerchant.getWxAppSecret())) {
+                wxAppId = mtMerchant.getWxAppId();
+                wxAppSecret = mtMerchant.getWxAppSecret();
+                tokenKey = tokenKey + merchantId;
+            }
+        }
 
+        String wxTokenUrl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s";
         String url = String.format(wxTokenUrl, wxAppId, wxAppSecret);
         String token = "";
 
         if (useCache) {
-            token = RedisUtil.get("FUINT_ACCESS_TOKEN");
+            token = RedisUtil.get(tokenKey);
         }
 
         if (token == null || StringUtil.isEmpty(token)) {
@@ -104,7 +120,7 @@ public class WeixinServiceImpl implements WeixinService {
                 String response = HttpRESTDataClient.requestGet(url);
                 JSONObject json = (JSONObject) JSONObject.parse(response);
                 if (!json.containsKey("errcode")) {
-                    RedisUtil.set("FUINT_ACCESS_TOKEN", json.get("access_token"), 7200);
+                    RedisUtil.set(tokenKey, json.get("access_token"), 7200);
                     token = (String) json.get("access_token");
                 } else {
                     logger.error("获取微信accessToken出错:" + json.get("errmsg"));
@@ -240,12 +256,24 @@ public class WeixinServiceImpl implements WeixinService {
 
     /**
      * 获取微信个人信息
+     *
+     * @param merchantId
+     * @param code
      * @return
      * */
     @Override
-    public JSONObject getWxProfile(String code) {
+    public JSONObject getWxProfile(Integer merchantId, String code) throws BusinessCheckException {
         String wxAppId = env.getProperty("wxpay.appId");
         String wxAppSecret = env.getProperty("wxpay.appSecret");
+
+        if (merchantId != null && merchantId > 0) {
+            MtMerchant mtMerchant = merchantService.queryMerchantById(merchantId);
+            if (mtMerchant != null && StringUtil.isNotEmpty(mtMerchant.getWxAppId()) && StringUtil.isNotEmpty(mtMerchant.getWxAppSecret())) {
+                wxAppId = mtMerchant.getWxAppId();
+                wxAppSecret = mtMerchant.getWxAppSecret();
+            }
+        }
+
         String wxAccessUrl = "https://api.weixin.qq.com/sns/jscode2session?appid=%s&secret=%s&js_code=%s&grant_type=authorization_code";
         String url = String.format(wxAccessUrl, wxAppId, wxAppSecret, code);
         try {
@@ -265,12 +293,24 @@ public class WeixinServiceImpl implements WeixinService {
 
     /**
      * 获取公众号openId
+     *
+     * @param merchantId
+     * @param code
      * @return
      * */
     @Override
-    public JSONObject getWxOpenId(String code) {
+    public JSONObject getWxOpenId(Integer merchantId, String code) throws BusinessCheckException {
         String wxAppId = env.getProperty("weixin.official.appId");
         String wxAppSecret = env.getProperty("weixin.official.appSecret");
+
+        if (merchantId != null && merchantId > 0) {
+            MtMerchant mtMerchant = merchantService.queryMerchantById(merchantId);
+            if (mtMerchant != null && StringUtil.isNotEmpty(mtMerchant.getWxOfficialAppId()) && StringUtil.isNotEmpty(mtMerchant.getWxOfficialAppSecret())) {
+                wxAppId = mtMerchant.getWxOfficialAppId();
+                wxAppSecret = mtMerchant.getWxOfficialAppSecret();
+            }
+        }
+
         String wxAccessUrl = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=%s&secret=%s&code=%s&grant_type=authorization_code";
         String url = String.format(wxAccessUrl, wxAppId, wxAppSecret, code);
         try {
@@ -391,6 +431,7 @@ public class WeixinServiceImpl implements WeixinService {
 
         // 存储到消息表里,后续通过定时任务发送
         MtMessage mtMessage = new MtMessage();
+        mtMessage.setMerchantId(merchantId);
         mtMessage.setUserId(userId);
         mtMessage.setType(MessageEnum.SUB_MSG.getKey());
         mtMessage.setTitle(WxMessageEnum.getValue(key));
@@ -406,14 +447,14 @@ public class WeixinServiceImpl implements WeixinService {
     }
 
     @Override
-    public Boolean doSendSubscribeMessage(String reqDataJsonStr) {
+    public Boolean doSendSubscribeMessage(Integer merchantId, String reqDataJsonStr) {
         try {
-            String url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=" + this.getAccessToken(true);
+            String url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=" + getAccessToken(merchantId, true);
             String response = HttpRESTDataClient.requestPost(url, "application/json; charset=utf-8", reqDataJsonStr);
             logger.info("WeixinService sendSubscribeMessage response={}", response);
             JSONObject json = (JSONObject) JSONObject.parse(response);
             if (json.get("errcode").toString().equals("40001")) {
-                this.getAccessToken(false);
+                getAccessToken(merchantId, false);
                 logger.error("发送订阅消息出错error1:" + json.get("errcode").toString());
                 return false;
             } else if (!json.get("errcode").toString().equals("0")) {
@@ -664,6 +705,15 @@ public class WeixinServiceImpl implements WeixinService {
         if (platform.equals(PlatformTypeEnum.H5.getCode())) {
             String wxAppId = env.getProperty("weixin.official.appId");
             String wxAppSecret = env.getProperty("weixin.official.appSecret");
+
+            if (mtStore != null) {
+                MtMerchant mtMerchant = merchantService.queryMerchantById(mtStore.getMerchantId());
+                if (mtMerchant != null && StringUtil.isNotEmpty(mtMerchant.getWxOfficialAppId()) && StringUtil.isNotEmpty(mtMerchant.getWxOfficialAppSecret())) {
+                    wxAppId = mtMerchant.getWxOfficialAppId();
+                    wxAppSecret = mtMerchant.getWxOfficialAppSecret();
+                }
+            }
+
             if (StringUtil.isNotEmpty(wxAppId) && StringUtil.isNotEmpty(wxAppSecret)) {
                 apiConfig.setAppId(wxAppId);
                 apiConfig.setApiKey(wxAppSecret);

+ 25 - 1
fuint-application/src/main/java/com/fuint/module/backendApi/controller/BackendMerchantController.java

@@ -2,6 +2,8 @@ package com.fuint.module.backendApi.controller;
 
 import com.fuint.common.Constants;
 import com.fuint.common.dto.AccountInfo;
+import com.fuint.common.dto.ParamDto;
+import com.fuint.common.enums.CouponTypeEnum;
 import com.fuint.common.enums.MerchantTypeEnum;
 import com.fuint.common.enums.StatusEnum;
 import com.fuint.common.service.MerchantService;
@@ -20,6 +22,7 @@ import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 import javax.servlet.http.HttpServletRequest;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -92,9 +95,21 @@ public class BackendMerchantController extends BaseController {
 
         String imagePath = settingService.getUploadBasePath();
 
+        // 商户类型列表
+        MerchantTypeEnum[] typeListEnum = MerchantTypeEnum.values();
+        List<ParamDto> typeList = new ArrayList<>();
+        for (MerchantTypeEnum enumItem : typeListEnum) {
+             ParamDto paramDto = new ParamDto();
+             paramDto.setKey(enumItem.getKey());
+             paramDto.setName(enumItem.getValue());
+             paramDto.setValue(enumItem.getKey());
+             typeList.add(paramDto);
+        }
+
         Map<String, Object> result = new HashMap<>();
         result.put("dataList", paginationResponse);
         result.put("imagePath", imagePath);
+        result.put("typeList", typeList);
 
         return getSuccessResult(result);
     }
@@ -178,8 +193,14 @@ public class BackendMerchantController extends BaseController {
         String address = params.get("address") == null ? "" : CommonUtil.replaceXSS(params.get("address").toString());
         String status = params.get("status") == null ? "" : CommonUtil.replaceXSS(params.get("status").toString());
         String logo = params.get("logo") == null ? "" : CommonUtil.replaceXSS(params.get("logo").toString());
+        String type = params.get("type") == null ? MerchantTypeEnum.RETAIL.getKey() : CommonUtil.replaceXSS(params.get("type").toString());
+        String wxAppId = params.get("wxAppId") == null ? "" : CommonUtil.replaceXSS(params.get("wxAppId").toString());
+        String wxAppSecret = params.get("wxAppSecret") == null ? "" : CommonUtil.replaceXSS(params.get("wxAppSecret").toString());
+        String wxOfficialAppId = params.get("wxOfficialAppId") == null ? "" : CommonUtil.replaceXSS(params.get("wxOfficialAppId").toString());
+        String wxOfficialAppSecret = params.get("wxOfficialAppSecret") == null ? "" : CommonUtil.replaceXSS(params.get("wxOfficialAppSecret").toString());
 
         MtMerchant merchantInfo = new MtMerchant();
+        merchantInfo.setType(type);
         merchantInfo.setName(name);
         merchantInfo.setNo(merchantNo);
         merchantInfo.setContact(contact);
@@ -187,8 +208,11 @@ public class BackendMerchantController extends BaseController {
         merchantInfo.setDescription(description);
         merchantInfo.setAddress(address);
         merchantInfo.setLogo(logo);
+        merchantInfo.setWxAppId(wxAppId);
+        merchantInfo.setWxAppSecret(wxAppSecret);
+        merchantInfo.setWxOfficialAppId(wxOfficialAppId);
+        merchantInfo.setWxOfficialAppSecret(wxOfficialAppSecret);
         merchantInfo.setStatus(status);
-        merchantInfo.setType(MerchantTypeEnum.RETAIL.getKey());
         if (accountInfo.getMerchantId() != null && accountInfo.getMerchantId() > 0) {
             merchantInfo.setId(accountInfo.getMerchantId());
         }

+ 17 - 5
fuint-application/src/main/java/com/fuint/module/clientApi/controller/ClientSignController.java

@@ -12,6 +12,7 @@ import com.fuint.common.util.TokenUtil;
 import com.fuint.framework.exception.BusinessCheckException;
 import com.fuint.framework.web.BaseController;
 import com.fuint.framework.web.ResponseObject;
+import com.fuint.repository.model.MtMerchant;
 import com.fuint.repository.model.MtStore;
 import com.fuint.repository.model.MtUser;
 import com.fuint.repository.model.MtVerifyCode;
@@ -90,11 +91,10 @@ public class ClientSignController extends BaseController {
         String storeId = request.getHeader("storeId") == null ? "0" : request.getHeader("storeId");
         String merchantNo = request.getHeader("merchantNo") == null ? "" : request.getHeader("merchantNo");
         JSONObject paramsObj = new JSONObject(param);
-
         logger.info("微信授权登录参数:{}", param);
-
+        Integer merchantId = merchantService.getMerchantId(merchantNo);
         JSONObject userInfo = paramsObj.getJSONObject("userInfo");
-        JSONObject loginInfo = weixinService.getWxProfile(param.get("code").toString());
+        JSONObject loginInfo = weixinService.getWxProfile(merchantId, param.get("code").toString());
         if (loginInfo == null) {
             return getFailureResult(0, "微信登录失败");
         }
@@ -115,7 +115,6 @@ public class ClientSignController extends BaseController {
             }
         }
         userInfo.put("storeId", storeId);
-        Integer merchantId = merchantService.getMerchantId(merchantNo);
         MtUser mtUser = memberService.queryMemberByOpenId(merchantId, loginInfo.get("openid").toString(), userInfo);
         if (mtUser == null) {
             return getFailureResult(0, "用户状态异常");
@@ -146,8 +145,11 @@ public class ClientSignController extends BaseController {
     @CrossOrigin
     public ResponseObject mpWxAuth(HttpServletRequest request, @RequestBody Map<String, Object> param) throws BusinessCheckException {
         String token = request.getHeader("Access-Token");
+        String merchantNo = request.getHeader("merchantNo") == null ? "" : request.getHeader("merchantNo");
         String storeId = request.getHeader("storeId") == null ? "0" : request.getHeader("storeId");
-        JSONObject mpUserInfo = weixinService.getWxOpenId(param.get("code").toString());
+
+        Integer merchantId = merchantService.getMerchantId(merchantNo);
+        JSONObject mpUserInfo = weixinService.getWxOpenId(merchantId, param.get("code").toString());
         if (mpUserInfo == null) {
             return getFailureResult(201, "微信公众号授权失败");
         }
@@ -232,8 +234,14 @@ public class ClientSignController extends BaseController {
             outParams.put("userName", userInfo.getName());
             outParams.put("token", token);
             outParams.put("openId", "");
+
             String domain = env.getProperty("website.url");
             String appId = env.getProperty("weixin.official.appId");
+            MtMerchant mtMerchant = merchantService.queryMerchantById(merchantId);
+            if (mtMerchant != null && StringUtil.isNotEmpty(mtMerchant.getWxOfficialAppId())) {
+                appId = mtMerchant.getWxOfficialAppId();
+            }
+
             outParams.put("domain", domain);
             outParams.put("appId", appId);
             return getSuccessResult("注册成功", outParams);
@@ -341,6 +349,10 @@ public class ClientSignController extends BaseController {
             outParams.put("openId", mtUser.getOpenId());
             String domain = env.getProperty("website.url");
             String appId = env.getProperty("weixin.official.appId");
+            MtMerchant mtMerchant = merchantService.queryMerchantById(merchantId);
+            if (mtMerchant != null && StringUtil.isNotEmpty(mtMerchant.getWxOfficialAppId())) {
+                appId = mtMerchant.getWxOfficialAppId();
+            }
             outParams.put("domain", domain);
             outParams.put("appId", appId);
             return getSuccessResult("登录成功", outParams);

+ 3 - 1
fuint-application/src/main/java/com/fuint/module/clientApi/controller/ClientUserController.java

@@ -227,19 +227,21 @@ public class ClientUserController extends BaseController {
     @CrossOrigin
     public ResponseObject saveInfo(HttpServletRequest request, @RequestBody Map<String, Object> param) throws BusinessCheckException {
         String token = request.getHeader("Access-Token");
+        String merchantNo = request.getHeader("merchantNo") == null ? "" : request.getHeader("merchantNo");
         String name = param.get("name") == null ? "" : param.get("name").toString();
         String birthday = param.get("birthday") == null ? "" : param.get("birthday").toString();
         String avatar = param.get("avatar") == null ? "" : param.get("avatar").toString();
         Integer sex = param.get("sex") == null ? 1 : Integer.parseInt(param.get("sex").toString());
         String code = param.get("code") == null ? "" : param.get("code").toString();
         String mobile = "";
+        Integer merchantId = merchantService.getMerchantId(merchantNo);
         UserInfo userInfo = TokenUtil.getUserInfoByToken(token);
         if (userInfo == null) {
             return getFailureResult(1001);
         }
 
         if (StringUtil.isNotEmpty(code)) {
-            JSONObject loginInfo = weixinService.getWxProfile(code);
+            JSONObject loginInfo = weixinService.getWxProfile(merchantId, code);
             if (loginInfo != null) {
                 mobile = weixinService.getPhoneNumber(param.get("encryptedData").toString(), loginInfo.get("session_key").toString(), param.get("iv").toString());
             }

+ 2 - 2
fuint-application/src/main/java/com/fuint/module/schedule/MessageJob.java

@@ -1,5 +1,6 @@
 package com.fuint.module.schedule;
 
+import com.fuint.common.service.MerchantService;
 import com.fuint.common.service.MessageService;
 import com.fuint.common.service.WeixinService;
 import com.fuint.framework.exception.BusinessCheckException;
@@ -13,7 +14,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Component;
 import org.springframework.transaction.annotation.Transactional;
-
 import java.util.Date;
 import java.util.List;
 
@@ -62,7 +62,7 @@ public class MessageJob {
                     Date nowTime = new Date();
                     // 如果到了发送时间,发送并删除该条消息
                     if (dealNum <= MAX_SEND_NUM && mtMessage.getSendTime().before(nowTime) && StringUtil.isNotEmpty(mtMessage.getParams())) {
-                        boolean result = weixinService.doSendSubscribeMessage(mtMessage.getParams());
+                        boolean result = weixinService.doSendSubscribeMessage(mtMessage.getMerchantId(), mtMessage.getParams());
                         messageService.sendMessage(mtMessage.getId(), result);
                         dealNum++;
                     }

+ 12 - 0
fuint-repository/src/main/java/com/fuint/repository/model/MtMerchant.java

@@ -31,6 +31,18 @@ public class MtMerchant implements Serializable {
     @ApiModelProperty("类型")
     private String type;
 
+    @ApiModelProperty("微信小程序appId")
+    private String wxAppId;
+
+    @ApiModelProperty("微信小程序秘钥")
+    private String wxAppSecret;
+
+    @ApiModelProperty("微信公众号appId")
+    private String wxOfficialAppId;
+
+    @ApiModelProperty("微信公众号秘钥")
+    private String wxOfficialAppSecret;
+
     @ApiModelProperty("商户号")
     private String no;
 

+ 3 - 1
fuint-repository/src/main/java/com/fuint/repository/model/MtMessage.java

@@ -28,6 +28,9 @@ public class MtMessage implements Serializable {
     @TableId(value = "ID", type = IdType.AUTO)
     private Integer id;
 
+    @ApiModelProperty("商户ID")
+    private Integer merchantId;
+
     @ApiModelProperty("用户ID")
     private Integer userId;
 
@@ -61,5 +64,4 @@ public class MtMessage implements Serializable {
     @ApiModelProperty("状态")
     private String status;
 
-
 }

+ 1 - 1
fuint-repository/src/main/resources/mapper/MtGoodsMapper.xml

@@ -2,7 +2,7 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.fuint.repository.mapper.MtGoodsMapper">
     <select id="getStoreGoodsList" resultType="com.fuint.repository.model.MtGoods">
-        select * from mt_goods t where (t.STORE_ID = #{storeId} or t.STORE_ID = 0) and t.STATUS = 'A' order by t.sort asc
+        select * from mt_goods t where (t.STORE_ID = #{storeId} or t.STORE_ID = 0) and t.MERCHANT_ID = #{merchantId} and t.STATUS = 'A' order by t.sort asc
     </select>
 
     <select id="searchStoreGoodsList" resultType="com.fuint.repository.model.MtGoods">