Parcourir la source

[商户][修改[分账账户更新及删除功能]

release_toaliyun_real
gongbiao il y a 7 ans
Parent
révision
c1721642f3
3 fichiers modifiés avec 68 ajouts et 82 suppressions
  1. +13
    -0
      mallinkBApi/src/main/java/com/iformall/controller/WxMerchantController.java
  2. +4
    -2
      mallinkService/src/main/java/com/iformall/service/WxProfitSharingReceiverService.java
  3. +51
    -80
      mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingReceiverServiceImpl.java

+ 13
- 0
mallinkBApi/src/main/java/com/iformall/controller/WxMerchantController.java Voir le fichier

@@ -3,6 +3,7 @@ package com.iformall.controller;
import com.iformall.common.ErrorCode;
import com.iformall.common.ResultData;
import com.iformall.domain.po.WxMerchant;
import com.iformall.domain.po.WxProfitSharingReceiver;
import com.iformall.service.WxMerchantService;
import com.iformall.service.WxProfitSharingReceiverService;
import io.swagger.annotations.Api;
@@ -67,4 +68,16 @@ public class WxMerchantController extends BaseController {
return wxMerchantService.updateMerchantAccount(wxMerchant);
}

@ApiOperation("删除分账账户")
@GetMapping("/deleteByMerchantId")
@ApiImplicitParam(name = "id", value = "商户分账账户ID", dataType = "Long", paramType = "query", required = true)
public ResultData deleteByMerchantId(@ModelAttribute WxProfitSharingReceiver receiver) {
log.debug("[" + getIpAddr() + "] WxMerchantController::deleteByMerchantId");
if (receiver.getId() == null) {
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "商户分账账户ID不能为空");
}
receiver.setTenantId(getTenantId());
return wxProfitSharingReceiverService.delReceiver(receiver);
}

}

+ 4
- 2
mallinkService/src/main/java/com/iformall/service/WxProfitSharingReceiverService.java Voir le fichier

@@ -5,6 +5,8 @@ import com.iformall.common.ResultData;
import com.iformall.domain.po.WxMerchant;
import com.iformall.domain.po.WxProfitSharingReceiver;

import java.util.List;

