Commit 5eb612205b83da421b6870207e6900f735a7b152

Authored by yvan.ni
1 parent 87f42fd5

订单促销的取价规则

packageE/pages/cart/cart2/cart2.js
@@ -1042,35 +1042,9 @@ Page({ @@ -1042,35 +1042,9 @@ Page({
1042 //-- 多促销活动调用接口需要的参数,和商品的购买数量和活动的购买数量的请求参数 -- 1042 //-- 多促销活动调用接口需要的参数,和商品的购买数量和活动的购买数量的请求参数 --
1043 var dug_cx_arr = []; 1043 var dug_cx_arr = [];
1044 //获取 限购 和 多活动的促销---2024-2-1 1044 //获取 限购 和 多活动的促销---2024-2-1
1045 - for (var i = 0; i < carr.length; i++) {  
1046 -  
1047 - let item1 = carr[i];  
1048 -  
1049 - //如果有户有点击参与订单促销的话,那么可以参与订单促销的商品的活动都要清理成0,订单促销在使用过程中的重要方法  
1050 - if (this.data.can_use_ord_prom[item1.pick_id]) {  
1051 - //从订单促销的order_prom_map_ck数据结构中获取到可以参与的商品列表  
1052 - let gdlist = this.data.order_prom_map_ck[item1.pick_id] ? this.data.order_prom_map_ck[item1.pick_id].goodsList : null;  
1053 - if (gdlist && gdlist.length) {  
1054 - //查找商品item1有没有在gdlist中,就要把商品的prom_type清理0  
1055 - let f_idx = gdlist.findIndex(function (ele) {  
1056 - return ele.id == item1.id  
1057 - });  
1058 - if (f_idx != -1) {  
1059 - //开始变换商品的价格显示  
1060 - switch (th.data.show_ord_prom[item1.pick_id]) {  
1061 - case 1:  
1062 - carr[i].goods_price = item1.shop_price;  
1063 - break;  
1064 - case 2:  
1065 - carr[i].goods_price = item1.goods_market_price;  
1066 - break;  
1067 - }  
1068 - carr[i].prom_type = 0;  
1069 - continue; //要跳过  
1070 - }  
1071 - }  
1072 - } 1045 + for (var iv = 0; iv < carr.length; iv++) {
1073 1046
  1047 + let item1 = carr[iv];
1074 //如果不是活动的时候,不是代发商品的时候,不是赠品的时候,不是阶梯商品拆分的,不是组合购拆分的 1048 //如果不是活动的时候,不是代发商品的时候,不是赠品的时候,不是阶梯商品拆分的,不是组合购拆分的
1075 if ([1, 2, 4, 6, 8, 9].indexOf(item1.prom_type) == -1 && !item1.whsle_id 1049 if ([1, 2, 4, 6, 8, 9].indexOf(item1.prom_type) == -1 && !item1.whsle_id
1076 && !item1.is_gift && !item1.is_ld_split && !item1.is_zh_split) { 1050 && !item1.is_gift && !item1.is_ld_split && !item1.is_zh_split) {
@@ -1080,7 +1054,7 @@ Page({ @@ -1080,7 +1054,7 @@ Page({
1080 }); 1054 });
1081 if (f_idx == -1) { 1055 if (f_idx == -1) {
1082 let gd_ite = { 1056 let gd_ite = {
1083 - goods_id: carr[i].goods_id, 1057 + goods_id: carr[iv].goods_id,
1084 goods_num: 1, 1058 goods_num: 1,
1085 is_limit_show: 1, 1059 is_limit_show: 1,
1086 is_state: 0 1060 is_state: 0
@@ -1091,7 +1065,7 @@ Page({ @@ -1091,7 +1065,7 @@ Page({
1091 } 1065 }
1092 1066
1093 if (is_change) { 1067 if (is_change) {
1094 - carr[i].collocationList = null; 1068 + carr[iv].collocationList = null;
1095 } 1069 }
1096 } 1070 }
1097 //-- 对商品的多促销进行判断 ---2024-2-1-- 1071 //-- 对商品的多促销进行判断 ---2024-2-1--
@@ -1099,9 +1073,46 @@ Page({ @@ -1099,9 +1073,46 @@ Page({
1099 await th.buy_pro_group(dug_cx_arr,carr); 1073 await th.buy_pro_group(dug_cx_arr,carr);
1100 } 1074 }
1101 } 1075 }
  1076 +
1102 //在分组的时候,就不要再调用接口,await 1077 //在分组的时候,就不要再调用接口,await
1103 for (var i = 0; i < carr.length; i++) { 1078 for (var i = 0; i < carr.length; i++) {
1104 var item = carr[i]; 1079 var item = carr[i];
  1080 +
  1081 + //如果有户有点击参与订单促销的话,那么可以参与订单促销的商品的活动都要清理成0,订单促销在使用过程中的重要方法
  1082 + if (this.data.can_use_ord_prom[item.pick_id]) {
  1083 + //从订单促销的order_prom_map_ck数据结构中获取到可以参与的商品列表
  1084 + let gdlist = this.data.order_prom_map_ck[item.pick_id] ? this.data.order_prom_map_ck[item.pick_id].goodsList : null;
  1085 + if (gdlist && gdlist.length) {
  1086 + //查找商品item1有没有在gdlist中,就要把商品的prom_type清理0
  1087 + let f_idx = gdlist.findIndex(function (ele) {
  1088 + return ele.id == item1.id
  1089 + });
  1090 + if (f_idx != -1) {
  1091 + //开始变换商品的价格显示
  1092 + switch (th.data.show_ord_prom[item1.pick_id]) {
  1093 + case 1:
  1094 + carr[i].goods_price = item1.shop_price;
  1095 + break;
  1096 + case 2:
  1097 + carr[i].goods_price = item1.goods_market_price;
  1098 + break;
  1099 + }
  1100 +
  1101 + if(!carr[i].prom_type) carr[i].prom_type=0;
  1102 + switch (parseInt(carr[i].prom_type)){
  1103 + case 4:
  1104 + carr[i].is_integral_normal = 1;
  1105 + break;
  1106 + default:
  1107 + carr[i].is_pd_normal = 1;
  1108 + break;
  1109 + }
  1110 + carr[i].prom_type = 0;
  1111 + carr[i].discount_field = th.data.show_ord_prom[item1.pick_id];
  1112 + }
  1113 + }
  1114 + }
  1115 +
1105 //-- 如果是等级会员注册返回 -- 1116 //-- 如果是等级会员注册返回 --
1106 if (is_card_back) { 1117 if (is_card_back) {
1107 th.data.card_name = th.data.userinfo.card_field; 1118 th.data.card_name = th.data.userinfo.card_field;
@@ -4950,6 +4961,12 @@ Page({ @@ -4950,6 +4961,12 @@ Page({
4950 'prom_id': th.data.bn_goods.prom_id, //促销活动id 4961 'prom_id': th.data.bn_goods.prom_id, //促销活动id
4951 }; 4962 };
4952 4963
  4964 + //如果有参与非实收的订单促销,那么就相当于是普通购买
  4965 + if(th.data.can_use_ord_prom[th.data.bn_pick]){
  4966 + goods.is_pd_normal=1;
  4967 + goods.discount_field= th.data.show_ord_prom[th.data.bn_pick];
  4968 + }
  4969 +
4953 if (th.data.bn_goods.whsle_id) { 4970 if (th.data.bn_goods.whsle_id) {
4954 item.is_whsle = 1; 4971 item.is_whsle = 1;
4955 item.whsle_id = th.data.bn_goods.whsle_id; 4972 item.whsle_id = th.data.bn_goods.whsle_id;
@@ -5343,6 +5360,11 @@ Page({ @@ -5343,6 +5360,11 @@ Page({
5343 'store_id': oo.stoid, 5360 'store_id': oo.stoid,
5344 }; 5361 };
5345 5362
  5363 + //订单促销取价规则使用
  5364 + if (g_item.discount_field) {
  5365 + goods.discount_field =g_item.discount_field;
  5366 + }
  5367 +
5346 if (g_item.is_pd_normal) { 5368 if (g_item.is_pd_normal) {
5347 goods.is_pd_normal = 1; 5369 goods.is_pd_normal = 1;
5348 } 5370 }
@@ -9012,6 +9034,10 @@ Page({ @@ -9012,6 +9034,10 @@ Page({
9012 good.shop_price=good.market_price; 9034 good.shop_price=good.market_price;
9013 break; 9035 break;
9014 } 9036 }
  9037 +
  9038 + //-- 转成普通商品 ---
  9039 + good.prom_type=0;
  9040 + good.prom_id=0;
9015 }else{ 9041 }else{
9016 good=ut.deep_cp(th.data.old_bn_goods); 9042 good=ut.deep_cp(th.data.old_bn_goods);
9017 } 9043 }
packageE/pages/cart/cart2/cart2.wxml
@@ -355,9 +355,9 @@ @@ -355,9 +355,9 @@
355 355
356 <!-- 订单促销取价规则的优化 --> 356 <!-- 订单促销取价规则的优化 -->
357 <view class="set-mes" wx:if="{{show_ord_prom[item.pickup_id]}}"> 357 <view class="set-mes" wx:if="{{show_ord_prom[item.pickup_id]}}">
358 - <view class="use-item" data-pd="{{item.pickup_id}}" bindtap='set_can_use_ord_prom'>  
359 - <icon color="{{can_use_ord_prom[item.pickup_id]?'red':'gray'}}" size="16" type="success"></icon>  
360 - <view class="yu_er">参与订单促销</view> 358 + <view class="use-item" >
  359 + <icon data-pd="{{item.pickup_id}}" bindtap='set_can_use_ord_prom' color="{{can_use_ord_prom[item.pickup_id]?'red':'gray'}}" size="16" type="success"></icon>
  360 + <view data-pd="{{item.pickup_id}}" bindtap='set_can_use_ord_prom' class="yu_er">参与订单促销</view>
361 </view> 361 </view>
362 </view> 362 </view>
363 363
@@ -695,9 +695,9 @@ @@ -695,9 +695,9 @@
695 695
696 <!-- 订单促销取价规则的优化 --> 696 <!-- 订单促销取价规则的优化 -->
697 <view class="set-mes" wx:if="{{show_ord_prom[bn_pick]}}"> 697 <view class="set-mes" wx:if="{{show_ord_prom[bn_pick]}}">
698 - <view class="use-item" bindtap='set_can_use_ord_prom_now'>  
699 - <icon color="{{can_use_ord_prom[bn_pick]?'red':'gray'}}" size="16" type="success"></icon>  
700 - <view class="yu_er">参与订单促销</view> 698 + <view class="use-item" >
  699 + <icon bindtap='set_can_use_ord_prom_now' color="{{can_use_ord_prom[bn_pick]?'red':'gray'}}" size="16" type="success"></icon>
  700 + <view bindtap='set_can_use_ord_prom_now' class="yu_er">参与订单促销</view>
701 </view> 701 </view>
702 </view> 702 </view>
703 703
packageE/pages/cart/cart2_inte/cart2_inte.js
@@ -85,7 +85,14 @@ Page({ @@ -85,7 +85,14 @@ Page({
85 same_ok:1, //同城配送的控制,默认ok 85 same_ok:1, //同城配送的控制,默认ok
86 bconfig: null, 86 bconfig: null,
87 showFold:true, 87 showFold:true,
88 - template_id:[] 88 + template_id:[],
  89 +
  90 + //-- 订单促销判断积累 ---2024-2-20
  91 + order_prom_map_ck: {},
  92 + //能不能使用订单促销
  93 + can_use_ord_prom:{},
  94 + //存储订单促销的取价,按照门店进行索引
  95 + show_ord_prom:{},
89 }, 96 },
90 97
91 98
@@ -632,6 +639,8 @@ Page({ @@ -632,6 +639,8 @@ Page({
632 success: async function (tt) { 639 success: async function (tt) {
633 if (tt.data.code == 0 && tt.data.data && tt.data.data.pageData) { 640 if (tt.data.code == 0 && tt.data.data && tt.data.data.pageData) {
634 var inte_data = tt.data.data.pageData[0]; 641 var inte_data = tt.data.data.pageData[0];
  642 +
  643 + gd.shop_price_y=gd.shop_price;
635 t.data.data.shop_price = inte_data.addmoney; 644 t.data.data.shop_price = inte_data.addmoney;
636 t.data.data.integral = inte_data.integral; 645 t.data.data.integral = inte_data.integral;
637 646
@@ -658,6 +667,9 @@ Page({ @@ -658,6 +667,9 @@ Page({
658 667
659 668
660 669
  670 + //用深拷贝把商品缓存起来,方便后面使用
  671 + th.data.old_bn_goods=ut.deep_cp(t.data.data);
  672 +
661 th.setData({ 673 th.setData({
662 bn_goods: t.data.data, bn_pickname: gg.pick_name, bn_exp_type: et, index: m_wind, 674 bn_goods: t.data.data, bn_pickname: gg.pick_name, bn_exp_type: et, index: m_wind,
663 bn_pick: gg.pick_id, bn_t_exp_t: distr_t, bn_exp_type: et,inv_is_post:inte_data.is_post 675 bn_pick: gg.pick_id, bn_t_exp_t: distr_t, bn_exp_type: et,inv_is_post:inte_data.is_post
@@ -742,16 +754,23 @@ Page({ @@ -742,16 +754,23 @@ Page({
742 var condition = parseFloat(allpice-cut_price).toFixed(2); 754 var condition = parseFloat(allpice-cut_price).toFixed(2);
743 var ord_prom = null; 755 var ord_prom = null;
744 var is_ord_prom_post = 0; 756 var is_ord_prom_post = 0;
  757 + //---如果有选择优惠券的情况下---
  758 + var quan_price = 0, bn_pick = th.data.bn_pick;
745 759
746 if (condition > 0 && th.data.bn_is_order_yh && !th.data.bn_goods.whsle_id) { 760 if (condition > 0 && th.data.bn_is_order_yh && !th.data.bn_goods.whsle_id) {
747 - await getApp().request.promiseGet("/api/weshop/promorder/getOrderPromotion", {  
748 - data: { store_id: os.stoid, orderAmount: condition, user_id: getApp().globalData.user_id }  
749 - }).then(res => {  
750 - if (res.data.code == 0) {  
751 - var data = res.data.data;  
752 - ord_prom = data;  
753 - }  
754 - }) 761 + // await getApp().request.promiseGet("/api/weshop/promorder/getOrderPromotion", {
  762 + // data: { store_id: os.stoid, orderAmount: condition, user_id: getApp().globalData.user_id }
  763 + // }).then(res => {
  764 + // if (res.data.code == 0) {
  765 + // var data = res.data.data;
  766 + // ord_prom = data;
  767 + // }
  768 + // })
  769 +
  770 + th.set_by_now_ord_prom(th.data.bn_goods);
  771 + th.data.order_prom_map_ck[bn_pick].goods_price_all=condition;
  772 + ord_prom=await th.get_cur_ord_prom(bn_pick);
  773 +
755 if (ord_prom && ord_prom.is_post_temp) { 774 if (ord_prom && ord_prom.is_post_temp) {
756 is_ord_prom_post = 1; 775 is_ord_prom_post = 1;
757 } 776 }
@@ -894,8 +913,7 @@ Page({ @@ -894,8 +913,7 @@ Page({
894 var wl_txt = "formData.shipping_price"; 913 var wl_txt = "formData.shipping_price";
895 th.setData({ [wl_txt]: 0, }) 914 th.setData({ [wl_txt]: 0, })
896 } 915 }
897 - //---如果有选择优惠券的情况下---  
898 - var quan_price = 0, bn_pick = th.data.bn_pick; 916 +
899 917
900 //-----------------支付价,优惠券不减物流----------------- 918 //-----------------支付价,优惠券不减物流-----------------
901 var total_m = (parseFloat(allpice)).toFixed(2); 919 var total_m = (parseFloat(allpice)).toFixed(2);
@@ -1281,7 +1299,6 @@ Page({ @@ -1281,7 +1299,6 @@ Page({
1281 item.samecity_order_amount=th.data.bn_samecity_order_amount; 1299 item.samecity_order_amount=th.data.bn_samecity_order_amount;
1282 } 1300 }
1283 1301
1284 -  
1285 //获取立即购买的商品的信息 1302 //获取立即购买的商品的信息
1286 var gg = to.get_b_now(); 1303 var gg = to.get_b_now();
1287 //--商品的房间号-- 1304 //--商品的房间号--
@@ -1319,6 +1336,15 @@ Page({ @@ -1319,6 +1336,15 @@ Page({
1319 'prom_id': th.data.bn_goods.prom_id, //促销活动id 1336 'prom_id': th.data.bn_goods.prom_id, //促销活动id
1320 }; 1337 };
1321 1338
  1339 + if(th.data.bn_goods.discount_field){
  1340 + goods.discount_field=th.data.bn_goods.discount_field;
  1341 + }
  1342 +
  1343 + //如果有参与非实收的订单促销,那么就相当于是普通购买
  1344 + if(th.data.can_use_ord_prom[th.data.bn_pick]){
  1345 + goods.is_integral_normal=1;
  1346 + }
  1347 +
1322 if(getApp().globalData.skinface_id){ 1348 if(getApp().globalData.skinface_id){
1323 goods.skinface_id=getApp().globalData.skinface_id; 1349 goods.skinface_id=getApp().globalData.skinface_id;
1324 } 1350 }
@@ -1757,7 +1783,146 @@ Page({ @@ -1757,7 +1783,146 @@ Page({
1757 var th = this; 1783 var th = this;
1758 th.setData({bn_use_commission: !th.data.bn_use_commission}); 1784 th.setData({bn_use_commission: !th.data.bn_use_commission});
1759 th.calculatePrice2(); 1785 th.calculatePrice2();
  1786 + },
  1787 +
  1788 + //-- 获取订单促销的判断结构 --
  1789 + set_by_now_ord_prom(item){
  1790 + let pickid=this.data.bn_pick;
  1791 + let order_prom_map_ck= this.data.order_prom_map_ck;
  1792 + order_prom_map_ck[pickid]={
  1793 + shop_price_all:0, //手店价的累计
  1794 + market_price_all:0, //市场价的累计
  1795 + goods_price_all:0, //实收价的累计
  1796 + no_ord_price:0, //要累计上不参与订单促销的金额
  1797 + goodsList:[],
  1798 + }
  1799 +
  1800 + let pk_ord_map=order_prom_map_ck[pickid];
  1801 + pk_ord_map.shop_price_all += item.shop_price_y * item.buynum;
  1802 + pk_ord_map.market_price_all += item.goods_market_price * item.buynum;
  1803 +
  1804 + },
  1805 +
  1806 + //获取当前进行中订单促销,同时带入相应的金额判断订单促销是不是运行,同时订单促销的条件不是实收价判断的话,默认的时候,订单促销是不参与运算的
  1807 + async get_cur_ord_prom(pickid) {
  1808 + let ord_prom = null;
  1809 + let order_prom_map_ck = this.data.order_prom_map_ck[pickid];
  1810 + if(!order_prom_map_ck) return null;
  1811 +
  1812 + //获取当前进行中的优惠促销
  1813 + await getApp().request.promiseGet("/api/weshop/promorder/getPromOrder", {
  1814 + data: {
  1815 + store_id: os.stoid,
  1816 + orderAmount: -1, //-1为不判断金额条件
  1817 + user_id: getApp().globalData.user_id
  1818 + }
  1819 + }).then(res => {
  1820 + if (res.data.code == 0) {
  1821 + ord_prom = res.data.data;
  1822 + }
  1823 + })
  1824 +
  1825 + if (!ord_prom) return null;
  1826 + //用于计算订单促销的金额
  1827 + let calculate_price=0;
  1828 +
  1829 + let txt1='show_ord_prom['+pickid+']';
  1830 + //-- 此时判断活动的金额满足与否 --
  1831 + switch (ord_prom.discount_field) {
  1832 + //实收价的时候
  1833 + case 0:
  1834 + //要先还原
  1835 + this.setData({
  1836 + [txt1]: 0
  1837 + });
  1838 +
  1839 + if (ord_prom.money > order_prom_map_ck.goods_price_all){
  1840 + return null;
  1841 + }
  1842 + break;
  1843 + //手店价的时候
  1844 + case 1:
  1845 + if (ord_prom.money > order_prom_map_ck.shop_price_all){
  1846 + //要先还原
  1847 + this.setData({
  1848 + [txt1]: 0
  1849 + });
  1850 + return null;
  1851 + }
  1852 + //要显示订单促销使用的按钮
  1853 + this.setData({
  1854 + [txt1]: 1
  1855 + });
  1856 + break;
  1857 + //市场价的时候
  1858 + case 2:
  1859 + if (ord_prom.money > order_prom_map_ck.market_price_all){
  1860 + //要先还原
  1861 + this.setData({
  1862 + [txt1]: 0
  1863 + });
  1864 + return null;
  1865 + }
  1866 + //要显示订单促销使用的按钮
  1867 + this.setData({
  1868 + [txt1]: 2
  1869 + });
  1870 + break;
  1871 + }
  1872 + //如果订单促销是不参与订单促销的,那么就直接返回null(订单促销不是实收价的时候)
  1873 + if(ord_prom.discount_field>0 && !this.data.can_use_ord_prom[pickid]){
  1874 + return null;
  1875 + }
  1876 + return ord_prom;
  1877 + },
  1878 +
  1879 + //立即购买的时候,点击订单促销的参与
  1880 + set_can_use_ord_prom_now:function (e){
  1881 +
  1882 + if(this.data.submit) return false;
  1883 + this.setData({ submit: 1,same_ok:1 });
  1884 +
  1885 + let pickid=this.data.bn_pick;
  1886 + let txt = 'can_use_ord_prom[' + pickid + ']';
  1887 + let can_use = this.data.can_use_ord_prom[pickid] ? this.data.can_use_ord_prom[pickid] : 0;
  1888 + this.setData({
  1889 + [txt]: !can_use
  1890 + })
  1891 +
  1892 + let th=this;
  1893 + let good=th.data.bn_goods;
  1894 +
  1895 + //如果有要参与订单促销的按钮点击后,要修改商品的价格
  1896 + if(th.data.can_use_ord_prom[pickid]){
  1897 + let discount_field=th.data.show_ord_prom[pickid];
  1898 + switch (discount_field){
  1899 + case 1:
  1900 + good.shop_price=good.shop_price_y;
  1901 + break;
  1902 + case 2:
  1903 + good.shop_price=good.market_price;
  1904 + break;
  1905 + }
  1906 + //-- 转成普通商品 ---
  1907 + good.prom_type=0;
  1908 + good.prom_id=0;
  1909 + good.integral=0;
  1910 + good.discount_field=discount_field;
  1911 +
  1912 + }else{
  1913 + good=ut.deep_cp(th.data.old_bn_goods);
  1914 + }
  1915 +
  1916 + th.setData({
  1917 + bn_goods:good
  1918 + })
  1919 + wx.showLoading({
  1920 + title: "处理中.",
  1921 + mark:true
  1922 + })
  1923 + th.calculatePrice2()
1760 } 1924 }
1761 1925
1762 1926
  1927 +
1763 }); 1928 });
packageE/pages/cart/cart2_inte/cart2_inte.wxml
@@ -94,6 +94,14 @@ @@ -94,6 +94,14 @@
94 <icon color="#f23030" size="16" type="info"></icon>{{order.store_prom}} 94 <icon color="#f23030" size="16" type="info"></icon>{{order.store_prom}}
95 </view> 95 </view>
96 96
  97 + <!-- 订单促销取价规则的优化 -->
  98 + <view class="set-mes" wx:if="{{show_ord_prom[bn_pick]}}">
  99 + <view class="use-item" >
  100 + <icon bindtap='set_can_use_ord_prom_now' color="{{can_use_ord_prom[bn_pick]?'red':'gray'}}" size="16" type="success"></icon>
  101 + <view bindtap='set_can_use_ord_prom_now' class="yu_er">参与订单促销</view>
  102 + </view>
  103 + </view>
  104 +
97 <view class="xc-coupon-frame flex-center" data-bn="1" bindtap="open_coupon_list" data-pickid="{{bn_pick}}" wx:if="{{(selected_quan_list && selected_quan_list.length>0) || get_by_quan_list!=null}}"> 105 <view class="xc-coupon-frame flex-center" data-bn="1" bindtap="open_coupon_list" data-pickid="{{bn_pick}}" wx:if="{{(selected_quan_list && selected_quan_list.length>0) || get_by_quan_list!=null}}">
98 <view class="work-frame flex-space-between"> 106 <view class="work-frame flex-space-between">
99 <view class="work"> 107 <view class="work">
packageE/pages/cart/cart2_pt/cart2_pt.js
@@ -90,6 +90,13 @@ Page({ @@ -90,6 +90,13 @@ Page({
90 is_no_by: {}, 90 is_no_by: {},
91 is_by: {}, 91 is_by: {},
92 is_quan_by: {}, 92 is_quan_by: {},
  93 +
  94 + //-- 订单促销判断积累 ---2024-2-20
  95 + order_prom_map_ck: {},
  96 + //能不能使用订单促销
  97 + can_use_ord_prom:{},
  98 + //存储订单促销的取价,按照门店进行索引
  99 + show_ord_prom:{},
93 }, 100 },
94 101
95 102
@@ -444,7 +451,9 @@ Page({ @@ -444,7 +451,9 @@ Page({
444 et = 2; 451 et = 2;
445 } 452 }
446 453
  454 + t.data.data.shop_price_y=t.data.data.shop_price
447 t.data.data.shop_price = gg.goods_price; 455 t.data.data.shop_price = gg.goods_price;
  456 +
448 //--如果是普通购买的时候-- 457 //--如果是普通购买的时候--
449 if (gg.is_normal == 1) { 458 if (gg.is_normal == 1) {
450 t.data.data.prom_id = 0; 459 t.data.data.prom_id = 0;
@@ -485,6 +494,8 @@ Page({ @@ -485,6 +494,8 @@ Page({
485 494
486 } 495 }
487 496
  497 + //用深拷贝把商品缓存起来,方便后面使用
  498 + th.data.old_bn_goods=ut.deep_cp(t.data.data);
488 499
489 th.setData({ 500 th.setData({
490 bn_goods: t.data.data, bn_pickname: gg.pick_name, 501 bn_goods: t.data.data, bn_pickname: gg.pick_name,
@@ -568,7 +579,6 @@ Page({ @@ -568,7 +579,6 @@ Page({
568 et = th.data.bn_exp_type; 579 et = th.data.bn_exp_type;
569 } 580 }
570 581
571 -  
572 //-- 计算获得佣金的金额 -- 582 //-- 计算获得佣金的金额 --
573 if (getApp().globalData.userInfo.is_distribut 583 if (getApp().globalData.userInfo.is_distribut
574 && th.data.dis_config && th.data.dis_config.is_yongjin_dk) { 584 && th.data.dis_config && th.data.dis_config.is_yongjin_dk) {
@@ -591,6 +601,8 @@ Page({ @@ -591,6 +601,8 @@ Page({
591 601
592 } 602 }
593 603
  604 + //用深拷贝把商品缓存起来,方便后面使用
  605 + th.data.old_bn_goods=ut.deep_cp(t.data.data);
594 606
595 th.setData({ 607 th.setData({
596 bn_goods: t.data.data, bn_pickname: gg.pick_name, 608 bn_goods: t.data.data, bn_pickname: gg.pick_name,
@@ -834,13 +846,17 @@ Page({ @@ -834,13 +846,17 @@ Page({
834 846
835 if(th.data.bn_is_order_yh && th.data.kt_type != 3 ){ 847 if(th.data.bn_is_order_yh && th.data.kt_type != 3 ){
836 848
837 - await getApp().request.promiseGet("/api/weshop/promorder/getOrderPromotion", {  
838 - data: { store_id: os.stoid, orderAmount: o_condition, user_id: getApp().globalData.user_id }  
839 - }).then(res => {  
840 - if (res.data.code == 0) {  
841 - ord_prom = res.data.data;  
842 - }  
843 - }) 849 + // await getApp().request.promiseGet("/api/weshop/promorder/getOrderPromotion", {
  850 + // data: { store_id: os.stoid, orderAmount: o_condition, user_id: getApp().globalData.user_id }
  851 + // }).then(res => {
  852 + // if (res.data.code == 0) {
  853 + // ord_prom = res.data.data;
  854 + // }
  855 + // })
  856 +
  857 + th.set_by_now_ord_prom(th.data.bn_goods);
  858 + th.data.order_prom_map_ck[bn_pick].goods_price_all=condition;
  859 + ord_prom=await th.get_cur_ord_prom(bn_pick);
844 } 860 }
845 861
846 862
@@ -2260,6 +2276,142 @@ Page({ @@ -2260,6 +2276,142 @@ Page({
2260 th.setData({ open_quan: 0 }); 2276 th.setData({ open_quan: 0 });
2261 }, 2277 },
2262 2278
  2279 + //-- 获取订单促销的判断结构 --
  2280 + set_by_now_ord_prom(item){
  2281 + let pickid=this.data.bn_pick;
  2282 + let order_prom_map_ck= this.data.order_prom_map_ck;
  2283 + order_prom_map_ck[pickid]={
  2284 + shop_price_all:0, //手店价的累计
  2285 + market_price_all:0, //市场价的累计
  2286 + goods_price_all:0, //实收价的累计
  2287 + no_ord_price:0, //要累计上不参与订单促销的金额
  2288 + goodsList:[],
  2289 + }
  2290 +
  2291 + let pk_ord_map=order_prom_map_ck[pickid];
  2292 + pk_ord_map.shop_price_all += item.shop_price_y * item.buynum;
  2293 + pk_ord_map.market_price_all += item.goods_market_price * item.buynum;
  2294 +
  2295 + },
  2296 +
  2297 + //获取当前进行中订单促销,同时带入相应的金额判断订单促销是不是运行,同时订单促销的条件不是实收价判断的话,默认的时候,订单促销是不参与运算的
  2298 + async get_cur_ord_prom(pickid) {
  2299 + let ord_prom = null;
  2300 + let order_prom_map_ck = this.data.order_prom_map_ck[pickid];
  2301 + if(!order_prom_map_ck) return null;
  2302 +
  2303 + //获取当前进行中的优惠促销
  2304 + await getApp().request.promiseGet("/api/weshop/promorder/getPromOrder", {
  2305 + data: {
  2306 + store_id: os.stoid,
  2307 + orderAmount: -1, //-1为不判断金额条件
  2308 + user_id: getApp().globalData.user_id
  2309 + }
  2310 + }).then(res => {
  2311 + if (res.data.code == 0) {
  2312 + ord_prom = res.data.data;
  2313 + }
  2314 + })
  2315 +
  2316 + if (!ord_prom) return null;
  2317 + //用于计算订单促销的金额
  2318 + let calculate_price=0;
  2319 +
  2320 + let txt1='show_ord_prom['+pickid+']';
  2321 + //-- 此时判断活动的金额满足与否 --
  2322 + switch (ord_prom.discount_field) {
  2323 + //实收价的时候
  2324 + case 0:
  2325 + //要先还原
  2326 + this.setData({
  2327 + [txt1]: 0
  2328 + });
  2329 +
  2330 + if (ord_prom.money > order_prom_map_ck.goods_price_all){
  2331 + return null;
  2332 + }
  2333 + break;
  2334 + //手店价的时候
  2335 + case 1:
  2336 + if (ord_prom.money > order_prom_map_ck.shop_price_all){
  2337 + //要先还原
  2338 + this.setData({
  2339 + [txt1]: 0
  2340 + });
  2341 + return null;
  2342 + }
  2343 + //要显示订单促销使用的按钮
  2344 + this.setData({
  2345 + [txt1]: 1
  2346 + });
  2347 + break;
  2348 + //市场价的时候
  2349 + case 2:
  2350 + if (ord_prom.money > order_prom_map_ck.market_price_all){
  2351 + //要先还原
  2352 + this.setData({
  2353 + [txt1]: 0
  2354 + });
  2355 + return null;
  2356 + }
  2357 + //要显示订单促销使用的按钮
  2358 + this.setData({
  2359 + [txt1]: 2
  2360 + });
  2361 + break;
  2362 + }
  2363 + //如果订单促销是不参与订单促销的,那么就直接返回null(订单促销不是实收价的时候)
  2364 + if(ord_prom.discount_field>0 && !this.data.can_use_ord_prom[pickid]){
  2365 + return null;
  2366 + }
  2367 + return ord_prom;
  2368 + },
  2369 +
  2370 + //立即购买的时候,点击订单促销的参与
  2371 + set_can_use_ord_prom_now:function (e){
  2372 +
  2373 + if(this.data.submit) return false;
  2374 + this.setData({ submit: 1,same_ok:1 });
  2375 +
  2376 + let pickid=this.data.bn_pick;
  2377 + let txt = 'can_use_ord_prom[' + pickid + ']';
  2378 + let can_use = this.data.can_use_ord_prom[pickid] ? this.data.can_use_ord_prom[pickid] : 0;
  2379 + this.setData({
  2380 + [txt]: !can_use
  2381 + })
  2382 +
  2383 + let th=this;
  2384 + let good=th.data.bn_goods;
  2385 +
  2386 + //如果有要参与订单促销的按钮点击后,要修改商品的价格
  2387 + if(th.data.can_use_ord_prom[pickid]){
  2388 + let discount_field=th.data.show_ord_prom[pickid];
  2389 + switch (discount_field){
  2390 + case 1:
  2391 + good.shop_price=good.shop_price_y;
  2392 + break;
  2393 + case 2:
  2394 + good.shop_price=good.market_price;
  2395 + break;
  2396 + }
  2397 + //-- 转成普通商品 ---
  2398 + good.prom_type=0;
  2399 + good.prom_id=0;
  2400 + good.discount_field=discount_field;
  2401 + }else{
  2402 + good=ut.deep_cp(th.data.old_bn_goods);
  2403 + }
  2404 +
  2405 + th.setData({
  2406 + bn_goods:good
  2407 + })
  2408 + wx.showLoading({
  2409 + title: "处理中.",
  2410 + mark:true
  2411 + })
  2412 + th.calculatePrice2()
  2413 + }
  2414 +
2263 2415
2264 2416
2265 2417
packageE/pages/cart/cart2_pt/cart2_pt.wxml
@@ -102,6 +102,13 @@ @@ -102,6 +102,13 @@
102 <icon color="#f23030" size="16" type="info"></icon>{{order.store_prom}} 102 <icon color="#f23030" size="16" type="info"></icon>{{order.store_prom}}
103 </view> 103 </view>
104 104
  105 + <!-- 订单促销取价规则的优化 -->
  106 + <view class="set-mes" wx:if="{{show_ord_prom[bn_pick]}}">
  107 + <view class="use-item" >
  108 + <icon bindtap='set_can_use_ord_prom_now' color="{{can_use_ord_prom[bn_pick]?'red':'gray'}}" size="16" type="success"></icon>
  109 + <view bindtap='set_can_use_ord_prom_now' class="yu_er">参与订单促销</view>
  110 + </view>
  111 + </view>
105 112
106 <view class="xc-coupon-frame flex-center" data-bn="1" bindtap="open_coupon_list" data-pickid="{{bn_pick}}" hidden="{{(selected_quan_list?selected_quan_list.length:0)+ (get_by_quan_list && bn_exp_type==0?get_by_quan_list.length:0)<=0}}" wx:if="{{(selected_quan_list && selected_quan_list.length>0) || get_by_quan_list!=null}}"> 113 <view class="xc-coupon-frame flex-center" data-bn="1" bindtap="open_coupon_list" data-pickid="{{bn_pick}}" hidden="{{(selected_quan_list?selected_quan_list.length:0)+ (get_by_quan_list && bn_exp_type==0?get_by_quan_list.length:0)<=0}}" wx:if="{{(selected_quan_list && selected_quan_list.length>0) || get_by_quan_list!=null}}">
107 <view class="work-frame flex-space-between"> 114 <view class="work-frame flex-space-between">