Authored by wujiexiang

Merge branch 'dev-promotion' into test6.8.2

# Conflicts:
#	web/src/main/resources/databases.yml
#	web/src/main/webapp/META-INF/autoconf/databases.yml
... ... @@ -12,5 +12,5 @@ public interface OrderCouponMapper {
int insert(OrderCoupon orderCoupon);
List<OrderCoupon> selectByUidAndOrderCode(@Param("uid") int uid, @Param("orderCode") long orderCode);
OrderCoupon selectByUidAndOrderCode(@Param("uid") int uid, @Param("orderCode") long orderCode);
}
... ...
... ... @@ -4,11 +4,20 @@ package com.yohoufo.dal.order.model;
* Created by jiexiang.wu on 2018/11/20.
*/
public class OrderCoupon {
private long id;
private int uid;
private long orderCode;
private String couponCode;
private int createTime;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public int getUid() {
return uid;
}
... ...
... ... @@ -20,8 +20,9 @@
<select id="selectByUidAndOrderCode" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from buyer_order
from order_coupon
where order_code = #{orderCode,jdbcType=BIGINT}
and uid = #{uid,jdbcType=INTEGER}
limit 1
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -50,13 +50,13 @@ public class ChargeService {
//1.计算商品金额
calculateGoodsAmount(chargeContext);
//2.计算运费
calculateExpressDeliveryAmount(chargeContext);
calculateShippingAmount(chargeContext);
//3.计算优惠券
calculateCouponIfNeed(chargeContext);
}
private void initCharge(ChargeContext chargeContext) {
logger.info("[{}] init charge,charge param:{},charge goods:{}",
logger.info("[{}] step init charge,charge param:{},charge goods:{}",
chargeContext.getChargeParam().getUid(),
chargeContext.getChargeParam(),
chargeContext.getChargeGoods());
... ... @@ -75,7 +75,7 @@ public class ChargeService {
chargeContext.getChargeResult().setGoodsAmount(chargeGoods.getGoodsAmount().doubleValue());
chargeContext.getChargeResult().setFinalAmount(chargeGoods.getGoodsAmount().doubleValue());
logger.info("[{}] STEP goods charge,goodsPrice:{},goodsAmount:{},amount:{}",
logger.info("[{}] step goods charge,goodsPrice:{},goodsAmount:{},amount:{}",
chargeContext.getChargeParam().getUid(),
chargeGoods.getGoodsPrice(),
chargeContext.getChargeResult().getGoodsAmount(),
... ... @@ -87,9 +87,9 @@ public class ChargeService {
*
* @param chargeContext
*/
private void calculateExpressDeliveryAmount(ChargeContext chargeContext) {
private void calculateShippingAmount(ChargeContext chargeContext) {
//运费
chargeContext.getChargeResult().setExpressDeliveryAmount(delivery_way_sf_cost);
chargeContext.getChargeResult().setShippingAmount(delivery_way_sf_cost);
ChargeResult chargeResult = chargeContext.getChargeResult();
... ... @@ -97,9 +97,9 @@ public class ChargeService {
//包括运费
double newFinalAmount = YHMath.add(oldFinalAmount, delivery_way_sf_cost);
chargeResult.setFinalAmount(newFinalAmount);
logger.info("[{}] STEP express charge,sfExpressAmount:{},oldFinalAmount:{},newFinalAmount:{}",
logger.info("[{}] step shipping charge,sfExpressAmount:{},oldFinalAmount:{},newFinalAmount:{}",
chargeContext.getChargeParam().getUid(),
chargeResult.getExpressDeliveryAmount(),
chargeResult.getShippingAmount(),
oldFinalAmount,
chargeResult.getFinalAmount());
}
... ... @@ -131,7 +131,7 @@ public class ChargeService {
chargeResult.setCouponPayResult(couponPayResult);
logger.info("[{}] STEP coupon charge,oldFinalAmount:{},newFinalAmount:{},couponPayResult:{}",
logger.info("[{}] step coupon charge,oldFinalAmount:{},newFinalAmount:{},couponPayResult:{}",
chargeContext.getChargeParam().getUid(),
couponPayAmount, oldFinalAmount, chargeResult.getFinalAmount(), chargeResult.getCouponPayResult());
... ...
... ... @@ -18,7 +18,7 @@ public class ChargeResult {
/**
* 快递金额
*/
private double expressDeliveryAmount;
private double shippingAmount;
/**
... ...
... ... @@ -4,10 +4,14 @@ import com.yohobuy.ufo.model.order.common.OrderStatus;
import com.yohobuy.ufo.model.order.common.SkupStatus;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.dal.order.BuyerOrderMapper;
import com.yohoufo.dal.order.OrderCouponMapper;
import com.yohoufo.dal.order.SellerOrderGoodsMapper;
import com.yohoufo.dal.order.model.OrderCoupon;
import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.order.event.BeforeDepotReceiveEvent;
import com.yohoufo.order.event.BeforeSellerDeliverEvent;
import com.yohoufo.order.model.bo.CouponBo;
import com.yohoufo.order.service.proxy.CouponProxyService;
import com.yohoufo.order.utils.LoggerUtils;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -33,6 +37,12 @@ public class BuyerOrderCancelService {
@Autowired
private SellerOrderGoodsMapper sellerOrderGoodsMapper;
@Autowired
private OrderCouponMapper orderCouponMapper;
@Autowired
private CouponProxyService couponProxyService;
public void cancel(BeforeSellerDeliverEvent bsdEvent){
OrderDynamicConfig.BuyerCancelCompensateNode compensate = orderDynamicConfig.getBeforeSellerDeliverBCCN();
... ... @@ -83,11 +93,25 @@ public class BuyerOrderCancelService {
//(转账)瓜分指定赔偿款给卖家和平台
//(退费)扣除赔偿款,计算剩余的货款,退给买家
}
}
/**
* 退还优惠券
*
* @param uid
* @param orderCode
*/
public void refundCouponIfNeed(int uid, long orderCode) {
try {
OrderCoupon orderCoupon = orderCouponMapper.selectByUidAndOrderCode(uid, orderCode);
if (orderCoupon == null) {
logger.info("[{}] not need to refund coupon", orderCode);
return;
}
couponProxyService.orderCancelCoupon(uid, orderCode, CouponBo.builder().couponCode(orderCoupon.getCouponCode()).build());
} catch (Exception ex) {
logger.warn("refund coupon error,uid:{},orderCode:{}", uid, orderCode, ex);
}
}
}
... ...
... ... @@ -141,6 +141,8 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService {
case WAITING_PAY:
targetStatus = OrderStatus.BUYER_CANCEL_BEFORE_PAY;
cancelBeforePaid(orderRequest, node, expectStatus, targetStatus);
//退还优惠券
buyerOrderCancelService.refundCouponIfNeed(orderRequest.getUid(),orderRequest.getOrderCode());
break;
case HAS_PAYED:
BuyerOrderGoods bog = buyerOrderGoodsMapper.selectByOrderCode(orderRequest.getUid(),
... ... @@ -152,6 +154,8 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService {
.expected(expectStatus).target(targetStatus).skup(skup).sellerUid(buyerOrder.getSellerUid())
.build();
buyerOrderCancelService.cancel(bsde);
//退还优惠券
buyerOrderCancelService.refundCouponIfNeed(orderRequest.getUid(),orderRequest.getOrderCode());
break;
case SELLER_SEND_OUT:
bog = buyerOrderGoodsMapper.selectByOrderCode(orderRequest.getUid(),
... ... @@ -163,6 +167,8 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService {
.expected(expectStatus).target(targetStatus).skup(skup).sellerUid(buyerOrder.getSellerUid())
.build();
buyerOrderCancelService.cancel(bdre);
//退还优惠券
buyerOrderCancelService.refundCouponIfNeed(orderRequest.getUid(),orderRequest.getOrderCode());
break;
}
... ...
package com.yohoufo.order.service.impl;
import com.google.common.collect.Lists;
import com.yoho.core.rest.client.ServiceCaller;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
... ... @@ -40,7 +39,6 @@ import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
import com.yohoufo.order.utils.AddressHelper;
import com.yohoufo.order.utils.MathUtils;
import org.apache.commons.lang3.StringUtils;
import org.elasticsearch.search.aggregations.bucket.histogram.Histogram;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -272,7 +270,7 @@ public class ShoppingServiceImpl implements IShoppingService {
.deliverWay(OrderConstant.DELIVERY_WAY_SF)
.channelNo(shoppingRequest.getChannelNo())
.amount(BigDecimal.valueOf(chargeResult.getFinalAmount()))
.shipFee(BigDecimal.valueOf(chargeResult.getExpressDeliveryAmount()))
.shipFee(BigDecimal.valueOf(chargeResult.getShippingAmount()))
.couponBo(CouponBo.builder().couponCode(chargeResult.getCouponPayResult().getCouponCode())
.couponAmount(BigDecimal.valueOf(chargeResult.getCouponPayResult().getCouponAmount()))
.build()
... ...
... ... @@ -98,10 +98,10 @@ public class CouponProxyService implements Compensator {
ApiResponse resp = serviceCaller.call("app.coupons.cancel", uid, orderCode, Lists.newArrayList(coupon.getCouponCode()));
Boolean result = getResultFromApiResponse(resp);
if (result == null || result.booleanValue() == false) {
logger.warn("[{}] cancel couponBo fail,coupons is {}", orderCode, coupon);
throw new ServiceException(ServiceError.PROMOTION_COUPON_IS_NOT_VAILD);
logger.warn("[{}] cancel coupon fail,couponBo is {}", orderCode, coupon);
} else {
logger.info("[{}] cancel coupon success", orderCode);
}
logger.info("[{}] cancel coupon success", orderCode);
}
private <T> T getResultFromApiResponse(ApiResponse resp) {
... ...
... ... @@ -86,7 +86,7 @@ public class ShoppingSupport {
//运费
PromotionFormula expressFormula = new PromotionFormula();
expressFormula.setPromotion(OrderConstant.DELIVERY_DESC);
expressFormula.setPromotionAmount(OrderConstant.PLUS_SIGN + MathUtils.formatCurrencyStr(chargeResult.getExpressDeliveryAmount()));
expressFormula.setPromotionAmount(OrderConstant.PLUS_SIGN + MathUtils.formatCurrencyStr(chargeResult.getShippingAmount()));
formulas.add(expressFormula);
... ...
... ... @@ -55,6 +55,7 @@ datasources:
- com.yohoufo.dal.order.SkupBatchMapper
- com.yohoufo.dal.order.SellerWalletMapper
- com.yohoufo.dal.order.SellerWalletDetailMapper
- com.yohoufo.dal.order.OrderCouponMapper
ufo_promotion:
servers:
... ...
... ... @@ -55,6 +55,7 @@ datasources:
- com.yohoufo.dal.order.SkupBatchMapper
- com.yohoufo.dal.order.SellerWalletMapper
- com.yohoufo.dal.order.SellerWalletDetailMapper
- com.yohoufo.dal.order.OrderCouponMapper
ufo_promotion:
servers:
... ...