123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- <?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
- {
- const def_bless = '恭喜发财大吉大利';
- const max_total_amount = 1000000;
- const max_total_num = 1000;
- 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,send_end_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;
- }
- if($type->isEnd()) {
- $ret['is_end'] = 1;
- } else {
- $ret['is_end'] = 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->getBinded($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;
- }
- }
- //检查个人发送红包参数
- static public function check_personal($input,&$ret)
- {
- $param = array();
- $send_type = intval($input['send_type']);
- if(!in_array($send_type,array(1,2))) {
- $ret = array('code' => errcode::ErrParamter,'msg' => "请输入正确的红包类型.");
- return false;
- }
- $param['send_type'] = $send_type; // '红包类型,1为随机红包,2为固定额度红包'
- $type_bless = isset($input['type_bless']) && !empty($input['type_bless']) ? $input['type_bless'] : self::def_bless;
- $type_bless = urldecode($type_bless);
- $type_bless = text_filter::filter_input($type_bless);
- $param['type_bless'] = $type_bless;
- $param['total_num'] = intval($input['total_num']);
- if($param['total_num'] <= 0) {
- $ret = array('code' => errcode::ErrParamter,'msg' => "红包个数不能小于1.");
- return false;
- }
- if(bonus_helper::isFixed($send_type))
- {
- $fixed_mondey = floatval($input['fixed_money']);
- if ($fixed_mondey * 100 < 1) {
- $ret = array('code' => errcode::ErrParamter,'msg' => "红包额度不能小于一分钱.");
- return false;
- }
- $param['total_amount'] = $fixed_mondey * $param['total_num'];
- $param['fixed_money'] = $fixed_mondey;
- }
- else if (bonus_helper::isRandom($send_type))
- {
- $total_amount = floatval($input['total_amount']);
- if($total_amount * 100 < $param['total_num']) {
- $ret = array('code' => errcode::ErrParamter,'msg' => "金额不够.");
- return false;
- }
- $param['total_amount'] = $total_amount;
- }
- if($total_amount > self::max_total_amount || $param['total_num'] > self::max_total_num) {
- $ret = array('code' => errcode::ErrParamter,'msg' => sprintf("红包个数不能大于%d,总金额不能大于%.2f元.",self::max_total_num,self::max_total_amount));
- return false;
- }
- $param['use_type'] = 1;
- $param['user_type'] = 2;
- return $param;
- }
- //检查活动红包参数
- static public function check_activity($input,&$ret)
- {
- if(!isset($input['start_time']) || !isset($input['end_time'])) {
- $ret = array('code' => errcode::ErrParamter,'msg' => "请输入活动开始和结束时间.");
- return false;
- }
- $start_tm = strtotime($input['start_time']);
- if($start_tm == false) {
- $ret = array('code' => errcode::ErrParamter,'msg' => "错误的活动开始时间格式,请参考,2016-06-04 10:00:00.");
- return false;
- }
- if($start_tm < time()) {
- $cur_time = date("Y-m-d H:i:s");
- $ret = array('code' => errcode::ErrParamter,'msg' => "活动时间不能小于服务器当前时间:{$cur_time}");
- return false;
- }
- $end_tm = strtotime($input['end_time']);
- if($end_tm == false) {
- $ret = array('code' => errcode::ErrParamter,'msg' => "错误的活动结束时间格式,请参考,2016-06-04 10:00:00.");
- return false;
- }
- if($end_tm <= $start_tm) {
- $ret = array('code' => errcode::ErrParamter,'msg' => "活动结束时间必须大于开始时间");
- return false;
- }
- $param = array();
- $param['send_start_date'] = $start_tm;
- $param['send_end_date'] = $end_tm;
- return $param;
- }
- }
|