|
|
@@ -4,8 +4,10 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.yami.shop.bean.app.dto.*;
|
|
|
import com.yami.shop.bean.app.param.OrderParam;
|
|
|
+import com.yami.shop.bean.event.ConfirmOrderEvent;
|
|
|
import com.yami.shop.bean.event.PlatformConfirmOrderEvent;
|
|
|
import com.yami.shop.bean.event.ScoreConfirmOrderEvent;
|
|
|
+import com.yami.shop.bean.dto.XsbMemberDiscountInfo;
|
|
|
import com.yami.shop.bean.model.Category;
|
|
|
import com.yami.shop.bean.model.UserExtension;
|
|
|
import com.yami.shop.bean.order.ConfirmOrderOrder;
|
|
|
@@ -16,6 +18,7 @@ import com.yami.shop.security.api.util.SecurityUtils;
|
|
|
import com.yami.shop.service.CategoryService;
|
|
|
import com.yami.shop.service.SysConfigService;
|
|
|
import com.yami.shop.service.UserExtensionService;
|
|
|
+import com.yami.shop.service.XsbMemberSupportService;
|
|
|
import com.yami.shop.user.comment.dao.UserLevelMapper;
|
|
|
import com.yami.shop.user.comment.model.UserLevel;
|
|
|
import com.yami.shop.user.comment.util.CategoryScale;
|
|
|
@@ -26,11 +29,12 @@ import org.springframework.core.annotation.Order;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.swing.text.StyledEditorKit;
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
- * 计算订单时的积分及成长值抵现和折扣信息
|
|
|
+ * 閻犱緤绱曢悾鑽ゆ媼閵忕姴绀嬮柡鍐ㄥ濞堟垹绮旈姘€婚柛娆忥攻閸ㄦ岸姊归崹顔瑰亾閸忕厧啸闁绘粍婢橀幏浼村箮濡鈷忓ǎ鍥e墲娴?
|
|
|
*/
|
|
|
@Component("userConfirmOrderListener")
|
|
|
@AllArgsConstructor
|
|
|
@@ -40,18 +44,19 @@ public class ConfirmOrderListener {
|
|
|
private final SysConfigService sysConfigService;
|
|
|
private final UserLevelMapper userLevelMapper;
|
|
|
private final CategoryService categoryService;
|
|
|
+ private final XsbMemberSupportService xsbMemberSupportService;
|
|
|
|
|
|
/**
|
|
|
- * 计算积分抵现和分摊
|
|
|
+ * 閻犱緤绱曢悾鑽ょ矓椤栨艾鐎婚柟鍓佹暩楠炲洭宕仦钘夌€婚柟?
|
|
|
*/
|
|
|
@EventListener(ScoreConfirmOrderEvent.class)
|
|
|
@Order(ConfirmOrderOrder.SCORE)
|
|
|
public void scoreSubmitOrderListener(ScoreConfirmOrderEvent event) {
|
|
|
System.out.println(JSONObject.toJSONString(event));
|
|
|
-// //获取用户等级积分详细表
|
|
|
+// //闁兼儳鍢茶ぐ鍥偨閵婏箑鐓曠紒娑橆槺妤犲洨绮旈姘€婚悹鍥峰缁繒鎮?
|
|
|
// UserExtension extension = userExtensionService.getOne(
|
|
|
// new LambdaQueryWrapper<UserExtension>().eq(UserExtension::getUserId, SecurityUtils.getUser().getUserId()));
|
|
|
-// //获取配置信息
|
|
|
+// //闁兼儳鍢茶ぐ鍥煀瀹ュ洨鏋傚ǎ鍥e墲娴?
|
|
|
// ScoreConfigParam scoreParam = sysConfigService.getSysConfigObject(Constant.SCORE_CONFIG,ScoreConfigParam.class);
|
|
|
// if(Objects.nonNull(scoreParam) && scoreParam.getShopScoreSwitch() != null && !scoreParam.getShopScoreSwitch()){
|
|
|
// return;
|
|
|
@@ -61,33 +66,33 @@ public class ConfirmOrderListener {
|
|
|
// if(orderParam.getUserUseScore() != null && orderParam.getUserUseScore() < 0 && extension.getScore() < 0){
|
|
|
// return;
|
|
|
// }
|
|
|
-// //计算积分最多抵现金额
|
|
|
+// //閻犱緤绱曢悾鑽ょ矓椤栨艾鐎婚柡鍫氬亾濠㈣埖纰嶆慨鐑芥偝娴兼潙娅ㄥΛ?
|
|
|
// double totalScoreAmount = 0.0;
|
|
|
// List<Category> categories = categoryService.listByShopId(Constant.PLATFORM_SHOP_ID);
|
|
|
// Map<Long, Double> categoryMap = CategoryScale.getScaleByCategory(categories,scoreParam,0);
|
|
|
-// // 积分抵现金额可用上限 = 订单可使用积分比例 * ((实际总值)/100)
|
|
|
+// // 缂佸鍨伴崹搴ㄥ箮閻㈤潧绠涢梺鍙夊灴椤ゅ倿宕i婊勬殢濞戞挸锕?= 閻犱降鍨瑰畷鐔煎矗椤栨瑥鈻忛柣顫妿琚ч柛鎺戞閻︻喗绗?* ((閻庡湱鍋ゅ顖炲箑鐠囨祴鍋?/100闁?
|
|
|
// if(scoreParam.getUseDiscountRange() == 0){
|
|
|
-// // 如果有等级优惠金额,还需减去等级的优惠金额、运费才是实际金额,包邮时运费为0
|
|
|
+// // 濠碘€冲€归悘澶愬嫉婢跺瞼鎼肩紒鐙欏倻鍠橀柟顖滃█閸g偓锛愬┑鎾剁閺夆晜锕㈠〒鍫曞礄韫囨挸绠电紒娑橆槺妤犲洭鎯冮崟顏嗗枠闁诡垳濞€閸g偓锛愬┑鍕ㄥ亾娴g晫绠ラ悹鎰潐婢х娀寮伴姘辨澖闂傚嫬鎳橀崳鐐紣濠垫挾绀夐柛鏍ф嚇閸嬫牠寮幆鎵閻犳劙鈧稖绀?
|
|
|
// double actualTotal = Arith.sub(shopCartOrderMergerDto.getActualTotal(),shopCartOrderMergerDto.getTotalTransfee());
|
|
|
// totalScoreAmount = Arith.div(Arith.mul(actualTotal, scoreParam.getUseDiscount()), 100);
|
|
|
// }else{
|
|
|
-// //获取大类的比例并转成map
|
|
|
+// //闁兼儳鍢茶ぐ鍥ㄥ緞瑜忕悮顐︽儍閸曨剛妲峰〒姘儏閼荤喐娼浣哥亣map
|
|
|
// for (ShopCartItemDto shopCartItem : event.getAllCartItem()) {
|
|
|
// if(!categoryMap.containsKey(shopCartItem.getCategoryId())) {
|
|
|
// continue;
|
|
|
// }
|
|
|
-// // 商品总额减去商家优惠、平台优惠,就是商品项的实际金额
|
|
|
+// // 闁哥喎妫楅幖褔骞€婵犳凹鏉洪柛鎴濈箰楠炴捇宕崱妤婂晙濞村吋蓱閸庮剟濡存担鎼佹尙闁告瑩顣︾槐顓㈠箚閻欏懐绀夐悘蹇氶哺濡叉悂宕崱妤佹儌濡炪倕婀卞▓鎴犫偓鍦仱濡绢垶鏌岄幋锔绘澓
|
|
|
// double actualTotal = Arith.sub(Arith.sub(shopCartItem.getProductTotalAmount(), shopCartItem.getShareReduce()),shopCartItem.getPlatformShareReduce());
|
|
|
// double scoreReduce = Arith.div(Arith.mul(actualTotal, categoryMap.get(shopCartItem.getCategoryId())),100);
|
|
|
// totalScoreAmount = Arith.add(totalScoreAmount,scoreReduce);
|
|
|
// }
|
|
|
// }
|
|
|
-// //计算用户可用积分 如果大于总共的积分使用比例直接使用,如果小于根据比例使用
|
|
|
+// //閻犱緤绱曢悾濠氭偨閵婏箑鐓曢柛娆樺灣閺併倗绮旈姘€?濠碘€冲€归悘澶嬪緞瑜岀花顒勫箑鐠囨彃褰欓柣銊ュ琚ч柛鎺戞婵炲洭鎮介妸锔炬Х濞撴艾顑囧ú鍧楀箳閵夈倕鈻忛柣銏╃厜缁辨繃淇婇崒娑氫函閻忓繐绻嬬花顒勫冀鐟欏嫬绁︽慨锝嗘煣缁躲儲鎷呯捄銊︽殢
|
|
|
// int canUseScore = (int) Arith.mul(totalScoreAmount, scoreParam.getShopUseScore());
|
|
|
//// totalScoreAmount = Arith.div(canUseScore, scoreParam.getShopUseScore(),2);
|
|
|
// Integer userUseScore = extension.getScore();
|
|
|
// Integer totalUsableScore = extension.getScore();
|
|
|
-// //如果是用户选择的积分数额,则用此积分数额
|
|
|
+// //濠碘€冲€归悘澶愬及椤栨粍鏆忛柟瀵稿厴閳ь剙顦扮€氥劑鎯冮崟顓夋繈宕氶崱妯绘濡増绻愮槐婵嬪礆濞嗘垶鏆忔慨婵勫€楄ⅶ闁告帒妫欓弳鐔革紣?
|
|
|
// if(orderParam.getUserUseScore() != null && orderParam.getIsScorePay() == 1 && orderParam.getUserUseScore() >= 0){
|
|
|
// userUseScore = Math.min(orderParam.getUserUseScore(),userUseScore);
|
|
|
// }else{
|
|
|
@@ -99,19 +104,19 @@ public class ConfirmOrderListener {
|
|
|
// }
|
|
|
// int maxScore = Math.min(totalUsableScore,canUseScore);
|
|
|
// userUseScore = Math.min(userUseScore, canUseScore);
|
|
|
-// // 如果为大于100的比例,则积分需要整10使用
|
|
|
+// // 濠碘€冲€归悘澶嬬▔閸濆嫨浜eù?00闁汇劌瀚惁顔界瑹鐎e墎绀夐柛鎺撶懅琚ч柛鎺戞濞撳墎鎲版担瑙勬10濞达綀娉曢弫?
|
|
|
// if(scoreParam.getShopUseScore() > 100){
|
|
|
// userUseScore = userUseScore - userUseScore % 10;
|
|
|
// maxScore = maxScore - maxScore % 10;
|
|
|
// }
|
|
|
-// // 计算最大可抵扣金额,并且如果小数大于两位四舍五入,还需在计算一遍实际使用积分
|
|
|
+// // 閻犱緤绱曢悾濠氬嫉閳ь剚寰勮瑜版煡骞庨崹顐⑩拸闂佸弶鍨块·鍌炴晬鐏炲€熷珯濞戞挻鏌ㄩ々褔寮稿鍐瘓闁轰焦婢橀妵鍥ㄧ鎼存繆鈷堝ù锝呯Т濞叉捇鎳滃鍕畨闁稿繈鍎荤槐婵囨交濮椻偓濞撳爼宕烽妸顭戝悁缂佺姵銇炵粩鎾焼瀹ュ懐鏉介梻鍕噸婵炲洭鎮介妸顬繈宕?
|
|
|
// totalScoreAmount = Arith.div(userUseScore,scoreParam.getShopUseScore(),2);
|
|
|
// userUseScore = (int) Arith.mul(totalScoreAmount, scoreParam.getShopUseScore());
|
|
|
-// //用户选择积分抵现,组装积分信息
|
|
|
+// //闁活潿鍔嶉崺娑㈡焻婢跺顏ョ紒澶樺灠閸ㄥ酣骞庨悽闈涚疀闁挎稑鐬肩划宥囨啑閸涱垍婵嬪礆閸℃洑绻嗛柟?
|
|
|
// List<ShopCartOrderDto> shopCartOrders = shopCartOrderMergerDto.getShopCartOrders();
|
|
|
// double totalScoreReduce = 0.0;
|
|
|
// int totalScore = 0;
|
|
|
-// //通过for i找出最后一项,将计算偏差的1积分给最后的最大的一项
|
|
|
+// //闂侇偅淇虹换鍍╫r i闁瑰灚鍎抽崵顓㈠嫉閳ь剟宕ユ惔婵堫伇濡炪倗娅㈢槐婵堜焊閸℃凹鍚€缂佺姵顨呮禍绋款啅椤旂偓鐣?缂佸鍨伴崹搴g磼濞嗘劖浠橀柛姘捣濞堟垿寮甸埀顒佸緞瑜忓▓鎴炵▔閳ь剚銇?
|
|
|
// for (int shopIndex = 0; shopIndex < shopCartOrders.size(); shopIndex++) {
|
|
|
// ShopCartOrderDto shopCartOrder = shopCartOrders.get(shopIndex);
|
|
|
// double reduceSum = 0.0;
|
|
|
@@ -122,9 +127,9 @@ public class ConfirmOrderListener {
|
|
|
// for (int itemIndex = 0; itemIndex< shopCartItems.size(); itemIndex++) {
|
|
|
// ShopCartItemDto shopCartItem = shopCartItems.get(itemIndex);
|
|
|
// double scoreReduceProd = 0.0;
|
|
|
-// //判断是否最后一项
|
|
|
+// //闁告帇鍊栭弻鍥及椤栨碍鍎婇柡鍫氬亾闁告艾绨肩粩瀛樸亜?
|
|
|
// boolean isEnd = shopIndex == shopCartOrders.size() - 1 && discountIndex ==shopCartItemDiscounts.size() - 1 && itemIndex == shopCartItems.size() - 1;
|
|
|
-// //计算商品分摊的金额,需要乘以比例
|
|
|
+// //閻犱緤绱曢悾濠氬疮閸℃鎯傞柛鎺戞閹诧繝鎯冮崟顖氭濡増绻愮槐婵嬫閳ь剛鎲版担椋庮啋濞寸姰鍎查惁顔界瑹?
|
|
|
// if(scoreParam.getUseDiscountRange() == 0){
|
|
|
// scoreReduceProd = Arith.div(Arith.mul(shopCartItem.getActualTotal(),scoreParam.getUseDiscount()),100,2);
|
|
|
// }else if(categoryMap.containsKey(shopCartItem.getCategoryId())){
|
|
|
@@ -132,9 +137,9 @@ public class ConfirmOrderListener {
|
|
|
// }
|
|
|
// int useScore = (int) Arith.mul(Arith.round(Arith.mul(scoreReduceProd,scale),2), scoreParam.getShopUseScore());
|
|
|
// scoreReduceProd = Arith.div(useScore, scoreParam.getShopUseScore(),2);
|
|
|
-// //如果大于可用上限则直接等于,或者如果是最后一项直接将剩余的抵扣金额全部赋予最后一个,积分和金额直接等于 使用的 - 已经抵扣的
|
|
|
+// //濠碘€冲€归悘澶嬪緞瑜岀花顒勫矗椤栨粍鏆忓☉鎾筹躬濡炬椽宕氬▎鎴炵函闁规亽鍎抽悺鎴炵鎼搭垳绀夐柟瀛樼墳閳ь剙鎳庨々褔寮稿鍕﹂柡鍫氬亾闁告艾绨肩粩瀛樸亜閸︻厽绾柟鎭掑劚閻ㄣ垽宕滈埡鈧紞鎴︽儍閸曨剙啸闁圭缍侀崳鐐紣濠靛棗寮块梺顔哄姀缁佸瓨绂嶉崼鐔镐粯闁告艾绨肩粩瀛樼▔椤忓海绀夌紒澶樺灠閸ㄥ酣宕畝鍕濡増绻勫ú鍧楀箳閵壯呮惣濞?濞达綀娉曢弫銈夋儍?- 鐎规瓕灏欑划锟犲箮閸偄鈷忛柣?
|
|
|
// if(Arith.add(totalScoreReduce,scoreReduceProd) > totalScoreAmount || isEnd){
|
|
|
-// //减去当前总共的积分,减去店铺已分摊的积分
|
|
|
+// //闁告垵绻愰獮鎾广亹閹惧啿顤呴柟顒冾嚙閸欙繝鎯冮崟顓夋繈宕氶崱顓犵闁告垵绻愰獮鎾存償濡ゅ懏鎳欑€瑰憡褰冮崹搴ㄥ箺婵犲嫭鐣辩紒澶樺灠閸?
|
|
|
// useScore = userUseScore - totalScore - shopScore;
|
|
|
// scoreReduceProd = Arith.sub(totalScoreAmount ,totalScoreReduce);
|
|
|
// }
|
|
|
@@ -152,19 +157,19 @@ public class ConfirmOrderListener {
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
-// //设置店铺的实际总值、积分优惠金额和订单优惠金额
|
|
|
+// //閻犱礁澧介悿鍡樻償濡ゅ懏鎳欓柣銊ュ閻ゅ嫰姊介崨顔瑰亾鐠囨祴鍋撶粭琛″亾娴g洅婵嬪礆閸℃洜鍠橀柟顖滃█閸g偓锛愬┑鍡樺閻犱降鍨瑰畷鐔稿濡鍔曢梺鍙夊灴椤?
|
|
|
// shopCartOrder.setScoreReduce(reduceSum);
|
|
|
// shopCartOrder.setActualTotal(Arith.sub(shopCartOrder.getActualTotal(),reduceSum));
|
|
|
-// //放入优惠金额
|
|
|
+// //闁衡偓閹冨汲濞村吋蓱閸庮剟鏌岄幋锔绘澓
|
|
|
// shopCartOrder.setShopReduce(Arith.add(shopCartOrder.getShopReduce(),reduceSum));
|
|
|
-// //放入平台优惠金额,如果用户等级免自营店运费也要放进去
|
|
|
+// //闁衡偓閹冨汲妤犵偛鍟胯ぐ瀛樺濡鍔曢梺鍙夊灴椤?濠碘€冲€归悘澶愭偨閵婏箑鐓曠紒娑橆槺妤犲洭宕楀鍫濇闁解偓閵夈儳鏆楅弶鈺傚姌閸ㄥ倹绋婇悢娲绘矗闁衡偓閹规劗绠婚柛?
|
|
|
// shopCartOrder.setPlatformAmount(Arith.add(shopCartOrder.getPlatformAmount(),reduceSum));
|
|
|
// totalScore += shopScore;
|
|
|
// if (orderParam.getIsScorePay() != null && orderParam.getIsScorePay() == 1) {
|
|
|
// shopCartOrder.setUseScore(shopScore);
|
|
|
// }
|
|
|
// }
|
|
|
-// //设置订单的实际总值和订单优惠金额
|
|
|
+// //閻犱礁澧介悿鍡欐媼閵忕姴绀嬮柣銊ュ閻ゅ嫰姊介崨顔瑰亾鐠囨祴鍋撻悡搴㈠閻犱降鍨瑰畷鐔稿濡鍔曢梺鍙夊灴椤?
|
|
|
// shopCartOrderMergerDto.setTotalScoreAmount(totalScoreReduce);
|
|
|
// shopCartOrderMergerDto.setShopUseScore(scoreParam.getShopUseScore());
|
|
|
// shopCartOrderMergerDto.setTotalUsableScore(totalScore);
|
|
|
@@ -177,7 +182,74 @@ public class ConfirmOrderListener {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 计算等级折扣比例和分摊比例
|
|
|
+ * Apply member discount for XSB mall items only.
|
|
|
+ */
|
|
|
+ @EventListener(ConfirmOrderEvent.class)
|
|
|
+ @Order(ConfirmOrderOrder.MEMBER)
|
|
|
+ public void memberDiscountConfirmOrderListener(ConfirmOrderEvent event) {
|
|
|
+ ShopCartOrderDto shopCartOrderDto = event.getShopCartOrderDto();
|
|
|
+ List<ShopCartItemDto> xsbItems = event.getShopCartItems().stream()
|
|
|
+ .filter(xsbMemberSupportService::isXsbItem)
|
|
|
+ .filter(item -> Boolean.TRUE.equals(item.getIsMember()))
|
|
|
+ .filter(item -> item.getMemberPrice() != null)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (CollectionUtils.isEmpty(xsbItems)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Double memberDiscountRate = resolveMemberDiscountRate();
|
|
|
+ double memberReduce = 0.0;
|
|
|
+ for (ShopCartItemDto shopCartItem : xsbItems) {
|
|
|
+ double productTotal = shopCartItem.getProductTotalAmount() == null ? 0.0 : shopCartItem.getProductTotalAmount();
|
|
|
+ double memberTotal = Arith.mul(shopCartItem.getMemberPrice(), shopCartItem.getProdCount());
|
|
|
+ double reduceAmount = Arith.round(Arith.sub(productTotal, memberTotal), 2);
|
|
|
+ if (reduceAmount < 0) {
|
|
|
+ reduceAmount = 0.0;
|
|
|
+ }
|
|
|
+ if (reduceAmount > productTotal) {
|
|
|
+ reduceAmount = productTotal;
|
|
|
+ }
|
|
|
+ if (reduceAmount <= 0) {
|
|
|
+ shopCartItem.setMemberDiscountShareAmount(0.0);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ shopCartItem.setMemberDiscountShareAmount(reduceAmount);
|
|
|
+ shopCartItem.setShareReduce(Arith.add(shopCartItem.getShareReduce(), reduceAmount));
|
|
|
+ shopCartItem.setActualTotal(Arith.sub(shopCartItem.getActualTotal(), reduceAmount));
|
|
|
+ memberReduce = Arith.add(memberReduce, reduceAmount);
|
|
|
+ }
|
|
|
+ if (memberReduce <= 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ shopCartOrderDto.setMemberDiscountAmount(memberReduce);
|
|
|
+ shopCartOrderDto.setMemberDiscountDesc("Member discount");
|
|
|
+ shopCartOrderDto.setMemberDiscountRate(memberDiscountRate);
|
|
|
+ shopCartOrderDto.setMemberBenefitDesc(buildMemberBenefitDesc(memberDiscountRate));
|
|
|
+ shopCartOrderDto.setActualTotal(Arith.sub(shopCartOrderDto.getActualTotal(), memberReduce));
|
|
|
+ shopCartOrderDto.setShopReduce(Arith.add(shopCartOrderDto.getShopReduce(), memberReduce));
|
|
|
+ }
|
|
|
+
|
|
|
+ private Double resolveMemberDiscountRate() {
|
|
|
+ XsbMemberDiscountInfo memberInfo = xsbMemberSupportService.getMemberDiscountInfo(SecurityUtils.getUser().getUserId());
|
|
|
+ if (memberInfo == null || !Boolean.TRUE.equals(memberInfo.getMember())) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ Double discountRate = memberInfo.getDiscountRate();
|
|
|
+ if (discountRate == null || discountRate <= 0 || discountRate >= 1) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return discountRate;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String buildMemberBenefitDesc(Double memberDiscountRate) {
|
|
|
+ if (memberDiscountRate == null) {
|
|
|
+ return "会员权益";
|
|
|
+ }
|
|
|
+ BigDecimal discountValue = BigDecimal.valueOf(memberDiscountRate).multiply(BigDecimal.TEN).stripTrailingZeros();
|
|
|
+ return "会员权益(" + discountValue.toPlainString() + "折)";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Apply original level discount logic.
|
|
|
*/
|
|
|
@EventListener(PlatformConfirmOrderEvent.class)
|
|
|
@Order(ConfirmOrderOrder.LEVEL)
|
|
|
@@ -193,8 +265,8 @@ public class ConfirmOrderListener {
|
|
|
}
|
|
|
ShopCartOrderMergerDto shopCartOrderMergerDto = event.getShopCartOrderMergerDto();
|
|
|
List<ShopCartOrderDto> shopCartOrders = shopCartOrderMergerDto.getShopCartOrders();
|
|
|
- //获取分类比例
|
|
|
- //最后计算成长值折扣
|
|
|
+ //闁兼儳鍢茶ぐ鍥礆閸℃瑨顫︽慨锝嗘煣缁?
|
|
|
+ //闁哄牃鍋撻柛姘唉椤撳摜绮诲Δ浣哥亣闂傗偓閸喒鍋撻崗鐓庮潙闁?
|
|
|
if (extension.getLevel() == null) {
|
|
|
extension.setLevel(Constant.USER_LEVEL_INIT);
|
|
|
}
|
|
|
@@ -203,18 +275,18 @@ public class ConfirmOrderListener {
|
|
|
// double levelDiscountActualTotal= 0.0;
|
|
|
double discount = Arith.sub(10, level.getDiscount());
|
|
|
|
|
|
- //将分类转成map
|
|
|
+ //閻忓繐妫楅崹搴g尵閺勫繑绁柟瀛樹粣ap
|
|
|
List<Long> categoryIds = level.getCategoryIds();
|
|
|
Map<Long, Long> categoryMap = new HashMap<>(100);
|
|
|
if (CollectionUtils.isNotEmpty(categoryIds)) {
|
|
|
categoryIds.forEach(categoryId -> categoryMap.put(categoryId, categoryId));
|
|
|
}
|
|
|
- //计算折扣总额
|
|
|
+ //閻犱緤绱曢悾濠氬箮濡鈷忛柟顒€顭烽·?
|
|
|
double maxlevelFeeTotal = getLevelFeeTotal(shopCartOrders, level, categoryMap);
|
|
|
- //通过for i找出最后一项,将计算偏差的1积分给最后的最大的一项
|
|
|
+ //闂侇偅淇虹换鍍╫r i闁瑰灚鍎抽崵顓㈠嫉閳ь剟宕ユ惔婵堫伇濡炪倗娅㈢槐婵堜焊閸℃凹鍚€缂佺姵顨呮禍绋款啅椤旂偓鐣?缂佸鍨伴崹搴g磼濞嗘劖浠橀柛姘捣濞堟垿寮甸埀顒佸緞瑜忓▓鎴炵▔閳ь剚銇?
|
|
|
for (int shopIndex = 0; shopIndex < shopCartOrders.size(); shopIndex++) {
|
|
|
ShopCartOrderDto shopCartOrder = shopCartOrders.get(shopIndex);
|
|
|
- //如果可用范围为自营店不为当前店铺直接下一次循环
|
|
|
+ //濠碘€冲€归悘澶愬矗椤栨粍鏆忛柤鐓庡暙濞叉寧绋夋ウ鍨闁解偓閵夈儳鏆楀☉鎾崇С鐠愮喕銇愰幘鍐差枀閹煎瓨顨婇幗鐢告儎鐎涙ê澶嶅☉鎾愁儎缁旀潙鈻庨垾铏剷闁?
|
|
|
if (level.getDiscountRange() == 1 && !Objects.equals(shopCartOrder.getShopId(), 1L)) {
|
|
|
continue;
|
|
|
}
|
|
|
@@ -225,25 +297,25 @@ public class ConfirmOrderListener {
|
|
|
for (int itemIndex = 0; itemIndex < shopCartItems.size(); itemIndex++) {
|
|
|
ShopCartItemDto shopCartItem = shopCartItems.get(itemIndex);
|
|
|
double prodDiscount = 0.0;
|
|
|
- //判断是否最后一项
|
|
|
+ //闁告帇鍊栭弻鍥及椤栨碍鍎婇柡鍫氬亾闁告艾绨肩粩瀛樸亜?
|
|
|
boolean isEnd = shopIndex == shopCartOrders.size() - 1 && discountIndex == shopCartItemDiscounts.size() - 1 && itemIndex == shopCartItems.size() - 1;
|
|
|
- //折扣
|
|
|
+ //闁硅埖蓱婢?
|
|
|
if (level.getDiscountType() == 0 || categoryMap.containsKey(shopCartItem.getCategoryId())) {
|
|
|
prodDiscount = Arith.div(Arith.mul(shopCartItem.getActualTotal(), discount), 10, 2);
|
|
|
if (isEnd || Arith.add(Arith.add(levelDiscount, reduceSum), prodDiscount) > maxlevelFeeTotal) {
|
|
|
- //总折扣金额减去当前累计的折扣金额,就为最后一件商品分摊的等级优惠金额
|
|
|
+ //闁诡剛绮慨宀勫箥閿濆娅ㄥΛ鐗堢箓閸f椽宕㈢拠鑼Ъ闁告挸绉堕悿顔炬媼閿涘嫭鐣遍柟鑸瞪戞晶鎼佹煂閹达富鏉洪柨娑樿嫰濮樸劍绋夐悜妯讳粯闁告艾绨肩粩瀛樼鐠虹儤娅岄柛婵呯閸ㄥ酣骞楁繝鍕暠缂佹稑顦辨鍥ㄥ濡鍔曢梺鍙夊灴椤?
|
|
|
prodDiscount = Arith.sub(Arith.sub(maxlevelFeeTotal, levelDiscount), reduceSum);
|
|
|
}
|
|
|
}
|
|
|
- //计算商品分摊的金额
|
|
|
+ //閻犱緤绱曢悾濠氬疮閸℃鎯傞柛鎺戞閹诧繝鎯冮崟顖氭濡?
|
|
|
shopCartItem.setPlatformShareReduce(Arith.add(shopCartItem.getPlatformShareReduce(), prodDiscount));
|
|
|
reduceSum = Arith.add(reduceSum, Arith.round(prodDiscount, 2));
|
|
|
}
|
|
|
}
|
|
|
- //设置店铺的实际总值、积分优惠金额和订单优惠金额
|
|
|
+ //閻犱礁澧介悿鍡樻償濡ゅ懏鎳欓柣銊ュ閻ゅ嫰姊介崨顔瑰亾鐠囨祴鍋撶粭琛″亾娴g洅婵嬪礆閸℃洜鍠橀柟顖滃█閸g偓锛愬┑鍡樺閻犱降鍨瑰畷鐔稿濡鍔曢梺鍙夊灴椤?
|
|
|
shopCartOrder.setLevelReduce(reduceSum);
|
|
|
levelDiscount = Arith.add(levelDiscount, reduceSum);
|
|
|
- //判断用户等级是否自营店包邮
|
|
|
+ //闁告帇鍊栭弻鍥偨閵婏箑鐓曠紒娑橆槺妤犲洭寮伴姘剨闁煎浜i幆鈧幖瀛橆殔鐎垫﹢鏌?
|
|
|
//&& level.getCategoryIds()
|
|
|
if (Objects.equals(shopCartOrder.getShopId(), Constant.MAIN_SHOP) && level.getIsFreeFee() == 1) {
|
|
|
freeTransfee = shopCartOrder.getTransfee();
|
|
|
@@ -252,22 +324,22 @@ public class ConfirmOrderListener {
|
|
|
}
|
|
|
}
|
|
|
shopCartOrderMergerDto.setTotalLevelAmount(levelDiscount);
|
|
|
- //设置运费优惠金额
|
|
|
+ //閻犱礁澧介悿鍡樻交閹邦垰鐎ù鍏忌戦崕顒勬煂閹达富鏉?
|
|
|
shopCartOrderMergerDto.setFreeTransfee(freeTransfee);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 计算出总共可以折扣的金额
|
|
|
+ * 閻犱緤绱曢悾濠氬礄閻戞ǚ鍋撶拠鎻掑綑闁告瑯鍨禍鎺楀箮濡鈷忛柣銊ュ閸g偓锛?
|
|
|
*
|
|
|
- * @param shopCartOrders 全部商品项
|
|
|
- * @param level 等级
|
|
|
- * @param categoryMap 分类
|
|
|
- * @return 总折扣金额
|
|
|
+ * @param shopCartOrders 闁稿繈鍔戦崕鎾疮閸℃鎯傚?
|
|
|
+ * @param level 缂佹稑顦辨?
|
|
|
+ * @param categoryMap 闁告帒妫涚悮?
|
|
|
+ * @return 闁诡剛绮慨宀勫箥閿濆娅ㄥΛ?
|
|
|
*/
|
|
|
private double getLevelFeeTotal(List<ShopCartOrderDto> shopCartOrders, UserLevel level, Map<Long, Long> categoryMap) {
|
|
|
double totalFee = 0.0;
|
|
|
for (ShopCartOrderDto shopCartOrder : shopCartOrders) {
|
|
|
- //如果可用范围为自营店不为当前店铺直接下一次循环
|
|
|
+ //濠碘€冲€归悘澶愬矗椤栨粍鏆忛柤鐓庡暙濞叉寧绋夋ウ鍨闁解偓閵夈儳鏆楀☉鎾崇С鐠愮喕銇愰幘鍐差枀閹煎瓨顨婇幗鐢告儎鐎涙ê澶嶅☉鎾愁儎缁旀潙鈻庨垾铏剷闁?
|
|
|
if (level.getDiscountRange() == 1 && !Objects.equals(shopCartOrder.getShopId(), 1L)) {
|
|
|
continue;
|
|
|
}
|
|
|
@@ -275,7 +347,7 @@ public class ConfirmOrderListener {
|
|
|
for (ShopCartItemDiscountDto shopCartItemDiscount : shopCartItemDiscounts) {
|
|
|
List<ShopCartItemDto> shopCartItems = shopCartItemDiscount.getShopCartItems();
|
|
|
for (ShopCartItemDto shopCartItem : shopCartItems) {
|
|
|
- //折扣
|
|
|
+ //闁硅埖蓱婢?
|
|
|
if (level.getDiscountType() == 0 || categoryMap.containsKey(shopCartItem.getCategoryId())) {
|
|
|
totalFee = Arith.add(totalFee, shopCartItem.getActualTotal());
|
|
|
}
|