Authored by caoyan

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

... ... @@ -51,7 +51,7 @@ public interface StorageDepositMapper {
StorageDeposit selectByDepositCode(@Param("uid") int uid, @Param("depositCode")String depositCode, @Param("statusList")List<Integer> statusList);
List<StorageDeposit> getDepositOffs(@Param("uid") Integer uid, @Param("storageId") Integer storageId, @Param("count") Integer count);
int updateStorageStatus(@Param("depositCode")String depositCode, @Param("status")int status);
int updateStorageStatus(@Param("depositCode")String depositCode, @Param("status")int status, @Param("orderStatus")int orderStatus);
int getUserDepositCount(@Param("uid") Integer uid);
... ...
... ... @@ -347,7 +347,7 @@
<update id="updateStorageStatus">
update storage_deposit
set status = #{status,jdbcType=INTEGER} ,update_time = unix_timestamp(now())
where deposit_code = #{depositCode,jdbcType=VARCHAR} AND del_status = 0
where deposit_code = #{depositCode,jdbcType=VARCHAR} AND del_status = 0 AND order_status = #{orderStatus,jdbcType=INTEGER}
</update>
<select id="selectByOrderCode" resultMap="BaseResultMap">
... ...
... ... @@ -22,6 +22,11 @@ public interface MetaKey {
*/
String ACTIVITY_KEY = "activity";
String RECALL_ADDRESS = "recall_address",
RECALL_HIDDEN_ADDRESS ="recall_hidden_address";
/**
* 金额明细
*/
... ...
package com.yohoufo.order.controller;
import com.yohobuy.ufo.model.order.bo.DepositDetailBo;
import com.yohobuy.ufo.model.order.bo.SoldPrdComputeBo;
import com.yohobuy.ufo.model.order.req.DepositOrderComputeReq;
import com.yohobuy.ufo.model.order.req.SellerOrderComputeReq;
import com.yohobuy.ufo.model.order.resp.DepositOrderComputeResp;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.common.annotation.IgnoreSession;
import com.yohoufo.common.annotation.IgnoreSignature;
import com.yohoufo.common.cache.Cachable;
import com.yohoufo.common.cache.ControllerCacheAop;
import com.yohoufo.common.exception.GatewayException;
import com.yohoufo.order.model.response.OrderSubmitResponse;
import com.yohoufo.order.service.deposit.DepositOrderService;
... ... @@ -13,10 +18,13 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.lang.reflect.Method;
/**
* Created by li.ma on 2019/7/9.
*/
... ... @@ -27,6 +35,9 @@ public class DepositOrderController {
@Autowired
private DepositOrderService depositOrderService;
@Autowired
private ControllerCacheAop cacheAop;
/**
* 根据库存货号,计算召回的费用
* @param uid
... ... @@ -34,13 +45,13 @@ public class DepositOrderController {
* @param price
* @return
* @throws GatewayException
* http://java-yohoufo-fore.test3.ingress.dev.yohocorp.com/ufo-gateway/?debug=XYZ&method=ufo.deposit.computeRecall&uid=500031974&deposit_code=56257845
* http://java-yohoufo-fore.test3.ingress.dev.yohocorp.com/ufo-gateway/?debug=XYZ&method=ufo.deposit.computeRecall&uid=500031974&deposit_code=56257845&address_id=7777777
*/
@RequestMapping(params = "method=ufo.deposit.computeRecall")
@ResponseBody
public ApiResponse computePublishPrd(@RequestParam(name = "uid", required = true)int uid,
@RequestParam(name = "deposit_code", required = true)String depositCode,
@RequestParam(name="address_id")String addressId) throws GatewayException {
@RequestParam(name="address_id", required = false)String addressId) throws GatewayException {
DepositOrderComputeReq req = DepositOrderComputeReq.builder().uid(uid)
.address_id(addressId).depositCode(depositCode).build();
... ... @@ -57,7 +68,7 @@ public class DepositOrderController {
* @param price
* @return
* @throws GatewayException
* http://java-yohoufo-fore.test3.ingress.dev.yohocorp.com/ufo-gateway/?debug=XYZ&method=ufo.deposit.publishDepositOrder&uid=500031974&deposit_code=56257845
* http://java-yohoufo-fore.test3.ingress.dev.yohocorp.com/ufo-gateway/?debug=XYZ&method=ufo.deposit.publishDepositOrder&uid=500031974&deposit_code=56257845&address_id=7777777
*/
@RequestMapping(params = "method=ufo.deposit.publishDepositOrder")
@ResponseBody
... ... @@ -83,6 +94,7 @@ public class DepositOrderController {
*/
@RequestMapping(params = "method=ufo.deposit.orderInfo")
@ResponseBody
@Cachable(expire = 60)
public ApiResponse depositOrderInfo(@RequestParam(name = "uid", required = true)int uid,
@RequestParam(name = "deposit_code", required = true)String depositCode) throws GatewayException {
DepositOrderComputeReq req = DepositOrderComputeReq.builder().uid(uid).depositCode(depositCode).build();
... ... @@ -92,4 +104,20 @@ public class DepositOrderController {
return new ApiResponse.ApiResponseBuilder().code(200).data(resp).message("查询成功").build();
}
@RequestMapping("/depositOrder/clearDepositOrderCache")
@IgnoreSignature
@IgnoreSession
public ApiResponse clearDepositOrderCache(@RequestBody DepositOrderComputeReq bo) {
Integer uid = bo.getUid();
String depositCode = bo.getDepositCode();
LOG.info("in clearDepositOrderCache bo={}", bo);
try {
Method depositOrderInfo = DepositOrderController.class.getMethod("depositOrderInfo", new Class[]{Integer.class, String.class});
cacheAop.clearCache(depositOrderInfo, new Object[]{uid, depositCode});
} catch (Exception e) {
LOG.error("删除寄存订单缓存失败!", e);
}
return new ApiResponse(200, "缓存清除成功!", Boolean.TRUE);
}
}
... ...
... ... @@ -136,7 +136,7 @@ public class BuyerOrderPaymentService extends AbstractOrderPaymentService {
Integer skup = null;
try {
depositService.changeOwner(sellerUid = buyerOrder.getSellerUid(), skup = sellerOrderGoods.getId(),
orderCode = buyerOrder.getOrderCode(), buyerUid = buyerOrder.getUid());
orderCode = buyerOrder.getOrderCode(), buyerUid = buyerOrder.getUid(), true);
}catch (Exception ex){
logger.warn("pay successful, processDepositOrder invoke depositService.changeOwner fail, sellerUid {}, buyerUid {},orderCode {},skup {}",
sellerUid, buyerUid, orderCode, skup);
... ... @@ -196,10 +196,24 @@ public class BuyerOrderPaymentService extends AbstractOrderPaymentService {
orderOverTimeService.insertDeliveryTime(new OrderOverTime(orderCode, ts + secondsOfLimit, minutes));
}
private void processQuickDeliverOrder(BuyerOrder orderInfo, SellerOrderGoods sellerOrderGoods){
private void processQuickDeliverOrder(BuyerOrder buyerOrder, SellerOrderGoods sellerOrderGoods){
//寄存订单 & 闪购商品
if (SkupType.QUICK_DELIVER.getCode() == sellerOrderGoods.getAttributes()){
Integer sellerUid = null;
Integer buyerUid = null;
Long orderCode = null;
Integer skup = null;
try {
depositService.changeOwner(sellerUid = buyerOrder.getSellerUid(), skup = sellerOrderGoods.getId(),
orderCode = buyerOrder.getOrderCode(), buyerUid = buyerOrder.getUid(), false);
}catch (Exception ex){
logger.warn("pay successful, processQuickDeliverOrder invoke depositService.changeOwner fail, sellerUid {}, buyerUid {},orderCode {},skup {}",
sellerUid, buyerUid, orderCode, skup);
}
}
//todo notice
}
@Override
public void processAfterPay(OrderInfo orderInfo) {
... ...
... ... @@ -41,7 +41,7 @@ public interface DepositService {
// 剩余存储天数
int getRemainDay(Integer uid, String depositCode);
int changeStorageStatus(String depositCode, int status);
int changeStorageStatus(String depositCode, int status, int orderStatus);
/**
* Do 转 Vo
... ...
... ... @@ -2,7 +2,6 @@ package com.yohoufo.order.service;
import com.yohobuy.ufo.model.order.common.OrderListType;
import com.yohobuy.ufo.model.order.resp.BuyerOrderNums;
import com.yohobuy.ufo.model.order.resp.OrderCancelComputeResult;
import com.yohobuy.ufo.model.order.resp.OrderCntResp;
import com.yohobuy.ufo.model.order.vo.AddressInfo;
import com.yohoufo.order.model.request.OrderRequest;
... ... @@ -62,7 +61,12 @@ public interface IBuyerOrderService {
void miniFaultCreate(SaveQualityCheckInfoRequest request);
void modifyAddressOfDepositOrder(int uid, Long orderCode, String addressIdstr);
OrderCntResp getOrderCnt(OrderRequest req, OrderListType listType);
}
... ...
... ... @@ -13,15 +13,20 @@ import com.yohobuy.ufo.model.order.req.DepositOrderComputeReq;
import com.yohobuy.ufo.model.order.resp.DepositOrderComputeResp;
import com.yohobuy.ufo.model.order.vo.AddressInfo;
import com.yohoufo.common.exception.UfoServiceException;
import com.yohoufo.common.utils.AddressUtil;
import com.yohoufo.common.utils.StringUtil;
import com.yohoufo.dal.order.*;
import com.yohoufo.dal.order.model.*;
import com.yohoufo.order.convert.GoodsInfoConvertor;
import com.yohoufo.order.model.response.AppraiseAddressResp;
import com.yohoufo.order.model.response.OrderSubmitResponse;
import com.yohoufo.order.service.DepositService;
import com.yohoufo.order.service.IBuyerOrderMetaService;
import com.yohoufo.order.service.IBuyerOrderService;
import com.yohoufo.order.service.IExpressInfoService;
import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -30,6 +35,7 @@ import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
/**
* Created by li.ma on 2019/7/9.
... ... @@ -59,6 +65,12 @@ public class DepositOrderService {
@Autowired
private DepositService depositService;
@Autowired
private IExpressInfoService expressInfoService;
@Autowired
private IBuyerOrderService buyerOrderService;
/**
* 根据库存货号,计算需要召回的费用
* @param req
... ... @@ -75,12 +87,14 @@ public class DepositOrderService {
GoodsInfo goodsInfo = getGoodsInfo(skup); // 查询购买商品的详细信息
AddressInfo addressInfo = buyerOrderMetaService.getHiddenAddressInfo(req.getUid(), orderCode);
DepositOrderComputeResp.PriceInfo priceInfo = getFeeInfo(orderCode, req.getAddress_id()); // 获取各种费用
addressInfo.setAddress_id(AddressUtil.getDecryptStr(String.valueOf(addressInfo.getAddress_id())));// 加密addressId
setBuyerPrice(orderCode, priceInfo); // 设置入手价
DepositOrderComputeResp.PriceInfo priceInfo = getFeeInfo(orderCode, StringUtils.isEmpty(req.getAddress_id()) ?
String.valueOf(addressInfo.getAddress_id()) : req.getAddress_id(), req.getUid()); // 获取各种费用
AddressInfo addressInfo = buyerOrderMetaService.getHiddenAddressInfo(req.getUid(), orderCode);
setBuyerPrice(orderCode, priceInfo); // 设置入手价
return DepositOrderComputeResp.builder().depositRemainDay(getReplacedContent(DepositOrderComputeResp.DEPOSITREMAINDAY_TIP, depositRemainDay))
.userAddress(addressInfo).priceInfo(priceInfo).goodsInfo(goodsInfo).build();
... ... @@ -100,7 +114,7 @@ public class DepositOrderService {
long orderCode = orderCodeGenerator.generate(OrderCodeType.STORAGE_MANAGEMENT);
int now = (int) (System.currentTimeMillis()/1000);
DepositOrderComputeResp.PriceInfo priceInfo = getFeeInfo(orderCode, req.getAddress_id());
DepositOrderComputeResp.PriceInfo priceInfo = getFeeInfo(orderCode, req.getAddress_id(), req.getUid());
DepositOrder depositOrder = DepositOrder.builder().uid(uid).amount(priceInfo.getAmount())
.contractFee(priceInfo.getContractFee())
... ... @@ -109,7 +123,9 @@ public class DepositOrderService {
.eventType(DepositEventTypeEnum.DEPOSIT_RECALL_FEE.getCode()).orderCode(orderCode).payment(0).status(0).updateTime(now).build();
// TODO 创建召回地址
storageDeposit.getOrderCode();
LOG.info("enter publishRecallAddress begin save getOrderCode {} addressId is {} ", storageDeposit.getOrderCode(), req.getAddress_id());
buyerOrderService.modifyAddressOfDepositOrder(req.getUid(), storageDeposit.getOrderCode(), req.getAddress_id());
LOG.info("enter publishRecallAddress end save getOrderCode {} ", storageDeposit.getOrderCode());
LOG.info("enter publishDepositOrder begin save depositOrder {} ",depositOrder);
int num = depositOrderMapper.insert(depositOrder); // 生成订单数据,insert db
... ... @@ -143,8 +159,8 @@ public class DepositOrderService {
*/
public DepositOrderComputeResp depositOrderInfo(DepositOrderComputeReq req) {
StorageDeposit storageDeposit = checkStorageDeposit(req,
Lists.newArrayList(StorageDepositStatusEnum.WAITING_QUERY.getCode(), StorageDepositStatusEnum.WAITING_OUT.getCode()
, StorageDepositStatusEnum.HAS_OUT.getCode(), StorageDepositStatusEnum.HAS_END.getCode())); // 不存在的时候有异常
Lists.newArrayList(StorageDepositStatusEnum.WAITING_QUERY.getCode(), StorageDepositStatusEnum.WAITING_OUT.getCode(), StorageDepositStatusEnum.WAITING_IN.getCode()
, StorageDepositStatusEnum.HAS_OUT.getCode(), StorageDepositStatusEnum.HAS_END.getCode(), StorageDepositStatusEnum.HAS_IN.getCode())); // 不存在的时候有异常
DepositDetailBo depositDetailBo = depositService.convert(storageDeposit);
... ... @@ -156,6 +172,8 @@ public class DepositOrderService {
setBuyerPrice(storageDeposit.getOrderCode(), priceInfo); // 设置入手价
queryWaybillCode(depositDetailBo);// 查询召回(到期)后寄回的运单号
return DepositOrderComputeResp.builder().userAddress(addressInfo).priceInfo(priceInfo).goodsInfo(goodsInfo).depositDetailBo(depositDetailBo).build();
}
... ... @@ -195,9 +213,12 @@ public class DepositOrderService {
}
// 查询召回所需要的费用
private DepositOrderComputeResp.PriceInfo getFeeInfo(Long orderCode, String addressId) {
private DepositOrderComputeResp.PriceInfo getFeeInfo(Long orderCode, String addressId, int uid) {
AppraiseAddressResp resp = expressInfoService.queryByUserAddress(uid, addressId);
BigDecimal contractFee = new BigDecimal(15); // 违约金
BigDecimal shipFee = new BigDecimal(15); // 运费
BigDecimal shipFee = Optional.ofNullable(resp).map(AppraiseAddressResp::getShipFee).orElse(new BigDecimal(15)); // 运费
BigDecimal amount = contractFee.add(shipFee);
return DepositOrderComputeResp.PriceInfo.builder().contractFee(contractFee).shipFee(shipFee).amount(amount).build();
... ... @@ -216,4 +237,8 @@ public class DepositOrderService {
}
return storageDeposit;
}
private void queryWaybillCode(DepositDetailBo depositDetailBo) {
}
}
... ...
... ... @@ -17,6 +17,7 @@ import com.yohoufo.order.model.dto.SellerTaskDTO;
import com.yohoufo.order.model.dto.SellerTaskResult;
import com.yohoufo.order.model.dto.SkupDownShelfPrepareDto;
import com.yohoufo.order.model.dto.SkupDto;
import com.yohoufo.order.service.DepositService;
import com.yohoufo.order.service.MerchantOrderPaymentService;
import com.yohoufo.order.service.cache.CacheKeyBuilder;
import com.yohoufo.order.service.seller.setting.SellerService;
... ... @@ -55,6 +56,9 @@ public class SellerDownShelfTaskHandler extends AbstractSellerTaskHandler<SkupDo
@Autowired
private MerchantOrderPaymentService merchantOrderPaymentService;
@Autowired
private DepositService depositService;
@Override
protected boolean preHandle(SellerTaskResult result, SellerTaskDTO<SkupDownShelfPrepareDto> taskDto) {
SkupDownShelfPrepareDto sdspDto = taskDto.getProcessData();
... ... @@ -103,6 +107,15 @@ public class SellerDownShelfTaskHandler extends AbstractSellerTaskHandler<SkupDo
SellerWallet sellerWallet = postRefundEarnest(uid, taskId, isSuper, result, successOrders);
//明细
addWalletDetail(uid, taskId, isSuper, sellerWallet, successOrders);
}else{
for (Integer skup : result.successSkups) {
try {
depositService.changeSaleStatusOff(uid, skup);
}catch (Exception ex){
log.warn("in batch off shelve 4 quick deliver prd fail , uid {} skup {}",
uid, skup, ex);
}
}
}
//消息盒子
inboxNotify(uid, skupDtoMap);
... ...
... ... @@ -701,16 +701,8 @@ public class AppraiseService {
//退买家的钱
BigDecimal goodsMoney = buyerOrder.getAmount();
/*
BillLogEvent.BillLogEventBuilder bleb = BillLogEvent.builder()
.buyerUid(buyerUid).sellerUid(sellerUid).orderCode(orderCode)
.payType(buyerOrder.getPayment()).refundCase(RefundCase.BUYER_GOODS_MONEY)
.amount(goodsMoney)
.skup(skup);
*/
boolean refundGoodsMoneyFlag = new RefundGoodsMoneyHandler()
.loadPaymentRequest(buyerUid, orderCode, buyerOrder.getPayment(), goodsMoney)
//.loadBillLogEventBuilder(bleb)
.loadTargetOrderStatus(targetStatus)
.loadRefundAction(payRefundService::refund)
.loadLogger(LOGGER)
... ... @@ -1028,14 +1020,8 @@ public class AppraiseService {
//退钱给买家
BigDecimal goodsMoney = buyerOrder.getAmount();
/*BillLogEvent.BillLogEventBuilder bleb = BillLogEvent.builder()
.buyerUid(buyerUid).sellerUid(sellerUid).orderCode(orderCode)
.payType(buyerOrder.getPayment()).refundCase(RefundCase.BUYER_GOODS_MONEY)
.amount(goodsMoney)
.skup(skup);*/
boolean refundGoodsMoneyFlag = new RefundGoodsMoneyHandler()
.loadPaymentRequest(buyerUid, orderCode, buyerOrder.getPayment(), goodsMoney)
//.loadBillLogEventBuilder(bleb)
.loadTargetOrderStatus(targetStatus)
.loadRefundAction(payRefundService::refund)
.loadLogger(LOGGER)
... ...
... ... @@ -622,13 +622,6 @@ public class BuyerOrderCancelService {
void refundLeftOrderAmount(BuyerPenaltyCalResult bpcr, BuyerOrder buyerOrder){
Integer sellerUid = buyerOrder.getSellerUid();
BigDecimal leftBuyerMoney = bpcr.getLeftAmount();
/*
BillLogEvent.BillLogEventBuilder blebOfBuyer = BillLogEvent.builder()
.buyerUid(buyerUid).sellerUid(sellerUid).orderCode(orderCode)
.payType(buyerOrder.getPayment()).refundCase(RefundCase.BUYER_GOODS_MONEY)
.amount(leftBuyerMoney)
.skup(skup);
*/
logger.info("in BuyerCancelAfterProcessTask call begin payRefundService.refund buyer, buyerUid {}, orderCode {}, skup {} refundAmount {}",
buyerUid, orderCode, skup, leftBuyerMoney );
... ...
... ... @@ -11,17 +11,16 @@ import com.yohobuy.ufo.model.order.resp.OrderCntResp;
import com.yohobuy.ufo.model.order.vo.AddressInfo;
import com.yohoufo.common.alarm.EventBusPublisher;
import com.yohoufo.common.exception.UfoServiceException;
import com.yohoufo.common.utils.AddressUtil;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.common.utils.UserInfoHiddenHelper;
import com.yohoufo.dal.order.BuyerOrderGoodsMapper;
import com.yohoufo.dal.order.BuyerOrderMapper;
import com.yohoufo.dal.order.QualityCheckMapper;
import com.yohoufo.dal.order.SellerOrderGoodsMapper;
import com.yohoufo.dal.order.*;
import com.yohoufo.dal.order.model.*;
import com.yohoufo.dal.product.ProductMapper;
import com.yohoufo.dal.product.model.Product;
import com.yohoufo.order.common.ActionStatusHold;
import com.yohoufo.order.common.DelStatus;
import com.yohoufo.order.constants.MetaKey;
import com.yohoufo.order.event.*;
import com.yohoufo.order.model.PayQueryBo;
import com.yohoufo.order.model.request.OrderRequest;
... ... @@ -40,6 +39,7 @@ import com.yohoufo.order.service.pay.AbstractPayService;
import com.yohoufo.order.service.proxy.InBoxFacade;
import com.yohoufo.order.service.proxy.OrderStatusFlowService;
import com.yohoufo.order.service.proxy.ProductProxyService;
import com.yohoufo.order.service.proxy.UserProxyService;
import com.yohoufo.order.utils.BuyerOrderUtils;
import com.yohoufo.order.utils.LoggerUtils;
import org.apache.commons.collections.CollectionUtils;
... ... @@ -775,6 +775,85 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService {
orderStatusFlowService.addAsy(buyerOrder.getOrderCode(), targetStatus.getCode());
}
}
@Autowired
private BuyerOrderMetaMapper buyerOrderMetaMapper;
@Autowired
private UserProxyService userProxyService;
@Override
public void modifyAddressOfDepositOrder(int uid, Long orderCode, String addressIdstr) {
int addressId = AddressUtil.getDecryptStr(addressIdstr);
if (addressId < 0){
logger.warn("modifyAddressOfDepositOrder addressId invalidate, uid {}, orderCode {}, addressId is {}",
uid, orderCode, addressIdstr);
throw new ServiceException(ServiceError.ORDER_ADDRESSID_INVALIDATE);
}
BuyerOrder pbo = buyerOrderMapper.selectOnlyByOrderCode(orderCode);
if (pbo == null ){
logger.warn("in modifyAddressOfDepositOrder BuyerOrder is null,uid {} orderCode {} addressIdstr {}",
uid, orderCode, addressIdstr);
return;
}
Integer oa;
if (OrderAttributes.DEPOSITE.getCode() != (oa=pbo.getAttributes())){
logger.warn("in modifyAddressOfDepositOrder BuyerOrder.Attributes is {},uid {} orderCode {} addressIdstr {}",
oa, uid, orderCode, addressIdstr);
return;
}
//the address of send back 2 seller
AddressInfo hiddenBackAddress = userProxyService.getHiddenAddressInfo(uid, addressId);
AddressInfo noHiddenBackAddress = userProxyService.getAddressInfoNotHidden(uid, addressId);
final String key = MetaKey.RECALL_ADDRESS, hiiden_key = MetaKey.RECALL_HIDDEN_ADDRESS;
BuyerOrderMeta noHiddenAddressMeta=new BuyerOrderMeta();
noHiddenAddressMeta.setUid(uid);
noHiddenAddressMeta.setOrderCode(orderCode);
noHiddenAddressMeta.setMetaKey(key);
noHiddenAddressMeta.setMetaValue(JSONObject.toJSONString(noHiddenBackAddress));
//hidden address
BuyerOrderMeta hiddenAddressMeta=new BuyerOrderMeta();
hiddenAddressMeta.setUid(uid);
hiddenAddressMeta.setOrderCode(orderCode);
hiddenAddressMeta.setMetaKey(hiiden_key);
hiddenAddressMeta.setMetaValue(JSONObject.toJSONString(hiddenBackAddress));
//
List<BuyerOrderMeta> boms = new ArrayList<>(2);
boms.add(noHiddenAddressMeta);
boms.add(hiddenAddressMeta);
List<BuyerOrderMeta> pboms = buyerOrderMetaMapper.selectByMetaKeys(uid, orderCode, Arrays.asList(key, hiiden_key));
if(CollectionUtils.isEmpty(pboms)){
buyerOrderMetaMapper.insertBatch(boms);
}else{
boolean hitNoHidden = false;
boolean hitHidden = false;
for (BuyerOrderMeta pbom : pboms){
if (pbom.getMetaKey().equals(hiiden_key)){
hitHidden = true;
}
if (pbom.getMetaKey().equals(key)){
hitNoHidden = true;
}
}
doPersistent4AddessMeta(hitHidden, hiddenAddressMeta);
doPersistent4AddessMeta(hitNoHidden, noHiddenAddressMeta);
}
}
private void doPersistent4AddessMeta(boolean isExisted, BuyerOrderMeta bom){
if (isExisted){
buyerOrderMetaMapper.updateMetaValueByUidAndOrderCodeAndMetaKey(bom);
}else {
buyerOrderMetaMapper.insert(bom);
}
}
//清理缓存
... ...
... ... @@ -20,6 +20,8 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Objects;
@Service
public class DepositOrderPaymentService extends AbstractOrderPaymentService {
private final Logger logger = LoggerFactory.getLogger(getClass());
... ... @@ -129,7 +131,16 @@ public class DepositOrderPaymentService extends AbstractOrderPaymentService {
public void processAfterPay(OrderInfo orderInfo) {
DepositOrder depositOrder = depositOrderService.selectByOrderCode(orderInfo.getOrderCode());
depositService.changeStorageStatus(depositOrder.getDepositCode(), StorageDepositStatusEnum.WAITING_QUERY.getCode());
if (Objects.isNull(depositOrder)) {
logger.error("depositOrderService.selectByOrderCode is null, orderCode is {}", orderInfo.getOrderCode());
return;
}
// 更新为拣货状态的时候,必须是下架状态
int result = depositService.changeStorageStatus(depositOrder.getDepositCode(), StorageDepositStatusEnum.WAITING_QUERY.getCode(), OrderStatus.WAITING_PAY.getCode());
if (result != 1) {
logger.error("depositService.changeStorageStatus find wrong, depositCode is {}, result is {}", depositOrder.getDepositCode(), result);
return;
}
}
private OrderInfo buildOrderInfo(DepositOrder order) {
... ...
... ... @@ -151,6 +151,7 @@ public class DepositServiceImpl implements DepositService {
bo.setStorageId(depo.getStorageId());
BigDecimal least = leastMap.get(depo.getStorageId());
bo.setFlashMinPrice(least == null ? "" : least.toString());
bo.setDepositCode(depo.getDepositCode());
}
bo.setButtons(Arrays.asList(ButtonShowBo.back(), ButtonShowBo.addDepositDays(), depo.getOrderStatus() == 0 ? ButtonShowBo.grounding() : ButtonShowBo.detail("详情")));
result.add(bo);
... ... @@ -279,8 +280,8 @@ public class DepositServiceImpl implements DepositService {
return getRemainDay(sd.getDepositEndTime());
}
public int changeStorageStatus(String depositCode, int status) {
return storageDepositMapper.updateStorageStatus(depositCode, status);
public int changeStorageStatus(String depositCode, int status, int orderStatus) {
return storageDepositMapper.updateStorageStatus(depositCode, status, orderStatus);
}
/**
... ...
... ... @@ -4,6 +4,7 @@ import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yohobuy.ufo.model.order.bo.MerchantOrderAttachInfo;
import com.yohobuy.ufo.model.order.common.*;
import com.yohobuy.ufo.model.order.constants.SkupType;
import com.yohoufo.common.alarm.EventBusPublisher;
import com.yohoufo.common.alarm.UfoInfluxdbEvent;
import com.yohoufo.common.alarm.UfoInfluxdbVo;
... ... @@ -27,6 +28,7 @@ import com.yohoufo.order.model.request.TransferMoneyRequest;
import com.yohoufo.order.mq.DelayTime;
import com.yohoufo.order.mq.TopicConstants;
import com.yohoufo.order.mq.producer.TradeMqSender;
import com.yohoufo.order.service.DepositService;
import com.yohoufo.order.service.IPaymentService;
import com.yohoufo.order.service.MerchantOrderPaymentService;
import com.yohoufo.order.service.cache.CacheCleaner;
... ... @@ -51,6 +53,7 @@ import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
import com.yohoufo.order.service.support.codegenerator.bean.CodeMeta;
import com.yohoufo.order.utils.LoggerUtils;
import com.yohoufo.order.utils.PaymentHelper;
import com.yohoufo.order.utils.SellerGoodsHelper;
import lombok.Builder;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
... ... @@ -133,6 +136,9 @@ public class SellerOrderCancelService {
@Autowired
private OrderChangeListenerContainer orderChangeListenerContainer;
@Autowired
private DepositService depositService;
/**
* TODO 如何控制好并发,必须控制不能重复转账 退款
* 使用乐观锁,带着查询到的状态且符合条件时再去更新
... ... @@ -448,9 +454,22 @@ public class SellerOrderCancelService {
int result = cancelBeforeBuyerPayAction(sellerUid, orderCode, skup, statusNode);
if(result > 0 ){
refundEarnestMoney(sellerOrder, targetSOStatus,sellerOrder.getEarnestMoney());
//async execute msg
SellerOrderGoods psog = sellerOrderGoodsMapper.selectByPrimaryKey(skup);
SkupType skupType = SkupType.getSkupType(psog.getAttributes());
boolean isQuickDeliver = SellerGoodsHelper.isQuickDeliver(skupType);
if (isQuickDeliver){
try {
depositService.changeSaleStatusOff(sellerUid, skup);
}catch (Exception ex){
logger.warn("in cancelAfterPayButNotBuyAction changeSaleStatusOff fail, uid {} skup {}",
sellerUid, skup, ex);
}
}
if (!isQuickDeliver) {
refundEarnestMoney(sellerOrder, targetSOStatus, sellerOrder.getEarnestMoney());
}
//async execute msg
inBoxFacade.sellerPlaySelf(sellerUid, psog);
}
... ... @@ -623,13 +642,7 @@ public class SellerOrderCancelService {
} else {
logger.error("can not find penalty result, uid = {}, skup={}", sellerOrder.getUid(), sellerOrder.getSkup());
}
/*
BillLogEvent.BillLogEventBuilder bleb = BillLogEvent.builder()
.buyerUid(buyerUid).sellerUid(sellerUid).orderCode(buyerOrderCode)
.payType(buyerOrder.getPayment()).refundCase(RefundCase.BUYER_GOODS_MONEY)
.amount(goodsMoney)
.skup(sellerOrder.getSkup());
*/
// 退买家货款
new RefundGoodsMoneyHandler().loadLogger(logger)
.loadTargetOrderStatus(targetBOStatus)
... ... @@ -795,6 +808,19 @@ public class SellerOrderCancelService {
//
cacheCleaner.cleanList(sellerUid, TabType.SELL.getValue());
cacheCleaner.cleanSellerDetail(psog);
SkupType skupType = SkupType.getSkupType(psog.getAttributes());
boolean isQuickDeliver = SellerGoodsHelper.isQuickDeliver(skupType);
if (isQuickDeliver){
try {
depositService.changeSaleStatusOff(sellerUid, skup);
}catch (Exception ex){
logger.warn("in doCancelByErp changeSaleStatusOff fail, uid {} skup {}",
sellerUid, skup, ex);
}
}
if (!isQuickDeliver) {
double earnestMoney = sellerOrder.getEarnestMoney().doubleValue();
Integer sop = sellerOrder.getPayment() == null ? 0 : sellerOrder.getPayment();
... ... @@ -803,7 +829,7 @@ public class SellerOrderCancelService {
//不是超级卖家 ,上架商品用钱包支付保证金
MerchantOrderAttachInfo moai = null;
if(!sellerIsSuper && PaymentHelper.isWallet(sop)){
if (!sellerIsSuper && PaymentHelper.isWallet(sop)) {
moai = MerchantOrderAttachInfo.builder().uid(sellerUid)
.orderCode(orderCode).skup(skup).earnestMoney(sellerOrder.getEarnestMoney())
.type(orderCancelCase.getSwdType().getValue()).build();
... ... @@ -830,11 +856,14 @@ public class SellerOrderCancelService {
.loadSeller(sellerUid, sellerIsSuper, orderCode, targetSellerOrderStatus)
.loadLogger(logger)
.refund();
}
cpn = new CancelPreparedNode();
cpn.psog = psog;
return cpn;
}
/**
* 审核不通过
* @param auditCancelCase
... ...
... ... @@ -82,7 +82,7 @@ public class QuickDeliverGoodsService {
int storageId = context.getStorageId();
int uid = context.getUid();
BigDecimal salePrice = context.getSalePrice();
int successNum = 0;
//submit all as atomic operation, use transaction of DB
//all include : 1. skup, 2. order , 3. 寄回地址
for(String depositCode : context.getDepositCodes()) {
... ... @@ -114,15 +114,15 @@ public class QuickDeliverGoodsService {
String content = "用户" + uid + "发布闪购商品" + depositCode + "失败";
SmsAlarmEvent smsAlarmEvent = new SmsAlarmEvent("sellerOrder.create", "create", content);
EventBusPublisher.publishEvent(smsAlarmEvent);
logger.warn("in publish quick deliver Prd create order fail , uid {}, depositCode {}", uid, depositCode);
logger.warn("in publish quick deliver Prd create order fail , uid {}, depositCode {}", uid, depositCode, ex);
throw new ServiceException(ServiceError.EARNESTMONEY_ORDER_CREATE_FAIL);
}
syncPrd(context, depositCode);
successNum++;
}
DepositPublishResp resp = DepositPublishResp.builder()
DepositPublishResp resp = DepositPublishResp.builder().successNum(successNum)
.build();
return resp;
}
... ...
package com.yohoufo.order.service.seller.quickDeliver;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yohobuy.ufo.model.order.bo.GoodsInfo;
import com.yohobuy.ufo.model.order.common.SkupStatus;
import com.yohobuy.ufo.model.order.constants.SkupType;
import com.yohobuy.ufo.model.order.req.QuickDeliverOrderSubmitReq;
import com.yohobuy.ufo.model.order.req.SellerOrderComputeReq;
... ... @@ -10,6 +14,7 @@ import com.yohoufo.order.model.QuickDeliverOrderContext;
import com.yohoufo.order.service.DepositService;
import com.yohoufo.order.service.IBuyerOrderMetaService;
import com.yohoufo.order.service.seller.PublishProcessor;
import com.yohoufo.order.service.seller.SkupService;
import com.yohoufo.order.service.seller.processor.PriceComputePrepareProcessor;
import com.yohoufo.order.utils.LoggerUtils;
import org.apache.commons.collections.CollectionUtils;
... ... @@ -18,10 +23,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
@Service
public class QuickDeliverPublishProcessor implements PublishProcessor<QuickDeliverOrderSubmitReq,QuickDeliverOrderContext> {
... ... @@ -36,6 +38,9 @@ public class QuickDeliverPublishProcessor implements PublishProcessor<QuickDeliv
@Autowired
private IBuyerOrderMetaService buyerOrderMetaService;
@Autowired
private SkupService skupService;
@Override
public QuickDeliverOrderContext buildPublishCtx(QuickDeliverOrderSubmitReq qdosr) {
... ... @@ -47,6 +52,17 @@ public class QuickDeliverPublishProcessor implements PublishProcessor<QuickDeliv
.num(num=qdosr.getNum())
.price(qdosr.getPrice()).skupType(qdosr.getSkupTypeCode()).build();
PriceComputePrepareProcessor.PriceComputeNode icpNode = priceComputePrepareProcessor.checkAndAcquire(socr);
BigDecimal salePrice = icpNode.getSalePrice();
SkupType skupType = icpNode.getSkupType();
//step 1: rpc get product detail by storage id
//ufo.product.storage.data
GoodsInfo goodsInfo = skupService.getProductDetail(uid, storageId, salePrice, skupType);
//step 2: generate skup ,action :set price status(unsaleable)
if (Objects.isNull(goodsInfo)){
logger.warn("in buildSellerOrderContext storageId not exist in prd service , uid {}, storageId {}", uid, storageId);
throw new ServiceException(ServiceError.ORDER_ORDERS_GOODS_IS_EMPTY);
}
goodsInfo.setTargetSkupStatus(SkupStatus.CAN_SELL);
// query deposit code is exist in system
List<StorageDeposit> depositPrds = depositService.getStorageDeposit4Publish(uid, storageId, num);
... ... @@ -63,8 +79,7 @@ public class QuickDeliverPublishProcessor implements PublishProcessor<QuickDeliv
BigDecimal salePrice = icpNode.getSalePrice();
SkupType skupType = icpNode.getSkupType();
List<String> depositCodes = new ArrayList<>(depositPrdsize);
Map<String, AddressInfo> hiddenBackAddressMap = new HashMap<>(depositPrdsize),
... ... @@ -89,8 +104,10 @@ public class QuickDeliverPublishProcessor implements PublishProcessor<QuickDeliv
context.setHiddenBackAddressMap(hiddenBackAddressMap);
context.setNoHiddenBackAddressMap(noHiddenBackAddressMap);
context.setDepositCodes(depositCodes);
context.setSoldProduct(goodsInfo);
//
context.setSkupType(skupType);
context.setSellerOrderComputeResult(icpNode.getComputeResult());
return context;
}
}
... ...