package com.hx.phip.tool.payment;
|
|
import com.hx.common.service.CommonService;
|
import com.hx.mybatisTool.SqlSentence;
|
import com.hx.phiappt.model.PaymentMethod;
|
import com.hx.phiappt.model.consume.ConsumeNotify;
|
import com.hx.phiappt.model.consume.ConsumePay;
|
import com.hx.phip.dao.mapper.ConsumeNotifyMapper;
|
import com.hx.phip.dao.mapper.PaymentMethodMapper;
|
import com.hx.util.StringUtils;
|
|
import java.math.BigDecimal;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
/**消费记录工具
|
*
|
* @author CJH
|
*/
|
public class ConsumeTool {
|
|
/**通过支付编号或者作废流水号获取到支付回调信息
|
* @param orderId 支付回调信息关联标识,可不传
|
* @param outOrderNo 支付编号
|
* @param commonService 映射
|
* @return 支付回调信息
|
*/
|
public static ConsumeNotify selectConsumeNotifyByOrderNo(String orderId,String outOrderNo,String platTrxNo, CommonService commonService){
|
SqlSentence sqlSentence = new SqlSentence();
|
Map<String,Object> values = new HashMap<>();
|
StringBuilder sql = new StringBuilder();
|
|
values.put("outOrderNo",outOrderNo);
|
values.put("platTrxNo",platTrxNo);
|
sql.append("SELECT * FROM consume_notify WHERE isDel = 0 AND (outOrderNo = #{m.outOrderNo} OR platTrxNo = #{m.platTrxNo})");
|
if(StringUtils.noNull(orderId)){
|
values.put("orderId",orderId);
|
sql.append(" AND orderId = #{m.orderId}");
|
}
|
|
sqlSentence.sqlSentence(sql.toString(),values);
|
return commonService.selectOne(ConsumeNotifyMapper.class,sqlSentence);
|
}
|
|
/**绑定支付信息,没有绑定的,单个
|
* 没有关联到支付记录的支付信息
|
* @param orderId 支付回调信息关联标识
|
* @param paymentNo 支付方式编号
|
* @param payAmount 支付金额
|
* @param consumePayId 支付记录标识
|
* @param commonService 映射
|
* @return 支付回调信息
|
*/
|
public static void bindConsume(String orderId,String paymentNo,BigDecimal payAmount,String consumePayId, CommonService commonService){
|
ConsumeNotify consumeNotify = selectNoBind(orderId,paymentNo,payAmount,commonService);
|
if(consumeNotify == null){
|
return;
|
}
|
bindConsumeNotify(consumeNotify,consumePayId,commonService);
|
}
|
|
/**绑定支付信息集合,没有绑定的
|
* 没有关联到支付记录的支付信息
|
* @param orderId 支付回调信息关联标识
|
* @param consumePayList 支付方式编号
|
* @param commonService 映射
|
* @return 支付回调信息
|
*/
|
public static void bindConsumeList(String orderId,List<ConsumePay> consumePayList, CommonService commonService){
|
|
Map<String,Integer> consumePayCount = new HashMap<>();
|
Integer count;
|
for(ConsumePay consumePay:consumePayList){
|
count = consumePayCount.getOrDefault(consumePay.getNumberNo(),0);
|
count++;
|
consumePayCount.put(consumePay.getNumberNo(),count);
|
}
|
List<ConsumeNotify> consumeNotifyList;
|
for(ConsumePay consumePay:consumePayList){
|
count = consumePayCount.get(consumePay.getNumberNo());
|
if(count == 1){
|
//单条,绑定所有的支付回调信息
|
consumeNotifyList = selectNoBindList(orderId,consumePay.getNumberNo(),null,commonService);
|
for(ConsumeNotify consumeNotify:consumeNotifyList){
|
bindConsumeNotify(consumeNotify,consumePay.getId(),commonService);
|
}
|
}else if(count > 1){
|
//多条,绑定金额一样的回调信息
|
bindConsume(orderId,consumePay.getNumberNo(),consumePay.getActualTotal(),consumePay.getId(),commonService);
|
}
|
}
|
}
|
|
/**绑定回调记录*/
|
public static void bindConsumeNotify(ConsumeNotify consumeNotify,String consumePayId,CommonService commonService){
|
SqlSentence sqlSentence = new SqlSentence();
|
Map<String,Object> values = new HashMap<>();
|
|
values.put("id",consumeNotify.getId());
|
values.put("consumePayId",consumePayId);
|
sqlSentence.sqlUpdate("consumePayId = #{m.consumePayId} WHERE id = #{m.id} AND consumePayId IS NULL",values);
|
commonService.updateWhere(ConsumeNotifyMapper.class,sqlSentence);
|
}
|
|
/**通过支付方式编号和金额获取到支付回调信息,获取单条
|
* 没有关联到支付记录的支付信息
|
* @param orderId 支付回调信息关联标识
|
* @param paymentNo 支付方式编号
|
* @param payAmount 支付金额
|
* @param commonService 映射
|
* @return 支付回调信息
|
*/
|
public static ConsumeNotify selectNoBind(String orderId,String paymentNo,BigDecimal payAmount, CommonService commonService){
|
SqlSentence sqlSentence = new SqlSentence();
|
Map<String,Object> values = new HashMap<>();
|
values.put("orderId",orderId);
|
values.put("paymentNo",paymentNo);
|
values.put("payAmount",payAmount);
|
values.put("refundStatus",ConsumeNotify.REFUND_STATUS_NO);
|
sqlSentence.sqlSentence("SELECT * FROM consume_notify WHERE isDel = 0 AND paymentNo = #{m.paymentNo} AND orderId = #{m.orderId}" +
|
" AND payAmount = #{m.payAmount} AND refundStatus = #{m.refundStatus} AND consumePayId IS NULL LIMIT 1",values);
|
return commonService.selectOne(ConsumeNotifyMapper.class,sqlSentence);
|
}
|
|
/**通过支付方式编号和金额获取到支付回调信息,获取多条
|
* 没有关联到支付记录的支付信息
|
* @param orderId 支付回调信息关联标识
|
* @param paymentNo 支付方式编号
|
* @param payAmount 支付金额
|
* @param commonService 映射
|
* @return 支付回调信息
|
*/
|
public static List<ConsumeNotify> selectNoBindList(String orderId,String paymentNo,BigDecimal payAmount, CommonService commonService){
|
SqlSentence sqlSentence = new SqlSentence();
|
Map<String,Object> values = new HashMap<>();
|
StringBuilder stringBuilder = new StringBuilder();
|
|
values.put("orderId",orderId);
|
values.put("paymentNo",paymentNo);
|
values.put("refundStatus",ConsumeNotify.REFUND_STATUS_NO);
|
stringBuilder.append("SELECT * FROM consume_notify WHERE isDel = 0 AND paymentNo = #{m.paymentNo} AND orderId = #{m.orderId}");
|
if(payAmount != null){
|
values.put("payAmount",payAmount);
|
stringBuilder.append(" AND payAmount = #{m.payAmount}");
|
}
|
stringBuilder.append(" AND refundStatus = #{m.refundStatus} AND consumePayId IS NULL");
|
sqlSentence.sqlSentence(stringBuilder.toString(),values);
|
return commonService.selectList(ConsumeNotifyMapper.class,sqlSentence);
|
}
|
|
/**通过支付方式编号和金额获取到支付回调信息,获取多条,升序排序
|
* @param orderId 支付回调信息关联标识
|
* @param paymentNo 支付方式编号
|
* @param payAmount 支付金额
|
* @param commonService 映射
|
* @return 支付回调信息
|
*/
|
public static List<ConsumeNotify> selectList(String orderId,String paymentNo,BigDecimal payAmount, CommonService commonService){
|
SqlSentence sqlSentence = new SqlSentence();
|
Map<String,Object> values = new HashMap<>();
|
StringBuilder stringBuilder = new StringBuilder();
|
|
values.put("orderId",orderId);
|
stringBuilder.append("SELECT * FROM consume_notify WHERE isDel = 0 AND orderId = #{m.orderId}");
|
if(StringUtils.noNull(paymentNo)){
|
values.put("paymentNo",paymentNo);
|
stringBuilder.append(" AND paymentNo = #{m.paymentNo}");
|
}
|
if(payAmount != null){
|
values.put("payAmount",payAmount);
|
stringBuilder.append(" AND payAmount = #{m.payAmount}");
|
}
|
stringBuilder.append(" ORDER BY payAmount ASC");
|
sqlSentence.sqlSentence(stringBuilder.toString(),values);
|
return commonService.selectList(ConsumeNotifyMapper.class,sqlSentence);
|
}
|
|
/**更新支付回调的退款金额信息*/
|
public static void updateRefundTotal(ConsumeNotify consumeNotify,BigDecimal refundTotal,int refundStatus,CommonService commonService){
|
SqlSentence sqlSentence = new SqlSentence();
|
Map<String,Object> values = new HashMap<>();
|
|
values.put("refundTotal",refundTotal);
|
values.put("id",consumeNotify.getId());
|
values.put("refundStatus",refundStatus);
|
sqlSentence.sqlUpdate("refundTotal = refundTotal+#{m.refundTotal},refundStatus = #{m.refundStatus} WHERE id = #{m.id}",values);
|
commonService.updateWhere(ConsumeNotifyMapper.class,sqlSentence);
|
}
|
|
|
/**
|
* 获取支付方式
|
* @param numberNo 支付编号
|
* @param commonService 映射
|
* @return 支付方式
|
*/
|
public static PaymentMethod getPaymentMethod(String numberNo,CommonService commonService){
|
SqlSentence sqlSentence = new SqlSentence();
|
Map<String,Object> values = new HashMap<>();
|
|
values.put("numberNo",numberNo);
|
sqlSentence.sqlSentence("SELECT * FROM payment_method WHERE isDel = 0 AND isUp = 1 AND numberNo = #{m.numberNo}",values);
|
return commonService.selectOne(PaymentMethodMapper.class,sqlSentence);
|
}
|
|
|
|
}
|