Commit e499af95e175e5dd6da0b2d87676672412d0bec8

Authored by taiyuan
2 parents 710fbe2b cbfad2cd

Merge branch 'dev' of http://git.vipzhuang.cn/wxd/MShopWeApp into dev

packageB/pages/zuhegou/index/index.js
... ... @@ -531,6 +531,9 @@ Page({
531 531 this.data.sele_g = this.data.list[index];
532 532 this.data.sele_index=index;
533 533 th.data.goodsInputNum = this.data.sele_g.num + 1;
  534 + if(this.data.sele_g.cart_num){
  535 + th.data.s_cart_num = this.data.sele_g.cart_num + 1;
  536 + }
534 537 th.add_cart_func();
535 538 },
536 539  
... ... @@ -566,6 +569,7 @@ Page({
566 569 th.data.sele_g = item;
567 570 th.data.sele_index = index;
568 571 th.data.goodsInputNum = check_num;
  572 + th.data.s_cart_num = this.data.sele_g.cart_num - 1;
569 573 th.sub_updata_cart();
570 574 return false;
571 575 }
... ... @@ -767,9 +771,11 @@ Page({
767 771 //-- 加入购物的函数 --
768 772 add_cart_func: function () {
769 773 if (oo.user_id == null) {
  774 + this.data.changing=0;
770 775 return getApp().my_warnning("还未登录!", 0, this);
771 776 }
772 777 if (!getApp().globalData.userInfo) {
  778 + this.data.changing=0;
773 779 return getApp().my_warnning("还未登录!", 0, this);
774 780 }
775 781  
... ... @@ -782,31 +788,48 @@ Page({
782 788 e.get_buy_num(o, function (ee) {
783 789 //---判断商品是否超出限购---
784 790 if (th.data.g_buy_num != null && th.data.sele_g.viplimited > 0) {
785   - if (th.data.goodsInputNum + th.data.g_buy_num.get(th.data.sele_g.goods_id) > th.data.sele_g.viplimited) {
  791 + if (th.data.goodsInputNum + th.data.g_buy_num.get(th.data.sele_g.goods_id).gd_buynum > th.data.sele_g.viplimited) {
786 792 wx.showModal({
787 793 title: '提示',
788 794 content: '超出商品限购'
789 795 });
  796 + th.data.changing=0;
790 797 return false;
791 798 }
  799 + if(th.data.s_cart_num){
  800 + if (th.data.s_cart_num + th.data.g_buy_num.get(th.data.sele_g.goods_id).gd_buynum > th.data.sele_g.viplimited) {
  801 + wx.showModal({
  802 + title: '提示',
  803 + content: '超出商品限购'
  804 + });
  805 + th.data.changing=0;
  806 + return false;
  807 + }
  808 + }
  809 +
792 810 }
793 811 //---判断商品是否超出活动限购---
794 812 if (th.data.sele_g.buyqty > 0) {
795   - if (th.data.goodsInputNum > th.data.sele_g.buyqty) {
  813 + if (th.data.goodsInputNum+ th.data.g_buy_num.get(th.data.sele_g.goods_id).prom_buybum > th.data.sele_g.buyqty) {
796 814 wx.showModal({
797 815 title: '提示',
798 816 content: '超出商品活动限购'
799 817 });
  818 + th.data.changing=0;
800 819 return false;
801 820 }
802 821 }
803 822  
804   - if (th.data.goodsInputNum <= 0) return s.my_warnning("商品数量不能为0", 0, th);
  823 + if (th.data.goodsInputNum <= 0){
  824 + this.data.changing=0;return s.my_warnning("商品数量不能为0", 0, th);
  825 + }
805 826 if (th.data.sto_sele_name == null || th.data.sto_sele_name == undefined)
806 827 this.setData({
807 828 sto_sele_name: ""
808 829 });
809   - if (th.data.sto_sele_name == "") return s.my_warnning("请选择门店", 0, th);
  830 + if (th.data.sto_sele_name == "") {
  831 + th.data.changing=0;return s.my_warnning("请选择门店", 0, th);
  832 + }
810 833  
811 834 //--------------此时操作的数据------------
812 835 var newd = {
... ... @@ -843,8 +866,12 @@ Page({
843 866 if (newd.goods_id == getApp().globalData.room_goods_id) newd.room_id = getApp().globalData.room_id;
844 867 }
845 868  
846   - if (o.store_count <= 0) return getApp().my_warnning("库存已为空!", 0, th);
847   - if (o.store_count < e.data.goodsInputNum) return getApp().my_warnning("库存不足!", 0, th);
  869 + if (o.store_count <= 0){
  870 + th.data.changing=0;return getApp().my_warnning("库存已为空!", 0, th);
  871 + }
  872 + if (o.store_count < e.data.goodsInputNum){
  873 + th.data.changing=0;return getApp().my_warnning("库存不足!", 0, th);
  874 + }
848 875 th.add_cart_next(o, newd); //加入购物车下一步
849 876  
850 877 })
... ... @@ -881,11 +908,11 @@ Page({
881 908 th.data.adding = 0;
882 909 return getApp().my_warnning("库存不足!", 0, th);
883 910 }
884   - if (th.data.goodsInputNum > o.buyqty && o.buyqty>0) {
  911 + if (th.data.goodsInputNum+ th.data.g_buy_num.get(th.data.sele_g.goods_id).prom_buybum > o.buyqty && o.buyqty>0) {
885 912 th.data.adding = 0;
886 913 return getApp().my_warnning("超出商品活动限购!", 0, th);
887 914 }
888   - if (th.data.goodsInputNum + th.data.g_buy_num.get(th.data.sele_g.goods_id) > th.data.sele_g.viplimited
  915 + if (th.data.goodsInputNum + th.data.g_buy_num.get(th.data.sele_g.goods_id).prom_buybum > th.data.sele_g.viplimited
889 916 && th.data.sele_g.viplimited > 0
890 917 ) {
891 918 th.data.adding = 0;
... ... @@ -900,7 +927,9 @@ Page({
900 927 member_goods_price: newd.goods_price,
901 928 store_id: os.stoid,
902 929 };
903   -
  930 + if(th.data.s_cart_num){
  931 + updata.goods_num=th.data.s_cart_num;
  932 + }
904 933 //---是不是从收藏夹出来的---
905 934 if (th.data.c_guide_id) {
906 935 updata['guide_id'] = th.data.c_guide_id;
... ... @@ -915,7 +944,7 @@ Page({
915 944 data: updata,
916 945 success: function (t) {
917 946 th.setData({
918   - [txt1]: updata.goods_num,
  947 + [txt1]: th.data.goodsInputNum,
919 948 [txt2]: true,
920 949 [txt]: true,
921 950 [txt3]: newd.goods_price,
... ... @@ -925,8 +954,6 @@ Page({
925 954 th.re_sum_price();//重新统计数量和总金额
926 955 }
927 956 });
928   -
929   -
930 957 } else {
931 958  
932 959 getApp().request.post("/api/weshop/cart/save", {
... ... @@ -1287,7 +1314,6 @@ Page({
1287 1314 } else {
1288 1315 item = th.data.only_pk[index]; //当没有门店分类的时候
1289 1316 }
1290   -
1291 1317 } else {
1292 1318 var index = th.data.sec_pick_index;
1293 1319 item = th.data.sec_sto.s_arr[index];
... ... @@ -1437,25 +1463,36 @@ Page({
1437 1463 if (map && map.has(gd.goods_id)) {
1438 1464 "function" == typeof func && func();
1439 1465 } else {
  1466 + var res1=null;
1440 1467 //----获取商品购买数----
1441   - getApp().request.get("/api/weshop/ordergoods/getUserBuyGoodsNum", {
  1468 + getApp().request.promiseGet("/api/weshop/ordergoods/getUserBuyGoodsNum", {
1442 1469 data: {
1443 1470 store_id: os.stoid,
1444 1471 user_id: user_id,
1445   - goods_id: gd.goods_id
  1472 + goods_id: gd.goods_id,
  1473 + prom_type: gd.prom_type,
  1474 + prom_id: gd.prom_id
1446 1475 },
1447   - success: function (t) {
1448   - if (t.data.code == 0) {
1449   - var g_buy_num = t.data.data.goodsbuynum;
1450   - if (!map) map = new Map();
1451   - map.set(gd.goods_id, g_buy_num);
1452   - th.setData({
1453   - g_buy_num: map
1454   - });
1455   - "function" == typeof func && func();
1456   - }
  1476 + }).then(res2=>{
  1477 + var g_buy_num=0;
  1478 + var promgoodsbuynum=0;
  1479 + if (res2.data.code == 0) {
  1480 + var buy_num_data = res2.data.data;
  1481 + if (buy_num_data.promgoodsbuynum) promgoodsbuynum = buy_num_data.promgoodsbuynum;
  1482 + g_buy_num = buy_num_data.goodsbuynum;
1457 1483 }
1458   - });
  1484 +
  1485 + if (!map) map = new Map();
  1486 + var ob={
  1487 + gd_buynum:g_buy_num,
  1488 + prom_buybum:promgoodsbuynum,
  1489 + }
  1490 + map.set(gd.goods_id, ob);
  1491 + th.setData({
  1492 + g_buy_num: map
  1493 + });
  1494 + "function" == typeof func && func();
  1495 + })
1459 1496 }
1460 1497 },
1461 1498  
... ... @@ -1477,6 +1514,11 @@ Page({
1477 1514 goods_price: cur_price,
1478 1515 store_id: os.stoid,
1479 1516 };
  1517 +
  1518 + if(th.data.s_cart_num){
  1519 + updata.goods_num=th.data.s_cart_num;
  1520 + }
  1521 +
1480 1522 //---是不是从收藏夹出来的---
1481 1523 if (th.data.c_guide_id) {
1482 1524 updata['guide_id'] = th.data.c_guide_id;
... ... @@ -1496,7 +1538,6 @@ Page({
1496 1538 [txt2]: true,
1497 1539 [txt]: true,
1498 1540 });
1499   -
1500 1541 th.data.adding = 0;
1501 1542 th.data.sele_store = 1;
1502 1543 th.re_sum_price();//重新统计数量和总金额
... ... @@ -1525,6 +1566,7 @@ Page({
1525 1566 var txt2 = "list[" + index + "].showNum";
1526 1567 var txt3 = "list[" + index + "].cart_id";
1527 1568 var txt4 = "list[" + index + "].current_price";
  1569 + var txt5 = "list[" + index + "].cart_num";
1528 1570  
1529 1571 //----先看会员在购物车中是否加入了该商品-----
1530 1572 getApp().request.get("/api/weshop/cart/page", {
... ... @@ -1537,39 +1579,89 @@ Page({
1537 1579 success: function (re) {
1538 1580 if (re.data.data.total > 0) {
1539 1581 var item = re.data.data.pageData[0];
  1582 + th.get_buy_num(th.data.sele_g,function () {
  1583 + //当前的价格要更新进去
  1584 + var cur_price = th.data.sele_g.shop_price;
  1585 + if (th.data.card_field && th.data.sele_g[th.data.card_field]) {
  1586 + cur_price = th.data.sele_g[th.data.card_field];
  1587 + }
1540 1588  
1541   - //当前的价格要更新进去
1542   - var cur_price = th.data.sele_g.shop_price;
1543   - if (th.data.card_field && th.data.sele_g[th.data.card_field]) {
1544   - cur_price = th.data.sele_g[th.data.card_field];
1545   - }
  1589 + var prom_buybum=0;
  1590 + var gd_buynum=0;
  1591 + //加入也要控制一下限购
  1592 + var check_obj=th.data.g_buy_num.get(th.data.sele_g.goods_id);
  1593 + if(check_obj.gd_buynum && check_obj.gd_buynum>0) gd_buynum=check_obj.gd_buynum;
  1594 + if(check_obj.prom_buybum && check_obj.prom_buybum>0) prom_buybum=check_obj.prom_buybum;
  1595 +
  1596 + if(check_obj){
  1597 + if(check_obj.prom_buybum && check_obj.prom_buybum>th.data.sele_g.buyqty &&
  1598 + th.data.sele_g.buyqty>0
  1599 + ){
  1600 + wx.showToast({
  1601 + title: "您的已购数量超出活动的限购",
  1602 + icon: 'none',
  1603 + duration: 2000
  1604 + });
  1605 + return false;
  1606 + }
  1607 + if(check_obj.gd_buynum && check_obj.gd_buynum>th.data.sele_g.viplimited &&
  1608 + th.data.sele_g.viplimited>0
  1609 + ){
  1610 + wx.showToast({
  1611 + title: "您的已购数量超出商品的限购",
  1612 + icon: 'none',
  1613 + duration: 2000
  1614 + });
  1615 + return false;
  1616 + }
  1617 + }
1546 1618  
1547   - th.setData({
1548   - [txt1]: item.goods_num,
1549   - [txt2]: true,
1550   - [txt]: true,
1551   - [txt3]: item.id,
1552   - [txt4]: cur_price,
1553   - });
  1619 + item.cbuy=-1;
  1620 + var cbuy=th.data.sele_g.viplimited>0?th.data.sele_g.viplimited-gd_buynum:-1;
  1621 + if(cbuy>-1) item.cbuy=cbuy;
  1622 + var cbuy2=th.data.sele_g.buyqty>0?th.data.sele_g.buyqty-prom_buybum:-1;
  1623 + if(cbuy2>-1){
  1624 + if(item.cbuy==-1 || item.cbuy>cbuy2) item.cbuy=cbuy2;
  1625 + }
1554 1626  
1555   - var updata = {
1556   - id: item.id,
1557   - prom_type: 7,
1558   - goods_price: cur_price,
1559   - prom_id: th.data.act.id
1560   - };
1561   - if (getApp().globalData.guide_id) {
1562   - updata['guide_id'] = getApp().globalData.guide_id;
1563   - updata['guide_type'] = 0;
1564   - }
  1627 + var num=item.goods_num;
  1628 + if(item.cbuy>-1 && item.cbuy<item.goods_num){
  1629 + num=item.cbuy;
  1630 + }
  1631 + th.setData({
  1632 + [txt1]: num,
  1633 + [txt2]: true,
  1634 + [txt]: true,
  1635 + [txt3]: item.id,
  1636 + [txt4]: cur_price,
  1637 + [txt5]: item.goods_num,
  1638 + });
1565 1639  
1566   - getApp().request.put("/api/weshop/cart/update", {
1567   - data: updata,
1568   - success: function (t) {
  1640 + if(item.cbuy>-1){
  1641 + th.setData({
  1642 + [txt5]: item.cbuy,
  1643 + });
1569 1644 }
1570   - });
1571 1645  
1572   - th.re_sum_price();
  1646 + var updata = {
  1647 + id: item.id,
  1648 + prom_type: 7,
  1649 + goods_price: cur_price,
  1650 + prom_id: th.data.act.id
  1651 + };
  1652 + if (getApp().globalData.guide_id) {
  1653 + updata['guide_id'] = getApp().globalData.guide_id;
  1654 + updata['guide_type'] = 0;
  1655 + }
  1656 +
  1657 + getApp().request.put("/api/weshop/cart/update", {
  1658 + data: updata,
  1659 + success: function (t) {
  1660 + }
  1661 + });
  1662 + th.re_sum_price();
  1663 + })
  1664 +
1573 1665 } else {
1574 1666 func();
1575 1667 }
... ... @@ -1627,7 +1719,7 @@ Page({
1627 1719 }
1628 1720  
1629 1721 //看一下剩下的数量有没有满足组合购的要求,以及要不要倍增
1630   - if (this.data.act.is_bz && no_in_arr.length >= this.data.act.zhbuyqty) {
  1722 + if (this.data.act.is_bz && no_in_arr.length > this.data.act.zhbuyqty) {
1631 1723 //看一下是几倍
1632 1724 var be = parseInt(no_in_arr.length / this.data.act.zhbuyqty);
1633 1725 aprice += be * aprice;
... ...
pages/cart/cart/cart.js
... ... @@ -1240,7 +1240,11 @@ Page({
1240 1240 },
1241 1241 }).then(res => {
1242 1242 var buy_num_data = res.data.data;
1243   - if (buy_num_data.promgoodsbuynum) promgoodsbuynum = buy_num_data.promgoodsbuynum;
  1243 + if (buy_num_data.promgoodsbuynum) {
  1244 + promgoodsbuynum = buy_num_data.promgoodsbuynum;
  1245 + var txt="requestData[" + pitem + "].goods[" + item + "].zh_b_num";
  1246 + th.setData({[txt]:promgoodsbuynum});
  1247 + }
1244 1248 goodsbuynum = buy_num_data.goodsbuynum;
1245 1249 })
1246 1250  
... ...
pages/cart/cart/zh_calculate.js
... ... @@ -51,7 +51,7 @@ module.exports = {
51 51 }
52 52 },
53 53  
54   - //把组合购的商品价格计算出来
  54 + //把组合购的商品价格计算出来,同时每个会员都有购买组合商品的上限!zh_b_num是已经购买了多少件
55 55 calculate_zh: function(car, a, th) {
56 56 var car_item = car[a];
57 57 var tfeel = 0,
... ... @@ -81,6 +81,7 @@ module.exports = {
81 81 var need_to_buy = 0;
82 82 var all_zhqty = 0; //所有商品要求起购数之和
83 83 var no_in_arr = []; //剩余的未加入组合购
  84 + var out_arr=[]; //超出活动限购的商品放入
84 85  
85 86 var title =""; //提示语;
86 87 //var goods = bitem.goods;
... ... @@ -109,7 +110,36 @@ module.exports = {
109 110  
110 111 for (var i in goods) {
111 112 var item = goods[i];
112   - item.num = get_num(item).goods_num;
  113 + item.goods_price=get_num(item).goods_price;
  114 + item.offline_price=get_num(item).offline_price;
  115 + var cart_num=get_num(item).goods_num;
  116 + var zh_b_num=get_num2(item).zh_b_num;
  117 +
  118 + //-- 当商品有购买的时候,以及有限购的时候 --
  119 + if(zh_b_num>0 && item.buyqty>0){
  120 +
  121 + var cbuy=item.buyqty-zh_b_num;
  122 + //当可买的数量为0
  123 + if(cbuy<=0){
  124 + item.num=0;
  125 + out_arr.push({
  126 + price: item.goods_price,offline_price:item.offline_price,goods_id:item.goods_id,num:cart_num
  127 + })
  128 + }else{
  129 + if(cbuy>=cart_num) item.num =cart_num;
  130 + else{
  131 + item.num =cbuy;
  132 + out_arr.push({
  133 + price: item.goods_price,offline_price:item.offline_price,goods_id:item.goods_id,num:cart_num-cbuy
  134 + })
  135 + }
  136 + }
  137 +
  138 + }else{
  139 + item.num =cart_num;
  140 + }
  141 +
  142 +
113 143 item.goods_price=get_num(item).goods_price;
114 144 item.offline_price=get_num(item).offline_price;
115 145  
... ... @@ -166,8 +196,6 @@ module.exports = {
166 196 no_in_arr.pop();
167 197 }
168 198 }
169   -
170   -
171 199 //算一下剩余的钱
172 200 if (no_in_arr.length) {
173 201 for (var ii in no_in_arr) {
... ... @@ -188,6 +216,31 @@ module.exports = {
188 216 }
189 217 }
190 218 }
  219 +
  220 + //超量的部分也要计算一下
  221 + if(out_arr.length){
  222 + for (var m in out_arr) {
  223 + var item = out_arr[m];
  224 + var gitem=get_num2(item);
  225 + if(gitem) {
  226 + if (!gitem.need_downlow_num) {
  227 + gitem.need_downlow_num = item.num;
  228 + }
  229 + else {
  230 + gitem.need_downlow_num+=item.num;
  231 + }
  232 + aprice += item.price*item.num;
  233 + if (item.offline_price) {
  234 + offline_price += (item.goods_price - item.offline_price)*item.num;
  235 + offline_num += item.num;
  236 + }
  237 +
  238 + }
  239 + }
  240 + }
  241 +
  242 +
  243 +
191 244 all_price = aprice;
192 245  
193 246 //-- 设置还需要购买多少件,享受活动,前段显示 --
... ... @@ -254,7 +307,6 @@ module.exports = {
254 307 console.log('nyf111');
255 308 console.log(car_item);
256 309  
257   -
258 310 var res = {
259 311 tfeel: tfeel,
260 312 offline_price: offline_price,
... ...