Authored by Lixiaodi

转账相关代码

... ... @@ -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;
}
}
/**
* 获取正负区间的一个随机数
... ...
... ... @@ -385,7 +385,15 @@ public class PaymentServiceImpl implements IPaymentService {
}
/**
* <pre>
* 1:鉴定通过(货款-->卖家);
* 2:鉴定不通过(保证金 --> 买家);
* 3:有买家时卖家不卖了(保证金 --> 买家)
* </pre>
*
* @param request 请求
*/
public void transferMon(TransferMoneyRequest request){
logger.info("transferMon转账开始,request = {}", request);
... ... @@ -419,7 +427,7 @@ public class PaymentServiceImpl implements IPaymentService {
throw new ServiceException(ServiceError.ORDER_NULL);
}
// 查看是否已经有记录
// 查看是否已经有转账记录
OrdersPayTransfer exist = ordersPayTransferMapper.selectByBuyerOrderCode(buyerOrderCode);
if (exist != null) {
logger.warn("getOrderInfo order not exist, orderCode is {}", buyerOrderCode);
... ... @@ -527,19 +535,40 @@ public class PaymentServiceImpl implements IPaymentService {
}
// 支付保证金流水记录
public void addPayEnsureRecord(Integer uid, Long orderCode, Integer payType, BigDecimal amount) {
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(2);
record.setPayType(payType);
record.setTradeType(1);
record.setIncomeOutcome(2);
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);
record.setSystemAmount(amount.multiply(new BigDecimal("-1")));// 有货收入
record.setTradeStatus(0);//0:订单未完结;1:订单完结
record.setCreateTime((int) (System.currentTimeMillis() / 1000));
tradeBillsMapper.insert(record);
} catch (Exception e) {
... ...