public interface WxProfitSharingReceiverService {

/**
@@ -41,9 +43,9 @@ public interface WxProfitSharingReceiverService {

WxProfitSharingReceiver findReceiver(WxMerchant merchant);

ResultData addReceiver(WxMerchant merchant, WxProfitSharingReceiver receiver);
ResultData addReceiver(WxMerchant merchant, WxProfitSharingReceiver receiver, List<WxProfitSharingReceiver> delList);

ResultData delReceiver(WxMerchant merchant);
ResultData delReceiver(WxProfitSharingReceiver receiver);

ResultData updateReceiver(WxMerchant merchant, WxProfitSharingReceiver receiver);



+ 51
- 80
mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingReceiverServiceImpl.java Voir le fichier

@@ -102,7 +102,7 @@ public class WxProfitSharingReceiverServiceImpl implements WxProfitSharingReceiv


@Override
public ResultData addReceiver(WxMerchant merchant, WxProfitSharingReceiver receiver) {
public ResultData addReceiver(WxMerchant merchant, WxProfitSharingReceiver receiver, List<WxProfitSharingReceiver> delList) {

WxAppinfo appInfo = new WxAppinfo();
appInfo.setTenantId(merchant.getTenantId());
@@ -169,6 +169,11 @@ public class WxProfitSharingReceiverServiceImpl implements WxProfitSharingReceiv

wxProfitSharingReceiverMapper.insertSelective(receiver);

//添加成功才删除账户
for (WxProfitSharingReceiver delReceiver : delList) {
delReceiver(delReceiver);
}

WxProfitSharingReceiver wxProfitSharingReceiver = new WxProfitSharingReceiver();
wxProfitSharingReceiver.setMerchantId(receiver.getMerchantId());
wxProfitSharingReceiver.setStatus(EnumProfitSharingReceiverStatus.PROFIT_SHARING_RECEIVER_STATUS_INVALID.getCode());
@@ -176,11 +181,9 @@ public class WxProfitSharingReceiverServiceImpl implements WxProfitSharingReceiv

if (size == 0) {
//发送添加短信
sendMsgByType(EnumMsgModel.ADD_SHARING_ACCOUNT_NOTIFY_MANAGER.getCode(), merchant.getId(), receiver.getReceiverAccount(), receiver.getTenantId());
sendMsgByType(EnumMsgModel.ADD_SHARING_ACCOUNT_NOTIFY_MERCHANT.getCode(), merchant.getId(), receiver.getReceiverAccount(), receiver.getTenantId());
} else {
//添加变更短信
sendMsgByType(EnumMsgModel.UPDATE_SHARING_ACCOUNT_NOTIFY_MANAGER.getCode(), merchant.getId(), receiver.getReceiverAccount(), receiver.getTenantId());
sendMsgByType(EnumMsgModel.UPDATE_SHARING_ACCOUNT_NOTIFY_MERCHANT.getCode(), merchant.getId(), receiver.getReceiverAccount(), receiver.getTenantId());
}
return new ResultData(returnMap);
@@ -199,13 +202,6 @@ public class WxProfitSharingReceiverServiceImpl implements WxProfitSharingReceiv
String merchantName = wxMerchant.getMerchantName();
Set<String> managerPhone = wxMerchant.getShopVoList().parallelStream().map(s -> s.getLinkPhone())
.filter(phone -> StringUtils.isNotEmpty(phone)).collect(Collectors.toSet());
if (type.equals(EnumMsgModel.ADD_SHARING_ACCOUNT_NOTIFY_MANAGER.getCode()) ||
type.equals(EnumMsgModel.UPDATE_SHARING_ACCOUNT_NOTIFY_MANAGER.getCode())) {
//添加时发给商管 变更时发送商管
for (String phone : managerPhone) {
sendMsg(phone, null, merchantName, null, type, tenantId);
}
}
if (type.equals(EnumMsgModel.ADD_SHARING_ACCOUNT_NOTIFY_MERCHANT.getCode()) ||
type.equals(EnumMsgModel.UPDATE_SHARING_ACCOUNT_NOTIFY_MERCHANT.getCode())) {
//添加时发送商户
@@ -248,89 +244,65 @@ public class WxProfitSharingReceiverServiceImpl implements WxProfitSharingReceiv
}

@Override
public ResultData delReceiver(WxMerchant merchant) {
public ResultData delReceiver(WxProfitSharingReceiver receiver) {
WxAppinfo appInfo = new WxAppinfo();
appInfo.setTenantId(merchant.getTenantId());
appInfo.setTenantId(receiver.getTenantId());
appInfo.setType(EnumAppType.C.getCode());

appInfo = wxAppinfoMapper.findList(appInfo).get(0);
WxPayAccount payAccount = wxPayAccountMapper.selectByPrimaryKey(appInfo.getPayId());

WxProfitSharingReceiver receiver = new WxProfitSharingReceiver();
receiver.setTenantId(merchant.getTenantId());
receiver.setMerchantId(merchant.getId());
receiver.setSharingType(EnumProfitSharingType.PROFIT_SHARING_TYPE_WECHAT.getCode());
receiver.setStatus(EnumProfitSharingReceiverStatus.PROFIT_SHARING_RECEIVER_STATUS_VALID.getCode());
//receiver.setReceiverAccount(receiverParam.getReceiverAccount());
//receiver.setReceiverType(receiverParam.getReceiverType());

receiver = wxProfitSharingReceiverMapper.selectOne(receiver);
receiver = wxProfitSharingReceiverMapper.selectByPrimaryKey(receiver.getId());

if (receiver == null)
return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getCode(), ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getMessage());

//删除分账账户从微信服务器
WxProfitSharingReceiverP wxProfitSharingReceiverP = new WxProfitSharingReceiverP();
wxProfitSharingReceiverP.setAppid(appInfo.getParentAppId());
wxProfitSharingReceiverP.setMch_id(payAccount.getMchId());
wxProfitSharingReceiverP.setSub_appid(appInfo.getAppId());
wxProfitSharingReceiverP.setSub_mch_id(payAccount.getSubMchId());
wxProfitSharingReceiverP.setNonce_str(Utility.generate32UUID());
wxProfitSharingReceiverP.setSign_type("HMAC-SHA256");

//检查此接受者是否注册在同一个商场的别的商户下

final WxProfitSharingReceiver receiverParam = receiver;
WxProfitSharingReceiver params = new WxProfitSharingReceiver();
params.setTenantId(merchant.getTenantId());
params.setStatus(EnumProfitSharingReceiverStatus.PROFIT_SHARING_RECEIVER_STATUS_VALID.getCode());
List<WxProfitSharingReceiver> receiverList = wxProfitSharingReceiverMapper.findList(params);
if (receiverList.stream().anyMatch(r -> (
r.getReceiverType().equals(receiverParam.getReceiverType()) &&
r.getReceiverAccount().equals(receiverParam.getReceiverAccount()) &&
r.getTrueName().equals(receiverParam.getTrueName()) &&
!r.getMerchantId().equals(receiverParam.getMerchantId())
))) {
//还有别的商户使用这个账号,不从微信服务器申请删除
} else {
//删除分账账户从微信服务器
WxProfitSharingReceiverP wxProfitSharingReceiverP = new WxProfitSharingReceiverP();
wxProfitSharingReceiverP.setAppid(appInfo.getParentAppId());
wxProfitSharingReceiverP.setMch_id(payAccount.getMchId());
wxProfitSharingReceiverP.setSub_appid(appInfo.getAppId());
wxProfitSharingReceiverP.setSub_mch_id(payAccount.getSubMchId());
wxProfitSharingReceiverP.setNonce_str(Utility.generate32UUID());
wxProfitSharingReceiverP.setSign_type("HMAC-SHA256");

JSONObject receiverJSON = new JSONObject();
receiverJSON.put("type", EnumProfitSharingReceiverType.getEnum(receiver.getReceiverType()).getMessage());
receiverJSON.put("account", receiver.getReceiverAccount());

wxProfitSharingReceiverP.setReceiver(receiverJSON.toJSONString());
String response;
try {
wxProfitSharingReceiverP.setSign(WxPayment.createSignHMAC(BeanUtils.toStringMap(wxProfitSharingReceiverP), payAccount.getApiKey()));
response = WxProfitSharing.delReceiver(BeanUtils.toStringMap(wxProfitSharingReceiverP));
} catch (Exception e) {
logger.error(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getMessage() + e.getMessage());
return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED, e.getMessage());
}
Map<String, String> returnMap = WxPayment.xmlToMap(response);
String return_code = returnMap.get("return_code");
if (!"SUCCESS".equals(return_code)) {
logger.error(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getMessage() + returnMap.get("return_msg"));
return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getCode(), returnMap.get("return_msg"));
}
JSONObject receiverJSON = new JSONObject();
receiverJSON.put("type", EnumProfitSharingReceiverType.getEnum(receiver.getReceiverType()).getMessage());
receiverJSON.put("account", receiver.getReceiverAccount());

wxProfitSharingReceiverP.setReceiver(receiverJSON.toJSONString());
String response;
try {
wxProfitSharingReceiverP.setSign(WxPayment.createSignHMAC(BeanUtils.toStringMap(wxProfitSharingReceiverP), payAccount.getApiKey()));
response = WxProfitSharing.delReceiver(BeanUtils.toStringMap(wxProfitSharingReceiverP));
} catch (Exception e) {
logger.error(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getMessage() + e.getMessage());
return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED, e.getMessage());
}
Map<String, String> returnMap = WxPayment.xmlToMap(response);
String return_code = returnMap.get("return_code");
if (!"SUCCESS".equals(return_code)) {
logger.error(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getMessage() + returnMap.get("return_msg"));
return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getCode(), returnMap.get("return_msg"));
}

String result_code = returnMap.get("result_code");
if (!"SUCCESS".equals(result_code)) {
String result_code = returnMap.get("result_code");
if (!"SUCCESS".equals(result_code)) {

if (returnMap.get("err_code").contains("USER_NOT_EXIST")) {
receiver.setStatus(EnumProfitSharingReceiverStatus.PROFIT_SHARING_RECEIVER_STATUS_INVALID.getCode());
receiver.setUpdateTime(new Date());
wxProfitSharingReceiverMapper.updateByPrimaryKeySelective(receiver);
}
logger.error(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getMessage() + returnMap.get("err_code_des"));
return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getCode(), returnMap.get("err_code_des"));
if (returnMap.get("err_code").contains("USER_NOT_EXIST")) {
receiver.setStatus(EnumProfitSharingReceiverStatus.PROFIT_SHARING_RECEIVER_STATUS_INVALID.getCode());
receiver.setUpdateTime(new Date());
wxProfitSharingReceiverMapper.updateByPrimaryKeySelective(receiver);
}
logger.error(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getMessage() + returnMap.get("err_code_des"));
return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getCode(), returnMap.get("err_code_des"));
}

if (!WxPayment.verifyNotifyHMAC(returnMap, payAccount.getApiKey())) {
logger.error(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getMessage());
return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getCode(), "verifyNotifyHMAC");
}
if (!WxPayment.verifyNotifyHMAC(returnMap, payAccount.getApiKey())) {
logger.error(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getMessage());
return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getCode(), "verifyNotifyHMAC");
}

receiver.setStatus(EnumProfitSharingReceiverStatus.PROFIT_SHARING_RECEIVER_STATUS_INVALID.getCode());
receiver.setUpdateTime(new Date());
wxProfitSharingReceiverMapper.updateByPrimaryKeySelective(receiver);
@@ -345,7 +317,7 @@ public class WxProfitSharingReceiverServiceImpl implements WxProfitSharingReceiv
oldReceiver.setMerchantId(merchant.getId());
oldReceiver.setSharingType(EnumProfitSharingType.PROFIT_SHARING_TYPE_WECHAT.getCode());
oldReceiver.setStatus(EnumProfitSharingReceiverStatus.PROFIT_SHARING_RECEIVER_STATUS_VALID.getCode());
List<WxProfitSharingReceiver> delList = wxProfitSharingReceiverMapper.select(oldReceiver);
oldReceiver.setReceiverAccount(receiver.getReceiverAccount());
oldReceiver.setReceiverType(receiver.getReceiverType());
oldReceiver.setTrueName(receiver.getTrueName());
@@ -353,8 +325,7 @@ public class WxProfitSharingReceiverServiceImpl implements WxProfitSharingReceiv
oldReceiver = wxProfitSharingReceiverMapper.selectOne(oldReceiver);

if (oldReceiver == null) {
delReceiver(merchant);
return addReceiver(merchant, receiver);
return addReceiver(merchant, receiver, delList);
} else {
oldReceiver.setParameter(receiver.getParameter());
oldReceiver.setUpdateTime(new Date());


Chargement…
Annuler
Enregistrer