Authored by tanling

申请寄存返利-第一版

... ... @@ -2,6 +2,7 @@ package com.yohoufo.dal.order;
import com.yohoufo.dal.order.model.OrdersPayTransfer;
import org.apache.ibatis.annotations.Param;
public interface OrdersPayTransferMapper {
... ... @@ -11,6 +12,8 @@ public interface OrdersPayTransferMapper {
OrdersPayTransfer selectByPrimaryKey(Integer id);
int selectByUidAndTransferType(@Param("uid") Integer uid, @Param("transferType") Integer transferType);
int updateByPrimaryKeySelective(OrdersPayTransfer record);
int updateByPrimaryKey(OrdersPayTransfer record);
... ...
... ... @@ -48,6 +48,7 @@ public class SellerWalletDetail {
SELLER_CANCEL("卖家不卖了", 31),
SELLER_OVER_TIME("卖家发货超时", 32),
APPRAISE_FAIL("鉴定不通过", 33),
DEPOSIT_REBATE("申请寄存返利", 53),
SELLER_SHAM_SEND_OUT("卖家虚假发货", 34),
MINI_FAULT_REJECT("瑕疵确认不接受", 35),
BUYER_CANCEL_NO_DELIVERY("买家取消(无物流)", 41),
... ...
... ... @@ -40,6 +40,14 @@
where buyer_order_code = #{buyerOrderCode,jdbcType=INTEGER}
</select>
<select id="selectByUidAndTransferType" resultMap="BaseResultMap" parameterType="java.lang.Long" >
select
count(1)
from orders_pay_transfer
where uid = #{uid,jdbcType=INTEGER}
and transfer_type = #{transferType,jdbcType=INTEGER}
</select>
<insert id="insert" parameterType="com.yohoufo.dal.order.model.OrdersPayTransfer" useGeneratedKeys="true" keyProperty="id" >
insert into orders_pay_transfer (id, buyer_order_code, seller_order_code,
alipay_trade_id, transfer_type, uid,
... ...
... ... @@ -14,7 +14,8 @@ public enum TransferCase {
ALL_GOODS_MONEY_TO_SELLER(1, "货款->卖家"),
EARNEST_MONEY_TO_BUYER(3,"保证金->买家"),
PART_GOODS_MONEY_TO_SELLER(6,"部分货款->卖家");
PART_GOODS_MONEY_TO_SELLER(6,"部分货款->卖家"),
DEPOSIT_REBATE_TO_USER(7, "申请寄存返利->用户");
private int code;
private String info;
... ...
... ... @@ -27,6 +27,10 @@ public enum AlarmConfig {
"buyerOrder.transferEarnestMoney",
"buyerOrder.refundGoodsMoney"),
DEPOSIT_REBATE_FAIL("申请寄存返利",
"appraiseOrder.depositRebate",
""),
SELLER_SHAM_SEND_OUT("卖家虚假发货",
"buyerOrder.transferEarnestMoney",
"buyerOrder.refundGoodsMoney");
... ...
... ... @@ -18,14 +18,13 @@ import com.yohoufo.order.model.request.OrderRequest;
import com.yohoufo.order.model.request.SaveQualityCheckInfoRequest;
import com.yohoufo.order.service.IBuyerOrderService;
import com.yohoufo.order.service.IPaymentService;
import com.yohoufo.order.service.impl.BuyerOrderCancelService;
import com.yohoufo.order.service.impl.BuyerOrderViewService;
import com.yohoufo.order.service.impl.SellerOrderService;
import com.yohoufo.order.service.impl.*;
import com.yohoufo.order.utils.LoggerUtils;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Objects;
@RestController
... ... @@ -48,6 +47,9 @@ public class ErpGWOrderController {
BuyerOrderCancelService buyerOrderCancelService;
@Autowired
AppraiseOrderService appraiseOrderService;
@Autowired
private BuyerOrderViewService buyerOrderViewService;
@RequestMapping(params = "method=ufo.buyer.orderNums")
... ... @@ -161,6 +163,16 @@ public class ErpGWOrderController {
return new ApiResponse.ApiResponseBuilder().code(200).message("鉴定中心确认收货成功").build();
}
@IgnoreSession
@IgnoreSignature
@RequestMapping(value = "/depositRebate")
public ApiResponse depositRebate(@RequestBody List<Long> orderCodeList) {
LOG.info("method depositRebate in, req is {}", orderCodeList);
appraiseOrderService.depositRebate(orderCodeList);
LOG.info("method depositRebate, req is {}", orderCodeList);
return new ApiResponse.ApiResponseBuilder().code(200).message("申请寄存返利").build();
}
/**
* 后台手工确认的清关失败的订单
... ...
... ... @@ -4,10 +4,19 @@ import com.yohobuy.ufo.model.order.common.OrderAttributes;
import com.yohobuy.ufo.model.order.req.DeliverToDepotReq;
import com.yohoufo.dal.order.model.AppraiseOrder;
import java.util.List;
public interface IGoodsService {
/**
* 申请寄存返利
* @param orderCodeList
*/
void depositRebate(List<Long> orderCodeList);
/**
* 发货
* @param req
*/
... ...
... ... @@ -21,6 +21,22 @@ public class AlipayTransferChancelSelector {
@Autowired
private ConfigReader configReader;
/**
* 申请寄存返利的单数
* @return
*/
public int getDepositRebateOrderCnt(){
return configReader.getInt("ufo.order.pay.depositRebateCnt", 4);
}
/**
* 申请寄存返利一单返利数目
* @return
*/
public double getDepositRebateAmount(){
return configReader.getDouble("ufo.order.pay.depositRebatePerAmount", 40);
}
public boolean isTransferWithAlipayExceedMillionTransfer() {
boolean value = configReader.getBoolean("ufo.order.pay.exceedSwitch", false);
if (value) {
... ...
... ... @@ -19,23 +19,31 @@ import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.dal.order.AppraiseOrderGoodsMapper;
import com.yohoufo.dal.order.AppraiseOrderMapper;
import com.yohoufo.dal.order.AppraiseOrderMetaMapper;
import com.yohoufo.dal.order.OrdersPayTransferMapper;
import com.yohoufo.dal.order.model.*;
import com.yohoufo.order.common.ClientType;
import com.yohoufo.order.common.TransferCase;
import com.yohoufo.order.constants.AlarmConfig;
import com.yohoufo.order.constants.MetaKey;
import com.yohoufo.order.convert.AppraiseOrderGoodsConvertor;
import com.yohoufo.order.convert.SellerOrderConvertor;
import com.yohoufo.order.model.dto.AppraiseOrderContext;
import com.yohoufo.order.model.request.TranseferCellNode;
import com.yohoufo.order.model.request.TransferMoneyRequest;
import com.yohoufo.order.service.IExpressInfoService;
import com.yohoufo.order.service.IGoodsService;
import com.yohoufo.order.service.handler.GoodsServiceRefundHandler;
import com.yohoufo.order.service.handler.transfer.AlipayTransferChancelSelector;
import com.yohoufo.order.service.proxy.InBoxFacade;
import com.yohoufo.order.service.proxy.ProductProxyService;
import com.yohoufo.order.service.proxy.UserProxyService;
import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
import com.yohoufo.order.utils.AddressHelper;
import com.yohoufo.order.utils.LoggerUtils;
import com.yohoufo.order.utils.NamedThreadFactory;
import lombok.Builder;
import lombok.Data;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -46,6 +54,10 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.stream.Collectors;
... ... @@ -68,10 +80,6 @@ public class AppraiseOrderService extends AbsGoodsServiceOrderService implements
@Autowired
IExpressInfoService expressInfoService;
@Autowired
private OrderCodeGenerator orderCodeGenerator;
@Autowired
private AppraiseOrderMetaMapper appraiseOrderMetaMapper;
... ... @@ -87,6 +95,82 @@ public class AppraiseOrderService extends AbsGoodsServiceOrderService implements
@Autowired
private PayRefundService payRefundService;
@Autowired
OrderCodeGenerator orderCodeGenerator;
@Autowired
private AlipayTransferChancelSelector alipayTransferChancelSelector;
@Autowired
TransferService transferService;
@Autowired
OrdersPayTransferMapper ordersPayTransferMapper;
private ExecutorService executorService = new ThreadPoolExecutor(5, 10, 60, TimeUnit.SECONDS,
new ArrayBlockingQueue<>(1000),
NamedThreadFactory.newThreadFactory("appraise"));
/**
* 申请寄存返利
* @param orderCodeList
*/
public void depositRebate(List<Long> orderCodeList){
logger.info("depositRebate param is {}", orderCodeList);
if (CollectionUtils.isEmpty(orderCodeList)){
return;
}
// 过滤1: 通过code过滤出来 goods_service的订单号
List<Long> goodServiceOrderLists = orderCodeList.stream()
.filter(orderCode -> orderCodeGenerator.expId(orderCode).getType() == OrderCodeType.GOODS_SERVICE.getType())
.collect(Collectors.toList());
// 过滤2: 通过查表 appaise_order & attribute
List<AppraiseOrder> appraiseOrderList = appraiseOrderMapper.selectByOrderCodeList(goodServiceOrderLists);
if (CollectionUtils.isEmpty(appraiseOrderList)){
return;
}
List<AppraiseOrder> depositCodeList = appraiseOrderList.stream()
.filter(appraiseOrder -> appraiseOrder.getAttributes() == OrderAttributes.DEPOSITE.getCode())
.collect(Collectors.toList());
// executorService.execute(() -> {
// 只返4单
int DEFAULT_REBATE_CNT = alipayTransferChancelSelector.getDepositRebateOrderCnt();
depositCodeList.stream().forEach(depositCode -> {
int rebateCnt = ordersPayTransferMapper.selectByUidAndTransferType(depositCode.getUid(),TransferCase.DEPOSIT_REBATE_TO_USER.getCode());
logger.info("rebate transfer cnt {}, uid {}", rebateCnt, depositCode.getUid());
if (rebateCnt < DEFAULT_REBATE_CNT){
TransferCase transferCase = TransferCase.DEPOSIT_REBATE_TO_USER;
TranseferCellNode transeferCellNode = new TranseferCellNode();
transeferCellNode.setUid(depositCode.getUid());
transeferCellNode.setAmount(new BigDecimal(alipayTransferChancelSelector.getDepositRebateAmount())); // 一单返40元
TransferMoneyRequest tmReq = TransferMoneyRequest.builder()
.sellerUid(depositCode.getUid())
.buyerOrderCode(depositCode.getOrderCode())
.type(transferCase.getCode())
.transferCase(transferCase)
.transeferCellNode(transeferCellNode)
.swdType(SellerWalletDetail.Type.DEPOSIT_REBATE)
.alarmConfig(AlarmConfig.DEPOSIT_REBATE_FAIL) // 打款失败的时候警告
.build();
transferService.transfer(tmReq);
}
});
// });
}
public AppraiseOrderComputeResp compute(AppraiseOrderComputeReq req){
logger.info("in AppraiseOrderService.compute req {}", req);
... ...
... ... @@ -100,9 +100,6 @@ public class PaymentServiceImpl implements IPaymentService {
MerchantOrderPaymentService merchantOrderPaymentService;
@Autowired
OrderCodeGenerator orderCodeGenerator;
@Autowired
WeixinPayUFORealAppService weixinPayAppService;
@Autowired
... ... @@ -171,6 +168,9 @@ public class PaymentServiceImpl implements IPaymentService {
@Autowired
private RefundManager refundManager;
@Autowired
OrderCodeGenerator orderCodeGenerator;
/**
* 订单支付结果确认
... ... @@ -419,6 +419,11 @@ public class PaymentServiceImpl implements IPaymentService {
private void penaltyEarnestIfWalletSellerOrder(BiFunction penaltyEarnestFunction, SellerWalletDetail.Type swdType, SellerOrder sellerOrder) {
if (sellerOrder == null){
return;
}
Integer sellerUid = sellerOrder.getUid();
Long sellerOrderCode = sellerOrder.getOrderCode();
Integer skup = sellerOrder.getSkup();
... ... @@ -462,6 +467,7 @@ public class PaymentServiceImpl implements IPaymentService {
Integer targetUid = transferMoneyModel.getTargetUid();
int now = transferMoneyModel.getNow();
penaltyEarnestIfWalletSellerOrder(request.getPenaltyEarnestFunction(), request.getSwdType(), sellerOrder);
OrdersPayTransfer transfer = createTransfer(buyerOrderCode, sellerOrderCode, transferCase.getCode(), null, targetUid, BigDecimal.ZERO, now);
... ... @@ -1310,54 +1316,87 @@ public class PaymentServiceImpl implements IPaymentService {
}
public TransferMoneyModel invoke() {
buyerOrderCode = request.getBuyerOrderCode();
logTag = String.format("transfer money orderCode is %s", buyerOrderCode);
// 订单号check
if (buyerOrderCode < 1L) {
logger.warn("{}, transfer fail orderCode empty", logTag);
throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
}
// 类型检查
transferCase = TransferCase.getTransferCase(request.getType());
if (transferCase == null) {
logger.warn("{}, transfer fail transferType invalid", logTag);
throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
}
// 买家订单检查
BuyerOrder buyerOrder = buyerOrderMapper.selectByOrderCode(buyerOrderCode);
if (buyerOrder == null) {
logger.warn("{}, transfer fail buyer order not exist", logTag);
throw new ServiceException(ServiceError.ORDER_NULL);
}
CodeMeta codeMeta = orderCodeGenerator.expId(buyerOrderCode);
// 买家订单号
if (codeMeta.getType() == OrderCodeType.BUYER_TYPE.getType()){
logTag = String.format("transfer money orderCode is %s", buyerOrderCode);
// 订单号check
if (buyerOrderCode < 1L) {
logger.warn("{}, transfer fail orderCode empty", logTag);
throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
}
// 类型检查
transferCase = TransferCase.getTransferCase(request.getType());
if (transferCase == null) {
logger.warn("{}, transfer fail transferType invalid", logTag);
throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
}
BuyerOrderGoods buyerOrderGoods = buyerOrderGoodsMapper.selectByOrderCode(buyerOrder.getUid(), buyerOrderCode);
if (buyerOrderGoods == null) {
logger.warn("{}, transfer fail buyerOrderGoods not exist", logTag);
throw new ServiceException(ServiceError.ORDER_NULL);
}
// 买家订单检查
BuyerOrder buyerOrder = buyerOrderMapper.selectByOrderCode(buyerOrderCode);
if (buyerOrder == null) {
logger.warn("{}, transfer fail buyer order not exist", logTag);
throw new ServiceException(ServiceError.ORDER_NULL);
}
BuyerOrderGoods buyerOrderGoods = buyerOrderGoodsMapper.selectByOrderCode(buyerOrder.getUid(), buyerOrderCode);
if (buyerOrderGoods == null) {
logger.warn("{}, transfer fail buyerOrderGoods not exist", logTag);
throw new ServiceException(ServiceError.ORDER_NULL);
}
// 卖家订单检查
Integer skup = buyerOrderGoods.getSkup();
sellerOrder = sellerOrderMapper.selectBySkup(skup);
if (sellerOrder == null) {
logger.warn("{}, transfer fail getOrderInfo seller order not exist, skup is {}", logTag, buyerOrderGoods.getSkup());
throw new ServiceException(ServiceError.ORDER_NULL);
// 卖家订单检查
Integer skup = buyerOrderGoods.getSkup();
sellerOrder = sellerOrderMapper.selectBySkup(skup);
if (sellerOrder == null) {
logger.warn("{}, transfer fail getOrderInfo seller order not exist, skup is {}", logTag, buyerOrderGoods.getSkup());
throw new ServiceException(ServiceError.ORDER_NULL);
}
Integer sellerUid = sellerOrder.getUid();
sellerOrderCode = sellerOrder.getOrderCode();
targetUserType = transferCase == EARNEST_MONEY_TO_BUYER ? TargetUserType.buyer : TargetUserType.seller;
targetUid = targetUserType == TargetUserType.buyer ? buyerOrder.getUid() : sellerUid;
if (targetUid == null || targetUid < 1) {
logger.warn("{}, transfer fail uid {} invalid", logTag, targetUid);
throw new ServiceException(400, "uid[" + targetUid + "]不合法");
}
now = (int) (System.currentTimeMillis() / 1000);
// 查看是否已经有转账记录
checkTransferExist(buyerOrderCode);
}
Integer sellerUid = sellerOrder.getUid();
sellerOrderCode = sellerOrder.getOrderCode();
// 商品服务
else if(codeMeta.getType() == OrderCodeType.GOODS_SERVICE.getType()){
targetUserType = transferCase == EARNEST_MONEY_TO_BUYER ? TargetUserType.buyer : TargetUserType.seller;
targetUid = targetUserType == TargetUserType.buyer ? buyerOrder.getUid() : sellerUid;
if (targetUid == null || targetUid < 1) {
logger.warn("{}, transfer fail uid {} invalid", logTag, targetUid);
throw new ServiceException(400, "uid[" + targetUid + "]不合法");
logTag = String.format("transfer money orderCode is %s", buyerOrderCode);
// 类型检查
transferCase = TransferCase.getTransferCase(request.getType());
if (transferCase == null) {
logger.warn("{}, transfer fail transferType invalid", logTag);
throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
}
// 商品返利的场合,不存在 买家订单号|卖家订单号的区分
sellerOrderCode = buyerOrderCode;
targetUserType = TargetUserType.seller;
targetUid = request.getSellerUid();
if (targetUid == null || targetUid < 1) {
logger.warn("{}, transfer fail uid {} invalid", logTag, targetUid);
throw new ServiceException(400, "uid[" + targetUid + "]不合法");
}
now = (int) (System.currentTimeMillis() / 1000);
}
now = (int) (System.currentTimeMillis() / 1000);
// 查看是否已经有转账记录
checkTransferExist(buyerOrderCode);
return this;
}
... ...