Commit 5f5f53a6572e2d7bbf4e28496eeab77f4fa8936b

Authored by yvan.ni
1 parent 620f449d

购物车的优化

components/promate_pop/promate_pop.wxml
@@ -18,10 +18,11 @@ @@ -18,10 +18,11 @@
18 </view> 18 </view>
19 19
20 <view class="item_pro_right"> 20 <view class="item_pro_right">
21 - <view wx:if="{{item.prom_type!=3}}" class="fs26">{{item.title}}</view>  
22 - <view wx:else class="fs26">{{item.title}} 21 + <view wx:if="{{item.prom_type!=3}}" class="fs26" style="max-width:81%" >{{item.title}}</view>
  22 + <view wx:else class="fs26" style="max-width:81%" >{{item.title}}
23 消费满<text class="c-red">{{item.condition}}</text>享优惠({{item.limit}}) 23 消费满<text class="c-red">{{item.condition}}</text>享优惠({{item.limit}})
24 </view> 24 </view>
  25 +
25 <view wx:if="{{item.prom_type==5}}" class="fs26">搭配价:<text class="c-red">{{item.show_price}}</text></view> 26 <view wx:if="{{item.prom_type==5}}" class="fs26">搭配价:<text class="c-red">{{item.show_price}}</text></view>
26 27
27 <view wx:if="{{item.prom_type!=3}}" class="fs22" style="color: #b9b6b6"> 28 <view wx:if="{{item.prom_type!=3}}" class="fs22" style="color: #b9b6b6">
packageE/pages/cart/cart2/cart2.js
@@ -788,9 +788,29 @@ Page({ @@ -788,9 +788,29 @@ Page({
788 }, 788 },
789 789
790 790
  791 + //-- is_change是有没有切换活动的意思 --
791 async get_cart_next(carr,is_change){ 792 async get_cart_next(carr,is_change){
792 793
793 - if(is_change) carr=this.data.cartlist_y; 794 + //--- 切换的时候一定要把赠品去掉 ---
  795 + if(is_change){
  796 +
  797 + carr=this.data.cartlist_y;
  798 + //-- 剔除赠品的数据,等到确定活动是优惠促销的时候,在显示赠品, 赠品直接删除 --
  799 + var new_arr=[];
  800 + for (var ir = 0; ir < carr.length; ir++) {
  801 + if(carr[ir].is_gift && ) {
  802 + var url = '/api/weshop/cart/del/' + oo.stoid + '/' + item.id;
  803 + getApp().request.delete(url, {
  804 + success: function (t) {}
  805 + });
  806 + //商品已经下架
  807 + continue;
  808 + }
  809 + new_arr.push(carr[ir]);
  810 + }
  811 + carr=new_arr;
  812 +
  813 + }
794 //按门店分类的数组 814 //按门店分类的数组
795 var arr = new Array(); 815 var arr = new Array();
796 816
@@ -803,6 +823,7 @@ Page({ @@ -803,6 +823,7 @@ Page({
803 var no_zh_num={}; 823 var no_zh_num={};
804 824
805 for (var i = 0; i < carr.length; i++) { 825 for (var i = 0; i < carr.length; i++) {
  826 +
806 var item1 = carr[i]; 827 var item1 = carr[i];
807 //-- 获取一下商品的所有活动 -- 828 //-- 获取一下商品的所有活动 --
808 await th.buy_pro_group(item1); 829 await th.buy_pro_group(item1);
@@ -844,179 +865,10 @@ Page({ @@ -844,179 +865,10 @@ Page({
844 }) 865 })
845 } 866 }
846 867
847 - //要把优惠活动加入,prom_goods_map中,赠品不要运算,代发商品不算优惠  
848 - if (item1.prom_type == 3 && item1.is_gift != 1 && !item1.whsle_id) {  
849 - // th.check_is_youhui(item1.goods_id, item1.pick_id);  
850 - //增加优惠活动次数限制  
851 - let limit_num= await th.getprom(item1) //活动限制次数  
852 -  
853 - if(!limit_num){  
854 - await th.add_prom_goods_map(item1);  
855 - // item1.prom_id=''  
856 - // item1.prom_type=''  
857 - }else{  
858 - let user_pre_buynum = await th.getUserBuyPromNum_pre(item1.prom_id) //用户已经参与次数  
859 - if(user_pre_buynum<limit_num){  
860 - await th.add_prom_goods_map(item1);  
861 - }else{  
862 - // await th.add_prom_goods_map(item1);  
863 - item1.prom_id=''  
864 - item1.prom_type=''  
865 - }  
866 - }  
867 - }  
868 -  
869 - //-- 如果组合购的总数量不足的处理 --  
870 - if(no_zh_num[item1.prom_id] && item1.prom_type == 7){  
871 - item1.prom_type = 0;  
872 - item1.prom_type1 = 0;  
873 - item1.prom_id = 0;  
874 - item1.prom_id1 = 0  
875 - }  
876 -  
877 - //要把组合购的东西拿出来算一下,同时组合购的总数量要有存在  
878 - if (item1.prom_type == 7) {  
879 - if (!th.data.zuhe_map_good[item1.prom_id]) {  
880 - var isok = 1;  
881 - var is_flag = 1;  
882 - var store_count_ok=1;  
883 - //如果有组合购  
884 - var url = "/api/weshop/prom/zhbuy/get/" + os.stoid + "/" + item1.prom_id + '/' + getApp().globalData.userInfo.user_id;  
885 - await getApp().request.promiseGet(url, {}).then(res => {  
886 - if (res.data.code == 0 && res.data.data) {  
887 - //如果活动已经结束  
888 - if (res.data.data.is_end == 1) {  
889 - isok = 0;  
890 - }  
891 - if (ut.gettimestamp() > res.data.data.end_time) {  
892 - isok = 0;  
893 - }  
894 - item1.act = res.data.data;  
895 -  
896 - //-- 在这里要判断一下活动的组合购总数量 --  
897 - if(item1.act.zh_num>0 && item1.act.zh_buy_num>=item1.act.zh_num){  
898 - store_count_ok = 0;  
899 - no_zh_num[item1.prom_id]=1;  
900 - //-- 清理一下活动的状态 --  
901 - item1.prom_type = 0;  
902 - item1.prom_type1 = 0;  
903 - item1.prom_id = 0;  
904 - item1.prom_id1 = 0  
905 -  
906 - }else{  
907 - th.data.zhhe_act_map[item1.prom_id] = res.data.data;  
908 - }  
909 -  
910 - } else {  
911 - //未找到商品的活动  
912 - is_flag = 0;  
913 - }  
914 - })  
915 -  
916 - if (!isok) {  
917 - getApp().my_warnning("组合购的活动已经过期", 0, th);  
918 - return false;  
919 - }  
920 -  
921 - //------ 先增组合活动的总数量的时候 -------  
922 - if(store_count_ok) {  
923 - var url1 = "/api/weshop/prom/zhbuyGoods/page";  
924 - var req_data = {  
925 - page: 1,  
926 - pageSize: 2000,  
927 - store_id: os.stoid,  
928 - zh_id: item1.prom_id,  
929 - }  
930 - await getApp().request.promiseGet(url1, {  
931 - data: req_data  
932 - }).then(res => {  
933 - if (ut.ajax_ok(res)) {  
934 - var gdlist = res.data.data.pageData;  
935 - gdlist.forEach(i => {  
936 - if (item1.goods_id == i.goods_id && !is_flag) {  
937 - item1.prom_type = 0;  
938 - item1.prom_type1 = 0;  
939 - item1.prom_id = 0;  
940 - item1.prom_id1 = 0  
941 - }  
942 - })  
943 - th.data.zuhe_map_good[item1.prom_id] = gdlist;  
944 - }  
945 - })  
946 - }  
947 -  
948 -  
949 -  
950 - }  
951 - else {  
952 - item1.act = th.data.zhhe_act_map[item1.prom_id];  
953 - }  
954 - }  
955 - if (item1.prom_type == 10) {  
956 - if (!th.data.ladder_map[item1.prom_id]) {  
957 - //如果有预售  
958 - var isok = 1;  
959 - var is_flag = 1;  
960 - var act = null;  
961 - var url = "/api/weshop/prom/ladderForm/get/" + os.stoid + "/" + item1.prom_id;  
962 - await getApp().request.promiseGet(url, {}).then(res => {  
963 - console.log(res, 1000);  
964 - if (res.data.code == 0 && res.data.data) {  
965 - if (res.data.data.isuse != 1) {  
966 - isok = 0;  
967 - }  
968 - //如果活动已经结束  
969 - if (res.data.data.is_end == 1) {  
970 - isok = 0;  
971 - }  
972 - //已经结束  
973 - if (ut.gettimestamp() > res.data.data.end_time) {  
974 - isok = 0;  
975 - }  
976 - //还未开始  
977 - if (ut.gettimestamp() < res.data.data.start_time) {  
978 - isok = 0;  
979 - }  
980 - act = res.data.data;  
981 -  
982 - } else {  
983 - //未找到商品的活动  
984 - is_flag = 0;  
985 - }  
986 - })  
987 - if (!isok) {  
988 - var url = '/api/weshop/cart/del/' + oo.stoid + '/' + item1.id;  
989 - getApp().request.delete(url, {});  
990 - th.data.ladder_map[item1.prom_id] = -1;  
991 - continue;  
992 - }  
993 - th.data.ladder_map[item1.prom_id] = act;  
994 -  
995 - //-- 获取阶梯规则 --  
996 - var url1 = "/api/weshop/prom/ladderList/list";  
997 - var req_data = {  
998 - store_id: os.stoid,  
999 - form_id: item1.prom_id,  
1000 - }  
1001 - await getApp().request.promiseGet(url1, {  
1002 - data: req_data  
1003 - }).then(rs1 => {  
1004 - if (rs1.data.code == 0 && rs1.data.data) {  
1005 - var gdlist = rs1.data.data;  
1006 - th.data.ladder_map[item1.prom_id].ladder_list = gdlist;  
1007 - }  
1008 - })  
1009 - }  
1010 - }  
1011 -  
1012 if(is_change){ 868 if(is_change){
1013 - carr[i].collocationList=null; 869 + carr[i].collocationList=null;
1014 } 870 }
1015 871
1016 - //-- 判断一下,获取搭配购的消息,只有prom_type==5才会判断优惠活动 --  
1017 - if ( item1.prom_type == 5 && (!carr[i].collocationList || !carr[i].collocationList.length)) {  
1018 - await th.set_collection(item1, carr, i);  
1019 - }  
1020 } 872 }
1021 873
1022 //在分组的时候,就不要再调用接口,await 874 //在分组的时候,就不要再调用接口,await
@@ -1250,6 +1102,179 @@ Page({ @@ -1250,6 +1102,179 @@ Page({
1250 } 1102 }
1251 } 1103 }
1252 1104
  1105 + //要在多活动确定之后,在来计算
  1106 + for(var jh=0;jh<arr[k].goods.length;jh++){
  1107 + var item1=arr[k].goods[jh]
  1108 + //要把优惠活动加入,prom_goods_map中,赠品不要运算,代发商品不算优惠
  1109 + if (item1.prom_type == 3 && item1.is_gift != 1 && !item1.whsle_id) {
  1110 + // th.check_is_youhui(item1.goods_id, item1.pick_id);
  1111 + //增加优惠活动次数限制
  1112 + let limit_num= await th.getprom(item1) //活动限制次数
  1113 +
  1114 + if(!limit_num){
  1115 + await th.add_prom_goods_map(item1);
  1116 + // item1.prom_id=''
  1117 + // item1.prom_type=''
  1118 + }else{
  1119 + let user_pre_buynum = await th.getUserBuyPromNum_pre(item1.prom_id) //用户已经参与次数
  1120 + if(user_pre_buynum<limit_num){
  1121 + await th.add_prom_goods_map(item1);
  1122 + }else{
  1123 + // await th.add_prom_goods_map(item1);
  1124 + item1.prom_id=''
  1125 + item1.prom_type=''
  1126 + }
  1127 + }
  1128 + }
  1129 + //-- 如果组合购的总数量不足的处理 --
  1130 + if(no_zh_num[item1.prom_id] && item1.prom_type == 7){
  1131 + item1.prom_type = 0;
  1132 + item1.prom_type1 = 0;
  1133 + item1.prom_id = 0;
  1134 + item1.prom_id1 = 0
  1135 + }
  1136 + //要把组合购的东西拿出来算一下,同时组合购的总数量要有存在
  1137 + if (item1.prom_type == 7) {
  1138 + if (!th.data.zuhe_map_good[item1.prom_id]) {
  1139 + var isok = 1;
  1140 + var is_flag = 1;
  1141 + var store_count_ok=1;
  1142 + //如果有组合购
  1143 + var url = "/api/weshop/prom/zhbuy/get/" + os.stoid + "/" + item1.prom_id + '/' + getApp().globalData.userInfo.user_id;
  1144 + await getApp().request.promiseGet(url, {}).then(res => {
  1145 + if (res.data.code == 0 && res.data.data) {
  1146 + //如果活动已经结束
  1147 + if (res.data.data.is_end == 1) {
  1148 + isok = 0;
  1149 + }
  1150 + if (ut.gettimestamp() > res.data.data.end_time) {
  1151 + isok = 0;
  1152 + }
  1153 + item1.act = res.data.data;
  1154 +
  1155 + //-- 在这里要判断一下活动的组合购总数量 --
  1156 + if(item1.act.zh_num>0 && item1.act.zh_buy_num>=item1.act.zh_num){
  1157 + store_count_ok = 0;
  1158 + no_zh_num[item1.prom_id]=1;
  1159 + //-- 清理一下活动的状态 --
  1160 + item1.prom_type = 0;
  1161 + item1.prom_type1 = 0;
  1162 + item1.prom_id = 0;
  1163 + item1.prom_id1 = 0
  1164 +
  1165 + }else{
  1166 + th.data.zhhe_act_map[item1.prom_id] = res.data.data;
  1167 + }
  1168 +
  1169 + } else {
  1170 + //未找到商品的活动
  1171 + is_flag = 0;
  1172 + }
  1173 + })
  1174 +
  1175 + if (!isok) {
  1176 + getApp().my_warnning("组合购的活动已经过期", 0, th);
  1177 + return false;
  1178 + }
  1179 +
  1180 + //------ 先增组合活动的总数量的时候 -------
  1181 + if(store_count_ok) {
  1182 + var url1 = "/api/weshop/prom/zhbuyGoods/page";
  1183 + var req_data = {
  1184 + page: 1,
  1185 + pageSize: 2000,
  1186 + store_id: os.stoid,
  1187 + zh_id: item1.prom_id,
  1188 + }
  1189 + await getApp().request.promiseGet(url1, {
  1190 + data: req_data
  1191 + }).then(res => {
  1192 + if (ut.ajax_ok(res)) {
  1193 + var gdlist = res.data.data.pageData;
  1194 + gdlist.forEach(i => {
  1195 + if (item1.goods_id == i.goods_id && !is_flag) {
  1196 + item1.prom_type = 0;
  1197 + item1.prom_type1 = 0;
  1198 + item1.prom_id = 0;
  1199 + item1.prom_id1 = 0
  1200 + }
  1201 + })
  1202 + th.data.zuhe_map_good[item1.prom_id] = gdlist;
  1203 + }
  1204 + })
  1205 + }
  1206 +
  1207 +
  1208 +
  1209 + }
  1210 + else {
  1211 + item1.act = th.data.zhhe_act_map[item1.prom_id];
  1212 + }
  1213 + }
  1214 + if (item1.prom_type == 10) {
  1215 + if (!th.data.ladder_map[item1.prom_id]) {
  1216 + //如果有预售
  1217 + var isok = 1;
  1218 + var is_flag = 1;
  1219 + var act = null;
  1220 + var url = "/api/weshop/prom/ladderForm/get/" + os.stoid + "/" + item1.prom_id;
  1221 + await getApp().request.promiseGet(url, {}).then(res => {
  1222 + console.log(res, 1000);
  1223 + if (res.data.code == 0 && res.data.data) {
  1224 + if (res.data.data.isuse != 1) {
  1225 + isok = 0;
  1226 + }
  1227 + //如果活动已经结束
  1228 + if (res.data.data.is_end == 1) {
  1229 + isok = 0;
  1230 + }
  1231 + //已经结束
  1232 + if (ut.gettimestamp() > res.data.data.end_time) {
  1233 + isok = 0;
  1234 + }
  1235 + //还未开始
  1236 + if (ut.gettimestamp() < res.data.data.start_time) {
  1237 + isok = 0;
  1238 + }
  1239 + act = res.data.data;
  1240 +
  1241 + } else {
  1242 + //未找到商品的活动
  1243 + is_flag = 0;
  1244 + }
  1245 + })
  1246 + if (!isok) {
  1247 + var url = '/api/weshop/cart/del/' + oo.stoid + '/' + item1.id;
  1248 + getApp().request.delete(url, {});
  1249 + th.data.ladder_map[item1.prom_id] = -1;
  1250 + continue;
  1251 + }
  1252 + th.data.ladder_map[item1.prom_id] = act;
  1253 +
  1254 + //-- 获取阶梯规则 --
  1255 + var url1 = "/api/weshop/prom/ladderList/list";
  1256 + var req_data = {
  1257 + store_id: os.stoid,
  1258 + form_id: item1.prom_id,
  1259 + }
  1260 + await getApp().request.promiseGet(url1, {
  1261 + data: req_data
  1262 + }).then(rs1 => {
  1263 + if (rs1.data.code == 0 && rs1.data.data) {
  1264 + var gdlist = rs1.data.data;
  1265 + th.data.ladder_map[item1.prom_id].ladder_list = gdlist;
  1266 + }
  1267 + })
  1268 + }
  1269 + }
  1270 +
  1271 + //-- 判断一下,获取搭配购的消息,只有prom_type==5才会判断优惠活动 --
  1272 + if ( item1.prom_type == 5 && (!carr[i].collocationList || !carr[i].collocationList.length)) {
  1273 + await th.set_collection(item1, carr, i);
  1274 + }
  1275 + }
  1276 +
  1277 +
1253 var item = arr[k].goods; 1278 var item = arr[k].goods;
1254 var offline_price = 0; 1279 var offline_price = 0;
1255 var offline_num = 0; 1280 var offline_num = 0;
@@ -1384,8 +1409,6 @@ Page({ @@ -1384,8 +1409,6 @@ Page({
1384 }, 500) 1409 }, 500)
1385 }, 1410 },
1386 1411
1387 -  
1388 -  
1389 //-----单个商品购买的入口判断---- 1412 //-----单个商品购买的入口判断----
1390 get_buy_goods: function (e) { 1413 get_buy_goods: function (e) {
1391 var th = this; 1414 var th = this;
@@ -1903,6 +1926,10 @@ Page({ @@ -1903,6 +1926,10 @@ Page({
1903 async buy_pro_group(item1, is_state) { 1926 async buy_pro_group(item1, is_state) {
1904 //-- 代发商品不参与任何活动 -- 1927 //-- 代发商品不参与任何活动 --
1905 if (item1.whsle_id) return false; 1928 if (item1.whsle_id) return false;
  1929 + //-- 购物车的秒杀和团购不计算 --
  1930 + var p_type=parseInt(item1.prom_type);
  1931 + if([1,2].indexOf(p_type)>-1) return false;
  1932 +
1906 var th=this; 1933 var th=this;
1907 var req_d = { 1934 var req_d = {
1908 store_id: os.stoid, 1935 store_id: os.stoid,
@@ -2087,6 +2114,13 @@ Page({ @@ -2087,6 +2114,13 @@ Page({
2087 duo_zp_num_arr[item_map.prom_id] = t_zp_num; 2114 duo_zp_num_arr[item_map.prom_id] = t_zp_num;
2088 } 2115 }
2089 } 2116 }
  2117 + //--- 不是多个赠品赠送的时候, ---
  2118 + else{
  2119 +
  2120 + }
  2121 +
  2122 +
  2123 +
2090 } else item_map.cy_cx = 0; 2124 } else item_map.cy_cx = 0;
2091 }) 2125 })
2092 } 2126 }
@@ -2271,8 +2305,6 @@ Page({ @@ -2271,8 +2305,6 @@ Page({
2271 }, 2305 },
2272 2306
2273 2307
2274 -  
2275 -  
2276 calclate_lbNum(r_data) { 2308 calclate_lbNum(r_data) {
2277 2309
2278 if(!r_data) return false; 2310 if(!r_data) return false;
@@ -7550,14 +7582,18 @@ Page({ @@ -7550,14 +7582,18 @@ Page({
7550 var fg=goods.findIndex(function (g_item){ 7582 var fg=goods.findIndex(function (g_item){
7551 return g_item.goods_id==ck_prom_type.goods[b].goods_id 7583 return g_item.goods_id==ck_prom_type.goods[b].goods_id
7552 && [0,3,5,7,10].indexOf(g_item.prom_type)>-1 7584 && [0,3,5,7,10].indexOf(g_item.prom_type)>-1
7553 - && g_item.pick_id==pk 7585 + && g_item.pick_id==pk && g_item.is_gift==0;
7554 }) 7586 })
7555 if(fg>-1){ 7587 if(fg>-1){
7556 goods[fg].prom_type=ck_prom_type.prom_type; 7588 goods[fg].prom_type=ck_prom_type.prom_type;
7557 goods[fg].prom_id=ck_prom_type.prom_id; 7589 goods[fg].prom_id=ck_prom_type.prom_id;
7558 - th.data.cartlist_y[idx].goods[fg].prom_type= goods[fg].prom_type;  
7559 - th.data.cartlist_y[idx].goods[fg].prom_id= goods[fg].prom_id;  
7560 7590
  7591 + for(var ik=0;ik< th.data.cartlist[idx].goods.length;ik++){
  7592 + if(th.data.cartlist[idx].goods[ik].id==goods[fg].id){
  7593 + th.data.cartlist[idx].goods[ik].prom_type= goods[fg].prom_type;
  7594 + th.data.cartlist[idx].goods[ik].prom_id= goods[fg].prom_id;
  7595 + }
  7596 + }
7561 } 7597 }
7562 } 7598 }
7563 7599
packageE/pages/cart/cart2/cart2.wxml
@@ -168,7 +168,6 @@ @@ -168,7 +168,6 @@
168 </block> 168 </block>
169 </block> 169 </block>
170 170
171 -  
172 <!-- 使用搭配 --> 171 <!-- 使用搭配 -->
173 <cart_collect_temp id="col{{pidx}}" 172 <cart_collect_temp id="col{{pidx}}"
174 bind:childFun="select_coll" sales_rules="{{sales_rules}}" 173 bind:childFun="select_coll" sales_rules="{{sales_rules}}"
pages/cart/cart/cart.js
@@ -4203,7 +4203,6 @@ Page({ @@ -4203,7 +4203,6 @@ Page({
4203 continue; 4203 continue;
4204 } 4204 }
4205 4205
4206 -  
4207 var url = "/api/weshop/cart/delGift?store_id=" + newd.store_id + "&user_id=" + 4206 var url = "/api/weshop/cart/delGift?store_id=" + newd.store_id + "&user_id=" +
4208 newd.user_id + "&goods_id=" + newd.goods_id + "&is_gift=1&pick_id=" + newd.pick_id + "&prom_id=" + newd.prom_id 4207 newd.user_id + "&goods_id=" + newd.goods_id + "&is_gift=1&pick_id=" + newd.pick_id + "&prom_id=" + newd.prom_id
4209 await getApp().request.promiseDelete(url, {}) 4208 await getApp().request.promiseDelete(url, {})
pages/goods/goodsInfo/goodsInfo.js
@@ -7637,6 +7637,7 @@ Page({ @@ -7637,6 +7637,7 @@ Page({
7637 } 7637 }
7638 if (fir_act.lb_id) more_arr.push('送' + fir_act.lbtitle); 7638 if (fir_act.lb_id) more_arr.push('送' + fir_act.lbtitle);
7639 if (fir_act.zxlb_id) more_arr.push('送' + fir_act.zxlbtitle); 7639 if (fir_act.zxlb_id) more_arr.push('送' + fir_act.zxlbtitle);
  7640 + if (fir_act.monthgiftbag_id) more_arr.push('送' + fir_act.monthgiftbag_title);
7640 7641
7641 //-- 开始组装数据 -- 7642 //-- 开始组装数据 --
7642 th.add_cx_prom_group({ 7643 th.add_cx_prom_group({