Authored by Lixiaodi

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

Showing 28 changed files with 942 additions and 149 deletions
... ... @@ -11,4 +11,6 @@ public class PriceFormater {
}
}
... ...
... ... @@ -17,9 +17,13 @@ public interface AppraiseOrderMetaMapper {
AppraiseOrderMeta selectByOrderCode(AppraiseOrderMeta condition);
List<AppraiseOrderMeta> selectByOrderCodeMetaKeys(@Param("orderCode") long orderCode,
@Param("metaKeys") Collection<String> metaKeys);
AppraiseOrderMeta selectByOrderCodeStorageId(AppraiseOrderMeta condition);
List<AppraiseOrderMeta> selectByOrderCodeStorageIds(@Param("condition") AppraiseOrderMeta condition,
@Param("storageIds")Collection<Integer> storageIds);
int updateMetaValueByOrderCodeAndMetaKey(AppraiseOrderMeta condition);
}
\ No newline at end of file
... ...
... ... @@ -54,7 +54,9 @@ public class SellerWalletDetail {
BUYER_CANCEL_DELIVERY("买家取消(有物流)", 42),
APPRAISE_OK("鉴定通过", 51),
APPRAISE_UNSURE("商品无法鉴定", 52),
MERCHANT_EXIT("商家退出入驻", 61);
MERCHANT_EXIT("商家退出入驻", 61),
CANCEL_DELIVER("不寄了", 71),
FLAW("瑕疵品",72);
private String name;
private int value;
... ...
... ... @@ -40,6 +40,7 @@
<select id="selectCntByOrderType" resultType="java.lang.Integer">
select count(*) from appraise_order
where uid = #{uid,jdbcType=INTEGER} and attributes = #{attributes,jdbcType=INTEGER}
and is_del = 1
and status in
<foreach collection="statusList" item="status" open="(" close=")" separator=",">
#{status,jdbcType=TINYINT}
... ... @@ -51,6 +52,7 @@
<include refid="Base_Column_List" />
from appraise_order
where uid = #{uid,jdbcType=INTEGER} and attributes = #{attributes,jdbcType=INTEGER}
and is_del = 1
and status in
<foreach collection="statusList" item="status" open="(" close=")" separator=",">
#{status,jdbcType=TINYINT}
... ...
... ... @@ -83,6 +83,18 @@
and meta_key = #{metaKey,jdbcType=VARCHAR}
</select>
<select id="selectByOrderCodeMetaKeys" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from appraise_order_meta
where order_code = #{orderCode,jdbcType=INTEGER}
and meta_key in
<foreach collection="metaKeys" item="metaKey" open="(" close=")" separator=",">
#{metaKey,jdbcType=VARCHAR}
</foreach>
</select>
<select id="selectByOrderCodeStorageId" parameterType="com.yohoufo.dal.order.model.AppraiseOrderMeta" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
... ... @@ -104,4 +116,10 @@
and meta_key = #{condition.metaKey,jdbcType=VARCHAR}
</select>
<update id="updateMetaValueByOrderCodeAndMetaKey" parameterType="com.yohoufo.dal.order.model.AppraiseOrderMeta">
update appraise_order_meta set meta_value = #{metaValue,jdbcType=VARCHAR}
where order_code = #{orderCode,jdbcType=BIGINT} and meta_key = #{metaKey,jdbcType=VARCHAR}
</update>
</mapper>
\ No newline at end of file
... ...
... ... @@ -218,4 +218,32 @@ public class SellerDepositOrderController {
.build();
}
@RequestMapping(params = "method=ufo.depositOrder.addOrModifyAddress")
public ApiResponse addOrModifyAddress(@RequestParam(name = "uid")int uid,
@RequestParam(name = "orderCode")long orderCode,
@RequestParam(value = "addressId") String addressId
){
logger.info("in method=ufo.depositOrder.addOrModifyAddress orderCode {} addressId {}", orderCode, addressId);
sellerDepositOrderService.addOrModifyAddress(uid, orderCode, addressId);
return new ApiResponse.ApiResponseBuilder()
.code(200)
.message("地址修改成功")
.build();
}
@RequestMapping(params = "method=ufo.depositOrder.delete")
public ApiResponse deleteVisuable(@RequestParam(name = "uid")int uid,
@RequestParam(name = "orderCode")long orderCode
){
logger.info("in method=ufo.depositOrder.addOrModifyAddress orderCode {} uid {}", orderCode, uid);
sellerDepositOrderService.deleteVisuable(uid, orderCode);
return new ApiResponse.ApiResponseBuilder()
.code(200)
.message("成功")
.build();
}
}
... ...
... ... @@ -6,6 +6,7 @@ import com.yohobuy.ufo.model.order.vo.GoodsVo;
import com.yohobuy.ufo.model.order.vo.ProductVo;
import com.yohobuy.ufo.model.response.StorageDataResp;
import com.yohoufo.common.helper.ImageUrlAssist;
import com.yohoufo.common.utils.BigDecimalHelper;
import com.yohoufo.dal.order.model.AppraiseOrderGoods;
import com.yohoufo.dal.order.model.AppraiseOrderStorage;
... ... @@ -26,7 +27,7 @@ public final class ProductConvertor {
.sizeName(storageDataResp.getSize().getSizeName())
.num(num)
.totalEM(totalEM)
.earnestMoney(SellerOrderConvertor.formatFee(totalEM))
.earnestMoney(BigDecimalHelper.formatNumber(totalEM, BigDecimalHelper.FORMAT_TWOBITAFTERPOINT))
.build();
}
... ...
... ... @@ -37,6 +37,14 @@ public class AlarmEventBuilder {
return smsAlarmEvent;
}
public static SmsAlarmEvent buildRefundEarnestMoneyAlarmEvent(Integer sellerUid,
Long buyerOrderCode){
SmsAlarmEvent smsAlarmEvent ;
String content = "用户服务类订单"+ buyerOrderCode +",uid" + sellerUid + "退款失败";
smsAlarmEvent = new SmsAlarmEvent("ServiceOrder.finish", "finish", content);
return smsAlarmEvent;
}
public static SmsAlarmEvent buildRefundSellerEarnestMoneyAlarmEvent(OrderStatus orderStatus,Integer sellerUid,
Long buyerOrderCode){
... ...
package com.yohoufo.order.event;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import java.util.function.Function;
@ToString(of = {"uid", "orderCode"})
public class SellerDepositOrderCancelAsyncEvent extends AsyncEvent {
@Getter@Setter
private int uid;
@Getter@Setter
private long orderCode;
public SellerDepositOrderCancelAsyncEvent(Function<SellerDepositOrderCancelAsyncEvent,Boolean> function) {
super(function);
}
@Override
AsyncEvent getAsyncEvent() {
return this;
}
}
... ...
... ... @@ -28,4 +28,6 @@ public interface DelayTime {
int CANCEL_SHAM_DELIVERY_TIME_MINUTE=48*60;
int MINUTES_120_HOURS = 120 * 60;
int SELLER_DEPOSIT_ORDER_PAY_TIME_LIMIT = 10;
}
... ...
... ... @@ -63,4 +63,7 @@ public interface TopicConstants {
*/
String DEPOSIT_FINISH_DELIVERY = "deposit.finishDelivery";
String SELLER_DEPOSIT_ORDER_AUTO_CANCEL = "sellerDepositOrder.autoCancel";
}
... ...
package com.yohoufo.order.mq.consumer;
import com.yohoufo.order.event.OrderCancelEvent;
import com.yohoufo.order.mq.TopicConstants;
import com.yohoufo.order.service.seller.deposit.SellerDepositOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class SellerDepositOrderAutoCancelMsgConsumer extends AbsOrderAutoCancelDelayMsgConsumer {
@Autowired
private SellerDepositOrderService sellerDepositOrderService;
@Override
public String getTopic() {
return TopicConstants.SELLER_DEPOSIT_ORDER_AUTO_CANCEL;
}
@Override
public void cancel(OrderCancelEvent event) {
sellerDepositOrderService.cancelByTimeout(event);
}
@Override
public void sendAgain(OrderCancelEvent cancelBean) {
producerTemplate.send(getTopic(), cancelBean, null, cancelBean.getPayExpire());
}
}
... ...
... ... @@ -7,6 +7,7 @@ import com.yohobuy.ufo.model.order.bo.OrderInfo;
import com.yohobuy.ufo.model.order.common.AppraiseOrderStatus;
import com.yohobuy.ufo.model.order.common.OrderAttributes;
import com.yohobuy.ufo.model.order.common.OrderCodeType;
import com.yohoufo.common.alarm.EventBusPublisher;
import com.yohoufo.common.exception.UfoServiceException;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.dal.order.AppraiseOrderMapper;
... ... @@ -14,9 +15,12 @@ import com.yohoufo.dal.order.AppraiseOrderMetaMapper;
import com.yohoufo.dal.order.model.AppraiseOrder;
import com.yohoufo.dal.order.model.AppraiseOrderMeta;
import com.yohoufo.order.constants.MetaKey;
import com.yohoufo.order.event.EventHandlerContainer;
import com.yohoufo.order.event.SellerDepositOrderCancelAsyncEvent;
import com.yohoufo.order.model.request.PaymentRequest;
import com.yohoufo.order.model.response.PrepayResponse;
import com.yohoufo.order.mq.DelayTime;
import com.yohoufo.order.service.seller.deposit.SellerDepositOrderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -35,6 +39,9 @@ public class AppraiseOrderPaymentService extends AbstractOrderPaymentService {
@Autowired
private AppraiseOrderMetaMapper appraiseOrderMetaMapper;
@Autowired
private SellerDepositOrderService sellerDepositOrderService;
@Override
public boolean isTimeoutCancelStatus(OrderInfo orderInfo) {
if (orderInfo.getStatus() != null
... ... @@ -158,5 +165,18 @@ public class AppraiseOrderPaymentService extends AbstractOrderPaymentService {
@Override
public void processAfterPay(OrderInfo orderInfo) {
OrderAttributes oa = OrderAttributes.getOrderAttributes(orderInfo.getAttributes());
switch (oa){
case APPRAISE:
break;
case DEPOSITE:
SellerDepositOrderCancelAsyncEvent event = new SellerDepositOrderCancelAsyncEvent(sellerDepositOrderService::handleOrderCancelAsyncEvent);
event.setUid(orderInfo.getUid());
event.setOrderCode(orderInfo.getOrderCode());
EventBusPublisher.publishEvent(event);
logger.info("processAfterPay seller deposit order , SellerDepositOrderCancelAsyncEvent send out");
break;
}
}
}
... ...
... ... @@ -2,6 +2,7 @@ package com.yohoufo.order.service;
import com.yohobuy.ufo.model.order.common.OrderAttributes;
import com.yohobuy.ufo.model.order.req.DeliverToDepotReq;
import com.yohoufo.dal.order.model.AppraiseOrder;
public interface IGoodsService {
... ... @@ -23,21 +24,35 @@ public interface IGoodsService {
/**
* 鉴定通过
* @param orderCode
* @param appraiseOrder
*/
int appraisePass(long orderCode);
int appraisePass(AppraiseOrder appraiseOrder);
/**
* 鉴别为假
* @param orderCode
* @param appraiseOrder
*/
int appraiseFake(long orderCode);
int appraiseFake(AppraiseOrder appraiseOrder);
/**
* 无法鉴别
* @param orderCode
* @param appraiseOrder
*/
int unsure(long orderCode);
int unsure(AppraiseOrder appraiseOrder);
OrderAttributes getOrderAttributes();
/**
* 虚假发货
* @param appraiseOrder
* @return
*/
int shamDeliver(AppraiseOrder appraiseOrder);
/**
* 瑕疵
* @param appraiseOrder
* @return
*/
int findFlaw(AppraiseOrder appraiseOrder);
}
... ...
package com.yohoufo.order.service.handler;
import com.yohobuy.ufo.model.order.bo.MerchantOrderAttachInfo;
import com.yohoufo.common.alarm.EventBusPublisher;
import com.yohoufo.common.alarm.SmsAlarmEvent;
import com.yohoufo.common.exception.UfoServiceException;
import com.yohoufo.dal.order.model.SellerWalletDetail;
import com.yohoufo.order.common.BillTradeStatus;
import com.yohoufo.order.common.RefundCase;
import com.yohoufo.order.convert.builder.AlarmEventBuilder;
import com.yohoufo.order.event.BillLogEvent;
import com.yohoufo.order.model.request.PaymentRequest;
import org.slf4j.Logger;
import java.math.BigDecimal;
import java.util.function.BiConsumer;
public class GoodsServiceRefundHandler extends AbsRefundOrderHandler {
private long orderCode;
private Long paidOrderCode;
private int uid;
private BigDecimal refundEarnestMoney;
private SellerWalletDetail.Type type;
private Integer payment;
public GoodsServiceRefundHandler loadLogger(Logger logger){
this.logger = logger;
return this;
}
public GoodsServiceRefundHandler loadRefundAction(BiConsumer<PaymentRequest, BillLogEvent.BillLogEventBuilder> refundConsumer){
this.refundConsumer = refundConsumer;
return this;
}
public GoodsServiceRefundHandler loadUser(int uid){
this.uid = uid;
return this;
}
public GoodsServiceRefundHandler loadOrder(Long orderCode,
Long paidOrderCode,
Integer payment,
BigDecimal refundEarnestMoney){
this.orderCode = orderCode;
this.paidOrderCode = paidOrderCode;
this.refundEarnestMoney = refundEarnestMoney;
this.payment = payment;
return this;
}
public GoodsServiceRefundHandler loadActionCase(SellerWalletDetail.Type type){
this.type = type;
return this;
}
@Override
public boolean refund() {
if (paidOrderCode == null){
throw new UfoServiceException(400, "退款订单不存在");
}
try {
MerchantOrderAttachInfo moai = MerchantOrderAttachInfo.builder()
.uid(uid)
.orderCode(orderCode).earnestMoney(this.refundEarnestMoney)
.type(type.getValue()).build();
PaymentRequest request = PaymentRequest.builder().orderCode(this.orderCode)
.paidOrderCode(this.paidOrderCode)
.refundAmount(this.refundEarnestMoney.doubleValue())
.refundattch(moai).build();
BillLogEvent.BillLogEventBuilder bleb = BillLogEvent.builder()
.buyerUid(uid).sellerUid(uid).orderCode(orderCode)
.payType(payment).refundCase(RefundCase.SELLER_EARNEST_MONEY)
;
refundConsumer.accept(request, bleb);
return true;
}catch (Exception ex){
logger.warn("in refund earnest money fail orderCode {} refundEarnestMoney {} ex {}",
orderCode, refundEarnestMoney, ex);
BillLogEvent buyerBillLogEvent = bleb.tradeStatus(BillTradeStatus.FAIL.getCode()).build();
EventBusPublisher.publishEvent(buyerBillLogEvent);
SmsAlarmEvent smsAlarmEvent = AlarmEventBuilder.buildRefundEarnestMoneyAlarmEvent( uid, orderCode);
EventBusPublisher.publishEvent(smsAlarmEvent);
return false;
}
}
}
... ...
... ... @@ -3,9 +3,7 @@ package com.yohoufo.order.service.handler;
import com.google.common.eventbus.Subscribe;
import com.yoho.core.dal.datasource.annotation.Database;
import com.yohobuy.ufo.model.order.common.EntrySellerType;
import com.yohoufo.common.alarm.EventBusPublisher;
import com.yohoufo.common.alarm.IEventHandler;
import com.yohoufo.common.alarm.SmsAlarmEvent;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.dal.order.model.SellerOrderStatsResult;
import com.yohoufo.order.event.SellerEnterTypeChangeEvent;
... ... @@ -66,7 +64,7 @@ public class SellerEnterTypeChangeEventHandler implements IEventHandler<SellerEn
case QUIT:
if (storedSellerService.isStoredSeller(sellerUid)) {
logger.warn("[{}] is stored seller yet,can't handle quit event", sellerUid);
EventBusPublisher.publishEvent(new SmsAlarmEvent("seller.enterQuitEvent", "handle_exception", "seller(" + sellerUid +") is stored seller yet"));
return false;
} else {
//退出入驻,需要更新当前周期,以及下个周期的统计数据
handleQuitEvent(sellerUid, entrySellerType);
... ...
... ... @@ -5,6 +5,7 @@ import com.yohobuy.ufo.model.order.req.DeliverToDepotReq;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.dal.order.AppraiseOrderGoodsMapper;
import com.yohoufo.dal.order.AppraiseOrderMapper;
import com.yohoufo.dal.order.model.AppraiseOrder;
import com.yohoufo.dal.order.model.AppraiseOrderGoods;
import com.yohoufo.order.service.IGoodsService;
import com.yohoufo.order.service.proxy.OrderStatusFlowService;
... ... @@ -41,7 +42,7 @@ public abstract class AbsGoodsServiceOrderService implements IGoodsService {
return rows;
}
private int triggerStatusChange(Long orderCode, AppraiseOrderStatus targetStatus, AppraiseOrderStatus expectedStatus){
public int triggerStatusChange(Long orderCode, AppraiseOrderStatus targetStatus, AppraiseOrderStatus expectedStatus){
int cdt = DateUtil.getCurrentTimeSecond();
int rows = appraiseOrderMapper.updateStatusByOrderCode(orderCode, targetStatus.getCode(), expectedStatus.getCode(), cdt);
if (rows==0){
... ... @@ -83,10 +84,11 @@ public abstract class AbsGoodsServiceOrderService implements IGoodsService {
/**
* 鉴定通过
* @param orderCode
* @param appraiseOrder
*/
@Override
public int appraisePass(long orderCode){
public int appraisePass(AppraiseOrder appraiseOrder){
long orderCode = appraiseOrder.getOrderCode();
AppraiseOrderStatus targetStatus = AppraiseOrderStatus.JUDGE_PASS,
expectedStatus = AppraiseOrderStatus.PLATFORM_CHECKING;
... ... @@ -97,11 +99,11 @@ public abstract class AbsGoodsServiceOrderService implements IGoodsService {
/**
* 鉴别为假
* @param orderCode
* @param appraiseOrder
*/
@Override
public int appraiseFake(long orderCode){
public int appraiseFake(AppraiseOrder appraiseOrder){
long orderCode = appraiseOrder.getOrderCode();
AppraiseOrderStatus targetStatus = AppraiseOrderStatus.CHECKING_FAKE,
expectedStatus = AppraiseOrderStatus.PLATFORM_CHECKING;
... ... @@ -112,10 +114,11 @@ public abstract class AbsGoodsServiceOrderService implements IGoodsService {
/**
* 无法鉴别
* @param orderCode
* @param appraiseOrder
*/
@Override
public int unsure(long orderCode){
public int unsure(AppraiseOrder appraiseOrder){
long orderCode = appraiseOrder.getOrderCode();
AppraiseOrderStatus targetStatus = AppraiseOrderStatus.PLATFORM_APPRAISE_UNSURE,
expectedStatus = AppraiseOrderStatus.PLATFORM_RECEIVE;
... ... @@ -123,4 +126,26 @@ public abstract class AbsGoodsServiceOrderService implements IGoodsService {
logger.info("appraise order appraiseFake update status, orderCode {} rows {}", orderCode, rows);
return rows;
}
@Override
public int shamDeliver(AppraiseOrder appraiseOrder){
long orderCode = appraiseOrder.getOrderCode();
AppraiseOrderStatus targetStatus = AppraiseOrderStatus.SHAM_SEND_OUT,
expectedStatus = AppraiseOrderStatus.SELLER_SEND_OUT;
int rows = triggerStatusChange(orderCode, targetStatus, expectedStatus);
logger.info("appraise order appraiseFake update status, orderCode {} rows {}", orderCode, rows);
return rows;
}
@Override
public int findFlaw(AppraiseOrder appraiseOrder){
long orderCode = appraiseOrder.getOrderCode();
AppraiseOrderStatus targetStatus = AppraiseOrderStatus.QUALITY_CHECK_FAKE,
expectedStatus = AppraiseOrderStatus.PLATFORM_RECEIVE;
int rows = triggerStatusChange(orderCode, targetStatus, expectedStatus);
logger.info("appraise order appraiseFake update status, orderCode {} rows {}", orderCode, rows);
return rows;
}
}
... ...
... ... @@ -13,6 +13,7 @@ import com.yohobuy.ufo.model.order.resp.*;
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.BigDecimalHelper;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.dal.order.AppraiseOrderGoodsMapper;
import com.yohoufo.dal.order.AppraiseOrderMapper;
... ... @@ -327,7 +328,7 @@ public class AppraiseOrderService extends AbsGoodsServiceOrderService implements
}
AppraiseOrderDetailResp aodResp = AppraiseOrderDetailResp.builder()
.uid(uid).orderCode(orderCode)
.amount(SellerOrderConvertor.formatFee(pao.getAmount()))
.amount(BigDecimalHelper.formatNumber(pao.getAmount(), BigDecimalHelper.FORMAT_TWOBITAFTERPOINT))
.statusDetail(statusDetail)
.createTime(DateUtil.formatDate(pao.getCreateTime(), DateUtil.yyyy_MM_dd_HH_mm_SS))
.goodsInfo(AppraiseOrderGoodsConvertor.do2Bo(paog))
... ... @@ -337,46 +338,7 @@ public class AppraiseOrderService extends AbsGoodsServiceOrderService implements
return aodResp;
}
/**
* 是否付费鉴定 or 卖家寄存订单
* @param orderCode
* @return
*/
public ExistenceNode isAppraiseOrder(long orderCode){
AppraiseOrder pao = appraiseOrderMapper.selectByOrderCode(orderCode);
boolean flag = Objects.nonNull(pao);
Integer aoac = flag ? pao.getAttributes() : null;
logger.info("in isAppraiseOrder orderCode {} aoac {} flag {}",
orderCode, aoac, flag);
return ExistenceNode.builder().isExisted(flag).appraiseOrder(pao).build();
}
@Data
@Builder
public static class ExistenceNode{
boolean isExisted;
AppraiseOrder appraiseOrder;
}
/**
* 是否付费鉴定订单
* @param uid
* @param orderCode
* @return
*/
public ExistenceNode isPaidAppraiseOrder(int uid, long orderCode){
AppraiseOrder pao = appraiseOrderMapper.selectByOrderCode(orderCode);
Integer aoac = null;
OrderAttributes oa = null;
boolean flag = Objects.nonNull(pao)
&& Objects.nonNull(aoac=pao.getAttributes())
&& Objects.nonNull(oa = OrderAttributes.getOrderAttributes(aoac))
&& Objects.equals(oa, OrderAttributes.APPRAISE);
logger.info("in isAppraiseOrder uid {} orderCode {} aoac {} oa {} flag {}",
uid, orderCode, aoac, oa, flag);
return ExistenceNode.builder().isExisted(flag).appraiseOrder(pao).build();
}
/**
* 发货
... ... @@ -399,28 +361,30 @@ public class AppraiseOrderService extends AbsGoodsServiceOrderService implements
/**
* 鉴定通过
* @param orderCode
* @param appraiseOrder
*/
@Override
public int appraisePass(long orderCode){
return super.appraisePass(orderCode);
public int appraisePass(AppraiseOrder appraiseOrder){
return super.appraisePass(appraiseOrder);
}
/**
* 鉴别为假
* @param orderCode
* @param appraiseOrder
*/
@Override
public int appraiseFake(long orderCode){
return super.appraiseFake(orderCode);
public int appraiseFake(AppraiseOrder appraiseOrder){
return super.appraiseFake(appraiseOrder);
}
/**
* 无法鉴别
* @param orderCode
* @param appraiseOrder
*/
@Override
public int unsure(long orderCode){
return super.unsure(orderCode);
public int unsure(AppraiseOrder appraiseOrder){
return super.unsure(appraiseOrder);
}
}
... ...
... ... @@ -849,7 +849,9 @@ public class AppraiseService {
Long orderCode = appraiseExpressInfoBo.getOrderCode();
ApiResponse apiResponse = new ApiResponse();
if (serviceOrderProcessor.isGoodsServiceOrder(orderCode)){
serviceOrderProcessor.findGoodsServiceInstance(orderCode).appraiseFake(orderCode);
LOGGER.info("appraiseFailAndDelivery isGoodsServiceOrder, appraiseNotPassFlag {}", appraiseExpressInfoBo);
ServiceOrderProcessor.ExistenceNode existenceNode = serviceOrderProcessor.findGoodsServiceInstanceAndExt(orderCode);
existenceNode.getGoodsService().appraiseFake(existenceNode.getAppraiseOrder());
apiResponse.setCode(200);
return apiResponse;
}
... ... @@ -1098,7 +1100,8 @@ public class AppraiseService {
LOGGER.info("judgeCenterNotPass enter , orderCode {} ", orderCode);
ApiResponse apiResponse = new ApiResponse();
if(serviceOrderProcessor.isGoodsServiceOrder(orderCode)){
serviceOrderProcessor.findGoodsServiceInstance(orderCode).appraiseFake(orderCode);
ServiceOrderProcessor.ExistenceNode existenceNode = serviceOrderProcessor.findGoodsServiceInstanceAndExt(orderCode);
existenceNode.getGoodsService().appraiseFake(existenceNode.getAppraiseOrder());
apiResponse.setCode(200);
return apiResponse;
}
... ... @@ -1181,7 +1184,8 @@ public class AppraiseService {
ApiResponse apiResponse = new ApiResponse();
if (serviceOrderProcessor.isGoodsServiceOrder(orderCode)){
LOGGER.info("qualityCheckReject isGoodsServiceOrder order code {}", orderCode);
serviceOrderProcessor.findGoodsServiceInstance(orderCode).appraiseFake(orderCode);
ServiceOrderProcessor.ExistenceNode existenceNode = serviceOrderProcessor.findGoodsServiceInstanceAndExt(orderCode);
existenceNode.getGoodsService().appraiseFake(existenceNode.getAppraiseOrder());
apiResponse.setCode(200);
return apiResponse;
}
... ... @@ -1280,7 +1284,8 @@ public class AppraiseService {
ApiResponse apiResponse = new ApiResponse();
if(serviceOrderProcessor.isGoodsServiceOrder(orderCode)){
LOGGER.info("judgeCenterPass isGoodsServiceOrder orderCode {}", orderCode);
serviceOrderProcessor.findGoodsServiceInstance(orderCode).appraisePass(orderCode);
ServiceOrderProcessor.ExistenceNode existenceNode = serviceOrderProcessor.findGoodsServiceInstanceAndExt(orderCode);
existenceNode.getGoodsService().appraisePass(existenceNode.getAppraiseOrder());
apiResponse.setCode(200);
return apiResponse;
}
... ... @@ -1537,7 +1542,9 @@ public class AppraiseService {
public void appraiseUnsure(Integer uid, Long orderCode) {
if (serviceOrderProcessor.isGoodsServiceOrder(orderCode)){
LOGGER.info("in appraiseUnsure isGoodsServiceOrder ordercode {}", orderCode);
serviceOrderProcessor.findGoodsServiceInstance(orderCode).unsure(orderCode);
ServiceOrderProcessor.ExistenceNode existenceNode = serviceOrderProcessor.findGoodsServiceInstanceAndExt(orderCode);
existenceNode.getGoodsService().unsure(existenceNode.getAppraiseOrder());
return;
}
... ...
... ... @@ -132,6 +132,9 @@ public class BuyerOrderCancelService {
@Autowired
private ExpressInfoMapper expressInfoMapper;
@Autowired
private ServiceOrderProcessor serviceOrderProcessor;
@Resource(name = "tradeMqProducer")
private YhProducer tradeMqProducer;
... ... @@ -250,6 +253,13 @@ public class BuyerOrderCancelService {
}
public void cancelForSellerShamSendOut(int uid, long orderCode,OrderStatus targetStatus) {
if (serviceOrderProcessor.isGoodsServiceOrder(orderCode)){
logger.info("cancelForSellerShamSendOut isGoodsServiceOrder orderCode {}", orderCode);
ServiceOrderProcessor.ExistenceNode existenceNode = serviceOrderProcessor.findGoodsServiceInstanceAndExt(orderCode);
existenceNode.getGoodsService().shamDeliver(existenceNode.getAppraiseOrder());
}
new BuyerOrderCancelHandler(uid, orderCode)
.withBuyerOrderSupplier(buyerOrderMapper, buyerOrderGoodsMapper)
.withSellerOrderSupplier(sellerOrderGoodsMapper,sellerOrderMetaMapper)
... ...
... ... @@ -39,6 +39,7 @@ import com.yohoufo.order.service.listener.BuyerOrderChangeEvent;
import com.yohoufo.order.service.listener.OrderChangeListenerContainer;
import com.yohoufo.order.service.pay.AbstractPayService;
import com.yohoufo.order.service.proxy.*;
import com.yohoufo.order.service.seller.deposit.SellerDepositOrderService;
import com.yohoufo.order.utils.BuyerOrderUtils;
import com.yohoufo.order.utils.LoggerUtils;
import com.yohoufo.order.utils.SellerGoodsHelper;
... ... @@ -108,6 +109,15 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService {
@Autowired
protected ServiceOrderProcessor serviceOrderProcessor;
@Autowired
private BuyerOrderMetaMapper buyerOrderMetaMapper;
@Autowired
private UserProxyService userProxyService;
@Autowired
private SellerDepositOrderService sellerDepositOrderService;
/**
* 提交订单
* @param orderRequest
... ... @@ -825,15 +835,17 @@ 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) {
if (serviceOrderProcessor.isGoodsServiceOrder(orderCode)){
sellerDepositOrderService.addOrModifyAddress(uid, orderCode, addressIdstr);
return;
}
int addressId = AddressUtil.getDecryptStr(addressIdstr);
if (addressId < 0){
logger.warn("modifyAddressOfDepositOrder addressId invalidate, uid {}, orderCode {}, addressId is {}",
... ... @@ -853,59 +865,77 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService {
return;
}
MetaAddressService.ActionCallBack<BuyerOrderMeta> callBack = new MetaAddressService.ActionCallBack<BuyerOrderMeta>() {
@Override
public List selectByMetaKeys(int uid, long orderCode, List metaKeys) {
List<BuyerOrderMeta> pboms = buyerOrderMetaMapper.selectByMetaKeys(uid, orderCode, metaKeys);
return pboms;
}
//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);
@Override
public void insertBatch(List<BuyerOrderMeta> list) {
buyerOrderMetaMapper.insertBatch(list);
}
@Override
public void insert(BuyerOrderMeta o) {
buyerOrderMetaMapper.insert(o);
}
List<BuyerOrderMeta> pboms = buyerOrderMetaMapper.selectByMetaKeys(uid, orderCode, Arrays.asList(key, hiiden_key));
@Override
public void updateMetaVal(BuyerOrderMeta o) {
buyerOrderMetaMapper.updateMetaValueByUidAndOrderCodeAndMetaKey(o);
}
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;
}
@Override
public AddressInfo hiddenBackAddress(int uid, int addressId) {
AddressInfo hiddenBackAddress = userProxyService.getHiddenAddressInfo(uid, addressId);
return hiddenBackAddress;
}
doPersistent4AddessMeta(hitHidden, hiddenAddressMeta);
doPersistent4AddessMeta(hitNoHidden, noHiddenAddressMeta);
}
}
private void doPersistent4AddessMeta(boolean isExisted, BuyerOrderMeta bom){
if (isExisted){
buyerOrderMetaMapper.updateMetaValueByUidAndOrderCodeAndMetaKey(bom);
}else {
buyerOrderMetaMapper.insert(bom);
}
@Override
public AddressInfo noHiddenBackAddress(int uid, int addressId) {
AddressInfo noHiddenBackAddress = userProxyService.getAddressInfoNotHidden(uid, addressId);
return noHiddenBackAddress;
}
@Override
public BuyerOrderMeta buildnoHiddenAddressMeta(int uid, long orderCode, String key, AddressInfo noHiddenBackAddress) {
BuyerOrderMeta noHiddenAddressMeta=new BuyerOrderMeta();
noHiddenAddressMeta.setUid(uid);
noHiddenAddressMeta.setOrderCode(orderCode);
noHiddenAddressMeta.setMetaKey(key);
noHiddenAddressMeta.setMetaValue(JSONObject.toJSONString(noHiddenBackAddress));
return noHiddenAddressMeta;
}
@Override
public BuyerOrderMeta buildHiddenAddressMeta(int uid, long orderCode, String hiddenKey, AddressInfo hiddenBackAddress) {
BuyerOrderMeta hiddenAddressMeta=new BuyerOrderMeta();
hiddenAddressMeta.setUid(uid);
hiddenAddressMeta.setOrderCode(orderCode);
hiddenAddressMeta.setMetaKey(hiddenKey);
hiddenAddressMeta.setMetaValue(JSONObject.toJSONString(hiddenBackAddress));
return hiddenAddressMeta;
}
@Override
public boolean hitHidden(BuyerOrderMeta buyerOrderMeta, String hidden_key) {
return buyerOrderMeta.getMetaKey().equals(hidden_key);
}
@Override
public boolean hitNoHidden(BuyerOrderMeta buyerOrderMeta, String noHiddenKey) {
return buyerOrderMeta.getMetaKey().equals(noHiddenKey);
}
};
new MetaAddressService().modifyAddressOfDepositOrder(uid, orderCode, addressIdstr, callBack);
}
//清理缓存
private SellerOrderGoods cleanCacheAfterUpdateStatus(long orderCode,int uid,int sellerUid){
BuyerOrderGoods bog = buyerOrderGoodsMapper.selectByOrderCode(uid, orderCode);
... ...
... ... @@ -135,6 +135,9 @@ public class ExpressInfoServiceImpl implements IExpressInfoService {
@Autowired
private OrderCodeGenerator orderCodeGenerator;
@Autowired
private ServiceOrderProcessor serviceOrderProcessor;
private static String EXPRESS_MQ_SEND = "third.logistics.logistics_data";
//物流文案设置
... ... @@ -146,8 +149,6 @@ public class ExpressInfoServiceImpl implements IExpressInfoService {
@Autowired
private SkupService skupService;
@Autowired
private ServiceOrderProcessor serviceOrderProcessor;
private int processBuyerOrder(BuyerOrder buyerOrder,
... ... @@ -1089,7 +1090,7 @@ public class ExpressInfoServiceImpl implements IExpressInfoService {
OrderCodeType orderCodeType = OrderCodeType.getOrderCodeType(codeMeta.getType());
AppraiseAddressResp resp = null;
if (OrderCodeType.GOODS_SERVICE.equals(orderCodeType)){
AppraiseOrderService.ExistenceNode existenceNode = appraiseOrderService.isAppraiseOrder(orderCode);
ServiceOrderProcessor.ExistenceNode existenceNode = serviceOrderProcessor.isAppraiseOrder(orderCode);
if (!existenceNode.isExisted()){
throwServiceException(400,"订单不存在");
}
... ...
package com.yohoufo.order.service.impl;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yohobuy.ufo.model.order.vo.AddressInfo;
import com.yohoufo.common.utils.AddressUtil;
import com.yohoufo.order.constants.MetaKey;
import com.yohoufo.order.utils.LoggerUtils;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class MetaAddressService<E> {
private final Logger logger = LoggerUtils.getBuyerOrderLogger();
public void modifyAddressOfDepositOrder(int uid, Long orderCode, String addressIdstr, ActionCallBack<E> callBack) {
int addressId = AddressUtil.getDecryptStr(addressIdstr);
if (addressId < 0){
logger.warn("addOrModifyAddress addressId invalidate, uid {}, orderCode {}, addressId is {}",
uid, orderCode, addressIdstr);
throw new ServiceException(ServiceError.ORDER_ADDRESSID_INVALIDATE);
}
//the address of send back 2 seller
AddressInfo hiddenBackAddress = callBack.hiddenBackAddress(uid, addressId);
AddressInfo noHiddenBackAddress = callBack.noHiddenBackAddress(uid, addressId);
final String key = MetaKey.RECALL_ADDRESS, hiiden_key = MetaKey.RECALL_HIDDEN_ADDRESS;
E noHiddenAddressMeta= callBack.buildnoHiddenAddressMeta(uid, orderCode, key, noHiddenBackAddress);
//hidden address
E hiddenAddressMeta= callBack.buildHiddenAddressMeta(uid, orderCode, hiiden_key, hiddenBackAddress);
//
List<E> boms = new ArrayList<>(2);
boms.add(noHiddenAddressMeta);
boms.add(hiddenAddressMeta);
List<E> pboms = callBack.selectByMetaKeys(uid, orderCode, Arrays.asList(key, hiiden_key));
if(CollectionUtils.isEmpty(pboms)){
callBack.insertBatch(boms);
}else{
boolean hitNoHidden = false;
boolean hitHidden = false;
for (E pbom : pboms){
if (callBack.hitHidden(pbom, hiiden_key)){
hitHidden = true;
}
if (callBack.hitNoHidden(pbom, key)){
hitNoHidden = true;
}
}
doPersistent4AddessMeta(hitHidden, hiddenAddressMeta, callBack);
doPersistent4AddessMeta(hitNoHidden, noHiddenAddressMeta, callBack);
}
}
private void doPersistent4AddessMeta(boolean isExisted, E bom, ActionCallBack callBack){
if (isExisted){
callBack.updateMetaVal(bom);
}else {
callBack.insert(bom);
}
}
public interface ActionCallBack<E>{
List<E> selectByMetaKeys(int uid, long orderCode, List<String> metaKeys);
void insertBatch(List<E> list);
void insert(E e);
void updateMetaVal(E e);
AddressInfo hiddenBackAddress(int uid, int addressId);
AddressInfo noHiddenBackAddress(int uid, int addressId);
E buildnoHiddenAddressMeta(int uid, long orderCode, String key, AddressInfo noHiddenBackAddress);
E buildHiddenAddressMeta(int uid, long orderCode, String hiddenKey, AddressInfo hiddenBackAddress);
boolean hitHidden(E e, String hidden_key);
boolean hitNoHidden(E e, String noHiddenKey);
}
}
... ...
... ... @@ -5,22 +5,30 @@ import com.yoho.error.exception.ServiceException;
import com.yohobuy.ufo.model.order.common.OrderAttributes;
import com.yohobuy.ufo.model.order.common.OrderCodeType;
import com.yohoufo.common.exception.UfoServiceException;
import com.yohoufo.dal.order.AppraiseOrderMapper;
import com.yohoufo.dal.order.model.AppraiseOrder;
import com.yohoufo.order.service.IGoodsService;
import com.yohoufo.order.service.seller.deposit.SellerDepositOrderService;
import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
import com.yohoufo.order.service.support.codegenerator.bean.CodeMeta;
import com.yohoufo.order.utils.LoggerUtils;
import lombok.Builder;
import lombok.Data;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Objects;
@Service
public class ServiceOrderProcessor {
private final Logger logger = LoggerUtils.getSellerOrderLogger();
@Autowired
private AppraiseOrderMapper appraiseOrderMapper;
@Autowired
private AppraiseOrderService appraiseOrderService;
@Autowired
... ... @@ -54,7 +62,7 @@ public class ServiceOrderProcessor {
public IGoodsService findGoodsServiceInstance(long orderCode){
AppraiseOrderService.ExistenceNode existenceNode = appraiseOrderService.isAppraiseOrder(orderCode);
ExistenceNode existenceNode = isAppraiseOrder(orderCode);
if (!existenceNode.isExisted) {
logger.warn("deliverToDepot getOrderInfo order not exist, orderCode is {}", orderCode);
throw new ServiceException(ServiceError.ORDER_NULL);
... ... @@ -63,4 +71,60 @@ public class ServiceOrderProcessor {
IGoodsService goodsService = findGoodsServiceInstance(appraiseOrder.getAttributes());
return goodsService;
}
public ExistenceNode findGoodsServiceInstanceAndExt(long orderCode){
ExistenceNode existenceNode = isAppraiseOrder(orderCode);
if (!existenceNode.isExisted) {
logger.warn("deliverToDepot getOrderInfo order not exist, orderCode is {}", orderCode);
throw new ServiceException(ServiceError.ORDER_NULL);
}
AppraiseOrder appraiseOrder = existenceNode.appraiseOrder;
IGoodsService goodsService = findGoodsServiceInstance(appraiseOrder.getAttributes());
existenceNode.setGoodsService(goodsService);
return existenceNode;
}
/**
* 是否付费鉴定 or 卖家寄存订单
* @param orderCode
* @return
*/
public ExistenceNode isAppraiseOrder(long orderCode){
AppraiseOrder pao = appraiseOrderMapper.selectByOrderCode(orderCode);
boolean flag = Objects.nonNull(pao);
Integer aoac = flag ? pao.getAttributes() : null;
logger.info("in isAppraiseOrder orderCode {} aoac {} flag {}",
orderCode, aoac, flag);
return ExistenceNode.builder().isExisted(flag).appraiseOrder(pao).build();
}
/**
* 是否付费鉴定订单
* @param uid
* @param orderCode
* @return
*/
public ExistenceNode isPaidAppraiseOrder(int uid, long orderCode){
AppraiseOrder pao = appraiseOrderMapper.selectByOrderCode(orderCode);
Integer aoac = null;
OrderAttributes oa = null;
boolean flag = Objects.nonNull(pao)
&& Objects.nonNull(aoac=pao.getAttributes())
&& Objects.nonNull(oa = OrderAttributes.getOrderAttributes(aoac))
&& Objects.equals(oa, OrderAttributes.APPRAISE);
logger.info("in isAppraiseOrder uid {} orderCode {} aoac {} oa {} flag {}",
uid, orderCode, aoac, oa, flag);
return ExistenceNode.builder().isExisted(flag).appraiseOrder(pao).build();
}
@Data
@Builder
public static class ExistenceNode{
boolean isExisted;
AppraiseOrder appraiseOrder;
IGoodsService goodsService;
}
}
... ...
... ... @@ -21,7 +21,6 @@ import com.yohoufo.dal.order.AppraiseOrderMapper;
import com.yohoufo.dal.order.AppraiseOrderMetaMapper;
import com.yohoufo.dal.order.AppraiseOrderStorageMapper;
import com.yohoufo.dal.order.model.AppraiseOrder;
import com.yohoufo.dal.order.model.AppraiseOrderGoods;
import com.yohoufo.order.convert.SellerOrderConvertor;
import com.yohoufo.order.model.response.AppraiseAddressResp;
import com.yohoufo.order.service.impl.AbsOrderViewService;
... ... @@ -31,7 +30,6 @@ import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.List;
@Service
... ... @@ -93,8 +91,6 @@ public class SellerDepositOrderDetailService extends AbsOrderViewService {
AppraiseOrder pao = appraiseOrderMapper.selectByOrderCode(orderCode);
OrderAttributes oa = OrderAttributes.getOrderAttributes(pao.getAttributes());
//todo use another page list query
List<AppraiseOrderGoods> paogList = appraiseOrderGoodsMapper.selectByOrderCodes(Arrays.asList(orderCode));
//
TimeoutBo timeout = calTimeout(TabType.BUY, uid, orderCode, pao.getStatus(),
pao.getCreateTime(), oa);
... ... @@ -133,6 +129,7 @@ public class SellerDepositOrderDetailService extends AbsOrderViewService {
.userAddress(userAddress)
.appraiseAddress(appraiseAddressInfo)
.addressUpgradable(addressUpgradable)
.buttons(aos.detailButtons(oa))
.build()
;
}
... ...
... ... @@ -11,6 +11,7 @@ import com.yohobuy.ufo.model.order.resp.SellerDepositOrderListResp;
import com.yohobuy.ufo.model.order.vo.GoodsVo;
import com.yohobuy.ufo.model.order.vo.ProductVo;
import com.yohoufo.common.helper.ImageUrlAssist;
import com.yohoufo.common.utils.BigDecimalHelper;
import com.yohoufo.dal.order.AppraiseOrderGoodsMapper;
import com.yohoufo.dal.order.AppraiseOrderMapper;
import com.yohoufo.dal.order.AppraiseOrderMetaMapper;
... ... @@ -78,7 +79,6 @@ public class SellerDepositOrderListService {
List<Long> orderCodes = orderList.stream().map(AppraiseOrder::getOrderCode).collect(Collectors.toList());
List<AppraiseOrderGoods> paogs = appraiseOrderGoodsMapper.selectByOrderCodes(orderCodes);
Map<Long,List<AppraiseOrderGoods>> orderCodeAOGMap = new HashMap<>(paogs.size());
for (AppraiseOrderGoods paog : paogs){
long orderCode;
... ... @@ -120,6 +120,7 @@ public class SellerDepositOrderListService {
return SellerDepositOrderListResp.builder()
.uid(uid)
.orderCode(orderCode)
.earnestMoney(BigDecimalHelper.formatNumber(pao.getAmount(), BigDecimalHelper.FORMAT_TWOBITAFTERPOINT))
.status(status)
.statuStr(appraiseOrderStatus.statusStr(oa))
.buttons(appraiseOrderStatus.listButtons(oa))
... ... @@ -199,7 +200,7 @@ public class SellerDepositOrderListService {
Integer storageNum;
BigDecimal emOfSku = socr.getEarnestMoney().getEarnestMoney().multiply(new BigDecimal(storageNum=aos.getNum()));
GoodsVo goodsVo = GoodsVo.builder().sizeName(aos.getSizeName()).num(storageNum)
.earnestMoney(SellerOrderConvertor.formatFee(emOfSku)).build();
.earnestMoney(BigDecimalHelper.formatNumber(emOfSku, BigDecimalHelper.FORMAT_TWOBITAFTERPOINT)).build();
goodsList.add(goodsVo);
}
... ...
package com.yohoufo.order.service.seller.deposit;
import com.alibaba.fastjson.JSONObject;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yohobuy.ufo.model.order.common.AppraiseOrderStatus;
import com.yohobuy.ufo.model.order.common.OrderAttributes;
import com.yohobuy.ufo.model.order.common.OrderCodeType;
import com.yohobuy.ufo.model.order.common.Payment;
import com.yohobuy.ufo.model.order.req.*;
import com.yohobuy.ufo.model.order.resp.DepositOrderInStorePrdListResp;
import com.yohobuy.ufo.model.order.resp.PageResp;
import com.yohobuy.ufo.model.order.resp.SellerDepositOrderComputeResp;
import com.yohobuy.ufo.model.order.resp.SellerDepositOrderSubmitResp;
import com.yohobuy.ufo.model.order.vo.AddressInfo;
import com.yohobuy.ufo.model.order.vo.GoodsVo;
import com.yohobuy.ufo.model.order.vo.ProductVo;
import com.yohoufo.common.alarm.EventBusPublisher;
import com.yohoufo.common.exception.UfoServiceException;
import com.yohoufo.common.utils.AddressUtil;
import com.yohoufo.common.utils.BigDecimalHelper;
import com.yohoufo.dal.order.AppraiseOrderGoodsMapper;
import com.yohoufo.dal.order.AppraiseOrderMapper;
import com.yohoufo.dal.order.AppraiseOrderMetaMapper;
import com.yohoufo.dal.order.AppraiseOrderStorageMapper;
import com.yohoufo.dal.order.model.AppraiseOrder;
import com.yohoufo.dal.order.model.AppraiseOrderGoods;
import com.yohoufo.dal.order.model.AppraiseOrderStorage;
import com.yohoufo.dal.order.model.*;
import com.yohoufo.order.common.ClientType;
import com.yohoufo.order.convert.SellerOrderConvertor;
import com.yohoufo.order.common.DelStatus;
import com.yohoufo.order.constants.MetaKey;
import com.yohoufo.order.event.BuyerCancelEvent;
import com.yohoufo.order.event.OrderCancelEvent;
import com.yohoufo.order.event.PayConfirmEvent;
import com.yohoufo.order.event.SellerDepositOrderCancelAsyncEvent;
import com.yohoufo.order.model.PayQueryBo;
import com.yohoufo.order.model.dto.PlatformFeeDto;
import com.yohoufo.order.model.dto.SellerDepositOrderContext;
import com.yohoufo.order.model.dto.SellerDepositSubOrderContext;
import com.yohoufo.order.model.dto.SellerOrderComputeResult;
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.IGoodsService;
import com.yohoufo.order.service.impl.AbsGoodsServiceOrderService;
import com.yohoufo.order.service.impl.AppraiseAddressService;
import com.yohoufo.order.service.impl.AppraiseOrderCreateService;
import com.yohoufo.order.service.IPaymentService;
import com.yohoufo.order.service.handler.GoodsServiceRefundHandler;
import com.yohoufo.order.service.impl.*;
import com.yohoufo.order.service.pay.AbstractPayService;
import com.yohoufo.order.service.proxy.OrderStatusFlowService;
import com.yohoufo.order.service.proxy.UserProxyService;
import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
import com.yohoufo.order.utils.LoggerUtils;
import org.slf4j.Logger;
... ... @@ -73,7 +94,14 @@ public class SellerDepositOrderService extends AbsGoodsServiceOrderService imple
@Autowired
private OrderStatusFlowService orderStatusFlowService;
@Autowired
private DepositService depositService;
@Autowired
private UserProxyService userProxyService;
@Autowired
private PayRefundService payRefundService;
... ... @@ -84,7 +112,7 @@ public class SellerDepositOrderService extends AbsGoodsServiceOrderService imple
SellerDepositOrderSupport.SummaryNode summaryNode = sdos.buildList(dtNode,
SellerDepositOrderSupport.buildProductVoTypeRef(),
SellerDepositOrderSupport.buildgoodsVoTypeRef());
String earnestMoneystr = SellerOrderConvertor.formatFee(summaryNode.earnestMoney);
String earnestMoneystr = BigDecimalHelper.formatNumber(summaryNode.earnestMoney, BigDecimalHelper.FORMAT_TWOBITAFTERPOINT);
String tips = "温馨提示:早支付早发货早寄存早上架早出售";
SellerDepositOrderComputeResp resp = SellerDepositOrderComputeResp.builder()
.earnestMoney(earnestMoneystr)
... ... @@ -100,7 +128,7 @@ public class SellerDepositOrderService extends AbsGoodsServiceOrderService imple
SellerDepositOrderPrepareService.DTNode dtNode = sellerDepositOrderPrepareService.checkAndAckquireBySku(req);
SellerOrderComputeResult socr = dtNode.getStorageIdSOCRMap().get(req.getStorageId());
BigDecimal total = socr.getEarnestMoney().getEarnestMoney().multiply(new BigDecimal(req.getNum()));
String earnestMoneystr = SellerOrderConvertor.formatFee(total);
String earnestMoneystr = BigDecimalHelper.formatNumber(total, BigDecimalHelper.FORMAT_TWOBITAFTERPOINT);
SellerDepositOrderComputeResp resp = SellerDepositOrderComputeResp.builder()
.earnestMoney(earnestMoneystr)
.build();
... ... @@ -156,18 +184,106 @@ public class SellerDepositOrderService extends AbsGoodsServiceOrderService imple
return null;
}
@Autowired
private ServiceOrderProcessor serviceOrderProcessor;
@Autowired
IPaymentService paymentService;
public void cancel(SellerDepositOrderDetailReq req){
//TODO
long orderCode = req.getOrderCode();
if(serviceOrderProcessor.isGoodsServiceOrder(orderCode)){
logger.warn("cancel AppraiseOrder not GoodsServiceOrder, orderCode {}", orderCode);
throw new UfoServiceException(400, "订单已迷路");
}
ServiceOrderProcessor.ExistenceNode existenceNode = serviceOrderProcessor.isAppraiseOrder(orderCode);
if (!existenceNode.isExisted()){
logger.warn("cancel AppraiseOrder not exist, orderCode {}", orderCode);
throw new UfoServiceException(400, "订单已迷路");
}
AppraiseOrder pao = existenceNode.getAppraiseOrder();
OrderAttributes oa = OrderAttributes.getOrderAttributes(pao.getAttributes());
if (!OrderAttributes.DEPOSITE.equals(oa)){
logger.warn("cancel AppraiseOrder not deposit Order, orderCode {}", orderCode);
throw new UfoServiceException(400, "订单已迷路");
}
AppraiseOrderStatus appraiseOrderStatus = AppraiseOrderStatus.getByCode(pao.getStatus());
switch (appraiseOrderStatus){
case WAITING_PAY:
super.triggerStatusChange(orderCode, AppraiseOrderStatus.CANCEL_BEFORE_PAY, appraiseOrderStatus);
break;
case HAS_PAYED:
super.triggerStatusChange(orderCode, AppraiseOrderStatus.CANCEL_BEFORE_DELIVER, appraiseOrderStatus);
//refund amount
new GoodsServiceRefundHandler()
.loadLogger(logger)
.loadUser(pao.getUid())
.loadActionCase(SellerWalletDetail.Type.CANCEL_DELIVER)
.loadRefundAction(payRefundService::refund)
.loadOrder(orderCode, orderCode, pao.getPayment(), pao.getAmount())
.refund();
break;
default:
throw new UfoServiceException(400, "订单不支持取消");
}
}
public int cancelByTimeout(OrderCancelEvent orderCancelEvent){
Long orderCode = orderCancelEvent.getOrderCode();
int uid = orderCancelEvent.getUid();
if(serviceOrderProcessor.isGoodsServiceOrder(orderCode)){
logger.warn("auto cancel AppraiseOrder not GoodsServiceOrder, orderCode {}", orderCode);
throw new UfoServiceException(400, "订单已迷路");
}
ServiceOrderProcessor.ExistenceNode existenceNode = serviceOrderProcessor.isAppraiseOrder(orderCode);
if (!existenceNode.isExisted()){
logger.warn("auto cancel AppraiseOrder not exist, orderCode {}", orderCode);
throw new UfoServiceException(400, "订单已迷路");
}
AppraiseOrder pao = existenceNode.getAppraiseOrder();
OrderAttributes oa = OrderAttributes.getOrderAttributes(pao.getAttributes());
if (!OrderAttributes.DEPOSITE.equals(oa)){
logger.warn("auto cancel AppraiseOrder not deposit Order, orderCode {}", orderCode);
throw new UfoServiceException(400, "订单已迷路");
}
AppraiseOrderStatus appraiseOrderStatus = AppraiseOrderStatus.getByCode(pao.getStatus());
int rows = 0;
switch (appraiseOrderStatus){
case WAITING_PAY:
Payment payment = Payment.getPayment(pao.getPayment());
AbstractPayService payService = paymentService.getPayService(payment.getCode());
PayQueryBo payQueryBo = payService.payQuery(String.valueOf(orderCode), pao.getCreateTime());
if (payQueryBo != null && payQueryBo.isPayStatus()){
logger.info("seller deposit order auto cancel failed, confirm paid. uid is {}, orderCode is {}", uid, orderCode);
PayConfirmEvent event = new PayConfirmEvent(uid, orderCode, pao.getPayment());
EventBusPublisher.publishEvent(event);
}
// 如果近1分钟有预支付记录,则发送 自动取消延迟消息
if ( !orderCancelEvent.isFinalRetry()){
paymentService.checkPrePay(uid, orderCode);
}
rows = super.triggerStatusChange(orderCode, AppraiseOrderStatus.CANCEL_TIMEOUT, appraiseOrderStatus);
break;
default:
throw new UfoServiceException(400, "订单不支持取消");
}
return rows;
}
@Override
public int deliver2Depot(DeliverToDepotReq req) {
//
int rows = super.deliver2Depot(req);
if (rows==0){
return rows;
... ... @@ -205,31 +321,248 @@ public class SellerDepositOrderService extends AbsGoodsServiceOrderService imple
/**
* 鉴定通过
* @param orderCode
* @param pao
*/
@Override
public int appraisePass(long orderCode){
int rows = super.appraisePass(orderCode);
public int appraisePass(AppraiseOrder pao){
int rows = super.appraisePass(pao);
if (rows == 0){
return rows;
}
Long orderCode = pao.getOrderCode();
Long paidCode = pao.getParentOrderCode();
BigDecimal left = calLeftMoney(pao.getAmount(), orderCode);
if (left.compareTo(BigDecimal.ZERO)>0){
//refund amount
new GoodsServiceRefundHandler()
.loadLogger(logger)
.loadUser(pao.getUid())
.loadActionCase(SellerWalletDetail.Type.APPRAISE_OK)
.loadRefundAction(payRefundService::refund)
.loadOrder(orderCode, paidCode, pao.getPayment(), left)
.refund();
}
return rows;
}
/**
* 鉴别为假
* 完好正品 仓储费:10元/45天 鉴定费:15元 包装费:6元 剩余保证金退回
* @param amount
* @param orderCode
* @return
*/
private BigDecimal calLeftMoney(BigDecimal amount, Long orderCode){
AppraiseOrderMeta feeCondition = new AppraiseOrderMeta();
feeCondition.setOrderCode(orderCode);
feeCondition.setMetaKey(MetaKey.SELLER_FEE);
BigDecimal totalOfPlatform = new BigDecimal(35);
try {
AppraiseOrderMeta feeMeta = appraiseOrderMetaMapper.selectByOrderCode(feeCondition);
SellerOrderComputeResult socr = JSONObject.parseObject(feeMeta.getMetaValue(), SellerOrderComputeResult.class);
PlatformFeeDto platformFeeDto = socr.getPlatformFee();
totalOfPlatform = platformFeeDto.getTotal();
}catch (Exception ex){
logger.warn("calLeftMoney 4 seller deposit order fail use default totalOfPlatform {} orderCode {}", totalOfPlatform, orderCode, ex);
}
if (totalOfPlatform.compareTo(BigDecimal.ZERO)<0){
totalOfPlatform = BigDecimal.ZERO;
}
BigDecimal left = amount.subtract(totalOfPlatform);
if (left.compareTo(BigDecimal.ZERO) <= 0){
left = BigDecimal.ZERO;
}else {
//format
left = BigDecimalHelper.halfUp(left);
}
logger.info("calLeftMoney 4 seller deposit order,orderCode {} ,amount {}, totalOfPlatform {}, left {}",
orderCode, amount, totalOfPlatform, left);
return left;
}
/**
* 鉴别为假
* @param appraiseOrder
*/
@Override
public int appraiseFake(long orderCode){
int rows = super.appraiseFake(orderCode);
public int appraiseFake(AppraiseOrder appraiseOrder){
int rows = super.appraiseFake(appraiseOrder);
if (rows == 0){
return rows;
}
depositService.insertFakeDeposit(appraiseOrder.getUid(), appraiseOrder.getOrderCode(), appraiseOrder.getParentOrderCode());
return rows;
}
/**
* 无法鉴别
* @param orderCode
* @param appraiseOrder
*/
@Override
public int unsure(AppraiseOrder appraiseOrder){
int rows = super.unsure(appraiseOrder);
if (rows == 0){
return rows;
}
depositService.insertFakeDeposit(appraiseOrder.getUid(), appraiseOrder.getOrderCode(), appraiseOrder.getParentOrderCode());
return rows;
}
/**
* 确认收货环节发现少件,取消订单保证金原路退回
* @param appraiseOrder
* @return
*/
@Override
public int unsure(long orderCode){
int rows = super.unsure(orderCode);
public int shamDeliver(AppraiseOrder appraiseOrder){
int rows = super.shamDeliver(appraiseOrder);
if (rows == 0){
return rows;
}
//refund amount
new GoodsServiceRefundHandler()
.loadLogger(logger)
.loadUser(appraiseOrder.getUid())
.loadActionCase(SellerWalletDetail.Type.SELLER_SHAM_SEND_OUT)
.loadRefundAction(payRefundService::refund)
.loadOrder(appraiseOrder.getOrderCode(), appraiseOrder.getParentOrderCode(), appraiseOrder.getPayment(), appraiseOrder.getAmount())
.refund();
depositService.insertFakeDeposit(appraiseOrder.getUid(), appraiseOrder.getOrderCode(), appraiseOrder.getParentOrderCode());
return rows;
}
public void addOrModifyAddress(int uid, Long orderCode, String addressIdstr) {
int addressId = AddressUtil.getDecryptStr(addressIdstr);
if (addressId < 0){
logger.warn("addOrModifyAddress addressId invalidate, uid {}, orderCode {}, addressId is {}",
uid, orderCode, addressIdstr);
throw new ServiceException(ServiceError.ORDER_ADDRESSID_INVALIDATE);
}
AppraiseOrder pbo = appraiseOrderMapper.selectByOrderCode(orderCode);
if (pbo == null ){
logger.warn("in addOrModifyAddress AppraiseOrder is null,uid {} orderCode {} addressIdstr {}",
uid, orderCode, addressIdstr);
return;
}
Integer oa;
if (OrderAttributes.DEPOSITE.getCode() != (oa=pbo.getAttributes())){
logger.warn("in addOrModifyAddress AppraiseOrder.Attributes is {},uid {} orderCode {} addressIdstr {}",
oa, uid, orderCode, addressIdstr);
return;
}
MetaAddressService.ActionCallBack<AppraiseOrderMeta> callBack = new MetaAddressService.ActionCallBack<AppraiseOrderMeta>() {
@Override
public List<AppraiseOrderMeta> selectByMetaKeys(int uid, long orderCode, List<String> metaKeys) {
List<AppraiseOrderMeta> pboms = appraiseOrderMetaMapper.selectByOrderCodeMetaKeys(orderCode, metaKeys);
return pboms;
}
@Override
public void insertBatch(List<AppraiseOrderMeta> list) {
appraiseOrderMetaMapper.insertBatch(list);
}
@Override
public void insert(AppraiseOrderMeta appraiseOrderMeta) {
appraiseOrderMetaMapper.insert(appraiseOrderMeta);
}
@Override
public void updateMetaVal(AppraiseOrderMeta appraiseOrderMeta) {
appraiseOrderMetaMapper.updateMetaValueByOrderCodeAndMetaKey(appraiseOrderMeta);
}
@Override
public AddressInfo hiddenBackAddress(int uid, int addressId) {
return userProxyService.getHiddenAddressInfo(uid, addressId);
}
@Override
public AddressInfo noHiddenBackAddress(int uid, int addressId) {
return userProxyService.getAddressInfoNotHidden(uid, addressId);
}
@Override
public AppraiseOrderMeta buildnoHiddenAddressMeta(int uid, long orderCode, String key, AddressInfo noHiddenBackAddress) {
AppraiseOrderMeta noHiddenAddressMeta = new AppraiseOrderMeta();
noHiddenAddressMeta.setUid(uid);
noHiddenAddressMeta.setOrderCode(orderCode);
noHiddenAddressMeta.setMetaKey(key);
noHiddenAddressMeta.setMetaValue(JSONObject.toJSONString(noHiddenBackAddress));
return noHiddenAddressMeta;
}
@Override
public AppraiseOrderMeta buildHiddenAddressMeta(int uid, long orderCode, String hiddenKey, AddressInfo hiddenBackAddress) {
AppraiseOrderMeta hiddenAddressMeta=new AppraiseOrderMeta();
hiddenAddressMeta.setUid(uid);
hiddenAddressMeta.setOrderCode(orderCode);
hiddenAddressMeta.setMetaKey(hiddenKey);
hiddenAddressMeta.setMetaValue(JSONObject.toJSONString(hiddenBackAddress));
return hiddenAddressMeta;
}
@Override
public boolean hitHidden(AppraiseOrderMeta appraiseOrderMeta, String hidden_key) {
return appraiseOrderMeta.getMetaKey().equals(hidden_key);
}
@Override
public boolean hitNoHidden(AppraiseOrderMeta appraiseOrderMeta, String noHiddenKey) {
return appraiseOrderMeta.getMetaKey().equals(noHiddenKey);
}
};
new MetaAddressService().modifyAddressOfDepositOrder(uid, orderCode, addressIdstr, callBack);
}
public int deleteVisuable(int uid, long orderCode){
logger.info("in delete deposit order Visuable uid {} orderCode {}", uid, orderCode);
AppraiseOrder condition = new AppraiseOrder();
condition.setOrderCode(orderCode);
condition.setIsDel(DelStatus.IS_DEL.getCode());
int rows = appraiseOrderMapper.updateByOrderCode(condition);
logger.info("in delete deposit order Visuable uid {} orderCode {} rows {}", uid, orderCode, rows);
return rows;
}
/**
* 瑕疵
* 退回对应保证金至卖家账户
* @param appraiseOrder
* @return
*/
public int findFlaw(AppraiseOrder appraiseOrder){
int rows = super.findFlaw(appraiseOrder);
if (rows == 0){
return rows;
}
new GoodsServiceRefundHandler()
.loadLogger(logger)
.loadUser(appraiseOrder.getUid())
.loadActionCase(SellerWalletDetail.Type.FLAW)
.loadRefundAction(payRefundService::refund)
.loadOrder(appraiseOrder.getOrderCode(), appraiseOrder.getParentOrderCode(), appraiseOrder.getPayment(), appraiseOrder.getAmount())
.refund();
depositService.insertFakeDeposit(appraiseOrder.getUid(), appraiseOrder.getOrderCode(), appraiseOrder.getParentOrderCode());
return rows;
}
@Autowired
private TradeMqSender tradeMqSender;
public boolean handleOrderCancelAsyncEvent(SellerDepositOrderCancelAsyncEvent event) {
logger.info("Subscribe Buyer timeout cancel delay msg, event {}", event);
OrderCancelEvent orderCancelEvent = OrderCancelEvent.builder()
.uid(event.getUid())
.orderCode(event.getOrderCode())
.payExpire(DelayTime.SELLER_DEPOSIT_ORDER_PAY_TIME_LIMIT)
.build();
tradeMqSender.send(TopicConstants.SELLER_DEPOSIT_ORDER_AUTO_CANCEL, orderCancelEvent, DelayTime.SELLER_DEPOSIT_ORDER_PAY_TIME_LIMIT);
return true;
}
}
... ...
... ... @@ -55,6 +55,12 @@ public class QuickDeliverPublishProcessor implements PublishProcessor<QuickDeliv
.num(num=qdosr.getNum())
.price(qdosr.getPrice()).skupType(qdosr.getSkupTypeCode()).build();
PriceComputePrepareProcessor.PriceComputeNode icpNode = priceComputePrepareProcessor.checkAndAcquire(socr);
if (num>10){
logger.warn("in buildSellerOrderContext storageId num over limit , qdosr {}", qdosr);
throw new UfoServiceException(400, "上架数目不能超过10个");
}
BigDecimal salePrice = icpNode.getSalePrice();
SkupType skupType = icpNode.getSkupType();
//step 1: rpc get product detail by storage id
... ...