Authored by Lixiaodi

Merge branch 'dev_order_transfer' into dev

# Conflicts:
#	dal/src/main/java/com/yohoufo/dal/order/TradeBillsMapper.java
#	dal/src/main/java/com/yohoufo/dal/order/model/TradeBills.java
#	dal/src/main/resources/META-INF/mybatis/order/TradeBillsMapper.xml
#	order/src/main/java/com/yohoufo/order/service/impl/PaymentServiceImpl.java
... ... @@ -57,4 +57,6 @@ public interface CacheClient {
public <T> T hashGet(String key, String field, Class<T> clazz);
boolean setNx(String key, int expireInSeconds, Object o);
}
... ...
... ... @@ -164,6 +164,24 @@ public class RedisGwCacheClient implements CacheClient {
}
return null;
}
@Override
public boolean setNx(String key, int expireInSeconds, Object o) {
try {
RedisKeyBuilder keyB = RedisKeyBuilder.newInstance().appendFixed(key);
String compressStr = SnappyZipUtils.compress(JSON.toJSONString(o));
Boolean resu = this.valueOperations.setIfAbsent(keyB, compressStr);
if (resu != null && resu) {
redis.expire(keyB, expireInSeconds, TimeUnit.SECONDS);
return true;
}
return false;
} catch (Exception e) {
LOGGER.warn("setNx into redis failed!! key is :{} ,e is :{}", key, e);
return false;
}
}
/**
* 获取正负区间的一个随机数
... ...
... ... @@ -15,4 +15,6 @@ public interface OrdersPayTransferMapper {
int updateByPrimaryKeySelective(OrdersPayTransfer record);
int updateByPrimaryKey(OrdersPayTransfer record);
OrdersPayTransfer selectByBuyerOrderCode(long buyerOrderCode);
}
\ No newline at end of file
... ...
package com.yohoufo.dal.order;
import com.yohoufo.dal.order.model.TradeBills;
import org.apache.ibatis.annotations.Param;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import org.apache.ibatis.annotations.Param;
import com.yohoufo.dal.order.model.TradeBills;
public interface TradeBillsMapper {
TradeBills selectByPrimaryKey(Integer id);
... ... @@ -23,6 +23,13 @@ public interface TradeBillsMapper {
//根据用户uid,获取用户总支出
List<Map<String, Object>> selectSpendAmountByUid(@Param("uid") Integer uid);
int deleteByPrimaryKey(Integer id);
int insertSelective(TradeBills record);
int updateByPrimaryKeySelective(TradeBills record);
int updateByPrimaryKey(TradeBills record);
}
... ...
... ... @@ -5,9 +5,13 @@ import java.math.BigDecimal;
public class OrdersPayTransfer {
private Integer id;
private Long orderCode;
private Long buyerOrderCode;
private String orderId;
private Long sellerOrderCode;
private String alipayTradeId;
private Integer transferType;
private Integer uid;
... ... @@ -15,15 +19,13 @@ public class OrdersPayTransfer {
private BigDecimal amount;
private Integer transferType;
private Byte status;
private Integer status;
private Integer createTime;
private Integer updateTime;
private String transferCode;
private String alipayTradeResult;
public Integer getId() {
return id;
... ... @@ -33,20 +35,36 @@ public class OrdersPayTransfer {
this.id = id;
}
public Long getOrderCode() {
return orderCode;
public Long getBuyerOrderCode() {
return buyerOrderCode;
}
public void setBuyerOrderCode(Long buyerOrderCode) {
this.buyerOrderCode = buyerOrderCode;
}
public void setOrderCode(Long orderCode) {
this.orderCode = orderCode;
public Long getSellerOrderCode() {
return sellerOrderCode;
}
public String getOrderId() {
return orderId;
public void setSellerOrderCode(Long sellerOrderCode) {
this.sellerOrderCode = sellerOrderCode;
}
public void setOrderId(String orderId) {
this.orderId = orderId == null ? null : orderId.trim();
public String getAlipayTradeId() {
return alipayTradeId;
}
public void setAlipayTradeId(String alipayTradeId) {
this.alipayTradeId = alipayTradeId == null ? null : alipayTradeId.trim();
}
public Integer getTransferType() {
return transferType;
}
public void setTransferType(Integer transferType) {
this.transferType = transferType;
}
public Integer getUid() {
... ... @@ -73,19 +91,11 @@ public class OrdersPayTransfer {
this.amount = amount;
}
public Integer getTransferType() {
return transferType;
}
public void setTransferType(Integer transferType) {
this.transferType = transferType;
}
public Byte getStatus() {
public Integer getStatus() {
return status;
}
public void setStatus(Byte status) {
public void setStatus(Integer status) {
this.status = status;
}
... ... @@ -105,11 +115,11 @@ public class OrdersPayTransfer {
this.updateTime = updateTime;
}
public String getTransferCode() {
return transferCode;
public String getAlipayTradeResult() {
return alipayTradeResult;
}
public void setTransferCode(String transferCode) {
this.transferCode = transferCode == null ? null : transferCode.trim();
public void setAlipayTradeResult(String alipayTradeResult) {
this.alipayTradeResult = alipayTradeResult == null ? null : alipayTradeResult.trim();
}
}
\ No newline at end of file
... ...
... ... @@ -37,4 +37,6 @@ public class TradeBills {
private Integer tradeStatus;
private Integer createTime;
}
}
... ...
... ... @@ -3,24 +3,32 @@
<mapper namespace="com.yohoufo.dal.order.OrdersPayTransferMapper" >
<resultMap id="BaseResultMap" type="com.yohoufo.dal.order.model.OrdersPayTransfer" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="order_code" property="orderCode" jdbcType="BIGINT" />
<result column="order_id" property="orderId" jdbcType="VARCHAR" />
<result column="buyer_order_code" property="buyerOrderCode" jdbcType="BIGINT" />
<result column="seller_order_code" property="sellerOrderCode" jdbcType="BIGINT" />
<result column="alipay_trade_id" property="alipayTradeId" jdbcType="VARCHAR" />
<result column="transfer_type" property="transferType" jdbcType="INTEGER" />
<result column="uid" property="uid" jdbcType="INTEGER" />
<result column="alipay_account" property="alipayAccount" jdbcType="VARCHAR" />
<result column="amount" property="amount" jdbcType="DECIMAL" />
<result column="transfer_type" property="transferType" jdbcType="INTEGER" />
<result column="status" property="status" jdbcType="TINYINT" />
<result column="status" property="status" jdbcType="INTEGER" />
<result column="create_time" property="createTime" jdbcType="INTEGER" />
<result column="update_time" property="updateTime" jdbcType="INTEGER" />
<result column="transfer_code" property="transferCode" jdbcType="VARCHAR" />
</resultMap>
<resultMap id="ResultMapWithBLOBs" type="com.yohoufo.dal.order.model.OrdersPayTransfer" extends="BaseResultMap" >
<result column="alipay_trade_result" property="alipayTradeResult" jdbcType="LONGVARCHAR" />
</resultMap>
<sql id="Base_Column_List" >
id, order_code, order_id, uid, alipay_account, amount, transfer_type, status, create_time,
update_time, transfer_code
id, buyer_order_code, seller_order_code, alipay_trade_id, transfer_type, uid, alipay_account,
amount, status, create_time, update_time
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
<sql id="Blob_Column_List" >
alipay_trade_result
</sql>
<select id="selectByPrimaryKey" resultMap="ResultMapWithBLOBs" parameterType="java.lang.Integer" >
select
<include refid="Base_Column_List" />
,
<include refid="Blob_Column_List" />
from orders_pay_transfer
where id = #{id,jdbcType=INTEGER}
</select>
... ... @@ -29,14 +37,16 @@
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.yohoufo.dal.order.model.OrdersPayTransfer" >
insert into orders_pay_transfer (id, order_code, order_id,
uid, alipay_account, amount,
transfer_type, status, create_time,
update_time, transfer_code)
values (#{id,jdbcType=INTEGER}, #{orderCode,jdbcType=BIGINT}, #{orderId,jdbcType=VARCHAR},
#{uid,jdbcType=INTEGER}, #{alipayAccount,jdbcType=VARCHAR}, #{amount,jdbcType=DECIMAL},
#{transferType,jdbcType=INTEGER}, #{status,jdbcType=TINYINT}, #{createTime,jdbcType=INTEGER},
#{updateTime,jdbcType=INTEGER}, #{transferCode,jdbcType=VARCHAR})
insert into orders_pay_transfer (id, buyer_order_code, seller_order_code,
alipay_trade_id, transfer_type, uid,
alipay_account, amount, status,
create_time, update_time, alipay_trade_result
)
values (#{id,jdbcType=INTEGER}, #{buyerOrderCode,jdbcType=BIGINT}, #{sellerOrderCode,jdbcType=BIGINT},
#{alipayTradeId,jdbcType=VARCHAR}, #{transferType,jdbcType=INTEGER}, #{uid,jdbcType=INTEGER},
#{alipayAccount,jdbcType=VARCHAR}, #{amount,jdbcType=DECIMAL}, #{status,jdbcType=INTEGER},
#{createTime,jdbcType=INTEGER}, #{updateTime,jdbcType=INTEGER}, #{alipayTradeResult,jdbcType=LONGVARCHAR}
)
</insert>
<insert id="insertSelective" parameterType="com.yohoufo.dal.order.model.OrdersPayTransfer" >
insert into orders_pay_transfer
... ... @@ -44,11 +54,17 @@
<if test="id != null" >
id,
</if>
<if test="orderCode != null" >
order_code,
<if test="buyerOrderCode != null" >
buyer_order_code,
</if>
<if test="sellerOrderCode != null" >
seller_order_code,
</if>
<if test="orderId != null" >
order_id,
<if test="alipayTradeId != null" >
alipay_trade_id,
</if>
<if test="transferType != null" >
transfer_type,
</if>
<if test="uid != null" >
uid,
... ... @@ -59,9 +75,6 @@
<if test="amount != null" >
amount,
</if>
<if test="transferType != null" >
transfer_type,
</if>
<if test="status != null" >
status,
</if>
... ... @@ -71,19 +84,25 @@
<if test="updateTime != null" >
update_time,
</if>
<if test="transferCode != null" >
transfer_code,
<if test="alipayTradeResult != null" >
alipay_trade_result,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="id != null" >
#{id,jdbcType=INTEGER},
</if>
<if test="orderCode != null" >
#{orderCode,jdbcType=BIGINT},
<if test="buyerOrderCode != null" >
#{buyerOrderCode,jdbcType=BIGINT},
</if>
<if test="sellerOrderCode != null" >
#{sellerOrderCode,jdbcType=BIGINT},
</if>
<if test="alipayTradeId != null" >
#{alipayTradeId,jdbcType=VARCHAR},
</if>
<if test="orderId != null" >
#{orderId,jdbcType=VARCHAR},
<if test="transferType != null" >
#{transferType,jdbcType=INTEGER},
</if>
<if test="uid != null" >
#{uid,jdbcType=INTEGER},
... ... @@ -94,11 +113,8 @@
<if test="amount != null" >
#{amount,jdbcType=DECIMAL},
</if>
<if test="transferType != null" >
#{transferType,jdbcType=INTEGER},
</if>
<if test="status != null" >
#{status,jdbcType=TINYINT},
#{status,jdbcType=INTEGER},
</if>
<if test="createTime != null" >
#{createTime,jdbcType=INTEGER},
... ... @@ -106,19 +122,25 @@
<if test="updateTime != null" >
#{updateTime,jdbcType=INTEGER},
</if>
<if test="transferCode != null" >
#{transferCode,jdbcType=VARCHAR},
<if test="alipayTradeResult != null" >
#{alipayTradeResult,jdbcType=LONGVARCHAR},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.yohoufo.dal.order.model.OrdersPayTransfer" >
update orders_pay_transfer
<set >
<if test="orderCode != null" >
order_code = #{orderCode,jdbcType=BIGINT},
<if test="buyerOrderCode != null" >
buyer_order_code = #{buyerOrderCode,jdbcType=BIGINT},
</if>
<if test="sellerOrderCode != null" >
seller_order_code = #{sellerOrderCode,jdbcType=BIGINT},
</if>
<if test="orderId != null" >
order_id = #{orderId,jdbcType=VARCHAR},
<if test="alipayTradeId != null" >
alipay_trade_id = #{alipayTradeId,jdbcType=VARCHAR},
</if>
<if test="transferType != null" >
transfer_type = #{transferType,jdbcType=INTEGER},
</if>
<if test="uid != null" >
uid = #{uid,jdbcType=INTEGER},
... ... @@ -129,11 +151,8 @@
<if test="amount != null" >
amount = #{amount,jdbcType=DECIMAL},
</if>
<if test="transferType != null" >
transfer_type = #{transferType,jdbcType=INTEGER},
</if>
<if test="status != null" >
status = #{status,jdbcType=TINYINT},
status = #{status,jdbcType=INTEGER},
</if>
<if test="createTime != null" >
create_time = #{createTime,jdbcType=INTEGER},
... ... @@ -141,24 +160,39 @@
<if test="updateTime != null" >
update_time = #{updateTime,jdbcType=INTEGER},
</if>
<if test="transferCode != null" >
transfer_code = #{transferCode,jdbcType=VARCHAR},
<if test="alipayTradeResult != null" >
alipay_trade_result = #{alipayTradeResult,jdbcType=LONGVARCHAR},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.yohoufo.dal.order.model.OrdersPayTransfer" >
<update id="updateByPrimaryKeyWithBLOBs" parameterType="com.yohoufo.dal.order.model.OrdersPayTransfer" >
update orders_pay_transfer
set order_code = #{orderCode,jdbcType=BIGINT},
order_id = #{orderId,jdbcType=VARCHAR},
set buyer_order_code = #{buyerOrderCode,jdbcType=BIGINT},
seller_order_code = #{sellerOrderCode,jdbcType=BIGINT},
alipay_trade_id = #{alipayTradeId,jdbcType=VARCHAR},
transfer_type = #{transferType,jdbcType=INTEGER},
uid = #{uid,jdbcType=INTEGER},
alipay_account = #{alipayAccount,jdbcType=VARCHAR},
amount = #{amount,jdbcType=DECIMAL},
transfer_type = #{transferType,jdbcType=INTEGER},
status = #{status,jdbcType=TINYINT},
status = #{status,jdbcType=INTEGER},
create_time = #{createTime,jdbcType=INTEGER},
update_time = #{updateTime,jdbcType=INTEGER},
transfer_code = #{transferCode,jdbcType=VARCHAR}
alipay_trade_result = #{alipayTradeResult,jdbcType=LONGVARCHAR}
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.yohoufo.dal.order.model.OrdersPayTransfer" >
update orders_pay_transfer
set buyer_order_code = #{buyerOrderCode,jdbcType=BIGINT},
seller_order_code = #{sellerOrderCode,jdbcType=BIGINT},
alipay_trade_id = #{alipayTradeId,jdbcType=VARCHAR},
transfer_type = #{transferType,jdbcType=INTEGER},
uid = #{uid,jdbcType=INTEGER},
alipay_account = #{alipayAccount,jdbcType=VARCHAR},
amount = #{amount,jdbcType=DECIMAL},
status = #{status,jdbcType=INTEGER},
create_time = #{createTime,jdbcType=INTEGER},
update_time = #{updateTime,jdbcType=INTEGER}
where id = #{id,jdbcType=INTEGER}
</update>
</mapper>
\ No newline at end of file
... ...
... ... @@ -62,4 +62,141 @@
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from trade_bills
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.yohoufo.dal.order.model.TradeBills" >
insert into trade_bills (id, uid, order_code,
user_type, pay_type, trade_type,
income_outcome, amount, system_amount,
trade_status, create_time)
values (#{id,jdbcType=INTEGER}, #{uid,jdbcType=INTEGER}, #{orderCode,jdbcType=BIGINT},
#{userType,jdbcType=INTEGER}, #{payType,jdbcType=INTEGER}, #{tradeType,jdbcType=INTEGER},
#{incomeOutcome,jdbcType=INTEGER}, #{amount,jdbcType=DECIMAL}, #{systemAmount,jdbcType=DECIMAL},
#{tradeStatus,jdbcType=INTEGER}, #{createTime,jdbcType=INTEGER})
</insert>
<insert id="insertSelective" parameterType="com.yohoufo.dal.order.model.TradeBills" >
insert into trade_bills
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="id != null" >
id,
</if>
<if test="uid != null" >
uid,
</if>
<if test="orderCode != null" >
order_code,
</if>
<if test="userType != null" >
user_type,
</if>
<if test="payType != null" >
pay_type,
</if>
<if test="tradeType != null" >
trade_type,
</if>
<if test="incomeOutcome != null" >
income_outcome,
</if>
<if test="amount != null" >
amount,
</if>
<if test="systemAmount != null" >
system_amount,
</if>
<if test="tradeStatus != null" >
trade_status,
</if>
<if test="createTime != null" >
create_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="id != null" >
#{id,jdbcType=INTEGER},
</if>
<if test="uid != null" >
#{uid,jdbcType=INTEGER},
</if>
<if test="orderCode != null" >
#{orderCode,jdbcType=BIGINT},
</if>
<if test="userType != null" >
#{userType,jdbcType=INTEGER},
</if>
<if test="payType != null" >
#{payType,jdbcType=INTEGER},
</if>
<if test="tradeType != null" >
#{tradeType,jdbcType=INTEGER},
</if>
<if test="incomeOutcome != null" >
#{incomeOutcome,jdbcType=INTEGER},
</if>
<if test="amount != null" >
#{amount,jdbcType=DECIMAL},
</if>
<if test="systemAmount != null" >
#{systemAmount,jdbcType=DECIMAL},
</if>
<if test="tradeStatus != null" >
#{tradeStatus,jdbcType=INTEGER},
</if>
<if test="createTime != null" >
#{createTime,jdbcType=INTEGER},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.yohoufo.dal.order.model.TradeBills" >
update trade_bills
<set >
<if test="uid != null" >
uid = #{uid,jdbcType=INTEGER},
</if>
<if test="orderCode != null" >
order_code = #{orderCode,jdbcType=BIGINT},
</if>
<if test="userType != null" >
user_type = #{userType,jdbcType=INTEGER},
</if>
<if test="payType != null" >
pay_type = #{payType,jdbcType=INTEGER},
</if>
<if test="tradeType != null" >
trade_type = #{tradeType,jdbcType=INTEGER},
</if>
<if test="incomeOutcome != null" >
income_outcome = #{incomeOutcome,jdbcType=INTEGER},
</if>
<if test="amount != null" >
amount = #{amount,jdbcType=DECIMAL},
</if>
<if test="systemAmount != null" >
system_amount = #{systemAmount,jdbcType=DECIMAL},
</if>
<if test="tradeStatus != null" >
trade_status = #{tradeStatus,jdbcType=INTEGER},
</if>
<if test="createTime != null" >
create_time = #{createTime,jdbcType=INTEGER},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.yohoufo.dal.order.model.TradeBills" >
update trade_bills
set uid = #{uid,jdbcType=INTEGER},
order_code = #{orderCode,jdbcType=BIGINT},
user_type = #{userType,jdbcType=INTEGER},
pay_type = #{payType,jdbcType=INTEGER},
trade_type = #{tradeType,jdbcType=INTEGER},
income_outcome = #{incomeOutcome,jdbcType=INTEGER},
amount = #{amount,jdbcType=DECIMAL},
system_amount = #{systemAmount,jdbcType=DECIMAL},
trade_status = #{tradeStatus,jdbcType=INTEGER},
create_time = #{createTime,jdbcType=INTEGER}
where id = #{id,jdbcType=INTEGER}
</update>
</mapper>
\ No newline at end of file
... ...
... ... @@ -33,6 +33,11 @@
<groupId>com.yohoufo.fore</groupId>
<artifactId>yohoufo-fore-product</artifactId>
</dependency>
<dependency>
<groupId>com.yohoufo.fore</groupId>
<artifactId>yohoufo-fore-user</artifactId>
</dependency>
<dependency>
<groupId>com.yoho.core</groupId>
... ...
... ... @@ -3,18 +3,26 @@ package com.yohoufo.order.model.request;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.Builder;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class CheckupRequest {
@ToString
public class TransferMoneyRequest {
private long buyerOrderCode;
long orderCode;
private long sellerOrderCode;
/**
* 鉴定结果 1:鉴定通过; 2:鉴定不通过
* <pre>
* 1:鉴定通过(货款-->卖家);
* 2:鉴定不通过(保证金 --> 买家);
* 3:有买家时卖家不卖了(保证金 --> 买家)
* </pre>
*/
int checkupResult;
private int type;
}
... ...
package com.yohoufo.order.service.impl;
import java.math.BigDecimal;
import java.util.Date;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yoho.core.common.utils.DateUtil;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yoho.tools.common.beans.ApiResponse;
import com.yohoufo.common.caller.UfoServiceCaller;
import com.yohoufo.common.utils.TimeUtils;
import com.yohoufo.dal.order.*;
import com.yohoufo.dal.order.model.*;
import com.yohoufo.order.common.*;
import com.yohoufo.order.constants.OrderConstant;
import com.yohoufo.order.constants.RefundContant;
import com.yohoufo.order.model.*;
import com.yohoufo.dal.order.BuyerOrderGoodsMapper;
import com.yohoufo.dal.order.BuyerOrderMapper;
import com.yohoufo.dal.order.BuyerOrderMetaMapper;
import com.yohoufo.dal.order.OrdersPayMapper;
import com.yohoufo.dal.order.OrdersPayRefundMapper;
import com.yohoufo.dal.order.OrdersPayTransferMapper;
import com.yohoufo.dal.order.SellerOrderMapper;
import com.yohoufo.dal.order.SellerOrderMetaMapper;
import com.yohoufo.dal.order.TradeBillsMapper;
import com.yohoufo.dal.order.model.BuyerOrder;
import com.yohoufo.dal.order.model.OrdersPay;
import com.yohoufo.order.common.*;
import com.yohoufo.dal.order.model.OrdersPayRefund;
import com.yohoufo.dal.order.model.OrdersPayTransfer;
import com.yohoufo.dal.order.model.SellerOrder;
import com.yohoufo.dal.order.model.SellerOrderMeta;
import com.yohoufo.dal.order.model.TradeBills;
import com.yohoufo.order.common.OrderCodeType;
import com.yohoufo.order.common.Payment;
import com.yohoufo.order.constants.OrderConstant;
import com.yohoufo.order.constants.RefundContant;
import com.yohoufo.order.model.OrderInfo;
import com.yohoufo.order.model.PayQueryBo;
import com.yohoufo.order.model.PayRefundBo;
import com.yohoufo.order.model.PaymentData;
import com.yohoufo.order.model.request.CheckupRequest;
import com.yohoufo.order.model.request.PaymentRequest;
import com.yohoufo.order.model.request.TransferMoneyRequest;
import com.yohoufo.order.model.response.PaymentConfirmRsp;
import com.yohoufo.order.model.response.PrepayResponse;
import com.yohoufo.order.service.AbstractOrderPaymentService;
... ... @@ -27,18 +50,10 @@ import com.yohoufo.order.service.IPaymentService;
import com.yohoufo.order.service.SellerOrderPaymentService;
import com.yohoufo.order.service.pay.AbstractPayService;
import com.yohoufo.order.service.pay.alipay.AlipayOuyinService;
import com.yohoufo.order.service.pay.weixin.WeixinPayAppService;
import com.yohoufo.order.service.pay.weixin.WeixinPayBlkAppService;
import com.yohoufo.order.service.pay.weixin.WeixinPayUFOAppService;
import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
import com.yohoufo.order.service.support.codegenerator.bean.CodeMeta;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.Date;
import com.yohoufo.user.responseVO.AuthorizeResultRespVO;
@Service
... ... @@ -78,6 +93,21 @@ public class PaymentServiceImpl implements IPaymentService {
@Autowired
SellerOrderMapper sellerOrderMapper;
@Autowired
SellerOrderMetaMapper sellerOrderMetaMapper;
@Autowired
OrdersPayTransferMapper ordersPayTransferMapper;
@Autowired
BuyerOrderMapper buyerOrderMapper;
@Autowired
UfoServiceCaller ufoServiceCaller;
@Autowired
TradeBillsMapper tradeBillsMapper;
/**
* 获取主场的订单service
... ... @@ -355,89 +385,240 @@ public class PaymentServiceImpl implements IPaymentService {
}
public void transferMon(CheckupRequest request){
// 参数检查
if (request.getOrderCode() < 0
|| request.getCheckupResult() <0){
logger.warn("transferMon request empty");
throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
}
// 未更新前,买家订单号的状态: 鉴定中
// 买家订单号信息
OrderInfo orderInfo = buyerOrderPaymentService.getOrderInfo(request.getOrderCode());
if (orderInfo == null) {
logger.warn("getOrderInfo order not exist, orderCode is {}", request.getOrderCode());
throw new ServiceException(ServiceError.ORDER_NULL);
}
// TODO 安全性校验:比如对转账的金额限额
// 保证金抽成 货款抽成 都在货款抽成
// 运费买家下单的时候 确定的
// 鉴定通过: 1、保证金退款给卖家(参见退款接口) 2、打货款给卖家
if (request.getCheckupResult() == 1){
// 根据买家订单号,查支付成功记录
OrdersPay ordersPay = ordersPayMapper.selectOrdersPay(orderInfo.getOrderCode(), orderInfo.getUid());
if (ordersPay == null){
}
// 实施转账
}
// 鉴定不通过: 1、保证金赔款给买家
else if(request.getCheckupResult() == 2){
// 检查 保证金是否已经支付
// 1.根据买家订单号 获取 skup
BuyerOrderGoods buyerOrderGoods = buyerOrderGoodsMapper.selectByOrderCode(orderInfo.getUid(), orderInfo.getOrderCode());
if (buyerOrderGoods == null){
}
// 2.根据skup获取 卖家订单号
SellerOrder sellerOrder = sellerOrderMapper.selectBySkup(buyerOrderGoods.getSkup());
if (sellerOrder == null){
}
// 3.根据卖家订单号,获取支付成功结果
OrdersPay ordersPay = ordersPayMapper.selectOrdersPay(sellerOrder.getOrderCode(), sellerOrder.getUid());
if (ordersPay == null){
}
// 根据用户uid,获取卖家支付宝账号
// 从meta中获取,取费用系数
String transferOrderCode = String.valueOf(request.getOrderCode()) + ordersPay.getId();
String alipayAccount = "";
// 算费
double transferAmount = 0;
// TODO 下面转账的代码放入到提现接口
// 转账订单号必须唯一,所以一笔订单的一笔支付,只能转账一次
JSONObject jsonObject = alipayService.transferMoney(transferOrderCode, alipayAccount, transferAmount);
if (jsonObject.getInteger("code") == 10000){
}
/**
* <pre>
* 1:鉴定通过(货款-->卖家);
* 2:鉴定不通过(保证金 --> 买家);
* 3:有买家时卖家不卖了(保证金 --> 买家)
* </pre>
*
* @param request 请求
*/
public void transferMon(TransferMoneyRequest request){
logger.info("transferMon转账开始,request = {}", request);
long buyerOrderCode = request.getBuyerOrderCode();
long sellerOrderCode = request.getBuyerOrderCode();
int transferType = request.getType();
logger.info("transferMon参数检查");
// 订单号check
if (buyerOrderCode < 1 || sellerOrderCode < 1) {
logger.warn("transferMon orderCode empty");
throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
}
// 类型检查
if (transferType < 1 || transferType > 3) {
logger.warn("transferType invalid");
throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
}
// 买家订单检查
BuyerOrder buyerOrder = buyerOrderMapper.selectByOrderCode(buyerOrderCode);
if (buyerOrder == null) {
logger.warn("getOrderInfo buyer order not exist, orderCode is {}", buyerOrderCode);
throw new ServiceException(ServiceError.ORDER_NULL);
}
// 卖家订单检查
SellerOrder sellerOrder = sellerOrderMapper.selectByOrderCode(sellerOrderCode);
if (sellerOrder == null){
logger.warn("getOrderInfo seller order not exist, orderCode is {}", sellerOrderCode);
throw new ServiceException(ServiceError.ORDER_NULL);
}
// 记录转账记录到 orders_pay_transfer
// 更新订单状态
// 查看是否已经有转账记录
OrdersPayTransfer exist = ordersPayTransferMapper.selectByBuyerOrderCode(buyerOrderCode);
if (exist != null) {
logger.warn("getOrderInfo order not exist, orderCode is {}", buyerOrderCode);
throw new ServiceException(400, "订单已经处理过");
}
Integer targetUid = transferType == 1 ? sellerOrder.getUid() : buyerOrder.getUid();
if (targetUid == null || targetUid < 1) {
logger.warn("uid {} 不合法", targetUid);
throw new ServiceException(400, "uid[" + targetUid + "]不合法");
}
String alipayAccount = getAlipayAccount(targetUid);
if (StringUtils.isBlank(alipayAccount)) {
logger.warn("uid {} 没有获取到有效的支付宝账号", targetUid);
throw new ServiceException(400, "uid[" + targetUid + "]没有获取到有效的支付宝账号");
}
logger.info("transferMon参数检查成功!");
int now = (int) (System.currentTimeMillis()/1000);
OrdersPayTransfer transfer = new OrdersPayTransfer();
transfer.setBuyerOrderCode(buyerOrderCode);
transfer.setSellerOrderCode(sellerOrderCode);
transfer.setAlipayTradeId("");
transfer.setAlipayTradeResult("");
transfer.setTransferType(transferType);
transfer.setUid(targetUid);
transfer.setAlipayAccount(alipayAccount);
transfer.setAmount(BigDecimal.ZERO);
transfer.setCreateTime(now);
transfer.setStatus(0);
try {
logger.info("transferMon插入初始化转账信息buyerOrderCode is {}", buyerOrderCode);
ordersPayTransferMapper.insert(transfer);
} catch (Exception e) {
logger.warn("insert ordersPayTransfer failed, orderCode is {}, msg is {}", buyerOrderCode, e.getMessage());
throw new ServiceException(400, "交易记录创建失败");
}
logger.info("transferMon插入初始化转账信息成功,接下来计算费用");
// 算费
BigDecimal transferAmount = calcTransferAmount(sellerOrder.getUid(), sellerOrder.getSkup(), transferType);
logger.info("transferMon计算费用结果为 {}", transferAmount);
if (transferAmount == null || transferAmount.compareTo(new BigDecimal("0.1")) < 0) {
logger.warn("transferMon计算费用结果为 {}, 不合法的金额", transferAmount);
throw new ServiceException(400, "不合法的金额");
}
transfer.setAmount(transferAmount);
// 转账
try {
logger.info("transferMon开始调用阿里接口参数buyerOrderCode={}, alipayAccount={}, transferAmount={}", buyerOrderCode, alipayAccount, transferAmount);
JSONObject jsonObject = alipayService.transferMoney(Long.toString(buyerOrderCode), alipayAccount, transferAmount);
if (jsonObject == null) {
logger.warn("转账失败 , orderCode is {}", buyerOrderCode);
transfer.setStatus(3);
throw new ServiceException(500, "转账失败");
}
transfer.setAlipayTradeResult(jsonObject.toJSONString());
// 成功
Integer code = null;
String orderId = null;
if (jsonObject.containsKey("code")
&& (code = jsonObject.getInteger("code")) == 10000
&& jsonObject.containsKey("order_id")
&& StringUtils.isNotBlank(orderId = jsonObject.getString("order_id"))) {
logger.info("转账成功,targeAccount is {}, amount is {}", alipayAccount, transferAmount);
transfer.setAlipayTradeId(orderId);
transfer.setStatus(1);
} else {
logger.warn("返回code或者order_id不是成功状态,code={}, orderId={}", code, orderId);
transfer.setStatus(3);
}
} catch (Exception e) {
transfer.setStatus(3);
logger.warn("转账失败 , orderCode is {}, msg is {}", buyerOrderCode, e.getMessage());
throw new ServiceException(500, "转账失败");
} finally {
logger.info("transferMon最后更新状态 status= {}", transfer.getStatus());
transfer.setUpdateTime(now);
ordersPayTransferMapper.updateByPrimaryKeySelective(transfer);
logger.info("transferMon最后更新状态完成,转账结束, buyerOrderCode is {}!", buyerOrderCode);
}
// 增加流水记录
TradeBills record = new TradeBills();
try {
record.setUid(targetUid);
record.setOrderCode(transferType == 1 ? sellerOrderCode : buyerOrderCode);
record.setUserType(transferType == 1 ? 2 : 1);
record.setPayType(1);
record.setTradeType(transferType == 1 ? 2 : 3);
record.setIncomeOutcome(1);
record.setAmount(transferAmount);
// 因为转账支付宝扣费累计计算,使用转账额
record.setSystemAmount(transferAmount.multiply(new BigDecimal("-1")));
record.setTradeStatus(1);
record.setCreateTime(now);
tradeBillsMapper.insert(record);
} catch (Exception e) {
logger.error("记录交易到数据库出错 err={}, rec = {}", e.getMessage(), record);
}
}
// 支付保证金流水记录
public void addPayEnsureRecord(Integer uid, Integer skup, Long orderCode, Integer payType, BigDecimal amount) {
// 增加流水记录
TradeBills record = new TradeBills();
try {
record.setUid(uid);
record.setOrderCode(orderCode);
record.setUserType(2);// 1:买家uid; 2:卖家uid
record.setPayType(payType);// 1:支付宝; 2:微信
record.setTradeType(1);//1:保证金;2:货款;3:补偿款
record.setIncomeOutcome(2);// 1:用户收入; 2:用户支出
record.setAmount(amount);
record.setSystemAmount(amount.multiply(new BigDecimal("-1")));// 有货收入
record.setTradeStatus(0);//0:订单未完结;1:订单完结
record.setCreateTime((int) (System.currentTimeMillis() / 1000));
tradeBillsMapper.insert(record);
} catch (Exception e) {
logger.error("记录交易到数据库出错 err={}, rec = {}", e.getMessage(), record);
}
}
// 支付货款流水记录
public void addPayBuyRecord(Integer uid, Long orderCode, Integer payType, BigDecimal amount) {
// 增加流水记录
TradeBills record = new TradeBills();
try {
record.setUid(uid);
record.setOrderCode(orderCode);
record.setUserType(1);// 1:买家uid; 2:卖家uid
record.setPayType(payType);// 1:支付宝; 2:微信
record.setTradeType(2);//1:保证金;2:货款;3:补偿款
record.setIncomeOutcome(2);// 1:用户收入; 2:用户支出
record.setAmount(amount);
record.setSystemAmount(amount.multiply(new BigDecimal("-1")));// 有货收入
record.setTradeStatus(0);//0:订单未完结;1:订单完结
record.setCreateTime((int) (System.currentTimeMillis() / 1000));
tradeBillsMapper.insert(record);
} catch (Exception e) {
logger.error("记录交易到数据库出错 err={}, rec = {}", e.getMessage(), record);
}
}
/**
private BigDecimal calcTransferAmount(Integer sellerUid, Integer skup, int transferType) {
SellerOrderMeta meta = sellerOrderMetaMapper.selectByMetaKey(sellerUid, skup, "fee");
if (meta == null) {
logger.warn("查询SellerOrderMeta无数据, sellerUid is {}, skup is {}", sellerUid, skup);
throw new ServiceException(500, "计费信息不完整");
}
if (StringUtils.isBlank(meta.getMetaValue())) {
logger.warn("查询SellerOrderMeta的MetaValue为空, sellerUid is {}, skup is {}", sellerUid, skup);
throw new ServiceException(500, "计费信息不完整");
}
try {
JSONObject metavalue = JSON.parseObject(meta.getMetaValue());
// 交易成功的情况
if (transferType == 1) {
return metavalue.getBigDecimal("income");
}
// (1-Y)*A
// 保证金
BigDecimal ensure = metavalue.getBigDecimal("earnestMoney");
// 保证金抽成
BigDecimal ensureYohoRage = metavalue.getJSONObject("serviceFeeRate").getBigDecimal("earnestMoney");
return ensure.multiply(BigDecimal.ONE.subtract(ensureYohoRage));
} catch (Exception e) {
logger.warn("计费信息不完整, sellerUid is {}, skup is {}, err is {}", sellerUid, skup, e.getMessage());
throw new ServiceException(500, "计费信息不完整");
}
}
@SuppressWarnings("unchecked")
private String getAlipayAccount(int targetUid) {
ApiResponse<AuthorizeResultRespVO> resp = ufoServiceCaller.call("ufo.user.aliPayAccountQuery", ApiResponse.class, targetUid);
if (resp != null) {
AuthorizeResultRespVO data = (AuthorizeResultRespVO) resp.getData();
if (data != null && data.getAlipayAccount() != null) {
return data.getAlipayAccount();
}
}
return null;
}
/**
* 支付
* @param request
* @return
... ...
... ... @@ -140,12 +140,12 @@ public abstract class AlipayServiceAbstract extends AbstractPayService {
* @param transferAmount
* @return
*/
public JSONObject transferMoney(String transferOrderCode, String alipayAccount, double transferAmount){
public JSONObject transferMoney(String transferOrderCode, String alipayAccount, BigDecimal transferAmount){
Map<String, String> queryParams = buildTransferParams(transferOrderCode, alipayAccount, transferAmount);
String respTxt = sendOpenApiRequest(transferOrderCode, queryParams);
JSONObject result = new JSONObject();
JSONObject result = null;
if (StringUtils.isNotBlank(respTxt)){
JSONObject json = JSON.parseObject(respTxt);
... ... @@ -237,7 +237,7 @@ public abstract class AlipayServiceAbstract extends AbstractPayService {
* @param orderData
* @return
*/
private Map<String, String> buildTransferParams(String transferOrderCode, String alipayAccount, double transferAmount) {
private Map<String, String> buildTransferParams(String transferOrderCode, String alipayAccount, BigDecimal transferAmount) {
Map<String, String> params = new HashMap<String, String>();
params.put("app_id", getAppId());
params.put("method", "alipay.fund.trans.toaccount.transfer");
... ... @@ -251,7 +251,7 @@ public abstract class AlipayServiceAbstract extends AbstractPayService {
bizJson.put("out_biz_no", transferOrderCode); // 商户转账唯一订单号
bizJson.put("payee_type", "ALIPAY_LOGONID");
bizJson.put("payee_account", alipayAccount); // 支付宝账号
bizJson.put("amount", transferAmount);
bizJson.put("amount", transferAmount.toString());
params.put("biz_content", bizJson.toJSONString());
... ...