소스 검색

修改完运营相关的为message publish 和 subscribe 模型

stanley-king 8 년 전
부모
커밋
ce3644efed

+ 6 - 10
data/model/goods_combo.model.php

@@ -23,7 +23,7 @@ class goods_comboModel extends Model {
                 if ($v['goods_id']) $this->_dGoodsComboCache($v['goods_id']);
             }
 
-            $this->_wVersionCache();
+            $this->publish_message();
         }
         return $result;
     }
@@ -49,7 +49,7 @@ class goods_comboModel extends Model {
             foreach ($list as $v) {
                 $this->_dGoodsComboCache($v['goods_id']);
             }
-            $this->_wVersionCache();
+            $this->publish_message();
         }
         return $result;
     }
@@ -100,14 +100,10 @@ class goods_comboModel extends Model {
         return dcache($goods_id, 'goods_combo');
     }
 
-    private function _wVersionCache()
+
+    private function publish_message()
     {
-        $version = rkcache('activity_version_rcombo');
-        if(empty($version)) {
-            $version = 1;
-        } else {
-            $version = intval($version) + 1;
-        }
-        return wkcache("activity_version_rcombo", $version);
+        $publisher = new message\publisher();
+        $publisher->modify_activity_recommend_combo();
     }
 }

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

@@ -4,6 +4,9 @@
  *
  */
 defined('InShopNC') or exit('Access Invalid!');
+require_once (BASE_ROOT_PATH . '/helper/message/publisher.php');
+
+
 class goods_giftModel extends Model 
 {
     public function __construct(){
@@ -17,7 +20,11 @@ class goods_giftModel extends Model
      * @return boolean
      */
     public function addGoodsGiftAll($insert) {
-        return $this->insertAll($insert);
+        $ret = $this->insertAll($insert);
+        if($ret != false) {
+            $this->publish_message();
+        }
+        return $ret;
     }
     
     /**
@@ -49,10 +56,12 @@ class goods_giftModel extends Model
             return true;
         }
         $result = $this->where($condition)->delete();
-        if ($result) {
+        if ($result)
+        {
             foreach ($gift_list as $val) {
                 $this->_dGoodsGiftCache($val['goods_id']);
             }
+            $this->publish_message();
         }
         return $result;
     }
@@ -84,4 +93,10 @@ class goods_giftModel extends Model
     private function _dGoodsGiftCache($goods_id) {
         return dcache($goods_id, 'goods_gift');
     }
+
+    private function publish_message()
+    {
+        $publisher = new message\publisher();
+        $publisher->modify_activity_goods_gift();
+    }
 }

+ 8 - 12
data/model/groupbuy.model.php

@@ -7,6 +7,8 @@
  *
  */
 defined('InShopNC') or exit('Access Invalid!');
+require_once (BASE_ROOT_PATH . '/helper/message/publisher.php');
+
 class groupbuyModel extends Model
 {
     const GROUPBUY_STATE_REVIEW = 10;
@@ -263,7 +265,7 @@ class groupbuyModel extends Model
         if ($result) {
             // 更新商品抢购缓存
             $this->_dGoodsGroupbuyCache($param['goods_commonid']);
-            $this->_wGroupbuyChangedCache();
+            $this->publish_message();
             return $result;
         } else {
             return false;
@@ -309,7 +311,7 @@ class groupbuyModel extends Model
                     $this->_dGoodsGroupbuyCache($val['goods_commonid']);
                 }
 
-                $this->_wGroupbuyChangedCache();
+                $this->publish_message();
             }
         }
         return $result;
@@ -449,7 +451,7 @@ class groupbuyModel extends Model
                     @unlink($path.$base_name.'_max.'.$ext);
                 }
             }
-            $this->_wGroupbuyChangedCache();
+            $this->publish_message();
         }
         return true;
     }
@@ -544,15 +546,10 @@ class groupbuyModel extends Model
         return dcache($goods_commonid, 'goods_groupbuy');
     }
 
