Просмотр исходного кода

[系统][更改]:更改分账接口

release_toaliyun_real
hupeng 7 лет назад
Родитель
Сommit
ec56dd0600
14 измененных файлов: 336 добавлений и 157 удалений
  1. +112
    -0
      mallinkService/src/main/java/com/iformall/domain/dto/WxSharingOrderDto.java
  2. +23
    -0
      mallinkService/src/main/java/com/iformall/domain/po/WxProfitSharingOrder.java
  3. +9
    -0
      mallinkService/src/main/java/com/iformall/domain/po/WxProfitSharingReceiver.java
  4. +4
    -4
      mallinkService/src/main/java/com/iformall/enums/EnumProfitSharingOrderStatus.java
  5. +36
    -0
      mallinkService/src/main/java/com/iformall/enums/EnumProfitSharingOrderType.java
  6. +2
    -2
      mallinkService/src/main/java/com/iformall/enums/EnumProfitSharingType.java
  7. +8
    -38
      mallinkService/src/main/java/com/iformall/service/WxProfitSharingOrderService.java
  8. +0
    -3
      mallinkService/src/main/java/com/iformall/service/impl/MarkingDataReportServiceImpl.java
  9. +15
    -2
      mallinkService/src/main/java/com/iformall/service/impl/WxCouponOrderServiceImpl.java
  10. +5
    -2
      mallinkService/src/main/java/com/iformall/service/impl/WxMerchantServiceImpl.java
  11. +112
    -99
      mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingOrderServiceImpl.java
  12. +4
    -0
      mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingReceiverServiceImpl.java
  13. +4
    -6
      mallinkService/src/main/resources/mapper/WxProfitSharingOrderMapper.xml
  14. +2
    -1
      mallinkService/src/main/resources/mapper/WxProfitSharingReceiverMapper.xml

+ 112
- 0
mallinkService/src/main/java/com/iformall/domain/dto/WxSharingOrderDto.java Просмотреть файл

@@ -0,0 +1,112 @@
package com.iformall.domain.dto;

import java.io.Serializable;
import java.util.Date;


public class WxSharingOrderDto implements Serializable {
private static final long serialVersionUID = 1L;

/**租户ID**/
@io.swagger.annotations.ApiModelProperty(value="租户ID",name="tenantId")
private String tenantId;
/**订单ID**/
@io.swagger.annotations.ApiModelProperty(value="订单ID",name="orderId")
private Long orderId;
/**用户ID**/
@io.swagger.annotations.ApiModelProperty(value="用户ID",name="cUserId")
private Long cUserId;
/**微信生成的订单号**/
@io.swagger.annotations.ApiModelProperty(value="微信生成的订单号",name="transactionId")
private String transactionId;
/**支付金额(分)**/
@io.swagger.annotations.ApiModelProperty(value="支付金额(分)",name="payAmount")
private Integer payAmount;
/***/
@io.swagger.annotations.ApiModelProperty(value="",name="merchantId")
private Long merchantId;
/**分账金额(总金额扣除手续费后的金额)**/
@io.swagger.annotations.ApiModelProperty(value="分账金额",name="shareAmount")
private Integer shareAmount;

/**支付发起时间**/
@io.swagger.annotations.ApiModelProperty(value="支付发起时间",name="payTimeStart")
private Date payTimeStart;
/**支付结束时间**/
@io.swagger.annotations.ApiModelProperty(value="支付结束时间",name="payTimeEnd")
private Date payTimeEnd;
/**分账订单类型**/
@io.swagger.annotations.ApiModelProperty(value="分账订单类型",name="type")
private Integer type;


public String getTenantId() {
return tenantId;
}
public Long getOrderId() {
return orderId;
}
public void setOrderId(Long _orderId) {
orderId = _orderId;
}

public Long getcUserId() {
return cUserId;
}
public void setcUserId(Long cUserId) {
this.cUserId = cUserId;
}

public Integer getPayAmount() {
return payAmount;
}
public void setPayAmount(Integer _payAmount) {
payAmount = _payAmount;
}
public Date getPayTimeStart() {
return payTimeStart;
}
public void setPayTimeStart(Date _payTimeStart) {
payTimeStart = _payTimeStart;
}
public Date getPayTimeEnd() {
return payTimeEnd;
}
public void setPayTimeEnd(Date _payTimeEnd) {
payTimeEnd = _payTimeEnd;
}

public String getTransactionId() {
return transactionId;
}
public void setTransactionId(String _transactionId) {
transactionId = _transactionId;
}

public Integer getShareAmount() {
return shareAmount;
}
public void setShareAmount(Integer shareAmount) {
this.shareAmount = shareAmount;
}

public void setTenantId(String tenantId) {
this.tenantId = tenantId;
}

public Long getMerchantId() {
return merchantId;
}

public void setMerchantId(Long merchantId) {
this.merchantId = merchantId;
}

public Integer getType() {
return type;
}

public void setType(Integer type) {
this.type = type;
}
}

