Authored by tanling

Merge branch 'test6.9.12' of http://git.yoho.cn/ufo/yohoufo-fore into test6.9.12

Showing 21 changed files with 445 additions and 85 deletions
... ... @@ -11,9 +11,11 @@ import com.yohoufo.common.utils.ServletUtils;
import org.apache.commons.httpclient.HttpStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.bind.UnsatisfiedServletRequestParameterException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
... ... @@ -52,8 +54,10 @@ public class GlobalDefaultExceptionHandler {
}
//如果是请求URL匹配不了,则返回400
if (e instanceof UnsatisfiedServletRequestParameterException) {
log.warn("can not find validate request mapping at {}", request.getRequestURI());
if (e instanceof UnsatisfiedServletRequestParameterException
|| e instanceof MissingServletRequestParameterException
|| e instanceof MethodArgumentTypeMismatchException) {
log.warn("can not find validate request mapping at {}, params is {}", request.getRequestURI(), params);
response.setStatus(HttpStatus.SC_BAD_REQUEST);
return new ModelAndView();
}
... ...
... ... @@ -34,6 +34,8 @@ public interface SellerOrderMapper {
List<SellerOrder> selectBySkups(@Param("skupList") Collection<Integer> skups);
List<SellerOrder> selectByOrderCodes(@Param("orderCodes")Collection<Long> orderCodes);
/**
* 根据用户id查询卖的单数
* @param uid
... ...
... ... @@ -8,6 +8,8 @@ public class OrdersPayTransfer {
public static final Integer INTERFACE_TYPE_TRANSFER_WHEN_EXCEED_MILLION = 2;
public static final Integer INTERFACE_TYPE_TRANSFER_WALLET = 3;
private Integer id;
private Long buyerOrderCode;
... ...
... ... @@ -65,6 +65,18 @@
order by create_time desc
</select>
<select id="selectByOrderCodes" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from seller_order
where order_code IN
<foreach collection="orderCodes" item="orderCode" open="(" separator="," close=")">
#{orderCode,jdbcType=BIGINT}
</foreach>
</select>
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.yohoufo.dal.order.model.SellerOrder" useGeneratedKeys="true">
insert into seller_order (order_code, skup, uid,
... ...
... ... @@ -48,7 +48,7 @@
edit_time, edit_pid, order_by
from brand
</select>
<select id="selectExcludeAppraise" resultMap="BaseResultMap">
<select id="selectExcludeAppraise" resultType="java.lang.Integer">
select id
from brand where ex_raise = 1
</select>
... ...
package com.yohoufo.order.controller;
import com.google.common.base.Splitter;
import com.yohobuy.ufo.model.order.common.OrderListType;
import com.yohobuy.ufo.model.order.common.OrderStatus;
import com.yohobuy.ufo.model.order.common.SellerOrderListType;
... ... @@ -18,14 +19,17 @@ 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.OrderGoodsFinder;
import com.yohoufo.order.service.impl.*;
import com.yohoufo.order.utils.LoggerUtils;
import lombok.val;
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;
import java.util.stream.Collectors;
@RestController
@RequestMapping("/erp")
... ... @@ -52,6 +56,9 @@ public class ErpGWOrderController {
@Autowired
private BuyerOrderViewService buyerOrderViewService;
@Autowired
private OrderGoodsFinder orderGoodsFinder;
@RequestMapping(params = "method=ufo.buyer.orderNums")
@IgnoreSession
public BuyerOrderNums getBuyerOrderNums(@RequestParam("uid") int uid){
... ... @@ -208,6 +215,19 @@ public class ErpGWOrderController {
}
@IgnoreSignature
@IgnoreSession
@RequestMapping(value = "/findOrderGoods")
public ApiResponse findOrderGoods(@RequestParam(value = "orderCodes") String orderCodes) {
List<Long> orderCodeList = Splitter.on(",")
.trimResults()
.omitEmptyStrings()
.splitToList(orderCodes).stream()
.map(Long::valueOf)
.collect(Collectors.toList());
val result = orderGoodsFinder.find(orderCodeList);
return new ApiResponse.ApiResponseBuilder().code(200).data(result).build();
}
}
... ...
package com.yohoufo.order.controller;
import com.google.common.collect.Lists;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.order.model.response.OrderSummaryResp;
import com.yohoufo.order.service.IBuyerOrderService;
import com.yohoufo.order.service.impl.SellerOrderViewService;
import com.yohoufo.order.utils.LoggerUtils;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
public class OrderStatisticController {
private Logger logger = LoggerUtils.getBuyerOrderLogger();
@Autowired
private SellerOrderViewService sellerOrderViewService;
@Autowired
private IBuyerOrderService ibuyerOrderService;
/**
* 我的出售记录数,买入记录数
* 准备逐步弃用 from version 6.9.12
* @return
*/
@Deprecated
@RequestMapping(value = "/shopping", params = "method=ufo.order.summary")
public ApiResponse summary(@RequestParam(name = "uid") int uid,
@RequestParam(name = "client_type", required = false) String clientType){
logger.info("in ufo.order.summary, uid {}, clientType is {}", uid, clientType);
OrderSummaryResp orderSummaryResp1 = sellerOrderViewService.selectOrderNumByUid(uid);
OrderSummaryResp orderSummaryResp2 = ibuyerOrderService.selectOrderNumByUid(uid);
return new ApiResponse.ApiResponseBuilder().code(200).data(Lists.newArrayList(orderSummaryResp1, orderSummaryResp2)).message("查询成功").build();
}
@RequestMapping(params = "method=ufo.seller.orderSummary")
public ApiResponse sellerOrderSummary(@RequestParam(name = "uid") int uid,
@RequestParam(name = "client_type", required = false) String clientType){
logger.info("in ufo.seller.orderSummary, uid {}, clientType is {}", uid, clientType);
List<OrderSummaryResp> orderSummaryResps = sellerOrderViewService.getOrderCntListByUid(uid);
return new ApiResponse.ApiResponseBuilder().code(200).data(orderSummaryResps).message("查询成功").build();
}
}
... ...
package com.yohoufo.order.controller;
import com.google.common.collect.Lists;
import com.yohobuy.ufo.model.order.constants.OrderConstant;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.order.constants.ActivityTypeEnum;
import com.yohoufo.order.annotation.BlackUserType;
import com.yohoufo.order.common.BlackTypeEnum;
import com.yohoufo.order.constants.ActivityTypeEnum;
import com.yohoufo.order.constants.CouponConstants;
import com.yohoufo.order.model.request.ShoppingRequest;
import com.yohoufo.order.model.response.*;
import com.yohoufo.order.service.IBuyerOrderService;
import com.yohoufo.order.service.IShoppingService;
import com.yohoufo.order.service.impl.SellerOrderViewService;
import com.yohoufo.order.utils.CouponCodeUtils;
import com.yohoufo.order.utils.LoggerUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping(value = "/shopping")
... ... @@ -27,15 +26,7 @@ public class ShoppingController {
private Logger logger = LoggerUtils.getBuyerOrderLogger();
@Autowired
IShoppingService buyerOrderService;
@Autowired
private SellerOrderViewService sellerOrderViewService;
@Autowired
IBuyerOrderService ibuyerOrderService;
private IShoppingService buyerOrderService;
/**
* 结算
... ... @@ -170,22 +161,7 @@ public class ShoppingController {
return new ApiResponse.ApiResponseBuilder().code(200).data(submitResponse).message("提交订单SUCCESS").build();
}
/**
* 我的出售记录数,买入记录数
* @return
*/
@RequestMapping(params = "method=ufo.order.summary")
public ApiResponse summary(@RequestParam(name = "uid") int uid,
@RequestParam(name = "client_type", required = false) String clientType){
logger.info("in ufo.order.summary, uid {}, clientType is {}", uid, clientType);
OrderSummaryResp orderSummaryResp1 = sellerOrderViewService.selectOrderNumByUid(uid);
OrderSummaryResp orderSummaryResp2 = ibuyerOrderService.selectOrderNumByUid(uid);
return new ApiResponse.ApiResponseBuilder().code(200).data(Lists.newArrayList(orderSummaryResp1, orderSummaryResp2)).message("查询成功").build();
}
/**
... ...
package com.yohoufo.order.model.response;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* Created by li.ma on 2018/9/27.
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class OrderSummaryResp {
@JSONField(name = "actor")
private String actor;
private Integer listType;
@JSONField(name = "sum")
private Integer sum;
public OrderSummaryResp() {
}
public OrderSummaryResp(String actor, Integer sum) {
this.actor = actor;
this.sum = sum;
}
public String getActor() {
return actor;
}
public void setActor(String actor) {
this.actor = actor;
}
public Integer getSum() {
return sum;
}
public void setSum(Integer sum) {
this.sum = sum;
}
}
... ...
package com.yohoufo.order.service;
import com.google.common.collect.Lists;
import com.yohobuy.ufo.model.order.common.OrderCodeType;
import com.yohobuy.ufo.model.order.resp.OrderGoodsFindBO;
import com.yohobuy.ufo.model.resp.product.ProductResponceBo;
import com.yohoufo.dal.order.BuyerOrderGoodsMapper;
import com.yohoufo.dal.order.SellerOrderGoodsMapper;
import com.yohoufo.dal.order.SellerOrderMapper;
import com.yohoufo.dal.order.model.BuyerOrderGoods;
import com.yohoufo.dal.order.model.SellerOrder;
import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
import lombok.val;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
@Service
public class OrderGoodsFinder {
@Autowired
private BuyerOrderGoodsMapper buyerOrderGoodsMapper;
@Autowired
private SellerOrderMapper sellerOrderMapper;
@Autowired
private SellerOrderGoodsMapper sellerOrderGoodsMapper;
@Autowired
private OrderCodeGenerator orderCodeGenerator;
public List<OrderGoodsFindBO> find(List<Long> orderCodes) {
val orderCodeHoldList = orderCodes.stream()
.map(orderCode -> Pair.of(orderCode, orderCodeGenerator.expId(orderCode)))
.collect(Collectors.toList());
val buyerOrderCodeList = orderCodeHoldList.stream()
.filter(e -> e.getRight().getType() == OrderCodeType.BUYER_TYPE.getType())
.map(e -> e.getLeft())
.collect(Collectors.toList());
val sellerOrderCodeList = orderCodeHoldList.stream()
.filter(e -> e.getRight().getType() == OrderCodeType.SELLER_TYPE.getType())
.map(e -> e.getLeft())
.collect(Collectors.toList());
List<Pair<Long, Integer>> orderCodeList = Lists.newArrayList();
orderCodeList.addAll(findSkupForSellerOrderCode(sellerOrderCodeList));
orderCodeList.addAll(findSkupForBuyerOrderCode(buyerOrderCodeList));
if (CollectionUtils.isEmpty(orderCodeList)) {
return Lists.newArrayList();
}
val skupList = orderCodeList.stream()
.map(e -> e.getRight())
.collect(Collectors.toList());
List<SellerOrderGoods> sellerOrderGoodsList = sellerOrderGoodsMapper.selectBySkups(skupList);
return orderCodeList.stream()
.map(order -> sellerOrderGoodsList.stream()
.filter(e -> Objects.equals(e.getId(), order.getRight()))
.findFirst()
.map(e -> {
OrderGoodsFindBO bo = new OrderGoodsFindBO();
bo.setOrderCode(order.getLeft());
bo.setProductName(e.getProductName());
return bo;
})
.orElse(null)
)
.filter(Objects::nonNull)
.collect(Collectors.toList());
}
private List<Pair<Long, Integer>> findSkupForSellerOrderCode(List<Long> sellerOrderCodeList) {
if (CollectionUtils.isEmpty(sellerOrderCodeList)) {
return Lists.newArrayList();
}
List<SellerOrder> sellerOrders = sellerOrderMapper.selectByOrderCodes(sellerOrderCodeList);
return sellerOrders.stream()
.map(e -> Pair.of(e.getOrderCode(), e.getSkup()))
.collect(Collectors.toList());
}
private List<Pair<Long, Integer>> findSkupForBuyerOrderCode(List<Long> buyerOrderCodeList) {
if (CollectionUtils.isEmpty(buyerOrderCodeList)) {
return Lists.newArrayList();
}
List<BuyerOrderGoods> buyerOrderGoodsList = buyerOrderGoodsMapper.selectByOrderCodes(buyerOrderCodeList);
return buyerOrderGoodsList.stream()
.map(e -> Pair.of(e.getOrderCode(), e.getSkup()))
.collect(Collectors.toList());
}
}
... ...
... ... @@ -47,6 +47,14 @@ public class AlipayTransferChancelSelector {
return StringUtils.equals(lastTransferDate, nowDate);
}
public boolean isTransferWithWallet() {
return configReader.getBoolean("ufo.order.pay.transferWithWallet", false);
}
public boolean isTransferWithWallet(Integer interfaceType) {
return OrdersPayTransfer.INTERFACE_TYPE_TRANSFER_WALLET.equals(interfaceType);
}
public boolean isStopTransferWithAlipay(){
boolean isStop = configReader.getBoolean("ufo.order.pay.isStop.transfer", false);
... ...
... ... @@ -43,6 +43,7 @@ public class BuyerOrderAssistant {
@Data
public static class DepositSkuCheckNode{
private String depositCode;
private StorageDeposit psd;
private boolean existDepositGoods;
}
... ... @@ -77,6 +78,7 @@ public class BuyerOrderAssistant {
dsNode.setPsd(psd);
}
dsNode.setExistDepositGoods(existDepositGoods);
dsNode.setDepositCode(depositCode);
return dsNode;
}
... ... @@ -85,4 +87,7 @@ public class BuyerOrderAssistant {
Integer pboa = pbo.getAttributes();
return BuyerOrderUtils.isInstockDeposit(skupType, pboa);
}
}
... ...
... ... @@ -807,7 +807,11 @@ public class DepositServiceImpl implements DepositService {
return num;
}
LOGGER.info("updateDepositWaitToPick, uid is {}, depositCode is {}, old depositInfo is {}", uid, depositCode, deposit);
return storageDepositMapper.updateStorageStatus(deposit.getId(), StorageDepositStatusEnum.WAITING_OUT.getCode(), 0, DepositOutTypeEnum.OUTTYPE_DEPOSIT_CHANGE_TO_IN_STOCK.getCode(), uid);
if(!deposit.getStatus().equals(StorageDepositStatusEnum.HAS_IN.getCode())) {
LOGGER.warn("updateDepositWaitToPick preStatus error, depositCode is {}, status is {}", depositCode, deposit.getStatus());
throw new UfoServiceException(400, "寄存商品不是在库状态");
}
return storageDepositMapper.updateStorageStatus(deposit.getId(), StorageDepositStatusEnum.WAITING_QUERY.getCode(), 0, DepositOutTypeEnum.OUTTYPE_DEPOSIT_CHANGE_TO_IN_STOCK.getCode(), uid);
}
private List<DepositDetailBo> convertDepositResp(List<StorageDeposit> list, List<Long> orderCodeList){
... ...
... ... @@ -3,6 +3,7 @@ package com.yohoufo.order.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.common.base.Joiner;
import com.google.common.base.Throwables;
import com.google.common.collect.Lists;
import com.yoho.core.common.helpers.ImagesHelper;
import com.yoho.core.rabbitmq.YhProducer;
... ... @@ -31,7 +32,6 @@ import com.yohoufo.common.utils.UserInfoHiddenHelper;
import com.yohoufo.dal.order.*;
import com.yohoufo.dal.order.model.*;
import com.yohoufo.order.common.ExpressForMqSend;
import com.yohoufo.order.constants.MetaKey;
import com.yohoufo.order.constants.SellerConfig;
import com.yohoufo.order.event.BuyerOrderSellerDeliveryCheckEvent;
import com.yohoufo.order.event.ErpBuyerOrderEvent;
... ... @@ -171,6 +171,9 @@ public class ExpressInfoServiceImpl implements IExpressInfoService {
@Autowired
private SkupService skupService;
@Autowired
private ProductProxyService productProxyService;
/**
* 这个方法请尽量保持单一原则
... ... @@ -303,22 +306,27 @@ public class ExpressInfoServiceImpl implements IExpressInfoService {
if(existDepositGoods){
//set depot num
depotNum = DepotType.NJ.getCode();
//bind deposit code 2 buyer order
buyerOrderMetaService.saveDepositCode(depositCode, buyerUid, orderCode);
//生成内部使用的物流单号
wayBillCode = new StringBuilder()
.append(orderCode)
.append("_")
.append(depositCode).toString();
//TODO skup 下架
StorageDeposit psd = dscNode.getPsd();
//TODO 寄存商品 出库准备
}
//香港卖家不能售卖现货 在业务规则上天然互斥
if (isHKLargeSettlementSuper(sellerUid)) {
depotNum = DepotType.HK.getCode();
}
updateOrderCnt = processBuyerOrder(preparedData, expressCompanyId, expressType, wayBillCode, depotNum);
if (updateOrderCnt>0){
try {
processOrderDeliverByDepositGoods(preparedData, dscNode);
}catch (Exception ex){
LOGGER.warn("deliverToDepot processOrderDeliverByDepositGoods fail ,req {} error {}",
req, Throwables.getStackTraceAsString(ex));
}
}
break;
case GOODS_SERVICE:
... ... @@ -364,6 +372,31 @@ public class ExpressInfoServiceImpl implements IExpressInfoService {
LOGGER.info("deliverToDepot update buyer order status, orderCode {} result {} ", orderCode, updateOrderCnt);
}
private void processOrderDeliverByDepositGoods(BuyerOrderAssistant.PreparedData preparedData,
BuyerOrderAssistant.DepositSkuCheckNode dscNode){
if (!dscNode.isExistDepositGoods()){
return;
}
BuyerOrder buyerOrder = preparedData.getBuyerOrder();
Integer buyerUid = buyerOrder.getUid();
Long orderCode = buyerOrder.getOrderCode();
String depositCode = dscNode.getDepositCode();
//bind deposit code 2 buyer order
buyerOrderMetaService.saveDepositCode(depositCode, buyerUid, orderCode);
//TODO skup 下架
StorageDeposit psd = dscNode.getPsd();
Integer skup;
Integer productId;
if (Objects.nonNull(skup = psd.getNewSkup())){
// 减库存
productProxyService.subtractStorage(productId=psd.getProductId(), skup);
//
skupService.saleOut(skup);
}
//TODO 寄存商品 出库准备
}
@Override
public void returnBackCauseOfBuyerCancelAfterSellerSendOut(Integer sellerUid, Integer expressCompanyId, Long orderCode, String wayBillCode, Integer depotNum, String sellerMobile, boolean unSureFlag) {
Integer expressType = EnumExpressType.EXPRESS_TYPE_REBACK.getCode();
... ...
... ... @@ -47,12 +47,12 @@ import com.yohoufo.order.service.pay.unionpay.JsUnionpayService;
import com.yohoufo.order.service.pay.wallet.WalletPayService;
import com.yohoufo.order.service.pay.weixin.WeixinMiniappPayService;
import com.yohoufo.order.service.pay.weixin.WeixinPayUFORealAppService;
import com.yohoufo.order.service.proxy.WalletTransferService;
import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
import com.yohoufo.order.service.support.codegenerator.bean.CodeMeta;
import com.yohoufo.order.service.transfer.TransferResult;
import com.yohoufo.order.utils.LoggerUtils;
import com.yohoufo.order.utils.PaymentHelper;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -62,8 +62,8 @@ import java.math.BigDecimal;
import java.util.*;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
import static com.yohoufo.dal.order.model.OrdersPayTransfer.*;
import static com.yohoufo.order.common.BillTradeStatus.HK_AMOUNT_WAIT_PAYMENT;
import static com.yohoufo.order.common.BillTradeStatus.YOHO_STORE_AMOUNT_WAIT_PAYMENT;
import static com.yohoufo.order.common.TransferCase.EARNEST_MONEY_TO_BUYER;
... ... @@ -168,6 +168,8 @@ public class PaymentServiceImpl implements IPaymentService {
@Autowired
OrderCodeGenerator orderCodeGenerator;
@Autowired
private WalletTransferService walletTransferService;
/**
... ... @@ -519,12 +521,17 @@ public class PaymentServiceImpl implements IPaymentService {
// 转账
try {
logger.info("{}, transfer alipayAccount={}, transferAmount={}", logTag, alipayAccount, transferAmount);
if (alipayTransferChancelSelector.isTransferWithAlipayExceedMillionTransfer()) {
transfer.setInterfaceType(OrdersPayTransfer.INTERFACE_TYPE_TRANSFER_WHEN_EXCEED_MILLION);
if (alipayTransferChancelSelector.isTransferWithWallet()) {
transfer.setInterfaceType(INTERFACE_TYPE_TRANSFER_WALLET);
ordersPayTransferMapper.updateByPrimaryKeySelective(transfer);
transferWithWallet(logTag, record, buyerOrderCode, account, transferAmount, transfer);
} else if (alipayTransferChancelSelector.isTransferWithAlipayExceedMillionTransfer()) {
transfer.setInterfaceType(INTERFACE_TYPE_TRANSFER_WHEN_EXCEED_MILLION);
ordersPayTransferMapper.updateByPrimaryKeySelective(transfer);
transferWithAlipayExceedMillionTransfer(logTag, record, buyerOrderCode, account, transferAmount, transfer);
} else {
transfer.setInterfaceType(OrdersPayTransfer.INTERFACE_TYPE_TRANSFER_NON_EXCEED_MILLION);
transfer.setInterfaceType(INTERFACE_TYPE_TRANSFER_NON_EXCEED_MILLION);
ordersPayTransferMapper.updateByPrimaryKeySelective(transfer);
transferWithAlipayTransfer(logTag, record, buyerOrderCode, account, transferAmount, transfer);
}
... ... @@ -602,11 +609,24 @@ public class PaymentServiceImpl implements IPaymentService {
boolean exceedMillionAndSuccess = false;
transfer.setUpdateTime(now);
try {
if (alipayTransferChancelSelector.isTransferWithWallet()) {
transfer.setInterfaceType(INTERFACE_TYPE_TRANSFER_WALLET);
ordersPayTransferMapper.updateByPrimaryKeySelective(transfer);
TransferResult transferResult = walletTransferService.transfer(logTag, transfer.getUid(), orderCode, record.getTradeType(), amount);
if (transferResult.getCode() == 200) {
transfer.setStatus(1);
return true;
} else {
throwServiceException(transferResult.getCode(), transferResult.getMsg());
}
}
logger.info("{}, transfer start", logTag);
shoppingRiskWatchDog.checkAlipayBlackUser(aliPayAccount.getUid(), aliPayAccount);
shoppingRiskWatchDog.checkManualStopAlipayTransfer();
if (alipayTransferChancelSelector.isTransferWithAlipayExceedMillionTransfer()) {
transfer.setInterfaceType(2);
transfer.setInterfaceType(INTERFACE_TYPE_TRANSFER_WHEN_EXCEED_MILLION);
ordersPayTransferMapper.updateByPrimaryKeySelective(transfer);
Map<String, String> mapResult = transferWhenExceedMillion(transfer.getId(), record, orderCode, aliPayAccount, amount, now);
String resultStr = JSON.toJSONString(mapResult);
... ... @@ -619,7 +639,7 @@ public class PaymentServiceImpl implements IPaymentService {
}
}
transfer.setInterfaceType(1);
transfer.setInterfaceType(INTERFACE_TYPE_TRANSFER_NON_EXCEED_MILLION);
ordersPayTransferMapper.updateByPrimaryKeySelective(transfer);
jsonObject = alipayService.transferMoney(Long.toString(orderCode), aliPayAccount.getAlipayId(), aliPayAccount.getAlipayAccount(), amount);
if (jsonObject == null) {
... ... @@ -640,7 +660,7 @@ public class PaymentServiceImpl implements IPaymentService {
transfer.setStatus(1);
return true;
} else if (alipayTransferChancelSelector.isExceedMillion(jsonObject)) {
transfer.setInterfaceType(2);
transfer.setInterfaceType(INTERFACE_TYPE_TRANSFER_WHEN_EXCEED_MILLION);
ordersPayTransferMapper.updateByPrimaryKeySelective(transfer);
Map<String, String> mapResult = transferWhenExceedMillion(transfer.getId(), record, orderCode, aliPayAccount, amount, now);
String resultStr = JSON.toJSONString(mapResult);
... ... @@ -896,7 +916,9 @@ public class PaymentServiceImpl implements IPaymentService {
400, "转账记录已成功转账,请不要重复操作。");
Integer interfaceType = transfer.getInterfaceType();
logger.info("{}, transfer channel router {}", logTag, interfaceType);
if (alipayTransferChancelSelector.isTransferWithAlipayExceedMillionTransfer(interfaceType)) {
if (alipayTransferChancelSelector.isTransferWithWallet(interfaceType)) {
transferWithWalletAndAddSuccessTradeBills(logTag, tradeBills, orderCode, account, amount, transfer);
} else if (alipayTransferChancelSelector.isTransferWithAlipayExceedMillionTransfer(interfaceType)) {
transferWithAlipayExceedMillionTransfer(logTag, tradeBills, orderCode, account, amount, transfer);
} else {
transferWithAlipayTransferAndAddSuccessTradeBills(logTag, tradeBills, orderCode, account, amount, transfer);
... ... @@ -947,6 +969,36 @@ public class PaymentServiceImpl implements IPaymentService {
.riskWatcher(Arrays.asList((uid, aliRsp) -> shoppingRiskWatchDog.checkAlipayBlackUser(uid, aliRsp),
(uid, aliRsp) -> shoppingRiskWatchDog.checkManualStopAlipayTransfer()))
.transfer();
parseTransferResultAndAddSuccessTradeBills(logTag, tradeBills, orderCode, transfer, transferResult);
}
private void transferWithWalletAndAddSuccessTradeBills(String logTag, TradeBills tradeBills, long orderCode, AuthorizeResultRespVO account, BigDecimal amount, OrdersPayTransfer transfer) {
TransferResult transferResult = walletTransferService.transfer(logTag,account.getUid(),orderCode,tradeBills.getTradeType(),amount);
parseTransferResultAndAddSuccessTradeBills(logTag, tradeBills, orderCode, transfer, transferResult);
}
private void transferWithWallet(String logTag, TradeBills tradeBills, long orderCode, AuthorizeResultRespVO account, BigDecimal amount, OrdersPayTransfer transfer) {
TransferResult transferResult = walletTransferService.transfer(logTag,account.getUid(),orderCode,tradeBills.getTradeType(),amount);
parseTransferResultAndUpdateTradeBillToSuccess(logTag, tradeBills, orderCode, transfer, transferResult);
}
private void transferWithAlipayTransfer(String logTag, TradeBills tradeBills, long orderCode, AuthorizeResultRespVO account, BigDecimal amount, OrdersPayTransfer transfer) {
TransferResult transferResult = alipayService.newAlipayTransfer(account.getUid())
.transferOrderCode(Long.toString(orderCode))
.alipayUid(account.getAlipayId())
.alipayAccount(account.getAlipayAccount())
.transferAmount(amount)
.riskWatcher(Arrays.asList((uid, alipayUid) -> shoppingRiskWatchDog.checkAlipayBlackUser(uid, alipayUid),
(uid, alipayUid) -> shoppingRiskWatchDog.checkManualStopAlipayTransfer() ))
.transfer();
parseTransferResultAndUpdateTradeBillToSuccess(logTag, tradeBills, orderCode, transfer, transferResult);
}
private void parseTransferResultAndAddSuccessTradeBills(String logTag, TradeBills tradeBills, long orderCode, OrdersPayTransfer transfer, TransferResult transferResult) {
if (transferResult.getCode() == 200) {
logger.info("{}, transfer success and out trade no is {}", logTag, orderCode);
// 加新流水
... ... @@ -960,21 +1012,12 @@ public class PaymentServiceImpl implements IPaymentService {
ordersPayTransferMapper.updateByPrimaryKeySelective(transferSuccess);
} else {
logger.warn("{}, transfer fail {}", logTag, transferResult);
recordTransferFailResult(transfer, transferResult);
throwServiceException(transferResult.getCode(), transferResult.getMsg());
}
}
private void transferWithAlipayTransfer(String logTag, TradeBills tradeBills, long orderCode, AuthorizeResultRespVO account, BigDecimal amount, OrdersPayTransfer transfer) {
TransferResult transferResult = alipayService.newAlipayTransfer(account.getUid())
.transferOrderCode(Long.toString(orderCode))
.alipayUid(account.getAlipayId())
.alipayAccount(account.getAlipayAccount())
.transferAmount(amount)
.riskWatcher(Arrays.asList((uid, alipayUid) -> shoppingRiskWatchDog.checkAlipayBlackUser(uid, alipayUid),
(uid, alipayUid) -> shoppingRiskWatchDog.checkManualStopAlipayTransfer() ))
.transfer();
private void parseTransferResultAndUpdateTradeBillToSuccess(String logTag, TradeBills tradeBills, long orderCode, OrdersPayTransfer transfer, TransferResult transferResult) {
if (transferResult.getCode() == 200) {
logger.info("{}, transfer success and out trade no is {}", logTag, orderCode);
// 更新流水
... ... @@ -990,10 +1033,19 @@ public class PaymentServiceImpl implements IPaymentService {
} else {
alipayTransferChancelSelector.isExceedMillion(transferResult);
logger.warn("{}, transfer fail {}", logTag, transferResult);
recordTransferFailResult(transfer, transferResult);
throwServiceException(transferResult.getCode(), transferResult.getMsg());
}
}
private void recordTransferFailResult(OrdersPayTransfer transfer, TransferResult transferResult) {
OrdersPayTransfer transferFail = new OrdersPayTransfer();
transferFail.setId(transfer.getId());
transferFail.setAlipayTradeResult(JSONObject.toJSONString(transferResult));
transferFail.setUpdateTime(DateUtil.getCurrentTimeSecond());
ordersPayTransferMapper.updateByPrimaryKeySelective(transferFail);
}
private void transferWithAlipayExceedMillionTransfer(String logTag,
TradeBills tradeBills,
long orderCode,
... ...
... ... @@ -26,6 +26,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
... ... @@ -108,7 +109,7 @@ public class SellerOrderViewService {
if (cnt == null) {
//todo add cache
Integer num = sellerOrderGoodsMapper.selectCntByUidStatusList(uid, Arrays.asList(SkupStatus.CAN_SELL.getCode()));
List<SellerOrderListType> types = Arrays.asList(SellerOrderListType.WAITING_SEND, SellerOrderListType.WAITING_PAY);
List<SellerOrderListType> types = Arrays.asList(SellerOrderListType.SEND_OUT, SellerOrderListType.WAITING_PAY);
List<Integer> statusList = types.parallelStream().flatMap(solt -> solt.getStatus().parallelStream()).collect(Collectors.toList());
Integer buyerOrderNum = buyerOrderMapper.selectCntBySellerUid(uid, statusList);
logger.info("in seller order count uid {}, num {}, buyerOrderNum {}", uid, num, buyerOrderNum);
... ... @@ -129,6 +130,34 @@ public class SellerOrderViewService {
return new OrderSummaryResp("sell", cnt);
}
public List<OrderSummaryResp> getOrderCntListByUid(int uid) {
List<OrderSummaryResp> list = new ArrayList<>(8);
final String actor = TabType.SELL.getValue();
SellerOrderListType insale = SellerOrderListType.IN_SALE;
//TODO add cache
int num = sellerOrderGoodsMapper.selectCntByUidStatusList(uid, Arrays.asList(SkupStatus.CAN_SELL.getCode()));
OrderSummaryResp sellerGoodsSummary = new OrderSummaryResp(actor, insale.getType(), num);
list.add(sellerGoodsSummary);
//
List<SellerOrderListType> types = Arrays.asList(SellerOrderListType.WAITING_PAY,
SellerOrderListType.SEND_OUT,
SellerOrderListType.ORDER_SUCCESS,
SellerOrderListType.ORDER_FAILED);
for(SellerOrderListType solt : types) {
List<Integer> statusList = solt.getStatus();
int buyerOrderNum = buyerOrderMapper.selectCntBySellerUid(uid, statusList);
logger.info("in seller order count uid {}, num {}, buyerOrderNum {}", uid, num, buyerOrderNum);
//
OrderSummaryResp osResp = new OrderSummaryResp();
osResp.setActor(actor);
osResp.setSum(buyerOrderNum);
osResp.setListType(solt.getType());
list.add(osResp);
}
return list;
}
public OrderCntResp getOrderCnt(OrderRequest orderRequest, SellerOrderListType listType){
logger.info("in seller getOrderCnt req {} listType {}", orderRequest, listType);
int cnt ;
... ...
... ... @@ -22,6 +22,7 @@ import com.yohoufo.order.model.dto.BuyerOrderSubmitResult;
import com.yohoufo.order.model.dto.OrderBuilder;
import com.yohoufo.order.service.ISubmitOrderService;
import com.yohoufo.order.service.proxy.*;
import com.yohoufo.order.service.seller.SkupService;
import com.yohoufo.order.utils.LoggerUtils;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
... ... @@ -154,6 +155,9 @@ public class SubmitOrderServiceImpl implements ISubmitOrderService {
@Autowired
private OrderStatusFlowService orderStatusFlowService;
@Autowired
private SkupService skupService;
/**
* 创建订单
* @param orderBuilder
... ... @@ -340,11 +344,7 @@ public class SubmitOrderServiceImpl implements ISubmitOrderService {
private int updSellerOrderGoods(OrderBuilder orderBuilder) {
int skup;
int uid = orderBuilder.getUid();
SellerOrderGoods condition = new SellerOrderGoods();
condition.setId(skup = orderBuilder.getSkup());
condition.setExceptStatus(SkupStatus.CAN_SELL.getCode());
condition.setStatus(SkupStatus.SELL_OUT.getCode());
int num = sellerOrderGoodsMapper.updateStatusBySkpu(condition);
int num = skupService.saleOut(skup= orderBuilder.getSkup());
if (num == 0 ){
logger.warn("in buyer create order fail on update skup status , uid {} skup {}", uid, skup);
throw new ServiceException(ServiceError.ORDER_SKUP_CANNOT_SELL);
... ...
package com.yohoufo.order.service.proxy;
import com.yohobuy.ufo.model.user.resp.AuthorizeResultRespVO;
import com.yohoufo.dal.order.model.OrdersPayTransfer;
import com.yohoufo.dal.order.model.TradeBills;
import com.yohoufo.order.service.transfer.TransferResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
@Slf4j
@Service
public class DefaultWalletTransferService implements WalletTransferService {
@Override
public TransferResult transfer(String logTag,
Integer uid,
Long orderCode,
Integer tradeType,
BigDecimal transferAmount) {
//TODO
log.info("{}, transfer success uid is {} orderCode is {} tradeType is {} transferAmount is {}",
logTag, uid, orderCode, tradeType, transferAmount);
return TransferResult.builder()
.code(505)
.transferOrderCode(orderCode.toString())
.msg("转账到钱包接口未实现")
.build();
}
}
... ...
package com.yohoufo.order.service.proxy;
import com.yohobuy.ufo.model.user.resp.AuthorizeResultRespVO;
import com.yohoufo.dal.order.model.OrdersPayTransfer;
import com.yohoufo.dal.order.model.TradeBills;
import com.yohoufo.order.service.transfer.TransferResult;
import java.math.BigDecimal;
public interface WalletTransferService {
TransferResult transfer(String logTag,
Integer uid,
Long orderCode,
Integer tradeType,
BigDecimal amount);
}
... ...
package com.yohoufo.order.service.seller;
import com.yoho.core.dal.datasource.annotation.Database;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yohobuy.ufo.model.GoodsSize;
import com.yohobuy.ufo.model.order.bo.GoodsInfo;
import com.yohobuy.ufo.model.order.common.SkupStatus;
... ... @@ -9,6 +11,7 @@ import com.yohobuy.ufo.model.response.StorageDataResp;
import com.yohoufo.dal.order.SellerOrderGoodsMapper;
import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.order.convert.GoodsInfoConvertor;
import com.yohoufo.order.model.dto.OrderBuilder;
import com.yohoufo.order.service.proxy.ProductProxyService;
import com.yohoufo.order.service.seller.support.SkupTypeCodeSupport;
import com.yohoufo.order.utils.LoggerUtils;
... ... @@ -139,4 +142,15 @@ public class SkupService {
productProxyService.setDepotNum(skup,depotNum);
return result;
}
@Transactional(propagation = Propagation.REQUIRED)
@Database(ForceMaster=true, DataSource="ufo_order")
public int saleOut(int skup) {
SellerOrderGoods condition = new SellerOrderGoods();
condition.setId(skup);
condition.setExceptStatus(SkupStatus.CAN_SELL.getCode());
condition.setStatus(SkupStatus.SELL_OUT.getCode());
int num = sellerOrderGoodsMapper.updateStatusBySkpu(condition);
return num;
}
}
... ...
... ... @@ -42,4 +42,7 @@ ufo.order.seller.noticeHKSellerEmailTo=chao.chen@yoho.cn,xiuchun.luo@yoho.cn
ufo.user.idCertSwitch=false
#实名认证提示版本升级开关
ufo.user.idCertUpdateVersionSwitch = true
\ No newline at end of file
ufo.user.idCertUpdateVersionSwitch = true
ufo.order.pay.transferWithWallet=true
\ No newline at end of file
... ...