|
@@ -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();
|