|
|
|
@@ -1,11 +1,30 @@ |
|
|
|
package com.simple.service.impl; |
|
|
|
|
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.github.pagehelper.PageHelper; |
|
|
|
import com.github.pagehelper.PageInfo; |
|
|
|
import com.simple.common.ErrorCode; |
|
|
|
import com.simple.common.ResultData; |
|
|
|
import com.simple.domain.po.WxAppinfo; |
|
|
|
import com.simple.domain.po.WxMerchant; |
|
|
|
import com.simple.domain.po.WxPayAccount; |
|
|
|
import com.simple.domain.po.WxProfitSharingReceiver; |
|
|
|
import com.simple.enums.EnumAppType; |
|
|
|
import com.simple.enums.EnumProfitSharingReceiverType; |
|
|
|
import com.simple.enums.EnumProfitSharingStatus; |
|
|
|
import com.simple.enums.EnumProfitSharingType; |
|
|
|
import com.simple.mapper.WxAppinfoMapper; |
|
|
|
import com.simple.mapper.WxPayAccountMapper; |
|
|
|
import com.simple.mapper.WxProfitSharingReceiverMapper; |
|
|
|
import com.simple.pay.WxPayment; |
|
|
|
import com.simple.pay.WxProfitSharing; |
|
|
|
import com.simple.pay.WxProfitSharingP; |
|
|
|
import com.simple.pay.WxProfitSharingReceiverP; |
|
|
|
import com.simple.service.WxProfitSharingReceiverService; |
|
|
|
import com.simple.utils.BeanUtils; |
|
|
|
import com.simple.utils.Utility; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import com.simple.common.IdWorker; |
|
|
|
@@ -15,7 +34,10 @@ public class WxProfitSharingReceiverServiceImpl implements WxProfitSharingReceiv |
|
|
|
|
|
|
|
@Autowired |
|
|
|
WxProfitSharingReceiverMapper wxProfitSharingReceiverMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
WxAppinfoMapper wxAppinfoMapper; |
|
|
|
@Autowired |
|
|
|
WxPayAccountMapper wxPayAccountMapper; |
|
|
|
|
|
|
|
@Override |
|
|
|
public PageInfo<WxProfitSharingReceiver> listAsPage(WxProfitSharingReceiver record, Integer pageIndex, Integer pageSize) { |
|
|
|
@@ -43,12 +65,80 @@ public class WxProfitSharingReceiverServiceImpl implements WxProfitSharingReceiv |
|
|
|
public void deleteById(Long id) { |
|
|
|
wxProfitSharingReceiverMapper.deleteByPrimaryKey(id); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public ResultData addReceiver(WxMerchant merchant) { |
|
|
|
|
|
|
|
WxAppinfo subAppInfo = new WxAppinfo(); |
|
|
|
subAppInfo.setTenantId(merchant.getTenantId()); |
|
|
|
subAppInfo.setType(EnumAppType.C.getCode()); |
|
|
|
|
|
|
|
subAppInfo = wxAppinfoMapper.findList(subAppInfo).get(0); |
|
|
|
WxPayAccount payAccount = wxPayAccountMapper.selectByPrimaryKey(subAppInfo.getPayId()); |
|
|
|
//WxPayAccount mainPayAccount = wxPayAccountMapper.selectByPrimaryKey(new Long(EnumPayDomain.PAY_DOMAIN_MASTER_ACCOUNT_ID.getCode())); |
|
|
|
//WxAppinfo mainAppInfo = wxAppinfoMapper.selectByPrimaryKey(new Long(EnumPayDomain.PAY_DOMAIN_MASTER_APPINFO_ID.getCode())); |
|
|
|
|
|
|
|
|
|
|
|
WxProfitSharingReceiver receiver = new WxProfitSharingReceiver(); |
|
|
|
receiver.setMerchantId(merchant.getId().toString()); |
|
|
|
receiver.setSharingType(EnumProfitSharingType.PROFIT_SHARING_TYPE_WEICHAT.getCode()); |
|
|
|
receiver.setId(IdWorker.get().nextId()); |
|
|
|
receiver.setCreateTime(new Date()); |
|
|
|
receiver.setUpdateTime(new Date()); |
|
|
|
receiver.setReceiverAccount(merchant.getReceiverAccount().toString()); |
|
|
|
receiver.setReceiverComments(merchant.getName()); |
|
|
|
receiver.setReceiverType(EnumProfitSharingReceiverType.PROFIT_SHARING_RECEIVER_MERCHANT_ID.getCode()); |
|
|
|
receiver.setTrueName(merchant.getName()); |
|
|
|
|
|
|
|
//分账提交 |
|
|
|
WxProfitSharingReceiverP wxProfitSharingReceiverP = new WxProfitSharingReceiverP(); |
|
|
|
//wxProfitSharingP.setAppid(mainAppInfo.getAppId()); |
|
|
|
//wxProfitSharingP.setMch_id(mainPayAccount.getMchId()); |
|
|
|
wxProfitSharingReceiverP.setAppid(subAppInfo.getAppId()); |
|
|
|
wxProfitSharingReceiverP.setMch_id(payAccount.getMchId()); |
|
|
|
wxProfitSharingReceiverP.setSub_appid(subAppInfo.getAppId()); |
|
|
|
wxProfitSharingReceiverP.setSub_mch_id(payAccount.getMchId()); |
|
|
|
wxProfitSharingReceiverP.setNonce_str(Utility.generate32UUID()); |
|
|
|
|
|
|
|
|
|
|
|
JSONObject receiverJSON = new JSONObject(); |
|
|
|
receiverJSON.put("type",EnumProfitSharingReceiverType.PROFIT_SHARING_RECEIVER_MERCHANT_ID.getMessage()); |
|
|
|
receiverJSON.put("acount",merchant.getReceiverAccount()); |
|
|
|
receiverJSON.put("name",merchant.getName()); |
|
|
|
|
|
|
|
wxProfitSharingReceiverP.setReceiver(receiverJSON.toJSONString()); |
|
|
|
String response; |
|
|
|
try { |
|
|
|
wxProfitSharingReceiverP.setSign(WxPayment.createSign(BeanUtils.toStringMap(wxProfitSharingReceiverP), payAccount.getApiKey())); |
|
|
|
response = WxProfitSharing.addReceiver(BeanUtils.toStringMap(wxProfitSharingReceiverP)); |
|
|
|
}catch (Exception e) { |
|
|
|
return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_ADD_FAILED, e.getMessage()); |
|
|
|
} |
|
|
|
Map<String, String> returnMap = WxPayment.xmlToMap(response); |
|
|
|
String return_code = returnMap.get("return_code"); |
|
|
|
if (!"SUCCESS".equals(return_code)) { |
|
|
|
return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_ADD_FAILED.getCode(), returnMap.get("return_msg")); |
|
|
|
} |
|
|
|
|
|
|
|
if (!WxPayment.verifyNotify(returnMap,payAccount.getApiKey())){ |
|
|
|
return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_ADD_FAILED.getCode(), ErrorCode.PROFIT_SHARING_RETURN_INVALID.getMessage()); |
|
|
|
} |
|
|
|
|
|
|
|
String result_code = returnMap.get("result_code"); |
|
|
|
if (!"SUCCESS".equals(result_code)) { |
|
|
|
return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_ADD_FAILED.getCode(), returnMap.get("result_msg")); |
|
|
|
} |
|
|
|
|
|
|
|
wxProfitSharingReceiverMapper.insertSelective(receiver); |
|
|
|
return new ResultData(returnMap); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public ResultData delReceiver(WxMerchant merchant) { |
|
|
|
return new ResultData(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |