stanley-king преди 7 години
родител
ревизия
f5920642d4

+ 3 - 0
data/model/room_bargain.model.php

@@ -32,6 +32,9 @@ class room_bargainModel extends Model
     public function getBargainByUserGoods($user_id,$goods_id,$lock=false) {
         return $this->where(['user_id' => $user_id,'goods_id' => $goods_id])->lock($lock)->find();
     }
+    public function getBargainByUserGoodIDs($user_id,$goods_ids,$lock=false) {
+        return $this->where(['user_id' => $user_id,'goods_id' => ['in',$goods_ids]])->lock($lock)->select();
+    }
     public function getBargainList($condition, $field = '*', $page = 0 , $order = 'bargain_id desc', $limit = 0) {
         return $this->where($condition)->field($field)->order($order)->page($page)->limit($limit)->select();
     }

+ 15 - 2
helper/activity/bargain_goods.php

@@ -20,6 +20,7 @@ class bargain_item
     private $mLowestPrice;
     private $mRandom;
     private $mTotalNum;
+    private $mGoodsNum;
 
     public function __construct($goods_id,$params)
     {
@@ -29,6 +30,7 @@ class bargain_item
         $this->mLowestPrice = $params['lowest_price'];
         $this->mRandom = $params['type'];
         $this->mTotalNum = $params['total_num'];
+        $this->mGoodsNum = $params['goods_num'];
     }
 
     public function format()
@@ -39,7 +41,8 @@ class bargain_item
         $result['over_time'] = $this->over_time();
         $result['lowest_price'] = $this->lowest_price();
         $result['random'] = $this->random();
-        $result['total_num'] = $this->total_num();
+        $result['user_num'] = $this->total_num();
+        $result['goods_num'] = $this->goods_num();
 
         return $result;
     }
@@ -72,6 +75,10 @@ class bargain_item
     public function usable_days() {
         return $this->mUsableDays;
     }
+    public function goods_num()
+    {
+        return $this->mGoodsNum;
+    }
 }
 
 class bargain_goods
@@ -207,9 +214,15 @@ class bargain_goods
                     elseif($k == 'random') {
                         $params['type'] = intval($v);
                     }
-                    elseif($k == 'num') {
+                    elseif($k == 'user_num') {
                         $params['total_num'] = intval($v);
                     }
+                    elseif($k == 'goods_num') {
+                        $params['goods_num'] = intval($v);
+                    }
+                    else {
+
+                    }
                 }
             }
         }

+ 38 - 2
helper/goods_helper.php

@@ -201,10 +201,28 @@ class goods_helper
         }
 
         $ret['bargain_create'] = [];
-        foreach ($goods_list as $goods)
+        $mine_bargins = $this->bargains($summary_list);
+        foreach ($summary_list as $summary)
         {
-            $gid = intval($goods['goods_id']);
+            $gid = $summary['goods_id'];
             $item = activity\bargain_goods::instance()->get_info($gid);
+
+            $goods_num = $item['goods_num'];
+            $storage   = $summary['goods_storage'];
+            if($storage > intval(($goods_num - $storage) / 2)) {
+                $grabed_num = intval(($goods_num - $storage) / 2 + 0.5);
+            } else {
+                $grabed_num = $goods_num - $storage;
+            }
+
+            if(array_key_exists($gid,$mine_bargins)) {
+                $item['bargain_id'] = $mine_bargins[$gid];
+            }
+            else {
+                $item['bargain_id'] = 0;
+            }
+
+            $item['grabed_num'] = $grabed_num;
             if($item != false) {
                 $ret['bargain_create'][] = $item;
             }
@@ -212,6 +230,24 @@ class goods_helper
 
         return $ret;
     }
