123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- <?php
- /**
- * Created by PhpStorm.
- * User: stanley-king
- * Date: 16/4/11
- * Time: 上午12:51
- */
- require_once (BASE_ROOT_PATH . '/helper/bonus/util.php');
- require_once (BASE_ROOT_PATH . '/helper/bonus/type.php');
- require_once (BASE_ROOT_PATH . '/helper/bonus/user_bonus.php');
- require_once (BASE_ROOT_PATH . '/helper/bonus/generator.php');
- require_once (BASE_ROOT_PATH . '/helper/bonus/grab.php');
- require_once (BASE_ROOT_PATH . '/helper/bonus/bind.php');
- require_once (BASE_ROOT_PATH . '/helper/bonus/factory.php');
- require_once (BASE_ROOT_PATH . '/helper/bonus/manager.php');
- require_once (BASE_ROOT_PATH . '/helper/field_helper.php');
- require_once (BASE_ROOT_PATH . '/helper/predeposit_helper.php');
- 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,grab_lastime';
- $ret = array();
- field_helper::copy_column($ret,$type_info,$fileds);
- $ret['time_out'] = \bonus\manager::grab_period_timeout;
- if($type->binded_over()) {
- $ret['binded_over'] = 1;
- } else {
- $ret['binded_over'] = 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;
- return $ret;
- }
- static public function filter_bonus($bonus_info) {
- $fileds = 'bonus_sn,bonus_value,user_name,user_mobile,user_comment,get_time,bonus_status';
- $ret = array();
- field_helper::copy_column($ret,$bonus_info,$fileds);
- if(empty($bonus_info['user_name'])) {
- $ret['user_name'] = substr_replace($bonus_info['user_mobile'], '****', 3, 4);
- }
- return $ret;
- }
- static public function isFixed($send_type) {
- return ($send_type == \bonus\type::fixed_amount);
- }
- static public function isRandom($send_type) {
- return ($send_type == \bonus\type::random_amount);
- }
- static public function make_bonus($param)
- {
- $ret = \bonus\factory::make_bonus($param);
- return $ret;
- }
- static public function get_typeinfo($type_sn)
- {
- $manager = new \bonus\manager();
- return $manager->get_typeinfo($type_sn);
- }
- static public function get_mine_by_typesn($type_sn) {
- $manager = new \bonus\manager();
- return $manager->get_mine_by_typesn($type_sn);
- }
- static public function get_mine_by_bonussn($bonus_sn) {
- $manager = new \bonus\manager();
- return $manager->get_mine_by_bonussn($bonus_sn);
- }
- static public function grab_bonus($type_sn)
- {
- $manager = new \bonus\manager();
- return $manager->grab_bonus($type_sn);
- }
- static public function bind_bonus($bonus_sn,$session_id,$mobile,&$new_bonus_sn)
- {
- try
- {
- $manager = new \bonus\manager();
- return $manager->bind_bonus($bonus_sn,$session_id,$mobile,$new_bonus_sn);
- } catch (Exception $ex) {
- return array($ex->getCode(),$ex->getMessage());
- }
- }
- static public function comment($bonus_sn,$comment)
- {
- try
- {
- $manager = new \bonus\manager();
- return $manager->comment($bonus_sn,$comment);
- } catch (Exception $ex) {
- return false;
- }
- }
- static public function topup_bonus($mobile)
- {
- $mod_bonus = Model('user_bonus');
- $bind_bonus = $mod_bonus->getAllBind($mobile);
- if(empty($bind_bonus)) {
- return false;
- }
- $manager = new \bonus\manager();
- $pd_helper = new predeposit_helper();
- $bonusex = array();
- foreach($bind_bonus as $val)
- {
- $type_id = $val['type_id'];
- $type = \bonus\type::create_by_id($type_id);
- try
- {
- $info = sprintf("来自%s的红包.",$val['sender_name']);
- Db::beginTransaction();
- $pd_helper->bonus_add_money($val['bonus_value'],$val['bonus_sn'],$type->sender_name(),$info);
- if($manager->topup($mod_bonus,$val) === false) {
- throw new Exception();
- } else {
- $bonus['mine_bonus'] = $val;
- array_push($bonusex,$val);
- }
- Db::commit();
- } catch (Exception $ex) {
- Db::rollback();
- }
- }
- if(empty($bonusex)) {
- return false;
- } else {
- return $bonusex;
- }
- }
- }
|