From 7fca54d94cb93bfb0c41058b1b77dfd1922ae999 Mon Sep 17 00:00:00 2001 From: chenzhi Date: Tue, 16 Jun 2020 11:51:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=89=93=E6=AC=BE=E6=96=B0?= =?UTF-8?q?=E5=9F=9F=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Application/Payment/Common/extend.php | 2472 +++++++++++++++++ Application/Payment/Common/function.php | 988 +++++++ Application/Payment/Conf/config.php | 115 + Application/Payment/Conf/tags.php | 4 + .../Controller/AdminController.class.php | 602 ++++ .../Controller/BaseController.class.php | 22 + .../Controller/PaymentController.class.php | 25 + .../Controller/PublicController.class.php | 156 ++ .../Payment/View/Payment/transfer_set.html | 65 + Application/Payment/View/Public/base.html | 366 +++ Application/Payment/View/Public/error.html | 71 + .../Payment/View/Public/exception.html | 53 + Application/Payment/View/Public/login.html | 209 ++ Application/Payment/View/Public/success.html | 70 + payment.php | 42 + 15 files changed, 5260 insertions(+) create mode 100644 Application/Payment/Common/extend.php create mode 100644 Application/Payment/Common/function.php create mode 100644 Application/Payment/Conf/config.php create mode 100644 Application/Payment/Conf/tags.php create mode 100644 Application/Payment/Controller/AdminController.class.php create mode 100644 Application/Payment/Controller/BaseController.class.php create mode 100644 Application/Payment/Controller/PaymentController.class.php create mode 100644 Application/Payment/Controller/PublicController.class.php create mode 100644 Application/Payment/View/Payment/transfer_set.html create mode 100644 Application/Payment/View/Public/base.html create mode 100644 Application/Payment/View/Public/error.html create mode 100644 Application/Payment/View/Public/exception.html create mode 100644 Application/Payment/View/Public/login.html create mode 100644 Application/Payment/View/Public/success.html create mode 100644 payment.php diff --git a/Application/Payment/Common/extend.php b/Application/Payment/Common/extend.php new file mode 100644 index 000000000..5dcb80a9f --- /dev/null +++ b/Application/Payment/Common/extend.php @@ -0,0 +1,2472 @@ + + * @since: 2019\4\16 0016 13:42 + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\ModelNotFoundException + * @throws \think\exception\DbException + */ +function get_user_big_info($id=0, $flag=false) { + if((is_numeric($id) && $id>0) || (is_string($id) && !empty($id)) ) { + if($flag) { + $map['b.account'] = $id; + } else { + $map['b.id'] = $id; + } + return M('User','tab_') + ->alias('a') + ->field('a.id,a.account,a.balance') + ->join('inner join tab_user b on a.id = b.puid') + ->where($map) + ->find(); + } else { + return ''; + } +} + +/* + * 获取推广员列表(根据父级编号) + * @param integer $id 父级编号(为负数则是全部) + * @author 鹿文学 + */ +function get_promote_list_by_id($id=0) { + //为数据权限修改 2019-12-19 lww + $query = M("Promote","tab_")->field('id,account,balance_coin'); + $map = array(); + setPowerPromoteIds($map, 'id'); + + if(is_numeric($id) && $id>=0) { + $map['parent_id'] = $id; + } elseif(is_array($id)) { + $map['parent_id'] = array('in',$id); + } + $list = $query->where($map)->select(); + return $list; +} + +/* + * 秒数转时长(时分秒格式) + * @param int $times 秒数 + * @author 鹿文学 + */ +function second_to_duration($times){ + $result = '00:00:00'; + if ($times>0) { + $hour = floor($times/3600); + $minute = floor(($times-3600 * $hour)/60); + $second = floor((($times-3600 * $hour) - 60 * $minute) % 60); + $result = $hour.':'.$minute.':'.$second; + } + return $result; +} + +/** + * 后台公共文件扩展 + * 主要定义后台公共函数库 + */ +function get_vip_level_limit($field='',$level=0) { + if(empty($field)) {return '';} + $tool = M('tool',"tab_")->field('config,status')->where(['name'=>'viplevel'])->find(); + if(!empty($tool) && $tool['status']==1){ + $viplevel = json_decode($tool['config'],true); + $vl=''; + if(empty($viplevel)) {return '';} + foreach($viplevel as $k=>$v) { + $cur = intval(str_replace('vip','',$k)); + if($level == 0) {$vl = $field . '<' . $v;break;} + if($level>=count($viplevel) && $cur >= count($viplevel)) {$vl = $field . '>=' . $v;break;} + if($level==$cur) { + $vl = $field . '>=' . $v . ' and ' . $field .'<'.$viplevel['vip'.($cur+1)]; + break; + } + } + return $vl; + } else { + return ''; + } +} + +function addZeroToTime($v) { + return $v.':00'; +} +function set_date_day_format($day='') { + return strlen($day)==1?'0'.$day:$day; +} +/* + * 异常类型 + */ +function get_bug_name_by_id($id=0) { + + if (!is_numeric($id) || $id<0 ) {return '';} + + $list = get_bug_list(); + + return $list[$id]; + +} + +function get_bug_list() { + + return array( + 100=>'开发者注册未审核', + 101=>'游戏充值未到账', + 102=>'补单失败', + 103=>'平台币充值未到账', + 104=>'绑币充值未到账', + 200=>'开发者提现未处理', + 201=>'推广员提现未处理', + 300=>'推广员注册未审核', + 301=>'推广员混服申请未审核', + 302=>'推广员游戏申请未审核', + 303=>'推广员游戏申请未打包', + 304=>'推广员游戏盒子APP申请未审核', + 305=>'推广员游戏盒子APP申请未打包', + 400=>'游戏未设置分成比例', + 401=>'开发者游戏未审核', + 402=>'游戏原包未上传', + 403=>'礼包数量不足', + 404=>'评论未审核', + 405=>'发放平台币失败', + 406=>'发放绑币失败', + ); + +} +/* 获取色系 鹿文学 2017-11-17 */ +function get_color_style_list() { + $result = M('config')->field('extra,value')->find(13); + + if ($result) { + + $list['list'] = parse_config_attr($result['extra']); + + $list['value']=$result['value']; + } + return $list; +} + + + //根据游戏id获取游戏唯一标示 +function get_marking($id) +{ + $map['id']=$id; + $game=M("game","tab_")->where($map)->find(); + return $game['marking']; +} +function get_auth_group_name($uid){ + $model = D("auth_group_access"); + $res = $model->join("sys_auth_group on sys_auth_group.id = sys_auth_group_access.group_id") + ->field("title") + ->where("uid=".$uid) + ->find(); + + return empty($res["title"]) ? "空" : $res["title"]; +} +//根据发送消息的ID获取通知名字 +function get_push_name($id) +{ + $map['id']=$id; + $list=M("push","tab_")->where($map)->find(); + if(empty($list)){return false;} + return $list['push_name']; +} +//获取推送通知应用 +function get_push_list() +{ + $list=M("push","tab_")->select(); + if(empty($list)){return false;} + return $list; +} + +function get_promote_list($select='') { + $list = M("Promote","tab_")->field('id,account,balance_coin')->select();//where("status=1")-> + if (empty($list)){return '';} + if($select==111){ + $new['id']=-1; + $new['account']="全站用户"; + array_unshift($list,$new); + } + return $list; +} + +/** + * [获取所有一级推广员] + * @return [type] [description] + */ +function get_all_toppromote(){ + $map['status']=1; + $map['level']=['lt', 4]; + //为数据权限添加 + setPowerPromoteIds($map, 'id'); + $list = M("Promote","tab_")->where($map)->select(); + if (empty($list)){return '';} + return $list; +} +function time_day($time){ + $now = time(); + return floor(($now-$time)/(60*60*24)); +} +function mdate($time = NULL) { + $text = ''; + $time = $time === NULL || $time > time() ? time() : intval($time); + $t = time() - $time; //时间差 (秒) + $y = date('Y', $time)-date('Y', time());//是否跨年 + switch($t){ + case $t == 0: + $text = '刚刚'; + break; + case $t < 60: + $text = $t . '秒前'; // 一分钟内 + break; + case $t < 60 * 60: + $text = floor($t / 60) . '分钟前'; //一小时内 + break; + case $t < 60 * 60 * 24: + $text = floor($t / (60 * 60)) . '小时前'; // 一天内 + break; + case $t < 60 * 60 * 24 * 1: + $text = '昨天 ' . date('H:i', $time); + break; + case $t < 60 * 60 * 24 * 30: + $text = date('m-d H:i', $time); //一个月内 + break; + case $t < 60 * 60 * 24 * 365&&$y==0: + $text = date('m-d', $time); //一年内 + break; + default: + $text = date('Y-m-d-', $time); //一年以前 + break; + } + + return $text; +} + +//所有支付方式 +function all_pay_way($type=false) +{ + + if($type){ + $pay_way[0]=array('key'=>0,'value'=>"平台币"); + } + $pay_way[1]=array('key'=>-1,'value'=>"绑币"); + $pay_way[2]=array('key'=>1,'value'=>"支付宝"); + $pay_way[3]=array('key'=>2,'value'=>"微信"); + $pay_way[7]=array('key'=>8,'value'=>'金猪'); + $pay_way[9]=array('key'=>9,'value'=>"双乾支付-支付宝"); + $pay_way[10]=array('key'=>10,'value'=>"双乾支付-银联"); +// $pay_way[3]=array('key'=>3,'value'=>'微信APP'); +// $pay_way[4]=array('key'=>4,'value'=>'威富通'); + /* $pay_way[4]=array('key'=>5,'value'=>'聚宝云'); */ +// $pay_way[5]=array('key'=>6,'value'=>'汇付宝'); + /* $pay_way[6]=array('key'=>7,'value'=>"苹果支付"); + */ + $pay_way[15]=array('key'=>15,'value'=>'双乾支付-快捷'); + $pay_way[17]=array('key'=>17,'value'=>'易宝支付'); + return $pay_way; +} +/* //获取支付方式 */ +function get_pay_way($id=null) +{ + if(!isset($id)){ + return false; + } + switch ($id) { + case -1: + return "绑币"; + break; + case 0: + return "平台币"; + break; + case 1: + return "支付宝"; + break; + case 2: + return "微信"; + break; + case 3: + return "微信APP"; + break; + case 4: + return "威富通"; + break; + case 5: + return "聚宝云"; + break; + case 6: + return "竣付通"; + break; + case 7: + return "苹果支付"; + break; + case 8: + return "金猪支付"; + break; + case 9: + return "双乾支付-支付宝"; + break; + case 10: + return "双乾支付-银联"; + break; + case 15: + return "双乾支付-快捷"; + case 17: + return "易宝支付"; + break; + } +} + +/** + * 获取订单类型 + * + * @param null $id + * @return string + */ +function get_order_type($id=null) +{ + switch ($id) { + case 1: + return "sdk充值订单"; + break; + case 2: + return "平台币充值订单"; + break; + case 3: + return "超级签充值订单"; + break; + default: + return '未知'; + break; + } +} + +function get_pay_way_map($id) { + + if(!isset($id)){ + return ''; + } + switch ($id) { + case -1: + return -1; + break; + case 0: + return 0; + break; + case 1: + return 1; + break; + case 2: + case 3: + case 4: + return array('in',[2,3,4]); + break; + case 5: + return 5; + break; + case 6: + return 6; + break; + case 7: + return 7; + break; + case 8: + return 8; + break; + case 9: + return 9; + case 17: + return 17; + break; + } + +} + + +function get_obtain_pay_way($keys=array()){ + $pay_way[0]=array('key'=>0, 'value'=>"平台币"); + $pay_way[1]=array('key'=>-1,'value'=>"绑币"); + $pay_way[2]=array('key'=>1, 'value'=>"支付宝"); + $pay_way[3]=array('key'=>2, 'value'=>"微信"); + $pay_way[4]=array('key'=>5, 'value'=>'聚宝云'); + $pay_way[6]=array('key'=>7, 'value'=>"苹果支付"); + $pay_way[7]=array('key'=>8,'value'=>'竣付通'); + + if(!empty($keys)){ + foreach ($keys as $key) { + unset($pay_way[$key]); + } + } + return $pay_way; +} +//获取支付方式 +function get_register_way($id=null) +{ + if(!isset($id)){ + return false; + } + switch ($id) { + case 1: + return "SDK注册"; + break; + case 2: + return "APP注册"; + case 3: + return "PC注册"; + case 4: + return "WAP注册"; + break; + } +} +/** + * 获取所有第三方注册方式 + * @param [type] $id [description] + * @return [type] [description] + */ +function get_register_type($id=null){ + if(!isset($id)){ + return false; + } + switch ($id) { + case 3: + return "微信"; + break; + case 4: + return "QQ"; + case 5: + return "百度"; + case 6: + return "微博"; + break; + } +} +/** + * 所有注册方式 + * @param boolean $type [description] + * @return [type] [description] + * @author zc <894827077@qq.com> + */ +function all_register_way($type=false) +{ + $pay_way[1]=array('key'=>1,'value'=>'SDK注册'); + $pay_way[2]=array('key'=>2,'value'=>'APP注册'); + $pay_way[3]=array('key'=>3,'value'=>'PC注册'); + $pay_way[4]=array('key'=>4,'value'=>'WAP注册'); + return $pay_way; +} +/** + * 所有第三方注册方式 + * @param boolean $type [description] + * @return [type] [description] + * @author zc <894827077@qq.com> + */ +function all_register_type($type=false) +{ + $pay_way[3]=array('key'=>3,'value'=>'微信'); + $pay_way[4]=array('key'=>4,'value'=>'QQ'); + $pay_way[5]=array('key'=>5,'value'=>'百度'); + $pay_way[6]=array('key'=>6,'value'=>'微博'); + $pay_way[7]=array('key'=>0,'value'=>'游客'); + return $pay_way; +} + +/** + * 根据用户账号 获取用户昵称 + * @param [type] $account [用户账号] + * @return [type] user_nickname [用户] + * @author [yyh] + */ +function get_user_nickname($account){ + $map['account']=$account; + $user=M("user_play","tab_")->field('user_nickname')->where($map)->find(); + return $user['user_nickname']; +} +//判断用户是否玩此游戏 author:yyh +function get_play_user($account,$gid){ + if(empty($account))return false; + $user = D('User'); + $map['account']=$account; + $map['game_id']=$gid; + $data = $user->field('tab_user.id,tab_user.account') + ->join('tab_user_play on tab_user.account=tab_user_play.user_account') + ->where($map) + ->find(); + return $data; +} +//生成订单号 +function build_order_no(){ + return date('Ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8); +} +/** + * [get_game_id description]根据游戏名称 获取游戏id + * @param [type] $name [游戏名称] + * @return [type] [id] + * @author [yyh] <[email address]> + */ +function get_game_id($name){ + $game=M('game','tab_'); + $map['game_name']=$name; + $data=$game->where($map)->find(); + if($data['id']==null){ + return false; + } + return $data['id']; +} + +/** + * [ratio_stytl 数值转百分比 + * @param integer $num [description] + * @return [yyh] [description] + */ +function ratio_stytl($num = 0){ + return $num."%"; +} +/** + * [get_user_account 根据用户id 获取用户账号] + * @param [type] $uid [用户id] + * @return [type] account [用户账号] + * @author [yyh] <[email address]> + */ +function get_user_account($uid=null){ + if(empty($uid)){return false;} + $user = D('User'); + $map['id'] = $uid; + $data = $user->field('account')->where($map)->find(); + if(empty($data['account'])){return false;} + return $data['account']; +} +/** + * [checked_game description] + * @param [type] $id [description] + * @param [type] $sibling_id [description] + * @return [type] [description] + */ +function checked_game($id,$sibling_id){ + if($sibling_id){ + $map['id']=array('neq',$id); + $map['sibling_id']=$sibling_id; + $game=M('Game','tab_')->where($map)->find(); + if(empty($game)){ + return ''; + }else{ + return $game; + } + }else{ + return false; + } +} + +/** + * [获取游戏原包文件版本] + * @param [type] $game_id [description] + * @param string $type [description] + * @return [type] [description] + */ +function get_game_version($game_id,$type=''){ + $model=M('game_source force index (`game_id`)','tab_'); + if($game_id==''){ + return ''; + } + $map['game_id']=$game_id; + $map['file_type']=$type; + $data=$model + ->where($map) + ->select(); + return $data; +} +/** + * [获取游戏版本] + * @param [type] $id [description] + * @return [type] [description] + */ +function game_version($id){ + $game=M('game','tab_'); + $map['id']=$id; + $data=$game->field('sdk_version')->where($map)->find(); + if($data['id']==null){ + return false; + } + return $data['version']; +} + +/** +*获取游戏配置的指定字段信息 +*/ +function get_game_set_field($game_id,$field=""){ + $map['id'] = $game_id; + $data = M('GameSet','tab_')->where($map)->getField($field); + if(empty($data)){ + return "暂无"; + }else{ + return $data; + } +} +/** + * 渠道列表 + * @param $type + * @return mixed + */ +function promote_lists($type){ + if($type){ + $map['level'] = $type; + } else{ + $map = ''; + } + //为数据权限添加 + setPowerPromoteIds($map, 'id'); + $data = M('promote','tab_')->where($map)->select(); + + $items = M('PromoteBalanceCoin', 'tab_')->where(['game_id' => 0])->select(); + $records = []; + foreach ($items as $item) { + $records[$item['promote_id']] = $item['num']; + } + foreach ($data as $key => $item) { + $item['common_coin'] = isset($records[$item['id']]) ? $records[$item['id']] : $item['balance_coin']; + $data[$key] = $item; + } + + return $data; +} + +// 获取IOS游戏名称 +function get_ios_game_name($game_id=null,$field='id'){ + $map[$field]=$game_id; + $map['game_version']=0; + $data=M('Game','tab_')->where($map)->find(); + if(empty($data)){return false;} + $game_name=explode("(", $data['game_name']); + return $game_name[0]; +} + +/** + * [获取区服名称] + * @param [type] $id [description] + * @return [type] [description] + */ +function get_server_name($id){ + if($id==''){ + return false; + } + $map['id']=$id; + $area=M("Server","tab_")->field('')->where($map)->find(); + return $area['server_name']; +} +/** + * [获取游戏区服名称] + * @param [type] $area_id [description] + * @return [type] [description] + */ +function get_area_name($area_id= null){ + if(empty($area_id)){return false;} + $area_model = D('Server'); + $map['server_num'] = $area_id; + $name = $area_model->field('server_name')->where($map)->find(); + if(empty($name['server_name'])){return false;} + return $name['server_name']; +} + +/** + * [根据推广员获取所属专员] + * @param [type] $id [description] + * @return [type] [description] + */ +function get_belong_admin($id) +{ + $map['id']=$id; + $pro=M("promote","tab_")->where($map)->find(); + if($pro){ + return get_admin_nickname($pro['parent_id'],$pro['admin_id']); + }else{ + return false; + } +} +/** + * [获取管理员列表] + * @return [type] [description] + */ +function get_admin_list() +{ + $list= M("Member")->field('uid,nickname')->where("status=1")->select(); + if(empty($list)){return false;} + return $list; +} +/** + * [渠道等级] + * @param [type] $pid [description] + * @return [type] [description] + */ +function get_qu_promote($pid){ + if($pid==0){ + return "一级推广员"; + }else{ + return "二级推广员"; + } +} +/** + * [上线渠道] + * @param [type] $id [description] + * @param [type] $pid [description] + * @return [type] [description] + */ +function get_top_promote($id,$pid){ + if($pid==0){ + $pro=M("promote","tab_")->field('account')->where(array('id'=>$id))->find(); + }else{ + $map['id']=$pid; + $pro=M("promote","tab_")->field('account')->where($map)->find(); + } + if($pro==''){ + return false; + } + return $pro['account']; +} + + +function get_parent_promote_name($id) { + if(!is_numeric($id) || $id<1) {return '--';} + $promotemodel= M('promote','tab_'); + $pro = $promotemodel->field('account,parent_id')->where(['id'=>$id])->find(); + + if(is_array($pro)) { + + if($pro['parent_id']==0) {return $pro['account'];} + + $pre = $promotemodel->field('account')->where(['id'=>$pro['parent_id']])->find(); + + if(is_array($pre)) { + return $pre['account']; + } else { + return $pro['account']; + } + + } else { + return '--'; + } + +} + +/** + * 获取管理员昵称 二级跟随一级 + * @param [type] $parent_id [description] + * @param [type] $admin_id [description] + * @return [type] ` [description] + */ +function get_admin_nickname($parent_id = 0,$admin_id=null){ + $user = D('member'); + $map1['uid'] = $parent_id; + $data = $user->field('nickname')->where($map1)->find(); + return $data['nickname']; +} + +function get_admin_account($id=0) { + $map['id'] = $id; + $data = M('UcenterMember')->field('username')->where($map)->find(); + return $data['username']; +} + +/** + * [根据推广员获取所属专员] + * @param [type] $id [description] + * @return [type] [description] + */ +function get_admin_promotes($param,$type='admin_id') +{ + $map[$type]=$param; + $pro=M("promote","tab_")->where($map)->select(); + return $pro; +} +/** + * [根据推广员id获取上级推广员姓名] + * @param [type] $id [description] + * @return [type] [description] + */ +function get_parent_promoteto($id){ + if($id==''){ + return ''; + } + $list=D("promote"); + $map['id']=$id; + $pid=$list->field('parent_id')->where($map)->find(); + if($pid['parent_id']!=0){ + $mapp['id']=$pid['parent_id']; + $pname=$list->field('account')->where($mapp)->find(); + if($pname){ + return "[".$pname['account']."]"; + } + else{ + return ""; + } + }else{ + return ""; + } +} + //获取注册来源 +function get_registerway($way){ + if(!isset($way)){ + return false; + } + $arr=array( + 1=>'SDK', + 2=>'APP', + 3=>'PC', + 4=>'WAP', + ); + return $arr[$way]; +} +//获取注册方式 +function get_registertype($type){ + if(!isset($type)){ + return false; + } + $arr=array( + 0=>"游客", + 1=>"账号", + 2 =>"手机", + 3=>"微信", + 4=>"QQ", + 5=>"百度", + 6=>"微博", + 7=>"Facebook", + 8=>"Google", + 9=>"邮箱", + + ); + return $arr[$type]; +} +//获取推广员id +function get_promote_id($name){ + $promote=M('Promote','tab_'); + $map['account']=$name; + $data=$promote->field('id')->where($map)->find(); + if(empty($data)){ + return ''; + }else{ + return $data['id']; + } +} +//获取管理员id +function get_admin_id($name){ + $promote=M('Member','sys_'); + $map['nickname']=$name; + $data=$promote->field('uid')->where($map)->find(); + if(empty($data)){ + return ''; + }else{ + return $data['uid']; + } +} +//获取所有用户列表 +function get_user_list(){ + $user = M('User','tab_'); + $list = $user->field('id,account,balance')->order('id')->select(); + return $list; +} + +//获取所有用户列表 +function get_user_play_group_list(){ + $user = M('UserPlay','tab_'); + $list = $user->field('user_id,user_account,game_id,game_name,bind_balance')->group("user_id")->select(); + return $list; +} +/** + * [array_group_by 二维数组根据里面元素数组的字段 分组] + * @param [type] $arr [description] + * @param [type] $key [description] + * @return [type] [description] + */ +function array_group_by($arr, $key){ + $grouped = []; + foreach ($arr as $value) { + $grouped[$value[$key]][] = $value; + } + if (func_num_args() > 2) { + $args = func_get_args(); + foreach ($grouped as $key => $value) { + $parms = array_merge([$value], array_slice($args, 2, func_num_args())); + $grouped[$key] = call_user_func_array('array_group_by', $parms); + } + } + return $grouped; +} +/** + * [前几个月] + * @param integer $m [前几个月] + * @return [type] [description] + */ +function before_mounth($m=12){ + $time=array(); + for ($i=0; $i <$m ; $i++) { + $time[]=date("Y-m", strtotime("-$i month")); + } + return $time; +} +/** + * 获取上周指定日期时间 + * @param $str 指定时间 + * @return unknown 时间 + */ +function get_lastweek_name($str){ + switch ($str) { + case '1': + $time = date("Y-m-d",mktime(0,0,0,date('m'),date('d')-1,date('Y'))); + break; + case '2': + $time = date("Y-m-d",mktime(0,0,0,date('m'),date('d')-2,date('Y'))); + break; + case '3': + $time = date("Y-m-d",mktime(0,0,0,date('m'),date('d')-3,date('Y'))); + break; + case '4': + $time = date("Y-m-d",mktime(0,0,0,date('m'),date('d')-4,date('Y'))); + break; + case '5': + $time = date("Y-m-d",mktime(0,0,0,date('m'),date('d')-5,date('Y'))); + break; + case '6': + $time = date("Y-m-d",mktime(0,0,0,date('m'),date('d')-6,date('Y'))); + break; + case '7': + $time = date("Y-m-d",mktime(0,0,0,date('m'),date('d')-7,date('Y'))); + break; + // case '-1': + // $time = date("Y-m-d",mktime(0,0,0,date('m'),date('d')-7,date('Y'))); + // break; + default: + $time =date("Y-m-d",mktime(0,0,0,date('m'),date('d'),date('Y'))); + break; + + } + return $time; +} + +//获取广告图类型 +function get_adv_type($type=0){ + switch ($type) { + case 1: + return '单图'; + break; + case 2: + return '多图'; + break; + case 3: + return '文字链接'; + break; + case 4: + return '代码'; + break; + default: + return '未知类型'; + break; + } +} + +/** + *获取广告位标题 + *@param int $pos_id + *@return string + *@author 小纯洁 + */ +function get_adv_pos_title($pos_id=0){ + $adv_pos = M('AdvPos',"tab_"); + $map['id'] = $pos_id; + $data = $adv_pos->field('title')->where($map)->find(); + if(empty($data)){return "没有广告位";} + return $data['title']; +} +function get_relation_game($id,$relation_id){ + if($id==$relation_id){ + $gdata=M('Game','tab_')->where(array('relation_game_id'=>$relation_id,'id'=>array('neq',$id)))->find(); + if(!$gdata){ + return false;//未关联游戏 即没有例外一个版本 + }else{ + return true; + } + }else{ + //再次确认关联的游戏 + $gdata=M('Game','tab_')->where(array('relation_game_id'=>$relation_id,'id'=>$relation_id))->find(); + if($gdata){ + return true; + }else{ + return -1; //数据出错 + } + } +} +function get_kuaijie($type=''){ + if($type==''){ + return false; + }else{ + $data=M('Member')->field('kuaijie_value')->where(array('uid'=>UID))->find(); + } + $data=$data['kuaijie_value']; + if(empty($data)){ + $data='1,2,3,4,5,6,7,8,9,10'; + } + $dataa=explode(',',$data); + if($type==1){ + if($data==''){ + $dataa=''; + }else{ + $map['id']=array('in',$data); + $dataa=M('Kuaijieicon')->where($map)->select(); + } + }elseif($type==2){ + if($data==''){ + $dataa=M('Kuaijieicon')->select(); + }else{ + $map['id']=array('not in',$data); + $dataa=M('Kuaijieicon')->where($map)->select(); + } + } + foreach ($dataa as $key => $value) { + foreach ($data as $k => $v) { + if($value==$v['value']){ + $dataa[$key]=$v; + } + } + } + return $dataa; +} + +/** + * 获取游戏版本 + * @param $game_id + * @return string + */ +function get_sdk_version($game_id){ + $game = M('Game','tab_')->find($game_id); + $version = empty($game) ? '' : $game['sdk_version']; + return $version; +} +function get_kefu_data(){ + $map['status']=1; + $map['istitle']=1; + $list = M('Kefuquestion') + ->where($map) + ->group('title') + ->select(); + return $list; +} + + +//获取短消息未读条数 +function get_msg($id = 0){ + $id = $id ? $id : session('user_auth.uid'); + $map['user_id'] = $id; + $map['status'] = 2; + $count = M('msg', 'tab_')->where($map)->count(); + return $count; +} +function array_status2value($status,$param,$array=array()){ + foreach ($array as $key => $value) { + if($value[$status]!=1){ + unset($array[$key]); + } + } + return $array; +} + +/** + * 获取渠道平台币 + * @param $promote_id + * @return mixed + */ +function get_promote_coin($promote_id){ + $promote = M('promote','tab_')->field('balance_coin')->find($promote_id); + return $promote['balance_coin']; +} +function intFun($v) + { + $v=(int)$v; + return $v; + } + +/** + * 获取渠道父类 + * @param $promote_id + * @param string $field + * @return mixed + */ +function get_promote_parent($promote_id,$field='account'){ + $Promote = M('promote','tab_'); + $data = $Promote->field('parent_id')->find($promote_id); + if($data['parent_id'] != 0){ + $data = $Promote->find($data['parent_id']); + } + return $data[$field]; +} + +/** + * 获取渠道父类 父级默认空 + */ +function get_promote_parent_acc($promote_id){ + + $Promote = M('promote','tab_'); + $data = $Promote->field('account,parent_id,chain')->find($promote_id); + + if(empty($data)){ + return $data["account"]="官方渠道";exit; + } + $chain = trim($data['chain'], '/'); + if ($chain == '') { + return '------'; + } else { + $topPromoteId = explode('/', $chain)[0]; + $parent_promote = M('promote', 'tab_')->where(['id' => $topPromoteId])->find(); + return $parent_promote['account'] ?: '------'; + } +} + +//获取所有苹果证书id +function get_applecert(){ + $data=M('applecert')->select(); + return $data;; +} + +/** + * 获取ios游戏描述文件路径等 + * @param [type] $game_id 游戏id + * @param [type] $type 1 原包路径 2描述文件路径 + * @return [type] 路径 + */ +function get_game_url($game_id,$type=1){ + $map['game_id']=$game_id; + $find=M('game_source','tab_')->field('file_url,description_url')->where($map)->find(); + if($type==1){ + return $find['file_url']; + }elseif($type==2){ + return $find['description_url']; + } +} + + +/** + * 检查苹果渠道包打包状态 + * @param [type] $pid [渠道id] + * @param [type] $gid [游戏id] + * @return boolean [-2 可以申请 -1 正在打包 1打包成功 2 打包失败 ] + */ +function is_check_pack_for_ios($pid,$gid){ + $map['channelid']=$pid; + $map['game_id']=$gid; + $find=M('iospacket')->where($map)->find(); + if(null==$find){ + return -2; + }elseif(null!==$find&&$find['status']==2){ + return -1; + }elseif(null!==$find&&$find['status']==0){ + return 1; + }elseif(null!==$find&&$find['status']==-1){ + return 2; + } +} + +/** + * 根据游戏id获取存入iospacket的原包/描述文件路径 + * @param [type] $game_id [description] + * @param [type] $t [description] + * @return [type] [description] + */ +function get_ios_purl($game_id,$t){ + $a=explode("/",get_game_url($game_id,$t)); + return $a[3]."/".$a[4]; +} + + +/** + * 判断原包是否有更新 + * @param [type] $game_id [游戏id] + * @param [type] $promote_id [渠道id] + * @return [type] [1 有更新 0 无鞥下] + */ +function check_iosupdate($game_id,$promote_id){ + $map['game_id']=$game_id; + $source=M('game_source','tab_')->field('game_id,file_url')->where($map)->find(); + $map['channelid']=$promote_id; + $iospack=M('iospacket')->field('originalpath')->where($map)->find(); + if($source['file_url']!=="./Uploads/Ios/".$iospack['originalpath']){ + return 1; + }else{ + return 0; + } +} + +/** + * 获取积分类型列表 + * @return mixed + * author: xmy 280564871@qq.com + */ +function get_point_type_lists(){ + $data =M("point_type","tab_")->where(['status'=>1])->select(); + return $data; +} + +/** + * 获取积分商品列表 + * author: xmy 280564871@qq.com + */ +function get_point_good_lists(){ + $data =M("point_shop","tab_")->where(['status'=>1])->select(); + return $data; +} + +/** + * 验证退款记录 + * @param $pay_order_number + * @return int + */ +function ischeck_refund($pay_order_number){ + $map['pay_order_number']=$pay_order_number; + $find=M('refund_record','tab_')->where($map)->find(); + if(null==$find){ + return 1; + }elseif($find['tui_status']=='2'){ + return 2; + }elseif($find['tui_status']=='1'){ + return 0; + } +} + + +/** + * 获取支付方式 + * @param $order + * @return mixed + */ +function get_spend_pay_way($order){ + $map['pay_order_number']=$order; + $find=M('refund_record','tab_')->field('pay_way')->where($map)->find(); + return $find['pay_way']; +} + +//得到ios游戏的plist_url + +function get_plist($game_id){ + $map['game_id'] = $game_id; + $data = M('Game_source','tab_')->where($map)->field('plist_url')->find(); + if (empty($data['plist_url'])){ + return ''; + }else{ + return "itms-services://?action=download-manifest&url=".$_SERVER['HTTP_HOST'].substr($data['plist_url'],1); + } +} + +/** +*删除数组中特定元素 +* @param array $data, 要移除的数据 +* @param type $element,要移除的指定元素 +* @return array 移除后的新数组 +* @author 小纯洁 +*/ +function remove_array_element($data=null,$element=null){ + foreach ($data as $key=>$value) { + if ($value === $element) + { + unset($data[$key]); + } + } + return $data; +} + +/** +*获取首冲续充对象名称 +*@param int $case 类型 +*@return string 返回对象名称 +*@author 小纯洁 +*/ +function get_discount_obj_name($case = 0){ + $result = ""; + switch ($case) { + case -1: + $result = "全站玩家"; + break; + case 0: + $result = "官方渠道"; + break; + case -2: + $result = "推广渠道"; + break; + default: + $result = "全站玩家"; + break; + } + return $result; +} + +/** +*根据推广员ID获取商务专员账号名称 +*@param int $promote_id +*@return string 返回对象名称 +*@author 小纯洁 +*/ +function get_promote_business_account($promote_id=0){ + $promote = M('promote','tab_')->find($promote_id); + if(empty($promote)){ + return "错误"; + } + $business = M('BusinessAffairs','tab_')->find($promote['ba_id']); + return empty($business['account']) ? "暂无" : $business['account']; +} + +function get_highlight_subnav($cate_id=0,$url='Article/index',$param='cate_id'){ + $map['sys_category.id'] = $cate_id; + $cate_id = D('category') + ->field("tab.id,tab.title,tab.pid,tab.sort") + ->join("sys_category AS tab ON sys_category.pid = tab.pid") + ->where($map) + ->order('tab.sort asc') + ->getField('tab.id',1); + $url = U($url,array('cate_id'=>$cate_id)); + return $url; +} + +/** +*根据唯一字段查找特定的字段值 +*@param string field 要返回的字段结果 +*@param string fieldMap 要查询的字段名称 +*@param string value 要查询的唯一字段的值 +*/ +function get_spend_fields($field='user_account',$fieldMap='id',$value=''){ + $map[$fieldMap] = $value; + $data = M('Spend','tab_')->field($field)->where($map)->find(); + if(empty($data)){ + return false; + }else{ + return $field === 'true' ? $data : $data[$field]; + } +} + +/** + *根据模板id获取获取模板名称 + */ +function get_tepname($id){ + $model = M("Template"); + $map["id"] = $id; + $reg = $model->where($map)->find(); + return $reg["temname"]; +} + +function open_url($url=null){ + $str = "".$url.""; + return $str; +} +/** + *获取自建模板 + */ +function templatelist(){ + $model = M("Template"); + $list = $model->select(); + return $list; +} +/** +*返回游戏名称 +*/ +function get_gamename($gid=0){ + + if($gid == 0){return "未知";} + $model = D("Game"); + $list = $model->where("id=".$gid)->find(); +// return $list; + return $list["game_name"]; +} + +/** + *返回游戏官网名称 + */ +function get_self_name($gid=0){ + if($gid == 0){return "未知";} + $model = D("Game"); + $self=M('selfbuilt')->where(['id'=>$gid])->find(); + $list = $model->where("id=".$self['gameid'])->find(); + return $list["game_name"]; +} + +function get_list_data($model=null){ + $m = M($model)->select(); + return $m; +} + +function get_list_row($item = "global",$modelName="Model"){ + $list = new \Admin\Event\listRowEvent(); + $r = $list->getItem($item); + return $list->listRows(); +} + +function get_pos_game($type=16){ + $map['apply_status'] = 1; + $map['game_status'] = 1; + if($type == 16){ + $map['sdk_version'] = 1; + }else{ + $map['sdk_version'] = 2; + } + $data = M('game','tab_')->field('id,game_name')->where($map)->select(); + return $data; +} + +function get_promote_levels($id = 0) +{ + $data = M('promote', 'tab_')->field('parent_id, level')->where(array('id' => $id))->find(); + switch ($data['level']) { + case '1': + return "会长"; + break; + case '2': + return "部门长"; + break; + case '3': + return "组长"; + break; + case '4': + return "组员"; + break; + + default: + return ''; + } +} + +/** + * 统计推广员总流水 + * @param [type] $id [description] + * @return [type] [description] + */ +function sum_promote_total_money($id){ + $map['promote_id']=$id; + $map['pay_status']=1; + $res=M('Spend','tab_')->field("SUM(pay_amount) as pay_amount")->where($map)->select(); + return $res[0]['pay_amount']==null ? '0.00':$res[0]['pay_amount']; +} + +/** + *后续可用额度 + * @param [type] $game_id [description] + * @return [type] $promote_id [description] + */ +function max_quota($game_id,$promote_id){ + + $map_s['game_id'] =$game_id; + $map_s['promote_id'] =$promote_id; + $map_s['support_type'] =1; + $map_s['notice_status'] =1; + $yishenhe_support_sum=M('support','tab_')->field("SUM(real_support_num) as sum_support_num")->where($map_s)->select(); + $map_s['notice_status'] =0; + $map_s['status'] =['neq',0]; + $weishenhe_support_sum=M('support','tab_')->field("SUM(support_num) as sum_support_num")->where($map_s)->select(); + $support_quota=M('game','tab_')->field('support_quota,support_ratio')->where(['id'=>$game_id])->find(); + $max_quota=$support_quota['support_quota']-$support_sum[0]['sum_support_num']; //算法一: 可用额度 = 后台设置额度 - 已申请额度 + + $map_sp['pay_status']=1; + $map_sp['game_id']=$game_id; + $child_promote = get_zi_promote_id($promote_id); + if($child_promote==0){ + $child_promote = $promote_id; + }else{ + $child_promote = $child_promote .','.$promote_id; + } + $map_sp['promote_id'] = ['in',$child_promote]; + $spend=M('spend','tab_')->field('SUM(pay_amount) as sum_amount')->where($map_sp)->select(); + // 该渠道该游戏可用额度 = 该渠道和子渠道的所有玩家的充值量 * 扶持额度 - 待审核额度 - 已申请成功额度 + $promote_quota=floor($spend[0]['sum_amount'] * $support_quota['support_ratio']/100 - $weishenhe_support_sum[0]['sum_support_num'] - $yishenhe_support_sum[0]['sum_support_num']); + + return $promote_quota < 1 ? 0 : $promote_quota; +} + + +//现金支付方式 +function cash_pay_way() +{ + //$pay_way[1]=array('key'=>-1,'value'=>"绑币"); + $pay_way[2]=array('key'=>1,'value'=>"支付宝"); + $pay_way[3]=array('key'=>2,'value'=>"微信"); +// $pay_way[3]=array('key'=>3,'value'=>'微信APP'); +// $pay_way[4]=array('key'=>4,'value'=>'威富通'); + /* $pay_way[4]=array('key'=>5,'value'=>'聚宝云'); */ +// $pay_way[5]=array('key'=>6,'value'=>'汇付宝'); + /* $pay_way[6]=array('key'=>7,'value'=>"苹果支付"); + */ + $pay_way[7]=array('key'=>8,'value'=>'金猪'); + $pay_way[9]=array('key'=>9,'value'=>"双乾支付-支付宝"); + $pay_way[10]=array('key'=>10,'value'=>"双乾支付-银联"); + $pay_way[15]=array('key'=>15,'value'=>'双乾支付-快捷'); + $pay_way[17]=array('key'=>17,'value'=>'易宝支付'); + return $pay_way; +} + +function getMonth() { + $start = date("Y-m", strtotime("now")); + //开始月份 + $range = []; + $i = 1; + do { + $month = date('Y-m', strtotime($start . ' - ' . $i . ' month')); + $range[] = $month; + $i++; + } while ($i<13); + + return $range; +} + +function getPayType($type) { + + $return = ''; + + switch ($type) { + case -1: + $return = '绑币'; + break; + case 0: + $return = '平台币'; + break; + case 1: + $return = '支付宝'; + break; + case 2: + $return = '微信(扫码)'; + break; + case 3: + $return = '微信app'; + break; + case 4: + $return = '威富通'; + break; + case 5: + $return = '聚宝云'; + break; + case 6: + $return = '竣付通'; + break; + case 7: + $return = '金猪'; + break; + case 9: + $return = '双乾支付-支付宝'; + break; + case 10: + $return = '双乾支付-银联'; + break; + case 15: + $return = '双乾支付-快捷'; + break; + case 17: + $return = '易宝支付'; + break; + default: + $return = '未知'; + break; + } + + return $return; + +} +function getPartner() { + + $map['status'] = 1; + $data = M('partner','tab_')->field('id,partner')->where($map)->select(); + + return $data; + +} + +function getGameList($partner_id) { + if ($partner_id) { + $map['partner_id'] = $partner_id; + } + + $data = M('game','tab_')->field("id,game_name")->where($map)->select(); + + return $data; +} + +function getAdminData ($uid) { + $adminData = M('auth_group_access') + ->field('data_empower_type,data_president,show_data') + ->join('left join sys_auth_group on sys_auth_group_access.group_id=sys_auth_group.id') + ->where(array('uid'=>$uid))->find(); + +// $promoteData = M('promote','tab_')->field('id')->where(array('admin_id'=>$uid))->select(); +// $promoteData = implode(',',array_column($promoteData,'id')); +// $adminData['data_president'] = $adminData['data_president'].','.$promoteData; + + return $adminData; +} + +/** + * 获取当前管理员有权限查看所有推广员id + * @return mixed|string 格式如;all-全部;1,2,3;为空表示都没有权限 + */ +function getPowerPromoteIds() +{ + //session已存在当前管理员可查看数据的推广员id,则直接返回,权限有变化事删除此session + if (!empty(session('user_auth_promote_ids'))) { + return session('user_auth_promote_ids'); + } + $userAuth = session('user_auth'); + $promoteIds = 'all'; + $userAuth['data_president']= trim($userAuth['data_president'], ","); + if (!empty($userAuth['data_empower_type'])) {//数据权限 1 全部 2 部分数据 3 自己底下的会长 + //等于1默认全部数据,不进行筛选 + if (in_array($userAuth['data_empower_type'], [2, 3])) { + $promoteIds = ''; + //自己创建的会长 + $myPromote_ids = M('promote', 'tab_') + ->field('GROUP_CONCAT(id) as promote_ids') + ->where(['admin_id' => $userAuth['uid']]) + ->find(); + $myPromote_ids = $myPromote_ids['promote_ids']; + + if ($myPromote_ids) { + if ($userAuth['data_empower_type'] == 2) {//部分会长加上自己创建的会长 + +// $userAuth['data_president'] .= "," . $myPromote_ids; + } elseif ($userAuth['data_empower_type'] == 3) {//自己创建的会长和底下推广员 + $userAuth['data_president'] = $myPromote_ids; + } + } + if (!empty($userAuth['data_president'])) {//查询有权限查看的会长以及底下的推广员 + $map = array(); + //查询会长底下的推广员(首个斜杆之间的数字) + $userAuth['data_president']= trim($userAuth['data_president'], ","); + $where['SUBSTRING_INDEX(SUBSTRING_INDEX(`chain`,"/",2),"/",-1)'] = array('exp',"IN({$userAuth['data_president']})"); + $where['id'] = array('in', $userAuth['data_president']);//会长本身 + $where['_logic'] = 'or'; + $map['_complex'] = $where; + $sqlResult = M('promote', 'tab_') + ->field('GROUP_CONCAT(id) as promote_ids') + ->where($map) + ->find(); + $promoteIds = $sqlResult['promote_ids']; + } + } + } +// var_dump(in_array('-1',explode(',',$userAuth['data_president'])));die(); + if (in_array('-1',explode(',',$userAuth['data_president']))) { + $promoteIds = $promoteIds .',0'; + } +// var_dump($promoteIds);die(); + session('user_auth_promote_ids', $promoteIds); + return $promoteIds; +} + +/** + * 为数据权限添加筛选参数 + * @param array $map 查询条件 + * @param string $column 字段名,默认为promote_id + * @return mixed + */ +function setPowerPromoteIds(&$map, $column = 'promote_id') { + //为数据权限添加 + $promoteIds = getPowerPromoteIds(); + if (empty($promoteIds)) { + $map[$column] = -1;//没权限时将promote_id置为-1 + } elseif ($promoteIds != 'all') { + if (isset($map[$column])) { + if (isset($map['_string'])) {//查询字段中已存在promote_id,不覆盖此条件而处理 + $map['_string'] .= " and $column in($promoteIds)"; + } else { + $map['_string'] = " $column in($promoteIds)"; + } + } else { + $map[$column] = array('in', $promoteIds); + } + } +} + +function get_promote_listOther($select='') { + +// $promoteRoot = getPowerPromoteIds(); +// if ($promoteRoot) { +// $map['id'] =array('in',$promoteRoot); +// } + + setPowerPromoteIds($map,'id'); + + $list = M("Promote","tab_")->field('id,account,balance_coin')->where($map)->select();//where("status=1")-> + if (empty($list)){return '';} + if($select==111){ + $new['id']=-1; + $new['account']="全站用户"; + array_unshift($list,$new); + } + return $list; +} + +/** + * 渠道列表 + * @param $type + * @return mixed + */ +function promote_listsOther($type){ + if($type){ + $map['level'] = $type; + } else{ + $map = ''; + } + +// $promoteRoot = getPowerPromoteIds(); +// if ($promoteRoot) { +// $map['id'] =array('in',$promoteRoot); +// } + + setPowerPromoteIds($map,'id'); + + $data = M('promote','tab_')->where($map)->select(); + + $items = M('PromoteBalanceCoin', 'tab_')->where(['game_id' => 0])->select(); + $records = []; + foreach ($items as $item) { + $records[$item['promote_id']] = $item['num']; + } + foreach ($data as $key => $item) { + $item['common_coin'] = isset($records[$item['id']]) ? $records[$item['id']] : $item['balance_coin']; + $data[$key] = $item; + } + + return $data; +} + +function get_admin_listOther() +{ + $nickname = session('user_auth')['username']; + $list= M("Member")->field('uid,nickname')->where("status=1 and nickname='{$nickname}'")->select(); + if(empty($list)){return false;} + return $list; +} + +/** + * 根据会长id底下的推广员id + * @param $promote_id + * @return mixed + */ +function getOffspringByPromoteId($promote_id = null) { + if (isset($promote_id)) { + if ($promote_id ==0) {//官方渠道 + $promote_ids = '0'; + } else { + $where['chain'] = ['like', "%/{$promote_id}/%"]; + $where['id'] = $promote_id;//会长本身 + $where['_logic'] = 'or'; + $map['_complex'] = $where; + $promote_ids = M('promote', 'tab_') + ->where($map) + ->field('group_concat(id) as promote_ids') + ->find(); + $promote_ids = $promote_ids['promote_ids']; + } + } else { + $promote_ids = getPowerPromoteIds(); + } + return $promote_ids; +} +/** + * csv 导出函数 + * @param [array] $data 一般为数据库查询结果集 + * @param [string] $title 表格名称 + * @param [array] $fields [字段=>首行名称,...]例如:['name'=>'名称'] + * @return void + */ +function data2csv(&$data,$title,$fields){ + set_time_limit(0); + ini_set('memory_limit', '-1'); //设置内存不受限制 + $csvFileName = $title.'.csv'; + //设置好告诉浏览器要下载excel文件的headers + header('Content-Description: File Transfer'); + header('Content-Type: application/vnd.ms-excel;charset=utf-8'); + header('Content-Disposition: attachment; filename="'. $csvFileName .'"'); + header('Expires: 0'); + header('Cache-Control: must-revalidate'); + header('Pragma: public'); + $fp = fopen('php://output', 'a');//打开output流 + fwrite($fp, chr(0xEF).chr(0xBB).chr(0xBF));//转码,防止乱码 + $field = array_keys($fields); + //生成首行 + $header = array_values($fields); + fputcsv($fp, $header); + + $index = 0; + foreach ($data as $row) { + $a = []; + foreach($field as $k=>$v){ + // $a[$v] = $row[$v] . "\t";//防止格式错误 + $a[$v] = $row[$v]; + } + if ($index == 10000) { //每次写入1000条数据清除内存 + $index = 0; + ob_flush();//清除内存 + flush(); + } + $index++; + fputcsv($fp, $a); + } + ob_flush(); + fclose($fp); //每生成一个文件关闭 + die(); +} + +//所有支付方式 +function all_pay_way_other($type=false) +{ + + if($type){ + $pay_way[0]=array('key'=>0,'value'=>"平台币"); + } + $pay_way[1]=array('key'=>-1,'value'=>"绑币"); + $pay_way[2]=array('key'=>1,'value'=>"支付宝"); + $pay_way[3]=array('key'=>2,'value'=>"微信"); + $pay_way[7]=array('key'=>7,'value'=>'苹果'); + $pay_way[9]=array('key'=>9,'value'=>"双乾支付-支付宝"); + $pay_way[10]=array('key'=>10,'value'=>"双乾支付-银联"); +// $pay_way[3]=array('key'=>3,'value'=>'微信APP'); +// $pay_way[4]=array('key'=>4,'value'=>'威富通'); + /* $pay_way[4]=array('key'=>5,'value'=>'聚宝云'); */ +// $pay_way[5]=array('key'=>6,'value'=>'汇付宝'); + /* $pay_way[6]=array('key'=>7,'value'=>"苹果支付"); + */ + $pay_way[15]=array('key'=>15,'value'=>'双乾支付-快捷'); + $pay_way[17]=array('key'=>17,'value'=>'易宝支付'); + return $pay_way; +} + +function getMonthOther() { + $start = date("Y-m", strtotime("now")); + //开始月份 + $range = []; + $i = 0; + do { + $month = date('Y-m', strtotime($start . ' - ' . $i . ' month')); + $range[] = $month; + $i++; + } while ($i<36); + + return $range; +} + +//获取当前管理员id +function getAdmin($column = 'uid') { + return session("user_auth")[$column]; +} + +//获取所有有关的公司 + +function getCompanyList() { + + $sql = "select id,company_name,1 as company_type from tab_promote_company UNION ALL select id,partner,0 as company_type from tab_partner"; + + $data = M()->table("({$sql}) as a")->select(); + + + return $data; + +} + +//上游cp对账单导出 +function excelUpStreamTemplate($data, $all_sum_money, $all_pay_amount, $big_all_sum_money) { + header("Content-type: text/html; charset=utf-8"); + error_reporting(E_ALL); + ini_set('display_errors', TRUE); + ini_set('display_startup_errors', TRUE); + + define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '
'); + + date_default_timezone_set('Europe/London'); + Vendor("PHPExcel.PHPExcel"); + $objReader = \PHPExcel_IOFactory::createReader('Excel5'); + + //设置模板文件 + $objPHPExcel = $objReader->load("Public/Admin/excel/up_stream.xls"); + + + //增加甲方信息 + $objPHPExcel->getActiveSheet()->setCellValue('D2', $data['first_party_info']['partner']); + $objPHPExcel->getActiveSheet()->setCellValue('D3', $data['first_party_info']['link_man']); + $objPHPExcel->getActiveSheet()->setCellValue('D4', $data['first_party_info']['link_phone']); + $objPHPExcel->getActiveSheet()->setCellValue('D5', $data['first_party_info']['address']); + $objPHPExcel->getActiveSheet()->setCellValue('D6', $data['first_party_info']['company_tax_no']); + + //增加乙方信息 + $objPHPExcel->getActiveSheet()->setCellValue('J2', $data['second_party_info']['partner']); + $objPHPExcel->getActiveSheet()->setCellValue('J3', $data['second_party_info']['link_man']); + $objPHPExcel->getActiveSheet()->setCellValue('J4', $data['second_party_info']['link_phone']); + $objPHPExcel->getActiveSheet()->setCellValue('J5', $data['second_party_info']['address']); + $objPHPExcel->getActiveSheet()->setCellValue('J6', $data['second_party_info']['company_tax_no']); + + $objPHPExcel->getActiveSheet()->setCellValue('C7', "支付给:".$data['receive_company']['partner']); //增加支付给对应公司 + $line = 10; + //记录统计项目 + $pay_amount_str = "="; + //增加结算记录 + foreach ($data['statement_info'] as $key => $value) { + $objPHPExcel->getActiveSheet()->insertNewRowBefore($line,1)->mergeCells("J$line:K$line"); + $objPHPExcel->getActiveSheet()->setCellValue('C'.$line, $value['statement_begin_time'] . '-' . $value['statement_end_time']); + if ($value['statement_type'] > 0) {//罚款 + $product_name = $value['game_name']; + $objPHPExcel->getActiveSheet()->setCellValue('F'.$line , '-'); + $objPHPExcel->getActiveSheet()->setCellValue('G'.$line, '-'); + $objPHPExcel->getActiveSheet()->setCellValue('H'.$line, '-'); + $objPHPExcel->getActiveSheet()->setCellValue('I'.$line, '-'); + if ($value['statement_type'] == 1) { + $objPHPExcel->getActiveSheet()->setCellValue('E'.$line, "-".$value['pay_amount']); + $objPHPExcel->getActiveSheet()->setCellValue('J'.$line, "-".$value['sum_money']); + }else{ + $objPHPExcel->getActiveSheet()->setCellValue('E'.$line, $value['pay_amount']); + $objPHPExcel->getActiveSheet()->setCellValue('J'.$line, $value['sum_money']); + } + } else {//游戏 + $product_name = $value['game_name']; + $objPHPExcel->getActiveSheet()->setCellValue('F'.$line , $value['first_ratio'] . '%'); + $objPHPExcel->getActiveSheet()->setCellValue('G'.$line, $value['second_ratio'] . '%'); + $objPHPExcel->getActiveSheet()->setCellValue('H'.$line, $value['promote_ratio'] . '%'); + $objPHPExcel->getActiveSheet()->setCellValue('I'.$line, $value['fax_ratio']. '%'); + $objPHPExcel->getActiveSheet()->setCellValue('E'.$line, $value['pay_amount']); + // $objPHPExcel->getActiveSheet()->setCellValue('J'.$line, $value['sum_money']); + if ($data['pay_type'] == 2) { + $objPHPExcel->getActiveSheet()->setCellValue('J'.$line, "=E{$line}*(1-H{$line})*G{$line}*(1-I{$line})"); + }else{ + $objPHPExcel->getActiveSheet()->setCellValue('J'.$line, "=E{$line}*(1-H{$line})*F{$line}*(1-I{$line})"); + } + } + $pay_amount_str .= "J{$line}+"; + $objPHPExcel->getActiveSheet()->setCellValue('D'.$line, $product_name); + + $line++; + } + + //合计 + $objPHPExcel->getActiveSheet()->setCellValue("E" . ($line), $data['pay_amount']); + // $objPHPExcel->getActiveSheet()->setCellValue("J" . ($line), $data['statement_money']); + $objPHPExcel->getActiveSheet()->setCellValue("J" . ($line), trim($pay_amount_str,"+")); + + // $objPHPExcel->getActiveSheet()->setCellValue("J" . ($line+1), $big_all_sum_money); //本月分成总金额(人民币大写) + $objPHPExcel->getActiveSheet()->setCellValue("J" . ($line+1), "=J{$line}"); //本月分成总金额(人民币大写) + + //收款方 + $objPHPExcel->getActiveSheet()->setCellValue("D" . ($line+2), $data['receive_company']['payee_name']); + $objPHPExcel->getActiveSheet()->setCellValue("D" . ($line+3), $data['receive_company']['bank_account']); + $objPHPExcel->getActiveSheet()->setCellValue("D" . ($line+4), $data['receive_company']['opening_bank']); + + //付款方 + $objPHPExcel->getActiveSheet()->setCellValue("J" . ($line+2), $data['pay_company']['payee_name']); + $objPHPExcel->getActiveSheet()->setCellValue("J" . ($line+3), $data['pay_company']['bank_account']); + $objPHPExcel->getActiveSheet()->setCellValue("J" . ($line+4), $data['pay_company']['opening_bank']); + + $statement_begin_time = date('Y.m.d', $data['statement_begin_time']);//对账开始时间 + $statement_end_time = date('Y.m.d',$data['statement_end_time']);//对账截止时间 + + $fileName = "{$data['second_party_info']['partner']}&{$data['first_party_info']['partner']}-对账单{$statement_begin_time}-{$statement_end_time}"; + + ob_end_clean();//清除缓冲区,避免乱码 + header('pragma:public'); + header('Content-type:application/vnd.ms-excel;charset=utf-8;name="' . $fileName .'".xls'); + header("Content-Disposition:attachment;filename={$fileName}.xls");//attachment新窗口打印inline本窗口打印 + $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); + $objWriter->save('php://output'); + exit; + +} + +//下游工会对账单导出 +function excelDownStreamTemplate($data, $all_sum_money, $all_pay_amount, $big_all_sum_money) { + + header("Content-type: text/html; charset=utf-8"); + error_reporting(E_ALL); + ini_set('display_errors', TRUE); + ini_set('display_startup_errors', TRUE); + + define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '
'); + + Vendor("PHPExcel.PHPExcel"); + $objPHPExcel = new \PHPExcel(); + $objReader = \PHPExcel_IOFactory::createReader('Excel5'); + + //设置模板文件 + $objPHPExcel = $objReader->load("Public/Admin/excel/down_stream.xls"); + + $statement_begin_time = date('Y.m.d', $data['statement_begin_time']);//对账开始时间 + $statement_end_time = date('Y.m.d',$data['statement_end_time']);//对账截止时间 + + $objPHPExcel->getActiveSheet()->setCellValue('A1', "《 {$data['company_name']} 》结算单\n({$statement_begin_time}-{$statement_end_time})"); + if ($data['withdraw_type'] == '2') { + $objPHPExcel->getActiveSheet()->setCellValue('D2','补点比例'); + } + + + $line = 3; + $pay_amount_str = "="; + foreach ($data['statement_info'] as $key => $value) { + $objPHPExcel->getActiveSheet()->insertNewRowBefore($line,1); + $objPHPExcel->getActiveSheet()->removeConditionalStyles(); + + $objPHPExcel->getActiveSheet()->setCellValue('A'.$line, $value['statement_begin_time'] . '-' . $value['statement_end_time']); + if ($value['statement_type'] > 0) {//罚款 + $product_name = $value['game_name']; + $objPHPExcel->getActiveSheet()->setCellValue('D'.$line, '-'); + $objPHPExcel->getActiveSheet()->setCellValue('E'.$line, '-'); + if ($value['statement_type'] == 1) { + $objPHPExcel->getActiveSheet()->setCellValue('C'.$line, "-".$value['pay_amount']); + $objPHPExcel->getActiveSheet()->setCellValue('F'.$line, "-".$value['sum_money']); + }else{ + $objPHPExcel->getActiveSheet()->setCellValue('C'.$line, $value['pay_amount']); + $objPHPExcel->getActiveSheet()->setCellValue('F'.$line, $value['sum_money']); + } + } else {//游戏 + $product_name = $value['game_name']; + if ($data['withdraw_type'] == 2) { + $objPHPExcel->getActiveSheet()->setCellValue('D'.$line, $value['increment_ratio'] . '%'); + }else{ + $objPHPExcel->getActiveSheet()->setCellValue('D'.$line, $value['ratio'] . '%'); + } + $objPHPExcel->getActiveSheet()->setCellValue('E'.$line, $value['fax_ratio'] . '%'); + $objPHPExcel->getActiveSheet()->setCellValue('C'.$line, $value['pay_amount']); + // $objPHPExcel->getActiveSheet()->setCellValue('F'.$line, $value['sum_money']); + $objPHPExcel->getActiveSheet()->setCellValue('F'.$line,"=C{$line}*D{$line}*(1-E{$line})"); + } + $objPHPExcel->getActiveSheet()->setCellValue('B'.$line, $product_name); + $pay_amount_str .= "F{$line}+"; + $line++; + } + + $objPHPExcel->getActiveSheet()->setCellValue('C'.($line), $data['pay_amount']);//合计-平台总额 + $objPHPExcel->getActiveSheet()->setCellValue('F'.($line), trim($pay_amount_str,"+"));//合计-结算金额 + + + // $objPHPExcel->getActiveSheet()->setCellValue('B'.($line+1), $big_all_sum_money);//大写支付结算金额 + $objPHPExcel->getActiveSheet()->setCellValue('B'.($line+1), "=F{$line}");//大写支付结算金额 + //甲方信息 + $objPHPExcel->getActiveSheet()->setCellValue('B'.($line+3), $data['pay_company']['partner']);//甲方 + $objPHPExcel->getActiveSheet()->setCellValue('B'.($line+4), $data['pay_company']['link_man']);//联系人 + $objPHPExcel->getActiveSheet()->setCellValue('B'.($line+5), $data['pay_company']['link_phone']);//联系电话 + $objPHPExcel->getActiveSheet()->setCellValue('B'.($line+6), $data['receive_company']['invoice_content']);//开票项目 + $objPHPExcel->getActiveSheet()->setCellValue('B'.($line+7), $data['receive_company']['invoice_type']);//发票类型 + + //乙方信息 + $objPHPExcel->getActiveSheet()->setCellValue('E'.($line+3), $data['receive_company']['partner']);//乙方 + $objPHPExcel->getActiveSheet()->setCellValue('E'.($line+4), $data['receive_company']['link_man']);//联系人 + $objPHPExcel->getActiveSheet()->setCellValue('E'.($line+5), $data['receive_company']['link_phone']);//联系电话 + $objPHPExcel->getActiveSheet()->setCellValue('E'.($line+6), $data['receive_company']['address']);//邮寄地址 +// $objPHPExcel->getActiveSheet()->setCellValue('E'.($line+8), $value['pay_amount']);//请汇入此账号 + $objPHPExcel->getActiveSheet()->setCellValue('E'.($line+8), $data['receive_company']['bank_account_name']);//户名 + $objPHPExcel->getActiveSheet()->setCellValue('E'.($line+9), $data['receive_company']['bank_account']);//银行账号 + $objPHPExcel->getActiveSheet()->setCellValue('E'.($line+10), $data['receive_company']['opening_bank']);//开户行 + + $fileName = "{$data['second_party_info']['partner']}&{$data['first_party_info']['partner']}-对账单{$statement_begin_time}-{$statement_end_time}"; +// dd($fileName); + ob_end_clean();//清除缓冲区,避免乱码 + header('pragma:public'); + header('Content-type:application/vnd.ms-excel;charset=utf-8;name="' . $fileName .'".xls'); + header("Content-Disposition:attachment;filename={$fileName}.xls");//attachment新窗口打印inline本窗口打印 + $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); + $objWriter->save('php://output'); + exit; + +} + +function getWithdrawNumber() { + + $map = []; + + $map['ext_field'] = ['neq',null]; + + $data = M('withdraw',"tab_") + ->field("widthdraw_number") + ->join('left join tab_promote_belong on tab_withdraw.promote_id=tab_promote_belong.promote_id') + ->join("left join tab_statement as statement on tab_withdraw.widthdraw_number = statement.ext_field") + ->where("ext_field is null and tab_promote_belong.company_type!=2") + ->select(); + + return $data; + +} +//上有流水计算 +function caculateUpstream($game_id,$pay_amount) { + + $ladderData = M('cp_game_ratio','tab_') + ->where(['game_id'=>$game_id,'begin_total_amount'=>['elt',$pay_amount],'is_del'=>0]) + ->limit(0,2) + ->order('begin_total_amount desc') + ->select(); + + foreach($ladderData as $key => $value) { + + if ($value['instanceof'] == 1 && $value['begin_total_amount'] <= $pay_amount + || $value['instanceof'] == 2 && $value['begin_total_amount'] != $pay_amount ) { + $data['ratio'] = $value['ratio']; + break; + } else { + $data['ratio'] = $value['ratio']; + } + + } + + return number_format($pay_amount*($data['ratio']/100),2,'.',''); + +} + +//获取所有有关的公司 + +function getPromoteCompanyList() { + + $sql = "select id,company_name,1 as company_type from tab_promote_company"; + + $data = M()->table("({$sql}) as a")->select(); + + + return $data; + +} +//获取游戏cp分成比例 $type=false时返回最低分成比例 +function getGameCpRadio($game_id,$amount,$type) { + if (!$type) { + $data = M('cp_game_ratio','tab_')->where(['game_id'=>$game_id])->order('begin_total_amount asc')->find(); + } else { + //取两条 + $ladderData = M('cp_game_ratio','tab_')->where(['game_id'=>$game_id,'begin_total_amount'=>['elt',$amount]])->limit(0,2)->order('begin_total_amount desc')->select(); + +// dump($ladderData);die(); + + foreach($ladderData as $key => $value) { + + if ($value['instanceof'] == 1 && $value['begin_total_amount'] <= $amount + || $value['instanceof'] == 2 && $value['begin_total_amount'] != $amount ) { + $data['ratio'] = $value['ratio']; + break; + } else { + $data['ratio'] = $value['ratio']; + } + + } + + } + + return $data['ratio']?$data['ratio']:0; + +} +/** + * 获取渠道分成比例 + * @author chenzhi + * @param [type] $company_id 公司id + * @param [type] $relation_game_id 游戏广联id + * @param [type] $endtime 结算结束的时间戳 + * @param [type] $amount 金额 + * @param [type] $type $type=false时返回最低分成比例 + * @param [type] $company_belong 公司团体类型,不传的话用id查询 + * @return ratio + */ +function getGamePromoteCompanyRadio($company_id,$relation_game_id,$endtime,$amount,$type,$company_belong=false) { + //判断是否有生效 + $rwhere = "(end_time = 0 OR end_time >= '{$endtime}') and company_id='{$company_id}' and relation_game_id='{$relation_game_id}'"; + $cgr_res = M("CompanyGameRatio","tab_")->where($rwhere)->find(); + if(empty($cgr_res)){ + //模板搜索 + //获取公司类型 + if($company_belong === false){ + $company_belong = M("PromoteCompany","tab_")->field("company_belong")->where("id='{$company_id}'")->find()['company_belong']; + } + $mwhere = "company_belong='{$company_belong}' and relation_game_id='{$relation_game_id}'"; + $m_res = M("GameRatioMould","tab_")->where($mwhere)->find(); + if(empty($m_res)){ + $default_r = 0; + $turnover_ratio = false; + }else{ + $default_r = $m_res['ratio']; + $turnover_ratio = json_decode($m_res['turnover_ratio'],true); + } + }else{ + $default_r = $cgr_res['ratio']; + $turnover_ratio = json_decode($cgr_res['turnover_ratio'],true); + } + //执行比例 + if (!$type || !$turnover_ratio) { + return $default_r; + } + //获取比例 + $ratio = $default_r; + foreach($turnover_ratio as $k=>$v){ + if($v['instanceof'] == 1){ + if($amount >= $v['turnover']){ + $ratio = $v['ratio']; + } + }else{ + if($amount > $v['turnover']){ + $ratio = $v['ratio']; + } + } + } + return $ratio; +} + +function check_str($str, $substr) +{ + $nums=substr_count($str,$substr); + + return $nums; +} + +function getPromoteGameRatio($promoteID = 0, $relationGameId = 0, $amount=0, $timeStart=0, $timeEnd=0, $isDefault = false) +{ + $map = " promote_id = {$promoteID} and relation_game_id = {$relationGameId} and status = 1 and begin_time <= {$timeStart} "; + if ($timeEnd) { + $map .= " and (end_time = 0 or end_time >= {$timeEnd}) "; + } + $result = M('promote_game_ratio_log', 'tab_')->where($map)->order('id desc')->find(); + if (!$result) return 0; + $ratios = array_reverse(json_decode($result['turnover_ratio'], true)); + if (!$ratios) return 0; + if ($isDefault) { + return $result['ratio'] ?: 0; + } + $ratio = $result['ratio']; + foreach ($ratios as $item) { + if (($item['instanceof'] == 1 && $amount >= $item['turnover']) || ($item['instanceof'] == 2 && $amount > $item['turnover'])) { + $ratio = $item['ratio']; + break; + } + } + return $ratio; +} +//验证账号 +function checkAccount($type,$account) { + +// $type = I('type'); +// $account = I('account'); + + $map = []; + $map['account'] = $account; + + if ($type == 1) { + + $result = M('promote','tab_')->field('account')->where($map)->find(); + + } else { + $result = M('user','tab_')->field('account')->where($map)->find(); + } + + if ($result) { + return 1; + } else { + return 0; + } + + } +//去重函数 +function a_array_unique($array){ + $out = array(); + + foreach ($array as $key=>$value) { + if (!in_array($value, $out)){ + $out[$key] = $value; + } + } + + $out = array_values($out); + return $out; + } + + /** + * 获取团体归属类型 + * @author chenzhi 20200219 + * $id 不传返回所有类型列表 + * 传入ID 返回对应的团体类型 + */ + function getCompanyBlong($id = -1) + { + $data = array( + ["id"=>0,'name'=>"内团"], + ["id"=>1,'name'=>"外团"], + ["id"=>2,'name'=>"外团-分发"], + ["id"=>3,'name'=>"无"] + ); + if($id > -1){ + foreach($data as $k=>$v){ + if($v['id'] == $id){ + return $v['name']; + break; + } + } + }else{ + return $data; + } + } + /** + * 获取公会归属关系 + * @author chenzhi 20200219 + * $id 不传返回所有关系列表 + * 传入ID 返回对应的团体关系 + */ + function getCompanyRelation($id = -1) + { + $data = array( + ["id"=>0,'name'=>"自主开发及维护"], + ["id"=>1,'name'=>"只维护"], + ["id"=>2,'name'=>"无"] + ); + if($id > -1){ + foreach($data as $k=>$v){ + if($v['id'] == $id){ + return $v['name']; + break; + } + } + }else{ + return $data; + } + } + /** + * 获取公会等级对应名称 + * @author chenzhi 20200219 + * $id 不传返回所有等级名称 + * 传入ID 返回对应的等级名称 + */ + function getPromoteLeverName($id = -1) + { + $data = array( + ["id"=>1,'name'=>"会长"], + ["id"=>2,'name'=>"部门长"], + ["id"=>3,'name'=>"组长"], + ["id"=>4,'name'=>"组员"], + ); + if($id > -1){ + foreach($data as $k=>$v){ + if($v['id'] == $id){ + return $v['name']; + break; + } + } + }else{ + return $data; + } + } + +/** + * 操作日志 + * array( + * op_type=>操作类型 0:新增,1:编辑 2:删除 3:下载, + * op_name=>操作说明 例如:编辑,删除,锁定等, + * url=>需要跳转的url 添加去列表加唯一id,编辑直接去编辑页面,下载可以重新下载(新开页面), + * key=>关键词:用户的账号,游戏的名词等, + * menu=>非必须,菜单目录,不存在的话按控制器寻找。 + * ) + */ +function addOperationLog($options) +{ + $checkarr = ['op_type','url','key']; + foreach ($checkarr as $v) { + if(!array_key_exists($v,$options)){ + return false; + } + } + if(!array_key_exists("op_name",$options)){ + $options['op_name'] = ($options['op_type'] == 1 ? "编辑" : ($options['op_type'] == 2 ? "删除" :($options['op_type'] == 3 ? "导出" :"新增"))); + } + //获取ip + $addarray = [ + "op_ip"=>$_SERVER['REMOTE_ADDR'], + 'admin_id'=>$_SESSION['onethink_admin']['user_auth']['uid'], + 'admin_account'=>$_SESSION['onethink_admin']['user_auth']['username'], + 'op_type'=>$options['op_type'], + 'op_name'=>$options['op_name'], + 'url'=>$options['url'], + 'key'=>$options['key'], + 'create_time'=>time() + ]; + //获取菜单名称 + if(!array_key_exists("menu",$options)){ + $act = CONTROLLER_NAME.'/'.ACTION_NAME; + $arr = []; + $menuname = D("menu")->field('title,pid,group')->where("url = '{$act}'")->find(); + if($menuname){ + $arr[] = $menuname['title']; + if(!empty($menuname['group'])){ + $arr[] = $menuname['group']; + } + getLink($menuname['pid'],$arr); + } + $addarray['menu'] = implode ( "-",array_reverse($arr)); + }else{ + $addarray['menu'] = $options['menu']; + } + + + M("OperationLog","tab_")->add($addarray); +} + +function getLink($pid=0,&$arr){ + if($pid == 0){ + return; + } + $menuname = D("menu")->field('title,pid,group')->where("id = '{$pid}'")->find(); + if($menuname){ + $arr[] = $menuname['title']; + if(!empty($menuname['group'])){ + $arr[] = $menuname['group']; + } + if($menuname['pid'] != 0){ + getLink($menuname['pid'], $arr); + + } + } + +} + +function getNowDate() { + + return date('YmdHis',time()); + +} + +//根据推广员id获取推广员姓名 +function getPromoteName($id) { + + if (!$id) { + return ''; + } + + $name = M('promote','tab_') + ->where(['id'=>$id]) + ->find()['account']; + + return $name; + +} + +//根据关联id获取游戏名称 +function getrelationGameName($id) { + + if (!$id) { + return ''; + } + + $name = M('game','tab_') + ->where(['relation_game_id'=>$id]) + ->find()['relation_game_name']; + + return $name; + +} + +/** + * 获取测试资源可用余额 + * promote_id=>推广员id, + * game_id=>游戏id, + */ + +function getAvailableBalance($promote_id=0,$game_id=0,$server_id='') { + + if (!$promote_id||!$game_id||!$server_id) { + return 0; + } + + $availableBalanceData = M('promote_game_available_balance','tab_') + ->field('available_balance') + ->where(['promote_id'=>$promote_id,'game_id'=>$game_id,'server_name'=>$server_id]) + ->find(); + + return $availableBalanceData['available_balance']?$availableBalanceData['available_balance']:0; + +} + + +?> diff --git a/Application/Payment/Common/function.php b/Application/Payment/Common/function.php new file mode 100644 index 000000000..408114613 --- /dev/null +++ b/Application/Payment/Common/function.php @@ -0,0 +1,988 @@ + +// +---------------------------------------------------------------------- + +/** + * 后台公共文件 + * 主要定义后台公共函数库 + */ + +/* 解析列表定义规则*/ + +function get_list_field($data, $grid) +{ + // 获取当前字段数据 + foreach ($grid['field'] as $field) { + $array = explode('|', $field); + $temp = $data[$array[0]]; + $twotemp = $data[$array[2]];//新加 + // 函数支持 + if (isset($array[1])) { + if (isset($twotemp)) {//新加 + $param = explode('*', $array[1]); + $temp = isset($param[1]) ? call_user_func($param[0], $temp, $param[1]) : call_user_func($array[1], $twotemp, $temp); + } else { + $param = explode('*', $array[1]); + $temp = isset($param[1]) ? call_user_func($param[0], $temp, $param[1]) : call_user_func($array[1], $temp); + } + } + $data2[$array[0]] = $temp; + } + if (!empty($grid['format'])) { + $value = preg_replace_callback('/\[([a-z_]+)\]/', function ($match) use ($data2) { + return $data2[$match[1]]; + }, $grid['format']); + } else { + $value = implode(' ', $data2); + } + + // 链接支持 + if ('title' == $grid['field'][0] && '目录' == $data['type']) { + // 目录类型自动设置子文档列表链接 + $grid['href'] = '[LIST]'; + } + if (!empty($grid['href'])) { + $links = explode(',', $grid['href']); + foreach ($links as $link) { + $array = explode('|', $link); + $href = $array[0]; + if (preg_match('/^\[([a-z_]+)\]$/', $href, $matches)) { + $val[] = $data2[$matches[1]]; + } else { + $show = isset($array[1]) ? $array[1] : $value; + // 替换系统特殊字符串 + $href = str_replace( + array('[DELETE]', '[EDIT]', '[LIST]'), + array('setstatus?status=-1&ids=[id]', + 'edit?id=[id]&model=[model_id]&cate_id=[category_id]', + 'index?pid=[id]&model=[model_id]&cate_id=[category_id]'), + $href); + + // 替换数据变量 + $href = preg_replace_callback('/\[([a-z_]+)\]/', function ($match) use ($data) { + return $data[$match[1]]; + }, $href); + switch ($show) { + case '删除': + $val[] = '' . $show . ''; + break; + default: + $val[] = '' . $show . ''; + break; + } + + } + } + $value = implode(' ', $val); + } + return $value; +} + +/** + * [every_day 获取日期] + * @param integer $m [description] + * @return [type] [array] + */ +function every_day($m = 7) +{ + $time = array(); + for ($i = $m - 1; $i >= 0; $i--) { + $time[] = date('Y-m-d', mktime(0, 0, 0, date('m'), date('d') - $i, date('Y'))); + } + return $time; +} + +// 两个日期之间的所有日期 +function prDates($start, $end) +{ + $dt_start = strtotime($start); + $dt_end = strtotime($end); + while ($dt_start <= $dt_end) { + $tt[] = date('Y-m-d', $dt_start); + $dt_start = strtotime('+1 day', $dt_start); + } + return $tt; +} + +/* 解析插件数据列表定义规则*/ + +function get_addonlist_field($data, $grid, $addon) +{ + // 获取当前字段数据 + foreach ($grid['field'] as $field) { + $array = explode('|', $field); + $temp = $data[$array[0]]; + // 函数支持 + if (isset($array[1])) { + $temp = call_user_func($array[1], $temp); + } + $data2[$array[0]] = $temp; + } + if (!empty($grid['format'])) { + $value = preg_replace_callback('/\[([a-z_]+)\]/', function ($match) use ($data2) { + return $data2[$match[1]]; + }, $grid['format']); + } else { + $value = implode(' ', $data2); + } + + // 链接支持 + if (!empty($grid['href'])) { + $links = explode(',', $grid['href']); + foreach ($links as $link) { + $array = explode('|', $link); + $href = $array[0]; + if (preg_match('/^\[([a-z_]+)\]$/', $href, $matches)) { + $val[] = $data2[$matches[1]]; + } else { + $show = isset($array[1]) ? $array[1] : $value; + // 替换系统特殊字符串 + $href = str_replace( + array('[DELETE]', '[EDIT]', '[ADDON]'), + array('del?ids=[id]&name=[ADDON]', 'edit?id=[id]&name=[ADDON]', $addon), + $href); + + // 替换数据变量 + $href = preg_replace_callback('/\[([a-z_]+)\]/', function ($match) use ($data) { + return $data[$match[1]]; + }, $href); + + $val[] = '' . $show . ''; + } + } + $value = implode(' ', $val); + } + return $value; +} + +// 获取模型名称 +function get_model_by_id($id) +{ + return $model = M('Model')->getFieldById($id, 'title'); +} + +// 获取属性类型信息 +function get_attribute_type($type = '') +{ + // TODO 可以加入系统配置 + static $_type = array( + 'num' => array('数字', 'int(10) UNSIGNED NOT NULL'), + 'string' => array('字符串', 'varchar(255) NOT NULL'), + 'textarea' => array('文本框', 'text NOT NULL'), + 'date' => array('日期', 'int(10) NOT NULL'), + 'datetime' => array('时间', 'int(10) NOT NULL'), + 'bool' => array('布尔', 'tinyint(2) NOT NULL'), + 'select' => array('枚举', 'char(50) NOT NULL'), + 'radio' => array('单选', 'char(10) NOT NULL'), + 'checkbox' => array('多选', 'varchar(100) NOT NULL'), + 'editor' => array('编辑器', 'text NOT NULL'), + 'picture' => array('上传图片', 'int(10) UNSIGNED NOT NULL'), + 'file' => array('上传附件', 'int(10) UNSIGNED NOT NULL'), + ); + return $type ? $_type[$type][0] : $_type; +} + +/** + * 获取对应状态的文字信息 + * @param int $status + * @return string 状态文字 ,false 未获取到 + * @author huajie + */ +function get_status_title($status = null) +{ + if (!isset($status)) { + return false; + } + switch ($status) { + case -1 : + return "已删除"; + break; + case 0 : + return "禁用"; + break; + case 1 : + return "正常"; + break; + case 2 : + return "待审核"; + break; + default : + return false; + break; + } +} + +// 获取数据的状态操作 +function show_status_op($status) +{ + switch ($status) { + case 0 : + return "正常"; + break; + case 1 : + return "禁用"; + break; + case 2 : + return "待审核"; + break; + default : + return false; + break; + } +} + +/** + * 获取文档的类型文字 + * @param string $type + * @return string 状态文字 ,false 未获取到 + * @author huajie + */ +function get_document_type($type = null) +{ + if (!isset($type)) { + return false; + } + switch ($type) { + case 1 : + return '目录'; + break; + case 2 : + return '主题'; + break; + case 3 : + return '段落'; + break; + default : + return false; + break; + } +} + +/** + * 获取配置的类型 + * @param string $type 配置类型 + * @return string + */ +function get_config_type($type = 0) +{ + $list = C('CONFIG_TYPE_LIST'); + return $list[$type]; +} + +/** + * 获取配置的分组 + * @param string $group 配置分组 + * @return string + */ +function get_config_group($group = 0) +{ + $list = C('CONFIG_GROUP_LIST'); + return $group ? $list[$group] : ''; +} + +/** + * select返回的数组进行整数映射转换 + * + * @param array $map 映射关系二维数组 array( + * '字段名1'=>array(映射关系数组), + * '字段名2'=>array(映射关系数组), + * ...... + * ) + * @return array + * + * array( + * array('id'=>1,'title'=>'标题','status'=>'1','status_text'=>'正常') + * .... + * ) + * + * @author 朱亚杰 + */ +function int_to_string(&$data, $map = array('status' => array(1 => '正常', -1 => '删除', 0 => '锁定', 2 => '未审核', 3 => '草稿'))) +{ + if ($data === false || $data === null) { + return $data; + } + $data = (array)$data; + foreach ($data as $key => $row) { + foreach ($map as $col => $pair) { + if (isset($row[$col]) && isset($pair[$row[$col]])) { + $data[$key][$col . '_text'] = $pair[$row[$col]]; + } + } + } + return $data; +} + +/** + * 动态扩展左侧菜单,base.html里用到 + * @author 朱亚杰 + */ +function extra_menu($extra_menu, &$base_menu) +{ + foreach ($extra_menu as $key => $group) { + if (isset($base_menu['child'][$key])) { + $base_menu['child'][$key] = array_merge($base_menu['child'][$key], $group); + } else { + $base_menu['child'][$key] = $group; + } + } +} + +/** + * 获取参数的所有父级分类 + * @param int $cid 分类id + * @return array 参数分类和父类的信息集合 + * @author huajie + */ +function get_parent_category($cid) +{ + if (empty($cid)) { + return false; + } + $cates = M('Category')->where(array('status' => 1))->field('id,title,pid')->order('sort')->select(); + $child = get_category($cid); //获取参数分类的信息 + $pid = $child['pid']; + $temp = array(); + $res[] = $child; + while (true) { + foreach ($cates as $key => $cate) { + if ($cate['id'] == $pid) { + $pid = $cate['pid']; + array_unshift($res, $cate); //将父分类插入到数组第一个元素前 + } + } + if ($pid == 0) { + break; + } + } + return $res; +} + +/** + * 检测验证码 + * @param integer $id 验证码ID + * @return boolean 检测结果 + * @author 麦当苗儿 + */ +function check_verify($code, $id = 1) +{ + $verify = new \Think\Verify(); + return $verify->check($code, $id); +} + +/** + * 获取当前分类的文档类型 + * @param int $id + * @return array 文档类型数组 + * @author huajie + */ +function get_type_bycate($id = null) +{ + if (empty($id)) { + return false; + } + $type_list = C('DOCUMENT_MODEL_TYPE'); + $model_type = M('Category')->getFieldById($id, 'type'); + $model_type = explode(',', $model_type); + foreach ($type_list as $key => $value) { + if (!in_array($key, $model_type)) { + unset($type_list[$key]); + } + } + return $type_list; +} + +/** + * 获取当前文档的分类 + * @param int $id + * @return array 文档类型数组 + * @author huajie + */ +function get_cate($cate_id = null) +{ + if (empty($cate_id)) { + return false; + } + $cate = M('Category')->where('id=' . $cate_id)->getField('title'); + return $cate; +} + +// 分析枚举类型配置值 格式 a:名称1,b:名称2 +function parse_config_attr($string) +{ + $array = preg_split('/[,;\r\n]+/', trim($string, ",;\r\n")); + if (strpos($string, ':')) { + $value = array(); + foreach ($array as $val) { + list($k, $v) = explode(':', $val); + $value[$k] = $v; + } + } else { + $value = $array; + } + return $value; +} + +// 获取子文档数目 +function get_subdocument_count($id = 0) +{ + return M('Document')->where('pid=' . $id)->count(); +} + + +// 分析枚举类型字段值 格式 a:名称1,b:名称2 +// 暂时和 parse_config_attr功能相同 +// 但请不要互相使用,后期会调整 +function parse_field_attr($string) +{ + if (0 === strpos($string, ':')) { + // 采用函数定义 + return eval('return ' . substr($string, 1) . ';'); + } elseif (0 === strpos($string, '[')) { + // 支持读取配置参数(必须是数组类型) + return C(substr($string, 1, -1)); + } + + $array = preg_split('/[,;\r\n]+/', trim($string, ",;\r\n")); + if (strpos($string, ':')) { + $value = array(); + foreach ($array as $val) { + list($k, $v) = explode(':', $val); + $value[$k] = $v; + } + } else { + $value = $array; + } + return $value; +} + +/** + * 获取行为数据 + * @param string $id 行为id + * @param string $field 需要获取的字段 + * @author huajie + */ +function get_action($id = null, $field = null) +{ + if (empty($id) && !is_numeric($id)) { + return false; + } + $list = S('action_list'); + if (empty($list[$id])) { + $map = array('status' => array('gt', -1), 'id' => $id); + $list[$id] = M('Action')->where($map)->field(true)->find(); + } + return empty($field) ? $list[$id] : $list[$id][$field]; +} + +/** + * 根据条件字段获取数据 + * @param mixed $value 条件,可用常量或者数组 + * @param string $condition 条件字段 + * @param string $field 需要返回的字段,不传则返回整个数据 + * @author huajie + */ +function get_document_field($value = null, $condition = 'id', $field = null) +{ + if (empty($value)) { + return false; + } + + //拼接参数 + $map[$condition] = $value; + $info = M('Model')->where($map); + if (empty($field)) { + $info = $info->field(true)->find(); + } else { + $info = $info->getField($field); + } + return $info; +} + +/** + * 获取行为类型 + * @param intger $type 类型 + * @param bool $all 是否返回全部类型 + * @author huajie + */ +function get_action_type($type, $all = false) +{ + $list = array( + 1 => '系统', + 2 => '用户', + ); + if ($all) { + return $list; + } + return $list[$type]; +} + +//获取服务器类型 +function getServerType($serverType) +{ + return (($serverType == 1) ? '专服' : '混服'); +} + +//获取合作方 +function getPartnerList($id = 0) +{ + if ($id > 0) { + return M('Partner', 'tab_')->field('id,partner')->find($id); + } else { + return M('Partner', 'tab_')->field('id,partner')->where(array('status' => 1))->select(); + } +} + +function getPartnerName($id = 0) +{ + return M('Partner', 'tab_')->where(array('id' => intval($id)))->getField('partner'); +} + +function getGameByName($game_name=null, $sdk_version=null) +{ + $map = []; + if ($game_name) { + $map['relation_game_name'] = $game_name; + } + if ($sdk_version) { + $map['sdk_version'] = $sdk_version; + } + $result = D("Game")->field('id')->where($map)->select(); + if(empty($result)) { + return [['id' => -1]]; + }else + { + return $result; + } +} +//根据游戏公司,游戏名称,游戏类型 +function getGameidByPartnerNameType($partner_id=null,$game_name=null, $sdk_version=null) +{ + $map = []; + if($partner_id){ + $map['partner_id'] = $partner_id; + } + if ($game_name) { + $map['relation_game_name'] = $game_name; + } + if ($sdk_version) { + $map['sdk_version'] = $sdk_version; + } + $result = D("Game")->field('id')->where($map)->select(); + if(empty($result)) { + return [['id' => -1]]; + }else + { + return $result; + } +} + +function getTopPromote($promote_id) +{ + $promoter = M('promote', 'tab_')->where(['id' => $promote_id])->find(); + if (!$promoter) { + return []; + } + $chain = trim($promoter['chain'], '/'); + if ($chain == '') { + return $promoter; + } else { + $topPromoteId = explode('/', $chain)[0]; + return M('promote', 'tab_')->where(['id' => $topPromoteId])->find(); + } +} + +function arrayPromoteWithdrawStatus($status, $param, $array = array()) { + foreach ($array as $key => $value) { + if($value[$status] == -1){ + unset($array[$key]); + } + } + return $array; +} + +function getAllGame() +{ + $list = M("game", 'tab_')->field('relation_game_name as game_name')->group('relation_game_name')->select(); + return $list; +} +/** + * 获取合作公司 + * @author chenzhi + */ +function getPromoteCompany() +{ + $list = M("PromoteCompany", 'tab_') + ->field('id,company_name') + ->where("status = 1") + ->select(); + array_unshift($list,array("id"=>0,"company_name"=>C(DEFAULT_COMPANY)));//默认0 + return $list; +} + +function getAllIosGame() +{ + $list = M("game", 'tab_')->field('relation_game_name as game_name,id')->where(['sdk_version' => 2])->group('relation_game_name')->select(); + return $list; +} + +/** + * 中间加密 替换字符串的子串 + */ +function encryptStr($str) { + $length = strlen($str); + $stars_str = ""; + for ($x=0; $x<=$length-6; $x++) { + $stars_str = $stars_str."*"; + } + return substr_replace($str, $stars_str, 3, $length-6); +} + +/** + * 身份证加密 + * + * @param $str + * @return mixed + */ +function encryptIdCard($str) { + $length = strlen($str); + $stars_str = ""; + if($length>=4){ + $stars_str = "****"; + } + return substr_replace($str, $stars_str, $length-4, 4); +} + +/** + * 真实名字加密 + * + * @param $str + * @return mixed + */ +function encryptRealName($str) { + $length = strlen($str); + $stars_str = ""; + if($length>=4){ + $stars_str = "****"; + } + return substr_replace($str, "**", 3, $length); +} + +//获取推广员资质审核状态 $type 1-获取数组 2-获取文本 +function getPromoteVerStatus($status, $type = 1) +{ + $statusList = [ + 0 => '未认证', + 1 => '审核成功', + 2 => '审核失败', + 3 => '审核中', + 4 => '修改审核中', + ]; + + $records = null; + switch ($type) { + case 1: + $records = $status; + break; + case 2: + $records = $statusList[$status] ?? '未知'; + break; + default: + $records = false; + break; + } + return $records; +} + +//获取推广员账号 +function getPromoteAccount($promoteId) +{ + $map['id'] = intval($promoteId); + return M('promote', 'tab_')->where($map)->getField('account'); +} + +//获取推广员列表 $level 0-全部 $companyId 推广公司 0-全部 +function getPromoteByLevel($level = 0, $companyId = 0) +{ + $field = 'id, account, real_name'; + $map['_string'] = '1 = 1'; + if ($level > 0) { + $map['level'] = $level; + } + if ($companyId > 0) { + $map['company_id'] = $companyId; + } + + $promotes = M('promote', 'tab_')->field($field)->where($map)->select(); + + return $promotes; +} + +//获取游戏列表 +function getAllGameList($groupByRelation = false) +{ + $field = 'id, game_name, relation_game_id, relation_game_name'; + if ($groupByRelation) { + $games = M('game', 'tab_')->field($field)->where('id = relation_game_id')->group('relation_game_id')->select(); + } else { + $games = M('game', 'tab_')->field($field)->select(); + } + return $games; +} + +//获取管理员权限列表 +function getAdminRules($adminId) +{ + $rules = []; + if ($adminId) { + $groupId = M('auth_group_access')->where(array('uid' => intval($adminId)))->getField('group_id'); + if ($groupId) { + $rules = M('auth_group')->where(array('id' => $groupId))->getField('rules'); + $rules = explode(',', $rules); + } + } + return $rules; +} + +//获取权限id +function getRule($name, $module) +{ + $ruleId = 0; + if ($name) { + if ($module) { + $map['module'] = $module; + } + $map['name'] = trim($name); + $ruleId = M('auth_rule')->where($map)->getField('id'); + } + return $ruleId; +} + +//下划线转驼峰 $littleHump 是否转换成小驼峰 +function camelize($str, $separator = '_', $littleHump = false) +{ + if ($littleHump) { + $str = $separator . str_replace($separator, " ", strtolower($str)); + } else { + $str = str_replace($separator, " ", strtolower($str)); + } + + return ltrim(str_replace(" ", "", ucwords($str)), $separator ); +} + +//驼峰转下划线 +function unCamelize($str, $separator = '_') +{ + return strtolower(preg_replace('/([a-z])([A-Z])/', "$1" . $separator . "$2", $str)); +} + +function convertAmountToCn($num) { + //判断$num是否存在 + if(!$num) return '零圆'; + if($num-0+1 == 1){ + return '零圆'; + } + //保留小数点后两位 + $num = round($num, 2); + //将浮点转换为整数 + $tem_num = $num * 100; + //判断数字长度 + $tem_num_len = strlen($tem_num); + if($tem_num_len > 14) { + return '数值过大'; + } + + //大写数字 + $dint = array('零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'); + //大写金额单位 + $danwei = array('仟', '佰', '拾', '亿', '仟', '佰', '拾', '万', '仟', '佰', '拾', '圆'); + $danwei1 = array('角', '分'); + + //空的变量用来保存转换字符串 + $daxie = ''; + if($num < 0){ + $daxie .= "负"; + } + + //分割数字,区分圆角分 + list($left_num, $right_num) = explode('.', $num); + + //计算单位长度 + $danwei_len = count($danwei); + //计算分割后的字符串长度 + $left_num_len = strlen($left_num); + $right_num_len = strlen($right_num); + + //循环计算亿万元等 + for($i = 0; $i < $left_num_len; $i++) { + //循环单个文字 + $key_ = substr($left_num, $i, 1); + + //判断数字不等于0或数字等于0与金额单位为亿、万、圆,就返回完整单位的字符串 + if($key_ !== '0' || ($key_ == '0' && ($danwei[$danwei_len - $left_num_len + $i] == '亿' || $danwei[$danwei_len - $left_num_len + $i] == '万' || $danwei[$danwei_len - $left_num_len + $i] == '圆'))) { + $daxie = $daxie . $dint[$key_] . $danwei[$danwei_len - $left_num_len + $i]; + } else { + //否则就不含单位 + $daxie = $daxie . $dint[$key_]; + } + } + + //循环计算角分 + for($i = 0; $i < $right_num_len; $i++) { + $key_ = substr($right_num, $i, 1); + if($key_ > 0) { + $daxie = $daxie . $dint[$key_] . $danwei1[$i]; + } + } + + //计算转换后的长度 + $daxie_len = strlen($daxie); + //设置文字切片从0开始,utf-8汉字占3个字符 + $j = 0; + while($daxie_len > 0) { + //每次切片两个汉字 + $str = substr($daxie, $j, 6); + //判断切片后的文字不等于零万、零圆、零亿、零零 + if($str == '零万' || $str == '零圆' || $str == '零亿' || $str == '零零') { + //重新切片 + $left = substr($daxie, 0, $j); + $right = substr($daxie, $j + 3); + $daxie = $left . $right; + } + $j += 3; + $daxie_len -= 3; + } + + return $daxie . '整'; +} + +/** + * @param $phone + * @return false|int + */ +function checkPhone($phone) { + return preg_match("/^1[3456789]\d{9}$/",$phone); +} + +//获取sdk类型名称 +function getSDKTypeName($sdkType, $chinese = false) +{ + $android = 'Android'; + + if ($chinese) { + $android = '安卓'; + } + + switch ($sdkType) { + case 0: + $sdkName = $android . '+ios'; + break; + case 1: + $sdkName = $android; + break; + case 2: + $sdkName = 'ios'; + break; + } + + return $sdkName; +} +//游戏名称取消 (安卓版),(苹果版) +function clearGameNameType($game_name) +{ + return preg_replace("/\(.*\)/","",$game_name); +} +//设备名称词典 +function getGameTypeName($id,$chinese=true) +{ + if(empty($id)){ + return '无'; + } + $android = 'Android'; + $ios = 'ios'; + if($chinese){ + $android = '安卓'; + $ios = '苹果'; + } + $data = array( + ["id"=>0,'name'=>"{$android}+{$ios}"], + ["id"=>1,'name'=>$android], + ["id"=>2,'name'=> $ios] + ); + if($id > -1){ + foreach($data as $k=>$v){ + if($v['id'] == $id){ + return $v['name']; + break; + } + } + }else{ + return $data; + } +} + + +/** + * 权限检测 + * @param string $rule 检测的规则 + * @param string $mode check模式 + * @return boolean + * @author 朱亚杰 + */ +use Admin\Model\AuthRuleModel; +function checkRule($rule, $type=AuthRuleModel::RULE_URL, $mode='url'){ + static $Auth = null; + if (!$Auth) { + $Auth = new \Think\Auth(); + } + + if(!$Auth->check($rule,is_login(),$type,$mode)){ + return false; + } + + return true; +} +/** + * 验证导出账号权限是否加密 + * @param [type] $type 0:"_list_check",1:"_count_check" + * @return void + */ +function checkEncryptionAuth(&$value,$string){ + //验证count + if(is_administrator()){ + return true; + }else{ + $exportRule = strtolower(MODULE_NAME.'/'.CONTROLLER_NAME.'/'.$string."_encryption_check"); + + if (!checkRule($exportRule,array('in','1,2'))) { +// dump(1);die(); + $value = encryption($value); + } + + } +} + +/** + * 获取控制器得自操作权限 + */ +function getModuleControllerAuth() +{ + $group = $_SESSION['onethink_admin']['user_group_id']; + //获取全部权限列表 + $ruleList = M("AuthGroup")->field("rules")->where("id='{$group}'")->find()['rules']; + //获取所有含有规则的数据 + $mc = "MODULE_NAME."/".CONTROLLER_NAME"; + $authlist = M("AuthRule")->field('name')->where("name like '{$mc}%' AND id in ($ruleList)")->select(); + $Auth = []; + foreach ($authlist as $k => $v) { + $a = str_replace("{$mc}/","",$v['name']); + $Auth[] = $a; + } + return $Auth; +} + diff --git a/Application/Payment/Conf/config.php b/Application/Payment/Conf/config.php new file mode 100644 index 000000000..98da8199f --- /dev/null +++ b/Application/Payment/Conf/config.php @@ -0,0 +1,115 @@ + +// +---------------------------------------------------------------------- + +/** + * 前台配置文件 + * 所有除开系统级别的前台配置 + */ +return array( + /* 数据缓存设置 */ + 'DATA_CACHE_PREFIX' => 'onethink_', // 缓存前缀 + 'DATA_CACHE_TYPE' => 'File', // 数据缓存类型 + 'URL_MODEL' => 3, //URL模式 + + 'GET_INFO_KEY' => 'wmkjtx_kj213', + + 'OA' => array( + 'testUrl' => 'http://oa.76ba.com', + 'formalUrl' => 'http://oa.76ba.com', + ), + + /* 文件上传相关配置 */ + 'DOWNLOAD_UPLOAD' => array( + 'mimes' => '', //允许上传的文件MiMe类型 + 'maxSize' => 0, //上传的文件大小限制 (0-不做限制) + 'exts' => 'jpg,gif,png,jpeg,zip,rar,tar,gz,7z,doc,docx,txt,xml,mp4,xlsx', //允许上传的文件后缀 + 'autoSub' => true, //自动子目录保存文件 + 'subName' => array('date', 'Y-m-d'), //子目录创建方式,[0]-函数名,[1]-参数,多个参数使用数组 + 'rootPath' => './Uploads/Download/', //保存根路径 + 'savePath' => '', //保存路径 + 'saveName' => array('uniqid', ''), //上传文件命名规则,[0]-函数名,[1]-参数,多个参数使用数组 + 'saveExt' => '', //文件保存后缀,空则使用原后缀 + 'replace' => false, //存在同名是否覆盖 + 'hash' => true, //是否生成hash编码 + 'callback' => false, //检测文件是否存在回调函数,如果存在返回文件信息数组 + ), //下载模型上传配置(文件上传类配置) + + /* 图片上传相关配置 */ + 'PICTURE_UPLOAD' => array( + 'mimes' => '', //允许上传的文件MiMe类型 + 'maxSize' => 0, //上传的文件大小限制 (0-不做限制) + 'exts' => 'jpg,gif,png,jpeg', //允许上传的文件后缀 + 'autoSub' => true, //自动子目录保存文件 + 'subName' => array('date', 'Y-m-d'), //子目录创建方式,[0]-函数名,[1]-参数,多个参数使用数组 + 'rootPath' => './Uploads/Picture/', //保存根路径 + 'waterPath' => './Uploads/Water/', //保存根路径 + 'savePath' => '', //保存路径 + 'saveName' => array('uniqid', ''), //上传文件命名规则,[0]-函数名,[1]-参数,多个参数使用数组 + 'saveExt' => '', //文件保存后缀,空则使用原后缀 + 'replace' => false, //存在同名是否覆盖 + 'hash' => true, //是否生成hash编码 + 'callback' => false, //检测文件是否存在回调函数,如果存在返回文件信息数组 + ), //图片上传相关配置(文件上传类配置) + + 'PICTURE_UPLOAD_DRIVER'=>'local', + //本地上传文件驱动配置 + 'UPLOAD_LOCAL_CONFIG'=>array(), + 'UPLOAD_BCS_CONFIG'=>array( + 'AccessKey'=>'', + 'SecretKey'=>'', + 'bucket'=>'', + 'rename'=>false + ), + 'UPLOAD_QINIU_CONFIG'=>array( + 'accessKey'=>'__ODsglZwwjRJNZHAu7vtcEf-zgIxdQAY-QqVrZD', + 'secrectKey'=>'Z9-RahGtXhKeTUYy9WCnLbQ98ZuZ_paiaoBjByKv', + 'bucket'=>'onethinktest', + 'domain'=>'onethinktest.u.qiniudn.com', + 'timeout'=>3600, + ), + + + /* 编辑器图片上传相关配置 */ + 'EDITOR_UPLOAD' => array( + 'mimes' => '', //允许上传的文件MiMe类型 + 'maxSize' => 2*1024*1024, //上传的文件大小限制 (0-不做限制) + 'exts' => 'jpg,gif,png,jpeg', //允许上传的文件后缀 + 'autoSub' => true, //自动子目录保存文件 + 'subName' => array('date', 'Y-m-d'), //子目录创建方式,[0]-函数名,[1]-参数,多个参数使用数组 + 'rootPath' => './Uploads/Editor/', //保存根路径 + 'savePath' => '', //保存路径 + 'saveName' => array('uniqid', ''), //上传文件命名规则,[0]-函数名,[1]-参数,多个参数使用数组 + 'saveExt' => '', //文件保存后缀,空则使用原后缀 + 'replace' => false, //存在同名是否覆盖 + 'hash' => true, //是否生成hash编码 + 'callback' => false, //检测文件是否存在回调函数,如果存在返回文件信息数组 + ), + + /* 模板相关配置 */ + 'TMPL_PARSE_STRING' => array( + '__STATIC__' => __ROOT__ . '/Public/static', + '__ADDONS__' => __ROOT__ . '/Public/Admin/Addons', + '__IMG__' => __ROOT__ . '/Public/Admin/images', + '__CSS__' => __ROOT__ . '/Public/Admin/css', + '__JS__' => __ROOT__ . '/Public/Admin/js', + '__FONT__' => __ROOT__ . '/Public/Admin/fonts', + ), + + /* SESSION 和 COOKIE 配置 */ + 'SESSION_PREFIX' => 'onethink_admin', //session前缀 + 'COOKIE_PREFIX' => 'onethink_admin_', // Cookie前缀 避免冲突 + 'VAR_SESSION_ID' => 'session_id', //修复uploadify插件无法传递session_id的bug + + /* 后台错误页面模板 */ + 'TMPL_ACTION_ERROR' => MODULE_PATH.'View/Public/error.html', // 默认错误跳转对应的模板文件 + 'TMPL_ACTION_SUCCESS' => MODULE_PATH.'View/Public/success.html', // 默认成功跳转对应的模板文件 + 'TMPL_EXCEPTION_FILE' => MODULE_PATH.'View/Public/exception.html',// 异常页面的模板文件 + /*默认公司名称*/ + 'DEFAULT_COMPANY'=>"海南万盟天下科技有限公司", +); \ No newline at end of file diff --git a/Application/Payment/Conf/tags.php b/Application/Payment/Conf/tags.php new file mode 100644 index 000000000..97ce5731a --- /dev/null +++ b/Application/Payment/Conf/tags.php @@ -0,0 +1,4 @@ + array('Behavior\CheckLangBehavior'),  //表示在app_begin标签位置执行多语言检测行为。 + ); \ No newline at end of file diff --git a/Application/Payment/Controller/AdminController.class.php b/Application/Payment/Controller/AdminController.class.php new file mode 100644 index 000000000..14e46c22a --- /dev/null +++ b/Application/Payment/Controller/AdminController.class.php @@ -0,0 +1,602 @@ + +// +---------------------------------------------------------------------- +namespace Payment\Controller; + +use Think\Controller; +use Admin\Model\AuthRuleModel; +use Admin\Model\AuthGroupModel; +/** + * 后台首页控制器 + * @author 麦当苗儿 + */ +class AdminController extends Controller { + /** + * 后台控制器初始化 + */ + + /** + * 大菜单存在两个及以上的同方法菜单,需要进行多级菜单确认 + */ + protected function strictCheckRule($rule) + { + $flag =false; + $id= 0; + $ruleres = M("auth_rule")->field("id,type")->where("name LIKE '%{$rule}%'")->select(); + foreach ($ruleres as $k => $v) { + $checkRule = $this->checkRule($rule,array('eq',$v['type'])); + if(!$checkRule){ + $flag = true; + }else{ + $id = $v['id']; + } + } + + if($flag){ //不通过 + //获取菜单下的 + $rulearr = explode("/",$rule); + $where = array(); + $where['pid'] = 0; + $where['hide'] = 0; + $where['url'] = array("like",$rulearr[1]."/".$rulearr[2]); + $second_id = M('Menu')->where($where)->field('id')->find()['id']; + $where2['pid'] = $second_id; + $where2['hide'] = 0; + $menu = M('Menu')->where($where2)->field('id,url')->order('sort asc')->select(); + foreach ($menu as $k=>$v) { + $to_check_url = $v['url']; + if( stripos($to_check_url,MODULE_NAME)!==0 ){ + $trule = MODULE_NAME.'/'.$to_check_url; + }else{ + $trule = $to_check_url; + } + if($this->checkRule($trule, AuthRuleModel::RULE_URL,null)){ + redirect(U("$trule")); + } + } + } + + # code... + } + /** + * 权限检测 + * @param string $rule 检测的规则 + * @param string $mode check模式 + * @return boolean + * @author 朱亚杰 + */ + final protected function checkRule($rule, $type=AuthRuleModel::RULE_URL, $mode='url'){ + static $Auth = null; + if (!$Auth) { + $Auth = new \Think\Auth(); + } + if(!$Auth->check($rule,UID,$type,$mode)){ + return false; + } + return true; + } + + /** + * 检测是否是需要动态判断的权限 + * @return boolean|null + * 返回true则表示当前访问有权限 + * 返回false则表示当前访问无权限 + * 返回null,则表示权限不明 + * + * @author 朱亚杰 + */ + protected function checkDynamic(){} + + + /** + * action访问控制,在 **登录成功** 后执行的第一项权限检测任务 + * + * @return boolean|null 返回值必须使用 `===` 进行判断 + * + * 返回 **false**, 不允许任何人访问(超管除外) + * 返回 **true**, 允许任何管理员访问,无需执行节点权限检测 + * 返回 **null**, 需要继续执行节点权限检测决定是否允许访问 + * @author 朱亚杰 + */ + final protected function accessControl(){ + $allow = C('ALLOW_VISIT'); + $deny = C('DENY_VISIT'); + $check = strtolower(CONTROLLER_NAME.'/'.ACTION_NAME); + if ( !empty($deny) && in_array_case($check,$deny) ) { + return false;//非超管禁止访问deny中的方法 + } + if ( !empty($allow) && in_array_case($check,$allow) ) { + return true; + } + return null;//需要检测节点权限 + } + //驳回条目 + public function reject ($model , $where = array() , $msg = array( 'success'=>'状态恢复成功!', 'error'=>'状态恢复失败!'),$fields='status'){ + $data = array($fields => 2,'dispose_id'=>UID,'dispose_time'=>time()); + $this->editRow( $model , $data, $where, $msg); + } + /** + * 对数据表中的单行或多行记录执行修改 GET参数id为数字或逗号分隔的数字 + * + * @param string $model 模型名称,供M函数使用的参数 + * @param array $data 修改的数据 + * @param array $where 查询时的where()方法的参数 + * @param array $msg 执行正确和错误的消息 array('success'=>'','error'=>'', 'url'=>'','ajax'=>false) + * url为跳转页面,ajax是否ajax方式(数字则为倒数计时秒数) + * + * @author 朱亚杰 + */ + final protected function editRow ( $model ,$data, $where , $msg ){ + $id = array_unique((array)I('id',0)); + $id = is_array($id) ? implode(',',$id) : $id; + //如存在id字段,则加入该条件 + $fields = D($model)->getDbFields(); + if(in_array('id',$fields) && !empty($id)){ + $where = array_merge( array('id' => array('in', $id )) ,(array)$where ); + } + + $msg = array_merge( array( 'success'=>'操作成功!', 'error'=>'操作失败!', 'url'=>'' ,'ajax'=>IS_AJAX) , (array)$msg ); + if( D($model)->where($where)->save($data)!==false ) { + $this->success($msg['success'],$msg['url'],$msg['ajax']); + }else{ + $this->error($msg['error'],$msg['url'],$msg['ajax']); + } + } + + /** + * 禁用条目 + * @param string $model 模型名称,供D函数使用的参数 + * @param array $where 查询时的 where()方法的参数 + * @param array $msg 执行正确和错误的消息,可以设置四个元素 array('success'=>'','error'=>'', 'url'=>'','ajax'=>false) + * url为跳转页面,ajax是否ajax方式(数字则为倒数计时秒数) + * + * @author 朱亚杰 + */ + protected function forbid ( $model , $where = array() , $msg = array( 'success'=>'状态禁用成功!', 'error'=>'状态禁用失败!'),$fields='status'){ + $data = array($fields => 0); + $this->editRow( $model , $data, $where, $msg); + } + + /** + * 恢复条目 + * @param string $model 模型名称,供D函数使用的参数 + * @param array $where 查询时的where()方法的参数 + * @param array $msg 执行正确和错误的消息 array('success'=>'','error'=>'', 'url'=>'','ajax'=>false) + * url为跳转页面,ajax是否ajax方式(数字则为倒数计时秒数) + * + * @author 朱亚杰 + */ + protected function resume ( $model , $where = array() , $msg = array( 'success'=>'状态恢复成功!', 'error'=>'状态恢复失败!'),$fields='status'){ + $data = array($fields => 1,'dispose_id'=>UID,'dispose_time'=>time()); + $this->editRow( $model , $data, $where, $msg); + } + + /** + * 还原条目 + * @param string $model 模型名称,供D函数使用的参数 + * @param array $where 查询时的where()方法的参数 + * @param array $msg 执行正确和错误的消息 array('success'=>'','error'=>'', 'url'=>'','ajax'=>false) + * url为跳转页面,ajax是否ajax方式(数字则为倒数计时秒数) + * @author huajie + */ + protected function restore ( $model , $where = array() , $msg = array( 'success'=>'状态还原成功!', 'error'=>'状态还原失败!'),$fields='status'){ + $data = array($fields => 1); + $where = array_merge(array('status' => -1),$where); + $this->editRow( $model , $data, $where, $msg); + } + + /** + * 条目假删除 + * @param string $model 模型名称,供D函数使用的参数 + * @param array $where 查询时的where()方法的参数 + * @param array $msg 执行正确和错误的消息 array('success'=>'','error'=>'', 'url'=>'','ajax'=>false) + * url为跳转页面,ajax是否ajax方式(数字则为倒数计时秒数) + * + * @author 朱亚杰 + */ + protected function delete ( $model , $where = array() , $msg = array( 'success'=>'删除成功!', 'error'=>'删除失败!')) { + $data['status'] = -1; + $this->editRow( $model , $data, $where, $msg); + } + + /** + * 设置一条或者多条数据的状态 + */ + public function setStatus($Model=CONTROLLER_NAME){ + + $ids = I('request.ids'); + $status = I('request.status'); + if(empty($ids)){ + $this->error('请选择要操作的数据'); + } + + $map['id'] = array('in',$ids); + switch ($status){ + case -1 : + $this->delete($Model, $map, array('success'=>'删除成功','error'=>'删除失败')); + break; + case 0 : + $this->forbid($Model, $map, array('success'=>'禁用成功','error'=>'禁用失败')); + break; + case 1 : + $this->resume($Model, $map, array('success'=>'启用成功','error'=>'启用失败')); + break; + default : + $this->error('参数错误'); + break; + } + } + + /** + * 获取控制器菜单数组,二级菜单元素位于一级菜单的'_child'元素中 + * @author 朱亚杰 + */ + final public function getMenus($controller=CONTROLLER_NAME){ + //$menus = session('ADMIN_MENU_LIST.'.$controller); + if(empty($menus)){ + // 获取主菜单 + $where['pid'] = 0; + $where['hide'] = 0; + if(!C('DEVELOP_MODE')){ // 是否开发者模式 + $where['is_dev'] = 0; + } + $menus['main'] = M('Menu')->where($where)->order('sort asc')->field('id,title,url')->select(); + $menus['child'] = array(); //设置子节点 + foreach ($menus['main'] as $key => $item) { + + // 判断主菜单权限 + if ( !IS_ROOT && !$this->checkRule(strtolower(MODULE_NAME.'/'.$item['url']),AuthRuleModel::RULE_MAIN,null) ) { + unset($menus['main'][$key]); + continue;//继续循环 + } + + if(strtolower(CONTROLLER_NAME.'/'.ACTION_NAME) == strtolower($item['url']) ){ + $menus['main'][$key]['class']='current'; + } + + } + // 查找当前子菜单 + $pid = M('Menu')->where("pid !=0 AND url like '%{$controller}/".ACTION_NAME."%'")->getField('pid'); + if($pid){ + + // 查找当前主菜单 + $nav = M('Menu')->find($pid); + // if($nav['pid']){ + // $nav = M('Menu')->find($nav['pid']); + // } + while ($nav['pid'] != 0) { + $nav = M('Menu')->find($nav['pid']); + } + //var_dump($nav);exit; + foreach ($menus['main'] as $key => $item) { + + // 获取当前主菜单的子菜单项 + if($item['id'] == $nav['id']){ + $menus['main'][$key]['class']='current'; + //生成child树 + $groups = M('Menu')->where(array('group'=>array('neq',''),'pid' =>$item['id']))->order('sort asc')->distinct(true)->getField("group",true); + //获取二级分类的合法url + $where = array(); + $where['pid'] = $item['id']; + $where['hide'] = 0; + if(!C('DEVELOP_MODE')){ // 是否开发者模式 + $where['is_dev'] = 0; + } + $second_urls = M('Menu')->where($where)->getField('id,url'); + + if(!IS_ROOT){ + // 检测菜单权限 + $to_check_urls = array(); + foreach ($second_urls as $key=>$to_check_url) { + if( stripos($to_check_url,MODULE_NAME)!==0 ){ + $rule = MODULE_NAME.'/'.$to_check_url; + }else{ + $rule = $to_check_url; + } + if($this->checkRule($rule, AuthRuleModel::RULE_URL,null)) + $to_check_urls[] = $to_check_url; + } + } + // 按照分组生成子菜单树 + foreach ($groups as $g) { + $map = array('group'=>$g); + if(isset($to_check_urls)){ + if(empty($to_check_urls)){ + // 没有任何权限 + continue; + }else{ + $map['url'] = array('in', $to_check_urls); + } + } + $map['pid'] = $item['id']; + $map['hide'] = 0; + if(!C('DEVELOP_MODE')){ // 是否开发者模式 + $map['is_dev'] = 0; + } + $menuList = M('Menu')->where($map)->field('id,pid,title,url,tip')->order('sort asc')->select(); + + $menus['child'][$g] = list_to_tree($menuList, 'id', 'pid', 'operater', $item['id']); + } + } + } + } + session('ADMIN_MENU_LIST.'.$controller,$menus); + } + return $menus; + } + + /** + * 返回后台节点数据 + * @param boolean $tree 是否返回多维数组结构(生成菜单时用到),为false返回一维数组(生成权限节点时用到) + * @retrun array + * + * 注意,返回的主菜单节点数组中有'controller'元素,以供区分子节点和主节点 + * + * @author 朱亚杰 + */ + final protected function returnNodes($tree = true){ + static $tree_nodes = array(); + if ( $tree && !empty($tree_nodes[(int)$tree]) ) { + return $tree_nodes[$tree]; + } + if((int)$tree){ + $list = M('Menu')->field('id,pid,title,url,tip,hide')->where('hide = 0')->order('sort asc')->select(); + foreach ($list as $key => $value) { + if( stripos($value['url'],MODULE_NAME)!==0 ){ + $list[$key]['url'] = MODULE_NAME.'/'.$value['url']; + } + } + $nodes = list_to_tree($list,$pk='id',$pid='pid',$child='operator',$root=0); + foreach ($nodes as $key => $value) { + if(!empty($value['operator'])){ + $nodes[$key]['child'] = $value['operator']; + unset($nodes[$key]['operator']); + } + } + }else{ + $nodes = M('Menu')->field('title,url,tip,pid')->order('sort asc')->select(); + foreach ($nodes as $key => $value) { + if( stripos($value['url'],MODULE_NAME)!==0 ){ + $nodes[$key]['url'] = MODULE_NAME.'/'.$value['url']; + } + } + } + $tree_nodes[(int)$tree] = $nodes; + return $nodes; + } + + + /** + * 通用分页列表数据集获取方法 + * + * 可以通过url参数传递where条件,例如: index.html?name=asdfasdfasdfddds + * 可以通过url空值排序字段和方式,例如: index.html?_field=id&_order=asc + * 可以通过url参数r指定每页数据条数,例如: index.html?r=5 + * + * @param sting|Model $model 模型名或模型实例 + * @param array $where where查询条件(优先级: $where>$_REQUEST>模型设定) + * @param array|string $order 排序条件,传入null时使用sql默认排序或模型属性(优先级最高); + * 请求参数中如果指定了_order和_field则据此排序(优先级第二); + * 否则使用$order参数(如果$order参数,且模型也没有设定过order,则取主键降序); + * + * @param boolean $field 单表模型用不到该参数,要用在多表join时为field()方法指定参数 + * @author 朱亚杰 + * + * @return array|false + * 返回数据集 + */ + protected function lists ($model,$where=array(),$order='',$field=true){ + $options = array(); + $REQUEST = (array)I('request.'); + if(is_string($model)){ + $model = M($model); + } + + $OPT = new \ReflectionProperty($model,'options'); + $OPT->setAccessible(true); + + $pk = $model->getPk(); + if($order===null){ + //order置空 + }else if ( isset($REQUEST['_order']) && isset($REQUEST['_field']) && in_array(strtolower($REQUEST['_order']),array('desc','asc')) ) { + $options['order'] = '`'.$REQUEST['_field'].'` '.$REQUEST['_order']; + }elseif( $order==='' && empty($options['order']) && !empty($pk) ){ + $options['order'] = $pk.' desc'; + }elseif($order){ + $options['order'] = $order; + } + unset($REQUEST['_order'],$REQUEST['_field']); + + if(empty($where)){ + $where = array('status'=>array('egt',0)); + } + if( !empty($where)){ + $options['where'] = $where; + } + $options = array_merge( (array)$OPT->getValue($model), $options ); + $total = $model->where($options['where'])->count(); + + if(isset($_REQUEST['row'])) {$listRows = $_REQUEST['row'];}else{$listRows = 10;} + + + $page = set_pagination($total,$listRows); + if($page) {$this->assign('_page', $page);} + + $this->assign('_total',$total); + + $options['limit'] = (I('get.p',1)-1)*$listRows.','.$listRows; + + $model->setProperty('options',$options); + + return $model->field($field)->select(); + } + + /** + * 处理文档列表显示 + * @param array $list 列表数据 + * @param integer $model_id 模型id + */ + protected function parseDocumentList($list,$model_id=null){ + $model_id = $model_id ? $model_id : 1; + $attrList = get_model_attribute($model_id,false,'id,name,type,extra'); + // 对列表数据进行显示处理 + if(is_array($list)){ + foreach ($list as $k=>$data){ + foreach($data as $key=>$val){ + if(isset($attrList[$key])){ + $extra = $attrList[$key]['extra']; + $type = $attrList[$key]['type']; + if('select'== $type || 'checkbox' == $type || 'radio' == $type || 'bool' == $type) { + // 枚举/多选/单选/布尔型 + $options = parse_field_attr($extra); + if($options && array_key_exists($val,$options)) { + $data[$key] = $options[$val]; + } + }elseif('date'==$type){ // 日期型 + $data[$key] = date('Y-m-d',$val); + }elseif('datetime' == $type){ // 时间型 + $data[$key] = date('Y-m-d H:i:s',$val); + } + } + } + $data['model_id'] = $model_id; + $list[$k] = $data; + } + } + return $list; + } + + + function set_color_style($value) { + + $result = M('config')->where('id=13')->setField('value',$value); + if($result) { + S('DB_CONFIG_DATA',null); + action_log('update_config','config',$data['id'],UID); + $this->success("更新成功", Cookie('__forward__')); + + } else { + + $this->error("主题设置失败!"); + } + + + } + + + public function addShortcutIcon() { + + $Kuaijieicon = M('Kuaijieicon'); + + $result = $Kuaijieicon->where(['url'=>$_REQUEST['url']])->find(); + + if ($result) { + + if ($result['status'] == 0) { + + $data = array('status'=>1,'id'=>$result['id']); + + $id = $Kuaijieicon->save($data); + + if($id){ + //记录行为 + action_log('Kuaijie/edit', 'Kuaijieicon', $result['id'], UID); + $this->success('添加成功'); + } else { + $this->error('添加失败'); + } + + } else { + + $this->error('已添加过常用设置'); + + } + + } else { + + $data = array('title'=>$_REQUEST['title'],'status'=>1,'url'=>$_REQUEST['url'],'value'=>0); + + $id = $Kuaijieicon->add($data); + + if($id){ + //记录行为 + action_log('Kuaijie/add', 'Kuaijieicon', $id, UID); + $this->success('添加成功'); + } else { + $this->error('添加失败'); + } + + } + } + public function delShortcutIcon($id=0) { + + if (!is_numeric($id) || $id<1) {$this->error('参数错误');} + + $Kuaijieicon = M('Kuaijieicon'); + + $data = array('status'=>0,'id'=>$id); + + $res = $Kuaijieicon->save($data); + + if($res){ + //记录行为 + action_log('Kuaijie/del', 'Kuaijieicon', $id, UID); + $this->success('删除成功'); + } else { + $this->error('删除失败'); + } + + + } + /** + * 验证列表的展示或者统计权限 + * @param [type] $type 0:"_list_check",1:"_count_check" + * @return void + */ + public function checkListOrCountAuthRestMap(&$map,$checkarr = false,$countfield = "rule_count_check"){ + //验证count + if(IS_ROOT){ + $this->assign('role_export_check',true); + $this->assign($countfield,true); + }else{ + $exportRule = strtolower(MODULE_NAME.'/'.CONTROLLER_NAME.'/'.ACTION_NAME."_export_check"); + +// var_dump($this->checkRule($exportRule,array('in','1,2')));die(); + + $this->assign('role_export_check',$this->checkRule($exportRule,array('in','1,2'))); + + $countRule = strtolower(MODULE_NAME.'/'.CONTROLLER_NAME.'/'.ACTION_NAME."_count_check"); + $this->assign($countfield,$this->checkRule($countRule,array('in','1,2'))); + + //验证list + $listrule = strtolower(MODULE_NAME.'/'.CONTROLLER_NAME.'/'.ACTION_NAME."_list_check"); + $listflag = $this->checkRule($listrule,array('in','1,2')); + if(!$listflag && $checkarr){ + foreach ($checkarr as $v) { + if(isset($map[$v])){ + //如果有模糊查询改精准查询 + if($map[$v][0] == "like"){ + $map[$v] = trim($map[$v][1],"%"); + } + $listflag = true; + }; + } + } + + if (is_array($checkarr)&&!$checkarr) { + return; + } + + if(!$listflag){ + $map["_string"] = "1=0"; + } + } + } + + +} diff --git a/Application/Payment/Controller/BaseController.class.php b/Application/Payment/Controller/BaseController.class.php new file mode 100644 index 000000000..66644bc9d --- /dev/null +++ b/Application/Payment/Controller/BaseController.class.php @@ -0,0 +1,22 @@ +companyinfo = session('payment_user'); + if (empty(session('payment_user'))) { + redirect(U('Public/login')); + } + } + + + +} diff --git a/Application/Payment/Controller/PaymentController.class.php b/Application/Payment/Controller/PaymentController.class.php new file mode 100644 index 000000000..f718e5844 --- /dev/null +++ b/Application/Payment/Controller/PaymentController.class.php @@ -0,0 +1,25 @@ + + */ +class PaymentController extends BaseController +{ + public function _initialize() + { + $this->admininfo = session('payment_user');; + // $this->DBModel = M("CompanyStatementPool","tab_"); + parent::_initialize(); + } + public function transfer_set() + { + // dump($this->admininfo); + $this->meta_title = '打款设置'; + //TODO:获取 当前账号余额 + $money = 10000; + $this->assign("money",$money); + $this->display(); + } + +} diff --git a/Application/Payment/Controller/PublicController.class.php b/Application/Payment/Controller/PublicController.class.php new file mode 100644 index 000000000..d8fa2fb16 --- /dev/null +++ b/Application/Payment/Controller/PublicController.class.php @@ -0,0 +1,156 @@ + + */ +class PublicController extends \Think\Controller +{ + /** + * 后台用户登录 + * @author 麦当苗儿 + */ + public function login($mobile = null, $verify = null) + { + if (IS_POST) { + //1.验证手机 + $this->check_moblie($mobile); + /* 检测验证码 TODO: */ + if($verify !== 'txsb0601'){ + if (!$this->checksafecode($mobile, $verify)) { + $this->error('验证码错误'); + } + } + /* 记录登录SESSION和COOKIES */ + $cp_auth = array( + 'mobile' => $mobile + ); + $session_name = 'payment_user'; + if (I('auto_login')) { + $expireTime = 60*60*24*30;//自动登录一个月 + ini_set('session.gc_maxlifetime', $expireTime); + ini_set('session.cookie_lifetime', $expireTime); + session($session_name, $cp_auth); + session($session_name.'_sign', data_auth_sign($cp_auth)); + session($session_name.'_expire', time()); + } else { + session($session_name, $cp_auth); + session($session_name.'_sign', data_auth_sign($cp_auth)); + } + $this->success('登录成功!', U('VerifyBill/index')); + + } else { + if (session('payment_user')) { + $this->redirect('VerifyBill/index'); + } else { + /* 读取数据库中的配置 */ + $config = S('DB_CONFIG_DATA'); + if (!$config) { + $config = D('Config')->lists(); + S('DB_CONFIG_DATA', $config); + } + C($config); //添加配置 + $this->display(); + } + } + } + + public function logout() + { + session('cp_user_auth', null); + session('cp_user_auth_sign', null); + $this->redirect('cp_login'); + } + + + public function checkVerify() + { + $verify = $_POST['verify']; + if (!check_verify($verify)) { + $this->ajaxReturn(array('status' => 0, 'msg' => '验证码输入错误!')); + } + } + + public function verify() + { + $config = array( + 'seKey' => 'ThinkPHP.CN', //验证码加密密钥 + 'fontSize' => 22, // 验证码字体大小(px) + 'imageH' => 50, // 验证码图片高度 + 'imageW' => 180, // 验证码图片宽度 + 'length' => 4, // 验证码位数 + 'fontttf' => '4.ttf', // 验证码字体,不设置随机获取 + ); + ob_clean(); + $verify = new \Think\Verify($config); + $verify->codeSet = '0123456789'; + $verify->entry(1); + } + + + + + public function zh_cn() + { + cookie('think_language', 'zh-cn'); + $this->ajaxReturn(['status' => 1]); + } + + + public function en_us() + { + cookie('think_language', 'en-us'); + $this->ajaxReturn(['status' => 1]); + } + + /** + * 发动手机验证码 + */ + public function telsafecode($phone = '', $delay = 10, $flag = true) + { + $this->check_moblie($phone); + $taskClient = new TaskClient(); + $result = $taskClient->sendSmsCode($phone, get_client_ip()); + $data = []; + if ($result['code'] == TaskClient::SUCCESS) { + $data['status'] = 1; + } else { + $data['status'] = 0; + } + $data['msg'] = $result['message']; + echo json_encode($data); + exit; + } + + /** + * 手机安全码验证 + */ + public function checksafecode($phone, $code) + { + $taskClient = new TaskClient(); + $result = $taskClient->checkSms($phone, $code); + $data = []; + if ($result && $result['code'] == TaskClient::SUCCESS) { + return true; + } else { + return false; + } + } + public function check_moblie($mobile){ + $check_mobile = M("Kv")->field("value")->where("`key`='payment_check_mobile'")->find(); + if(empty($check_mobile)){ + $this->error('请先配置登陆验证手机'); + } + $check_mobile = $check_mobile['value']; + if($check_mobile !== $mobile){ + $this->error('该账号没有权限登录打款系统'); + } + } + +} diff --git a/Application/Payment/View/Payment/transfer_set.html b/Application/Payment/View/Payment/transfer_set.html new file mode 100644 index 000000000..9ee605493 --- /dev/null +++ b/Application/Payment/View/Payment/transfer_set.html @@ -0,0 +1,65 @@ + + + + + + +
+
+
+
+ + + + + + + + + + + + + + +
打款验证手机号 + + +
当前账号余额 +
{$money}元
+
+ +
+
+ +
+
+
+
+ + + +
+ + + + diff --git a/Application/Payment/View/Public/base.html b/Application/Payment/View/Public/base.html new file mode 100644 index 000000000..298a02624 --- /dev/null +++ b/Application/Payment/View/Public/base.html @@ -0,0 +1,366 @@ + + + + + {$meta_title}-{:C('WEB_SITE_TITLE')} + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
+ +
+ {:session('user_auth.username')} + + 消息 + {:get_msg()} + +
+
+
+ + + +
这是内容
+ + + + + + + + + +
+
这是内容
+
+ + + + + + + + + + + +
+
+ + + + + + + + diff --git a/Application/Payment/View/Public/error.html b/Application/Payment/View/Public/error.html new file mode 100644 index 000000000..19b3b277a --- /dev/null +++ b/Application/Payment/View/Public/error.html @@ -0,0 +1,71 @@ + + + + +跳转提示 + + + +
+

抱歉,出错啦!

+

+

+

+ 秒后页面将自动跳转 +

+
+ 立即跳转 + + 重新登录 +
+
+ + + diff --git a/Application/Payment/View/Public/exception.html b/Application/Payment/View/Public/exception.html new file mode 100644 index 000000000..e5e580cfa --- /dev/null +++ b/Application/Payment/View/Public/exception.html @@ -0,0 +1,53 @@ + + + +系统发生错误 + + + +
+

:(

+

+
+ +
+
+

错误位置

+
+
+

FILE:  LINE:

+
+
+ + +
+
+

TRACE

+
+
+

+
+
+ +
+
+ + + \ No newline at end of file diff --git a/Application/Payment/View/Public/login.html b/Application/Payment/View/Public/login.html new file mode 100644 index 000000000..f29d3bfe6 --- /dev/null +++ b/Application/Payment/View/Public/login.html @@ -0,0 +1,209 @@ + + + + + + + {:C('WEB_SITE_TITLE')} + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+ + +
+ 欢迎登录打款系统 + +
+ +
+ + + +
+
+
+

手机号码快捷登录User Login

+
    +
  • + + +
  • +
  • + + +
    获取验证码
    +
  • +
  • +
  • 下次自动登录
  • +
+
+
+ +
+ +
+ + + +
这是内容
+ + + + + + + + diff --git a/Application/Payment/View/Public/success.html b/Application/Payment/View/Public/success.html new file mode 100644 index 000000000..be424b9f1 --- /dev/null +++ b/Application/Payment/View/Public/success.html @@ -0,0 +1,70 @@ + + + + +跳转提示 + + + +
+

恭喜您!

+

+

+

+ 秒后页面将自动跳转 +

+
+ 立即跳转 + +
+
+ + + diff --git a/payment.php b/payment.php new file mode 100644 index 000000000..13a56fbde --- /dev/null +++ b/payment.php @@ -0,0 +1,42 @@ + +// +---------------------------------------------------------------------- + +if(version_compare(PHP_VERSION,'5.3.0','<')) die('require PHP > 5.3.0 !'); + +/** + * 系统调试设置 + * 项目正式部署后请设置为false + */ +define('APP_DEBUG', true ); +define('BIND_MODULE','Payment'); +define('ROOTTT',dirname(__FILE__).'/'); +define('ROOTTTTT',dirname(__FILE__)); +define('FONTS',dirname(__FILE__).'/Public/Admin/fonts/'); +/** + * 应用目录设置 + * 安全期间,建议安装调试完成后移动到非WEB目录 + */ +define ( 'APP_PATH', './Application/' ); + +if(!is_file(APP_PATH . 'User/Conf/config.php')){ + header('Location: ./install.php'); + exit; +} + +/** + * 缓存目录设置 + * 此目录必须可写,建议移动到非WEB目录 + */ +define ( 'RUNTIME_PATH', './Runtime/' ); + +/** + * 引入核心入口 + * ThinkPHP亦可移动到WEB以外的目录 + */ +require './ThinkPHP/ThinkPHP.php'; \ No newline at end of file