Browse Source

增加活动版本检查

stanley-king 8 years ago
parent
commit
2ecb5c1141

+ 2 - 2
data/model/p_booth.model.php

@@ -191,12 +191,12 @@ class p_boothModel extends Model {
 
     private function _wVersionCache()
     {
-        $version = rkcache('activity_version_fullsent');
+        $version = rkcache('activity_version_rgoods');
         if(empty($version)) {
             $version = 1;
         } else {
             $version = intval($version) + 1;
         }
-        return wkcache("activity_version_fullsent", $version);
+        return wkcache("activity_version_rgoods", $version);
     }
 }

+ 24 - 41
helper/activity/bundling.php

@@ -20,63 +20,46 @@ class bundling
     private $bundling_list;
     private $bundling_goods;
     private $goods_ids;
-
-    private $cur_version = 0;
+    private $verchecker;
 
     private function __construct()
     {
-
+        $this->verchecker = new version_checker('activity_version_bundling');
     }
     static public function instance()
     {
         if(self::$stInstance == null) {
             self::$stInstance = new bundling();
         }
-        self::$stInstance->init();
+        if(self::$stInstance->verchecker->need_init()) {
+            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)
         {
-            $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), 'goods_id,bl_goods_price');
-                foreach ($bgoods as $goods) {
-                    $goods_id =intval($goods['goods_id']);
-                    array_push($this->bundling_goods[$bl_id],$goods);
-                    $this->goods_ids[$goods_id][] = $bl_id;
-                }
+            $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), 'goods_id,bl_goods_price');
+            foreach ($bgoods as $goods) {
+                $goods_id =intval($goods['goods_id']);
+                array_push($this->bundling_goods[$bl_id],$goods);
+                $this->goods_ids[$goods_id][] = $bl_id;
             }
         }
     }

+ 13 - 29
helper/activity/full_sent.php

@@ -17,11 +17,12 @@ class full_sent
     const STORE_ID = 6;
 
     static private $stInstance = null;
-    private $cur_version = 0;
+    private $verchecker;
     private $contents;
 
     private function __construct()
     {
+        $this->verchecker = new version_checker('activity_version_fullsent');
     }
 
     static public function instance()
@@ -29,7 +30,9 @@ class full_sent
         if(self::$stInstance == null) {
             self::$stInstance = new full_sent();
         }
-        self::$stInstance->init();
+        if(self::$stInstance->verchecker->need_init()) {
+            self::$stInstance->init();
+        }
 
         return self::$stInstance;
     }
@@ -51,34 +54,15 @@ class full_sent
 
     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));
+        $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));
-            }
+        $list = $mod->getMansongList($condition);
+        $this->contents = array();
+        foreach ($list as $val) {
+            array_push($this->contents,$this->filter($val));
         }
     }
 

+ 17 - 33
helper/activity/goods_gift.php

@@ -19,12 +19,12 @@ class gift_item
 class goods_gift
 {
     static private $stInstance = null;
-    private $cur_version = 0;
+    private $verchecker;
     private $contents;
 
     private function __construct()
     {
-
+        $this->verchecker = new version_checker('activity_version_gift');
     }
 
     static public function instance()
@@ -32,46 +32,30 @@ class goods_gift
         if(self::$stInstance == null) {
             self::$stInstance = new goods_gift();
         }
-        self::$stInstance->init();
+        if(self::$stInstance->verchecker->need_init()) {
+            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());
+        $mod = Model('goods_gift');
+        $list = $mod->getGoodsGiftList(array());
 
-            $this->contents = array();
-            foreach ($list as $val)
-            {
-                $goods_id = intval($val['goods_id']);
-                $giftid = intval($val['gift_goodsid']);
-                $amount = intval($val['gift_amount']);
+        $this->contents = array();
+        foreach ($list as $val)
+        {
+            $goods_id = intval($val['goods_id']);
+            $giftid = intval($val['gift_goodsid']);
+            $amount = intval($val['gift_amount']);
 
-                if(array_key_exists($goods_id,$this->contents) == false) {
-                    $this->contents[$goods_id] = array();
-                }
-                $item = array('gift_goods_id' => $giftid,'amount' => $amount);
-                array_push($this->contents[$goods_id],$item);
+            if(array_key_exists($goods_id,$this->contents) == false) {
+                $this->contents[$goods_id] = array();
             }
+            $item = array('gift_goods_id' => $giftid,'amount' => $amount);
+            array_push($this->contents[$goods_id],$item);
         }
     }
 

+ 19 - 35
helper/activity/groupbuy.php

@@ -82,56 +82,40 @@ class groupbuy
     private $group_list;
     private $goodsid_gid;
 
-    private $cur_version = 0;
+    private $verchecker;
 
     private function __construct()
     {
-
+        $this->verchecker = new version_checker('activity_version_groupbuy');
     }
     static public function instance()
     {
         if(self::$stInstance == null) {
             self::$stInstance = new groupbuy();
         }
-        self::$stInstance->init();
+        if(self::$stInstance->verchecker->need_init()) {
+            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;
-            }
+        $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;
         }
     }
 

+ 21 - 37
helper/activity/limitime.php

@@ -47,59 +47,43 @@ class limitime
     private $limit_list;
     private $goodsid_limit;
 
