Authored by chenchao

add submit

... ... @@ -30,6 +30,8 @@ public interface SellerOrderMapper {
int updateByOrderCode(SellerOrder record);
int updateAmountByOrderCode(SellerOrder record);
int updateBySkups(@Param("condition") SellerOrder condition,@Param("skupList") Collection<Integer> skups);
List<SellerOrder> selectBySkups(@Param("skupList") Collection<Integer> skups);
... ...
package com.yohoufo.dal.order.model;
import com.alibaba.fastjson.JSONObject;
import lombok.Getter;
import lombok.Setter;
import java.math.BigDecimal;
... ... @@ -21,6 +23,8 @@ public class SellerOrder {
private BigDecimal earnestMoney;
@Getter@Setter
private BigDecimal couponCutAmount;
private Integer isDel;
... ...
... ... @@ -9,6 +9,7 @@
<result column="client_type" jdbcType="TINYINT" property="clientType" />
<result column="payment" jdbcType="TINYINT" property="payment" />
<result column="income" jdbcType="DECIMAL" property="income" />
<result column="coupon_cut_amount" property="couponCutAmount" jdbcType="DECIMAL"/>
<result column="earnest_money" jdbcType="DECIMAL" property="earnestMoney" />
<result column="is_del" jdbcType="TINYINT" property="isDel" />
<result column="status" jdbcType="TINYINT" property="status" />
... ... @@ -16,7 +17,7 @@
<result column="update_time" jdbcType="INTEGER" property="updateTime" />
</resultMap>
<sql id="Base_Column_List">
id, order_code, skup, uid, client_type, payment, income, earnest_money, is_del,
id, order_code, skup, uid, client_type, payment, income, earnest_money, coupon_cut_amount, is_del,
status, create_time, update_time
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
... ... @@ -271,6 +272,19 @@
</update>
<update id="updateAmountByOrderCode" parameterType="com.yohoufo.dal.order.model.SellerOrder">
update seller_order
<set>
income = #{income,jdbcType=DECIMAL},
<if test="couponCutAmount != null">
coupon_cut_amount = #{couponCutAmount,jdbcType=DECIMAL},
</if>
</set>
where uid = #{uid,jdbcType=INTEGER}
and order_code = #{orderCode,jdbcType=BIGINT}
</update>
<select id="selectOrderNumByUid" resultType="java.lang.Integer">
select count(*) from seller_order where uid = #{uid,jdbcType=INTEGER} and is_del = 1
and status in
... ...
... ... @@ -125,6 +125,12 @@ public final class SellerOrderConvertor {
String incomeStr = formatFee(income);
String earnestMoneyStr = formatFee(earnestMoney);
String bankTransferFeeStr = formatFee(computeResult.getBankTransferfee());
//
BigDecimal couponCutAmount = computeResult.getCouponCutAmount();
CouponInfo couponInfo = Objects.isNull(couponCutAmount) ? null
: CouponInfo.builder().couponAmountStr(formatFee(couponCutAmount)).build();
//
SoldPrdComputeBo computeBo = SoldPrdComputeBo.builder()
.earnestMoney(earnestMoney.doubleValue())
... ... @@ -132,6 +138,7 @@ public final class SellerOrderConvertor {
.platformFee(platformFeeWrapper)
.bankTransferFee(buildSubtractFee(bankTransferFeeStr))
.income(incomeStr)
.couponInfo(couponInfo)
.build();
return computeBo;
... ...
... ... @@ -17,6 +17,7 @@ import com.yohoufo.order.model.bo.CouponBo;
import com.yohoufo.order.model.bo.CouponBoList;
import com.yohoufo.order.model.dto.OrderBuilder;
import com.yohoufo.order.service.impl.ShoppingServiceImpl;
import com.yohoufo.order.service.support.CouponSupport;
import com.yohoufo.order.utils.OrderAssist;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
... ... @@ -51,7 +52,7 @@ public class OrderBuilderFactory {
.channelNo(channelNo)
.amount(BigDecimal.valueOf(chargeResult.getFinalAmount()))
.shipFee(BigDecimal.valueOf(chargeResult.getFinalShippingAmount()))
.couponBoList(buildOrderCouponBoList(chargeResult))
.couponBoList(CouponSupport.buildOrderCouponBoList(chargeResult.getCouponPayResultList()))
.hiddenAddressInfo(userAddressPair.getRight())
.addressInfo(userAddressPair.getLeft())
.clientType(clientType)
... ... @@ -95,23 +96,7 @@ public class OrderBuilderFactory {
.build();
}
/**
* 优惠券支付结果
*
* @param chargeResult
* @return
*/
protected CouponBoList buildOrderCouponBoList(ChargeResult chargeResult) {
return CouponBoList.builder().couponBos(chargeResult.getCouponPayResultList().getCouponPayResults().stream()
.map(couponPayResult -> CouponBo.builder()
.couponCode(couponPayResult.getCouponCode())
.couponType(couponPayResult.getCouponType())
.couponAmount(BigDecimal.valueOf(couponPayResult.getCouponAmount()))
.build()
)
.collect(Collectors.toList())
).build();
}
/**
* 订单金额明细
... ...
... ... @@ -2,9 +2,7 @@ package com.yohoufo.order.model.dto;
import com.alibaba.fastjson.annotation.JSONField;
import com.google.common.collect.Lists;
import com.yohobuy.ufo.model.order.bo.SellerCouponSimpleBo;
import com.yohobuy.ufo.model.order.dto.PlatformFeeDto;
import com.yohoufo.order.charge.model.ActivityCutResult;
import com.yohoufo.order.charge.model.CouponMatchResult;
import com.yohoufo.order.charge.model.CouponPayResultList;
import lombok.Data;
... ... @@ -44,6 +42,8 @@ public class SellerOrderComputeResult {
@JSONField(serialize = false, deserialize = false)
private transient CouponPayResultList couponPayResultList;
@JSONField(serialize = false, deserialize = false)
private transient boolean amountIsReset;
/**
* 支付的券是否是自动推优
*/
... ...
package com.yohoufo.order.model.dto;
import com.yohoufo.dal.order.model.SellerOrder;
import com.yohoufo.order.model.bo.CouponBoList;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Builder
@NoArgsConstructor@AllArgsConstructor
public class SellerOrderSubmitDTO {
private SellerOrder sellerOrder;
/**
* 使用的优惠券
*/
private CouponBoList couponBoList;
private SellerOrderComputeResult computeResult;
}
... ...
... ... @@ -11,6 +11,7 @@ import com.yohobuy.ufo.model.order.constants.DepotType;
import com.yohobuy.ufo.model.order.constants.OrderConstant;
import com.yohobuy.ufo.model.order.constants.OrderDetailDesc;
import com.yohobuy.ufo.model.order.constants.SkupType;
import com.yohobuy.ufo.model.order.resp.CouponInfo;
import com.yohobuy.ufo.model.order.resp.ExpressInfoDetail;
import com.yohobuy.ufo.model.order.vo.AddressInfo;
import com.yohoufo.common.config.SpecialTimeConfigReader;
... ... @@ -244,6 +245,8 @@ public class SellerOrderDetailService extends AbsOrderDetailService implements I
}
orderDetailInfo.setBankTransferFee(computeBo.getBankTransferFee());
orderDetailInfo.setPlatformFee(computeBo.getPlatformFee());
CouponInfo couponInfo;
orderDetailInfo.setCouponCutAmount(Objects.isNull(couponInfo = computeBo.getCouponInfo()) ? null : couponInfo.getCouponAmountStr());
orderDetailInfo.setIncome(computeBo.getIncome());
}
}
... ...
... ... @@ -26,6 +26,7 @@ import com.yohoufo.order.convert.SellerOrderConvertor;
import com.yohoufo.order.event.*;
import com.yohoufo.order.model.SellerOrderContext;
import com.yohoufo.order.model.SellerOrderRelatedBuyerOrderContext;
import com.yohoufo.order.model.bo.CouponBoList;
import com.yohoufo.order.model.dto.*;
import com.yohoufo.order.model.request.OrderListRequest;
import com.yohoufo.order.model.request.OrderRequest;
... ... @@ -53,6 +54,8 @@ import com.yohoufo.order.service.seller.orderMeta.SellerFeeService;
import com.yohoufo.order.service.seller.processor.*;
import com.yohoufo.order.service.seller.setting.SellerService;
import com.yohoufo.order.service.seller.setting.SellerWrapper;
import com.yohoufo.order.service.seller.trade.SellerOrderSubmitService;
import com.yohoufo.order.service.support.CouponSupport;
import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
import com.yohoufo.order.service.support.codegenerator.bean.CodeMeta;
import com.yohoufo.order.utils.LoggerUtils;
... ... @@ -177,6 +180,9 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServic
@Autowired
private BuyerOrderAssistant buyerOrderAssistant;
@Autowired
private SellerOrderSubmitService sellerOrderSubmitService;
private static final int MAX_DEAL = 10;
public SoldPrdComputeBo computePublishPrd(SellerOrderComputeReq req) {
... ... @@ -988,12 +994,35 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServic
public boolean submitWithCoupon(SellerOrderRelatedBuyerOrderContext sorboc){
public void submitWithCoupon(SellerOrderRelatedBuyerOrderContext sorboc){
SellerOrderChargeParam chargeParam = sorboc.getChargeParam();
chargeParam.setChargeStage(SellerOrderChargeParam.SUBMIT);
sellerOrderComputeService.compute(sorboc);
//TODO how to keep atomic,rollback when fail
//after compute, may be reset
SellerOrderComputeResult computeResult = sorboc.getSellerOrderComputeResult();
CouponBoList couponBoList = CouponSupport.buildOrderCouponBoList(computeResult.getCouponPayResultList());
SellerOrderGoods psog = sorboc.getSkupInfo();
SellerOrder sellerOrder = sellerOrderMapper.selectBySkup(psog.getId());
SellerOrderSubmitDTO submitDTO = SellerOrderSubmitDTO.builder()
.sellerOrder(sellerOrder)
.couponBoList(couponBoList)
.computeResult(computeResult)
.build();
sellerOrderSubmitService.submitByOld(submitDTO);
}
public void cancelWithCoupon(){
return false;
}
... ...
package com.yohoufo.order.service.seller;
import com.yoho.core.dal.datasource.annotation.Database;
import com.yohoufo.dal.order.SellerOrderMapper;
import com.yohoufo.dal.order.model.SellerOrder;
import com.yohoufo.order.model.dto.SellerOrderComputeResult;
import com.yohoufo.order.model.dto.SellerOrderSubmitDTO;
import com.yohoufo.order.service.seller.orderMeta.SellerOrderMetaService;
import com.yohoufo.order.utils.LoggerUtils;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
@Service
public class SellerOrderUpdateService {
private Logger logger = LoggerUtils.getSellerOrderLogger();
@Autowired
private SellerOrderMapper sellerOrderMapper;
@Autowired
private SellerOrderMetaService sellerOrderMetaService;
@Transactional(propagation = Propagation.REQUIRED)
@Database(ForceMaster=true, DataSource="ufo_order")
public boolean updateAmount(SellerOrderSubmitDTO submitDTO){
SellerOrder sellerOrder = submitDTO.getSellerOrder();
if (submitDTO.getCouponBoList().isNotEmpty()){
sellerOrderMetaService.saveUsedCoupons(sellerOrder.getSkup(), sellerOrder.getUid(), submitDTO.getCouponBoList().getCouponBos());
}
SellerOrderComputeResult computeResult = submitDTO.getComputeResult();
if (computeResult.isAmountIsReset()){
SellerOrder condition = new SellerOrder();
condition.setOrderCode(sellerOrder.getOrderCode());
condition.setUid(sellerOrder.getUid());
condition.setCouponCutAmount(computeResult.getCouponCutAmount());
condition.setIncome(computeResult.getIncome());
int updateOrderRusult = sellerOrderMapper.updateAmountByOrderCode(condition);
logger.info("SellerOrderUpdateService.updateAmount sellerOrderMapper.updateAmountByOrderCode condition {} result {}", condition, updateOrderRusult);
}
return true;
}
}
... ...
... ... @@ -97,7 +97,7 @@ public class SellerFeeService {
SellerOrderComputeResult computeResult = JSONObject.parseObject(meta.getMetaValue(), SellerOrderComputeResult.class);
return computeResult;
}catch (Exception ex){
logger.warn("in getSellerOrderComputeResult fail uid {}, skup {}", uid, skup);
logger.warn("in getSellerOrderComputeResult fail uid {}, skup {}", uid, skup, ex);
return null;
}
}
... ...
... ... @@ -2,10 +2,10 @@ package com.yohoufo.order.service.seller.orderMeta;
import com.alibaba.fastjson.JSONObject;
import com.yoho.core.dal.datasource.annotation.Database;
import com.yohobuy.ufo.model.order.bo.SellerCouponSimpleBo;
import com.yohoufo.dal.order.SellerOrderMetaMapper;
import com.yohoufo.dal.order.model.SellerOrderMeta;
import com.yohoufo.order.constants.MetaKey;
import com.yohoufo.order.model.bo.CouponBo;
import com.yohoufo.order.utils.LoggerUtils;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -45,7 +45,7 @@ public class SellerOrderMetaService {
@Transactional(propagation = Propagation.REQUIRED)
@Database(ForceMaster=true, DataSource="ufo_order")
public int saveUsedCoupons(int skup,int uid, List<SellerCouponSimpleBo> usedCoupons){
public int saveUsedCoupons(int skup,int uid, List<CouponBo> usedCoupons){
String key = MetaKey.SELLER_USED_COUPON;
SellerOrderMeta som = new SellerOrderMeta();
som.setUid(uid);
... ...
package com.yohoufo.order.service.seller.trade;
import com.yohobuy.ufo.model.order.constants.SkupType;
import com.yohoufo.order.service.seller.trade.OrderComputeHandler;
import com.yohoufo.order.utils.LoggerUtils;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
... ...
... ... @@ -185,35 +185,37 @@ public class SellerOrderComputeService {
* @return
*/
private Optional<CouponPayResult> activityCouponUse(UserCouponsBo activityCouponsBo, SellerOrderRelatedBuyerOrderContext chargeContext) {
SellerOrderComputeResult chargeResult = chargeContext.getSellerOrderComputeResult();
SellerOrderComputeResult computeResult = chargeContext.getSellerOrderComputeResult();
PlatformFeeDto platformFeeDto = chargeResult.getPlatformFee();
PlatformFeeDto platformFeeDto = computeResult.getPlatformFee();
BigDecimal oldServiceFee = platformFeeDto.getServiceFee();
//1. calculate coupon cut amount
BigDecimal couponPayAmount = BigDecimalHelper.min(oldServiceFee, activityCouponsBo.getCouponAmount());
BigDecimal oldIncome = chargeResult.getIncome();
BigDecimal oldIncome = computeResult.getIncome();
//2. calculate income and set
//2.1
BigDecimal newIncome = BigDecimalHelper.add(oldIncome, couponPayAmount);
//2.2 set income
chargeResult.setIncome(newIncome);
computeResult.setIncome(newIncome);
//3. calculate serviceFee and set
BigDecimal newServiceFee = BigDecimalHelper.sub(oldServiceFee, couponPayAmount);
platformFeeDto.setServiceFee(newServiceFee);
//platformFeeDto.setServiceFee(newServiceFee);
BigDecimal oldFinalAmountOfCutCoupons = chargeResult.getCouponCutAmount();
BigDecimal oldFinalAmountOfCutCoupons = computeResult.getCouponCutAmount();
BigDecimal newFinalAmountOfCutCoupons;
if (Objects.isNull(oldFinalAmountOfCutCoupons)){
newFinalAmountOfCutCoupons = couponPayAmount;
}else {
newFinalAmountOfCutCoupons = BigDecimalHelper.add(oldFinalAmountOfCutCoupons, couponPayAmount);
}
chargeResult.setCouponCutAmount(newFinalAmountOfCutCoupons);
computeResult.setCouponCutAmount(newFinalAmountOfCutCoupons);
CouponPayResult couponPayResult = CouponPayResult.builder().couponCode(activityCouponsBo.getCouponCode())
.couponAmount(couponPayAmount.doubleValue()).couponType(activityCouponsBo.getCouponType()).build();
logger.info("seller order [{}] step activity coupon charge,oldIncome:{},newIncome of cut coupons:{}",
chargeContext.getUid(), oldIncome, newIncome);
chargeContext.getUid(), oldIncome, newIncome, newFinalAmountOfCutCoupons);
//
computeResult.setAmountIsReset(true);
return Optional.of(couponPayResult);
}
... ...
package com.yohoufo.order.service.seller.trade;
import com.yoho.core.transaction.YHTxCoordinator;
import com.yoho.core.transaction.annoation.YHTransaction;
import com.yohoufo.dal.order.model.SellerOrder;
import com.yohoufo.order.model.dto.SellerOrderSubmitDTO;
import com.yohoufo.order.service.proxy.CouponProxyService;
import com.yohoufo.order.service.seller.SellerOrderUpdateService;
import com.yohoufo.order.utils.LoggerUtils;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class SellerOrderSubmitService {
private final Logger logger = LoggerUtils.getSellerOrderLogger();
@Autowired
private YHTxCoordinator tx;
@Autowired
private CouponProxyService couponProxyService;
@Autowired
private SellerOrderUpdateService sellerOrderUpdateService;
/**
* 提交已有的订单
* 目前场景 发货用券时重新结算
* @param submitDTO
*/
@YHTransaction
public void submitByOld(SellerOrderSubmitDTO submitDTO){
SellerOrder sellerOrder = submitDTO.getSellerOrder();
logger.info("in SellerOrderSubmitService.submitByOld, {}", sellerOrder);
//修改卖家订单
sellerOrderUpdateService.updateAmount(submitDTO);
//
try {
//使用优惠券
if (submitDTO.getCouponBoList().isNotEmpty()) {
couponProxyService.orderUseCoupon(sellerOrder.getUid(), sellerOrder.getOrderCode(), submitDTO.getCouponBoList().getCouponCodes());
}
}catch (Exception ex){
tx.rollback();
throw ex;
}
}
}
... ...
... ... @@ -10,11 +10,14 @@ import com.yohoufo.order.constants.CouponConstants;
import com.yohobuy.ufo.model.order.resp.CouponInfo;
import com.yohobuy.ufo.model.order.resp.RecommendedCouponInfo;
import com.yohobuy.ufo.model.order.resp.ShoppingCoupon;
import com.yohoufo.order.model.bo.CouponBo;
import com.yohoufo.order.model.bo.CouponBoList;
import com.yohoufo.order.utils.CouponCodeUtils;
import com.yohoufo.order.utils.MathUtils;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
... ... @@ -231,4 +234,23 @@ public class CouponSupport {
return result;
}
/**
* 优惠券支付结果
*
* @param couponPayResultList
* @return
*/
public static CouponBoList buildOrderCouponBoList(CouponPayResultList couponPayResultList) {
return CouponBoList.builder().couponBos(couponPayResultList.getCouponPayResults().stream()
.map(couponPayResult -> CouponBo.builder()
.couponCode(couponPayResult.getCouponCode())
.couponType(couponPayResult.getCouponType())
.couponAmount(BigDecimal.valueOf(couponPayResult.getCouponAmount()))
.build()
)
.collect(Collectors.toList())
).build();
}
}
... ...