Selaa lähdekoodia

增加抢购限时活动

stanley-king 8 vuotta sitten
vanhempi
commit
46fd04cd56

+ 15 - 1
data/model/goods_combo.model.php

@@ -22,6 +22,8 @@ class goods_comboModel extends Model {
             foreach ((array)$insert as $v) {
                 if ($v['goods_id']) $this->_dGoodsComboCache($v['goods_id']);
             }
+
+            $this->_wVersionCache();
         }
         return $result;
     }
@@ -31,7 +33,7 @@ class goods_comboModel extends Model {
      * @param unknown $condition
      */
     public function getGoodsComboList($condition) {
-        return $this->where($condition)->select();
+        return $this->where($condition)->limit(false)->select();
     }
     
     /**
@@ -47,6 +49,7 @@ class goods_comboModel extends Model {
             foreach ($list as $v) {
                 $this->_dGoodsComboCache($v['goods_id']);
             }
+            $this->_wVersionCache();
         }
         return $result;
     }
@@ -96,4 +99,15 @@ class goods_comboModel extends Model {
     private function _dGoodsComboCache($goods_id) {
         return dcache($goods_id, 'goods_combo');
     }
+
+    private function _wVersionCache()
+    {
+        $version = rkcache('activity_version_rcombo');
+        if(empty($version)) {
+            $version = 1;
+        } else {
+            $version = intval($version) + 1;
+        }
+        return wkcache("activity_version_rcombo", $version);
+    }
 }

+ 1 - 1
data/model/goods_gift.model.php

@@ -25,7 +25,7 @@ class goods_giftModel extends Model
      * @param unknown $condition
      */
     public function getGoodsGiftList($condition) {
-        return $this->where($condition)->select();
+        return $this->where($condition)->limit(false)->select();
     }
     
     public function getGoodsGiftListByGoodsId($goods_id) {

+ 19 - 3
data/model/groupbuy.model.php

@@ -7,8 +7,8 @@
  *
  */
 defined('InShopNC') or exit('Access Invalid!');
-class groupbuyModel extends Model{
-
+class groupbuyModel extends Model
+{
     const GROUPBUY_STATE_REVIEW = 10;
     const GROUPBUY_STATE_NORMAL = 20;
     const GROUPBUY_STATE_REVIEW_FAIL = 30;
@@ -263,6 +263,7 @@ class groupbuyModel extends Model{
         if ($result) {
             // 更新商品抢购缓存
             $this->_dGoodsGroupbuyCache($param['goods_commonid']);
+            $this->_wGroupbuyChangedCache();
             return $result;
         } else {
             return false;
@@ -306,6 +307,8 @@ class groupbuyModel extends Model{
                     // 更新商品抢购缓存
                     $this->_dGoodsGroupbuyCache($val['goods_commonid']);
                 }
+
+                $this->_wGroupbuyChangedCache();
             }
         }
         return $result;
@@ -421,7 +424,8 @@ class groupbuyModel extends Model{
         $groupbuy_list = $this->getGroupbuyExtendList($condition);
         $result = $this->where($condition)->delete();
 
-        if(!empty($groupbuy_list) && $result) {
+        if(!empty($groupbuy_list) && $result)
+        {
             foreach ($groupbuy_list as $value) {
                 // 商品解锁
                 $this->_unlockGoods($value['goods_commonid']);
@@ -444,6 +448,7 @@ class groupbuyModel extends Model{
                     @unlink($path.$base_name.'_max.'.$ext);
                 }
             }
+            $this->_wGroupbuyChangedCache();
         }
         return true;
     }
@@ -538,6 +543,17 @@ class groupbuyModel extends Model{
         return dcache($goods_commonid, 'goods_groupbuy');
     }
 
+    private function _wGroupbuyChangedCache()
+    {
+        $version = rkcache('activity_version_groupbuy');
+        if(empty($version)) {
+            $version = 1;
+        } else {
+            $version = intval($version) + 1;
+        }
+        return wkcache("activity_version_groupbuy", $version);
+    }
+
     /**
      * 读取抢购分类
      *

+ 24 - 5
data/model/p_booth.model.php

@@ -63,7 +63,8 @@ class p_boothModel extends Model {
      * @return boolean
      */
     public function addBoothQuota($insert, $replace = false) {
-        return $this->table('p_booth_quota')->insert($insert, $replace);
+        $ret = $this->table('p_booth_quota')->insert($insert, $replace);
+        return $ret;
     }
 
     /**
@@ -73,7 +74,8 @@ class p_boothModel extends Model {
      * @return array
      */
     public function editBoothQuota($update, $condition) {
-        return $this->table('p_booth_quota')->where($condition)->update($update);
+        $ret = $this->table('p_booth_quota')->where($condition)->update($update);
+        return $ret;
     }
 
     /**
@@ -118,7 +120,9 @@ class p_boothModel extends Model {
      * @return boolean
      */
     public function addBoothGoods($insert) {
-        return $this->table('p_booth_goods')->insert($insert);
+        $ret = $this->table('p_booth_goods')->insert($insert);
+        $this->_wVersionCache();
+        return $ret;
     }
 
     /**
@@ -128,7 +132,9 @@ class p_boothModel extends Model {
      * @param array $condition
      */
     public function editBooth($update, $condition) {
-        return $this->table('p_booth_goods')->where($condition)->update($update);
+        $ret = $this->table('p_booth_goods')->where($condition)->update($update);
+        $this->_wVersionCache();
+        return $ret;
     }
 
     /**
@@ -159,7 +165,9 @@ class p_boothModel extends Model {
      * @return boolean
      */
     public function delBoothGoods($condition) {
-        return $this->table('p_booth_goods')->where($condition)->delete();
+        $ret = $this->table('p_booth_goods')->where($condition)->delete();
+        $this->_wVersionCache();
+        return $ret;
     }
 
      /**
@@ -180,4 +188,15 @@ class p_boothModel extends Model {
         }
         return $condition;
     }
+
+    private function _wVersionCache()
+    {
+        $version = rkcache('activity_version_fullsent');
+        if(empty($version)) {
+            $version = 1;
+        } else {
+            $version = intval($version) + 1;
+        }
+        return wkcache("activity_version_fullsent", $version);
+    }
 }

+ 17 - 2
data/model/p_mansong.model.php

@@ -206,6 +206,7 @@ class p_mansongModel extends Model{
         $result = $this->insert($param);
         if ($result) {
             $this->_dGoodsMansongCache($param['store_id']);
+            $this->_wVersionCache();
         }
         return $result;
     }
@@ -227,6 +228,7 @@ class p_mansongModel extends Model{
             foreach ($mansong_list as $val) {
                 $this->_dGoodsMansongCache($val['store_id']);
             }
+            $this->_wVersionCache();
         }
         return $result;
     }
@@ -251,7 +253,9 @@ class p_mansongModel extends Model{
         $model_mansong_rule = Model('p_mansong_rule');
         $model_mansong_rule->delMansongRule($condition);
 
-        return $this->where($condition)->delete();
+        $ret = $this->where($condition)->delete();
+        $this->_wVersionCache();
+        return $ret;
     }
 
     /**
@@ -271,7 +275,7 @@ class p_mansongModel extends Model{
      * 过期满送修改状态
      */
     public function editExpireMansong() {
-        $updata = array();
+        $update = array();
         $update['state'] = self::MANSONG_STATE_CLOSE;
 
         $condition = array();
@@ -307,4 +311,15 @@ class p_mansongModel extends Model{
     private function _dGoodsMansongCache($store_id) {
         return dcache($store_id, 'goods_mansong');
     }
+
+    private function _wVersionCache()
+    {
+        $version = rkcache('activity_version_fullsent');
+        if(empty($version)) {
+            $version = 1;
+        } else {
+            $version = intval($version) + 1;
+        }
+        return wkcache("activity_version_fullsent", $version);
+    }
 }

+ 19 - 3
data/model/p_xianshi.model.php

@@ -94,7 +94,9 @@ class p_xianshiModel extends Model{
 	 */
     public function addXianshi($param){
         $param['state'] = self::XIANSHI_STATE_NORMAL;
-        return $this->insert($param);	
+        $ret = $this->insert($param);
+        $this->_wVersionCache();
+        return $ret;
     }
 
     /*
@@ -105,7 +107,9 @@ class p_xianshiModel extends Model{
      *
 	 */
     public function editXianshi($update, $condition){
-        return $this->where($condition)->update($update);
+        $ret = $this->where($condition)->update($update);
+        $this->_wVersionCache();
+        return $ret;
     }
 
 	/*
@@ -129,7 +133,9 @@ class p_xianshiModel extends Model{
             $model_xianshi_goods->delXianshiGoods(array('xianshi_id'=>array('in', $xianshi_id_string)));
         }
 
-        return $this->where($condition)->delete();
+        $ret = $this->where($condition)->delete();
+        $this->_wVersionCache();
+        return $ret;
     }
 
 	/*
@@ -205,4 +211,14 @@ class p_xianshiModel extends Model{
         return true;
     }
 
+    private function _wVersionCache()
+    {
+        $version = rkcache('activity_version_limit');
+        if(empty($version)) {
+            $version = 1;
+        } else {
+            $version = intval($version) + 1;
+        }
+        return wkcache("activity_version_limit", $version);
+    }
 }

+ 112 - 0
helper/activity/bundling.php

@@ -0,0 +1,112 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: stanley-king
+ * Date: 16/8/16
+ * Time: 上午11:15
+ */
+
+namespace activity;
+
+use \algorithm;
+
+class bundling
+{
+    const STATE_OPEN = 1;        // 开启
+    const STATE_CLOSE = 0;       // 关闭
+    const STORE_ID = 6;
+
+    static private $stInstance = null;
+    private $bundling_list;
+    private $bundling_goods;
+    private $goods_ids;
+
+    private $cur_version = 0;
+
+    private function __construct()
+    {
+
+    }
+    static public function instance()
+    {
+        if(self::$stInstance == null) {
+            self::$stInstance = new bundling();
+        }
+        self::$stInstance->init();
+
+        return self::$stInstance;
+    }
+
+    private function init()
+    {
+        $need_reset = false;
+        $version = rkcache('activity_version_bundling');
+        if(empty($version)) {
+            $this->cur_version = 1;
+            wkcache("activity_version_bundling", $this->cur_version);
+            $need_reset = true;
+        }
+        else
+        {
+            $version = intval($version);
+            if($version > $this->cur_version) {
+                $need_reset = true;
+                $this->cur_version = $version;
+            }
+        }
+        if($need_reset)
+        {
+            $mod = Model('p_bundling');
+            $condition = array();
+            $condition['store_id'] = self::STORE_ID;
+            $condition['state'] = self::STATE_OPEN;
+
+            $this->bundling_list = array();
+            $this->bundling_goods = array();
+            $this->goods_ids = array();
+
+            $list = $mod->getBundlingList(array('bl_state' => self::STATE_OPEN));
+            foreach ($list as $val)
+            {
+                $bl_id = intval($val['bl_id']);
+                $this->bundling_list[$bl_id] = $val;
+                $this->bundling_goods[$bl_id] = array();
+                $bgoods = $mod->getBundlingGoodsList(array('bl_id' => $bl_id, 'bl_appoint' => 1), 'bl_id,goods_id');
+                foreach ($bgoods as $goods) {
+                    $goods_id =intval($goods['goods_id']);
+                    array_push($this->bundling_goods[$bl_id],$goods);
+                    $this->add_goods($goods_id);
+                }
+            }
+        }
+    }
+
+    public function isTakepart($goods_id,&$act_id)
+    {
+        $goods_id = intval($goods_id);
+        if(algorithm::binary_search($this->goods_ids,$goods_id))
+        {
+            foreach ($this->bundling_goods as $bid => $goods_list)
+            {
+                foreach ($goods_list as $goods)
+                {
+                    $gid = intval($goods['goods_id']);
+                    if($goods_id == $gid) {
+                        $act_id = $bid;
+                        return true;
+                    }
+                }
+            }
+        }
+
+        return false;
+    }
+
+    private function add_goods($goods_id)
+    {
+        if(algorithm::binary_search($this->goods_ids,$goods_id) == false) {
+            $pos = algorithm::lower_bonud($this->goods_ids,$goods_id);
+            algorithm::array_insert($this->goods_ids,$pos,$goods_id);
+        }
+    }
+}

+ 97 - 0
helper/activity/full_sent.php

@@ -0,0 +1,97 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: stanley-king
+ * Date: 16/8/17
+ * Time: 下午3:49
+ */
+
+namespace activity;
+
+
+class full_sent
+{
+    const MANSONG_STATE_NORMAL = 1;
+    const MANSONG_STATE_CLOSE = 2;
+    const MANSONG_STATE_CANCEL = 3;
+    const STORE_ID = 6;
+
+    static private $stInstance = null;
+    private $cur_version = 0;
+    private $contents;
+
+    private function __construct()
+    {
+    }
+
+    static public function instance()
+    {
+        if(self::$stInstance == null) {
+            self::$stInstance = new full_sent();
+        }
+        self::$stInstance->init();
+
+        return self::$stInstance;
+    }
+
+    public function contents()
+    {
+        $contents = array();
+        $cur = time();
+        foreach ($this->contents as $item) {
+            $start = intval($item['start_time']);
+            $end   = intval($item['end_time']);
+            if($cur >= $start && $cur < $end) {
+                array_push($contents,$item);
+            }
+        }
+
+        return $contents;
+    }
+
+    private function init()
+    {
+        $need_reset = false;
+        $version = rkcache('activity_version_fullsent');
+        if(empty($version)) {
+            $this->cur_version = 1;
+            wkcache("activity_version_fullsent", $this->cur_version);
+            $need_reset = true;
+        }
+        else
+        {
+            $version = intval($version);
+            if($version > $this->cur_version) {
+                $need_reset = true;
+                $this->cur_version = $version;
+            }
+        }
+
+        if($need_reset)
+        {
+            $mod = Model('p_mansong');
+            $condition = array();
+            $condition['store_id'] = self::STORE_ID;
+            $condition['state'] = array('in', array(self::MANSONG_STATE_NORMAL));
+
+            $list = $mod->getMansongList($condition);
+            $this->contents = array();
+            foreach ($list as $val) {
+                array_push($this->contents,$this->filter($val));
+            }
+        }
+    }
+
+    private function filter($info)
+    {
+        if(!empty($info)) {
+            unset($$info['quota_id']);
+            unset($$info['member_id']);
+            unset($$info['store_id']);
+            unset($$info['member_name']);
+            unset($$info['store_name']);
+            unset($$info['state']);
+        }
+        return $info;
+    }
+}

+ 89 - 0
helper/activity/goods_gift.php

@@ -0,0 +1,89 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: stanley-king
+ * Date: 16/8/17
+ * Time: 下午5:00
+ */
+
+namespace activity;
+
+
+class gift_item
+{
+    public $goods_id;
+    public $amount;
+}
+
+
+class goods_gift
+{
+    static private $stInstance = null;
+    private $cur_version = 0;
+
+    private $contents;
+
+    private function __construct()
+    {
+
+    }
+
+    static public function instance()
+    {
+        if(self::$stInstance == null) {
+            self::$stInstance = new goods_gift();
+        }
+        self::$stInstance->init();
+
+        return self::$stInstance;
+    }
+
+    private function init()
+    {
+        $need_reset = false;
+        $version = rkcache('activity_version_gift');
+        if(empty($version)) {
+            $this->cur_version = 1;
+            wkcache("activity_version_gift", $this->cur_version);
+            $need_reset = true;
+        }
+        else
+        {
+            $version = intval($version);
+            if($version > $this->cur_version) {
+                $need_reset = true;
+                $this->cur_version = $version;
+            }
+        }
+        if($need_reset)
+        {
+            $mod = Model('goods_gift');
+            $list = $mod->getGoodsGiftList(array());
+
+            $this->contents = array();
+            foreach ($list as $val)
+            {
+                $common_id = intval($val['goods_commonid']);
+                $giftid = intval($val['gift_goodsid']);
+                $amount = intval($val['gift_amount']);
+
+
+                if(array_key_exists($common_id,$this->contents) == false) {
+                    $this->contents[$common_id] = array();
+                }
+                $item = array('goods_id' => $giftid,'amount' => $amount);
+                array_push($this->contents[$common_id],$item);
+            }
+        }
+    }
+
+    public function gifts($common_id)
+    {
+        $common_id = intval($common_id);
+        if(array_key_exists($common_id,$this->contents)) {
+            return $this->contents[$common_id];
+        } else {
+            return false;
+        }
+    }
+}

+ 180 - 0
helper/activity/groupbuy.php

@@ -0,0 +1,180 @@
+<?php
+
+/**
+ * Created by PhpStorm.
+ * User: stanley-king
+ * Date: 16/8/15
+ * Time: 下午4:04
+ */
+
+namespace activity;
+
+class group_item
+{
+//"groupbuy_id": "11",
+//"groupbuy_name": "新品上架,超低价购",
+//"start_time": "1471874040",
+//"end_time": "1472572800",
+//"goods_id": "4127",
+//"goods_commonid": "2582",
+//"goods_name": "雅漾舒缓特护洁面乳200ml 200ml",
+//"store_id": "6",
+//"store_name": "熊猫美妆",
+//"goods_price": "295.00",
+//"groupbuy_price": "100.00",
+//"groupbuy_rebate": "3.39",
+//"virtual_quantity": "100",
+//"upper_limit": "2",
+//"buyer_count": "0",
+//"buy_quantity": "0",
+//"groupbuy_intro": "",
+//"state": "20",
+//"recommended": "0",
+//"views": "0",
+//"groupbuy_image": "6_05252180202959484.jpg",
+//"groupbuy_image1": "6_05252180208131012.jpg",
+//"remark": "好玩"
+
+    private $mParam;
+    public function __construct($param)
+    {
+        $this->mParam = null;
+        if(isset($param) && is_array($param))
+        {
+            $this->mParam = $param;
+        }
+    }
+
+    public function to_array()
+    {
+        $info['groupbuy_id']   = intval($this->mParam['groupbuy_id']);
+        $info['groupbuy_name'] = $this->mParam['groupbuy_name'];
+        $info['remark']        = $this->mParam['remark'];
+        $info['start_time']    = intval($this->mParam['start_time']);
+        $info['end_time']      = intval($this->mParam['end_time']);
+        $info['goods_id']      = intval($this->mParam['goods_id']);
+        $info['promotion_price'] = $this->mParam['groupbuy_price'];
+        $info['rebate']          = $this->mParam['groupbuy_rebate'];
+        $info['quantity']        = $this->mParam['virtual_quantity'];
+        $info['upper_limit']     = $this->mParam['upper_limit'];
+        $info['buyer_count']     = $this->mParam['buyer_count'];
+        $info['groupbuy_intro']  = $this->mParam['groupbuy_intro'];
+        $info['groupbuy_image'] = $this->mParam['groupbuy_image'];
+        $info['groupbuy_image1'] = $this->mParam['groupbuy_image1'];
+
+        return $info;
+    }
+}
+
+class groupbuy
+{
+    const GROUPBUY_STATE_REVIEW = 10;
+    const GROUPBUY_STATE_NORMAL = 20;
+    const GROUPBUY_STATE_REVIEW_FAIL = 30;
+    const GROUPBUY_STATE_CANCEL = 31;
+    const GROUPBUY_STATE_CLOSE = 32;
+    const STORE_ID = 6;
+
+    static private $stInstance = null;
+    private $group_list;
+    private $goodsid_gid;
+
+    private $cur_version = 0;
+
+    private function __construct()
+    {
+
+    }
+    static public function instance()
+    {
+        if(self::$stInstance == null) {
+            self::$stInstance = new groupbuy();
+        }
+        self::$stInstance->init();
+
+        return self::$stInstance;
+    }
+
+    private function init()
+    {
+        $need_reset = false;
+        $version = rkcache('activity_version_groupbuy');
+        if(empty($version)) {
+            $this->cur_version = 1;
+            wkcache("activity_version_groupbuy", $this->cur_version);
+            $need_reset = true;
+        }
+        else
+        {
+            $version = intval($version);
+            if($version > $this->cur_version) {
+                $need_reset = true;
+                $this->cur_version = $version;
+            }
+        }
+        if($need_reset)
+        {
+            $mod = Model('groupbuy');
+            $condition = array();
+            $condition['store_id'] = self::STORE_ID;
+            $condition['state'] = array('in', array(self::GROUPBUY_STATE_CLOSE, self::GROUPBUY_STATE_NORMAL));
+
+            $this->group_list = array();
+            $this->goodsid_gid = array();
+
+            $list = $mod->getGroupbuyList($condition);
+            foreach ($list as $val) {
+                $goods_id = intval($val['goods_id']);
+                $gid = intval($val['groupbuy_id']);
+                $this->group_list[$gid] = $this->filter($val);
+                $this->goodsid_gid[$goods_id] = $gid;
+            }
+        }
+    }
+
+    private function filter($groupbuy)
+    {
+        if(!empty($groupbuy)) {
+            unset($groupbuy['class_id']);
+            unset($groupbuy['s_class_id']);
+            unset($groupbuy['is_vr']);
+            unset($groupbuy['vr_city_id']);
+            unset($groupbuy['is_vr']);
+            unset($groupbuy['vr_area_id']);
+            unset($groupbuy['vr_mall_id']);
+            unset($groupbuy['vr_class_id']);
+            unset($groupbuy['vr_s_class_id']);
+        }
+        return $groupbuy;
+    }
+
+    public function isTakepart($goods_id,&$act_id)
+    {
+        if(array_key_exists(intval($goods_id),$this->goodsid_gid))
+        {
+            $act_id = $this->goodsid_gid[$goods_id];
+            $start  = $this->group_list[$act_id]['start_time'];
+            $end    =  $this->group_list[$act_id]['end_time'];
+
+            $cur = time();
+            if($cur >= intval($start) && $cur < intval($end)) {
+                return true;
+            } else {
+                return false;
+            }
+        }
+        else {
+            return false;
+        }
+    }
+
+    public function get_info($act_id)
+    {
+        $act_id = intval($act_id);
+        if(array_key_exists($act_id,$this->group_list)) {
+            return $this->group_list[$act_id];
+        } else {
+            return false;
+        }
+    }
+}

+ 112 - 0
helper/activity/limitime.php

@@ -0,0 +1,112 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: stanley-king
+ * Date: 16/8/15
+ * Time: 下午10:21
+ */
+
+namespace activity;
+
+class limitime
+{
+    const XIANSHI_STATE_NORMAL = 1;
+    const XIANSHI_STATE_CLOSE = 2;
+    const XIANSHI_STATE_CANCEL = 3;
+
+    const STORE_ID = 6;
+
+    static private $stInstance = null;
+    private $limit_list;
+    private $goodsid_limit;
+
+    private $cur_version = 0;
+
+    private function __construct()
+    {
+
+    }
+    static public function instance()
+    {
+        if(self::$stInstance == null) {
+            self::$stInstance = new limitime();
+        }
+        self::$stInstance->init();
+
+        return self::$stInstance;
+    }
+
+    private function init()
+    {
+        $need_reset = false;
+        $version = rkcache('activity_version_limit');
+        if(empty($version)) {
+            $this->cur_version = 1;
+            wkcache("activity_version_limit", $this->cur_version);
+            $need_reset = true;
+        }
+        else
+        {
+            $version = intval($version);
+            if($version > $this->cur_version) {
+                $need_reset = true;
+                $this->cur_version = $version;
+            }
+        }
+        if($need_reset)
+        {
+            $mod = Model('p_xianshi');
+            $condition = array();
+            $condition['store_id'] = self::STORE_ID;
+            $condition['state'] = self::XIANSHI_STATE_NORMAL;
+
+            $this->limit_list = array();
+            $this->goodsid_limit = array();
+
+            $list = $mod->getXianshiList($condition);
+            foreach ($list as $val) {
+                $xianshi_id = intval($val['xianshi_id']);
+                $this->limit_list[$xianshi_id] = $this->filter($val);
+                $goods_list = Model('p_xianshi_goods')->getXianshiGoodsList(array('xianshi_id' => $xianshi_id));
+                foreach ($goods_list as $xianshi_goods) {
+                    $goods_id = intval($val['goods_id']);
+                    $this->goodsid_limit[$goods_id] = $xianshi_goods;
+                }
+            }
+        }
+    }
+
+    private function filter($val)
+    {
+        if(!empty($val)) {
+            unset($val['xianshi_state_text']);
+            unset($val['editable']);
+        }
+        return $val;
+    }
+
+    public function isTakepart($goods_id,&$act_id)
+    {
+        if(array_key_exists(intval($goods_id),$this->goodsid_limit))
+        {
+            $act_id = $this->goodsid_gid[$goods_id];
+            $start  = $this->group_list[$act_id]['start_time'];
+            $end    =  $this->group_list[$act_id]['end_time'];
+
+            $cur = time();
+            if($cur >= intval($start) && $cur < intval($end)) {
+                return true;
+            } else {
+                return false;
+            }
+        }
+        else {
+            return false;
+        }
+    }
+
+    public function get_info($act_id)
+    {
+
+    }
+}

+ 89 - 0
helper/activity/recommend_combo.php

@@ -0,0 +1,89 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: stanley-king
+ * Date: 16/8/16
+ * Time: 下午4:33
+ */
+
+namespace activity;
+
+
+class recommend_combo
+{
+    static private $stInstance = null;
+    private $cur_version = 0;
+
+    private $common_combos;
+
+    private function __construct()
+    {
+    }
+    static public function instance()
+    {
+        if(self::$stInstance == null) {
+            self::$stInstance = new recommend_combo();
+        }
+        self::$stInstance->init();
+
+        return self::$stInstance;
+    }
+
+    private function init()
+    {
+        $need_reset = false;
+        $version = rkcache('activity_version_rcombo');
+        if(empty($version)) {
+            $this->cur_version = 1;
+            wkcache("activity_version_rcombo", $this->cur_version);
+            $need_reset = true;
+        }
+        else
+        {
+            $version = intval($version);
+            if($version > $this->cur_version) {
+                $need_reset = true;
+                $this->cur_version = $version;
+            }
+        }
+
+        if($need_reset)
+        {
+            $mod = Model('goods_combo');
+            $this->common_combos = array();
+
+            $list = $mod->getGoodsComboList();
+            foreach ($list as $val)
+            {
+                $common = intval($val['goods_commonid']);
+                $cgid   = intval($val['combo_goodsid']);
+
+                if(array_key_exists($common,$this->common_combos)) {
+                    array_push($this->common_combos[$common],$cgid);
+                } else {
+                    $this->common_combos[$common] = array($cgid);
+                }
+            }
+        }
+    }
+
+    public function has_combo($commonid)
+    {
+        $commonid = intval($commonid);
+        if(array_key_exists($commonid,$this->common_combos)) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    public function combo_goods($commonid)
+    {
+        $commonid = intval($commonid);
+        if(array_key_exists($commonid,$this->common_combos)) {
+            return $this->common_combos[$commonid];
+        } else {
+            return false;
+        }
+    }
+}

+ 83 - 0
helper/activity/recommend_goods.php

@@ -0,0 +1,83 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: stanley-king
+ * Date: 16/8/17
+ * Time: 下午5:21
+ */
+
+namespace activity;
+
+use algorithm;
+
+class recommend_goods
+{
+    static private $stInstance = null;
+    private $cur_version = 0;
+    const STORE_ID = 6;
+
+    private $goods_ids;
+
+    static public function instance()
+    {
+        if(self::$stInstance == null) {
+            self::$stInstance = new recommend_goods();
+        }
+        self::$stInstance->init();
+
+        return self::$stInstance;
+    }
+
+    public function isTakepart($goods_id,&$act_id)
+    {
+        $goods_id = intval($goods_id);
+        $act_id = $goods_id;
+        if(algorithm::binary_search($this->goods_ids,$goods_id)) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    public function goods_ids() {
+        return $this->goods_ids;
+    }
+
+    private function __construct()
+    {
+
+    }
+
+    private function init()
+    {
+        $need_reset = false;
+        $version = rkcache('activity_version_rgoods');
+        if(empty($version)) {
+            $this->cur_version = 1;
+            wkcache("activity_version_rgoods", $this->cur_version);
+            $need_reset = true;
+        }
+        else
+        {
+            $version = intval($version);
+            if($version > $this->cur_version) {
+                $need_reset = true;
+                $this->cur_version = $version;
+            }
+        }
+
+        if($need_reset)
+        {
+            $mod = Model('p_booth');
+            $this->common_combos = array();
+            $list = $mod->getBoothGoodsList(array('store_id' => self::STORE_ID), 'goods_id');
+            $this->goods_ids = array();
+            foreach ($list as $val)
+            {
+                $goods_id = intval($val['goods_id']);
+                array_push($this->goods_ids,$goods_id);
+            }
+            sort($this->goods_ids);
+        }
+    }
+}

+ 71 - 0
helper/activity_helper.php

@@ -0,0 +1,71 @@
+<?php
+
+/**
+ * Created by PhpStorm.
+ * User: stanley-king
+ * Date: 16/8/14
+ * Time: 下午5:27
+ */
+
+require_once (BASE_ROOT_PATH . '/helper/activity/groupbuy.php');
+require_once (BASE_ROOT_PATH . '/helper/activity/limitime.php');
+require_once (BASE_ROOT_PATH . '/helper/activity/bundling.php');
+require_once (BASE_ROOT_PATH . '/helper/activity/recommend_combo.php');
+require_once (BASE_ROOT_PATH . '/helper/activity/full_sent.php');
+require_once (BASE_ROOT_PATH . '/helper/activity/recommend_goods.php');
+require_once (BASE_ROOT_PATH . '/helper/algorithm.php');
+
+//抢,限,推,三个信息会出现在商品的summary 中,其余的出现在商品的详细信息中
+class activity_helper
+{
+    const ACTIVITY_NONE      = 0;
+    const ACTIVITY_GROUPBUY  = 1; //抢
+    const ACTIVITY_LIMITTIME = 2; //限
+    const ACTIVITY_BUNDLING  = 3; //套装
+    const ACTIVITY_RECOMMEND = 4; //推荐
+
+    public static function take_parted($goods_id,&$act_type)
+    {
+        if(activity\groupbuy::instance()->isTakepart($goods_id,$act_id)) { //抢购
+            $act_type = self::ACTIVITY_GROUPBUY;
+            return $act_id;
+        }
+        elseif(activity\limitime::instance()->isTakepart($goods_id,$act_id)) { //
+            $act_type = self::ACTIVITY_LIMITTIME;
+            return $act_id;
+        }
+        elseif(activity\bundling::instance()->isTakepart($goods_id,$act_id)) {
+            $act_type = self::ACTIVITY_BUNDLING;
+            return $act_id;
+        }
+        elseif(activity\recommend_goods::instance()->isTakepart($goods_id,$act_id)) {
+            $act_type = self::ACTIVITY_RECOMMEND;
+            return $act_id;
+        }
+        else {
+            $act_type = self::ACTIVITY_NONE;
+            return false;
+        }
+    }
+
+    //商品组合
+    public static function has_combo($common_id) {
+        return activity\recommend_combo::instance()->has_combo($common_id);
+    }
+    public static function combo_goods($common_id) {
+        return activity\recommend_combo::instance()->combo_goods($common_id);
+    }
+    //满赠活动
+    public static function fullsent_contents() {
+        return activity\full_sent::instance()->contents();
+    }
+    //赠品信息
+    public static function goods_gifts($common_id) {
+        return activity\goods_gift::instance()->gifts($common_id);
+    }
+    //推荐商品列表
+    public static function recomoned_goodsids()
+    {
+        return \activity\recommend_goods::instance()->goods_ids();
+    }
+}

+ 51 - 8
helper/goods_helper.php

@@ -6,6 +6,7 @@
  * Time: 下午3:31
  */
 require_once (BASE_ROOT_PATH . '/helper/field_helper.php');
+require_once (BASE_ROOT_PATH . '/helper/model_helper.php');
 
 class goods_helper
 {
@@ -24,7 +25,6 @@ class goods_helper
 
     public function get_infos($goods_ids)
     {
-        perfor_start();
         $goods_list = Model('goods')->cls()->getGoodsOnlineList(array('goods_id' => array('in', $goods_ids)),self::fieldstr);
         perfor_end("get_infos");
 
@@ -34,6 +34,56 @@ class goods_helper
         return $goods_list;
     }
 
+    public function get_summary($goods_ids)
+    {
+        $goods_list = Model('goods')->cls()->getGoodsOnlineList(array('goods_id' => array('in', $goods_ids)),self::fieldstr);
+
+        $summary_list = array();
+        foreach ($goods_list as $goods) {
+            $summary = new goods_summary($goods);
+            $info = $summary->to_array($act_type,$act_id);
+            array_push($summary_list,$info);
+        }
+
+        $gbuys = array();
+        $ltimes = array();
+        foreach ($summary_list as $summary)
+        {
+            $act_id   = intval($summary['act_id']);
+            $act_type = intval($summary['act_type']);
+
+            if($act_type == activity_helper::ACTIVITY_GROUPBUY)
+            {
+                if(array_key_exists($act_id,$gbuys) == false) {
+                    $info = activity\groupbuy::instance()->get_info($act_id);
+                    $gbuys[$act_id] = $info;
+                }
+            }
+            elseif($act_type == activity_helper::ACTIVITY_LIMITTIME)
+            {
+                if(array_key_exists($act_id,$ltimes) == false) {
+                    $info = activity\limitime::instance()->get_info($act_id);
+                    $ltimes[$act_id] = $info;
+                }
+            }
+        }
+
+        $ret = array();
+        $ret['summary'] = $summary_list;
+
+        $ret['groupbuy'] = array();
+        foreach ($gbuys as $key => $val) {
+            array_push($ret['groupbuy'],$val);
+        }
+
+        $ret['limitime'] = array();
+        foreach ($ltimes as $key => $val) {
+            array_push($ret['limitime'],$val);
+        }
+
+        return $ret;
+    }
+
     /**
      * 处理商品列表(抢购、限时折扣、商品图片)
      */
@@ -42,14 +92,10 @@ class goods_helper
         if(empty($goods_list)) return $goods_list;
         $commonid_array = array_column($goods_list,'goods_commonid');
         $goodsid_array = array_column($goods_list,'goods_commonid');
-        perfor_end("goods_list_extend 1");
 
         //促销
         $groupbuy_list = Model('groupbuy')->getGroupbuyListByGoodsCommonIDString(implode(',', $commonid_array));
-        perfor_end("goods_list_extend 2");
-
         $xianshi_list = Model('p_xianshi_goods')->getXianshiGoodsListByGoodsString(implode(',', $goodsid_array));
-        perfor_end("goods_list_extend 3");
 
         foreach ($goods_list as $key => &$value)
         {
@@ -79,8 +125,6 @@ class goods_helper
                 'is_fcode,have_gift,goods_storage,goods_storage_alarm,goods_attr,group_flag,xianshi_flag';
             field_helper::unset_column($value,$fields);
         }
-        perfor_end("goods_list_extend 4");
-
         return $goods_list;
     }
 
@@ -109,5 +153,4 @@ class goods_helper
         }
         return $attr_item;
     }
-
 }

+ 71 - 0
helper/model/goods_summary.php

@@ -0,0 +1,71 @@
+<?php
+
+/**
+ * Created by PhpStorm.
+ * User: stanley-king
+ * Date: 16/8/19
+ * Time: 上午10:13
+ */
+class goods_summary
+{
+    const fieldstr = 'goods_id,goods_mobile_name,goods_commonid,store_id,brand_id,gc_id,goods_price,goods_marketprice,goods_promotion_price,goods_jingle,
+                  goods_image,goods_salenum,goods_storage,have_gift';
+    private $goods_id;
+    private $goods_commonid;
+    private $goods_info;
+
+    public function __construct($param)
+    {
+        if(is_array($param)) {
+            $this->goods_info = $param;
+            $this->goods_id = intval($this->goods_info['goods_id']);
+            $this->goods_commonid = intval($this->goods_info['goods_commonid']);
+        }
+        else
+        {
+            $this->goods_id = intval($param);
+            $mod = Model('goods');
+            $this->goods_info = $mod->getGoodsOnlineInfoByID($this->goods_id);
+            if(empty($this->goods_info)) {
+                throw new Exception("该商品不存在或者已经下架~");
+            }
+            $this->goods_commonid = intval($this->goods_info['goods_commonid']);
+        }
+    }
+
+    public function goods_id() {
+        return $this->goods_id;
+    }
+    public function goods_commonid() {
+        return $this->goods_commonid;
+    }
+    public function to_array(&$act_type,&$act_id)
+    {
+        $summary['goods_id'] = intval($this->goods_info['goods_id']);
+        $summary['goods_name'] = $this->goods_info['goods_mobile_name'];
+        $summary['goods_commonid'] = intval($this->goods_info['goods_commonid']);
+        $summary['store_id'] = intval($this->goods_info['store_id']);
+        $summary['brand_id'] = intval($this->goods_info['brand_id']);
+        $summary['gc_id'] = intval($this->goods_info['gc_id']);
+        $summary['goods_price'] = $this->goods_info['goods_price'];
+        $summary['goods_marketprice'] = $this->goods_info['goods_marketprice'];
+        $summary['goods_promotion_price'] = $this->goods_info['goods_promotion_price'];
+
+        $summary['goods_image'] = $this->goods_info['goods_image'];
+        $summary['goods_salenum'] = intval($this->goods_info['goods_salenum']);
+        $summary['goods_storage'] = intval($this->goods_info['goods_storage']);
+        $summary['have_gift'] = boolval($this->goods_info['have_gift']);
+
+        $act_id = activity_helper::take_parted($this->goods_id,$act_type);
+        if($act_id == false) {
+            $summary['act_id'] = 0;
+            $summary['act_type'] = $act_type;
+        }
+        else {
+            $summary['act_id'] = $act_id;
+            $summary['act_type'] = $act_type;
+        }
+
+        return $summary;
+    }
+}

+ 1 - 0
helper/model_helper.php

@@ -9,3 +9,4 @@
 require_once (BASE_ROOT_PATH . "/helper/model/member_info.php");
 require_once (BASE_ROOT_PATH . "/helper/model/order.php");
 require_once (BASE_ROOT_PATH . "/helper/model/ranklist.php");
+require_once (BASE_ROOT_PATH . "/helper/model/goods_summary.php");

+ 2 - 2
mobile/control/index.php

@@ -12,6 +12,7 @@ defined('InShopNC') or exit('Access Invalid!');
 
 require_once(BASE_ROOT_PATH . '/helper/goods_helper.php');
 require_once(BASE_ROOT_PATH . '/helper/special_helper.php');
+require_once(BASE_ROOT_PATH . '/helper/activity_helper.php');
 
 class indexControl extends mobileHomeControl
 {
@@ -216,8 +217,7 @@ class indexControl extends mobileHomeControl
 
     public function show_goodsOp()
     {
-        $goods_ids = rkcache('home_goods',true);
-
+        $goods_ids = activity_helper::recomoned_goodsids();
         $ret = array_chunk($goods_ids,$this->page_size());
         $pages = count($ret);
         $page_no = $pages >= $this->page_no() ? $this->page_no() : $pages;

+ 5 - 169
mobile/control/store.php

@@ -6,183 +6,19 @@
  *
  */
 defined('InShopNC') or exit('Access Invalid!');
+
 class storeControl extends mobileHomeControl
 {
 	public function __construct() {
         parent::__construct();
     }
 
-    /**
-     * 商品列表
-     */
-    public function goods_listOp() {
-        $model_goods = Model('goods');
-
-        //查询条件
-        $condition = array();
-        if(!empty($_GET['store_id']) && intval($_GET['store_id']) > 0) {
-            $condition['store_id'] = $_GET['store_id'];
-        } elseif (!empty($_GET['keyword'])) { 
-            $condition['goods_name|goods_jingle'] = array('like', '%' . $_GET['keyword'] . '%');
-        }
-
-        //所需字段
-        $fieldstr = "goods_id,goods_commonid,store_id,goods_name,goods_price,goods_marketprice,goods_image,goods_salenum,evaluation_good_star,evaluation_count";
-
-        //排序方式
-        $order = $this->_goods_list_order($_GET['key'], $_GET['order']);
+    public function groupbuysOp()
+    {
 
-        $goods_list = $model_goods->getGoodsListByColorDistinct($condition, $fieldstr, $order, $this->page_size);
-        $page_count = $model_goods->gettotalpage();
-
-        //处理商品列表(团购、限时折扣、商品图片)
-        $goods_list = $this->_goods_list_extend($goods_list);
-
-        output_data(array('goods_list' => $goods_list), mobile_page($page_count));
     }
+    public function fullsentsOp()
+    {
 
-    /**
-     * 商品列表排序方式
-     */
-    private function _goods_list_order($key, $order) {
-        $result = 'goods_id desc';
-        if (!empty($key)) {
-
-            $sequence = 'desc';
-            if($order == 1) {
-                $sequence = 'asc';
-            }
-
-            switch ($key) {
-                //销量
-                case '1' :
-                    $result = 'goods_salenum' . ' ' . $sequence;
-                    break;
-                //浏览量
-                case '2' : 
-                    $result = 'goods_click' . ' ' . $sequence;
-                    break;
-                //价格
-                case '3' :
-                    $result = 'goods_price' . ' ' . $sequence;
-                    break;
-            }
-        }
-        return $result;
     }
-
-    /**
-     * 处理商品列表(团购、限时折扣、商品图片)
-     */
-    private function _goods_list_extend($goods_list) {
-        //获取商品列表编号数组
-        $commonid_array = array();
-        $goodsid_array = array();
-        foreach($goods_list as $key => $value) {
-            $commonid_array[] = $value['goods_commonid'];
-            $goodsid_array[] = $value['goods_id'];
-        }
-
-        //促销
-        $groupbuy_list = Model('groupbuy')->getGroupbuyListByGoodsCommonIDString(implode(',', $commonid_array));
-        $xianshi_list = Model('p_xianshi_goods')->getXianshiGoodsListByGoodsString(implode(',', $goodsid_array));
-        foreach ($goods_list as $key => $value) {
-            //团购
-            if (isset($groupbuy_list[$value['goods_commonid']])) {
-                $goods_list[$key]['goods_price'] = $groupbuy_list[$value['goods_commonid']]['groupbuy_price'];
-                $goods_list[$key]['group_flag'] = true;
-            } else {
-                $goods_list[$key]['group_flag'] = false;
-            }
-
-            //限时折扣
-            if (isset($xianshi_list[$value['goods_id']]) && !$goods_list[$key]['group_flag']) {
-                $goods_list[$key]['goods_price'] = $xianshi_list[$value['goods_id']]['xianshi_price'];
-                $goods_list[$key]['xianshi_flag'] = true;
-            } else {
-                $goods_list[$key]['xianshi_flag'] = false;
-            }
-
-            //商品图片url
-            $goods_list[$key]['goods_image_url'] = cthumb($value['goods_image'], 360, $value['store_id']); 
-
-            unset($goods_list[$key]['store_id']);
-            unset($goods_list[$key]['goods_commonid']);
-            unset($goods_list[$key]['nc_distinct']);
-        }
-
-        return $goods_list;
-    }
-
-    /**
-     * 商品详细页
-     */
-    public function store_detailOp() {
-        $store_id = intval($_GET ['store_id']);
-        // 商品详细信息
-        $model_store = Model('store');
-        $store_info = $model_store->getStoreOnlineInfoByID($store_id);
-        if (empty($store_info)) {
-            output_error('店铺不存在');
-        }
-        $store_detail['store_pf'] = $store_info['store_credit'];
-        $store_detail['store_info'] = $store_info;
-        // //店铺导航
-        // $model_store_navigation = Model('store_navigation');
-        // $store_navigation_list = $model_store_navigation->getStoreNavigationList(array('sn_store_id' => $store_id));
-        // $store_detail['store_navigation_list'] = $store_navigation_list;
-        // //幻灯片图片
-        // if($this->store_info['store_slide'] != '' && $this->store_info['store_slide'] != ',,,,'){
-        //     $store_detail['store_slide'] = explode(',', $this->store_info['store_slide']);
-        //     $store_detail['store_slide_url'] = explode(',', $this->store_info['store_slide_url']);
-        // }
-
-        //店铺详细信息处理
-        // $store_detail = $this->_store_detail_extend($store_info);
-        output_data($store_detail);
-    }
-
-    /**
-     * 店铺详细信息处理
-     */
-    private function _store_detail_extend($store_detail) {
-        //整理数据
-        unset($store_detail['store_info']['goods_commonid']);
-        unset($store_detail['store_info']['gc_id']);
-        unset($store_detail['store_info']['gc_name']);
-        // unset($goods_detail['goods_info']['store_id']);
-        // unset($goods_detail['goods_info']['store_name']);
-        unset($store_detail['store_info']['brand_id']);
-        unset($store_detail['store_info']['brand_name']);
-        unset($store_detail['store_info']['type_id']);
-        unset($store_detail['store_info']['goods_image']);
-        unset($store_detail['store_info']['goods_body']);
-        unset($store_detail['store_info']['goods_state']);
-        unset($store_detail['store_info']['goods_stateremark']);
-        unset($store_detail['store_info']['goods_verify']);
-        unset($store_detail['store_info']['goods_verifyremark']);
-        unset($store_detail['store_info']['goods_lock']);
-        unset($store_detail['store_info']['goods_addtime']);
-        unset($store_detail['store_info']['goods_edittime']);
-        unset($store_detail['store_info']['goods_selltime']);
-        unset($store_detail['store_info']['goods_show']);
-        unset($store_detail['store_info']['goods_commend']);
-
-        return $store_detail;
-    }
-
-    // /**
-    //  * 商品详细页
-    //  */
-    // public function goods_bodyOp() {
-    //     $store_id = intval($_GET ['store_id']);
-
-    //     $model_goods = Model('goods');
-
-    //     $goods_info = $model_goods->getGoodsInfo(array('goods_id' => $goods_id));
-    //     $goods_common_info = $model_goods->getGoodeCommonInfo(array('goods_commonid' => $goods_info['goods_commonid']));
-
-    //     Tpl::output('goods_common_info', $goods_common_info);
-    //     Tpl::showpage('goods_body');
-    // }
 }

+ 61 - 0
test/activity_helperTest.php

@@ -0,0 +1,61 @@
+<?php
+
+/**
+ * Created by PhpStorm.
+ * User: stanley-king
+ * Date: 16/8/14
+ * Time: 下午5:29
+ */
+
+define('BASE_ROOT_PATH',str_replace('/test','',dirname(__FILE__)));
+
+require_once(BASE_ROOT_PATH . '/fooder.php');
+require_once(BASE_ROOT_PATH . '/helper/activity_helper.php');
+require_once(BASE_ROOT_PATH . '/helper/goods_helper.php');
+
+class activity_helperTest extends PHPUnit_Framework_TestCase
+{
+    public static function setUpBeforeClass()
+    {
+        Base::run_util();
+    }
+
+    public function testGift()
+    {
+        $helper = new goods_helper();
+        $helper->get_summary(array(4127,4217));
+    }
+
+    public function testGroupbuy()
+    {
+        $activity = new activity_helper();
+        $activity->groupbuy_list();
+    }
+
+    public function testXianshi()
+    {
+        $activity = new activity_helper();
+        $activity->xianshi_list(6);
+    }
+
+    public function testMansong()
+    {
+        $activity = new activity_helper();
+        $activity->mansong_list(6);
+    }
+    public function testBundling()
+    {
+        $activity = new activity_helper();
+        $activity->bundling_list(6);
+    }
+    public function testBooth()
+    {
+        $activity = new activity_helper();
+        $activity->booth_list(6);
+    }
+
+    public function testTakepart()
+    {
+        activity_helper::take_parted(30,$type);
+    }
+}