+    private function bargains($summary_list)
+    {
+        if(!session_helper::logined()) return [];
+
+        $gids = [];
+        foreach ($summary_list as $summary) {
+            $gids[] = $summary['goods_id'];
+        }
+        $mod_bargain = Model('room_bargain');
+        $items = $mod_bargain->getBargainByUserGoodIDs(session_helper::memberid(),$gids);
+
+        $result = [];
+        foreach ($items as $item) {
+            $gid = intval($item['goods_id']);
+            $result[$gid] = intval($item['bargain_id']);
+        }
+        return $result;
+    }
 
     /**
      * 处理商品列表(抢购、限时折扣、商品图片)

+ 9 - 2
helper/room/bargain_room.php

@@ -8,6 +8,8 @@
 
 namespace room;
 
+use url_helper;
+
 
 class bargain
 {
@@ -23,14 +25,19 @@ class bargain
         $result['goods_id']   = $this->goods_id();
         $result['discount']   = $this->discount();
         $result['lowest_price'] = $this->lowest_price();
+
+        $cur_price = $this->goods_price() - $this->discount();
+        $cur_price = intval($cur_price * 100 + 0.5);
+        $cur_price = $cur_price < 0 ? 0 : $cur_price;
+
+        $result['cur_price'] = $cur_price / 100;
         $result['add_time'] = $this->add_time();
         $result['over_time'] = $this->over_time();
         $result['user_num'] = $this->user_num();
         $result['closed'] = $this->closed();
-        $result['has_over'] = $this->has_over();
-
         return $result;
     }
+
     public function bargain_id() {
         return intval($this->mParams['bargain_id']);
     }

+ 1 - 1
helper/special_helper.php

@@ -332,7 +332,7 @@ class special_formater
             $item['image'] = "";
             $item['show_type'] = 'bargain_mine';
             $item['show_data'] = $bargain_id;
-            $item['type'] = 'web';
+            $item['type'] = 'url';
             $item['data'] = url_helper::bargain_detail_url($bargain_id);
             $item['title'] = '';
 

+ 6 - 0
helper/url_helper.php

@@ -71,6 +71,12 @@ class url_helper
         $url = BASE_SITE_URL . "/mobile/index.php?act=bargain&op=detail&client_type=wap&bargain_id={$bargain_id}";
         return $url;
     }
+    public static function bargain_open_url($bargain_id)
+    {
+        $relay_id = session_helper::share_id();
+        $url = BASE_SITE_URL . "/mobile/index.php?act=bargain&op=open&client_type=wap&bargain_id={$bargain_id}&relay_id={$relay_id}";
+        return $url;
+    }
 }
 
 class author_url

+ 31 - 1
mobile/control/bargain.php

@@ -143,6 +143,15 @@ class bargainControl extends mobileControl
             $block = special_formater::format_bargain($bargains,'我的砍价');
             $blocks[] = $block;
 
+            $summarys = $this->summary_map($ret['summary']);
+            foreach ($details as &$detail)
+            {
+                $summary = $summarys[$gid];
+                $gid = $detail['goods_id'];
+                $detail['storage'] = $summary['goods_storage'];
+                $detail['share_detail'] = $this->share_detail($detail['bargain_id'],$summary);
+            }
+
             return self::outsuccess(['special_list' => $blocks,
                 'summary'  => $ret['summary'],
                 'groupbuy' => $ret['groupbuy'],
@@ -165,8 +174,29 @@ class bargainControl extends mobileControl
             return self::outerr(errcode::ErrParamter);
         }
         else {
-            return self::outsuccess(['tpl' => new tpl_bargain($bargain_id)],'game/bargain');
+            return self::outsuccess(['tpl' => new tpl_bargain($bargain_id)],'bargain/bargain');
+        }
+    }
+
+
+    private function share_detail($bargain_id,$summary) {
+        $result = [];
+        $result['url'] = url_helper::bargain_open_url($bargain_id);
+        $result['title'] = $summary['goods_mobile_name'];
+        $result['sub_title'] = $summary['goods_mobile_name'];
+        $result['img_url'] = $summary['goods_image_url'];
+
+        return $result;
+    }
+
+    private function summary_map($summarys)
+    {
+        $ret = [];
+        foreach ($summarys as $summary) {
+            $gid = $summary['goods_id'];
+            $ret[$gid] = $summary;
         }
+        return $ret;
     }
 
     private function validate($bargain_id)