Commit d670eb09d7109a39d572abcd3afd91ed3c8e6f1b

Authored by yvan.ni
1 parent ecdefd73

订单促销的优化

packageE/pages/cart/cart2/cart2.js
... ... @@ -178,7 +178,17 @@ Page({
178 178 yhcx_act_map: {},
179 179  
180 180 //优惠促销购买次数
181   - yhcx_buy_map:{}
  181 + yhcx_buy_map:{},
  182 +
  183 + //-- 订单促销判断积累 ---2024-2-20
  184 + order_prom_map_ck: {
  185 + shop_price_all:0, //手店价的累计
  186 + market_price_all:0, //市场价的累计
  187 + goods_price_all:0, //实收价的累计
  188 + no_ord_price:0, //要累计上不参与订单促销的金额
  189 + goodsList:[],
  190 + },
  191 +
182 192 },
183 193  
184 194  
... ... @@ -1463,8 +1473,6 @@ Page({
1463 1473  
1464 1474  
1465 1475 } else {
1466   -
1467   -
1468 1476 item1.act = th.data.zhhe_act_map[item1.prom_id];
1469 1477 }
1470 1478 }
... ... @@ -2980,6 +2988,9 @@ Page({
2980 2988 }
2981 2989 }
2982 2990  
  2991 + //重置订单促销判断累计
  2992 + this.re_set_order_prom_map_ck();
  2993 +
2983 2994 for (var i in c_arr) {
2984 2995 var cart_item = c_arr[i];
2985 2996 cart_item.prom_pt_json=[];
... ... @@ -3009,7 +3020,7 @@ Page({
3009 3020  
3010 3021 //-- 经纬度不循环调用接口 --
3011 3022 var lon = 0; var lat = 0;
3012   - //---循环购物车---
  3023 + //---循环购物车,按照门店订单进行循环---
3013 3024 for (var i in c_arr) {
3014 3025 //因为搭配购买也是再这里计算,搭配购的is_b_now==1
3015 3026 if (th.data.is_b_now == 0) {
... ... @@ -3053,9 +3064,7 @@ Page({
3053 3064  
3054 3065 //普通券的时候
3055 3066 if (quan_no && th.data.using_quan[pickid].isby != 1) {
3056   -
3057 3067 var IsUserWare=1;
3058   -
3059 3068 //---获取优惠券优惠---
3060 3069 await getApp().request.promiseGet("/api/weshop/couponList/getUseCouponPrice", {
3061 3070 data: {
... ... @@ -3076,13 +3085,10 @@ Page({
3076 3085 quan_price=0;
3077 3086 break;
3078 3087 }
3079   -
3080 3088 }
3081   -
3082 3089 }
3083 3090 })
3084 3091  
3085   -
3086 3092 if(!IsUserWare){
3087 3093  
3088 3094 wx.showToast({
... ... @@ -3115,6 +3121,8 @@ Page({
3115 3121  
3116 3122 if (item[jc].whsle_id > 0) {
3117 3123 whsle_goods_price += item[jc].goods_price * item[jc].goods_num;
  3124 + }else if (item[jc].prom_type == 0) { //如果item的prom_type==0,没有如果活动的时候
  3125 + th.get_order_prom_map_ck(item);
3118 3126 }
3119 3127  
3120 3128 var is_no_zh = 0;
... ... @@ -3124,11 +3132,13 @@ Page({
3124 3132 if (item[jc].prom_type == 7 && th.data.zhhe_act_map && th.data.zhhe_act_map[item[jc].prom_id]
3125 3133 && th.data.zhhe_act_map[item[jc].prom_id].is_orderyh) {
3126 3134 is_no_zh = 1;
  3135 + th.get_order_prom_map_ck(item); //有订单优惠叠加的时候,就要构建数据解救
3127 3136 }
3128 3137 //阶梯购的商品,且有订单优惠的叠加,is_orderyh就是优惠叠加,就要累积阶梯促销的金额
3129 3138 if (item[jc].prom_type == 10 && ladder_prom_goods && ladder_prom_goods[item[jc].prom_id]
3130 3139 && th.data.ladder_map[item[jc].prom_id].is_useorderyh) {
3131 3140 is_no_zh = 1;
  3141 + th.get_order_prom_map_ck(item); //有订单优惠叠加的时候,就要构建数据解救
3132 3142 }
3133 3143  
3134 3144 if (is_no_zh) {
... ... @@ -3144,13 +3154,16 @@ Page({
3144 3154 var gd_price=item[jc].goods_price;
3145 3155 if(item[jc].account_fir) gd_price=item[jc].account_fir;
3146 3156  
3147   -
3148   - //组合购和阶梯购是订单优惠是另外算的
  3157 + //组合购和阶梯购是订单优惠是另外算的,不参与订单促销的时候
3149 3158 if(!item[jc].is_order_yh && !item[jc].whsle_id && item[jc].prom_type!=7 && item[jc].prom_type!=10){
3150 3159 no_order_yh+=gd_price * item[jc].goods_num;
3151 3160 if(item[jc].quan_num) no_order_yh-=item[jc].quan_num; //券要把他补回去
3152   -
3153 3161 }
  3162 + //参与订单促销的时候
  3163 + if(item[jc].is_order_yh && !item[jc].whsle_id && item[jc].prom_type!=7 && item[jc].prom_type!=10){
  3164 + th.get_order_prom_map_ck(item); //有订单优惠叠加的时候,就要构建数据解救
  3165 + }
  3166 +
3154 3167 if(!item[jc].is_post_temp){
3155 3168 no_post_temp+=gd_price * item[jc].goods_num;
3156 3169 if(item[jc].quan_num) no_post_temp-=item[jc].quan_num; //券要把他补回去
... ... @@ -3236,21 +3249,24 @@ Page({
3236 3249 ord_prom_condition=o_price - quan_price - whsle_goods_price - no_order_yh;
3237 3250 }
3238 3251  
  3252 + //判断订单促销的实收价的累计
  3253 + this.data.order_prom_map_ck.goods_price_all=ord_prom_condition;
3239 3254 //---判断是不是有订单优惠---
3240   - await getApp().request.promiseGet("/api/weshop/promorder/getOrderPromotion", {
3241   - data: { store_id: os.stoid, orderAmount: parseFloat(ord_prom_condition).toFixed(2), user_id: getApp().globalData.user_id }
3242   - }).then(res => {
3243   - if (res.data.code == 0) {
3244   - ord_prom = res.data.data;
3245   - }
3246   - })
  3255 + // await getApp().request.promiseGet("/api/weshop/promorder/getOrderPromotion", {
  3256 + // data: { store_id: os.stoid, orderAmount: parseFloat(ord_prom_condition).toFixed(2), user_id: getApp().globalData.user_id }
  3257 + // }).then(res => {
  3258 + // if (res.data.code == 0) {
  3259 + // ord_prom = res.data.data;
  3260 + // }
  3261 + // })
  3262 + //获取当前时间段的进行中的订单促销
  3263 + ord_prom=await th.get_cur_ord_prom();
3247 3264  
3248 3265 //如果有使用优惠券,如何订单促销有控制使用优惠券不参与此活动的话
3249 3266 if(quan_price>0 && ord_prom && ord_prom.is_xz_yh ){
3250 3267 ord_prom=null;
3251 3268 }
3252 3269  
3253   -
3254 3270 //--如果是物流,且选择了地址,就要开始显示包邮券,且包邮券也已经优惠了优惠活动的金额--
3255 3271 if (cart_item.exp_type == 0 && th.data.user_addr != null && !cart_item.is_xz_yh) {
3256 3272  
... ... @@ -3300,10 +3316,24 @@ Page({
3300 3316  
3301 3317 //-- 如果没有订单优惠,或者订单优惠中有勾选包邮模板 --
3302 3318 if (!ord_prom || ord_prom.is_post_temp) {
3303   - var user_addr = th.data.user_addr;
  3319 +
  3320 + let user_addr = th.data.user_addr;
  3321 + let c_wuliu=parseFloat(o_price - quan_price - whsle_goods_price - no_post_temp).toFixed(2);
  3322 +
  3323 + switch (ord_prom && ord_prom.discount_field){
  3324 + case 1:
  3325 +
  3326 + break;
  3327 + case 2:
  3328 +
  3329 +
  3330 + break;
  3331 + }
  3332 +
  3333 +
3304 3334 var req_d = {
3305 3335 province: user_addr.province, city: user_addr.city, district: user_addr.district,
3306   - wuliu: parseFloat(o_price - quan_price - whsle_goods_price - no_post_temp).toFixed(2), store_id: os.stoid
  3336 + wuliu: c_wuliu, store_id: os.stoid
3307 3337 }
3308 3338 await getApp().request.promisePost("/api/weshop/order/areaFreight", {
3309 3339 is_json: 1, data: req_d
... ... @@ -3313,7 +3343,6 @@ Page({
3313 3343 }
3314 3344 }
3315 3345  
3316   -
3317 3346 //如果是包邮券的时候,要看看券的情况
3318 3347 if (quan_no && th.data.using_quan[pickid].isby == 1) {
3319 3348 var quan = th.data.using_quan[pickid];
... ... @@ -3504,23 +3533,28 @@ Page({
3504 3533 }
3505 3534  
3506 3535 var order_m = 0;
3507   -
3508 3536 //么有使用券,或者活动没有限制使用优惠券
3509 3537 if (ord_prom && (quan_price <= 0 || !ord_prom.is_xz_yh)) {
3510 3538 order_prom_id = ord_prom['id'];
3511   - switch (ord_prom['type']) {
3512   - case 0:
3513   - order_m = Math.round(o_condition * ord_prom['expression']) / 100;//满额打折
3514   - order_prom_amount = (o_condition - order_m).toFixed(2);
3515   - break;
3516   - case 1:
3517   - //order_m = o_condition - ord_prom['expression'];//满额优惠金额
3518   - var bs = 1;
3519   - if (ord_prom.is_bz) {
3520   - bs = Math.floor(o_condition / ord_prom.money);
3521   - }
3522   - order_prom_amount = ord_prom['expression'];
3523   - break;
  3539 +
  3540 + if(ord_prom.discount_field>0){
  3541 +
  3542 + }else{
  3543 + //-- 订单促销是按照实收价格进行计算的时候 --
  3544 + switch (ord_prom['type']) {
  3545 + case 0:
  3546 + order_m = Math.round(o_condition * ord_prom['expression']) / 100;//满额打折
  3547 + order_prom_amount = (o_condition - order_m).toFixed(2);
  3548 + break;
  3549 + case 1:
  3550 + //order_m = o_condition - ord_prom['expression'];//满额优惠金额
  3551 + var bs = 1;
  3552 + if (ord_prom.is_bz) {
  3553 + bs = Math.floor(o_condition / ord_prom.money);
  3554 + }
  3555 + order_prom_amount = ord_prom['expression'];
  3556 + break;
  3557 + }
3524 3558 }
3525 3559 }
3526 3560  
... ... @@ -8689,16 +8723,125 @@ Page({
8689 8723  
8690 8724 //原始数据要有深拷贝不能有地址的牵连
8691 8725 th.data.cartlist_y = JSON.parse(JSON.stringify(goods))
8692   -
8693   -
8694 8726 //重新调用cart_next,进行下一步计算
8695 8727 wx.showLoading({
8696 8728 title: "处理中.",
8697 8729 })
8698 8730 this.get_cart_next(null, 1, {prom_type: 0, prom_id: 0});
8699 8731  
  8732 + },
  8733 +
  8734 + //---订单促销累计的数据结构的构建,购物车计算流程的那一部分
  8735 + get_order_prom_map_ck(item) {
  8736 + this.data.order_prom_map_ck.shop_price_all += item.shop_price * item.goods_num;
  8737 + this.data.order_prom_map_ck.market_price_all += item.goods_market_price * item.goods_num;
  8738 + let ite = {
  8739 + id: item.id,
  8740 + goods_id: item.goods_id,
  8741 + goods_num: item.goods_num,
  8742 + prom_type: item.prom_type
  8743 + }
  8744 + this.data.order_prom_map_ck.goodsList.push(item);
  8745 + },
  8746 +
  8747 + //重置订单促销判断累计
  8748 + re_set_order_prom_map_ck() {
  8749 + this.data.order_prom_map_ck = {
  8750 + shop_price_all: 0, //手店价的累计
  8751 + market_price_all: 0, //市场价的累计
  8752 + goodsList: [],
  8753 + }
  8754 + },
  8755 +
  8756 + //获取当前进行中订单促销,同时带入相应的金额判断订单促销是不是运行,同时订单促销的条件不是实收价判断的话,默认的时候,订单促销是不参与运算的
  8757 + async get_cur_ord_prom() {
  8758 + let ord_prom = null;
  8759 + let order_prom_map_ck = this.data.order_prom_map_ck;
  8760 +
  8761 + //获取当前进行中的优惠促销
  8762 + await getApp().request.promiseGet("/api/weshop/promorder/getPromOrder", {
  8763 + data: {
  8764 + store_id: os.stoid,
  8765 + orderAmount: -1, //-1为不判断金额条件
  8766 + user_id: getApp().globalData.user_id
  8767 + }
  8768 + }).then(res => {
  8769 + if (res.data.code == 0) {
  8770 + ord_prom = res.data.data;
  8771 + }
  8772 + })
  8773 +
  8774 + if (!ord_prom) return null;
  8775 + //用于计算订单促销的金额
  8776 + let calculate_price=0;
  8777 + //-- 此时判断活动的金额满足与否 --
  8778 + switch (ord_prom.discount_field) {
  8779 + //实收价的时候
  8780 + case 0:
  8781 + if (ord_prom.money > order_prom_map_ck.goods_price_all){
  8782 + return null;
  8783 + }
  8784 + break;
  8785 + //手店价的时候
  8786 + case 1:
  8787 + if (ord_prom.money > order_prom_map_ck.shop_price_all){
  8788 + return null;
  8789 + }
  8790 + //要显示订单促销使用的按钮
  8791 + this.setData({
  8792 + show_ord_prom: 1,
  8793 + join_ord_prom_goodslist:order_prom_map_ck.goodsList //用于筛选商品的价格选手
  8794 + });
  8795 + //要用户点击了同意使用订单优惠的按钮后,才允许使用订单优惠
  8796 + if (!this.data.can_use_ord_prom) {
  8797 + return null;
  8798 + }
  8799 + calculate_price=order_prom_map_ck.shop_price_all;
  8800 +
  8801 + break;
  8802 + //市场价的时候
  8803 + case 2:
  8804 + if (ord_prom.money > order_prom_map_ck.market_price_all){
  8805 + return null;
  8806 + }
  8807 + //要显示订单促销使用的按钮
  8808 + this.setData({
  8809 + show_ord_prom: 2,
  8810 + join_ord_prom_goodslist:order_prom_map_ck.goodsList //用于筛选商品的价格选手
  8811 + });
  8812 + //要用户点击了同意使用订单优惠的按钮后,才允许使用订单优惠
  8813 + if (!this.data.can_use_ord_prom) {
  8814 + return null;
  8815 + }
  8816 + calculate_price = order_prom_map_ck.market_price_all;
  8817 + break;
  8818 + }
  8819 +
  8820 + if (calculate_price > 0) {
  8821 + //-- 订单促销是按照实收价格进行计算的时候 --
  8822 + switch (ord_prom['type']) {
  8823 + case 0:
  8824 + order_m = Math.round(calculate_price * ord_prom['expression']) / 100;//满额打折
  8825 + order_prom_amount = (calculate_price - order_m).toFixed(2);
  8826 + break;
  8827 + case 1:
  8828 + //order_m = o_condition - ord_prom['expression'];//满额优惠金额
  8829 + var bs = 1;
  8830 + if (ord_prom.is_bz) {
  8831 + bs = Math.floor(calculate_price / ord_prom.money);
  8832 + }
  8833 + order_prom_amount = ord_prom['expression'];
  8834 + break;
  8835 + }
  8836 + //保存到订单促销中,订单促销的金额
  8837 + ord_prom.real_order_prom_amount = order_prom_amount;
  8838 + ord_prom.real_condition_price = calculate_price;
  8839 + }
  8840 + return ord_prom;
8700 8841  
8701 8842 }
8702 8843  
8703 8844  
  8845 +
  8846 +
8704 8847 });
... ...
packageE/pages/cart/cart2/cart2.wxml
... ... @@ -107,7 +107,8 @@
107 107  
108 108 <!-----商品名称规格------>
109 109 <view class="order-num flex-space-between">
110   - <view wx:if="{{items.prom_type==10}}" class="co-red">¥<text class="fs36">{{filters.toFix(items.goods_price,2)}}</text><text>({{items.discount}}折)</text></view>
  110 + <view wx:if="{{can_use_ord_prom}}" class="co-red">¥<text class="fs36">{{util.fm_join_ord_prom_price(items,join_ord_prom_goodslist,item.show_ord_prom,2)}}</text></view>
  111 + <view wx:elif="{{items.prom_type==10}}" class="co-red">¥<text class="fs36">{{filters.toFix(items.goods_price,2)}}</text><text>({{items.discount}}折)</text></view>
111 112 <view wx:else class="co-red">¥<text class="fs36">{{filters.toFix(items.goods_price,2)}}</text></view>
112 113 <view style="color: red;" wx:if="{{items.use_commission && items.use_commission*1>0}}">佣金:{{filters.toFix(items.use_commission/items.goods_num,2)}}*{{items.goods_num}}</view>
113 114 <view class="goods-num">x{{items.goods_num}}</view>
... ...
packageE/pages/cart/cart2/filter.wxs
... ... @@ -49,14 +49,38 @@ function check_is_last(index,goods_id){
49 49 return true;
50 50 }
51 51 return false;
52   -
53 52 }
54 53  
  54 +//-- 用于筛选商品的价格显示 --
  55 +function fm_join_ord_prom_price(gd,join_gd_list,show_ord_prom,count){
  56 + var price=gd.goods_price;
  57 + //在join_gd_list中查找是否已经存在gd商品,靠购物车的id来判断
  58 + for(var i=0;i<join_gd_list.length;i++){
  59 + var jgd=join_gd_list[i];
  60 + if(jgd.id==gd.id){
  61 + switch (show_ord_prom){
  62 + case 1:
  63 + price=gd.shop_price;
  64 + break;
  65 + case 2:
  66 + price=gd.goods_market_price;
  67 + break;
  68 + }
  69 + break;
  70 + }
  71 + }
  72 + if (!price) {
  73 + return parseFloat(0).toFixed(count);
  74 + }
  75 + val = parseFloat(val);
  76 + return val.toFixed(count);
  77 +}
55 78  
56 79  
57 80 module.exports = {
58 81 format: format,
59 82 is_more_act:is_more_act,
60 83 check_show:check_show,
61   - check_is_last:check_is_last
  84 + check_is_last:check_is_last,
  85 + fm_join_ord_prom_price:fm_join_ord_prom_price,
62 86 }
... ...