mParamer = $param; } public function isBinded() { return (intval($this->mParamer['bonus_status']) >= 2); } public function grab_time() { return intval($this->mParamer['grab_time']); } public function bonus_sn() { return $this->mParamer['bonus_sn']; } public function bonus_id() { return intval($this->mParamer['bonus_id']); } public function type_id() { return intval($this->mParamer['type_id']); } public function bonus_value() { $val = intval(doubleval($this->mParamer['bonus_value']) * 100 + 0.5); return doubleval($val) / 100; } public function bonus_status() { if(!isset($this->mParamer['bonus_status']) || empty($this->mParamer['bonus_status'])) { return 0; } else { return intval($this->mParamer['bonus_status']); } } public function can_share() { return intval($this->mParamer['can_share']) == 1; } public function client_can_share() { return (!$this->expired() && $this->can_share() && $this->spend_over() == false && $this->isBinded()); } public function can_shake() { $status = intval($this->mParamer['bonus_status']); return ($status == self::GrabStatus || $status == self::BindStatus); } public function expired() { $usable_time = intval($this->mParamer['usable_time']); return ($usable_time <= time()); } public function remain_amount() { $val = intval(doubleval($this->mParamer['remain_amount']) * 100 + 0.5); return doubleval($val) / 100; } public function pay_amount() { $val = intval(doubleval($this->mParamer['pay_amount']) * 100 + 0.5); return doubleval($val) / 100; } public function send_amount() { $val = intval(doubleval($this->mParamer['send_amount']) * 100 + 0.5); return doubleval($val) / 100; } public function spend_over() { $remain = intval(doubleval($this->mParamer['remain_amount']) * 100 + 0.5); return ($remain == 0); } public function type_sn() { return $this->mParamer['type_sn']; } public function get_param() { return $this->mParamer; } public function user_mobile() { return $this->mParamer['user_mobile']; } public function user_name() { $user_name = $this->mParamer['user_name']; if(empty($user_name)) { $user_name = substr_replace($this->mParamer['user_mobile'], '****', 3, 4); } return $user_name; } public function user_id() { return intval($this->mParamer['user_id']); } public function user_comment() { $user_comment = $this->mParamer['user_comment']; if(mb_strlen($user_comment) < 20) { return $user_comment; } else { return mb_substr($user_comment,0,15) . '...'; } } public function get_time() { return intval($this->mParamer['get_time']); } public function get_time_format() { $get_time = $this->mParamer['get_time']; return strftime("%m-%d %H:%M",$get_time); } public function usable_time() { return intval($this->mParamer['usable_time']); } public function bonus_rate() { return intval($this->mParamer['bonus_rate']); } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// static public function create_by_param($param) { return new user_bonus($param); } static public function create_by_sn($bonus_sn) { $mod_bonus = Model('user_bonus'); $items = $mod_bonus->get(array('bonus_sn' => $bonus_sn)); if(empty($items)) { throw new Exception("错误的红包SN号.",errcode::ErrBonusSN); } else { return new user_bonus($items[0]); } } }