Commit 19d480b4dc367260d26b1553aa75a761cd490b9f

Authored by yvan.ni
1 parent a8e5fd02

小程序多活动的优化

pages/cart/cart2_pt/cart2_pt.js
@@ -418,6 +418,8 @@ Page({ @@ -418,6 +418,8 @@ Page({
418 th.calculatePrice2(); 418 th.calculatePrice2();
419 } else { 419 } else {
420 420
  421 +
  422 + gd.prom_id=gg.prom_id;
421 //--阶梯团很特殊,不能用总表来拿价格-- 423 //--阶梯团很特殊,不能用总表来拿价格--
422 getApp().request.get("/api/weshop/teamlist/get/" + oo.stoid + "/" + gd.prom_id, { 424 getApp().request.get("/api/weshop/teamlist/get/" + oo.stoid + "/" + gd.prom_id, {
423 success: function (tt) { 425 success: function (tt) {
@@ -458,6 +460,11 @@ Page({ @@ -458,6 +460,11 @@ Page({
458 if (pt_data.kttype == 3) { 460 if (pt_data.kttype == 3) {
459 t.data.data.shop_price = tt.data.data.yf_price; //用定金来购买 461 t.data.data.shop_price = tt.data.data.yf_price; //用定金来购买
460 } 462 }
  463 +
  464 + t.data.data.prom_id = gd.prom_id;
  465 + t.data.data.prom_type = 6;
  466 +
  467 +
461 } 468 }
462 } else { 469 } else {
463 t.data.data.prom_id = 0; 470 t.data.data.prom_id = 0;
pages/cart/cart_wk/cart_wk.js
@@ -786,7 +786,7 @@ Page({ @@ -786,7 +786,7 @@ Page({
786 switch (ord_prom['type']) { 786 switch (ord_prom['type']) {
787 case 0: 787 case 0:
788 allpice = Math.round(o_condition * ord_prom['expression']) / 100;//满额打折 788 allpice = Math.round(o_condition * ord_prom['expression']) / 100;//满额打折
789 - order_prom_amount = (o_condition - order_m).toFixed(2); 789 + order_prom_amount = (o_condition - allpice).toFixed(2);
790 break; 790 break;
791 case 1: 791 case 1:
792 //-- 如果有优惠促销倍减的时候 -- 792 //-- 如果有优惠促销倍减的时候 --
@@ -847,7 +847,7 @@ Page({ @@ -847,7 +847,7 @@ Page({
847 switch (ord_prom['type']) { 847 switch (ord_prom['type']) {
848 case 0: 848 case 0:
849 allpice = Math.round(o_condition * ord_prom['expression']) / 100;//满额打折 849 allpice = Math.round(o_condition * ord_prom['expression']) / 100;//满额打折
850 - order_prom_amount = (o_condition - order_m).toFixed(2); 850 + order_prom_amount = (o_condition - allpice).toFixed(2);
851 break; 851 break;
852 case 1: 852 case 1:
853 //-- 如果有优惠促销倍减的时候 -- 853 //-- 如果有优惠促销倍减的时候 --
pages/user/order_detail/order_detail.js
@@ -543,12 +543,7 @@ Page({ @@ -543,12 +543,7 @@ Page({
543 543
544 //商品的普通购买 ,不要进行判断 544 //商品的普通购买 ,不要进行判断
545 if((good.prom_type==1 || good.prom_type==2 || good.prom_type==6 || good.prom_type==4) && !good.is_gift && !good.is_collocation && !good.is_integral_normal && !good.is_pd_normal){ 545 if((good.prom_type==1 || good.prom_type==2 || good.prom_type==6 || good.prom_type==4) && !good.is_gift && !good.is_collocation && !good.is_integral_normal && !good.is_pd_normal){
546 - if(gg.prom_type!=good.prom_type && gg.prom_type>0) {  
547 - var content=gg.goods_name+'商品的活动发生了变化,请取消订单重新购买';  
548 - th.toast(content);  
549 - th.setData({paying:0});  
550 - return false;  
551 - } 546 +
552 }else{ 547 }else{
553 if((gg.prom_type==1 || gg.prom_type==3 || gg.prom_type==5 || gg.prom_type==6 || gg.prom_type==4) 548 if((gg.prom_type==1 || gg.prom_type==3 || gg.prom_type==5 || gg.prom_type==6 || gg.prom_type==4)
554 && !good.is_collocation && !good.is_gift && !good.is_integral_normal && !good.is_pd_normal) { 549 && !good.is_collocation && !good.is_gift && !good.is_integral_normal && !good.is_pd_normal) {
@@ -597,7 +592,7 @@ Page({ @@ -597,7 +592,7 @@ Page({
597 if(prom){ 592 if(prom){
598 var t_now=ut.gettimestamp(); 593 var t_now=ut.gettimestamp();
599 if(prom.is_end==0 && prom.start_time<t_now && prom.end_time>t_now){ 594 if(prom.is_end==0 && prom.start_time<t_now && prom.end_time>t_now){
600 - 595 +
601 var content=gg.goods_name+'商品的活动发生了变化,请取消订单重新购买'; 596 var content=gg.goods_name+'商品的活动发生了变化,请取消订单重新购买';
602 th.toast(content); 597 th.toast(content);
603 th.setData({paying:0}); 598 th.setData({paying:0});
@@ -1160,94 +1155,105 @@ Page({ @@ -1160,94 +1155,105 @@ Page({
1160 b_item.price=good[card_field]; 1155 b_item.price=good[card_field];
1161 } 1156 }
1162 1157
1163 - var url="/api/weshop/activitylist/getGoodActInfo";  
1164 - var req_data={  
1165 - store_id:g_item.store_id,goodsidlist:g_item.goods_id,is_detail:1,user_id:user_id 1158 + var url = "/api/weshop/activitylist/listGoodActInfo2New";
  1159 + var req_data = {
  1160 + store_id: g_item.store_id, goods_id: g_item.goods_id, user_id: user_id
1166 }; 1161 };
1167 - await getApp().request.promiseGet(url, {data:req_data}).then(res=>{  
1168 - if(res.data.code==0){  
1169 - var list = res.data.data;  
1170 - for(let i in list){  
1171 - let item=list[i];  
1172 - if(item.prom_type==1){ good.prom_type=1; good.prom_id=item.act_id; } 1162 + await getApp().request.promiseGet(url, { data: req_data }).then(res => {
  1163 + if (res.data.code == 0) {
  1164 +
  1165 + var arr = res.data.data;
  1166 + //-- 预热也要计算 --
  1167 + var arr2 = arr.filter(function (e) {
  1168 + return e.s_time < ut.gettimestamp();
  1169 + })
  1170 +
  1171 + if (arr2.length == 1) {
  1172 + good.prom_type = 1;
  1173 + good.prom_id = item.act_id;
  1174 +
  1175 +
  1176 +
  1177 + }
  1178 + else if (arr2.length > 1) {
  1179 + good.prom_type = g_item.prom_type; good.prom_id = g_item.prom_id;
1173 } 1180 }
1174 } 1181 }
1175 }) 1182 })
1176 1183
1177 - if(!prom) {  
1178 - //--判断商品当前的活动情况--  
1179 - switch (good.prom_type) {  
1180 - case 1:  
1181 - var flash = null;  
1182 - await getApp().request.promiseGet("/api/ms/flash_sale/getNew/" + os.stoid + "/" + user_id + "/" + good.prom_id, {}).then(res => {  
1183 - if (res.data.code == 0) {  
1184 - flash = res.data.data;  
1185 - }  
1186 - })  
1187 - //----已经结束-----  
1188 - if (flash && flash.is_end == 0) {  
1189 -  
1190 - if( flash.end_time > timestamp && flash.start_time < timestamp){  
1191 - prom = flash;  
1192 - prom.price = prom.user_price;  
1193 - b_item.price = prom.price;  
1194 - good.prom_type = 1;  
1195 - good.prom_id = prom.id;  
1196 - }else{  
1197 - if(g_item.prom_type==0 && !flash.is_shop_buy ){  
1198 - err_text+=g_item['goods_name']+"秒杀活动不允许普通价\n";  
1199 - continue;  
1200 - } 1184 + //--判断商品当前的活动情况--
  1185 + switch (good.prom_type) {
  1186 + case 1:
  1187 + var flash = null;
  1188 + await getApp().request.promiseGet("/api/ms/flash_sale/getNew/" + os.stoid + "/" + user_id + "/" + good.prom_id, {}).then(res => {
  1189 + if (res.data.code == 0) {
  1190 + flash = res.data.data;
  1191 + }
  1192 + })
  1193 + //----已经结束-----
  1194 + if (flash && flash.is_end == 0) {
  1195 +
  1196 + if( flash.end_time > timestamp && flash.start_time < timestamp){
  1197 + prom = flash;
  1198 + prom.price = prom.user_price;
  1199 + b_item.price = prom.price;
  1200 + good.prom_type = 1;
  1201 + good.prom_id = prom.id;
  1202 + }else{
  1203 + if(g_item.prom_type==0 && !flash.is_shop_buy ){
  1204 + err_text+=g_item['goods_name']+"秒杀活动不允许普通价\n";
  1205 + continue;
1201 } 1206 }
  1207 + }
1202 1208
  1209 + }
  1210 + break;
  1211 + case 2:
  1212 + var group = null;
  1213 + await getApp().request.promiseGet("/api/weshop/goods/groupBuy/getActInfo/" + os.stoid + "/" + good.goods_id + "/" + good.prom_id, {}).then(res => {
  1214 + if (res.data.code == 0) {
  1215 + group = res.data.data;
1203 } 1216 }
1204 - break;  
1205 - case 2:  
1206 - var group = null;  
1207 - await getApp().request.promiseGet("/api/weshop/goods/groupBuy/getActInfo/" + os.stoid + "/" + good.goods_id + "/" + good.prom_id, {}).then(res => {  
1208 - if (res.data.code == 0) {  
1209 - group = res.data.data;  
1210 - }  
1211 - })  
1212 - //----已经结束-----  
1213 - if (group && group.is_end == 0 && group.end_time > timestamp && group.start_time < timestamp) {  
1214 - prom = group;  
1215 - prom.price = prom.price;  
1216 - b_item.price = prom.price;  
1217 - }  
1218 - break;  
1219 - case 6:  
1220 - b_item.is_pd_normal = 1;  
1221 - break;  
1222 - case 7:  
1223 - //如果有组合购  
1224 - var url = "/api/weshop/prom/zhbuy/get/" + os.stoid + "/" + good.prom_id + "/" + getApp().globalData.userInfo.user_id;  
1225 - await getApp().request.promiseGet(url, {}).then(res => {  
1226 - if (res.data.code == 0 && res.data.data) {  
1227 - if (res.data.data.is_show == 1 && res.data.data.is_end == 0  
1228 - && ut.gettimestamp() < res.data.data.end_time  
1229 - && ut.gettimestamp() > res.data.data.start_time  
1230 - ) {  
1231 - b_item.prom_type = 7;  
1232 - b_item.prom_id = res.data.data.id;  
1233 - good.prom_type = 7;  
1234 - good.prom_id = res.data.data.id;  
1235 - } 1217 + })
  1218 + //----已经结束-----
  1219 + if (group && group.is_end == 0 && group.end_time > timestamp && group.start_time < timestamp) {
  1220 + prom = group;
  1221 + prom.price = prom.price;
  1222 + b_item.price = prom.price;
  1223 + }
  1224 + break;
  1225 + case 6:
  1226 + b_item.is_pd_normal = 1;
  1227 + break;
  1228 + case 7:
  1229 + //如果有组合购
  1230 + var url = "/api/weshop/prom/zhbuy/get/" + os.stoid + "/" + good.prom_id + "/" + getApp().globalData.userInfo.user_id;
  1231 + await getApp().request.promiseGet(url, {}).then(res => {
  1232 + if (res.data.code == 0 && res.data.data) {
  1233 + if (res.data.data.is_show == 1 && res.data.data.is_end == 0
  1234 + && ut.gettimestamp() < res.data.data.end_time
  1235 + && ut.gettimestamp() > res.data.data.start_time
  1236 + ) {
  1237 + b_item.prom_type = 7;
  1238 + b_item.prom_id = res.data.data.id;
  1239 + good.prom_type = 7;
  1240 + good.prom_id = res.data.data.id;
1236 } 1241 }
1237 - })  
1238 - break;  
1239 - case 10:  
1240 -  
1241 - var url = `/api/weshop/prom/ladderForm/getNew/${os.stoid}/${user_id}/${good.prom_id}`;  
1242 - await getApp().request.promiseGet(url, {}).then(res => {  
1243 - if (res.data.code == 0 && res.data.data && res.data.data.isuse && res.data.data.is_end == 0) {  
1244 - b_item.prom_type = 10;  
1245 - b_item.prom_id = res.data.data.id;  
1246 - }  
1247 - })  
1248 - break;  
1249 - } 1242 + }
  1243 + })
  1244 + break;
  1245 + case 10:
  1246 +
  1247 + var url = `/api/weshop/prom/ladderForm/getNew/${os.stoid}/${user_id}/${good.prom_id}`;
  1248 + await getApp().request.promiseGet(url, {}).then(res => {
  1249 + if (res.data.code == 0 && res.data.data && res.data.data.isuse && res.data.data.is_end == 0) {
  1250 + b_item.prom_type = 10;
  1251 + b_item.prom_id = res.data.data.id;
  1252 + }
  1253 + })
  1254 + break;
1250 } 1255 }
  1256 +
1251 1257
1252 //如果有优惠促销的时候,要看下商品的优惠活动有没有过期 1258 //如果有优惠促销的时候,要看下商品的优惠活动有没有过期
1253 if((g_item.prom_type==3 || good.prom_type==3) && good.whsle_id<=0){ 1259 if((g_item.prom_type==3 || good.prom_type==3) && good.whsle_id<=0){
@@ -1603,12 +1609,33 @@ Page({ @@ -1603,12 +1609,33 @@ Page({
1603 if (res.data.data.total > 0) { 1609 if (res.data.data.total > 0) {
1604 b_cart_goods= res.data.data.pageData[0]; 1610 b_cart_goods= res.data.data.pageData[0];
1605 } 1611 }
1606 - }) 1612 + })
  1613 +
  1614 +
  1615 + //-- 判断购物车是不是有重复 --
  1616 + var is_has=0;
  1617 + if(b_cart_goods) {
  1618 + for (let jr = 0; jr < b_cart_goods.length; jr++) {
  1619 + var b_cart_item = b_cart_goods[jr];
  1620 + if (g_item.prom_type == 0) {
  1621 + if ([0, 3, 5, 7, 10].indexOf(b_cart_item.prom_type) > -1) {
  1622 + is_has = b_cart_item.id;
  1623 + break
  1624 + }
  1625 + } else {
  1626 + if (b_cart_goods.prom_type == g_item.prom_type && b_cart_goods.prom_id == g_item.prom_id) {
  1627 + is_has = b_cart_item.id;
  1628 + break
  1629 + }
  1630 + }
  1631 + }
  1632 + }
  1633 +
1607 1634
1608 //-- 如果就加入过购物车 -- 1635 //-- 如果就加入过购物车 --
1609 - if(b_cart_goods){ 1636 + if(is_has){
1610 var updata = { 1637 var updata = {
1611 - id: b_cart_goods.id, 1638 + id: is_has,
1612 goods_num: newd.goods_num + b_cart_goods.goods_num, 1639 goods_num: newd.goods_num + b_cart_goods.goods_num,
1613 goods_price: newd.goods_price, 1640 goods_price: newd.goods_price,
1614 member_goods_price:newd.goods_price, 1641 member_goods_price:newd.goods_price,
@@ -1688,7 +1715,15 @@ Page({ @@ -1688,7 +1715,15 @@ Page({
1688 var user_id=getApp().globalData.user_id; 1715 var user_id=getApp().globalData.user_id;
1689 if(!user_id) user_id=0; 1716 if(!user_id) user_id=0;
1690 1717
1691 - var gd= e.currentTarget.dataset.gd; 1718 + var gd_item= e.currentTarget.dataset.gd;
  1719 + var gd=gd_item.goods_id;
  1720 +
  1721 + if(gd_item.prom_type>0){
  1722 + good_url = "/pages/goods/goodsInfo/goodsInfo?goods_id=" + gd + "&prom_id=" + gd_item.prom_id + "&prom_type="+gd_item.prom_type;
  1723 + getApp().goto(good_url);
  1724 + return false;
  1725 + }
  1726 +
1692 var good_url="/pages/goods/goodsInfo/goodsInfo?goods_id=" + gd; 1727 var good_url="/pages/goods/goodsInfo/goodsInfo?goods_id=" + gd;
1693 var url="/api/weshop/activitylist/getGoodActInfo"; 1728 var url="/api/weshop/activitylist/getGoodActInfo";
1694 var req_data={ 1729 var req_data={
pages/user/order_detail/order_detail.wxml
@@ -20,12 +20,12 @@ @@ -20,12 +20,12 @@
20 </view> 20 </view>
21 <!--wx:if="{{item.return_btn!=4}}" --> 21 <!--wx:if="{{item.return_btn!=4}}" -->
22 <view class="order-detail" wx:for="{{order.order_goods}}" wx:key="{{index}}" > 22 <view class="order-detail" wx:for="{{order.order_goods}}" wx:key="{{index}}" >
23 - <view class="goods-img" bindtap="go_gd" data-gd="{{item.goods_id}}"> 23 + <view class="goods-img" bindtap="go_gd" data-gd="{{item}}">
24 <image class="wh100" src="{{resourceUrl+item.original_img}}" binderror="bind_bnerr" lazy-load="true" 24 <image class="wh100" src="{{resourceUrl+item.original_img}}" binderror="bind_bnerr" lazy-load="true"
25 data-errorimg="order.order_goods[{{index}}].original_img"></image> 25 data-errorimg="order.order_goods[{{index}}].original_img"></image>
26 </view> 26 </view>
27 <!-- 跳转到商品 --> 27 <!-- 跳转到商品 -->
28 - <navigator class="order-cont" bindtap="go_gd" data-gd="{{item.goods_id}}"> 28 + <navigator class="order-cont" bindtap="go_gd" data-gd="{{item}}">
29 <view class="goods-name">{{item.goods_name}}</view> 29 <view class="goods-name">{{item.goods_name}}</view>
30 <!--<view class="goods-color">{{item.goods_spec}} {{item.goods_color}}</view>--> 30 <!--<view class="goods-color">{{item.goods_spec}} {{item.goods_color}}</view>-->
31 <view class="goods-color">{{filters.show_gui_ge(item.goods_spec,item.goods_color)}}</view> 31 <view class="goods-color">{{filters.show_gui_ge(item.goods_spec,item.goods_color)}}</view>
pages/user/order_list/order_list.js
@@ -882,12 +882,6 @@ Page({ @@ -882,12 +882,6 @@ Page({
882 //商品的普通购买 ,不要进行判断 882 //商品的普通购买 ,不要进行判断
883 if ((good.prom_type == 1 || good.prom_type == 2 || good.prom_type == 6 || good.prom_type == 4 || good.prom_type == 8) 883 if ((good.prom_type == 1 || good.prom_type == 2 || good.prom_type == 6 || good.prom_type == 4 || good.prom_type == 8)
884 && !good.is_gift && !good.is_collocation && !good.is_integral_normal && !good.is_pd_normal) { 884 && !good.is_gift && !good.is_collocation && !good.is_integral_normal && !good.is_pd_normal) {
885 - if (gg.prom_type != good.prom_type && gg.prom_type > 0) {  
886 - var content = gg.goods_name + '商品的活动发生了变化,请取消订单重新购买';  
887 - th.toast(content);  
888 - th.setData({ paying: 0 });  
889 - return false;  
890 - }  
891 885
892 } else { 886 } else {
893 if ((gg.prom_type == 1 || good.prom_type == 2 || gg.prom_type == 3 || gg.prom_type == 5 || gg.prom_type == 6 || gg.prom_type == 4) 887 if ((gg.prom_type == 1 || good.prom_type == 2 || gg.prom_type == 3 || gg.prom_type == 5 || gg.prom_type == 6 || gg.prom_type == 4)
@@ -1485,7 +1479,8 @@ Page({ @@ -1485,7 +1479,8 @@ Page({
1485 }) 1479 })
1486 1480
1487 if (arr2.length == 1) { 1481 if (arr2.length == 1) {
1488 - good.prom_type = 1; good.prom_id = item.act_id; 1482 + good.prom_type = item.prom_type;
  1483 + good.prom_id = item.act_id;
1489 } 1484 }
1490 else if (arr2.length > 1) { 1485 else if (arr2.length > 1) {
1491 good.prom_type = g_item.prom_type; good.prom_id = g_item.prom_id; 1486 good.prom_type = g_item.prom_type; good.prom_id = g_item.prom_id;
@@ -1549,8 +1544,6 @@ Page({ @@ -1549,8 +1544,6 @@ Page({
1549 ) { 1544 ) {
1550 b_item.prom_type = 7; 1545 b_item.prom_type = 7;
1551 b_item.prom_id = res.data.data.id; 1546 b_item.prom_id = res.data.data.id;
1552 - good.prom_type = 7;  
1553 - good.prom_id = b_item.prom_id;  
1554 1547
1555 } 1548 }
1556 } 1549 }
@@ -1926,23 +1919,27 @@ Page({ @@ -1926,23 +1919,27 @@ Page({
1926 }).then(res => { 1919 }).then(res => {
1927 //-------如果购物车中有相关的数据------- 1920 //-------如果购物车中有相关的数据-------
1928 if (res.data.data.total > 0) { 1921 if (res.data.data.total > 0) {
1929 - b_cart_goods = res.data.data.pageData[0]; 1922 + b_cart_goods = res.data.data.pageData;
1930 } 1923 }
1931 }) 1924 })
1932 1925
1933 //-- 判断购物车是不是有重复 -- 1926 //-- 判断购物车是不是有重复 --
1934 - var is_has=0; 1927 + var is_has=null;
1935 if(b_cart_goods) { 1928 if(b_cart_goods) {
  1929 +
  1930 +
1936 for (let jr = 0; jr < b_cart_goods.length; jr++) { 1931 for (let jr = 0; jr < b_cart_goods.length; jr++) {
1937 var b_cart_item = b_cart_goods[jr]; 1932 var b_cart_item = b_cart_goods[jr];
  1933 +
  1934 +
1938 if (g_item.prom_type == 0) { 1935 if (g_item.prom_type == 0) {
1939 if ([0, 3, 5, 7, 10].indexOf(b_cart_item.prom_type) > -1) { 1936 if ([0, 3, 5, 7, 10].indexOf(b_cart_item.prom_type) > -1) {
1940 - is_has = b_cart_item.id; 1937 + is_has = b_cart_item;
1941 break 1938 break
1942 } 1939 }
1943 } else { 1940 } else {
1944 - if (b_cart_goods.prom_type == g_item.prom_type && b_cart_goods.prom_id == g_item.prom_id) {  
1945 - is_has = b_cart_item.id; 1941 + if (b_cart_item.prom_type == g_item.prom_type && b_cart_item.prom_id == g_item.prom_id) {
  1942 + is_has = b_cart_item;
1946 break 1943 break
1947 } 1944 }
1948 } 1945 }
@@ -1952,8 +1949,8 @@ Page({ @@ -1952,8 +1949,8 @@ Page({
1952 //-- 如果就加入过购物车 -- 1949 //-- 如果就加入过购物车 --
1953 if (is_has) { 1950 if (is_has) {
1954 var updata = { 1951 var updata = {
1955 - id: is_has_cart,  
1956 - goods_num: newd.goods_num + b_cart_goods.goods_num, 1952 + id: is_has.id,
  1953 + goods_num: newd.goods_num + is_has.goods_num,
1957 goods_price: newd.goods_price, 1954 goods_price: newd.goods_price,
1958 member_goods_price: newd.goods_price, 1955 member_goods_price: newd.goods_price,
1959 store_id: os.stoid, 1956 store_id: os.stoid,