-    private function _wGroupbuyChangedCache()
+    private function publish_message()
     {
-        $version = rkcache('activity_version_groupbuy');
-        if(empty($version)) {
-            $version = 1;
-        } else {
-            $version = intval($version) + 1;
-        }
-        return wkcache("activity_version_groupbuy", $version);
+        $publisher = new message\publisher();
+        $publisher->modify_activity_groupbuy();
     }
 
     /**
@@ -732,5 +729,4 @@ class groupbuyModel extends Model
      * @return array
      */
     protected $cachedData;
-
 }

+ 15 - 11
data/model/p_booth.model.php

@@ -8,6 +8,8 @@
  
  */
 defined('InShopNC') or exit('Access Invalid!');
+require_once (BASE_ROOT_PATH . '/helper/message/publisher.php');
+
 
 class p_boothModel extends Model {
     const STATE1 = 1;       // 开启
@@ -121,7 +123,10 @@ class p_boothModel extends Model {
      */
     public function addBoothGoods($insert) {
         $ret = $this->table('p_booth_goods')->insert($insert);
-        $this->_wVersionCache();
+        if($ret != false) {
+            $this->publish_message();
+        }
+
         return $ret;
     }
 
@@ -133,7 +138,9 @@ class p_boothModel extends Model {
      */
     public function editBooth($update, $condition) {
         $ret = $this->table('p_booth_goods')->where($condition)->update($update);
-        $this->_wVersionCache();
+        if($ret != false) {
+            $this->publish_message();
+        }
         return $ret;
     }
 
@@ -166,7 +173,9 @@ class p_boothModel extends Model {
      */
     public function delBoothGoods($condition) {
         $ret = $this->table('p_booth_goods')->where($condition)->delete();
-        $this->_wVersionCache();
+        if($ret != false) {
+            $this->publish_message();
+        }
         return $ret;
     }
 
@@ -189,14 +198,9 @@ class p_boothModel extends Model {
         return $condition;
     }
 
-    private function _wVersionCache()
+    private function publish_message()
     {
-        $version = rkcache('activity_version_rgoods');
-        if(empty($version)) {
-            $version = 1;
-        } else {
-            $version = intval($version) + 1;
-        }
-        return wkcache("activity_version_rgoods", $version);
+        $publisher = new message\publisher();
+        $publisher->modify_activity_recommend_goods();
     }
 }

+ 27 - 4
data/model/p_bundling.model.php

@@ -8,6 +8,8 @@
  
  */
 defined('InShopNC') or exit('Access Invalid!');
+require_once (BASE_ROOT_PATH . '/helper/message/publisher.php');
+
 
 class p_bundlingModel extends Model {
     const STATE1 = 1;       // 开启
@@ -70,7 +72,11 @@ class p_bundlingModel extends Model {
      * @return boolean
      */
     public function addBundling($insert, $replace = false) {
-        return $this->table('p_bundling')->insert($insert, $replace);
+        $ret = $this->table('p_bundling')->insert($insert, $replace);
+        if($ret != false) {
+            $this->publis_message();
+        }
+        return $ret;
     }
     
     /**
@@ -81,7 +87,11 @@ class p_bundlingModel extends Model {
      * @return boolean
      */
     public function editBundling($update, $condition) {
-        return $this->table('p_bundling')->where($condition)->update($update);
+        $ret = $this->table('p_bundling')->where($condition)->update($update);
+        if($ret != false) {
+            $this->publis_message();
+        }
+        return $ret;
     }
     
     /**
@@ -98,8 +108,13 @@ class p_bundlingModel extends Model {
             foreach ($bundlinggoods_list as $val) {
                 $blid_array[] = $val['bl_id'];
             }
+
             $update = array('bl_state' => self::STATE0);
-            return $this->table('p_bundling')->where(array('bl_id' => array('in', $blid_array)))->update($update);
+            $ret = $this->table('p_bundling')->where(array('bl_id' => array('in', $blid_array)))->update($update);
+            if($ret != false) {
+                $this->publis_message();
+            }
+            return $ret;
         }
         return true;
     }
@@ -310,10 +325,12 @@ class p_bundlingModel extends Model {
             return true;
         }
         $result = $this->table('p_bundling_goods')->where($condition)->delete();
-        if ($result) {
+        if ($result)
+        {
             foreach ($list as $v) {
                 $this->_dGoodsBundlingCache($v['goods_id']);
             }
+            $this->publis_message();
         }
         return $result;
     }
@@ -403,4 +420,10 @@ class p_bundlingModel extends Model {
     private function _dGoodsBundlingCache($goods_id) {
         return dcache($goods_id, 'goods_bundling');
     }
+
+    private function publis_message()
+    {
+        $publisher = new message\publisher();
+        $publisher->modify_activity_bundling();
+    }
 }

+ 9 - 12
data/model/p_mansong.model.php

@@ -8,8 +8,10 @@
  
  */
 defined('InShopNC') or exit('Access Invalid!');
-class p_mansongModel extends Model{
+require_once (BASE_ROOT_PATH . '/helper/message/publisher.php');
 
+class p_mansongModel extends Model
+{
     const MANSONG_STATE_NORMAL = 1;
     const MANSONG_STATE_CLOSE = 2;
     const MANSONG_STATE_CANCEL = 3;
@@ -206,7 +208,7 @@ class p_mansongModel extends Model{
         $result = $this->insert($param);
         if ($result) {
             $this->_dGoodsMansongCache($param['store_id']);
-            $this->_wVersionCache();
+            $this->publish_change();
         }
         return $result;
     }
@@ -228,7 +230,7 @@ class p_mansongModel extends Model{
             foreach ($mansong_list as $val) {
                 $this->_dGoodsMansongCache($val['store_id']);
             }
-            $this->_wVersionCache();
+            $this->publish_change();
         }
         return $result;
     }
@@ -254,7 +256,7 @@ class p_mansongModel extends Model{
         $model_mansong_rule->delMansongRule($condition);
 
         $ret = $this->where($condition)->delete();
-        $this->_wVersionCache();
+        $this->publish_change();
         return $ret;
     }
 
@@ -312,14 +314,9 @@ class p_mansongModel extends Model{
         return dcache($store_id, 'goods_mansong');
     }
 
-    private function _wVersionCache()
+    private function publish_change()
     {
-        $version = rkcache('activity_version_fullsent');
-        if(empty($version)) {
-            $version = 1;
-        } else {
-            $version = intval($version) + 1;
-        }
-        return wkcache("activity_version_fullsent", $version);
+        $publisher = new message\publisher();
+        $publisher->modify_activity_fullsent();
     }
 }

+ 6 - 9
data/model/p_xianshi.model.php

@@ -8,6 +8,8 @@
  
  */
 defined('InShopNC') or exit('Access Invalid!');
+require_once (BASE_ROOT_PATH . '/helper/message/publisher.php');
+
 class p_xianshiModel extends Model{
 
     const XIANSHI_STATE_NORMAL = 1;
@@ -206,19 +208,14 @@ class p_xianshiModel extends Model{
         $condition['state'] = self::XIANSHI_STATE_NORMAL;
         
         $updata = array();
-        $update['state'] = self::XIANSHI_STATE_CLOSE;
-        $this->editXianshi($update, $condition);
+        $updata['state'] = self::XIANSHI_STATE_CLOSE;
+        $this->editXianshi($updata, $condition);
         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);
+        $publisher = new message\publisher();
+        $publisher->modify_activity_limit();
     }
 }

+ 1 - 3
helper/activity/bundling.php

@@ -20,18 +20,16 @@ class bundling
     private $bundling_list;
     private $bundling_goods;
     private $goods_ids;
-    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();
         }
-        if(self::$stInstance->verchecker->need_init()) {
+        if(StatesHelper::fetch_state('bundling')) {
             self::$stInstance->init();
         }
 

+ 4 - 3
helper/activity/full_sent.php

@@ -8,6 +8,8 @@
 
 namespace activity;
 
+use StatesHelper;
+
 class full_item
 {
     private $mStart;
@@ -46,13 +48,11 @@ class full_sent
     const STORE_ID = 6;
 
     static private $stInstance = null;
-    private $verchecker;
     private $mItem;
     private $mFreePrice;
 
     private function __construct()
     {
-        $this->verchecker = new version_checker('activity_version_fullsent');
     }
 
     static public function instance()
@@ -60,7 +60,8 @@ class full_sent
         if(self::$stInstance == null) {
             self::$stInstance = new full_sent();
         }
-        if(self::$stInstance->verchecker->need_init()) {
+
+        if(StatesHelper::fetch_state('full_sent')) {
             self::$stInstance->init();
         }
 

+ 1 - 6
helper/activity/goods_gift.php

@@ -8,23 +8,19 @@
 
 namespace activity;
 
-
 class gift_item
 {
     public $goods_id;
     public $amount;
 }
 
-
 class goods_gift
 {
     static private $stInstance = null;
-    private $verchecker;
     private $contents;
 
     private function __construct()
     {
-        $this->verchecker = new version_checker('activity_version_gift');
     }
 
     static public function instance()
@@ -32,7 +28,7 @@ class goods_gift
         if(self::$stInstance == null) {
             self::$stInstance = new goods_gift();
         }
-        if(self::$stInstance->verchecker->need_init()) {
+        if(StatesHelper::fetch_state('goods_gift')) {
             self::$stInstance->init();
         }
 
@@ -84,7 +80,6 @@ class goods_gift
         }
     }
 
-
     public function have_gift($goods_id)
     {
         $goods_id = intval($goods_id);

+ 3 - 4
helper/activity/groupbuy.php

@@ -9,6 +9,8 @@
 
 namespace activity;
 use commonid_helper;
+use StatesHelper;
+
 
 class group_item
 {
@@ -59,18 +61,15 @@ class groupbuy
     private $group_list;
     private $mGoodsidGroupIDS;
 
-    private $verchecker;
-
     private function __construct()
     {
-        $this->verchecker = new version_checker('activity_version_groupbuy',120);
     }
     static public function instance()
     {
         if(self::$stInstance == null) {
             self::$stInstance = new groupbuy();
         }
-        if(self::$stInstance->verchecker->need_init()) {
+        if(StatesHelper::fetch_state('groupbuy')) {
             self::$stInstance->init();
         }
 

+ 1 - 4
helper/activity/limitime.php

@@ -49,18 +49,15 @@ class limitime
     private $mGoodsidLimitGoods;
     private $mLimitGoods;
 
-    private $verchecker;
-
     private function __construct()
     {
-        $this->verchecker = new version_checker('activity_version_limit',120);
     }
     static public function instance()
     {
         if(self::$stInstance == null) {
             self::$stInstance = new limitime();
         }
-        if(self::$stInstance->verchecker->need_init()) {
+        if(StatesHelper::fetch_state('limit')) {
             self::$stInstance->init();
         }
 

+ 1 - 4
helper/activity/recommend_combo.php

@@ -12,20 +12,17 @@ namespace activity;
 class recommend_combo
 {
     static private $stInstance = null;
-    private $verchecker;
-
     //goods_id 可能包含多个商品形成一个组合
     private $goods_combos;
 
     private function __construct() {
-        $this->verchecker = new version_checker('activity_version_rcombo');
     }
     static public function instance()
     {
         if(self::$stInstance == null) {
             self::$stInstance = new recommend_combo();
         }
-        if(self::$stInstance->verchecker->need_init()) {
+        if(StatesHelper::fetch_state('recommend_combo')) {
             self::$stInstance->init();
         }
 

+ 1 - 4
helper/activity/recommend_goods.php

@@ -13,9 +13,7 @@ use algorithm;
 class recommend_goods
 {
     static private $stInstance = null;
-    private $verchecker;
     const STORE_ID = 6;
-
     private $goods_ids;
 
     static public function instance()
@@ -24,7 +22,7 @@ class recommend_goods
             self::$stInstance = new recommend_goods();
         }
 
-        if(self::$stInstance->verchecker->need_init()) {
+        if(StatesHelper::fetch_state('recommend_goods')) {
             self::$stInstance->init();
         }
 
@@ -47,7 +45,6 @@ class recommend_goods
 
     private function __construct()
     {
-        $this->verchecker = new version_checker('activity_version_rgoods');
     }
 
     public function init()

+ 0 - 6
helper/activity_helper.php

@@ -14,8 +14,6 @@ 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');
 
 function less_endtime($left,$right)
@@ -134,10 +132,6 @@ class activity_helper
         $limits = activity\limitime::instance()->acting();
         $groupbuys = activity\groupbuy::instance()->acting();
 
-//        $x = count($limits);
-//        $y = count($groupbuys);
-//        Log::record("activity_helper::acting limit = {$x} groupbuy = {$y}",Log::DEBUG);
-
         $values = [];
         foreach ($limits as $val) {
             $values[] = $val;

+ 25 - 1
helper/message/msgutil.php

@@ -24,6 +24,31 @@ class StatesHelper
             $states['special'] = true;
         }
     }
+
+    static public function onActivity($states,$msg)
+    {
+        $type = $msg['type'];
+        if($type == 'full_sent') {
+            $states['full_sent'] = true;
+        }
+        elseif($type == 'groupbuy') {
+            $states['groupbuy'] = true;
+        }
+        elseif($type == 'limit') {
+            $states['limit'] = true;
+        }
+        elseif($type == 'recommend_goods') {
+            $states['recommend_goods'] = true;
+        }
+        elseif($type == 'bundling') {
+            $states['bundling'] = true;
+        }
+        elseif($type == 'recommend_combo') {
+            $states['recommend_combo'] = true;
+        }
+    }
+
+
     static public function onSearcher($states,$msg)
     {
         $type = $msg['type'];
@@ -32,7 +57,6 @@ class StatesHelper
         }
     }
 
-
     static public function fetch_state($tag)
     {
         global $gMessageStates;

+ 43 - 0
helper/message/publisher.php

@@ -47,6 +47,49 @@ class publisher
             $this->mRedis->publish('ch_index',serialize(array('type'=>'special','value' => 0)));
         }
     }
+    public function modify_activity_fullsent()
+    {
+        if($this->mConnected) {
+            $this->mRedis->publish('activity',serialize(array('type'=>'full_sent','value' => 0)));
+        }
+    }
+    public function modify_activity_groupbuy()
+    {
+        if($this->mConnected) {
+            $this->mRedis->publish('activity',serialize(array('type'=>'groupbuy','value' => 0)));
+        }
+    }
+    public function modify_activity_limit()
+    {
+        if($this->mConnected) {
+            $this->mRedis->publish('activity',serialize(array('type'=>'limit','value' => 0)));
+        }
+    }
+    public function modify_activity_recommend_goods()
+    {
+        if($this->mConnected) {
+            $this->mRedis->publish('activity',serialize(array('type'=>'recommend_goods','value' => 0)));
+        }
+    }
+    public function modify_activity_bundling()
+    {
+        if($this->mConnected) {
+            $this->mRedis->publish('activity',serialize(array('type'=>'bundling','value' => 0)));
+        }
+    }
+    public function modify_activity_recommend_combo()
+    {
+        if($this->mConnected) {
+            $this->mRedis->publish('activity',serialize(array('type'=>'recommend_combo','value' => 0)));
+        }
+    }
+    public function modify_activity_goods_gift()
+    {
+        if($this->mConnected) {
+            $this->mRedis->publish('activity',serialize(array('type'=>'goods_gift','value' => 0)));
+        }
+    }
+
     public function modify_seracher_init()
     {
         if($this->mConnected) {

+ 7 - 0
helper/message/subscriber.php

@@ -82,6 +82,13 @@ class subscriber extends Thread
 
             return $ret;
         }
+        elseif($channel == 'activity') {
+            Mutex::lock($this->mLock);
+            $ret = StatesHelper::onActivity($this->mStates,$msg);
+            Mutex::unlock($this->mLock);
+
+            return $ret;
+        }
         else {
             return false;
         }

+ 1 - 1
helper/search/tcp_client.php

@@ -101,10 +101,10 @@ class tcp_client
             $host = $this->remote_addr();
             $this->mSocket = stream_socket_client ($host,$err,$errno,30);
             if($this->mSocket == false) {
-                socket_set_timeout($this->mSocket,self::time_out);
                 Log::record("connect search server err --- code:{$errno} : {$err}");
                 return false;
             } else {
+                socket_set_timeout($this->mSocket,self::time_out);
                 return true;
             }
         }