stanley-king 9 rokov pred
rodič
commit
06bfd86db3

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

@@ -37,6 +37,15 @@ class user_bonusModel extends Model
         }
     }
 
+    public function lasted_grabed($condition) {
+        $items = $this->where($condition)->field('grab_time')->order('grab_time desc')->limit(1)->select();
+        if(count($items) == 1) {
+            return $items[0]['grab_time'];
+        } else {
+            return false;
+        }
+    }
+
     //public function luckey
 
     public function add($datas) {
@@ -76,9 +85,11 @@ class user_bonusModel extends Model
     }
 
     //返回单个红包
-    public function grab($type_id,$time_out,$mobile,$sess_id,&$isNew)
+    public function grab($type_id,$time_out,$mobile,$sess_id,&$is_new_grab,&$is_new_bind)
     {
-        $isNew = false;
+        $is_new_grab = false;
+        $is_new_bind = false;
+
         try
         {
             $fields = '*';
@@ -101,7 +112,10 @@ class user_bonusModel extends Model
                 $bonus = $this->where($condition)->field($fields)->order('status,bonus_id')->limit(1)->find();
                 if(!empty($bonus))
                 {
-                    $isNew = true;
+                    if($bonus['status'] == 0) {
+                        $is_new_grab = true;
+                    }
+
                     if(user_helper::isLogin()) { // 如果是登录状态直接绑定
                         $datas = array('status' => 2,
                             'grab_time' => time(),
@@ -110,6 +124,7 @@ class user_bonusModel extends Model
                             'user_id' => $_SESSION['member_id'],
                             'user_mobile' => user_helper::cur_mobile(),
                             'user_name' => user_helper::nickname());
+                        $is_new_bind = true;
                     }
                     else if(user_helper::isVerfiyMobile()) { //如果该会话手机号码曾经认证过,直接绑定
                         $datas = array('status' => 2,
@@ -117,6 +132,7 @@ class user_bonusModel extends Model
                             'get_time'  => time(),
                             'session_id' => $sess_id,
                             'user_mobile' => user_helper::cur_mobile());
+                        $is_new_bind = true;
                     }
                     else {
                         $datas = array('status' => 1,

+ 2 - 2
helper/bonus/factory.php

@@ -35,13 +35,13 @@ class factory
         }
     }
 
-    static public function grab_bonus($paramer,&$isNew) //数组类型的参数
+    static public function grab_bonus($paramer) //数组类型的参数
     {
         try
         {
             $type = type::create_by_sn($paramer['type_sn']);
             $iGrab = create_grab($type);
-            $bonus = $iGrab->get_bonus($paramer,$isNew);
+            $bonus = $iGrab->get_bonus($paramer);
             if(empty($bonus)) {
                 return false;
             } else {

+ 20 - 14
helper/bonus/grab.php

@@ -11,6 +11,7 @@ namespace bonus;
 use \Model;
 use \Exception;
 use \errcode;
+use \Log;
 
 
 abstract class IGrab
@@ -20,7 +21,7 @@ abstract class IGrab
         $this->mType = $type;
     }
 
-    abstract public function get_bonus($paramer,&$isNew);
+    abstract public function get_bonus($paramer);
 }
 
 class DirectGrab extends IGrab
@@ -29,7 +30,7 @@ class DirectGrab extends IGrab
         parent::__construct($type);
     }
 
-    public function get_bonus($type,&$isNew)
+    public function get_bonus($type)
     {
         throw new Exception("指定人群的红包不用抢,直接领就好",errcode::ErrBonusType);
     }
@@ -41,7 +42,7 @@ class general_grab extends IGrab
         parent::__construct($paramer);
     }
 
-    public function get_bonus($paramer,&$isNew) //($type_sn,$time_out,$sess_id)
+    public function get_bonus($paramer) //($type_sn,$time_out,$sess_id)
     {
         $time_out = $paramer['time_out'];
         $session_id = $paramer['session_id'];
@@ -49,23 +50,28 @@ class general_grab extends IGrab
         $type_id = $this->mType->getType_id();
 
         $user_bonus = Model('user_bonus');
-        $isNew = false;
-        $bonus = $user_bonus->grab($type_id,$time_out,$mobile,$session_id,$isNew);
+
+        $is_new_grab = false;
+        $is_new_bind = false;
+        $bonus = $user_bonus->grab($type_id,$time_out,$mobile,$session_id,$is_new_grab,$is_new_bind);
 
         if(!empty($bonus))
         {
             $user_bonus = user_bonus::create_by_param($bonus);
-            if($isNew == true)
-            {
+            if($is_new_grab && $is_new_bind) {
+                $bonus_val = $user_bonus->bonus_value();
+                Model('bonus_type')->edit(array('type_id' => $type_id),
+                    array('grabed_num' => array('exp', 'grabed_num+1'),'binded_num' => array('exp', 'binded_num+1'),'remain_amount' => array('exp', "remain_amount-" . "{$bonus_val}")));
+            }
+            else if($is_new_bind) {
                 $bonus_val = $user_bonus->bonus_value();
-                if($user_bonus->isBinded()) {
-                    Model('bonus_type')->edit(array('type_id' => $type_id), array('grabed_num' => array('exp', 'grabed_num+1'),
-                        'binded_num' => array('exp', 'binded_num+1'),
-                        'remain_amount' => array('exp', "remain_amount-" . "{$bonus_val}")));
-                } else {
-                    Model('bonus_type')->edit(array('type_id' => $type_id), array('grabed_num' => array('exp', 'grabed_num+1')));
-                }
+                Model('bonus_type')->edit(array('type_id' => $type_id),
+                    array('binded_num' => array('exp', 'binded_num+1'), 'remain_amount' => array('exp', "remain_amount-" . "{$bonus_val}")));
             }
+            else if($is_new_grab) {
+                Model('bonus_type')->edit(array('type_id' => $type_id), array('grabed_num' => array('exp', 'grabed_num+1')));
+            }
+
             return $user_bonus;
         } else {
             return array();

+ 14 - 14
helper/bonus/manager.php

@@ -48,10 +48,20 @@ class manager
                     $type_info['binded_period'] = $period == 0 ? 1 : $period;
                 }
                 $type_info['binded_over'] = 1;
-            } else {
+                $type_info['grab_lastime'] = 0;
+            }
+            else
+            {
                 $type_info['binded_period'] = 0;
                 $type_info['binded_over'] = 0;
+                if($type->grabed_over()) {
+                    $lasted_time = Model('user_bonus')->lasted_grabed(array('type_id' => $type->getType_id(),'status' => 1));
+                    $type_info['grab_lastime'] = $lasted_time;
+                } else {
+                    $type_info['grab_lastime'] = 0;
+                }
             }
+
             $type_sn = $type->getType_sn();
             $url = BASE_SITE_URL . "/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn={$type_sn}";
             $ret['url'] = $url;
@@ -67,21 +77,16 @@ class manager
 
     public function get_mine_by_typesn($type_sn)
     {
-        $bonus = '';//$this->read_session($type_sn);
+        $bonus = $this->read_session($type_sn);
         if(empty($bonus))
         {
             $mod_bonus = Model('user_bonus');
 
             $session_id = $_SESSION['PHPSESSID'];
             if(user_helper::isVerfiyMobile()) {
-//                $condition = array('type_sn' => $type_sn,
-//                    'session_id' => $session_id,
-//                        'user_mobile' => $_SESSION['member_mobile'],
-//                        '_op' => 'or');
                 $mobile = user_helper::cur_mobile();
                 $sql = "select * from lrlz_user_bonus where type_sn = '{$type_sn}' and (session_id = '{$session_id}' or user_mobile = '{$mobile}')";
             } else {
-                //$condition = array('session_id' => $session_id,'type_sn' => $type_sn);
                 $sql = "select * from lrlz_user_bonus where type_sn = '{$type_sn}' and session_id = '{$session_id}'";
             }
 
@@ -119,9 +124,7 @@ class manager
             if(user_helper::isVerfiyMobile()) {
                 $mobile = user_helper::cur_mobile();
                 $sql = "select * from lrlz_user_bonus where bonus_sn = '{$bonus_sn}' and (session_id = '{$session_id}' or user_mobile = '{$mobile}')";
-
             } else {
-                //$condition = array('session_id' => $session_id,'type_sn' => $bonus_sn);
                 $sql = "select * from lrlz_user_bonus where bonus_sn = '{$bonus_sn}' and session_id = '{$session_id}'";
             }
             $bonusex = $mod_bonus->get_by_sql($sql);
@@ -158,17 +161,14 @@ class manager
                 'time_out' => self::grab_period_timeout,
                 'member_mobile' => $_SESSION['member_mobile']);
 
-            $isNew = false; // 是否是一个新的红包
-            $bonus_obj = factory::grab_bonus($param,$isNew);
+            $bonus_obj = factory::grab_bonus($param);
             if($bonus_obj == false) {
                 return false;
             }
             else
             {
                 $this->write_session($bonus_obj->get_param());
-                if($isNew && $bonus_obj->isBinded()) {
-                    dcache($bonus_obj->type_sn(),self::type_prefix);
-                }
+                dcache($bonus_obj->type_sn(),self::type_prefix);
             }
             $bonus = $bonus_obj->get_param();
         }

+ 11 - 1
helper/bonus/type.php

@@ -148,6 +148,17 @@ class type
     public function binded_over() {
         return intval($this->mParam['total_num']) == intval($this->mParam['binded_num']);
     }
+    public function grabed_over() {
+        return intval($this->mParam['total_num']) == intval($this->mParam['grabed_num']);
+    }
+    public function grab_lastime()
+    {
+        if(isset($this->mParam['grab_lastime'])) {
+            return intval($this->mParam['grab_lastime']);
+        } else {
+            return false;
+        }
+    }
     public function min_amount() {
         return $this->mParam['min_amount'];
     }
@@ -159,7 +170,6 @@ class type
         $max_val = intval(floatval($this->mParam['max_amount']) * 100);
         return ($max_val == intval($value * 100));
     }
-
     static public function crate_by_input($paramer)
     {
         return new type($paramer,self::create_type);

+ 1 - 1
helper/bonus_helper.php

@@ -21,7 +21,7 @@ class bonus_helper
 {
     static public function filter_type($type_info) {
         $type = \bonus\type::crate_by_paramer($type_info);
-        $fileds = 'type_sn,type_bless,send_type,sender_name,total_amount,total_num,max_amount,grabed_num,binded_num,send_start_date,binded_over,binded_period';
+        $fileds = 'type_sn,type_bless,send_type,sender_name,total_amount,total_num,max_amount,grabed_num,binded_num,send_start_date,binded_over,binded_period,grab_lastime';
         $ret = array();
         field_helper::copy_column($ret,$type_info,$fileds);
         $ret['time_out'] = \bonus\manager::grab_period_timeout;

+ 29 - 0
mobile/control/bonusex.php

@@ -248,6 +248,35 @@ class bonusexControl extends mobileControl
     }
 }
 
+function bonus_output_grabinfo($output)
+{
+    $type_info = $output['type_info'];
+    $type = \bonus\type::crate_by_paramer($type_info);
+
+    if($type->binded_over()) {
+        return "<p>手慢了,红包被领完了</p>";
+    }
+
+    if($type->grabed_over())
+    {
+        echo ("<p>手慢了,红包被抢完了</p>");
+
+        $last_time = $type->grab_lastime();
+        if($last_time) {
+            $wait_sec = $last_time + 600 - time();
+            $wait_min = intval($wait_sec / 60);
+            $wait_sec = $wait_sec % 60;
+            if($wait_min > 0) {
+                return "{$wait_min}分钟后,您可以尝试抢一个未及时领取的红包.";
+            } else {
+                return "{$wait_sec}秒后,您可以尝试抢一个未及时领取的红包.";
+            }
+        }
+    }
+
+    return "";
+}
+
 function bonus_output_openurl($output)
 {
     $type_info = $output['type_info'];

+ 2 - 1
mobile/templates/default/bonus/over.php

@@ -16,7 +16,8 @@
     <div class="content center">
         <div class="logo"></div>
         <div class="msg_bottom">
-            <p>手慢了,红包派完了</p>
+            <?php echo bonus_output_grabinfo($output); ?>
+
         </div>
         <div>
             <p class="look"><a href="<?php echo bonus_output_detailurl($output); ?>">查看领取详情></a></p>