|
@@ -27,6 +27,7 @@ import com.gree.mall.manager.constant.Constant;
|
|
|
import com.gree.mall.manager.enums.OrderInfoSourceEnum;
|
|
|
import com.gree.mall.manager.enums.OrderShareStatusEnum;
|
|
|
import com.gree.mall.manager.enums.PayStatusEnum;
|
|
|
+import com.gree.mall.manager.enums.SettlementStatusNewEnum;
|
|
|
import com.gree.mall.manager.exception.RemoteServiceException;
|
|
|
import com.gree.mall.manager.plus.entity.*;
|
|
|
import com.gree.mall.manager.plus.service.*;
|
|
@@ -119,14 +120,11 @@ public class WechatLogic {
|
|
|
* @param source 公众号 / 小程序
|
|
|
* @return
|
|
|
*/
|
|
|
- public WxPayService getPayWebstiService(String companyWechatId,String source){
|
|
|
- if(StringUtils.equals(source,OrderInfoSourceEnum.A.getRemark())) {
|
|
|
- //小程序
|
|
|
- return WxConfiguration.wxSubPayWebsitServices.get(companyWechatId);
|
|
|
- }else{
|
|
|
- //公众号
|
|
|
- return WxConfiguration.wxPayWebsitServices.get(companyWechatId);
|
|
|
- }
|
|
|
+ public WxPayService getPayWebstiService(String id,String source){
|
|
|
+
|
|
|
+
|
|
|
+ return WxConfiguration.wxPayWebsitServices.get(id);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -596,6 +594,90 @@ public class WechatLogic {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * 电子支付分账
|
|
|
+ * @param settlementOrder
|
|
|
+ * @throws WxPayException
|
|
|
+ */
|
|
|
+ public void shareSettlementAmount(SettlementOrder settlementOrder) throws WxPayException {
|
|
|
+ if(settlementOrder == null){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if(!StringUtils.equals(settlementOrder.getPayStatus(), PayStatusEnum.PAID.getKey())){
|
|
|
+ throw new RemoteServiceException("未支付订单不可结算");
|
|
|
+ }
|
|
|
+ if(!StringUtils.equals(settlementOrder.getStatus(),"WAIT")){
|
|
|
+ log.error("非待结算状态不可结算,id:{}",settlementOrder.getOrderId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Map<String,BigDecimal> map = new HashMap<>();
|
|
|
+ map.put(settlementOrder.getOpenId(),settlementOrder.getWorkerAmount());
|
|
|
+ Map<String,String> mapPhone = new HashMap<>();
|
|
|
+ mapPhone.put(settlementOrder.getOpenId(),settlementOrder.getWorkerMobile());
|
|
|
+ //开始分账
|
|
|
+ try {
|
|
|
+ profitSettlementSharing(settlementOrder.getOrderId(), settlementOrder.getTranscationId(), map, mapPhone, settlementOrder.getCompanyWechatId(), "B",settlementOrder.getConfigId());
|
|
|
+
|
|
|
+ settlementOrder.setStatus(SettlementStatusNewEnum.OK.toString());
|
|
|
+ settlementOrder.updateById();
|
|
|
+
|
|
|
+ } catch (WxPayException e) {
|
|
|
+ log.error("异常结算", e);
|
|
|
+
|
|
|
+ settlementOrder.setStatus(SettlementStatusNewEnum.YC.toString());
|
|
|
+ settlementOrder.updateById();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分账
|
|
|
+ * @param orderSharingId 分账id
|
|
|
+ * @param transactionId 微信支付流水号
|
|
|
+ * @param amountMap key=分钱人的openid value=分多少钱
|
|
|
+ * @param phoneMap key=分钱人的openid value=手机号
|
|
|
+ * @param companyWechatId 商户id
|
|
|
+ * @param source
|
|
|
+ * @throws WxPayException
|
|
|
+ */
|
|
|
+ private void profitSettlementSharing(String orderSharingId, String transactionId, Map<String, BigDecimal> amountMap,
|
|
|
+ Map<String, String> phoneMap, String companyWechatId, String source,String config) throws WxPayException {
|
|
|
+
|
|
|
+ List<Map<String, Object>> list = new ArrayList<>();
|
|
|
+
|
|
|
+ for(String openId : amountMap.keySet()){
|
|
|
+ //添加分账人
|
|
|
+ addShareReveiver(openId,companyWechatId,source);
|
|
|
+
|
|
|
+ BigDecimal shareAmount = amountMap.get(openId);
|
|
|
+ String workerUserPhone = phoneMap.get(openId);
|
|
|
+ if(shareAmount.doubleValue() == 0){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Map<String, Object> receiver = new HashMap<>();
|
|
|
+ receiver.put("type", "PERSONAL_SUB_OPENID");
|
|
|
+ receiver.put("account", openId);
|
|
|
+ receiver.put("amount", ProfitSharingReceiverRequest.yuanToFen(shareAmount.toString()));
|
|
|
+ receiver.put("description", "销售返佣给" + workerUserPhone + ",金额:" + shareAmount + "元");
|
|
|
+ list.add(receiver);
|
|
|
+ }
|
|
|
+
|
|
|
+ ProfitSharingRequest profitSharingRequest = new ProfitSharingRequest();
|
|
|
+ profitSharingRequest.setOutOrderNo(orderSharingId);
|
|
|
+ profitSharingRequest.setTransactionId(transactionId);
|
|
|
+ profitSharingRequest.setReceivers(JSONObject.toJSONString(list));
|
|
|
+
|
|
|
+ ProfitSharingService profitSharingService = this.getPayWebstiService(config, source).getProfitSharingService();
|
|
|
+ //请求单次分账
|
|
|
+ log.info("【开始分账】request:{}", JSONObject.toJSONString(profitSharingRequest));
|
|
|
+ profitSharingService.profitSharing(profitSharingRequest);
|
|
|
+ //log.info("【开始分账】result:{}", JSONObject.toJSONString(profitSharingResult));
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 商城订单分账
|
|
@@ -1084,9 +1166,9 @@ public class WechatLogic {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public String paymentfkmWebsit(String id, BigDecimal payment, String profitSharingFlag, String ip, String companyWechatId, String authCode, String source) {
|
|
|
+ public String paymentfkmWebsit(String id, BigDecimal payment, String profitSharingFlag, String ip, String configId, String authCode, String source) {
|
|
|
|
|
|
- WxPayService payService = this.getPayWebstiService(companyWechatId,source);
|
|
|
+ WxPayService payService = this.getPayWebstiService(id,source);
|
|
|
|
|
|
WxPayMicropayRequest request = new WxPayMicropayRequest();
|
|
|
//request.setDeviceInfo(worker.getWorkerId());
|
|
@@ -1110,7 +1192,7 @@ public class WechatLogic {
|
|
|
}
|
|
|
//记录流水
|
|
|
|
|
|
- AdminCompanyWechatPayConfig adminCompanyWechatPayConfig = adminCompanyWechatPayConfigService.getById(companyWechatId);
|
|
|
+ AdminCompanyWechatPayConfig adminCompanyWechatPayConfig = adminCompanyWechatPayConfigService.getById(configId);
|
|
|
this.addPayWebsitRecord(adminCompanyWechatPayConfig,payment,"",payResult.getSubOpenid(),ip,payResult.getTradeType(),id,payResult.getTransactionId());
|
|
|
return payResult.getTransactionId();
|
|
|
}
|