|
|
|
@@ -18,6 +18,7 @@ import com.simple.mapper.*; |
|
|
|
import com.simple.pay.WxPayment; |
|
|
|
import com.simple.pay.WxProfitSharing; |
|
|
|
import com.simple.pay.WxProfitSharingP; |
|
|
|
import com.simple.pay.WxProfitSharingQueryP; |
|
|
|
import com.simple.service.WxProfitSharingOrderService; |
|
|
|
import com.simple.utils.BeanUtils; |
|
|
|
import com.simple.utils.Utility; |
|
|
|
@@ -48,6 +49,8 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ |
|
|
|
@Autowired |
|
|
|
WxProfitSharingResultMapper wxProfitSharingResultMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
WxCUserMapper wxCUserMapper; |
|
|
|
|
|
|
|
|
|
|
|
final JSONObject errorMap = JSON.parseObject( |
|
|
|
@@ -63,6 +66,27 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ |
|
|
|
"\"NOAUTH \":{\"detail\":\"无分账权限\",\"reason\":\"未开通分账权限\",\"resolution\":\"请先开通分账权限\"}," + |
|
|
|
"\"NOT_SHARE_ORDER\":{\"detail\":\"非分账订单\t\",\"reason\":\"不是分账订单,无法分账\",\"resolution\":\"下单时请用合适的参数\"}}"); |
|
|
|
|
|
|
|
final JSONObject errorMapQuery = JSON.parseObject( |
|
|
|
"{\"SYSTEMERROR\":{\"detail\":\"接口返回错误\",\"reason\":\"系统超时\",\"resolution\":\"系统异常,请用相同参数重新调用\"}," + |
|
|
|
"\"INVALID_TRANSACTIONID\":{\"detail\":\"无效的微信支付订单号\",\"reason\":\"请求参数未按指引进行填写\",\"resolution\":\"检查原交易单号是否存在\"}," + |
|
|
|
"\"PARAM_ERROR\":{\"detail\":\"参数错误\t\",\"reason\":\"请求参数未按指引进行填写\",\"resolution\":\"请求参数错误,请重新检查再调用分账接口\"}," + |
|
|
|
"\"INVALID_REQUEST\":{\"detail\":\"请求不合法\",\"reason\":\"参数中APPID或MCHID不存在等 \",\"resolution\":\"请重新检查再调用分账接口\"}," + |
|
|
|
"\"ORDERNOTEXIST\":{\"detail\":\"分账单不存在\",\"reason\":\"订单号错误或分账单号错误\",\"resolution\":\"请检查订单号或分账单号是否有错误\"}" ); |
|
|
|
|
|
|
|
|
|
|
|
final JSONObject statusMap = JSON.parseObject( |
|
|
|
"{\"ACCEPTED\":3," + |
|
|
|
"\"PROCESSING\":4" + |
|
|
|
"\"FINISHED\":5" + |
|
|
|
"\"CLOSED\":6}"); |
|
|
|
|
|
|
|
final JSONObject resultStatusMap = JSON.parseObject( |
|
|
|
"{\"PENDING\":1," + |
|
|
|
"\"SUCCESS\":2" + |
|
|
|
"\"ADJUST\":3" + |
|
|
|
"\"RETURNED\":4" + |
|
|
|
"\"CLOSED\":5}"); |
|
|
|
|
|
|
|
@Override |
|
|
|
public PageInfo<WxProfitSharingOrder> listAsPage(WxProfitSharingOrder record, Integer pageIndex, Integer pageSize) { |
|
|
|
return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxProfitSharingOrderMapper.findList(record)); |
|
|
|
@@ -95,17 +119,37 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ |
|
|
|
|
|
|
|
@Override |
|
|
|
public void test() { |
|
|
|
createSharingOrder(wxAppinfoMapper.selectByPrimaryKey(new Long(1L)),wxPayOrderMapper.selectByPrimaryKey(new Long(190403470006681600L))); |
|
|
|
createSharingOrder(wxPayOrderMapper.selectByPrimaryKey(new Long(190403470006681600L))); |
|
|
|
} |
|
|
|
|
|
|
|
private WxAppinfo getAppinfo(WxPayOrder wxPayOrder) { |
|
|
|
WxAppinfo wxAppinfo; |
|
|
|
|
|
|
|
WxCUser wxCUser = wxCUserMapper.selectByPrimaryKey(wxPayOrder.getCUserId()); |
|
|
|
if (wxCUser == null) |
|
|
|
throw new MallinkException(ErrorCode.USER_IS_EMPTY.getCode(), ErrorCode.USER_IS_EMPTY.getMessage()); |
|
|
|
wxAppinfo = wxAppinfoMapper.selectByPrimaryKey(wxCUser.getAppId()); |
|
|
|
if (wxAppinfo == null) |
|
|
|
throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND.getCode(), ErrorCode.APP_ID_NOT_FOUND.getMessage()); |
|
|
|
|
|
|
|
return wxAppinfo; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public ResultData createSharingOrder(WxAppinfo subAppInfo, WxPayOrder wxPayOrder) { |
|
|
|
public ResultData createSharingOrder(WxPayOrder wxPayOrder) { |
|
|
|
final IdWorker idworker = IdWorker.get(); |
|
|
|
|
|
|
|
WxProfitSharingOrder record = new WxProfitSharingOrder(); |
|
|
|
try { |
|
|
|
|
|
|
|
WxAppinfo subAppInfo = getAppinfo(wxPayOrder); |
|
|
|
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())); |
|
|
|
|
|
|
|
WxOrder wxOrder = wxOrderMapper.selectByPrimaryKey(wxPayOrder.getOrderId()); |
|
|
|
|
|
|
|
//是否已创建分账订单 |
|
|
|
WxProfitSharingOrder record = new WxProfitSharingOrder(); |
|
|
|
record.setOrderId(wxPayOrder.getId().toString()); |
|
|
|
record = wxProfitSharingOrderMapper.selectOne(record); |
|
|
|
if (record == null) { |
|
|
|
@@ -126,10 +170,6 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ |
|
|
|
wxProfitSharingOrderMapper.insertSelective(record); |
|
|
|
} |
|
|
|
|
|
|
|
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())); |
|
|
|
|
|
|
|
//分账提交 |
|
|
|
WxProfitSharingP wxProfitSharingP = new WxProfitSharingP(); |
|
|
|
//wxProfitSharingP.setAppid(mainAppInfo.getAppId()); |
|
|
|
@@ -211,4 +251,98 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ |
|
|
|
throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public ResultData querySharingOrder(WxPayOrder wxPayOrder) { |
|
|
|
|
|
|
|
WxProfitSharingOrder record = new WxProfitSharingOrder(); |
|
|
|
try { |
|
|
|
WxAppinfo subAppInfo = getAppinfo(wxPayOrder); |
|
|
|
WxPayAccount payAccount = wxPayAccountMapper.selectByPrimaryKey(subAppInfo.getPayId()); |
|
|
|
//WxPayAccount mainPayAccount = wxPayAccountMapper.selectByPrimaryKey(new Long(EnumPayDomain.PAY_DOMAIN_MASTER_ACCOUNT_ID.getCode())); |
|
|
|
|
|
|
|
WxOrder wxOrder = wxOrderMapper.selectByPrimaryKey(wxPayOrder.getOrderId()); |
|
|
|
|
|
|
|
//是否已创建分账订单 |
|
|
|
record.setOrderId(wxPayOrder.getId().toString()); |
|
|
|
record = wxProfitSharingOrderMapper.selectOne(record); |
|
|
|
if (record == null) |
|
|
|
throw new MallinkException(ErrorCode.ORDER_IS_NOT_FIND.getCode(), ErrorCode.ORDER_IS_NOT_FIND.getMessage()); |
|
|
|
|
|
|
|
//分账提交 |
|
|
|
WxProfitSharingQueryP wxProfitSharingQueryP = new WxProfitSharingQueryP(); |
|
|
|
//wxProfitSharingP.setMch_id(mainPayAccount.getMchId()); |
|
|
|
wxProfitSharingQueryP.setMch_id(payAccount.getMchId()); |
|
|
|
wxProfitSharingQueryP.setSub_mch_id(payAccount.getMchId()); |
|
|
|
wxProfitSharingQueryP.setNonce_str(Utility.generate32UUID()); |
|
|
|
wxProfitSharingQueryP.setTransaction_id(wxPayOrder.getTransactionId()); |
|
|
|
wxProfitSharingQueryP.setOut_trade_no(record.getId().toString()); |
|
|
|
|
|
|
|
wxProfitSharingQueryP.setSign(WxPayment.createSign(BeanUtils.toStringMap(wxProfitSharingQueryP), payAccount.getApiKey())); |
|
|
|
String response = WxProfitSharing.pushOrder(BeanUtils.toStringMap(wxProfitSharingQueryP)); |
|
|
|
|
|
|
|
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_QUERY_REQUEST_FAILED.getCode(), returnMap.get("return_msg")); |
|
|
|
} |
|
|
|
|
|
|
|
if (!WxPayment.verifyNotify(returnMap,payAccount.getApiKey())){ |
|
|
|
return new ResultData(ErrorCode.PROFIT_SHARING_QUERY_RETURN_INVALID.getCode(), ErrorCode.PROFIT_SHARING_RETURN_INVALID.getMessage()); |
|
|
|
} |
|
|
|
|
|
|
|
String out_order_no = returnMap.get("out_order_no"); |
|
|
|
if (!out_order_no.equals(record.getId().toString())){ |
|
|
|
return new ResultData(ErrorCode.PROFIT_SHARING_QUERY_RETURN_INVALID.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_QUERY_APPLY_FAILED.getCode(), returnMap.get("result_msg")); |
|
|
|
} |
|
|
|
|
|
|
|
record.setSharingStatus((Integer) statusMap.get(returnMap.get("status"))); |
|
|
|
record.setUpdateTime(new Date()); |
|
|
|
wxProfitSharingOrderMapper.updateByPrimaryKey(record); |
|
|
|
|
|
|
|
String receivers = returnMap.get("receivers"); |
|
|
|
JSONArray jReceivers = JSONArray.parseArray(receivers); |
|
|
|
|
|
|
|
WxProfitSharingResult result = new WxProfitSharingResult(); |
|
|
|
result.setSharingOrderId(record.getId().toString()); |
|
|
|
List <WxProfitSharingResult> wxProfitSharingResultList = wxProfitSharingResultMapper.findList(result); |
|
|
|
|
|
|
|
|
|
|
|
WxProfitSharingReceiver wxProfitSharingReceiver; |
|
|
|
WxProfitSharingResult wxProfitSharingResult; |
|
|
|
|
|
|
|
for(int i=0; i<wxProfitSharingResultList.size();i++) { |
|
|
|
wxProfitSharingResult = wxProfitSharingResultList.get(i); |
|
|
|
wxProfitSharingReceiver = wxProfitSharingReceiverMapper |
|
|
|
.selectByPrimaryKey(wxProfitSharingResult.getSharingReceiverId()); |
|
|
|
|
|
|
|
for(int j=0; j<jReceivers.size();j++) { |
|
|
|
JSONObject res = (JSONObject)jReceivers.get(j); |
|
|
|
|
|
|
|
if (res.getString("type").equals(wxProfitSharingReceiver.getReceiverType()) |
|
|
|
&& res.getString("account").equals(wxProfitSharingReceiver.getReceiverAccount())) { |
|
|
|
|
|
|
|
wxProfitSharingResult.setFinishTime(res.getString("finish_time")); |
|
|
|
wxProfitSharingResult.setUpdateTime(new Date()); |
|
|
|
wxProfitSharingResult.setSharingStatus(resultStatusMap.getIntValue(res.getString("result"))); |
|
|
|
wxProfitSharingResult.setFailedReason(res.getString("fail_reason")); |
|
|
|
wxProfitSharingResultMapper.updateByPrimaryKey(wxProfitSharingResult); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return new ResultData(returnMap); |
|
|
|
|
|
|
|
} catch (RuntimeException e) { |
|
|
|
throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), e.getMessage()); |
|
|
|
} catch (Exception e) { |
|
|
|
throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |