Commit f3f92c41744f7d23ff8d252e436e98cfcc5349f3

Authored by yvan.ni
1 parent 6c0e604b

多促销活动的优化

packageE/pages/cart/cart2/cart2.js
... ... @@ -133,6 +133,8 @@ Page({
133 133 in_zhact:{}, //组合购活动在列表中的显示
134 134 in_yhact:{}, //优惠活动在列表中的显示
135 135  
  136 + in_zh_gd_buy_map:{}, //就是商品在组合购中的
  137 +
136 138 in_zhact_gdmap_new: {}, //不同门店参与同一活动的限购,这些都是map表,是多促销互动专用,不能和in_zhact_gdmap重叠
137 139 in_zhact_new:{}, //组合购活动在列表中的显示 是多促销互动专用,不能和in_zhact重叠
138 140 in_yhact_new:{}, //组合购活动在列表中的显示 是多促销互动专用,不能和in_yhact重叠
... ...
pages/cart/cart/cart.js
... ... @@ -46,6 +46,7 @@ Page({
46 46 in_zhact_gdmap: {}, //不同门店参与同一活动的限购
47 47 in_zhact:{}, //组合购活动在列表中的显示
48 48 in_yhact:{}, //优惠活动在列表中的显示
  49 + in_zh_gd_buy_map:{}, //就是商品在组合购中的
49 50  
50 51 ladder_map: {}, //阶梯促销需要的map
51 52  
... ... @@ -1908,7 +1909,6 @@ Page({
1908 1909 if (car && car.length > 0) {
1909 1910 th.data.in_zhact_gdmap = {};
1910 1911  
1911   -
1912 1912 //-- 第一次过滤,show_can_cx的还要遍历一遍,确保数据的正确性 --
1913 1913 var rd_arr=[];
1914 1914 for (var a = 0; a < car.length; a++) {
... ... @@ -1917,22 +1917,52 @@ Page({
1917 1917 rd_arr.push(show_can_cx)
1918 1918 })
1919 1919 }
  1920 +
1920 1921 //--- 第二次过滤 ---
1921 1922 for(var ui=0;ui<rd_arr.length;ui++){
  1923 + var is_has_no_ok=0;
  1924 + var show_can_cx_item=rd_arr[ui];
  1925 + for (const per_sh_cx in show_can_cx_item) {
  1926 + var cx_cur_act=show_can_cx_item[per_sh_cx].cur_act; //每一种活动切换的时候的当前活动
  1927 + var aid=cx_cur_act.prom_id;
  1928 + //-- 就是那些活动未到达条件的时候,才需要重新过滤一遍 --
  1929 + if(cx_cur_act.is_no_ok) {
  1930 + switch (cx_cur_act.prom_type){
  1931 + case 3:
  1932 + if(th.data.in_yhact_new[aid]){
  1933 + is_has_no_ok=1;
  1934 + }
  1935 + break;
  1936 + case 7:
  1937 + if(th.data.in_zhact_new[aid]){
  1938 + is_has_no_ok=1;
  1939 + }
  1940 + break;
  1941 + }
  1942 + }
  1943 + }
1922 1944  
  1945 + //如果有重复就要重新计算一遍
  1946 + if(is_has_no_ok){
  1947 + await m_cx.cart_cx_group(th,car[ui].goods,car[ui],1,n_ok,(show_can_cx)=>{
  1948 + rd_arr[ui]=show_can_cx;
  1949 + })
  1950 + }
1923 1951 }
1924 1952  
1925 1953  
1926 1954  
1927 1955 for (var a = 0; a < car.length; a++) {
  1956 + //-- 把活动组装进去 ---
  1957 + var show_can_cx=rd_arr[a];
  1958 +
  1959 + car[a].zh_map=null;
  1960 + car[a].ladder_map=null;
1928 1961  
1929   - car[a].zh_map=null;
1930   - car[a].ladder_map=null;
1931 1962  
  1963 + var item = car[a].goods, is_s_sele = 1;
  1964 + //-- 先批量判断一下活动的类型,同时要同步跟新 --
1932 1965  
1933   - var item = car[a].goods, is_s_sele = 1;
1934   - //-- 先批量判断一下活动的类型,同时要同步跟新 --
1935   - await m_cx.cart_cx_group(th,item,car[a],1,n_ok,(show_can_cx)=>{
1936 1966 var offline_price = 0;
1937 1967 var offline_num = 0;
1938 1968 for (var c = 0; c < item.length; c++) {
... ... @@ -2012,13 +2042,13 @@ Page({
2012 2042 [txt]: Number(is_s_sele)
2013 2043 });
2014 2044  
2015   - // var txt1 = "requestData[" + a + "].show_can_cx";
2016   - // th.setData({
2017   - // [txt1]: show_can_cx
2018   - // });
  2045 + var txt1 = "requestData[" + a + "].show_can_cx";
  2046 + th.setData({
  2047 + [txt1]: show_can_cx
  2048 + });
2019 2049  
2020   - var et={show_can_cx:show_can_cx};
2021   - rd_arr.push(et);
  2050 + //-- var et={show_can_cx:show_can_cx};
  2051 + //-- rd_arr.push(et);
2022 2052  
2023 2053 //当有线下取价的时候
2024 2054 if (offline_price) {
... ... @@ -2038,11 +2068,9 @@ Page({
2038 2068 });
2039 2069 }
2040 2070 }
2041   - });
2042   -
2043 2071 }
2044 2072  
2045   - var gb=1;
  2073 +
2046 2074 //-- 切换活动的按钮要把他返回 --
2047 2075 this.data.change_act=0;
2048 2076 if(func) func();
... ...
utils/more_cx.js
... ... @@ -440,21 +440,33 @@ module.exports = {
440 440 need_num=th.data.in_yhact_new[aid]?th.data.in_yhact_new[aid]:0;
441 441 }
442 442 //-- 判断优惠促销要不要限购 --
443   - var fd=null;
444   - var fd_res = await getApp().request.promiseGet('/api/weshop/promgoods/get/'+os.stoid+'/'+ky0,{})
445   - if(fd_res && fd_res.data.code==0 ){
446   - fd=fd_res.data.data;
  443 + var fd=th.data.in_yhact[aid];
  444 + if(!fd) {
  445 + var fd_res = await getApp().request.promiseGet('/api/weshop/promgoods/get/' + os.stoid + '/' + aid, {})
  446 + if (fd_res && fd_res.data.code == 0) {
  447 + fd = fd_res.data.data;
  448 + th.data.in_yhact[aid]=fd;
  449 + }
447 450 }
448 451 //如果有限购的时候,也要计算一下
449 452 if (fd && fd['limit_num'] > 0){
450   - //-- 获取已经购买了多少件 --
451   - var url = "/api/weshop/ordergoods/getUserBuyPromNum?store_id="+os.stoid+"&user_id="
452   - +getApp().globalData.user_id+"&prom_type=3&prom_id="+zh_pro0.id;
453   - await getApp().request.promiseGet(url, {}).then(rh => {
454   - if(rh.data.code==0){
455   - item_act_map.buyed=rh.data.data.userbuynum;
456   - }
457   - })
  453 + // 优惠的促销的限购要反写进去不和
  454 + item_act_map.limit_num=fd['limit_num'];
  455 + if(fd.hasOwnProperty('buyed')){
  456 + item_act_map.buyed= fd.buyed;
  457 + }else{
  458 + //-- 获取已经购买了多少件 --
  459 + var url = "/api/weshop/ordergoods/getUserBuyPromNum?store_id="+os.stoid+"&user_id="
  460 + +getApp().globalData.user_id+"&prom_type=3&prom_id="+zh_pro0.id;
  461 + await getApp().request.promiseGet(url, {}).then(rh => {
  462 + if(rh.data.code==0){
  463 + item_act_map.buyed=rh.data.data.userbuynum;
  464 + fd.buyed=rh.data.data.userbuynum;
  465 + th.data.in_yhact[aid].buyed=rh.data.data.userbuynum;
  466 + }
  467 + })
  468 + }
  469 +
458 470 if(item_act_map.buyed+need_num>=fd['limit_num']){
459 471 continue; //-- 进行下一个循环 --
460 472 }
... ... @@ -500,21 +512,30 @@ module.exports = {
500 512 var zh_goods=item_act_map.goods;
501 513 //--- 要循环计算一下商品的已购数量 ---
502 514 for(var h=0;h<zh_goods.length;h++){
503   - //-- 商品的限购 --
504   - var promgoodsbuynum = 0;
505   - var res=await getApp().request.promiseGet("/api/weshop/ordergoods/getUserBuyGoodsNum", {
506   - data: {
507   - store_id: os.stoid,
508   - user_id: getApp().globalData.user_id,
509   - goods_id: zh_goods[h].goods_id,
510   - prom_type: 7,
511   - prom_id: item_act_map.prom_id
512   - },
513   - })
514   - if(res.data.code==0 && res.data.data && res.data.data.promgoodsbuynum){
515   - promgoodsbuynum = res.data.data.promgoodsbuynum;
  515 + if(zh_goods[h].zh_b_num) continue;
  516 + var ky=item_act_map.prom_id+"."+zh_goods[h].goods_id;
  517 + if(th.data.in_zh_gd_buy_map[ky]){
  518 + zh_goods[h].zh_b_num=th.data.in_zh_gd_buy_map[ky];
  519 + }else{
  520 + //-- 商品的限购 --
  521 + var promgoodsbuynum = 0;
  522 + var res=await getApp().request.promiseGet("/api/weshop/ordergoods/getUserBuyGoodsNum", {
  523 + data: {
  524 + store_id: os.stoid,
  525 + user_id: getApp().globalData.user_id,
  526 + goods_id: zh_goods[h].goods_id,
  527 + prom_type: 7,
  528 + prom_id: item_act_map.prom_id
  529 + },
  530 + })
  531 + if(res.data.code==0 && res.data.data && res.data.data.promgoodsbuynum){
  532 + promgoodsbuynum = res.data.data.promgoodsbuynum;
  533 + }
  534 + zh_goods[h].zh_b_num=promgoodsbuynum;
  535 + th.data.in_zh_gd_buy_map[ky]=promgoodsbuynum;
516 536 }
517   - zh_goods[h].zh_b_num=promgoodsbuynum;
  537 +
  538 +
518 539 }
519 540 //-- 放到参与组合优惠促销的map中 --
520 541 th.data.zuhe_map_good[item_act_map.prom_id] = zhact_gdlist;
... ... @@ -526,18 +547,22 @@ module.exports = {
526 547 if(!ob) ob=th.data.zhhe_act_map;
527 548  
528 549 var zh_pro0 = ob[item_act_map.prom_id];
  550 + if(zh_pro0.hasOwnProperty('buyed')){
  551 + item_act_map.buyed=zh_pro0.buyed;
  552 + }else {
  553 + //-- 获取活动信息 --
  554 + var url = "/api/weshop/ordergoods/getUserBuyPromNum?store_id="+os.stoid+"&user_id="
  555 + +getApp().globalData.user_id+"&prom_type=7&prom_id="+zh_pro0.id;
  556 + await getApp().request.promiseGet(url, {}).then(rh => {
  557 + if(rh.data.code==0){
  558 + item_act_map.buyed=rh.data.data.userbuynum;
  559 + zh_pro0.buyed=rh.data.data.userbuynum;
  560 + }
  561 + })
  562 + }
529 563  
530   - //-- 获取活动信息 --
531   - var url = "/api/weshop/ordergoods/getUserBuyPromNum?store_id="+os.stoid+"&user_id="
532   - +getApp().globalData.user_id+"&prom_type=7&prom_id="+zh_pro0.id;
533   - await getApp().request.promiseGet(url, {}).then(rh => {
534   - if(rh.data.code==0){
535   - item_act_map.buyed=rh.data.data.userbuynum;
536   - }
537   - })
538 564 //当满足组合的要求:总数要满足,起购数要满足
539 565 if(this.ch_zh_ok(zh_pro0,zhact_gdlist,zh_goods,th,item_act_map,is_need_ck_num,need_ok)){
540   -
541 566 can_calc_cx.push(item_act_map)
542 567 }
543 568 break;
... ...