+ 23
- 0
mallinkService/src/main/java/com/iformall/domain/po/WxProfitSharingOrder.java Просмотреть файл

@@ -65,6 +65,12 @@ public class WxProfitSharingOrder implements Serializable {
/*微信生成分账单号**/
@io.swagger.annotations.ApiModelProperty(value="微信生成分账单号",name="sharingOrderId")
private String sharingOrderNo;
/*分账类型,0单次,1多次,2完结**/
@io.swagger.annotations.ApiModelProperty(value="分账类型",name="type")
private Integer type;
/*分账接收者参数**/
@io.swagger.annotations.ApiModelProperty(value="分账接收者参数",name="receivers")
private String receivers;
/*分账申请失败原因**/
@io.swagger.annotations.ApiModelProperty(value="分账申请失败原因",name="errorMsg")
private String errorMsg;
@@ -125,6 +131,23 @@ public class WxProfitSharingOrder implements Serializable {
public void setSharingOrderNo(String _sharingOrderNo) {
sharingOrderNo = _sharingOrderNo;
}

public Integer getType() {
return type;
}

public void setType(Integer type) {
this.type = type;
}

public String getReceivers() {
return receivers;
}

public void setReceivers(String receivers) {
this.receivers = receivers;
}

public String getErrorMsg() {
return errorMsg;
}


+ 9
- 0
mallinkService/src/main/java/com/iformall/domain/po/WxProfitSharingReceiver.java Просмотреть файл

@@ -76,6 +76,9 @@ public class WxProfitSharingReceiver implements Serializable {
/*分账接收方状态 0,正常 1,停用**/
@io.swagger.annotations.ApiModelProperty(value="分账接收方状态 0,正常 1,停用",name="status")
private Integer status;
/*分账参数**/
@io.swagger.annotations.ApiModelProperty(value="分账参数,目前为分账比例(单位为万分之一)",name="parameter")
private String parameter;

public Integer getStatus() {
return status;
@@ -154,7 +157,13 @@ public class WxProfitSharingReceiver implements Serializable {
bankCode = _bankCode;
}

public String getParameter() {
return parameter;
}

public void setParameter(String parameter) {
this.parameter = parameter;
}

public static enum Field
{


mallinkService/src/main/java/com/iformall/enums/EnumProfitSharingStatus.java → mallinkService/src/main/java/com/iformall/enums/EnumProfitSharingOrderStatus.java Просмотреть файл

@@ -3,7 +3,7 @@ package com.iformall.enums;
/**
* Created by Stormeye on 2018/08/09.
*/
public enum EnumProfitSharingStatus {
public enum EnumProfitSharingOrderStatus {
PROFIT_SHARING_UNKNOWN(-1, "未知"),
PROFIT_SHARING_REQ_FAILED(1, "提交订单失败"),
PROFIT_SHARING_APPLY_FAILED(2, "提交业务失败"),
@@ -13,8 +13,8 @@ public enum EnumProfitSharingStatus {
PROFIT_SHARING_FAILED(6, "处理失败"),
;

public static EnumProfitSharingStatus getEnum(Integer code) {
for (EnumProfitSharingStatus value : values()) {
public static EnumProfitSharingOrderStatus getEnum(Integer code) {
for (EnumProfitSharingOrderStatus value : values()) {
if (value.getCode().equals(code)) {
return value;
}
@@ -25,7 +25,7 @@ public enum EnumProfitSharingStatus {
private Integer code;
private String message;

EnumProfitSharingStatus(Integer code, String message) {
EnumProfitSharingOrderStatus(Integer code, String message) {
this.code = code;
this.message = message;
}

+ 36
- 0
mallinkService/src/main/java/com/iformall/enums/EnumProfitSharingOrderType.java Просмотреть файл

@@ -0,0 +1,36 @@
package com.iformall.enums;

/**
* Created by Stormeye on 2018/08/09.
*/
public enum EnumProfitSharingOrderType {
PROFIT_SHARING_SINGLE(0, "单次分账"),
PROFIT_SHARING_MULTI(1, "多次分账"),
PROFIT_SHARING_FINISH(2, "多次分账完结"),
;

public static EnumProfitSharingOrderType getEnum(Integer code) {
for (EnumProfitSharingOrderType value : values()) {
if (value.getCode().equals(code)) {
return value;
}
}
return null;
}

private Integer code;
private String message;

EnumProfitSharingOrderType(Integer code, String message) {
this.code = code;
this.message = message;
}

public Integer getCode() {
return code;
}

public String getMessage() {
return message;
}
}

+ 2
- 2
mallinkService/src/main/java/com/iformall/enums/EnumProfitSharingType.java Просмотреть файл

@@ -4,8 +4,8 @@ package com.iformall.enums;
* Created by Stormeye on 2018/08/09.
*/
public enum EnumProfitSharingType {
PROFIT_SHARING_TYPE_WECHAT(1, "MERCHANT_ID"),
PROFIT_SHARING_TYPE_BANK(2, "PERSONAL_WECHATID"),
PROFIT_SHARING_TYPE_WECHAT(1, "微信分账"),
PROFIT_SHARING_TYPE_BANK(2, "银行卡分账"),
;

public static EnumProfitSharingType getEnum(Integer code) {


+ 8
- 38
mallinkService/src/main/java/com/iformall/service/WxProfitSharingOrderService.java Просмотреть файл

@@ -1,53 +1,23 @@
package com.iformall.service;

import com.github.pagehelper.PageInfo;
import com.iformall.common.ResultData;
import com.iformall.domain.po.WxPayOrder;
import com.iformall.domain.dto.WxSharingOrderDto;
import com.iformall.domain.po.WxProfitSharingOrder;

public interface WxProfitSharingOrderService {

/**
* 根据实体查询分页列表
*
* @param record
* @param offset
* @param limit
* @return
*/
PageInfo<WxProfitSharingOrder> listAsPage(WxProfitSharingOrder record, Integer pageIndex, Integer pageSize);
/**
* 根据Id获得实体
*
* @param id
* @return
*/
WxProfitSharingOrder getById(Long id);
/**
* 保存或更新实体
*
* @param record
*/
void saveOrUpdate(WxProfitSharingOrder record);

/**
* 根据Id删除实体
*
* @param id
* 创建分账订单
*/
void deleteById(Long id);
public ResultData createSharingOrder(WxSharingOrderDto wxSharingOrderDto);

/**
* 创建分账订单
* 查询分账订单
*/
public ResultData createSharingOrder(WxPayOrder wxPayOrder, Long merchantId);
public ResultData querySharingOrder(WxProfitSharingOrder sharingOrderDto);

/**
* 查询分账订单
* 结束分账订单
*/
public ResultData querySharingOrder(WxPayOrder wxPayOrder);
public ResultData finishSharingOrder(WxSharingOrderDto sharingOrderDto);
}

+ 0
- 3
mallinkService/src/main/java/com/iformall/service/impl/MarkingDataReportServiceImpl.java Просмотреть файл

@@ -13,8 +13,6 @@ import com.iformall.enums.EnumOrderType;
import com.iformall.mapper.*;
import com.iformall.service.MarkingDataReportService;
import com.iformall.utils.DateUtils;
import net.bytebuddy.asm.Advice;
import org.joda.time.Days;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -22,7 +20,6 @@ import org.springframework.stereotype.Service;

import java.text.NumberFormat;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.stream.Collectors;



+ 15
- 2
mallinkService/src/main/java/com/iformall/service/impl/WxCouponOrderServiceImpl.java Просмотреть файл

@@ -11,6 +11,7 @@ import com.google.common.collect.Lists;
import com.iformall.common.ErrorCode;
import com.iformall.common.IdWorker;
import com.iformall.common.ResultData;
import com.iformall.domain.dto.WxSharingOrderDto;
import com.iformall.domain.po.*;
import com.iformall.domain.vo.CUserDateAmountVo;
import com.iformall.domain.vo.WxCouponOrderBVo;
@@ -373,8 +374,20 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService {
wxPayOrder.setOrderId(couponOrder.getOrderId());
wxPayOrder.setPayOrderStatus(EnumPayStatus.PAY_STATUS_SUCCESS.getCode());
wxPayOrder = wxPayOrderMapper.selectOne(wxPayOrder);
if (wxPayOrder != null && wxPayOrder.getShare().equals(EnumPayShare.YES.getCode()))
wxProfitSharingOrderService.createSharingOrder(wxPayOrder, merchantId);
if (wxPayOrder != null && wxPayOrder.getShare().equals(EnumPayShare.YES.getCode())) {
WxSharingOrderDto wxSharingOrderDto = new WxSharingOrderDto();
wxSharingOrderDto.setcUserId(wxPayOrder.getcUserId());
wxSharingOrderDto.setMerchantId(merchantId);
wxSharingOrderDto.setType(EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE.getCode());
wxSharingOrderDto.setPayAmount(wxPayOrder.getPayAmount());
wxSharingOrderDto.setOrderId(wxPayOrder.getId());
wxSharingOrderDto.setPayTimeStart(wxPayOrder.getPayTimeStart());
wxSharingOrderDto.setPayTimeEnd(wxPayOrder.getPayTimeEnd());
wxSharingOrderDto.setTenantId(wxPayOrder.getTenantId());
wxSharingOrderDto.setTransactionId(wxPayOrder.getTransactionId());
wxSharingOrderDto.setShareAmount(wxPayOrder.getShareAmount());
wxProfitSharingOrderService.createSharingOrder(wxSharingOrderDto);
}
} catch (Exception e) {
logger.error("微信分账: " + e.getMessage());
}


+ 5
- 2
mallinkService/src/main/java/com/iformall/service/impl/WxMerchantServiceImpl.java Просмотреть файл

@@ -356,13 +356,16 @@ public class WxMerchantServiceImpl implements WxMerchantService {
return new ResultData(ErrorCode.MERCHANT_INFO_NOT_FOUND);
}
//添加商户的分账账户(不是必选)
if (wxMerchant.getAccountId() != null && wxMerchant.getAccountName() != null
&& !wxMerchant.getAccountId().isEmpty() && !wxMerchant.getAccountName().isEmpty()) {
if (wxMerchant.getAccountId() != null
&& wxMerchant.getAccountName() != null
&& !wxMerchant.getAccountId().isEmpty()
&& !wxMerchant.getAccountName().isEmpty()) {
WxProfitSharingReceiver receiver = new WxProfitSharingReceiver();
receiver.setReceiverAccount(wxMerchant.getAccountId());
receiver.setReceiverComments(wxMerchant.getName());
receiver.setReceiverType(wxMerchant.getAccountTypeValue());
receiver.setTrueName(wxMerchant.getAccountName());
receiver.setParameter(wxMerchant.getAccountParameter());
return wxProfitSharingReceiverService.updateReceiver(wxMerchant, receiver);
}
} catch (Exception e) {


+ 112
- 99
mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingOrderServiceImpl.java Просмотреть файл

@@ -5,10 +5,9 @@ import java.util.*;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.iformall.common.ErrorCode;
import com.iformall.common.ResultData;
import com.iformall.domain.dto.WxSharingOrderDto;
import com.iformall.domain.po.*;
import com.iformall.enums.*;
import com.iformall.exception.MallinkException;
@@ -53,6 +52,8 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ
@Autowired
WxCUserMapper wxCUserMapper;

@Autowired
WxPayOrderMapper wxPayOrderMapper;

final JSONObject errorMap = JSON.parseObject("{" +
"\"SYSTEMERROR\":{\"detail\":\"接口返回错误\",\"reason\":\"系统超时\",\"resolution\":\"系统异常,请用相同参数重新调用\"}," +
@@ -88,40 +89,12 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ
"\"RETURNED\": 4," +
"\"CLOSED\": 5}");

@Override
public PageInfo<WxProfitSharingOrder> listAsPage(WxProfitSharingOrder record, Integer pageIndex, Integer pageSize) {
return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxProfitSharingOrderMapper.findList(record));
}

@Override
public WxProfitSharingOrder getById(Long id) {
return wxProfitSharingOrderMapper.selectByPrimaryKey(id);
}

@Override
public void saveOrUpdate(WxProfitSharingOrder record) {
if (record.getId() == null) {
//record.setId(UUID.randomUUID().toString().replaceAll("-", ""));
final IdWorker idWorker = IdWorker.get();
record.setId(idWorker.nextId());
wxProfitSharingOrderMapper.insertSelective(record);
} else {
wxProfitSharingOrderMapper.updateByPrimaryKeySelective(record);
}
}

@Override
public void deleteById(Long id) {
wxProfitSharingOrderMapper.deleteByPrimaryKey(id);
}

@Autowired
WxPayOrderMapper wxPayOrderMapper;

private WxAppinfo getAppinfo(WxPayOrder wxPayOrder) {
private WxAppinfo getAppinfo(Long cUserId) {
WxAppinfo wxAppinfo = new WxAppinfo();

WxCUser wxCUser = wxCUserMapper.selectByPrimaryKey(wxPayOrder.getcUserId());
WxCUser wxCUser = wxCUserMapper.selectByPrimaryKey(cUserId);
if (wxCUser == null)
throw new MallinkException(ErrorCode.USER_IS_EMPTY);

@@ -133,13 +106,24 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ
return wxAppinfo;
}


@Override
@Transactional(isolation=Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class})
public ResultData createSharingOrder(WxPayOrder wxPayOrder, Long merchantId) {
//添加分账接受方
public ResultData createSharingOrder(WxSharingOrderDto sharingOrderDto) {
final IdWorker idworker = IdWorker.get();

if (!sharingOrderDto.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE.getCode()) &&
!sharingOrderDto.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE.getCode())){
return new ResultData(ErrorCode.SYS_PARAMETER_ERROR);
}

WxAppinfo appInfo = getAppinfo(sharingOrderDto.getcUserId());
WxPayAccount payAccount = wxPayAccountMapper.selectByPrimaryKey(appInfo.getPayId());

//准备分账列表
WxProfitSharingReceiver psReceiverQ = new WxProfitSharingReceiver();
psReceiverQ.setTenantId(wxPayOrder.getTenantId());
psReceiverQ.setMerchantId(merchantId);
psReceiverQ.setTenantId(sharingOrderDto.getTenantId());
psReceiverQ.setMerchantId(sharingOrderDto.getMerchantId());
psReceiverQ.setSharingType(EnumProfitSharingType.PROFIT_SHARING_TYPE_WECHAT.getCode());
psReceiverQ.setStatus(EnumProfitSharingReceiverStatus.PROFIT_SHARING_RECEIVER_STATUS_VALID.getCode());
List<WxProfitSharingReceiver> psReceiverList = wxProfitSharingReceiverMapper.findList(psReceiverQ);
@@ -147,84 +131,60 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ
throw new MallinkException(ErrorCode.PROFIT_SHARING_RECEIVER_INVALID);
}

return createPSOrder(wxPayOrder, merchantId, psReceiverList, false);
}

private ResultData createPSOrder(WxPayOrder wxPayOrder, Long merchantId, List<WxProfitSharingReceiver> psReceiverList, boolean multiCmd) {
final IdWorker idworker = IdWorker.get();

WxAppinfo appInfo = getAppinfo(wxPayOrder);
WxPayAccount payAccount = wxPayAccountMapper.selectByPrimaryKey(appInfo.getPayId());

// TODO
WxOrder wxOrder = wxOrderMapper.selectByPrimaryKey(wxPayOrder.getOrderId());

//单次分账检查是否已创建分账订单
WxProfitSharingOrder record = new WxProfitSharingOrder();
if(!multiCmd) {
record.setOrderId(wxPayOrder.getId());
record = wxProfitSharingOrderMapper.selectOne(record);
if (record == null) {
//创建分账订单
Date currentDate = new Date();
record = new WxProfitSharingOrder();
record.setId(idworker.nextId());
record.setTenantId(wxPayOrder.getTenantId());
record.setTransactionId(wxPayOrder.getTransactionId());
record.setOrderId(wxPayOrder.getId());
record.setPayAmount(wxPayOrder.getPayAmount());
record.setMerchantId(merchantId);
record.setSharingStatus(EnumProfitSharingStatus.PROFIT_SHARING_UNKNOWN.getCode());
record.setCreateTime(currentDate);
record.setUpdateTime(currentDate);
record.setPayTimeStart(currentDate);
record.setPayTimeEnd(currentDate);
wxProfitSharingOrderMapper.insertSelective(record);
}
} else {

record.setOrderId(sharingOrderDto.getOrderId());
record = wxProfitSharingOrderMapper.selectOne(record);
if (record == null) {
//创建分账订单
Date currentDate = new Date();
record = new WxProfitSharingOrder();
record.setId(idworker.nextId());
record.setTenantId(wxPayOrder.getTenantId());
record.setTransactionId(wxPayOrder.getTransactionId());
record.setOrderId(wxPayOrder.getId());
record.setPayAmount(wxPayOrder.getPayAmount());
record.setMerchantId(merchantId);
record.setSharingStatus(EnumProfitSharingStatus.PROFIT_SHARING_UNKNOWN.getCode());
record.setTenantId(sharingOrderDto.getTenantId());
record.setTransactionId(sharingOrderDto.getTransactionId());
record.setOrderId(sharingOrderDto.getOrderId());
record.setPayAmount(sharingOrderDto.getPayAmount());
record.setMerchantId(sharingOrderDto.getMerchantId());
record.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_UNKNOWN.getCode());
record.setCreateTime(currentDate);
record.setUpdateTime(currentDate);
record.setPayTimeStart(currentDate);
record.setPayTimeEnd(currentDate);
record.setType(sharingOrderDto.getType());

wxProfitSharingOrderMapper.insertSelective(record);
}


// 添加分账接收方

final WxProfitSharingOrder frecord = record;
JSONArray receivers = new JSONArray();
List <WxProfitSharingResult> resultList = new ArrayList<WxProfitSharingResult>();
for (int i=0;i<psReceiverList.size();i++){
WxProfitSharingReceiver receiver = psReceiverList.get(i);
psReceiverList.stream().forEach(receiver->{
Date currentDate = new Date();
JSONObject jo = new JSONObject();
jo.put("type",EnumProfitSharingReceiverType.getEnum(receiver.getReceiverType()).getMessage());
jo.put("account",receiver.getReceiverAccount());
jo.put("amount", wxPayOrder.getShareAmount()); //temp: sharing all money with only owner
jo.put("amount", sharingOrderDto.getShareAmount()); //temp: sharing all money with only owner
jo.put("description",receiver.getReceiverComments());
receivers.add(jo);

WxProfitSharingResult result = new WxProfitSharingResult();

result.setId(idworker.nextId());
result.setTenantId(record.getTenantId());
result.setMerchantId(record.getMerchantId());
result.setSharingOrderId(record.getId());
result.setTenantId(frecord.getTenantId());
result.setMerchantId(frecord.getMerchantId());
result.setSharingOrderId(frecord.getId());
result.setSharingReceiverId(receiver.getId());
result.setPayAmount(wxPayOrder.getShareAmount());
result.setPayAmount(sharingOrderDto.getShareAmount());
result.setCreateTime(currentDate);
result.setUpdateTime(currentDate);
result.setSharingStatus(EnumProfitSharingResultStatus.PROFIT_SHARING_RESULT_PENDING.getCode());
resultList.add(result);
}
});


//分账提交
WxProfitSharingP psCmd = new WxProfitSharingP();
@@ -233,7 +193,7 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ
psCmd.setAppid(appInfo.getParentAppId());
psCmd.setSub_appid(appInfo.getAppId());
psCmd.setNonce_str(Utility.generate32UUID());
psCmd.setTransaction_id(wxPayOrder.getTransactionId());
psCmd.setTransaction_id(sharingOrderDto.getTransactionId());
psCmd.setOut_order_no(record.getId().toString());
psCmd.setSign_type("HMAC-SHA256");
psCmd.setReceivers(receivers.toJSONString());
@@ -241,13 +201,15 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ
String response;
try {
psCmd.setSign(WxPayment.createSignHMAC(BeanUtils.toStringMap(psCmd), payAccount.getApiKey()));
if(!multiCmd) {
if(sharingOrderDto.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE.getCode())) {
response = WxProfitSharing.pushOrder(BeanUtils.toStringMap(psCmd), payAccount.getCertPath(), payAccount.getMchId());
} else {
} else if(sharingOrderDto.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_MULTI.getCode())) {
response = WxProfitSharing.pushMultiOrder(BeanUtils.toStringMap(psCmd), payAccount.getCertPath(), payAccount.getMchId());
} else {
throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR);
}
} catch (Exception e) {
record.setSharingStatus(EnumProfitSharingStatus.PROFIT_SHARING_REQ_FAILED.getCode());
record.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_REQ_FAILED.getCode());
record.setErrorMsg(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getMessage());
record.setUpdateTime(new Date());
wxProfitSharingOrderMapper.updateByPrimaryKey(record);
@@ -259,7 +221,7 @@ 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.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_REQ_FAILED.getCode());
record.setErrorMsg(returnMap.get("return_msg"));
record.setUpdateTime(new Date());
wxProfitSharingOrderMapper.updateByPrimaryKey(record);
@@ -275,7 +237,7 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ

String result_code = returnMap.get("result_code");
if (!"SUCCESS".equals(result_code)) {
record.setSharingStatus(EnumProfitSharingStatus.PROFIT_SHARING_APPLY_FAILED.getCode());
record.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_APPLY_FAILED.getCode());
record.setUpdateTime(new Date());
record.setErrorMsg(returnMap.get("err_code_des"));
wxProfitSharingOrderMapper.updateByPrimaryKey(record);
@@ -283,7 +245,7 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ
}

record.setSharingOrderNo(returnMap.get("order_id"));
record.setSharingStatus(EnumProfitSharingStatus.PROFIT_SHARING_ACCEPTED.getCode());
record.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_ACCEPTED.getCode());
record.setUpdateTime(new Date());
wxProfitSharingOrderMapper.updateByPrimaryKey(record);
for (WxProfitSharingResult result:resultList) {
@@ -295,15 +257,16 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ

@Override
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class})
public ResultData querySharingOrder(WxPayOrder wxPayOrder) {
public ResultData querySharingOrder(WxProfitSharingOrder wxProfitSharingOrder) {

WxProfitSharingOrder record = new WxProfitSharingOrder();

WxAppinfo appInfo = getAppinfo(wxPayOrder);
WxPayOrder wxPayOrder = wxPayOrderMapper.selectByPrimaryKey(wxProfitSharingOrder.getOrderId());
WxAppinfo appInfo = getAppinfo(wxPayOrder.getcUserId());
WxPayAccount payAccount = wxPayAccountMapper.selectByPrimaryKey(appInfo.getPayId());

//是否已创建分账订单
record.setOrderId(wxPayOrder.getId());
record.setOrderId(wxProfitSharingOrder.getOrderId());
record = wxProfitSharingOrderMapper.selectOne(record);
if (record == null)
return new ResultData(ErrorCode.ORDER_IS_NOT_FIND);
@@ -313,7 +276,7 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ
wxProfitSharingQueryP.setMch_id(payAccount.getMchId());
wxProfitSharingQueryP.setSub_mch_id(payAccount.getSubMchId());
wxProfitSharingQueryP.setNonce_str(Utility.generate32UUID());
wxProfitSharingQueryP.setTransaction_id(wxPayOrder.getTransactionId());
wxProfitSharingQueryP.setTransaction_id(wxProfitSharingOrder.getTransaction());
wxProfitSharingQueryP.setOut_order_no(record.getId().toString());
wxProfitSharingQueryP.setSign_type("HMAC-SHA256");
String response;
@@ -415,11 +378,42 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ
}

// 分账完结
private ResultData finishPSOrder(WxPayOrder wxPayOrder) {
WxAppinfo appInfo = getAppinfo(wxPayOrder);
@Override
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class})
public ResultData finishSharingOrder(WxSharingOrderDto sharingOrderDto) {
final IdWorker idworker = IdWorker.get();

if (!sharingOrderDto.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_FINISH.getCode())){
return new ResultData(ErrorCode.SYS_PARAMETER_ERROR);
}

WxAppinfo appInfo = getAppinfo(sharingOrderDto.getcUserId());
WxPayAccount payAccount = wxPayAccountMapper.selectByPrimaryKey(appInfo.getPayId());

WxOrder wxOrder = wxOrderMapper.selectByPrimaryKey(wxPayOrder.getOrderId());

//分账检查是否已创建分账订单
WxProfitSharingOrder record = new WxProfitSharingOrder();

record.setOrderId(sharingOrderDto.getOrderId());
record = wxProfitSharingOrderMapper.selectOne(record);
if (record == null) {
//创建分账订单
Date currentDate = new Date();
record = new WxProfitSharingOrder();
record.setId(idworker.nextId());
record.setTenantId(sharingOrderDto.getTenantId());
record.setTransactionId(sharingOrderDto.getTransactionId());
record.setOrderId(sharingOrderDto.getOrderId());
record.setPayAmount(sharingOrderDto.getPayAmount());
record.setMerchantId(sharingOrderDto.getMerchantId());
record.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_UNKNOWN.getCode());
record.setCreateTime(currentDate);
record.setUpdateTime(currentDate);
record.setPayTimeStart(currentDate);
record.setPayTimeEnd(currentDate);
record.setType(sharingOrderDto.getType());
wxProfitSharingOrderMapper.insertSelective(record);
}

//分账提交
WxProfitSharingFinishP psFCmd = new WxProfitSharingFinishP();
@@ -427,8 +421,8 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ
psFCmd.setSub_mch_id(payAccount.getSubMchId());
psFCmd.setAppid(appInfo.getParentAppId());
psFCmd.setNonce_str(Utility.generate32UUID());
psFCmd.setTransaction_id(wxPayOrder.getTransactionId());
psFCmd.setOut_order_no(wxPayOrder.getId().toString());
psFCmd.setTransaction_id(sharingOrderDto.getTransactionId());
psFCmd.setOut_order_no(record.getId().toString());
psFCmd.setSign_type("HMAC-SHA256");

String response;
@@ -436,6 +430,10 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ
psFCmd.setSign(WxPayment.createSignHMAC(BeanUtils.toStringMap(psFCmd), payAccount.getApiKey()));
response = WxProfitSharing.finishOrder(BeanUtils.toStringMap(psFCmd), payAccount.getCertPath(), payAccount.getMchId());
} catch (Exception e) {
record.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_REQ_FAILED.getCode());
record.setErrorMsg(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getMessage());
record.setUpdateTime(new Date());
wxProfitSharingOrderMapper.updateByPrimaryKey(record);
return new ResultData(ErrorCode.PROFIT_SHARING_REQUEST_FAILED);
}

@@ -444,18 +442,33 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ
String return_code = returnMap.get("return_code");

if (!"SUCCESS".equals(return_code)) {
record.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_REQ_FAILED.getCode());
record.setErrorMsg(returnMap.get("return_msg"));
record.setUpdateTime(new Date());
wxProfitSharingOrderMapper.updateByPrimaryKey(record);
return new ResultData(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getCode(), returnMap.get("return_msg"));
}

if (!WxPayment.verifyNotifyHMAC(returnMap,payAccount.getApiKey())){
record.setErrorMsg(ErrorCode.PROFIT_SHARING_RETURN_INVALID.getMessage());
record.setUpdateTime(new Date());
wxProfitSharingOrderMapper.updateByPrimaryKey(record);
return new ResultData(ErrorCode.PROFIT_SHARING_RETURN_INVALID.getCode());
}

String result_code = returnMap.get("result_code");
if (!"SUCCESS".equals(result_code)) {
record.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_APPLY_FAILED.getCode());
record.setUpdateTime(new Date());
record.setErrorMsg(returnMap.get("err_code_des"));
wxProfitSharingOrderMapper.updateByPrimaryKey(record);
return new ResultData(ErrorCode.PROFIT_SHARING_APPLY_FAILED.getCode(), returnMap.get("err_code_des"));
}

record.setSharingOrderNo(returnMap.get("order_id"));
record.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_ACCEPTED.getCode());
record.setUpdateTime(new Date());
wxProfitSharingOrderMapper.updateByPrimaryKey(record);
return new ResultData(returnMap);
}
}

+ 4
- 0
mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingReceiverServiceImpl.java Просмотреть файл

@@ -272,6 +272,10 @@ public class WxProfitSharingReceiverServiceImpl implements WxProfitSharingReceiv
if (oldReceiver == null) {
delReceiver(merchant);
return addReceiver(merchant, receiver);
} else {
oldReceiver.setParameter(receiver.getParameter());
oldReceiver.setUpdateTime(new Date());
wxProfitSharingReceiverMapper.updateByPrimaryKeySelective(oldReceiver);
}

return new ResultData();


+ 4
- 6
mallinkService/src/main/resources/mapper/WxProfitSharingOrderMapper.xml Просмотреть файл

@@ -11,6 +11,8 @@
<result column="pay_time_start" jdbcType="TIMESTAMP" property="payTimeStart" />
<result column="transaction_id" jdbcType="VARCHAR" property="transactionId" />
<result column="sharing_order_no" jdbcType="VARCHAR" property="sharingOrderNo" />
<result column="type" jdbcType="INTEGER" property="type" />
<result column="receivers" jdbcType="VARCHAR" property="receivers" />
<result column="error_msg" jdbcType="VARCHAR" property="errorMsg" />
<result column="sharing_status" jdbcType="INTEGER" property="sharingStatus" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
@@ -18,7 +20,7 @@
</resultMap>
<sql id="allColumns">
`id`,`tenant_id`,`merchant_id`,`order_id`,`pay_amount`,`pay_time_end`,`pay_time_start`,`transaction_id`,`sharing_order_no`,`error_msg`,`sharing_status`,`update_time`,`create_time`
`id`,`tenant_id`,`merchant_id`,`order_id`,`pay_amount`,`pay_time_end`,`pay_time_start`,`transaction_id`,`sharing_order_no`,`type`,`receivers`,`error_msg`,`sharing_status`,`update_time`,`create_time`
</sql>

<sql id="dynamicWhereConditions">
@@ -102,9 +104,5 @@
<include refid="dynamicWhereConditions" />
</select>

</mapper>

+ 2
- 1
mallinkService/src/main/resources/mapper/WxProfitSharingReceiverMapper.xml Просмотреть файл

@@ -15,10 +15,11 @@
<result column="true_name" jdbcType="VARCHAR" property="trueName" />
<result column="bank_code" jdbcType="VARCHAR" property="bankCode" />
<result column="status" jdbcType="INTEGER" property="status" />
<result column="parameter" jdbcType="VARCHAR" property="parameter" />
</resultMap>
<sql id="allColumns">
`id`,`tenant_id`,`merchant_id`,`receiver_type`,`receiver_account`,`receiver_comments`,`create_time`,`update_time`,`sharing_type`,`bank_no`,`true_name`,`bank_code`,`status`
`id`,`tenant_id`,`merchant_id`,`receiver_type`,`receiver_account`,`receiver_comments`,`create_time`,`update_time`,`sharing_type`,`bank_no`,`true_name`,`bank_code`,`status`,`parameter`
</sql>

<sql id="dynamicWhereConditions">


Загрузка…
Отмена
Сохранить