Authored by wujiexiang

新增优惠券结算接口

... ... @@ -39,14 +39,6 @@
and status = 0
</select>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
<include refid="Base_Column_List" />
from user_coupon
where id = #{id,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from user_coupon
where id = #{id,jdbcType=INTEGER}
... ...
package com.yohoufo.order.controller;
import com.google.common.collect.Lists;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.common.cache.Cachable;
import com.yohoufo.order.model.request.ShoppingRequest;
import com.yohoufo.order.model.response.OrderSubmitResponse;
import com.yohoufo.order.model.response.OrderSummaryResp;
import com.yohoufo.order.model.response.PaymentResponse;
import com.yohoufo.order.model.response.*;
import com.yohoufo.order.service.IBuyerOrderService;
import com.yohoufo.order.service.IShoppingService;
import com.yohoufo.order.service.impl.SellerOrderService;
import com.yohoufo.order.utils.CouponCodeUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -48,6 +45,38 @@ public class ShoppingController {
return new ApiResponse.ApiResponseBuilder().code(200).data(paymentResponse).message("结算成功").build();
}
/**
* 券列表
*
* @return
*/
@RequestMapping(params = "method=ufo.order.selectCoupon")
public ApiResponse selectCoupon(@RequestParam(name = "uid") int uid,
@RequestParam(name = "skup") int skup,
@RequestParam(name = "coupon_code",required = false) String couponCode) {
ShoppingRequest req = ShoppingRequest.builder().uid(uid).skup(skup).couponCodes(CouponCodeUtils.asList(couponCode)).build();
logger.info("in ufo.order.selectCoupon, req {}", req);
ShoppingCouponListResp resp = buyerOrderService.selectCoupon(req);
return new ApiResponse.ApiResponseBuilder().code(200).data(resp).message("ok").build();
}
/**
* 用券结算
*
* @return
*/
@RequestMapping(params = "method=ufo.order.compute")
public ApiResponse compute(@RequestParam(name = "uid") int uid,
@RequestParam(name = "skup") int skup,
@RequestParam(name = "coupon_code",required = false) String couponCode) {
ShoppingRequest req = ShoppingRequest.builder().uid(uid).skup(skup).couponCodes(CouponCodeUtils.asList(couponCode)).build();
logger.info("in ufo.order.compute, req {}", req);
ComputeResponse resp = buyerOrderService.compute(req);
return new ApiResponse.ApiResponseBuilder().code(200).data(resp).message("ok").build();
}
/**
* 提交订单成功
... ... @@ -56,13 +85,14 @@ public class ShoppingController {
@RequestMapping(params = "method=ufo.order.submit")
public ApiResponse submit(@RequestParam(name = "uid") int uid,
@RequestParam(name = "skup") int skup,
@RequestParam(name = "coupon_code",required = false) String couponCode,
@RequestParam(name = "channelNo", required = false) String channelNo,
@RequestParam(name = "addressId") String addressId,
@RequestParam(name = "client_type", required = false) String clientType){
if(StringUtils.isBlank(channelNo)){
channelNo = "2919";
}
ShoppingRequest request = ShoppingRequest.builder().uid(uid).skup(skup).channelNo(channelNo).clientType(clientType).addressId(addressId).build();
ShoppingRequest request = ShoppingRequest.builder().uid(uid).skup(skup).couponCodes(CouponCodeUtils.asList(couponCode)).channelNo(channelNo).clientType(clientType).addressId(addressId).build();
logger.info("in ufo.order.submit, req {}", request);
OrderSubmitResponse paymentResponse = buyerOrderService.submit(request);
return new ApiResponse.ApiResponseBuilder().code(200).data(paymentResponse).message("提交订单SUCCESS").build();
... ...
... ... @@ -5,6 +5,8 @@ import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Builder;
import java.util.List;
@Data
@Builder
@AllArgsConstructor
... ... @@ -16,6 +18,11 @@ public class ShoppingRequest {
private int uid;
/**
* 券code
*/
private List<String> couponCodes;
/**
* 加密过的地址Id
*/
private String addressId;
... ... @@ -31,5 +38,4 @@ public class ShoppingRequest {
private String channelNo;
}
... ...
package com.yohoufo.order.model.response;
import lombok.Data;
import lombok.ToString;
import java.util.List;
/**
* Created by jiexiang.wu on 2018/11/19.
*/
@Data
@ToString
public class ComputeResponse {
/**
* 券使用结果
*/
CouponUseResult couponUseResult;
/**
* 费用列表
*/
List<PromotionFormula> promotionFormulaList;
/**
* 待支付金额
*/
String amount;
}
... ...
package com.yohoufo.order.model.response;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;
import lombok.ToString;
/**
* Created by jiexiang.wu on 2018/11/19.
*/
@Data
@ToString
public class CouponUseResult {
@JSONField(name = "coupon_code")
private String couponCode;
@JSONField(name = "coupon_title")
private String couponTitle;
//coupon_amount的字符串表示
@JSONField(name = "coupon_amount_str")
private String couponAmountStr;
//券的个数
@JSONField(name = "coupon_count")
private int couponCount;
}
... ...
... ... @@ -59,14 +59,4 @@ public class PaymentResponse {
private String deliveryWayCost;
}
@Data
@ToString
public static class PromotionFormula{
private String promotion;
private String promotionAmount;
}
}
... ...
package com.yohoufo.order.model.response;
import lombok.Data;
import lombok.ToString;
/**
* Created by jiexiang.wu on 2018/11/19.
*/
@Data
@ToString
public class PromotionFormula {
private String promotion;
private String promotionAmount;
}
... ...
package com.yohoufo.order.model.response;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Builder;
/**
* Created by jiexiang.wu on 2018/11/19.
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class ShoppingCoupon {
//优惠券code
@JSONField(name = "coupon_code")
private String couponCode;
//名称
@JSONField(name = "coupon_name")
private String couponName;
/**
* 优惠券 有效期 2013.11.01-2017.01.31
*/
@JSONField(name = "coupon_validity")
private String couponValidity;
@JSONField(name = "coupon_value_str")
private String couponValueStr;
/**
* 使用规则描述 如:满200可用
*/
@JSONField(name = "use_rule_str")
private String useRuleStr;
//是否选中 Y选中
private String selected;
//是否支持可选
@JSONField(name = "is_selected_support")
private String isSelectedSupport;
}
... ...
package com.yohoufo.order.model.response;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Builder;
import java.util.List;
/**
* Created by jiexiang.wu on 2018/11/19.
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class ShoppingCouponListResp {
private List<ShoppingCoupon> coupons;
}
... ...
... ... @@ -2,8 +2,10 @@ package com.yohoufo.order.service;
import com.yohoufo.order.model.request.ShoppingRequest;
import com.yohoufo.order.model.response.ComputeResponse;
import com.yohoufo.order.model.response.OrderSubmitResponse;
import com.yohoufo.order.model.response.PaymentResponse;
import com.yohoufo.order.model.response.ShoppingCouponListResp;
public interface IShoppingService {
... ... @@ -16,6 +18,23 @@ public interface IShoppingService {
/**
* 券列表,选择券
*
* @param request
* @return
*/
ShoppingCouponListResp selectCoupon(ShoppingRequest request);
/**
* 重新结算
* @param request
* @return
*/
ComputeResponse compute(ShoppingRequest request);
/**
* 提交订单
* @param shoppingRequest
* @return
... ...
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;
... ... @@ -17,8 +18,7 @@ import com.yohoufo.order.model.AddressInfo;
import com.yohoufo.order.model.dto.BuyerOrderSubmitResult;
import com.yohoufo.order.model.dto.OrderBuilder;
import com.yohoufo.order.model.request.ShoppingRequest;
import com.yohoufo.order.model.response.OrderSubmitResponse;
import com.yohoufo.order.model.response.PaymentResponse;
import com.yohoufo.order.model.response.*;
import com.yohoufo.order.service.ISubmitOrderService;
import com.yohoufo.order.service.IShoppingService;
import com.yohoufo.order.service.cache.CacheCleaner;
... ... @@ -32,6 +32,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
... ... @@ -120,6 +122,69 @@ public class ShoppingServiceImpl implements IShoppingService {
}
@Override
public ShoppingCouponListResp selectCoupon(ShoppingRequest request) {
//todo
ShoppingCoupon coupon1 = new ShoppingCoupon();
coupon1.setCouponValueStr("100");
coupon1.setCouponCode("a123456");
coupon1.setCouponName("test");
coupon1.setCouponValidity("2018.1.1-2019.1.1");
coupon1.setSelected("N");
coupon1.setIsSelectedSupport("Y");
coupon1.setUseRuleStr("满499可用");
ShoppingCoupon coupon2 = new ShoppingCoupon();
coupon2.setCouponValueStr("50");
coupon2.setCouponCode("b987654");
coupon2.setCouponName("全场通用");
coupon2.setCouponValidity("2018.1.1-2019.1.1");
coupon2.setSelected("N");
coupon2.setIsSelectedSupport("Y");
coupon2.setUseRuleStr("满200可用");
ShoppingCouponListResp resp = new ShoppingCouponListResp();
resp.setCoupons(Lists.newArrayList(coupon1, coupon2));
return resp;
}
@Override
public ComputeResponse compute(ShoppingRequest request) {
CouponUseResult result = new CouponUseResult();
result.setCouponCode("a123456");
result.setCouponAmountStr("¥50.00");
result.setCouponTitle("test");
result.setCouponCount(1);
PromotionFormula formula1 = new PromotionFormula();
formula1.setPromotion(OrderConstant.GOODS_PRICE);
formula1.setPromotionAmount(OrderConstant.MONEY_SIGN + "500");
PromotionFormula formula2 = new PromotionFormula();
formula2.setPromotion(OrderConstant.DELIVERY_DESC);
formula2.setPromotionAmount(OrderConstant.PLUS_SIGN + OrderConstant.MONEY_SIGN + delivery_way_sf_cost);
PromotionFormula formula3 = new PromotionFormula();
formula3.setPromotion(OrderConstant.GOODS_REAL_PRICE);
formula3.setPromotionAmount(OrderConstant.MONEY_SIGN + "425");
PromotionFormula formula4 = new PromotionFormula();
formula4.setPromotion("优惠券");
formula4.setPromotionAmount("-"+ OrderConstant.MONEY_SIGN +"100");
List<PromotionFormula> formulaList = Arrays.asList(formula1, formula2, formula4, formula3);
ComputeResponse response = new ComputeResponse();
response.setCouponUseResult(result);
response.setPromotionFormulaList(formulaList);
response.setAmount("425.00");
return response;
}
/**
* 提交订单
* @param shoppingRequest
... ...
... ... @@ -6,6 +6,7 @@ import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohobuy.ufo.model.order.constants.OrderConstant;
import com.yohoufo.order.model.response.GoodsInfo;
import com.yohoufo.order.model.response.PaymentResponse;
import com.yohoufo.order.model.response.PromotionFormula;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
... ... @@ -69,17 +70,17 @@ public class ShoppingSupport {
* @param skup
* @return
*/
public List<PaymentResponse.PromotionFormula> getPromotionFormula(SellerOrderGoods skup) {
PaymentResponse.PromotionFormula formula1 = new PaymentResponse.PromotionFormula();
public List<PromotionFormula> getPromotionFormula(SellerOrderGoods skup) {
PromotionFormula formula1 = new PromotionFormula();
formula1.setPromotion(OrderConstant.GOODS_PRICE);
formula1.setPromotionAmount(OrderConstant.MONEY_SIGN + skup.getGoodsPrice());
PaymentResponse.PromotionFormula formula2 = new PaymentResponse.PromotionFormula();
PromotionFormula formula2 = new PromotionFormula();
formula2.setPromotion(OrderConstant.DELIVERY_DESC);
formula2.setPromotionAmount(OrderConstant.PLUS_SIGN + OrderConstant.MONEY_SIGN + delivery_way_sf_cost);
PaymentResponse.PromotionFormula formula3 = new PaymentResponse.PromotionFormula();
PromotionFormula formula3 = new PromotionFormula();
formula3.setPromotion(OrderConstant.GOODS_REAL_PRICE);
BigDecimal amount = BigDecimalHelper.halfUp(skup.getGoodsPrice().add(new BigDecimal(delivery_way_sf_cost)));
formula3.setPromotionAmount(OrderConstant.MONEY_SIGN + amount);
... ...
package com.yohoufo.order.utils;
import com.google.common.collect.Lists;
import org.apache.commons.lang3.StringUtils;
import java.util.List;
/**
* Created by jiexiang.wu on 2018/11/19.
*/
public class CouponCodeUtils {
public final static String SPLIT_TOKEN = ",";
public static List<String> asList(String couponCode) {
if (StringUtils.isEmpty(couponCode)) {
return Lists.newArrayList();
}
return Lists.newArrayList(couponCode.split(SPLIT_TOKEN));
}
public static String asString(List<String> list) {
return StringUtils.join(list, SPLIT_TOKEN);
}
}
... ...