-    private $cur_version = 0;
+    private $verchecker;
 
     private function __construct()
     {
-
+        $this->verchecker = new version_checker('activity_version_limit');
     }
     static public function instance()
     {
         if(self::$stInstance == null) {
             self::$stInstance = new limitime();
         }
-        self::$stInstance->init();
+        if(self::$stInstance->verchecker->need_init()) {
+            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)
         {
-            $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] = $val;
-                $goods_list = Model('p_xianshi_goods')->getXianshiGoodsList(array('xianshi_id' => $xianshi_id));
-                foreach ($goods_list as $xianshi_goods) {
-                    $goods_id = intval($xianshi_goods['goods_id']);
-                    $this->goodsid_limit[$goods_id] = $xianshi_goods;
-                }
+            $xianshi_id = intval($val['xianshi_id']);
+            $this->limit_list[$xianshi_id] = $val;
+            $goods_list = Model('p_xianshi_goods')->getXianshiGoodsList(array('xianshi_id' => $xianshi_id));
+            foreach ($goods_list as $xianshi_goods) {
+                $goods_id = intval($xianshi_goods['goods_id']);
+                $this->goodsid_limit[$goods_id] = $xianshi_goods;
             }
         }
     }

+ 16 - 33
helper/activity/recommend_combo.php

@@ -12,58 +12,41 @@ namespace activity;
 class recommend_combo
 {
     static private $stInstance = null;
-    private $cur_version = 0;
+    private $verchecker;
 
     //goods_id 可能包含多个商品形成一个组合
     private $goods_combos;
 
-    private function __construct()
-    {
+    private function __construct() {
+        $this->verchecker = new version_checker('activity_version_rcombo');
     }
     static public function instance()
     {
         if(self::$stInstance == null) {
             self::$stInstance = new recommend_combo();
         }
-        self::$stInstance->init();
+        if(self::$stInstance->verchecker->need_init()) {
+            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;
-            }
-        }
+        $mod = Model('goods_combo');
+        $this->goods_combos = array();
 
-        if($need_reset)
+        $list = $mod->getGoodsComboList(array());
+        foreach ($list as $val)
         {
-            $mod = Model('goods_combo');
-            $this->goods_combos = array();
-
-            $list = $mod->getGoodsComboList(array());
-            foreach ($list as $val)
-            {
-                $gid = intval($val['goods_id']);
-                $cgid   = intval($val['combo_goodsid']);
+            $gid = intval($val['goods_id']);
+            $cgid   = intval($val['combo_goodsid']);
 
-                if(array_key_exists($gid,$this->goods_combos)) {
-                    array_push($this->goods_combos[$gid],$cgid);
-                } else {
-                    $this->goods_combos[$gid] = array($cgid);
-                }
+            if(array_key_exists($gid,$this->goods_combos)) {
+                array_push($this->goods_combos[$gid],$cgid);
+            } else {
+                $this->goods_combos[$gid] = array($cgid);
             }
         }
     }

+ 15 - 31
helper/activity/recommend_goods.php

@@ -13,7 +13,7 @@ use algorithm;
 class recommend_goods
 {
     static private $stInstance = null;
-    private $cur_version = 0;
+    private $verchecker;
     const STORE_ID = 6;
 
     private $goods_ids;
@@ -23,7 +23,10 @@ class recommend_goods
         if(self::$stInstance == null) {
             self::$stInstance = new recommend_goods();
         }
-        self::$stInstance->init();
+
+        if(self::$stInstance->verchecker->need_init()) {
+            self::$stInstance->init();
+        }
 
         return self::$stInstance;
     }
@@ -44,39 +47,20 @@ class recommend_goods
 
     private function __construct()
     {
-
+        $this->verchecker = new version_checker('activity_version_rgoods');
     }
 
-    private function init()
+    public 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)
         {
-            $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);
+            $goods_id = intval($val['goods_id']);
+            array_push($this->goods_ids,$goods_id);
         }
+        sort($this->goods_ids);
     }
 }

+ 57 - 0
helper/activity/version_checker.php

@@ -0,0 +1,57 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: stanley-king
+ * Date: 16/9/1
+ * Time: 下午10:38
+ */
+
+namespace activity;
+
+
+class version_checker
+{
+    const max_interval = 60;
+    private $cur_version;
+    private $reset_time;
+
+    public function __construct($keyword)
+    {
+        $this->keyword = $keyword;
+        $this->cur_version = 0;
+        $this->reset_time = 0;
+    }
+
+    public function need_init()
+    {
+        if($this->reset_time == 0) {
+            $this->reset_time = time();
+            return true;
+        }
+        else if(time() - $this->reset_time < max_interval) {
+            return false;
+        }
+        else
+        {
+            $need_reset = false;
+            $version = rkcache($this->keyword);
+            if(empty($version)) {
+                $this->cur_version = 1;
+                wkcache($this->keyword, $this->cur_version);
+                $need_reset = true;
+                $this->reset_time = time();
+            }
+            else
+            {
+                $version = intval($version);
+                if($version > $this->cur_version) {
+                    $need_reset = true;
+                    $this->cur_version = $version;
+                    $this->reset_time = time();
+                }
+            }
+
+            return $need_reset;
+        }
+    }
+}

+ 2 - 0
helper/activity_helper.php

@@ -14,6 +14,8 @@ 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/activity/goods_gift.php');
+require_once (BASE_ROOT_PATH . '/helper/activity/version_checker.php');
+
 require_once (BASE_ROOT_PATH . '/helper/algorithm.php');
 
 //抢,限,推,套装,三个信息会出现在商品的summary 中,其余的出现在商品的详细信息中

+ 0 - 3
robots.txt

@@ -1,3 +0,0 @@
-#
-# 
-#