Pārlūkot izejas kodu

fixed 更新微信会员卡功能

fushengqian 1 gadu atpakaļ
vecāks
revīzija
cdde75e74b

+ 2 - 1
fuint-application/src/main/java/com/fuint/common/service/WeixinService.java

@@ -148,9 +148,10 @@ public interface WeixinService {
      * 开通微信卡券
      *
      * @param merchantId 商户ID
+     * @param wxCardId 微信会员卡ID
      * @return
      * */
-    String createWxCard(Integer merchantId) throws BusinessCheckException;
+    String createWxCard(Integer merchantId, String wxCardId) throws BusinessCheckException;
 
     /**
      * 创建微信卡券领取的二维码

+ 71 - 26
fuint-application/src/main/java/com/fuint/common/service/impl/WeixinServiceImpl.java

@@ -690,10 +690,11 @@ public class WeixinServiceImpl implements WeixinService {
      * 开通微信卡券
      *
      * @param merchantId 商户ID
+     * @param wxCardId 微信会员卡ID
      * @return
      * */
     @Override
-    public String createWxCard(Integer merchantId) throws BusinessCheckException {
+    public String createWxCard(Integer merchantId, String wxCardId) throws BusinessCheckException {
         String cardId = "";
         try {
             MtSetting mtSetting = settingService.querySettingByName(merchantId, UserSettingEnum.WX_MEMBER_CARD.getKey());
@@ -703,63 +704,107 @@ public class WeixinServiceImpl implements WeixinService {
             WxCardDto wxCardDto = JsonUtil.parseObject(mtSetting.getValue(), WxCardDto.class);
 
             String accessToken = getAccessToken(merchantId, false,true);
-            String url = "https://api.weixin.qq.com/card/create?access_token=" + accessToken;
+            String createUrl = "https://api.weixin.qq.com/card/create?access_token=" + accessToken;
+            String updateUrl = "https://api.weixin.qq.com/card/update?access_token=" + accessToken;
 
             Map<String, Object> params = new HashMap<>();
             Map<String, Object> card = new HashMap<>();
-            card.put("card_type", "MEMBER_CARD");
+            if (StringUtil.isEmpty(wxCardId)) {
+                card.put("card_type", "MEMBER_CARD");
+            }
             Map<String, Object> memberCard = new HashMap<>();
-            memberCard.put("background_pic_url", wxCardDto.getBackgroundUrl());
+            if (StringUtil.isNotEmpty(wxCardDto.getBackgroundUrl())) {
+                memberCard.put("background_pic_url", wxCardDto.getBackgroundUrl());
+            }
 
             // baseInfo
             Map<String, Object> baseInfo = new HashMap<>();
-            baseInfo.put("logo_url", wxCardDto.getLogoUrl());
-            baseInfo.put("brand_name", wxCardDto.getBrandName());
+            baseInfo.put("logo_url", "https://fuint-cn.oss-cn-shenzhen.aliyuncs.com/images/logo.png");
+            if (StringUtil.isEmpty(wxCardId)) {
+                baseInfo.put("brand_name", wxCardDto.getBrandName());
+            }
             baseInfo.put("code_type", "CODE_TYPE_TEXT");
             baseInfo.put("title", wxCardDto.getTitle());
             baseInfo.put("color", wxCardDto.getColor());
             baseInfo.put("notice", wxCardDto.getNotice());
-            baseInfo.put("service_phone", wxCardDto.getServicePhone());
+            if (StringUtil.isNotEmpty(wxCardDto.getServicePhone())) {
+                baseInfo.put("service_phone", wxCardDto.getServicePhone());
+            }
             baseInfo.put("description", wxCardDto.getDescription());
             Map<String, Object> dateInfo = new HashMap<>();
             dateInfo.put("type", "DATE_TYPE_PERMANENT");
-            baseInfo.put("date_info", dateInfo);
+            if (StringUtil.isEmpty(wxCardId)) {
+                baseInfo.put("date_info", dateInfo);
+            }
             Map<String, Object> sku = new HashMap<>();
             sku.put("quantity", Constants.ALL_ROWS);
-            baseInfo.put("sku", sku);
-            baseInfo.put("get_limit", 1);
-            baseInfo.put("use_custom_code", false);
-            baseInfo.put("bind_openid", false);
+            if (StringUtil.isEmpty(wxCardId)) {
+                baseInfo.put("sku", sku);
+                baseInfo.put("get_limit", 1);
+            }
+            if (StringUtil.isEmpty(wxCardId)) {
+                baseInfo.put("use_custom_code", false);
+                baseInfo.put("bind_openid", false);
+            }
             baseInfo.put("can_give_friend", false);
-            baseInfo.put("location_id_list", null);
-            baseInfo.put("custom_url_name", wxCardDto.getCustomUrlName());
-            baseInfo.put("custom_url", wxCardDto.getCustomUrl());
-            baseInfo.put("custom_url_sub_title", wxCardDto.getCustomUrlSubTitle());
+            if (StringUtil.isEmpty(wxCardId)) {
+                baseInfo.put("location_id_list", null);
+            }
+            if (StringUtil.isNotEmpty(wxCardDto.getCustomUrlName())) {
+                baseInfo.put("custom_url_name", wxCardDto.getCustomUrlName());
+            }
+            if (StringUtil.isNotEmpty(wxCardDto.getCustomUrl())) {
+                baseInfo.put("custom_url", wxCardDto.getCustomUrl());
+            }
+            if (StringUtil.isNotEmpty(wxCardDto.getCustomUrlSubTitle())) {
+                baseInfo.put("custom_url_sub_title", wxCardDto.getCustomUrlSubTitle());
+            }
             baseInfo.put("need_push_on_view", true);
             memberCard.put("base_info", baseInfo);
 
             // 特权说明
-            memberCard.put("prerogative", wxCardDto.getPrerogative());
+            if (StringUtil.isNotEmpty(wxCardDto.getPrerogative())) {
+                memberCard.put("prerogative", wxCardDto.getPrerogative());
+            }
             // 自动激活
             memberCard.put("auto_activate", true);
             memberCard.put("supply_bonus", wxCardDto.getSupplyBonus());
-            memberCard.put("bonus_url", wxCardDto.getBonusUrl());
-            memberCard.put("supply_balance", wxCardDto.getSupplyBalance());
-            memberCard.put("balance_url", wxCardDto.getBalanceUrl());
-
+            if (StringUtil.isNotEmpty(wxCardDto.getBonusUrl())) {
+                memberCard.put("bonus_url", wxCardDto.getBonusUrl());
+            }
+            if (StringUtil.isEmpty(wxCardId)) {
+                memberCard.put("supply_balance", wxCardDto.getSupplyBalance());
+            }
+            if (StringUtil.isNotEmpty(wxCardDto.getBalanceUrl())) {
+                memberCard.put("balance_url", wxCardDto.getBalanceUrl());
+            }
             card.put("member_card", memberCard);
-            params.put("card", card);
+            if (StringUtil.isEmpty(wxCardId)) {
+                params.put("card", card);
+            } else {
+                card.put("card_id", wxCardId);
+                params = card;
+            }
 
             ObjectMapper mapper = new ObjectMapper();
             String reqDataJson = mapper.writeValueAsString(params);
-
+            String url = createUrl;
+            if (StringUtil.isNotEmpty(wxCardId)) {
+                url = updateUrl;
+            }
+            logger.info("开通微信卡券接口url:{},请求参数:{}", url, reqDataJson);
             String response = HttpRESTDataClient.requestPost(url, "application/json; charset=utf-8", reqDataJson);
-            logger.error("开通微信卡券接口返回:{}", response);
+            logger.info("开通微信卡券接口返回:{}", response);
             JSONObject data = (JSONObject) JSONObject.parse(response);
             if (data.get("errcode").toString().equals("0")) {
-                cardId = data.get("card_id").toString();
+                if (StringUtil.isEmpty(wxCardId)) {
+                    cardId = data.get("card_id").toString();
+                } else {
+                    cardId = wxCardId;
+                }
             } else {
-                throw new BusinessCheckException("开通微信卡券出错啦:"+data.get("errmsg").toString());
+                logger.error("开通微信卡券出错啦{}", data.get("errmsg").toString());
+                throw new BusinessCheckException("开通微信卡券出错啦:" + data.get("errmsg").toString());
             }
         } catch (Exception e) {
             logger.error("开通微信卡券出错啦:{}", e.getMessage());

+ 6 - 5
fuint-application/src/main/java/com/fuint/module/backendApi/controller/BackendMemberController.java

@@ -460,9 +460,6 @@ public class BackendMemberController extends BaseController {
                 mtSetting.setValue(openWxCard);
             } else if (setting.getKey().equals(UserSettingEnum.WX_MEMBER_CARD.getKey())) {
                 mtSetting.setValue(wxMemberCard);
-                if (StringUtil.isEmpty(wxMemberCard)) {
-                    mtSetting.setValue(null);
-                }
             }
             mtSetting.setDescription(setting.getValue());
             mtSetting.setOperator(accountInfo.getAccountName());
@@ -475,8 +472,12 @@ public class BackendMemberController extends BaseController {
         MtSetting openCardSetting = settingService.querySettingByName(accountInfo.getMerchantId(), UserSettingEnum.OPEN_WX_CARD.getKey());
         MtSetting cardSetting = settingService.querySettingByName(accountInfo.getMerchantId(), UserSettingEnum.WX_MEMBER_CARD.getKey());
         MtSetting cardIdSetting = settingService.querySettingByName(accountInfo.getMerchantId(), UserSettingEnum.WX_MEMBER_CARD_ID.getKey());
-        if (openCardSetting != null && openCardSetting.getValue().equals(YesOrNoEnum.TRUE.getKey()) && cardIdSetting == null && cardSetting != null && accountInfo.getMerchantId() != null && accountInfo.getMerchantId() > 0) {
-            String cardId = weixinService.createWxCard(accountInfo.getMerchantId());
+        if (openCardSetting != null && openCardSetting.getValue().equals(YesOrNoEnum.TRUE.getKey()) && cardSetting != null && accountInfo.getMerchantId() != null && accountInfo.getMerchantId() > 0) {
+            String wxCardId = "";
+            if (cardIdSetting != null) {
+                wxCardId = cardIdSetting.getValue();
+            }
+            String cardId = weixinService.createWxCard(accountInfo.getMerchantId(), wxCardId);
             if (StringUtil.isNotEmpty(cardId)) {
                 MtSetting mtSetting = new MtSetting();
                 mtSetting.setType(SettingTypeEnum.USER.getKey());