浏览代码

add to local

stanley-king 9 年之前
父节点
当前提交
040d7fc398
共有 1 个文件被更改,包括 60 次插入0 次删除
  1. 60 0
      helper/bonus_helper.php

+ 60 - 0
helper/bonus_helper.php

@@ -19,6 +19,10 @@ 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';
@@ -149,4 +153,60 @@ class bonus_helper
             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;
+        $pre_helper = new predeposit_helper();
+        if(!$pre_helper->is_enough($param['total_amount'])) {
+            $ret = array('code' => errcode::ErrBonusNotEnough,'msg' => '余额不够发送红包');
+            return false;
+        }
+
+        return $param;
+    }
 }