Authored by tanling

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

# Conflicts:
#	promotion/src/main/java/com/yohoufo/promotion/controller/OrderCouponController.java
  1 +package com.yohoufo.dal.order;
  2 +
  3 + import com.yohoufo.dal.order.model.OrderCoupon;
  4 + import org.apache.ibatis.annotations.Param;
  5 +
  6 + import java.util.List;
  7 +
  8 +/**
  9 + * Created by jiexiang.wu on 2018/11/20.
  10 + */
  11 +public interface OrderCouponMapper {
  12 +
  13 + int insert(OrderCoupon orderCoupon);
  14 +
  15 + List<OrderCoupon> selectByUidAndOrderCode(@Param("uid") int uid, @Param("orderCode") long orderCode);
  16 +}
@@ -15,6 +15,11 @@ public class BuyerOrderGoods { @@ -15,6 +15,11 @@ public class BuyerOrderGoods {
15 15
16 private BigDecimal goodsAmount; 16 private BigDecimal goodsAmount;
17 17
  18 + /**
  19 + * 优惠券减免金额
  20 + */
  21 + private BigDecimal couponCutAmount;
  22 +
18 public Integer getUid() { 23 public Integer getUid() {
19 return uid; 24 return uid;
20 } 25 }
@@ -62,4 +67,12 @@ public class BuyerOrderGoods { @@ -62,4 +67,12 @@ public class BuyerOrderGoods {
62 public void setGoodsAmount(BigDecimal goodsAmount) { 67 public void setGoodsAmount(BigDecimal goodsAmount) {
63 this.goodsAmount = goodsAmount; 68 this.goodsAmount = goodsAmount;
64 } 69 }
  70 +
  71 + public BigDecimal getCouponCutAmount() {
  72 + return couponCutAmount;
  73 + }
  74 +
  75 + public void setCouponCutAmount(BigDecimal couponCutAmount) {
  76 + this.couponCutAmount = couponCutAmount;
  77 + }
65 } 78 }
  1 +package com.yohoufo.dal.order.model;
  2 +
  3 +/**
  4 + * Created by jiexiang.wu on 2018/11/20.
  5 + */
  6 +public class OrderCoupon {
  7 + private int uid;
  8 + private long orderCode;
  9 + private String couponCode;
  10 + private int createTime;
  11 +
  12 + public int getUid() {
  13 + return uid;
  14 + }
  15 +
  16 + public void setUid(int uid) {
  17 + this.uid = uid;
  18 + }
  19 +
  20 + public long getOrderCode() {
  21 + return orderCode;
  22 + }
  23 +
  24 + public void setOrderCode(long orderCode) {
  25 + this.orderCode = orderCode;
  26 + }
  27 +
  28 + public String getCouponCode() {
  29 + return couponCode;
  30 + }
  31 +
  32 + public void setCouponCode(String couponCode) {
  33 + this.couponCode = couponCode;
  34 + }
  35 +
  36 + public int getCreateTime() {
  37 + return createTime;
  38 + }
  39 +
  40 + public void setCreateTime(int createTime) {
  41 + this.createTime = createTime;
  42 + }
  43 +}
@@ -8,6 +8,7 @@ @@ -8,6 +8,7 @@
8 <result column="skup" jdbcType="INTEGER" property="skup" /> 8 <result column="skup" jdbcType="INTEGER" property="skup" />
9 <result column="goods_price" jdbcType="DECIMAL" property="goodsPrice" /> 9 <result column="goods_price" jdbcType="DECIMAL" property="goodsPrice" />
10 <result column="goods_amount" jdbcType="DECIMAL" property="goodsAmount" /> 10 <result column="goods_amount" jdbcType="DECIMAL" property="goodsAmount" />
  11 + <result column="coupons_cut_amount" jdbcType="DECIMAL" property="couponCutAmount" />
11 </resultMap> 12 </resultMap>
12 <sql id="Base_Column_List"> 13 <sql id="Base_Column_List">
13 id, order_code, skup, goods_price, goods_amount, uid 14 id, order_code, skup, goods_price, goods_amount, uid
@@ -83,6 +84,9 @@ @@ -83,6 +84,9 @@
83 <if test="uid != null"> 84 <if test="uid != null">
84 uid, 85 uid,
85 </if> 86 </if>
  87 + <if test="couponCutAmount != null">
  88 + coupons_cut_amount,
  89 + </if>
86 </trim> 90 </trim>
87 <trim prefix="values (" suffix=")" suffixOverrides=","> 91 <trim prefix="values (" suffix=")" suffixOverrides=",">
88 <if test="orderCode != null"> 92 <if test="orderCode != null">
@@ -100,6 +104,9 @@ @@ -100,6 +104,9 @@
100 <if test="uid != null"> 104 <if test="uid != null">
101 #{uid,jdbcType=INTEGER}, 105 #{uid,jdbcType=INTEGER},
102 </if> 106 </if>
  107 + <if test="couponCutAmount != null">
  108 + #{couponCutAmount,jdbcType=DECIMAL},
  109 + </if>
103 </trim> 110 </trim>
104 </insert> 111 </insert>
105 <update id="updateByPrimaryKeySelective" parameterType="com.yohoufo.dal.order.model.BuyerOrderGoods"> 112 <update id="updateByPrimaryKeySelective" parameterType="com.yohoufo.dal.order.model.BuyerOrderGoods">
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3 +<mapper namespace="com.yohoufo.dal.order.OrderCouponMapper">
  4 + <resultMap id="BaseResultMap" type="com.yohoufo.dal.order.model.OrderCoupon">
  5 + <id column="id" jdbcType="BIGINT" property="id"/>
  6 + <result column="uid" jdbcType="INTEGER" property="uid"/>
  7 + <result column="order_code" jdbcType="BIGINT" property="orderCode"/>
  8 + <result column="coupon_code" jdbcType="VARCHAR" property="couponCode"/>
  9 + <result column="create_time" jdbcType="INTEGER" property="createTime"/>
  10 + </resultMap>
  11 + <sql id="Base_Column_List">
  12 + id, uid, order_code, coupon_code, create_time
  13 + </sql>
  14 +
  15 + <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.yohoufo.dal.order.model.OrderCoupon" useGeneratedKeys="true">
  16 + insert into order_coupon (uid, order_code, coupon_code,create_time)
  17 + values (#{uid,jdbcType=INTEGER}, #{orderCode,jdbcType=BIGINT}, #{couponCode,jdbcType=VARCHAR}, #{createTime,jdbcType=INTEGER})
  18 + </insert>
  19 +
  20 + <select id="selectByUidAndOrderCode" resultMap="BaseResultMap">
  21 + select
  22 + <include refid="Base_Column_List"/>
  23 + from buyer_order
  24 + where order_code = #{orderCode,jdbcType=BIGINT}
  25 + and uid = #{uid,jdbcType=INTEGER}
  26 + </select>
  27 +</mapper>
@@ -31,4 +31,9 @@ public class ChargeResult { @@ -31,4 +31,9 @@ public class ChargeResult {
31 */ 31 */
32 private double finalAmount; 32 private double finalAmount;
33 33
  34 + public ChargeResult() {
  35 + //init
  36 + this.couponPayResult = CouponPayResult.builder().build();
  37 + }
  38 +
34 } 39 }
@@ -32,4 +32,9 @@ public class CouponPayResult { @@ -32,4 +32,9 @@ public class CouponPayResult {
32 */ 32 */
33 private double couponAmount = 0; 33 private double couponAmount = 0;
34 34
  35 + /**
  36 + * 券数量
  37 + */
  38 + private int couponCount = 0;
  39 +
35 } 40 }
  1 +package com.yohoufo.order.model.bo;
  2 +
  3 +import lombok.Data;
  4 +import lombok.ToString;
  5 +import lombok.experimental.Builder;
  6 +
  7 +import java.math.BigDecimal;
  8 +
  9 +/**
  10 + * Created by jiexiang.wu on 2018/11/20.
  11 + */
  12 +@Data
  13 +@ToString
  14 +@Builder
  15 +public class CouponBo {
  16 + //券code
  17 + private String couponCode;
  18 + //券金额
  19 + private BigDecimal couponAmount;
  20 +}
@@ -3,11 +3,13 @@ package com.yohoufo.order.model.dto; @@ -3,11 +3,13 @@ package com.yohoufo.order.model.dto;
3 3
4 import com.yoho.service.model.response.UserAddressRspBO; 4 import com.yoho.service.model.response.UserAddressRspBO;
5 import com.yohoufo.order.model.AddressInfo; 5 import com.yohoufo.order.model.AddressInfo;
  6 +import com.yohoufo.order.model.bo.CouponBo;
6 import lombok.Data; 7 import lombok.Data;
7 import lombok.ToString; 8 import lombok.ToString;
8 import lombok.experimental.Builder; 9 import lombok.experimental.Builder;
9 10
10 import java.math.BigDecimal; 11 import java.math.BigDecimal;
  12 +import java.util.List;
11 13
12 @Data 14 @Data
13 @Builder 15 @Builder
@@ -39,4 +41,9 @@ public class OrderBuilder { @@ -39,4 +41,9 @@ public class OrderBuilder {
39 AddressInfo addressInfo; 41 AddressInfo addressInfo;
40 42
41 AddressInfo hiddenAddressInfo; 43 AddressInfo hiddenAddressInfo;
  44 +
  45 + /**
  46 + * 使用的优惠券
  47 + */
  48 + CouponBo couponBo;
42 } 49 }
@@ -142,6 +142,11 @@ public class OrderDetailInfo { @@ -142,6 +142,11 @@ public class OrderDetailInfo {
142 String feePrice; 142 String feePrice;
143 143
144 /** 144 /**
  145 + * 优惠券金额
  146 + */
  147 + String couponCutPrice;
  148 +
  149 + /**
145 * 实付金额 150 * 实付金额
146 */ 151 */
147 String realPayPrice; 152 String realPayPrice;
@@ -150,6 +150,7 @@ public abstract class AbsOrderDetailService implements IOrderDetailService{ @@ -150,6 +150,7 @@ public abstract class AbsOrderDetailService implements IOrderDetailService{
150 OrderDetailInfo.PriceInfo priceInfo = OrderDetailInfo.PriceInfo.builder() 150 OrderDetailInfo.PriceInfo priceInfo = OrderDetailInfo.PriceInfo.builder()
151 .goodPrice(buyerOrderGoods.getGoodsPrice() == null ? "0" : buyerOrderGoods.getGoodsPrice().toPlainString() ) 151 .goodPrice(buyerOrderGoods.getGoodsPrice() == null ? "0" : buyerOrderGoods.getGoodsPrice().toPlainString() )
152 .feePrice(buyerOrder.getShipFee() == null ? "0" : buyerOrder.getShipFee().toPlainString()) 152 .feePrice(buyerOrder.getShipFee() == null ? "0" : buyerOrder.getShipFee().toPlainString())
  153 + .couponCutPrice(buyerOrderGoods.getCouponCutAmount() == null ? "0":buyerOrderGoods.getCouponCutAmount().toPlainString())
153 .realPayPrice(buyerOrder.getAmount() == null ? "0" : buyerOrder.getAmount().toPlainString()) 154 .realPayPrice(buyerOrder.getAmount() == null ? "0" : buyerOrder.getAmount().toPlainString())
154 .build(); 155 .build();
155 orderDetailInfo.setPriceInfo(priceInfo); 156 orderDetailInfo.setPriceInfo(priceInfo);
@@ -23,6 +23,7 @@ import com.yohoufo.order.charge.model.CouponMatchResult; @@ -23,6 +23,7 @@ import com.yohoufo.order.charge.model.CouponMatchResult;
23 import com.yohoufo.order.event.BuyerCancelEvent; 23 import com.yohoufo.order.event.BuyerCancelEvent;
24 import com.yohoufo.order.event.NotPaidNoticeEvent; 24 import com.yohoufo.order.event.NotPaidNoticeEvent;
25 import com.yohoufo.order.model.AddressInfo; 25 import com.yohoufo.order.model.AddressInfo;
  26 +import com.yohoufo.order.model.bo.CouponBo;
26 import com.yohoufo.order.model.dto.BuyerOrderSubmitResult; 27 import com.yohoufo.order.model.dto.BuyerOrderSubmitResult;
27 import com.yohoufo.order.model.dto.OrderBuilder; 28 import com.yohoufo.order.model.dto.OrderBuilder;
28 import com.yohoufo.order.model.request.ShoppingRequest; 29 import com.yohoufo.order.model.request.ShoppingRequest;
@@ -272,6 +273,10 @@ public class ShoppingServiceImpl implements IShoppingService { @@ -272,6 +273,10 @@ public class ShoppingServiceImpl implements IShoppingService {
272 .channelNo(shoppingRequest.getChannelNo()) 273 .channelNo(shoppingRequest.getChannelNo())
273 .amount(BigDecimal.valueOf(chargeResult.getFinalAmount())) 274 .amount(BigDecimal.valueOf(chargeResult.getFinalAmount()))
274 .shipFee(BigDecimal.valueOf(chargeResult.getExpressDeliveryAmount())) 275 .shipFee(BigDecimal.valueOf(chargeResult.getExpressDeliveryAmount()))
  276 + .couponBo(CouponBo.builder().couponCode(chargeResult.getCouponPayResult().getCouponCode())
  277 + .couponAmount(BigDecimal.valueOf(chargeResult.getCouponPayResult().getCouponAmount()))
  278 + .build()
  279 + )
275 .hiddenAddressInfo(hiddenAddress) 280 .hiddenAddressInfo(hiddenAddress)
276 .addressInfo(addressInfo) 281 .addressInfo(addressInfo)
277 .clientType(shoppingRequest.getClientType()) 282 .clientType(shoppingRequest.getClientType())
@@ -3,6 +3,7 @@ package com.yohoufo.order.service.impl; @@ -3,6 +3,7 @@ package com.yohoufo.order.service.impl;
3 import com.alibaba.fastjson.JSONObject; 3 import com.alibaba.fastjson.JSONObject;
4 import com.yoho.core.common.utils.DateUtil; 4 import com.yoho.core.common.utils.DateUtil;
5 import com.yoho.core.dal.datasource.annotation.Database; 5 import com.yoho.core.dal.datasource.annotation.Database;
  6 +import com.yoho.core.transaction.annoation.YHTransaction;
6 import com.yoho.error.ServiceError; 7 import com.yoho.error.ServiceError;
7 import com.yoho.error.exception.ServiceException; 8 import com.yoho.error.exception.ServiceException;
8 import com.yohoufo.dal.order.*; 9 import com.yohoufo.dal.order.*;
@@ -15,6 +16,7 @@ import com.yohoufo.order.constants.MetaKey; @@ -15,6 +16,7 @@ import com.yohoufo.order.constants.MetaKey;
15 import com.yohoufo.order.model.dto.BuyerOrderSubmitResult; 16 import com.yohoufo.order.model.dto.BuyerOrderSubmitResult;
16 import com.yohoufo.order.model.dto.OrderBuilder; 17 import com.yohoufo.order.model.dto.OrderBuilder;
17 import com.yohoufo.order.service.ISubmitOrderService; 18 import com.yohoufo.order.service.ISubmitOrderService;
  19 +import com.yohoufo.order.service.proxy.CouponProxyService;
18 import com.yohoufo.order.service.proxy.ProductProxyService; 20 import com.yohoufo.order.service.proxy.ProductProxyService;
19 import org.slf4j.Logger; 21 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory; 22 import org.slf4j.LoggerFactory;
@@ -34,13 +36,21 @@ public class SubmitOrderServiceImpl implements ISubmitOrderService { @@ -34,13 +36,21 @@ public class SubmitOrderServiceImpl implements ISubmitOrderService {
34 @Autowired 36 @Autowired
35 private ProductProxyService productProxyService; 37 private ProductProxyService productProxyService;
36 38
  39 + @Autowired
  40 + private CouponProxyService couponProxyService;
  41 +
37 42
  43 + @YHTransaction
38 public BuyerOrderSubmitResult doSumbitOrder(OrderBuilder orderBuilder){ 44 public BuyerOrderSubmitResult doSumbitOrder(OrderBuilder orderBuilder){
39 BuyerOrderSubmitResult result = null; 45 BuyerOrderSubmitResult result = null;
40 try { 46 try {
41 // 减库存 47 // 减库存
42 if(productProxyService.subtractStorage(orderBuilder.getProductId(), orderBuilder.getSkup())) { 48 if(productProxyService.subtractStorage(orderBuilder.getProductId(), orderBuilder.getSkup())) {
43 49
  50 + //使用优惠券
  51 + if (orderBuilder.getCouponBo().getCouponAmount().doubleValue() > 0) {
  52 + couponProxyService.orderUseCoupon(orderBuilder.getUid(), orderBuilder.getOrderCode(), orderBuilder.getCouponBo());
  53 + }
44 // 创建订单 54 // 创建订单
45 return orderCreateService.createOrder(orderBuilder); 55 return orderCreateService.createOrder(orderBuilder);
46 } 56 }
@@ -91,7 +101,8 @@ public class SubmitOrderServiceImpl implements ISubmitOrderService { @@ -91,7 +101,8 @@ public class SubmitOrderServiceImpl implements ISubmitOrderService {
91 @Autowired 101 @Autowired
92 BuyerOrderMetaMapper buyerOrderMetaMapper; 102 BuyerOrderMetaMapper buyerOrderMetaMapper;
93 103
94 - 104 + @Autowired
  105 + OrderCouponMapper orderCouponMapper;
95 106
96 @Autowired 107 @Autowired
97 private ProductProxyService productProxyService; 108 private ProductProxyService productProxyService;
@@ -110,6 +121,7 @@ public class SubmitOrderServiceImpl implements ISubmitOrderService { @@ -110,6 +121,7 @@ public class SubmitOrderServiceImpl implements ISubmitOrderService {
110 * 3.插入订单 表buyer_order 121 * 3.插入订单 表buyer_order
111 * 4.插入订单商品 buyer_order_goods 122 * 4.插入订单商品 buyer_order_goods
112 * 5.插入收货地址 buyer_order_meta 123 * 5.插入收货地址 buyer_order_meta
  124 + * 6.插入优惠券 order_coupon
113 */ 125 */
114 126
115 // 1.表seller_order_goods ==> 不可售 127 // 1.表seller_order_goods ==> 不可售
@@ -127,6 +139,9 @@ public class SubmitOrderServiceImpl implements ISubmitOrderService { @@ -127,6 +139,9 @@ public class SubmitOrderServiceImpl implements ISubmitOrderService {
127 // 5.插入收货地址 buyer_order_meta 买家收货地址 139 // 5.插入收货地址 buyer_order_meta 买家收货地址
128 insertOrderMeta(orderBuilder); 140 insertOrderMeta(orderBuilder);
129 141
  142 + //6.插入优惠券 order_coupon
  143 + insertOrderCouponIfNeed(orderBuilder);
  144 +
130 BuyerOrderSubmitResult result = BuyerOrderSubmitResult.builder() 145 BuyerOrderSubmitResult result = BuyerOrderSubmitResult.builder()
131 .orderCode(orderBuilder.getOrderCode()) 146 .orderCode(orderBuilder.getOrderCode())
132 .sellerOrder(sellerOrder).sellerOrderGoods(sellerOrderGoods).build(); 147 .sellerOrder(sellerOrder).sellerOrderGoods(sellerOrderGoods).build();
@@ -159,6 +174,7 @@ public class SubmitOrderServiceImpl implements ISubmitOrderService { @@ -159,6 +174,7 @@ public class SubmitOrderServiceImpl implements ISubmitOrderService {
159 buyerOrderGoods.setGoodsPrice(sellerOrderGoods.getGoodsPrice()); 174 buyerOrderGoods.setGoodsPrice(sellerOrderGoods.getGoodsPrice());
160 buyerOrderGoods.setGoodsAmount(sellerOrderGoods.getGoodsPrice()); 175 buyerOrderGoods.setGoodsAmount(sellerOrderGoods.getGoodsPrice());
161 buyerOrderGoods.setUid(orderBuilder.getUid()); 176 buyerOrderGoods.setUid(orderBuilder.getUid());
  177 + buyerOrderGoods.setCouponCutAmount(orderBuilder.getCouponBo().getCouponAmount());
162 buyerOrderGoodsMapper.insertSelective(buyerOrderGoods); 178 buyerOrderGoodsMapper.insertSelective(buyerOrderGoods);
163 } 179 }
164 180
@@ -181,6 +197,18 @@ public class SubmitOrderServiceImpl implements ISubmitOrderService { @@ -181,6 +197,18 @@ public class SubmitOrderServiceImpl implements ISubmitOrderService {
181 buyerOrderMapper.insert(buyerOrder); 197 buyerOrderMapper.insert(buyerOrder);
182 } 198 }
183 199
  200 + private void insertOrderCouponIfNeed(OrderBuilder orderBuilder) {
  201 + if (orderBuilder.getCouponBo().getCouponAmount().doubleValue() > 0) {
  202 + OrderCoupon orderCoupon = new OrderCoupon();
  203 + orderCoupon.setUid(orderBuilder.getUid());
  204 + orderCoupon.setOrderCode(orderBuilder.getOrderCode());
  205 + orderCoupon.setCouponCode(orderBuilder.getCouponBo().getCouponCode());
  206 + orderCoupon.setCreateTime(DateUtil.getCurrentTimeSecond());
  207 +
  208 + orderCouponMapper.insert(orderCoupon);
  209 + }
  210 + }
  211 +
184 private SellerOrder selectSellerOrder(OrderBuilder orderBuilder) { 212 private SellerOrder selectSellerOrder(OrderBuilder orderBuilder) {
185 SellerOrder sellerOrder = sellerOrderMapper.selectBySkup(orderBuilder.getSkup()); 213 SellerOrder sellerOrder = sellerOrderMapper.selectBySkup(orderBuilder.getSkup());
186 return sellerOrder; 214 return sellerOrder;
1 package com.yohoufo.order.service.proxy; 1 package com.yohoufo.order.service.proxy;
2 2
  3 +import com.alibaba.fastjson.JSON;
  4 +import com.alibaba.fastjson.JSONObject;
3 import com.google.common.collect.Lists; 5 import com.google.common.collect.Lists;
  6 +import com.yoho.core.transaction.Compensator;
  7 +import com.yoho.core.transaction.annoation.TxCompensatable;
  8 +import com.yoho.core.transaction.annoation.TxCompensateArgs;
  9 +import com.yoho.error.ServiceError;
  10 +import com.yoho.error.exception.ServiceException;
4 import com.yohobuy.ufo.model.promotion.UserCouponsBo; 11 import com.yohobuy.ufo.model.promotion.UserCouponsBo;
  12 +import com.yohoufo.common.ApiResponse;
  13 +import com.yohoufo.common.caller.UfoServiceCaller;
  14 +import com.yohoufo.order.model.bo.CouponBo;
  15 +import org.slf4j.Logger;
  16 +import org.slf4j.LoggerFactory;
  17 +import org.springframework.beans.factory.annotation.Autowired;
5 import org.springframework.stereotype.Service; 18 import org.springframework.stereotype.Service;
6 19
7 import java.math.BigDecimal; 20 import java.math.BigDecimal;
@@ -11,7 +24,13 @@ import java.util.List; @@ -11,7 +24,13 @@ import java.util.List;
11 * Created by jiexiang.wu on 2018/11/19. 24 * Created by jiexiang.wu on 2018/11/19.
12 */ 25 */
13 @Service 26 @Service
14 -public class CouponProxyService { 27 +public class CouponProxyService implements Compensator {
  28 +
  29 + private final static Logger logger = LoggerFactory.getLogger(CouponProxyService.class);
  30 +
  31 + @Autowired
  32 + private UfoServiceCaller serviceCaller;
  33 +
15 /** 34 /**
16 * 查询用户可以使用的券 35 * 查询用户可以使用的券
17 * 36 *
@@ -54,4 +73,75 @@ public class CouponProxyService { @@ -54,4 +73,75 @@ public class CouponProxyService {
54 userCouponsBo.setEndTime(1546275661L); 73 userCouponsBo.setEndTime(1546275661L);
55 return Lists.newArrayList(userCouponsBo); 74 return Lists.newArrayList(userCouponsBo);
56 } 75 }
  76 +
  77 +
  78 + /**
  79 + * 使用优惠券,有补偿功能
  80 + *
  81 + * @param uid
  82 + * @param orderCode
  83 + * @param coupon
  84 + */
  85 + @TxCompensatable(value = CouponProxyService.class)
  86 + public void orderUseCoupon(@TxCompensateArgs("uid") int uid, @TxCompensateArgs("orderCode") long orderCode,
  87 + @TxCompensateArgs("couponBo") CouponBo coupon) {
  88 + logger.info("[{}] request to use coupon,couponBo is {}", orderCode, coupon);
  89 + ApiResponse resp = serviceCaller.call("app.coupons.use", uid, orderCode, Lists.newArrayList(coupon.getCouponCode()));
  90 + if (getResultFromApiResponse(resp) == false) {
  91 + logger.warn("[{}] use couponBo fail,coupons is {}", orderCode, coupon);
  92 + throw new ServiceException(ServiceError.PROMOTION_COUPON_IS_NOT_VAILD);
  93 + }
  94 + logger.info("[{}] use coupon success", orderCode);
  95 + }
  96 +
  97 +
  98 + /**
  99 + * 取消券使用
  100 + *
  101 + * @param uid
  102 + * @param orderCode
  103 + * @param coupon
  104 + */
  105 + public void orderCancelCoupon(int uid, long orderCode, CouponBo coupon) {
  106 + logger.info("[{}] request to cancel coupon,couponBo is {}", orderCode, coupon);
  107 + ApiResponse resp = serviceCaller.call("app.coupons.cancel", uid, orderCode, Lists.newArrayList(coupon.getCouponCode()));
  108 + if (getResultFromApiResponse(resp) == false) {
  109 + logger.warn("[{}] cancel couponBo fail,coupons is {}", orderCode, coupon);
  110 + throw new ServiceException(ServiceError.PROMOTION_COUPON_IS_NOT_VAILD);
  111 + }
  112 + logger.info("[{}] cancel coupon success", orderCode);
  113 + }
  114 +
  115 + private boolean getResultFromApiResponse(ApiResponse resp) {
  116 + if (resp == null) {
  117 + return false;
  118 + }
  119 + if (resp.getCode() != 200 || resp.getData() == null) {
  120 + return false;
  121 + }
  122 + return (boolean) resp.getData();
  123 + }
  124 +
  125 + /**
  126 + * 补偿
  127 + *
  128 + * @param message json格式的字符串
  129 + */
  130 + @Override
  131 + public void compensate(String message) {
  132 + logger.info("CouponProxyService begin to compensate : {}", message);
  133 + int uid = 0;
  134 + long orderCode = 0;
  135 + CouponBo couponBo = null;
  136 + try {
  137 + JSONObject json = JSON.parseObject(message);
  138 + uid = json.getIntValue("uid");
  139 + orderCode = json.getLongValue("orderCode");
  140 + couponBo = json.getObject("coupons", CouponBo.class);
  141 + } catch (Exception ex) {
  142 + logger.warn("parse message to json error,message is {}", message, ex);
  143 + }
  144 + orderCancelCoupon(uid, orderCode, couponBo);
  145 + logger.info("CouponProxyService compensate end,uid is {},orderCode is {}", uid, orderCode);
  146 + }
57 } 147 }
1 package com.yohoufo.order.service.support; 1 package com.yohoufo.order.service.support;
2 2
3 -import com.fasterxml.jackson.databind.deser.DataFormatReaders;  
4 import com.google.common.collect.Lists; 3 import com.google.common.collect.Lists;
5 import com.yohoufo.common.helper.ImageUrlAssist; 4 import com.yohoufo.common.helper.ImageUrlAssist;
6 -import com.yohoufo.common.utils.BigDecimalHelper;  
7 import com.yohoufo.dal.order.model.SellerOrderGoods; 5 import com.yohoufo.dal.order.model.SellerOrderGoods;
8 import com.yohobuy.ufo.model.order.constants.OrderConstant; 6 import com.yohobuy.ufo.model.order.constants.OrderConstant;
9 -import com.yohoufo.order.charge.ChargeContext;  
10 import com.yohoufo.order.charge.model.ChargeResult; 7 import com.yohoufo.order.charge.model.ChargeResult;
11 import com.yohoufo.order.charge.model.CouponPayResult; 8 import com.yohoufo.order.charge.model.CouponPayResult;
12 import com.yohoufo.order.model.response.CouponInfo; 9 import com.yohoufo.order.model.response.CouponInfo;
13 -import com.yohoufo.order.model.response.CouponInfo;  
14 import com.yohoufo.order.model.response.GoodsInfo; 10 import com.yohoufo.order.model.response.GoodsInfo;
15 import com.yohoufo.order.model.response.PaymentResponse; 11 import com.yohoufo.order.model.response.PaymentResponse;
16 import com.yohoufo.order.model.response.PromotionFormula; 12 import com.yohoufo.order.model.response.PromotionFormula;
@@ -98,7 +94,7 @@ public class ShoppingSupport { @@ -98,7 +94,7 @@ public class ShoppingSupport {
98 94
99 //优惠券 95 //优惠券
100 CouponPayResult couponPayResult = chargeResult.getCouponPayResult(); 96 CouponPayResult couponPayResult = chargeResult.getCouponPayResult();
101 - if (couponPayResult != null) { 97 + if (couponPayResult.getCouponAmount() > 0) {
102 PromotionFormula couponFormula = new PromotionFormula(); 98 PromotionFormula couponFormula = new PromotionFormula();
103 couponFormula.setPromotion(OrderConstant.COUPON_DESC); 99 couponFormula.setPromotion(OrderConstant.COUPON_DESC);
104 couponFormula.setPromotionAmount(OrderConstant.SUB_SIGN + MathUtils.formatCurrencyStr(couponPayResult.getCouponAmount())); 100 couponFormula.setPromotionAmount(OrderConstant.SUB_SIGN + MathUtils.formatCurrencyStr(couponPayResult.getCouponAmount()));
@@ -134,16 +130,17 @@ public class ShoppingSupport { @@ -134,16 +130,17 @@ public class ShoppingSupport {
134 130
135 } 131 }
136 132
  133 + /**
  134 + * 使用的优惠券信息
  135 + * @param chargeResult
  136 + * @return
  137 + */
137 public CouponInfo getCouponInfo(ChargeResult chargeResult) { 138 public CouponInfo getCouponInfo(ChargeResult chargeResult) {
138 CouponPayResult couponPayResult = chargeResult.getCouponPayResult(); 139 CouponPayResult couponPayResult = chargeResult.getCouponPayResult();
139 - if (couponPayResult == null) {  
140 - return null;  
141 - }  
142 -  
143 return CouponInfo.builder().couponCode(couponPayResult.getCouponCode()) 140 return CouponInfo.builder().couponCode(couponPayResult.getCouponCode())
144 .couponTitle(couponPayResult.getCouponTitle()) 141 .couponTitle(couponPayResult.getCouponTitle())
145 .couponAmountStr(MathUtils.formatCurrencyStr(couponPayResult.getCouponAmount())) 142 .couponAmountStr(MathUtils.formatCurrencyStr(couponPayResult.getCouponAmount()))
146 - .couponCount(1) 143 + .couponCount(couponPayResult.getCouponCount())
147 .build(); 144 .build();
148 } 145 }
149 } 146 }
@@ -38,8 +38,8 @@ public class OrderCouponController { @@ -38,8 +38,8 @@ public class OrderCouponController {
38 @RequestMapping(params = "method=app.coupons.use") 38 @RequestMapping(params = "method=app.coupons.use")
39 @ResponseBody 39 @ResponseBody
40 public ApiResponse useCoupon(@RequestParam(value = "uid") Integer uid, 40 public ApiResponse useCoupon(@RequestParam(value = "uid") Integer uid,
41 - @RequestParam(value = "couponCodes") List<String> couponCodes,  
42 - @RequestParam(value = "orderCode") long orderCode) { 41 + @RequestParam(value = "orderCode") long orderCode,
  42 + @RequestParam(value = "couponCodes") List<String> couponCodes) {
43 43
44 logger.info("use coupons, uid: {},couponCodes: {}, orderCode :{}", uid, couponCodes, orderCode); 44 logger.info("use coupons, uid: {},couponCodes: {}, orderCode :{}", uid, couponCodes, orderCode);
45 boolean useSuccess = couponService.useCoupon(uid, couponCodes, orderCode); 45 boolean useSuccess = couponService.useCoupon(uid, couponCodes, orderCode);
@@ -58,8 +58,8 @@ public class OrderCouponController { @@ -58,8 +58,8 @@ public class OrderCouponController {
58 @RequestMapping(params = "method=app.coupons.cancel") 58 @RequestMapping(params = "method=app.coupons.cancel")
59 @ResponseBody 59 @ResponseBody
60 public ApiResponse cancelCoupon(@RequestParam(value = "uid") Integer uid, 60 public ApiResponse cancelCoupon(@RequestParam(value = "uid") Integer uid,
61 - @RequestParam(value = "couponCodes") List<String> couponCodes,  
62 - @RequestParam(value = "orderCode") long orderCode) { 61 + @RequestParam(value = "orderCode") long orderCode,
  62 + @RequestParam(value = "couponCodes") List<String> couponCodes) {
63 63
64 logger.info("cancel coupons, uid: {},couponCodes: {}, orderCode :{}", uid, couponCodes, orderCode); 64 logger.info("cancel coupons, uid: {},couponCodes: {}, orderCode :{}", uid, couponCodes, orderCode);
65 boolean cancelSuccess = couponService.cancelCoupon(uid, couponCodes, orderCode); 65 boolean cancelSuccess = couponService.cancelCoupon(uid, couponCodes, orderCode);
@@ -68,7 +68,6 @@ public class OrderCouponController { @@ -68,7 +68,6 @@ public class OrderCouponController {
68 } 68 }
69 69
70 70
71 -  
72 /** 71 /**
73 * 优惠券列表(订单使用) 72 * 优惠券列表(订单使用)
74 * @param uid 73 * @param uid
@@ -105,3 +105,8 @@ order.buyer.cancelWhenSellerUnDelivery.sellerGetMoneyRate=0.8 @@ -105,3 +105,8 @@ order.buyer.cancelWhenSellerUnDelivery.sellerGetMoneyRate=0.8
105 105
106 uic.url=http://java-yoho-uic.test3.ingress.dev.yohocorp.com/uic 106 uic.url=http://java-yoho-uic.test3.ingress.dev.yohocorp.com/uic
107 yoho.message.controller.url=http://message-controller.yohoops.org/yoho-message-controller 107 yoho.message.controller.url=http://message-controller.yohoops.org/yoho-message-controller
  108 +
  109 +#rabbit address for transaction compensate
  110 +rabbit_host=192.168.102.45:5672
  111 +rabbit_user=yoho
  112 +rabbit_password=yoho
@@ -76,3 +76,9 @@ order.buyer.cancelWhenSellerUnDelivery.sellerGetMoneyRate=${order.buyer.cancelWh @@ -76,3 +76,9 @@ order.buyer.cancelWhenSellerUnDelivery.sellerGetMoneyRate=${order.buyer.cancelWh
76 erp-gateway.url=${erp-gateway.url} 76 erp-gateway.url=${erp-gateway.url}
77 uic.url=${uic.url} 77 uic.url=${uic.url}
78 yoho.message.controller.url=${yoho.message.controller.url} 78 yoho.message.controller.url=${yoho.message.controller.url}
  79 +
  80 +
  81 +#rabbit address for transaction compensate
  82 +rabbit_host=${rabbit_order}
  83 +rabbit_user=${rabbit_order_user}
  84 +rabbit_password=${rabbit_order_password}