Authored by mali

Merge branch 'test6.9.0' into gray

Showing 27 changed files with 420 additions and 96 deletions
... ... @@ -23,6 +23,13 @@ public class InviteSettlement {
private Integer settleTime;
// bankcard
private String name;
private String idCardNo;
private String bankName;
private String bankBranch;
private String bankCardNo;
private Integer paidTime;
private Integer status;
... ...
... ... @@ -7,18 +7,28 @@
<result column="settle_code" property="settleCode" jdbcType="INTEGER" />
<result column="settle_amount" property="settleAmount" jdbcType="DECIMAL" />
<result column="settle_time" property="settleTime" jdbcType="INTEGER" />
<result column="name" property="name" jdbcType="VARCHAR" />
<result column="id_card_no" property="idCardNo" jdbcType="VARCHAR" />
<result column="bank_name" property="bankName" jdbcType="VARCHAR" />
<result column="bank_branch" property="bankBranch" jdbcType="VARCHAR" />
<result column="bank_card_no" property="bankCardNo" jdbcType="VARCHAR" />
<result column="paid_time" property="paidTime" jdbcType="INTEGER" />
<result column="status" property="status" jdbcType="INTEGER" />
<result column="create_time" property="createTime" jdbcType="INTEGER" />
</resultMap>
<sql id="Base_Column_List" >
id, uid, settle_code, settle_amount, settle_time,paid_time, status, create_time
id, uid, settle_code, settle_amount, settle_time, name, id_card_no, bank_name, bank_branch, bank_card_no, paid_time, status, create_time
</sql>
<insert id="insert" parameterType="com.yohoufo.dal.order.model.InviteSettlement" useGeneratedKeys="true" keyProperty="id">
insert into invite_settlement (id, uid, settle_code, settle_amount, settle_time, status, create_time)
values (#{id,jdbcType=INTEGER}, #{uid,jdbcType=INTEGER}, #{settleCode,jdbcType=DECIMAL}, #{settleAmount,jdbcType=DECIMAL},
#{settleTime,jdbcType=INTEGER}, #{status,jdbcType=INTEGER}, #{createTime,jdbcType=INTEGER})
insert into invite_settlement (id, uid,
settle_code, settle_amount, settle_time,
name, id_card_no, bank_name, bank_branch, bank_card_no,
status, create_time)
values (#{id,jdbcType=INTEGER}, #{uid,jdbcType=INTEGER},
#{settleCode,jdbcType=DECIMAL}, #{settleAmount,jdbcType=DECIMAL}, #{settleTime,jdbcType=INTEGER},
#{name,jdbcType=VARCHAR},#{idCardNo,jdbcType=VARCHAR},#{bankName,jdbcType=VARCHAR},#{bankBranch,jdbcType=VARCHAR},#{bankCardNo,jdbcType=VARCHAR},
#{status,jdbcType=INTEGER}, #{createTime,jdbcType=INTEGER})
</insert>
<update id="updateByUidAndId" parameterType="com.yohoufo.dal.order.model.InviteSettlement" >
... ...
... ... @@ -3,11 +3,11 @@ package com.yohoufo.order.charge;
import com.yoho.core.common.utils.YHMath;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yohobuy.ufo.model.order.constants.OrderConstant;
import com.yohobuy.ufo.model.promotion.UserCouponsBo;
import com.yohoufo.order.charge.coupon.CouponService;
import com.yohoufo.order.charge.model.*;
import com.yohoufo.order.constants.CouponConstants;
import com.yohoufo.order.service.support.DeliveryWayCostSupport;
import com.yohoufo.order.service.proxy.CouponProxyService;
import com.yohoufo.order.service.support.ShoppingSupport;
import com.yohoufo.order.utils.LoggerUtils;
import org.apache.commons.collections.CollectionUtils;
... ... @@ -16,6 +16,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
... ... @@ -27,17 +28,14 @@ public class ChargeService {
private final Logger logger = LoggerUtils.getBuyerOrderLogger();
@Autowired
private CouponProxyService couponProxyService;
@Autowired
private CouponRuleMatcher couponRuleMatcher;
@Autowired
private DeliveryWayCostSupport deliveryWayCostSupport;
@Autowired
private ShoppingSupport shoppingSupport;
@Autowired
private CouponService couponService;
/**
* 算费
... ... @@ -120,11 +118,49 @@ public class ChargeService {
* @param chargeContext
*/
private void calculateCouponIfNeed(ChargeContext chargeContext) {
if (CollectionUtils.isEmpty(chargeContext.getChargeParam().getCouponCodes())) {
List<String> couponCodes = chargeContext.getChargeParam().getCouponCodes();
if (CollectionUtils.isEmpty(couponCodes)) {
return;
}
if (couponCodes.contains(CouponConstants.AUTO_RECOMMENDED_COUPON_CODE)) {
//自动匹配
calculateRecommendedCoupons(chargeContext);
} else {
calculateSpecifiedCoupons(chargeContext);
}
}
/**
* 推荐券
*
* @param chargeContext
*/
private void calculateRecommendedCoupons(ChargeContext chargeContext) {
List<CouponMatchResult> usableCouponMatchResults = couponService.getRecommendedCoupons(chargeContext);
if (Objects.isNull(usableCouponMatchResults)) {
//获取券列表发生异常了
logger.warn("[{}] step recommended coupon charge,usable coupon count is null", chargeContext.getChargeParam().getUid());
return;
}
ChargeResult chargeResult = chargeContext.getChargeResult();
//只统计可用券的数量,不自动使用
RecommendedCouponPayResult recommendedCouponPayResult = new RecommendedCouponPayResult(null,
null,0,0,usableCouponMatchResults.size());
chargeResult.setCouponPayResult(recommendedCouponPayResult);
logger.info("[{}] step recommended coupon charge,newFinalAmount:{},couponPayResult:{}",
chargeContext.getChargeParam().getUid(), chargeResult.getFinalAmount(), chargeResult.getCouponPayResult());
}
/**
* 使用指定券
* @param chargeContext
*/
private void calculateSpecifiedCoupons(ChargeContext chargeContext) {
/**
* 目前只能使用一个券
*/
... ... @@ -132,6 +168,8 @@ public class ChargeService {
//券金额 取最小
double couponPayAmount = Math.min(chargeContext.getChargeGoods().getGoodsAmount().doubleValue(), userCouponsBo.getCouponAmount().doubleValue());
ChargeResult chargeResult = chargeContext.getChargeResult();
double oldFinalAmount = chargeResult.getFinalAmount();
double newFinalAmount = YHMath.sub(oldFinalAmount, couponPayAmount);
chargeResult.setFinalAmount(newFinalAmount);
... ... @@ -142,27 +180,19 @@ public class ChargeService {
chargeResult.setCouponPayResult(couponPayResult);
logger.info("[{}] step coupon charge,oldFinalAmount:{},newFinalAmount:{},couponPayResult:{}",
chargeContext.getChargeParam().getUid(),
couponPayAmount, oldFinalAmount, chargeResult.getFinalAmount(), chargeResult.getCouponPayResult());
chargeContext.getChargeParam().getUid(), oldFinalAmount, chargeResult.getFinalAmount(), chargeResult.getCouponPayResult());
}
private UserCouponsBo getOneUsableUserCouponBo(ChargeContext chargeContext) {
ChargeParam chargeParam = chargeContext.getChargeParam();
List<UserCouponsBo> couponsBos = couponProxyService.checkAndGetCoupons(chargeParam.getUid(), chargeParam.getCouponCodes());
if (CollectionUtils.isEmpty(couponsBos)) {
logger.info("[{}] not find any coupons by couponCodes:{}", chargeParam.getUid(), chargeParam.getCouponCodes());
throw new ServiceException(ServiceError.PROMOTION_COUPON_IS_NOT_VAILD);
}
//对券规则进行匹配
List<CouponMatchResult> couponMatchResults = couponRuleMatcher.match(couponsBos, chargeContext);
//找到可用的券
List<UserCouponsBo> usableCoupons = couponMatchResults.stream().filter(result -> result.isUsable()).map(result -> result.getUserCouponsBo()).collect(Collectors.toList());
List<CouponMatchResult> usableCouponMatchResults = couponService.getSpecifiedCoupons(chargeContext);
List<UserCouponsBo> usableCoupons = usableCouponMatchResults.stream().map(result -> result.getUserCouponsBo()).collect(Collectors.toList());
//当前只有使用一张券
if (CollectionUtils.isEmpty(usableCoupons) || usableCoupons.size() != 1) {
logger.info("[{}] get coupons by couponCodes:{} is invalid", chargeParam.getUid(), chargeParam.getCouponCodes());
logger.info("[{}] get coupons by couponCodes:{} is invalid", chargeContext.getChargeParam().getUid(), chargeContext.getChargeParam().getCouponCodes());
throw new ServiceException(ServiceError.PROMOTION_COUPON_IS_NOT_VAILD);
}
... ...
package com.yohoufo.order.charge.coupon;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yohobuy.ufo.model.promotion.UserCouponsBo;
import com.yohoufo.order.charge.ChargeContext;
import com.yohoufo.order.charge.CouponRuleMatcher;
import com.yohoufo.order.charge.model.ChargeParam;
import com.yohoufo.order.charge.model.CouponMatchResult;
import com.yohoufo.order.service.proxy.CouponProxyService;
import com.yohoufo.order.utils.LoggerUtils;
import org.apache.commons.collections.CollectionUtils;
import org.apache.zookeeper.Op;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
/**
* Created by jiexiang.wu on 2019/4/2.
* 优惠券服务
* @implNote
* 返回都是可用的优惠券
*/
@Component
public class CouponService {
private final Logger logger = LoggerUtils.getBuyerOrderLogger();
@Autowired
private CouponProxyService couponProxyService;
@Autowired
private CouponRuleMatcher couponRuleMatcher;
/**
* 返回推荐券数量,为了不影响结算,异常时返回null
*
* @param chargeContext
* @return
*/
public List<CouponMatchResult> getRecommendedCoupons(ChargeContext chargeContext) {
ChargeParam chargeParam = chargeContext.getChargeParam();
Optional<List<UserCouponsBo>> userCouponsBos = couponProxyService.getUserAvailableCouponsWhenExceptionHappenedReturnNull(chargeParam.getUid());
return userCouponsBos.isPresent() ? matchAndGetUsableCoupons(userCouponsBos.get(), chargeContext) : null;
}
/** 返回可用券
* @param chargeContext
* @return
*/
public List<CouponMatchResult> getUsableCoupons(ChargeContext chargeContext) {
//查询用户可用的优惠券
List<UserCouponsBo> userCouponsBos = couponProxyService.getUserAvailableCoupons(chargeContext.getChargeParam().getUid());
return matchAndGetUsableCoupons(userCouponsBos, chargeContext);
}
/**
* 通过券Code找到券,再匹配特定的券
*
* @param chargeContext
* @return 可用券列表
* @throws ServiceException 当通过券code查询不到券信息
*/
public List<CouponMatchResult> getSpecifiedCoupons(ChargeContext chargeContext) {
ChargeParam chargeParam = chargeContext.getChargeParam();
List<UserCouponsBo> couponsBos = couponProxyService.checkAndGetCoupons(chargeParam.getUid(), chargeParam.getCouponCodes());
if (CollectionUtils.isEmpty(couponsBos)) {
logger.info("[{}] not find any coupons by couponCodes:{}", chargeParam.getUid(), chargeParam.getCouponCodes());
throw new ServiceException(ServiceError.PROMOTION_COUPON_IS_NOT_VAILD);
}
return matchAndGetUsableCoupons(couponsBos, chargeContext);
}
/**
* 券处理并过滤出可用的优惠券
*
* @param userCouponsBos
* @param chargeContext
* @return 可用券列表
*/
private List<CouponMatchResult> matchAndGetUsableCoupons(List<UserCouponsBo> userCouponsBos, ChargeContext chargeContext) {
//规则匹配
List<CouponMatchResult> matchResults = couponRuleMatcher.match(userCouponsBos, chargeContext);
//返回可用优惠券列表
return matchResults.stream().filter(result -> result.isUsable()).collect(Collectors.toList());
}
}
... ...
... ... @@ -33,7 +33,7 @@ public class CouponPayResult {
private double couponAmount = 0;
/**
* 券数量
* 使用券数量
*/
private int couponCount = 0;
... ...
package com.yohoufo.order.charge.model;
import lombok.Data;
import lombok.ToString;
/**
* Created by jiexiang.wu on 2019/4/2.
* 推荐券支付结果,只能在结算时使用,其他时候请使用CouponPayResult
*/
@Data
@ToString
public class RecommendedCouponPayResult extends CouponPayResult {
//可用券张数
private int usableCouponCount;
public RecommendedCouponPayResult(String couponCode, String couponTitle, double couponAmount, int couponCount, int usableCouponCount) {
super(couponCode, couponTitle, couponAmount, couponCount);
this.usableCouponCount = usableCouponCount;
}
}
\ No newline at end of file
... ...
package com.yohoufo.order.common;
public enum InviterStatus {
public enum InviterStatus {
VALID(1),
INVALID(2);
... ...
package com.yohoufo.order.constants;
import com.google.common.collect.Lists;
import java.util.List;
/**
* Created by jiexiang.wu on 2019/4/2.
* 券常量
*/
public class CouponConstants {
//自动推荐的券code
public static final String AUTO_RECOMMENDED_COUPON_CODE = "AUTO";
//自动推荐的券code列表
public static final List<String> AUTO_RECOMMENDED_COUPON_CODES = Lists.newArrayList(CouponConstants.AUTO_RECOMMENDED_COUPON_CODE);
}
... ...
package com.yohoufo.order.controller;
import com.google.common.collect.Maps;
import com.yoho.core.rest.client.ServiceCaller;
import com.yoho.error.exception.ServiceException;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.order.service.proxy.BankCardService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
... ... @@ -13,7 +12,6 @@ import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
import java.util.concurrent.TimeUnit;
/**
* @author LUOXC
... ... @@ -21,10 +19,10 @@ import java.util.concurrent.TimeUnit;
*/
@Slf4j
@RestController
public class BankcardController {
public class BankCardController {
@Autowired
ServiceCaller serviceCaller;
BankCardService bankCardService;
@Value("${erp-gateway.url}")
private String erpGatewayUrl;
... ... @@ -35,7 +33,7 @@ public class BankcardController {
String url = erpGatewayUrl + "/erp/union/bankcard/getBankCard";
Map<String, Object> params = Maps.newHashMap();
params.put("uid", uid);
return proxyGet("ufo.bankcard.getBankCard", url, params);
return bankCardService.proxyGet("ufo.bankcard.getBankCard", url, params);
}
@RequestMapping(params = "method=ufo.bankcard.getBankList")
... ... @@ -45,7 +43,7 @@ public class BankcardController {
String url = erpGatewayUrl + "/erp/union/bankcard/getBankList";
Map<String, Object> params = Maps.newHashMap();
params.put("uid", uid);
return proxyGet("ufo.bankcard.getBankList", url, params);
return bankCardService.proxyGet("ufo.bankcard.getBankList", url, params);
}
/**
... ... @@ -71,7 +69,7 @@ public class BankcardController {
params.put("bankCardNo", bankCardNo);
params.put("bankBranch", bankBranch);
params.put("bankCode", bankCode);
return proxyPost("ufo.bankcard.bindBankCard", url, params);
return bankCardService.proxyPost("ufo.bankcard.bindBankCard", url, params);
}
/**
... ... @@ -97,30 +95,7 @@ public class BankcardController {
params.put("bankCardNo", bankCardNo);
params.put("bankBranch", bankBranch);
params.put("bankCode", bankCode);
return proxyPost("ufo.bankcard.checkBankCard", url, params);
}
private ApiResponse proxyGet(String serviceName, String url, Map<String, Object> params) {
return proxyCall(serviceName, url, params);
}
private ApiResponse proxyPost(String serviceName, String url, Map<String, Object> params) {
return proxyCall(serviceName, url, params);
}
private ApiResponse proxyCall(String serviceName, String url, Map<String, Object> params) {
try {
// 接口调用者:1 UFO, 0 CPS
params.put("source", 1);
ApiResponse response = serviceCaller.get(serviceName, url, params, ApiResponse.class, null).get(500, TimeUnit.MILLISECONDS);
return response;
} catch (ServiceException e) {
throw e;
} catch (Exception e) {
log.warn("bank card service call fail, url is {} params is {}", url, params, e);
return new ApiResponse.ApiResponseBuilder().code(500).message("服务访问异常").build();
}
return bankCardService.proxyPost("ufo.bankcard.checkBankCard", url, params);
}
}
... ...
... ... @@ -11,6 +11,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.Objects;
import java.util.List;
/**
... ... @@ -55,8 +57,12 @@ public class InviteSettlementController {
}
@RequestMapping(value = "/erp/invite/settlement/help/settle")
public ApiResponse settle() {
inviteSettlementService.settle();
public ApiResponse settle(@RequestParam(value = "uid", required = false) Integer uid) {
if (Objects.nonNull(uid)) {
inviteSettlementService.settle(uid);
} else {
inviteSettlementService.settle();
}
return new ApiResponse.ApiResponseBuilder().code(200).message("ok").build();
}
... ...
... ... @@ -2,6 +2,7 @@ package com.yohoufo.order.controller;
import com.google.common.collect.Lists;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.order.constants.CouponConstants;
import com.yohoufo.order.model.request.ShoppingRequest;
import com.yohoufo.order.model.response.*;
import com.yohoufo.order.service.IBuyerOrderService;
... ... @@ -39,7 +40,9 @@ public class ShoppingController {
@RequestMapping(params = "method=ufo.order.payment")
public ApiResponse payment(@RequestParam(name = "uid") int uid,
@RequestParam(name = "skup") int skup){
ShoppingRequest req = ShoppingRequest.builder().uid(uid).skup(skup).build();
//AUTO 自动匹配
ShoppingRequest req = ShoppingRequest.builder().uid(uid).skup(skup)
.couponCodes(CouponConstants.AUTO_RECOMMENDED_COUPON_CODES).build();
logger.info("in ufo.order.payment, req {}", req);
PaymentResponse paymentResponse = buyerOrderService.payment(req);
return new ApiResponse.ApiResponseBuilder().code(200).data(paymentResponse).message("结算成功").build();
... ...
package com.yohoufo.order.model.bo;
import lombok.Data;
/**
* @author LUOXC
* @date 2019/4/8 11:22
*/
@Data
public class BankCard {
private String name;
private String idCardNo;
private String bankName;
private String bankBranch;
private String bankCardNo;
}
... ...
... ... @@ -36,6 +36,11 @@ public class PaymentResponse {
*/
String damagesDesc;
/**
* 推荐的优惠券信息,为null表示没有获取到券信息
*/
RecommendedCouponInfo recommendedCouponInfo;
@Data
@ToString
public static class PaymentWay{
... ...
package com.yohoufo.order.model.response;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;
import lombok.ToString;
import lombok.experimental.Builder;
/**
* Created by jiexiang.wu on 2019/4/2.
* 结算时推荐券信息
*/
@Data
@ToString
@Builder
public class RecommendedCouponInfo {
//可用券张数
@JSONField(name = "usable_coupon_count")
private int usableCouponCount;
}
... ...
... ... @@ -34,5 +34,4 @@ public interface IInviteSettlementService {
* @param buyerOrderCode
*/
void createInviteSettlementItem(Long buyerOrderCode, Integer status);
}
... ...
... ... @@ -13,8 +13,8 @@ import com.yohoufo.order.common.Payment;
import com.yohoufo.order.constants.InviteConstant;
import com.yohoufo.order.model.request.InviteSettlementItemCreateRequest;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
... ...
... ... @@ -217,4 +217,4 @@ public class InviteSettlementServiceImpl implements IInviteSettlementService {
inviteSettlementItemCreator.createInviteSettlementItem(buyerOrderCode, status);
}
}
}
\ No newline at end of file
... ...
... ... @@ -12,6 +12,8 @@ import com.yohoufo.dal.order.model.InviteRecord;
import com.yohoufo.dal.order.model.InviteSettlement;
import com.yohoufo.dal.order.model.InviteSettlementItem;
import com.yohoufo.dal.order.model.InviteSettlementItemStats;
import com.yohoufo.order.model.bo.BankCard;
import com.yohoufo.order.service.proxy.BankCardService;
import com.yohoufo.order.utils.IdUtils;
import com.yohoufo.order.utils.InviteSettlementUtils;
import lombok.extern.slf4j.Slf4j;
... ... @@ -43,6 +45,9 @@ public class InviterSettleService {
private InviteSettlementItemMapper inviteSettlementItemMapper;
@Autowired
private BankCardService bankCardService;
@Autowired
private InviteRecordMapper inviteRecordMapper;
public void settle(int uid) {
... ... @@ -54,6 +59,11 @@ public class InviterSettleService {
log.info("settle for {} end it has no item to settle.", uid);
return;
}
BankCard bankCard = bankCardService.getBankCard(uid);
if (Objects.isNull(bankCard)) {
log.warn("settle for {} end bank card is null.", uid);
return;
}
// 新建结算单
log.info("settle for {} create a new settlement.", uid);
InviteSettlement settlement = new InviteSettlement();
... ... @@ -62,6 +72,11 @@ public class InviterSettleService {
settlement.setSettleCode(0);
settlement.setSettleAmount(BigDecimal.ZERO);
settlement.setSettleTime(0);
settlement.setName(bankCard.getName());
settlement.setIdCardNo(bankCard.getIdCardNo());
settlement.setBankName(bankCard.getBankName());
settlement.setBankBranch(bankCard.getBankBranch());
settlement.setBankCardNo(bankCard.getBankCardNo());
settlement.setStatus(InviteSettlement.STATUS_WAIT_SETTLE);
inviteSettlementMapper.insert(settlement);
// 计算结算金额
... ...
package com.yohoufo.order.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
... ... @@ -345,16 +346,16 @@ public class SellerOrderDetailService extends AbsOrderDetailService implements I
BigDecimal prdPrice = goodsInfo.getPrice();
final String defaultResult = "";
BigDecimal maxSuggestPrice = goodsInfo.getSuggestMaxPrice();
logger.info("in buildOverPriceTips, prdPrice {}, storageId {} maxSuggestPrice {} prdPrice {}",
prdPrice, storageId, maxSuggestPrice, prdPrice);
logger.info("in buildOverPriceTips, prdPrice {}, storageId {} maxSuggestPrice {} appVersion {},goodsInfo {}",
prdPrice, storageId, maxSuggestPrice, appVersion, JSON.toJSONString(goodsInfo));
boolean isOverflow = SellerGoodsHelper.isOverSuggestMaxPrice(maxSuggestPrice, prdPrice);
if (isOverflow){
return OrderConstant.Tips.SUGGEST_MAX_PRICE_OVERFLOW;
}else{
BigDecimal leastPrice = goodsInfo.getLeastPrice();
if(leastPrice!=null && leastPrice.compareTo(goodsInfo.getPrice())<0){
logger.info("in buildOverPriceTips with color judge appVersion {} prdPrice {}, storageId {} maxSuggestPrice {} prdPrice {}",appVersion,
prdPrice, storageId, maxSuggestPrice, prdPrice);
logger.info("in buildOverPriceTips with color judge appVersion {} prdPrice {}, storageId {} maxSuggestPrice {} leastPrice {}",appVersion,
prdPrice, storageId, maxSuggestPrice, leastPrice);
String tmpTip = sellerOrderViewService.buildOtherLowerPriceTips(leastPrice);
if(StringUtils.isNotBlank(appVersion) && appVersion.compareTo("6.8.9") >=0){
return MsgHelper.FLAG_PRE+tmpTip+MsgHelper.FLAG_SUFFIX;
... ... @@ -405,6 +406,8 @@ public class SellerOrderDetailService extends AbsOrderDetailService implements I
}
private void resetPriceOfProduct(GoodsInfo goodsInfo, int skupStatus, SkupType skupType){
logger.info("in resetPriceOfProduct, skupStatus {}, skupType {} ,old goodsInfo {}",
skupStatus, skupType, JSON.toJSONString(goodsInfo));
if(SkupStatus.CAN_SELL.getCode() == skupStatus){
PrdPrice prdPrice = sellerOrderViewService.getPrdPrice(goodsInfo.getStorageId());
BigDecimal leastPrice;
... ... @@ -414,6 +417,8 @@ public class SellerOrderDetailService extends AbsOrderDetailService implements I
goodsInfo.setSuggestMaxPrice(prdPrice.getSuggestMaxPrice());
goodsInfo.setLeastPriceOfSkuTips(sellerOrderViewService.buildLeastPriceTips(leastPrice));
}
logger.info("in resetPriceOfProduct after reset, leastPrice {},new goodsInfo {}",
leastPrice, JSON.toJSONString(goodsInfo));
}
}
... ...
... ... @@ -6,8 +6,6 @@ import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yohobuy.ufo.model.order.common.OrderAttributes;
import com.yohobuy.ufo.model.order.constants.ChangePriceStatus;
import com.yohobuy.ufo.model.order.constants.SkupType;
import com.yohobuy.ufo.model.promotion.UserCouponsBo;
import com.yohoufo.common.alarm.EventBusPublisher;
import com.yohoufo.common.exception.UfoServiceException;
import com.yohoufo.common.utils.AddressUtil;
... ... @@ -23,7 +21,7 @@ import com.yohobuy.ufo.model.order.common.TabType;
import com.yohobuy.ufo.model.order.constants.OrderConstant;
import com.yohoufo.order.charge.ChargeContext;
import com.yohoufo.order.charge.ChargeService;
import com.yohoufo.order.charge.CouponRuleMatcher;
import com.yohoufo.order.charge.coupon.CouponService;
import com.yohoufo.order.charge.model.ChargeGoods;
import com.yohoufo.order.charge.model.ChargeParam;
import com.yohoufo.order.charge.model.ChargeResult;
... ... @@ -41,7 +39,6 @@ import com.yohoufo.order.service.ISubmitOrderService;
import com.yohoufo.order.service.IShoppingService;
import com.yohoufo.order.service.cache.CacheCleaner;
import com.yohoufo.order.service.cache.CacheKeyBuilder;
import com.yohoufo.order.service.proxy.CouponProxyService;
import com.yohoufo.order.service.proxy.InBoxFacade;
import com.yohoufo.order.service.proxy.UserProxyService;
import com.yohoufo.order.service.support.CouponSupport;
... ... @@ -99,12 +96,6 @@ public class ShoppingServiceImpl implements IShoppingService {
private ChargeService chargeService;
@Autowired
private CouponProxyService couponProxyService;
@Autowired
private CouponRuleMatcher couponRuleMatcher;
@Autowired
private CouponSupport couponSupport;
@Autowired
... ... @@ -112,6 +103,9 @@ public class ShoppingServiceImpl implements IShoppingService {
@Autowired
private SellerOrderMapper sellerOrderMapper;
@Autowired
private CouponService couponService;
/**
* 结算页数据
* @param request
... ... @@ -139,7 +133,7 @@ public class ShoppingServiceImpl implements IShoppingService {
PaymentResponse response = new PaymentResponse();
response.setPaymentWay(shoppingSupport.getPaymentWay());
response.setDeliveryWay(shoppingSupport.getDeliverWay(chargeContext.getChargeResult()));
response.setDeliveryWay(shoppingSupport.getDeliverWay(chargeResult));
response.setGood(shoppingSupport.getGoodsInfo(skupGood));
response.setPromotionFormulaList(shoppingSupport.getPromotionFormula(chargeResult));
response.setAmount(MathUtils.formatStr(chargeResult.getFinalAmount()));
... ... @@ -148,6 +142,9 @@ public class ShoppingServiceImpl implements IShoppingService {
//赔偿金计算
response.setDamagesDesc(shoppingSupport.getDamagesDesc(ompensate));
//推荐券(可用券个数)
response.setRecommendedCouponInfo(shoppingSupport.getRecommendedCouponInfo(chargeResult));
return response;
}
... ... @@ -205,14 +202,10 @@ public class ShoppingServiceImpl implements IShoppingService {
//构建算费
ChargeContext chargeContext = buildChargeContext(request, skupGood);
//查询用户可用的优惠券
List<UserCouponsBo> userCouponsBos = couponProxyService.getUserAvailableCoupons(chargeContext.getChargeParam().getUid());
//进行券匹配
List<CouponMatchResult> couponMatchResults = couponRuleMatcher.match(userCouponsBos,chargeContext);
List<CouponMatchResult> usableCouponMatchResults = couponService.getUsableCoupons(chargeContext);
//满足当前商品的优惠券
List<ShoppingCoupon> usableCoupons = couponSupport.filterUsableCoupons(couponMatchResults);
List<ShoppingCoupon> usableCoupons = couponSupport.convert(usableCouponMatchResults);
//券选中
usableCoupons.forEach(shoppingCoupon -> {
... ...
package com.yohoufo.order.service.proxy;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Maps;
import com.yoho.core.rest.client.ServiceCaller;
import com.yoho.error.exception.ServiceException;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.order.model.bo.BankCard;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
/**
* @author LUOXC
* @date 2019/4/8 11:21
*/
@Slf4j
@Service
public class BankCardService {
@Autowired
ServiceCaller serviceCaller;
@Value("${erp-gateway.url}")
private String erpGatewayUrl;
public BankCard getBankCard(int uid) {
log.info("get bank card, uid is {}", uid);
String url = erpGatewayUrl + "/erp/union/bankcard/getBankCardUfo";
Map<String, Object> params = Maps.newHashMap();
params.put("uid", uid);
ApiResponse response = proxyGet("ufo.bankcard.getBankCardUfo", url, params);
if (response.getCode() != 200) {
return null;
}
if (Objects.isNull(response.getData())) {
return null;
}
if (response.getData() instanceof JSONObject) {
return ((JSONObject) response.getData()).toJavaObject(BankCard.class);
} else {
return JSONObject.parseObject(JSONObject.toJSONString(response.getData()), BankCard.class);
}
}
public ApiResponse proxyGet(String serviceName, String url, Map<String, Object> params) {
return proxyCall(serviceName, url, params);
}
public ApiResponse proxyPost(String serviceName, String url, Map<String, Object> params) {
return proxyCall(serviceName, url, params);
}
private ApiResponse proxyCall(String serviceName, String url, Map<String, Object> params) {
try {
// 接口调用者:1 UFO, 0 CPS
params.put("source", 1);
ApiResponse response = serviceCaller.get(serviceName, url, params, ApiResponse.class, null).get(500, TimeUnit.MILLISECONDS);
return response;
} catch (ServiceException e) {
throw e;
} catch (Exception e) {
log.warn("bank card service call fail, url is {} params is {}", url, params, e);
return new ApiResponse.ApiResponseBuilder().code(500).message("服务访问异常").build();
}
}
}
... ...
... ... @@ -21,6 +21,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
/**
... ... @@ -31,6 +32,16 @@ public class CouponProxyService extends AbsProxyService implements Compensator {
private final static Logger logger = LoggerUtils.getBuyerOrderLogger();
public Optional<List<UserCouponsBo>> getUserAvailableCouponsWhenExceptionHappenedReturnNull(int uid) {
try {
List<UserCouponsBo> userCouponsBos = getUserAvailableCoupons(uid);
return Optional.ofNullable(userCouponsBos);
} catch (Throwable t) {
logger.error("getUserAvailableCouponsWhenExceptionHappenedReturnNull error,uid:{}", uid, t);
return Optional.ofNullable(null);
}
}
/**
* 查询用户可以使用的券
*
... ...
package com.yohoufo.order.service.proxy;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Maps;
... ... @@ -7,6 +8,7 @@ import com.yoho.core.rest.client.ServiceCaller;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yoho.service.model.request.UserAddressReqBO;
import com.yoho.service.model.social.request.UicUserReqBO;
import com.yoho.service.model.social.response.UserInfoRspBO;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.order.convert.AddressInfoConvertor;
... ...
... ... @@ -22,12 +22,12 @@ import java.util.stream.Collectors;
@Component
public class CouponSupport {
public List<ShoppingCoupon> filterUsableCoupons(List<CouponMatchResult> couponMatchResults) {
if (CollectionUtils.isEmpty(couponMatchResults)) {
public List<ShoppingCoupon> convert(List<CouponMatchResult> usableCouponMatchResults) {
if (CollectionUtils.isEmpty(usableCouponMatchResults)) {
return Lists.newArrayList();
}
//找到可用的券
List<UserCouponsBo> usableCoupons = couponMatchResults.stream().filter(result -> result.isUsable()).map(result -> result.getUserCouponsBo()).collect(Collectors.toList());
List<UserCouponsBo> usableCoupons = usableCouponMatchResults.stream().map(result -> result.getUserCouponsBo()).collect(Collectors.toList());
if (CollectionUtils.isEmpty(usableCoupons)) {
return Lists.newArrayList();
... ...
... ... @@ -5,20 +5,18 @@ import com.yohobuy.ufo.model.order.constants.OrderDetailDesc;
import com.yohoufo.common.helper.ImageUrlAssist;
import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohobuy.ufo.model.order.constants.OrderConstant;
import com.yohoufo.order.charge.ChargeContext;
import com.yohoufo.order.charge.model.ChargeResult;
import com.yohoufo.order.charge.model.CouponPayResult;
import com.yohoufo.order.charge.model.RecommendedCouponPayResult;
import com.yohoufo.order.model.response.GoodsInfo;
import com.yohoufo.order.model.response.PaymentResponse;
import com.yohoufo.order.model.response.PromotionFormula;
import com.yohoufo.order.model.response.RecommendedCouponInfo;
import com.yohoufo.order.utils.MathUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.List;
import java.util.function.Supplier;
@Service
public class ShoppingSupport {
... ... @@ -143,4 +141,19 @@ public class ShoppingSupport {
return String.format(damagesDesc, damagedPrice.toPlainString());
}
/**
* 券自动推荐结果
* @param chargeResult
* @return
*/
public RecommendedCouponInfo getRecommendedCouponInfo(ChargeResult chargeResult) {
CouponPayResult couponPayResult = chargeResult.getCouponPayResult();
if (couponPayResult instanceof RecommendedCouponPayResult) {
RecommendedCouponPayResult recommendedCouponPayResult = (RecommendedCouponPayResult) couponPayResult;
return RecommendedCouponInfo.builder().usableCouponCount(recommendedCouponPayResult.getUsableCouponCount()).build();
} else {
return null;
}
}
}
... ...
... ... @@ -121,7 +121,11 @@ public class ProductIdentifyController {
@RequestParam(value = "nfcUid",required = false) String nfcUid,
@RequestParam(value = "uid", required = true) Integer uid) throws GatewayException {
try{
logger.info("method applyToBeOwner begin! tagId={}, nfcUid={}, uid={}", tagId, nfcUid, uid);
int result = identifyService.applyToBeOwner(tagId, nfcUid, uid);
logger.info("method applyToBeOwner end! tagId={}, nfcUid={}, uid={}", tagId, nfcUid, uid);
return new ApiResponse.ApiResponseBuilder().code(200).data(result).build();
}catch (Exception e){
logger.warn("applyToBeOwner error! tagId={}, nfcUid={}, uid={}, e is {}", tagId, nfcUid, uid, e);
... ... @@ -150,7 +154,11 @@ public class ProductIdentifyController {
@RequestParam(value = "status", required = true) Integer status,
@RequestParam(value = "inbox_id", required = true) Integer inboxId) throws GatewayException {
try{
logger.info("method confirmTransferOwner begin! tagId={}, nfcUid={}, fromUid={}, toUid is{}, status is {}, inboxId is {}", tagId, nfcUid, fromUid, toUid, status, inboxId);
int result = identifyService.confirmOwner(tagId, nfcUid, fromUid, toUid, status, inboxId);
logger.info("method confirmTransferOwner end! tagId={}, nfcUid={}, fromUid={}, toUid is{}, status is {}, inboxId is {}", tagId, nfcUid, fromUid, toUid, status, inboxId);
return new ApiResponse.ApiResponseBuilder().code(200).data(result).build();
}catch (Exception e){
logger.warn("confirmTransferOwner error! tagId={}, nfcUid={}, fromUid={}, toUid is{}, e is {}", tagId, nfcUid, fromUid, toUid, e);
... ...
... ... @@ -117,4 +117,6 @@ offline.store.seller=${offline.store.seller}
ip.port.uic.server = ${ip.port.uic.server}
ufo.nfc.syncBlockChain.url=${ufo.nfc.syncBlockChain.url}
\ No newline at end of file
ufo.nfc.syncBlockChain.url=${ufo.nfc.syncBlockChain.url}
ufo.invite.productSortLimit=16,20,40
\ No newline at end of file
... ...