Authored by kun

Merge remote-tracking branch 'origin/dev' into dev

... ... @@ -3,6 +3,9 @@ package com.yohoufo.dal.order.model;
import java.math.BigDecimal;
public class OrdersPayRefund {
private int orderType;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database column orders_pay_refund.id
... ... @@ -11,13 +14,7 @@ public class OrdersPayRefund {
*/
private Integer id;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database column orders_pay_refund.refund_order_code
*
* @mbggenerated
*/
private Long refundOrderCode;
/**
* This field was generated by MyBatis Generator.
... ... @@ -27,13 +24,6 @@ public class OrdersPayRefund {
*/
private Long orderCode;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database column orders_pay_refund.payment
*
* @mbggenerated
*/
private Byte payment;
/**
* This field was generated by MyBatis Generator.
... ... @@ -59,13 +49,7 @@ public class OrdersPayRefund {
*/
private Byte status;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database column orders_pay_refund.refund_status
*
* @mbggenerated
*/
private String refundStatus;
/**
* This field was generated by MyBatis Generator.
... ... @@ -109,29 +93,6 @@ public class OrdersPayRefund {
this.id = id;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column orders_pay_refund.refund_order_code
*
* @return the value of orders_pay_refund.refund_order_code
*
* @mbggenerated
*/
public Long getRefundOrderCode() {
return refundOrderCode;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column orders_pay_refund.refund_order_code
*
* @param refundOrderCode the value for orders_pay_refund.refund_order_code
*
* @mbggenerated
*/
public void setRefundOrderCode(Long refundOrderCode) {
this.refundOrderCode = refundOrderCode;
}
/**
* This method was generated by MyBatis Generator.
... ... @@ -157,29 +118,7 @@ public class OrdersPayRefund {
this.orderCode = orderCode;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column orders_pay_refund.payment
*
* @return the value of orders_pay_refund.payment
*
* @mbggenerated
*/
public Byte getPayment() {
return payment;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column orders_pay_refund.payment
*
* @param payment the value for orders_pay_refund.payment
*
* @mbggenerated
*/
public void setPayment(Byte payment) {
this.payment = payment;
}
/**
* This method was generated by MyBatis Generator.
... ... @@ -253,29 +192,7 @@ public class OrdersPayRefund {
this.status = status;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column orders_pay_refund.refund_status
*
* @return the value of orders_pay_refund.refund_status
*
* @mbggenerated
*/
public String getRefundStatus() {
return refundStatus;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column orders_pay_refund.refund_status
*
* @param refundStatus the value for orders_pay_refund.refund_status
*
* @mbggenerated
*/
public void setRefundStatus(String refundStatus) {
this.refundStatus = refundStatus == null ? null : refundStatus.trim();
}
/**
* This method was generated by MyBatis Generator.
... ... @@ -332,4 +249,13 @@ public class OrdersPayRefund {
public void setRefundCode(String refundCode) {
this.refundCode = refundCode;
}
public int getOrderType() {
return orderType;
}
public void setOrderType(int orderType) {
this.orderType = orderType;
}
}
\ No newline at end of file
... ...
... ... @@ -41,7 +41,7 @@
from orders_pay
where order_code = #{orderCode,jdbcType=BIGINT}
and uid = #{uid,jdbcType=INTEGER}
and payment = #{payment,jdbcType=INTEGER}
limit 1
</select>
... ...
... ... @@ -7,13 +7,10 @@
This element is automatically generated by MyBatis Generator, do not modify.
-->
<id column="id" property="id" jdbcType="INTEGER" />
<result column="refund_order_code" property="refundOrderCode" jdbcType="BIGINT" />
<result column="order_code" property="orderCode" jdbcType="BIGINT" />
<result column="payment" property="payment" jdbcType="TINYINT" />
<result column="serial_no" property="serialNo" jdbcType="VARCHAR" />
<result column="amount" property="amount" jdbcType="DECIMAL" />
<result column="status" property="status" jdbcType="TINYINT" />
<result column="refund_status" property="refundStatus" jdbcType="VARCHAR" />
<result column="create_time" property="createTime" jdbcType="INTEGER" />
<result column="update_time" property="updateTime" jdbcType="INTEGER" />
<result column="refund_code" property="refundCode" jdbcType="VARCHAR" />
... ... @@ -23,7 +20,7 @@
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
-->
id, refund_order_code, order_code, payment, serial_no, amount, status, refund_status,
id, order_code, serial_no, amount, status,
create_time, update_time
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
... ... @@ -43,12 +40,7 @@
from orders_pay_refund
where order_code = #{orderCode}
</select>
<select id="selectByRefundOrderCode" resultMap="BaseResultMap" >
select
<include refid="Base_Column_List" />
from orders_pay_refund
where refund_order_code = #{refundOrderCode} limit 1
</select>
<select id="selectByRefundCode" resultMap="BaseResultMap" >
select
... ... @@ -63,13 +55,13 @@
This element is automatically generated by MyBatis Generator, do not modify.
-->
insert into orders_pay_refund (id, order_code,
payment, serial_no, amount,
status, refund_status, create_time,
update_time, refund_code)
serial_no, amount,
status, create_time,
update_time, refund_code, order_type)
values (#{id,jdbcType=INTEGER}, #{orderCode,jdbcType=BIGINT},
#{payment,jdbcType=TINYINT}, #{serialNo,jdbcType=VARCHAR}, #{amount,jdbcType=DECIMAL},
#{status,jdbcType=TINYINT}, #{refundStatus,jdbcType=VARCHAR}, #{createTime,jdbcType=INTEGER},
#{updateTime,jdbcType=INTEGER}, #{refundCode,jdbcType=VARCHAR})
#{serialNo,jdbcType=VARCHAR}, #{amount,jdbcType=DECIMAL},
#{status,jdbcType=TINYINT}, #{createTime,jdbcType=INTEGER},
#{updateTime,jdbcType=INTEGER}, #{refundCode,jdbcType=VARCHAR}, #{orderType,jdbcType=INTEGER})
</insert>
<insert id="insertSelective" parameterType="com.yohoufo.dal.order.model.OrdersPayRefund" >
<!--
... ... @@ -81,15 +73,9 @@
<if test="id != null" >
id,
</if>
<if test="refundOrderCode != null" >
refund_order_code,
</if>
<if test="orderCode != null" >
order_code,
</if>
<if test="payment != null" >
payment,
</if>
<if test="serialNo != null" >
serial_no,
</if>
... ... @@ -99,9 +85,6 @@
<if test="status != null" >
status,
</if>
<if test="refundStatus != null" >
refund_status,
</if>
<if test="createTime != null" >
create_time,
</if>
... ... @@ -113,15 +96,9 @@
<if test="id != null" >
#{id,jdbcType=INTEGER},
</if>
<if test="refundOrderCode != null" >
#{refundOrderCode,jdbcType=BIGINT},
</if>
<if test="orderCode != null" >
#{orderCode,jdbcType=BIGINT},
</if>
<if test="payment != null" >
#{payment,jdbcType=TINYINT},
</if>
<if test="serialNo != null" >
#{serialNo,jdbcType=VARCHAR},
</if>
... ... @@ -131,9 +108,6 @@
<if test="status != null" >
#{status,jdbcType=TINYINT},
</if>
<if test="refundStatus != null" >
#{refundStatus,jdbcType=VARCHAR},
</if>
<if test="createTime != null" >
#{createTime,jdbcType=INTEGER},
</if>
... ... @@ -149,15 +123,9 @@
-->
update orders_pay_refund
<set >
<if test="refundOrderCode != null" >
refund_order_code = #{refundOrderCode,jdbcType=BIGINT},
</if>
<if test="orderCode != null" >
order_code = #{orderCode,jdbcType=BIGINT},
</if>
<if test="payment != null" >
payment = #{payment,jdbcType=TINYINT},
</if>
<if test="serialNo != null" >
serial_no = #{serialNo,jdbcType=VARCHAR},
</if>
... ... @@ -167,9 +135,6 @@
<if test="status != null" >
status = #{status,jdbcType=TINYINT},
</if>
<if test="refundStatus != null" >
refund_status = #{refundStatus,jdbcType=VARCHAR},
</if>
<if test="createTime != null" >
create_time = #{createTime,jdbcType=INTEGER},
</if>
... ... @@ -185,13 +150,11 @@
This element is automatically generated by MyBatis Generator, do not modify.
-->
update orders_pay_refund
set refund_order_code = #{refundOrderCode,jdbcType=BIGINT},
set
order_code = #{orderCode,jdbcType=BIGINT},
payment = #{payment,jdbcType=TINYINT},
serial_no = #{serialNo,jdbcType=VARCHAR},
amount = #{amount,jdbcType=DECIMAL},
status = #{status,jdbcType=TINYINT},
refund_status = #{refundStatus,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=INTEGER},
update_time = #{updateTime,jdbcType=INTEGER}
where id = #{id,jdbcType=INTEGER}
... ...
... ... @@ -32,6 +32,6 @@ public enum ClientType {
return v.getCode();
}
}
return -1;
return 0;
}
}
... ...
... ... @@ -7,17 +7,6 @@ public class RefundContant {
*/
public static final int PAYMENT_REFUND_RESULTCODE_FAIL = 1; //退款失败
public static final int PAYMENT_REFUND_RESULTCODE_SUCCESS = 2; //退款成功
public static final int PAYMENT_REFUND_RESULTCODE_UNKNOWN = 3; //退款情况未知
public static final int PAYMENT_REFUND_RESULTCODE_UNABLE = 4; //不能退款,如订单不存在、第三方没有查到付款等
public static final int PAYMENT_REFUND_RESULTCODE_REQERR = 5; //退款请求失败
public static final int PAYMENT_REFUND_RESULTCODE_ORDERNULL = 6; //校验订单不存在
public static final int PAYMENT_REFUND_RESULTCODE_AMOUNTDISMATCH = 7; //订单金额不一致
public static final int PAYMENT_REFUND_RESULTCODE_ORDERNOTPAY = 8; //订单为未支付状态
public static final int PAYMENT_REFUND_STATUS_NOTSUCCESSYET = 1;
public static final int PAYMENT_REFUND_STATUS_SUCCESS = 2;
public static final int PAYMENT_REFUND_STATUS_NOREFUND = 3;
public static final int PAYMENT_REFUND_STATUS_UNABLE = 4; //无法查询,如不支持的支付渠道
public static final int PAYMENT_REFUND_STATUS_REQERR = 5; //退款结果查询失败
}
... ...
... ... @@ -92,32 +92,15 @@ public class PaymentController {
* @return
*/
@RequestMapping(params = "method=ufo.order.refund")
public ApiResponse refund(@RequestParam(name = "orderCode") long orderCode){
public ApiResponse refund(@RequestParam(name = "orderCode") long orderCode,
@RequestParam(name = "refundAmount") double refundAmount){
PaymentRequest request = PaymentRequest.builder().orderCode(orderCode).build();
PaymentOrderQueryBO returnBo = new PaymentOrderQueryBO();
returnBo.setOrderCode(String.valueOf(request.getOrderCode()));
PaymentRequest request = PaymentRequest.builder().orderCode(orderCode).refundAmount(refundAmount).build();
PayRefundBo payRefundBo = null;
try{
paymentService.refund(request);
}catch (Exception ex){
logger.error("refund ServiceNotAvaibleException: {}", ex);
payRefundBo = getUnknownRefundResult();
}
returnBo.setResultCode(payRefundBo.getRefundStatus());
returnBo.setResultMsg(payRefundBo.getRefundMsg());
returnBo.setTradeNo(payRefundBo.getRefundOrderCode());
return new ApiResponse.ApiResponseBuilder().code(PrepayResponse.SUCCESS).data(returnBo).message("退款成功").build();
}
PayRefundBo payRefundBo = paymentService.refund(request);
private PayRefundBo getUnknownRefundResult() {
return new ApiResponse.ApiResponseBuilder().code(PrepayResponse.SUCCESS).data(payRefundBo).message("退款成功").build();
PayRefundBo payRefundBo = new PayRefundBo();
payRefundBo.setRefundStatus(RefundContant.PAYMENT_REFUND_RESULTCODE_UNKNOWN);
payRefundBo.setRefundMsg("退款申请结果未知");
return payRefundBo;
}
... ...
package com.yohoufo.order.model;
import lombok.Data;
import lombok.ToString;
@Data
@ToString
public class PayRefundBo {
//退款申请是否成功
private int refundStatus;
private String refundMsg;
//退款前检查成功与否?
private boolean refundValid = true;
private long payOrderCode;
//订单原始金额
... ... @@ -16,84 +19,15 @@ public class PayRefundBo {
//退款单号
private String refundOrderCode;
private int payment;
//本次退款金额
private double amount;
private String serialNo;
private int orderCreateTime;
//微信支付的appId
private String appId;
public int getRefundStatus() {
return refundStatus;
}
public void setRefundStatus(int refundStatus) {
this.refundStatus = refundStatus;
}
public String getRefundMsg() {
return refundMsg;
}
public void setRefundMsg(String refundMsg) {
this.refundMsg = refundMsg;
}
public String getRefundOrderCode() {
return refundOrderCode;
}
public void setRefundOrderCode(String refundOrderCode) {
this.refundOrderCode = refundOrderCode;
}
public long getPayOrderCode() {
return payOrderCode;
}
public void setPayOrderCode(long payOrderCode) {
this.payOrderCode = payOrderCode;
}
public int getPayment() {
return payment;
}
public void setPayment(int payment) {
this.payment = payment;
}
public double getAmount() {
return amount;
}
public void setAmount(double amount) {
this.amount = amount;
}
public String getSerialNo() {
return serialNo;
}
public void setSerialNo(String serialNo) {
this.serialNo = serialNo;
}
public double getOrderTotalFee() {
return orderTotalFee;
}
public void setOrderTotalFee(double orderTotalFee) {
this.orderTotalFee = orderTotalFee;
}
public boolean isRefundValid() {
return refundValid;
}
public void setRefundValid(boolean refundValid) {
this.refundValid = refundValid;
}
public int getOrderCreateTime() {
return orderCreateTime;
}
public void setOrderCreateTime(int orderCreateTime) {
this.orderCreateTime = orderCreateTime;
}
public String getAppId() {
return appId;
}
public void setAppId(String appId) {
this.appId = appId;
}
/**
* 订单类型: 买家订单 or 卖家订单
*/
private int orderType;
}
... ...
... ... @@ -19,4 +19,9 @@ public class PaymentRequest {
private int skup;
/**
* 退款金额
*/
private double refundAmount;
}
... ...
... ... @@ -178,7 +178,7 @@ public class PaymentServiceImpl implements IPaymentService {
request.getOrderCode(), request.getUid(), orderInfo.getStatus());
}
return PaymentConfirmRsp.builder().orderCode(orderInfo.getOrderCode()).build();
return PaymentConfirmRsp.builder().orderCode(orderInfo.getOrderCode()).isPaid(OrderConstant.Y_STR).build();
}
... ... @@ -262,7 +262,8 @@ public class PaymentServiceImpl implements IPaymentService {
public PayRefundBo refund(PaymentRequest request){
// 入口参数检查
if (request.getOrderCode() < 0){
if (request.getOrderCode() < 0
|| request.getRefundAmount() < 0){
logger.warn("refund orderCode is {}", request.getOrderCode());
throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
}
... ... @@ -275,27 +276,30 @@ public class PaymentServiceImpl implements IPaymentService {
OrderInfo orderInfo = orderPaymentService.getOrderInfo(request.getOrderCode());
if (!orderPaymentService.isOrderPaid(orderInfo)){
logger.warn("refund has not paid, orderCode is {}", request.getOrderCode());
logger.warn("refund has not paid status, orderCode is {}", request.getOrderCode());
throw new ServiceException(ServiceError.ORDER_HAS_NOT_PAID);
}
// 获取支付成功记录
OrdersPay ordersPay = ordersPayMapper.selectOrdersPay(orderInfo.getOrderCode(), orderInfo.getUid());
if(ordersPay == null){
if(ordersPay == null || ordersPay.getAmount() == null){
logger.warn("refund paid record not exist.orderCode is {}", request.getOrderCode());
throw new ServiceException(ServiceError.ORDER_HAS_NOT_PAID);
}
// 支付金额小于退款金额
if (ordersPay.getAmount().doubleValue() < request.getRefundAmount()){
logger.warn("refund refundAmount {} > amount {}, orderCode is {}",
ordersPay.getAmount(), request.getRefundAmount(), request.getOrderCode());
throw new ServiceException(ServiceError.ORDER_REFUND_OVER_TOTAL_AMOUNT);
}
// 退款
AbstractPayService payService = getPayService(orderInfo.getPayment());
PayRefundBo payRefundBo = new PayRefundBo();
payRefundBo.setPayOrderCode(ordersPay.getOrderCode());
payRefundBo.setAmount(ordersPay.getAmount().doubleValue());
payRefundBo.setRefundOrderCode(String.valueOf(ordersPay.getOrderCode()) + ordersPay.getId());
PayRefundBo payRefundBo = buildRefundRequest(request, ordersPay);
PayRefundBo refundBo = payService.refundOpenApi(payRefundBo);
//退款申请成功的记录添加到orders_pay_refund表
if (refundBo.getRefundStatus() == RefundContant.PAYMENT_REFUND_RESULTCODE_SUCCESS) {
recordPayRefund(refundBo);
... ... @@ -305,6 +309,15 @@ public class PaymentServiceImpl implements IPaymentService {
}
private PayRefundBo buildRefundRequest(PaymentRequest request, OrdersPay ordersPay) {
PayRefundBo payRefundBo = new PayRefundBo();
payRefundBo.setPayOrderCode(ordersPay.getOrderCode());
payRefundBo.setAmount(request.getRefundAmount());
payRefundBo.setOrderTotalFee(ordersPay.getAmount().doubleValue());
payRefundBo.setRefundOrderCode(String.valueOf(ordersPay.getOrderCode()) + ordersPay.getId());
return payRefundBo;
}
/**
* 数据库记录退款申请
... ... @@ -323,10 +336,9 @@ public class PaymentServiceImpl implements IPaymentService {
newRecord.setOrderCode(refundBo.getPayOrderCode());
newRecord.setRefundCode(refundBo.getRefundOrderCode());
newRecord.setAmount(BigDecimal.valueOf(refundBo.getAmount()));
newRecord.setPayment((byte) refundBo.getPayment());
newRecord.setStatus((byte) 0);
newRecord.setSerialNo(refundBo.getSerialNo());
newRecord.setOrderType(refundBo.getOrderType());
int timeStamp = (int) (new Date().getTime() / 1000);
newRecord.setCreateTime(timeStamp);
newRecord.setUpdateTime(timeStamp);
... ...
... ... @@ -90,7 +90,7 @@ public class ShoppingServiceImpl implements IShoppingService {
// 不可售
if (skupGood.getStatus() == null
|| skupGood.getStatus().intValue() != SkupStatus.CAN_SELL.getCode()){
logger.warn("payment skup status, skup is {}", skup);
logger.warn("payment skup status {}, skup is {}", skupGood.getStatus(), skup);
throw new ServiceException(ServiceError.ORDER_SKUP_CANNOT_SELL);
}
return skupGood;
... ...
... ... @@ -299,7 +299,7 @@ public abstract class AbstractWeixinPayService extends AbstractPayService {
paramMap.put("appid", getAppId());
paramMap.put("mch_id", getMchId());
paramMap.put("nonce_str", WXUtils.getNonceStr());
paramMap.put("out_trade_no", WeixinPayConfig.WECHAT_TRADE_NO_PREFIX + refundBo.getPayOrderCode());
paramMap.put("out_trade_no", String.valueOf(refundBo.getPayOrderCode()));
paramMap.put("out_refund_no", refundBo.getRefundOrderCode());
//String totalFee = String.valueOf((int)YHMath.mul(amount, 100)); //微信金额必须以分为单位,且不能包含小数点
... ...
package com.yohoufo.order.service.code;
import java.math.BigDecimal;
public class TempTest {
public static void main(String[] args){
BigDecimal a = new BigDecimal(0.01);
BigDecimal b = new BigDecimal(0.01);
System.out.println(a.compareTo(b));
}
}
... ...