|
|
|
@@ -8,16 +8,11 @@ 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.WxOrder; |
|
|
|
import com.simple.domain.po.WxPayAccount; |
|
|
|
import com.simple.domain.po.WxProfitSharingOrder; |
|
|
|
import com.simple.domain.po.*; |
|
|
|
import com.simple.enums.EnumPayDomain; |
|
|
|
import com.simple.enums.EnumProfitSharingStatus; |
|
|
|
import com.simple.exception.MallinkException; |
|
|
|
import com.simple.mapper.WxAppinfoMapper; |
|
|
|
import com.simple.mapper.WxPayAccountMapper; |
|
|
|
import com.simple.mapper.WxProfitSharingOrderMapper; |
|
|
|
import com.simple.mapper.*; |
|
|
|
import com.simple.pay.WxPayment; |
|
|
|
import com.simple.pay.WxProfitSharing; |
|
|
|
import com.simple.pay.WxProfitSharingP; |
|
|
|
@@ -43,7 +38,14 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ |
|
|
|
WxPayAccountMapper wxPayAccountMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
WxProfitSharingOrderMapper wxOrderMapper; |
|
|
|
WxOrderMapper wxOrderMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
WxProfitSharingReceiverMapper wxProfitSharingReceiverMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
WxProfitSharingResultMapper wxProfitSharingResultMapper; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JSONObject errorMap = JSON.parseObject( |
|
|
|
@@ -87,29 +89,29 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public ResultData createSharingOrder(WxAppinfo subAppInfo, WxOrder wxOrder) { |
|
|
|
public ResultData createSharingOrder(WxAppinfo subAppInfo, WxPayOrder wxPayOrder) { |
|
|
|
final IdWorker idworker = IdWorker.get(); |
|
|
|
|
|
|
|
WxProfitSharingOrder record = new WxProfitSharingOrder(); |
|
|
|
try { |
|
|
|
WxOrder wxOrder = wxOrderMapper.selectByPrimaryKey(wxPayOrder.getOrderId()); |
|
|
|
//是否已创建分账订单 |
|
|
|
Date currentDate = new Date(); |
|
|
|
record.setOrderId(wxOrder.getId().toString()); |
|
|
|
record.setOrderId(wxPayOrder.getId().toString()); |
|
|
|
record = wxProfitSharingOrderMapper.selectOne(record); |
|
|
|
if (record == null) { |
|
|
|
//创建分账订单 |
|
|
|
Date currentDate = new Date(); |
|
|
|
record.setId(idworker.nextId()); |
|
|
|
record.setTenantId(wxOrder.getTenantId()); |
|
|
|
record.setOrderId(wxOrder.getId().toString()); |
|
|
|
record.setPayAmount(wxOrder.getPayment()); |
|
|
|
//record.setMerchantId(); |
|
|
|
record.setTenantId(wxPayOrder.getTenantId()); |
|
|
|
record.setOrderId(wxPayOrder.getId().toString()); |
|
|
|
record.setPayAmount(wxPayOrder.getPayAmount()); |
|
|
|
record.setMerchantId(wxOrder.getMerchantId().toString()); |
|
|
|
record.setCreateTime(currentDate); |
|
|
|
record.setUpdateTime(currentDate); |
|
|
|
record.setPayTimeStart(currentDate); |
|
|
|
record.setPayTimeEnd(currentDate); |
|
|
|
|
|
|
|
if (wxProfitSharingOrderMapper.insertSelective(record) != 1) { |
|
|
|
throw new MallinkException(ErrorCode.DB_FAIL); |
|
|
|
} |
|
|
|
wxProfitSharingOrderMapper.insertSelective(record); |
|
|
|
} |
|
|
|
|
|
|
|
WxPayAccount payAccount = wxPayAccountMapper.selectByPrimaryKey(subAppInfo.getPayId()); |
|
|
|
@@ -121,15 +123,39 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ |
|
|
|
wxProfitSharingP.setAppid(mainAppInfo.getAppId()); |
|
|
|
wxProfitSharingP.setMch_id(mainPayAccount.getMchId()); |
|
|
|
wxProfitSharingP.setSub_appid(subAppInfo.getAppId()); |
|
|
|
wxProfitSharingP.setMch_id(payAccount.getMchId()); |
|
|
|
wxProfitSharingP.setSub_mch_id(payAccount.getMchId()); |
|
|
|
wxProfitSharingP.setNonce_str(Utility.generate32UUID()); |
|
|
|
wxProfitSharingP.setTransaction_id(wxOrder.getTenantId()); |
|
|
|
wxProfitSharingP.setTransaction_id(wxPayOrder.getTransactionId()); |
|
|
|
wxProfitSharingP.setOut_trade_no(record.getId().toString()); |
|
|
|
|
|
|
|
//添加分账接受方 |
|
|
|
WxProfitSharingReceiver wxProfitSharingReceiver = new WxProfitSharingReceiver(); |
|
|
|
wxProfitSharingReceiver.setMerchantId(wxOrder.getMerchantId().toString()); |
|
|
|
wxProfitSharingReceiver.setSharingType(1); |
|
|
|
List<WxProfitSharingReceiver> wxProfitSharingReceiverList = wxProfitSharingReceiverMapper.findList(wxProfitSharingReceiver); |
|
|
|
if (wxProfitSharingReceiverList.size()<=0 || wxProfitSharingReceiverList.size() > 50) { |
|
|
|
throw new MallinkException(ErrorCode.PROFIT_SHARING_RECEIVER_INVALID.getCode(), ErrorCode.PROFIT_SHARING_RECEIVER_INVALID.getMessage()); |
|
|
|
} |
|
|
|
JSONObject receivers = new JSONObject(); |
|
|
|
List <WxProfitSharingResult> resultList = new ArrayList<WxProfitSharingResult>(); |
|
|
|
for (int i=0;i<=wxProfitSharingReceiverList.size();i++){ |
|
|
|
WxProfitSharingReceiver receiver = wxProfitSharingReceiverList.get(i); |
|
|
|
Date currentDate = new Date(); |
|
|
|
receivers.put("type",receiver.getReceiverType()); |
|
|
|
receivers.put("acount",receiver.getReceiverAccount()); |
|
|
|
receivers.put("amount",record.getPayAmount()); //temp: sharing all money with only owner |
|
|
|
receivers.put("description",receiver.getReceiverComments()); |
|
|
|
WxProfitSharingResult result = new WxProfitSharingResult(); |
|
|
|
|
|
|
|
result.setId(idworker.nextId()); |
|
|
|
result.setSharingOrderId(record.getSharingOrderId()); |
|
|
|
result.setSharingReceiverId(receiver.getId().toString()); |
|
|
|
result.setCreateTime(currentDate); |
|
|
|
result.setUpdateTime(currentDate); |
|
|
|
resultList.add(result); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
wxProfitSharingP.setReceivers(receivers.toJSONString()); |
|
|
|
|
|
|
|
wxProfitSharingP.setSign(WxPayment.createSign(BeanUtils.toStringMap(wxProfitSharingP), payAccount.getApiKey())); |
|
|
|
String response = WxProfitSharing.pushOrder(BeanUtils.toStringMap(wxProfitSharingP)); |
|
|
|
@@ -138,26 +164,29 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ |
|
|
|
String return_code = returnMap.get("return_code"); |
|
|
|
if (!"SUCCESS".equals(return_code)) { |
|
|
|
record.setSharingStatus(EnumProfitSharingStatus.PROFIT_SHARING_REQ_FAILED.getCode()); |
|
|
|
record.setUpdateTime(new Date()); |
|
|
|
wxProfitSharingOrderMapper.updateByPrimaryKey(record); |
|
|
|
throw new MallinkException(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getCode(), returnMap.get("return_msg")); |
|
|
|
return new ResultData(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getCode(), returnMap.get("return_msg")); |
|
|
|
} |
|
|
|
|
|
|
|
if (!WxPayment.verifyNotify(returnMap,payAccount.getApiKey())){ |
|
|
|
throw new MallinkException(ErrorCode.PROFIT_SHARING_RETURN_INVALID.getCode(), ErrorCode.PROFIT_SHARING_RETURN_INVALID.getMessage()); |
|
|
|
return new ResultData(ErrorCode.PROFIT_SHARING_RETURN_INVALID.getCode(), ErrorCode.PROFIT_SHARING_RETURN_INVALID.getMessage()); |
|
|
|
} |
|
|
|
|
|
|
|
String result_code = returnMap.get("result_code"); |
|
|
|
if (!"SUCCESS".equals(result_code)) { |
|
|
|
record.setSharingStatus(EnumProfitSharingStatus.PROFIT_SHARING_APPLY_FAILED.getCode()); |
|
|
|
record.setUpdateTime(new Date()); |
|
|
|
wxProfitSharingOrderMapper.updateByPrimaryKey(record); |
|
|
|
throw new MallinkException(ErrorCode.PROFIT_SHARING_APPLY_FAILED.getCode(), returnMap.get("result_msg")); |
|
|
|
return new ResultData(ErrorCode.PROFIT_SHARING_APPLY_FAILED.getCode(), returnMap.get("result_msg")); |
|
|
|
} |
|
|
|
|
|
|
|
record.setSharingOrderId(returnMap.get("order_id")); |
|
|
|
record.setSharingStatus(EnumProfitSharingStatus.PROFIT_SHARING_ACCEPTED.getCode()); |
|
|
|
record.setUpdateTime(new Date()); |
|
|
|
wxProfitSharingOrderMapper.updateByPrimaryKey(record); |
|
|
|
|
|
|
|
return new ResultData(200, "分账申请成功", returnMap); |
|
|
|
wxProfitSharingResultMapper.insertList(resultList); |
|
|
|
return new ResultData(returnMap); |
|
|
|
|
|
|
|
} catch (RuntimeException e) { |
|
|
|
throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), e.getMessage()); |
|
|
|
|