浏览代码

add sampler store

stanley-king 7 年之前
父节点
当前提交
f2cbcddb53
共有 2 个文件被更改,包括 56 次插入19 次删除
  1. 33 15
      mobile/control/bonusex.php
  2. 23 4
      mobile/control/member_bonus.php

+ 33 - 15
mobile/control/bonusex.php

@@ -104,7 +104,7 @@ class bonusexControl extends mobileControl
                 }
             }
 
-            $summarys = $this->matched_goods();
+            $summarys = $this->matched_goods($type_sn);
             $data = array('type_info' => $type_info,
                 'mine_bonus' => $mine_bonus,
                 'binded_info' => $binded_info,
@@ -142,7 +142,7 @@ class bonusexControl extends mobileControl
             else
             {
                 if($type->isEnd() || $type->binded_over()) {
-                    $summarys = $this->matched_goods();
+                    $summarys = $this->matched_goods($type_sn);
                     return self::outsuccess(array('type_info' => $type_info,
                         'binded_info' => $binded_info,
                         'avatars' => $avatars,
@@ -178,7 +178,7 @@ class bonusexControl extends mobileControl
             $mine_bonus = bonus_helper::filter_bonus($mine_bonus);
         }
 
-        $summarys = $this->matched_goods();
+        $summarys = $this->matched_goods($type_sn);
         return self::outsuccess(array('type_info' => $type_info,
             'mine_bonus' => $mine_bonus,
             'binded_info' => $binded_info,
@@ -214,7 +214,7 @@ class bonusexControl extends mobileControl
             $mine_bonus = bonus_helper::filter_bonus($mine_bonus);
 
             if($bonus_obj->isBinded()) {
-                $summarys = $this->matched_goods();
+                $summarys = $this->matched_goods($type_sn);
                 return self::outsuccess(array('type_info' => $type_info,
                     'mine_bonus' => $mine_bonus,
                     'binded_info' => $binded_info,
@@ -236,7 +236,7 @@ class bonusexControl extends mobileControl
                     $ret = bonus_helper::bind_bonus($bonus_obj->bonus_sn(),$_SESSION['MPHPSESSID'],session_helper::cur_mobile(),$new_sn);
                     if($ret == true) {
                         $mine_bonus = bonus_helper::get_mine_by_bonussn($new_sn);
-                        $summarys = $this->matched_goods();
+                        $summarys = $this->matched_goods($type_sn);
                         return self::outsuccess(array('type_info' => $type_info,
                             'mine_bonus' => $mine_bonus,
                             'binded_info' => $binded_info,
@@ -282,7 +282,7 @@ class bonusexControl extends mobileControl
                             return self::outerr(errcode::ErrBonus,"无此红包.");
                         }
                         $this->fileter_typeinfos($type_infos,$type_info,$binded_info,$avatars);
-                        $summarys = $this->matched_goods();
+                        $summarys = $this->matched_goods($type_sn);
                         $data = array('type_info' => $type_info,
                             'mine_bonus' => $mine_bonus,
                             'binded_info' => $binded_info,
@@ -315,7 +315,7 @@ class bonusexControl extends mobileControl
             $type_infos = bonus_helper::get_typeinfo($type_sn);
             $this->fileter_typeinfos($type_infos,$type_info,$binded_info,$avatars);
             $mine_bonus = bonus_helper::filter_bonus($mine_bonus);
-            $summarys = $this->matched_goods();
+            $summarys = $this->matched_goods($type_sn);
             return self::outsuccess(array('type_info' => $type_info,
                 'mine_bonus' => $mine_bonus,
                 'binded_info' => $binded_info,
@@ -436,7 +436,7 @@ class bonusexControl extends mobileControl
                     $bonus = bonus_helper::get_mine_by_bonussn($bonus_obj->bonus_sn());
                     $type_infos = bonus_helper::get_typeinfo($bonus_obj->type_sn());
                     $this->fileter_typeinfos($type_infos,$type_info,$binded_info,$avatars);
-                    $summarys = $this->matched_goods();
+                    $summarys = $this->matched_goods($type_sn);
                     return self::outsuccess(array('type_info' => $type_info,
                         'mine_bonus' => $bonus,
                         'binded_info' => $binded_info,
@@ -472,16 +472,34 @@ class bonusexControl extends mobileControl
         }
     }
 
-    private function random_cids()
+    private function random_cids($type_sn)
     {
-        if(session_helper::is_man()) {
-            return activity\goods_sampler::instance()->fetch_male(self::bonus_goods);
-        } else {
-            return activity\goods_sampler::instance()->fetch_female(self::bonus_goods);
+        $time = 0;
+        $cids = [];
+        if(array_key_exists($type_sn,$_SESSION['goods_sampler']))
+        {
+            $cids = $_SESSION['goods_sampler'][$type_sn]['cids'];
+            $time = $_SESSION['goods_sampler'][$type_sn]['time'];
+        }
+
+        if($time < time() - 86400 || empty($cids))
+        {
+            if(session_helper::is_man()) {
+                $cids = activity\goods_sampler::instance()->fetch_male(self::bonus_goods);
+            } else {
+                $cids = activity\goods_sampler::instance()->fetch_female(self::bonus_goods);
+            }
+
+            if(!empty($cids)) {
+                $_SESSION['goods_sampler'][$type_sn]['cids'] = $cids;
+                $_SESSION['goods_sampler'][$type_sn]['time'] = time();
+            }
         }
+
+        return $cids;
     }
 
-    private function matched_goods()
+    private function matched_goods($type_sn)
     {
         if(session_helper::isapp())
         {
@@ -489,7 +507,7 @@ class bonusexControl extends mobileControl
         }
         else
         {
-            $cids = $this->random_cids();
+            $cids = $this->random_cids($type_sn);
             if(empty($cids)) return false;
 
             $model_goods = Model('goods');

+ 23 - 4
mobile/control/member_bonus.php

@@ -245,11 +245,30 @@ class member_bonusControl extends mbMemberControl
 
     private function random_cids()
     {
-        if(session_helper::is_man()) {
-            return activity\goods_sampler::instance()->fetch_male(self::sampler_goods);
-        } else {
-            return activity\goods_sampler::instance()->fetch_female(self::sampler_goods);
+        $type_sn = "member_bonus";
+        $time = 0;
+        $cids = [];
+        if(array_key_exists($type_sn,$_SESSION['goods_sampler']))
+        {
+            $cids = $_SESSION['goods_sampler'][$type_sn]['cids'];
+            $time = $_SESSION['goods_sampler'][$type_sn]['time'];
+        }
+
+        if($time < time() - 86400 || empty($cids))
+        {
+            if(session_helper::is_man()) {
+                $cids = activity\goods_sampler::instance()->fetch_male(self::sampler_goods);
+            } else {
+                $cids = activity\goods_sampler::instance()->fetch_female(self::sampler_goods);
+            }
+
+            if(!empty($cids)) {
+                $_SESSION['goods_sampler'][$type_sn]['cids'] = $cids;
+                $_SESSION['goods_sampler'][$type_sn]['time'] = time();
+            }
         }
+
+        return $cids;
     }
 
     public function match_goodsexOp()