assign('langType',$langType); $this->assign('lang',$lang); $this->assign('jsonlang',$jsonlang); // 用于分页和搜索查询的数据 $get = Request::instance()->get(); $query = http_build_query($get); $this->assign('get',$get); $this->assign('query',$query); // 搜索代理 $username = trim(Request::instance()->get('username')); $agent_id = trim(Request::instance()->get('agent_id')); $is_under = trim(Request::instance()->get('is_under')); if($agent_id > 0){ // 获取查询代理信息 $agent = Session::get('user_info'); $user_info = Db::connect('DB2')->name('user')->where('id',$agent_id)->find(); $user_info['account_type'] = $agent['account_type']; }else{ // 登录用户信息 $user_info = Session::get('user_info'); } if(!$is_under){ $is_under = 2; $get['is_under'] = 2; $this->assign('get',$get); } // 总代类型 $topAgentId = explode(',',$user_info['agent_parent_id_path'])[0]; $topAgent = Db::name('user')->where('id',$topAgentId)->find(); $user_info['top_agent_type'] = $topAgent['agent_type']; $user_info['top_agent_pay_channel'] = $topAgent['pay_channel']; // 拼装查询条件 $where = array(); $where['is_delete'] = 0; $where['agent'] = 1; if($is_under == 1){ if($user_info['agent_parent_id'] > 0){ $where['agent_parent_id_path'] = array('like','%,'.$user_info['id'].',%'); }else{ $where['agent_parent_id_path'] = array('like',$user_info['id'].',%'); } }else{ $where['agent_parent_id'] = $user_info['id']; } if($username){ $where['username'] = $username; $agent_list = Db::connect('DB2')->name('user')->where($where)->order('id asc')->paginate(20,false,array('query'=>$get)); }else{ $agent_list = Db::connect('DB2')->name('user')->where($where)->whereOr('id',$user_info['id'])->order('id asc')->paginate(20,false,array('query'=>$get)); } foreach($agent_list as $k => $v){ //充值分级 $agent_parent_id_path_arr = explode(',',$v['agent_parent_id_path']); $agent_id_intersect = array_intersect(LEVEL_AGENT_ID,$agent_parent_id_path_arr); if($v['agent'] == 0 && !empty($agent_id_intersect)){ $v['onlineRecharge'] = Db::name('recharge')->where(array('type' => 4, 'mode' => 1, 'user_id' => $v['id']))->sum('amount'); $v['onlineRechargeTitle'] = recharge_title(intval($v['onlineRecharge'])); }else{ $v['onlineRecharge'] = '-'; $v['onlineRechargeTitle'] = '-'; } // 检测是否有下级代理和会员 $v['childAgent'] = false; $v['childMember'] = false; $childAgent = Db::connect('DB2')->name('user')->where(['is_delete'=>0,'agent_parent_id'=>$v['id'],'agent'=>1])->find(); $childMember = Db::connect('DB2')->name('user')->where(['is_delete'=>0,'agent_parent_id'=>$v['id'],'agent'=>0])->find(); if($childAgent){ $v['childAgent'] = true; } if($childMember){ $v['childMember'] = true; } if($v['type_xima'] == 1){ /* $v['ximalv'] = $lang['bilateral'].' '.$v['agent_ximalv'].' / '.$v['agent_ximalv_dt'].' / '.$v['agent_ximalv_nn'].' / '.$v['agent_ximalv_tc'];*/ $v['ximalv'] = $lang['bilateral'].' '.$v['agent_ximalv'].' / '.$v['agent_ximalv_dt'].' / '.$v['agent_ximalv_nn']; }elseif($v['type_xima'] == 2){ /* $v['ximalv'] = $lang['unilateral'].' '.$v['agent_ximalv'].' / '.$v['agent_ximalv_dt'].' / '.$v['agent_ximalv_nn'].' / '.$v['agent_ximalv_tc'];*/ $v['ximalv'] = $lang['unilateral'].' '.$v['agent_ximalv'].' / '.$v['agent_ximalv_dt'].' / '.$v['agent_ximalv_nn']; }else{ $v['ximalv'] = '0 / 0 / 0'; } // 状态和时间 if($v['status'] == 0) $v['statusMsg'] = $lang['ban']; if($v['status'] == 1) $v['statusMsg'] = $lang['enable']; $v['reg_time'] = date('Y-m-d H:i:s',$v['reg_time']); // 钱包地址 $v['wallet_address'] = Db::name('user_wallet')->where('user_id',$v['id'])->value('address'); // 余额 $userWhere = []; $userWhere['is_delete'] = 0; $userWhere['status'] = 1; if($v['agent_parent_id'] > 0){ $userWhere['agent_parent_id_path'] = array('LIKE','%,'.$v['id'].',%'); }else{ $userWhere['agent_parent_id_path'] = array('LIKE',$v['id'].',%'); } $v['all_money'] = Db::name('user')->where($userWhere)->sum('money'); $agent_list[$k] = $v; } // 渲染参数和模板 $this->assign('user_info',$user_info); $this->assign('agent_list',$agent_list); return $this->fetch(); } // 已删除代理页面 public function delete(){ $langType = cookie('think_var'); $lang = Lang::get('agent'); $jsonlang = json_encode($lang); $this->assign('langType',$langType); $this->assign('lang',$lang); $this->assign('jsonlang',$jsonlang); // 获取管理员信息 $user_info = Session::get('user_info'); if($user_info['account_type'] == 2 || $user_info['account_type'] == 3){ return '非法请求'; } $account_type = $user_info['account_type']; $user_info = Db::connect('DB2')->name('user')->where('id',$user_info['id'])->find(); $user_info['account_type'] = $account_type; // 用于分页和搜索查询的数据 $get = Request::instance()->get(); $get['searchUrl'] = '/agent/index'; $query = http_build_query($get); $this->assign('get',$get); $this->assign('query',$query); // 搜索代理 $username = trim(Request::instance()->get('username')); $where = array(); $where['is_delete'] = 1; $where['agent'] = 1; $where['agent_parent_id'] = $user_info['id']; if($username){ $where['username'] = $username; $agent_list = Db::connect('DB2')->name('user')->where($where)->order('agent_level asc')->paginate(15,false,array('query'=>$get)); }else{ $agent_list = Db::connect('DB2')->name('user')->where($where)->order('agent_level asc')->paginate(15,false,array('query'=>$get)); } foreach($agent_list as $k => $v){ $v['reg_time'] = date('Y-m-d H:i:s',$v['reg_time']); $agent_list[$k] = $v; } // 渲染参数和模板 $this->assign('user_info',$user_info); $this->assign('agent_list',$agent_list); return $this->fetch(); } // 添加代理页面 public function add(){ $langType = cookie('think_var'); $lang = Lang::get('agent'); $jsonlang = json_encode($lang); $this->assign('langType',$langType); $this->assign('lang',$lang); $this->assign('jsonlang',$jsonlang); // 获取管理员信息 $user_info = Session::get('user_info'); if($user_info['account_type'] == 2 || $user_info['account_type'] == 3){ return $lang['illegal_request']; } // 获取父代理信息 $parent_id = Request::instance()->get('parent_id'); $agentParent = Db::name('user')->where('id',$parent_id)->find(); if(!$agentParent || $agentParent['agent'] == 0){ echo $lang['parent_error']; die(); } if($parent_id == CREDIT_AGENT_ID){//是否需要字母前缀 $newLetter = config('letters');//A-Z数组 }else{ $newLetter = $agentParent['letter']?[$agentParent['letter']]:[]; } // 总代性质 $topAgentId = explode(',',$user_info['agent_parent_id_path'])[0]; $topAgent = Db::name('user')->where('id',$topAgentId)->find(); $user_info['agent_type'] = $topAgent['agent_type']; $manager_list = []; if($agentParent['bet_type'] == 2){ if($agentParent['agent_parent_id'] == 0){ $manager_list = Db::name('manager')->where('parent_agent_id',$agentParent['id'])->where('status',1)->field(['id','nickname'])->select(); }else{ $whereManager = explode(',',$agentParent['agent_manager_id_list']); $manager_list = Db::name('manager')->whereIn('id',$whereManager)->where('status',1)->field(['id','nickname'])->select(); } } //渲染参数和模板 $this->assign('newLetter',$newLetter); $this->assign('user_info',$user_info); $this->assign('agentParent',$agentParent); $this->assign('manager_list',$manager_list); return $this->fetch(); } // 处理添加代理 public function do_add(){ $langType = cookie('think_var'); $lang = Lang::get('agent'); if(Request::instance()->post()){ // 获取管理员信息 $user_info = Session::get('user_info'); $account_type = $user_info['account_type']; $user_info = Db::name('user')->where('id',$user_info['id'])->find(); $user_info['account_type'] = $account_type; // 接收参数 $parent_id = intval(Request::instance()->post('parent_id')); $letter = trim(Request::instance()->post('letter')); $username = trim(Request::instance()->post('username')); $nickname = trim(Request::instance()->post('nickname')); $password = trim(Request::instance()->post('password')); $repassword = trim(Request::instance()->post('repassword')); $mobile = trim(Request::instance()->post('mobile')); //$bet_type = Request::instance()->post('bet_type'); $bet_type = $user_info['bet_type']; $limit_low = round(Request::instance()->post('limit_low'),2); $limit_high = round(Request::instance()->post('limit_high'),2); $limit_low_tie = round(Request::instance()->post('limit_low_tie'),2); $limit_high_tie = round(Request::instance()->post('limit_high_tie'),2); $limit_low_pair = round(Request::instance()->post('limit_low_pair'),2); $limit_high_pair = round(Request::instance()->post('limit_high_pair'),2); $limit_low_nn = round(Request::instance()->post('limit_low_nn'),2); $limit_high_nn = round(Request::instance()->post('limit_high_nn'),2); $agent_ximalv = round(Request::instance()->post('agent_ximalv'),2); $agent_ximalv_dt = round(Request::instance()->post('agent_ximalv_dt'),2); $agent_ximalv_nn = round(Request::instance()->post('agent_ximalv_nn'),2); $agent_ximalv_tc = round(Request::instance()->post('agent_ximalv_tc'),2); $agent_cs = round(Request::instance()->post('agent_cs')); $rebate_rate = Request::instance()->post('rebate_rate'); $manager_list = Request::instance()->post('manager_list'); $remark = Request::instance()->post('remark'); // 验证数据 if($parent_id <= 0){ die(json_encode(['code'=>0,'msg'=>$lang['parent_error']])); } $agentParent = Db::name('user')->where('id',$parent_id)->find(); if(!$agentParent || $agentParent['agent'] == 0){ die(json_encode(['code'=>0,'msg'=>$lang['parent_error']])); } if($agentParent['bet_type'] == 2){ if(!$manager_list){ die(json_encode(['code'=>0,'msg'=>$lang['select_manager']])); } } if(!$username){ die(json_encode(['code'=>0,'msg'=>$lang['empty_username']])); } $user = Db::name('user')->where('username',$username)->find(); if($user){ die(json_encode(['code'=>0,'msg'=>$lang['already_exist_username']])); } if($letter && !in_array($letter,config('letters'))){ die(json_encode(['code'=>0,'msg'=>$lang['letter_identification_error']])); } if(!$nickname){ die(json_encode(['code'=>0,'msg'=>$lang['empty_nickname']])); } if(!$password){ die(json_encode(['code'=>0,'msg'=>$lang['empty_password']])); } if(strlen($password) < 6){ die(json_encode(['code'=>0,'msg'=>$lang['new_pass_limit']])); } if($password != $repassword){ die(json_encode(['code'=>0,'msg'=>$lang['pass_diff']])); } if($bet_type > 3 && $bet_type <= 0){ die(json_encode(['code'=>0,'msg'=>$lang['bet_type_error']])); } if($limit_low < 0){ die(json_encode(['code'=>0,'msg'=>$lang['min_limit_0']])); } if($limit_high < 0){ die(json_encode(['code'=>0,'msg'=>$lang['max_limit_0']])); } if($limit_low > $limit_high && $limit_low > 0 && $limit_high > 0){ die(json_encode(['code'=>0,'msg'=>$lang['min_limit_bigger_than_max_limit']])); } if($limit_low_tie < 0){ die(json_encode(['code'=>0,'msg'=>$lang['min_tie_limit_0']])); } if($limit_high_tie < 0){ die(json_encode(['code'=>0,'msg'=>$lang['max_tie_limit_0']])); } if($limit_low_tie > $limit_high_tie && $limit_low_tie > 0 && $limit_high_tie > 0){ die(json_encode(['code'=>0,'msg'=>$lang['min_tie_limit_bigger_than_max_tie_limit']])); } if($limit_low_pair < 0){ die(json_encode(['code'=>0,'msg'=>$lang['min_pair_limit_0']])); } if($limit_high_pair < 0){ die(json_encode(['code'=>0,'msg'=>$lang['max_pair_limit_0']])); } if($limit_low_pair > $limit_high_pair && $limit_low_pair > 0 && $limit_high_pair > 0){ die(json_encode(['code'=>0,'msg'=>$lang['min_pair_limit_bigger_than_max_tie_limit']])); } if($limit_low_nn < 0){ die(json_encode(['code'=>0,'msg'=>$lang['min_nn_limit_0']])); } if($limit_high_nn < 0){ die(json_encode(['code'=>0,'msg'=>$lang['max_nn_limit_0']])); } if($limit_low_nn > $limit_high_nn && $limit_low_nn > 0 && $limit_high_nn > 0){ die(json_encode(['code'=>0,'msg'=>$lang['min_nn_limit_bigger_than_max']])); } if($limit_low < $agentParent['limit_low'] || $limit_low > $agentParent['limit_high'] || $limit_high < $agentParent['limit_low'] || $limit_high > $agentParent['limit_high']){ die(json_encode(['code'=>0,'msg'=>$lang['limit_cannot_bigger'].' '.$agentParent['limit_low'].'-'.$agentParent['limit_high']])); } if($limit_low_tie < $agentParent['limit_low_tie'] || $limit_low_tie > $agentParent['limit_high_tie'] || $limit_high_tie < $agentParent['limit_low_tie'] || $limit_high_tie > $agentParent['limit_high_tie']){ die(json_encode(['code'=>0,'msg'=>$lang['tie_limit_cannot_bigger'].' '.$agentParent['limit_low_tie'].'-'.$agentParent['limit_high_tie']])); } if($limit_low_pair < $agentParent['limit_low_pair'] || $limit_low_pair > $agentParent['limit_high_pair'] || $limit_high_pair < $agentParent['limit_low_pair'] || $limit_high_pair > $agentParent['limit_high_pair']){ die(json_encode(['code'=>0,'msg'=>$lang['pair_limit_cannot_bigger'].' '.$agentParent['limit_low_pair'].'-'.$agentParent['limit_high_pair']])); } if($limit_low_nn > 0 && $limit_high_nn > 0 && $agentParent['limit_low_nn'] > 0 && $agentParent['limit_high_nn'] > 0){ if($limit_low_nn < $agentParent['limit_low_nn'] || $limit_low_nn > $agentParent['limit_high_nn'] || $limit_high_nn < $agentParent['limit_low_nn'] || $limit_high_nn > $agentParent['limit_high_nn']){ die(json_encode(['code'=>0,'msg'=>$lang['nn_limit_cannot_bigger'].' '.$agentParent['limit_low_nn'].'-'.$agentParent['limit_high_nn']])); } } if($agent_ximalv < 0){ die(json_encode(['code'=>0,'msg'=>$lang['baccarat_limit_0']])); } if($agent_ximalv > $agentParent['agent_ximalv']){ die(json_encode(['code'=>0,'msg'=>$lang['baccarat_cannot_bigger_agent'].' '.$agentParent['agent_ximalv'].'!'])); } if($agent_ximalv_dt < 0){ die(json_encode(['code'=>0,'msg'=>$lang['dt_limit_0']])); } if($agent_ximalv_dt > $agentParent['agent_ximalv_dt']){ die(json_encode(['code'=>0,'msg'=>$lang['dt_cannot_bigger_agent'].' '.$agentParent['agent_ximalv_dt'].'!'])); } if($agent_ximalv_nn < 0){ die(json_encode(['code'=>0,'msg'=>$lang['cow_limit_0']])); } if($agent_ximalv_nn > $agentParent['agent_ximalv_nn']){ die(json_encode(['code'=>0,'msg'=>$lang['cow_cannot_bigger_agent'].' '.$agentParent['agent_ximalv_nn'].'!'])); } if($agent_ximalv_tc < 0){ die(json_encode(['code'=>0,'msg'=>$lang['tc_limit_0']])); } if($agent_ximalv_tc > $agentParent['agent_ximalv_tc']){ die(json_encode(['code'=>0,'msg'=>$lang['tc_cannot_bigger_agent'].' '.$agentParent['agent_ximalv_tc'].'!'])); } if($agent_cs > $agentParent['agent_cs']){ die(json_encode(['code'=>0,'msg'=>$lang['proportion_cannot_bigger_agent'].' '.$agentParent['agent_cs'].'!'])); } if($rebate_rate > $agentParent['rebate_rate']){ die(json_encode(['code'=>0,'msg'=>$lang['rebate_cannot_bigger_agent'].' '.$agentParent['rebate_rate'].'!'])); } // 拼装数据创建代理 $user_data = array(); $user_data['username'] = $username; $user_data['agent_manager_id_list'] = $manager_list; $user_data['letter'] = $letter; $user_data['nickname'] = $nickname; $user_data['password'] = think_ucenter_md5($password, UC_AUTH_KEY); $user_data['encrypt'] = getRandChar(); $user_data['mobile'] = $mobile; $user_data['status'] = 1; $user_data['agent'] = 1; $user_data['type_xima'] = $agentParent['type_xima']; $user_data['share_xima'] = $agentParent['share_xima']; $user_data['agent_ximalv'] = $agent_ximalv; $user_data['agent_ximalv_dt'] = $agent_ximalv_dt; $user_data['agent_ximalv_nn'] = $agent_ximalv_nn; $user_data['agent_ximalv_tc'] = $agent_ximalv_tc; $user_data['agent_cs'] = $agent_cs; $user_data['rebate_rate'] = $rebate_rate; $user_data['agent_parent_id'] = $agentParent['id']; $user_data['agent_parent_username'] = $agentParent['username']; $user_data['agent_parent_nickname'] = $agentParent['nickname']; $user_data['limit_low'] = $limit_low; $user_data['limit_high'] = $limit_high; $user_data['limit_low_tie'] = $limit_low_tie; $user_data['limit_high_tie'] = $limit_high_tie; $user_data['limit_low_pair'] = $limit_low_pair; $user_data['limit_high_pair'] = $limit_high_pair; $user_data['limit_low_nn'] = $limit_low_nn; $user_data['limit_high_nn'] = $limit_high_nn; $user_data['bet_type'] = $bet_type; $user_data['reg_time'] = time(); $ip = '0.0.0.0'; if(getIp()){ $ip = getIp(); } $user_data['reg_ip'] = $ip; $user_data['avatar'] = '/static/index/images/admin.png'; $user_data['update_time'] = time(); $user_data['create_mode'] = 2; $user_data['agent_mode'] = 1; $user_data['create_user_id'] = $user_info['id']; $user_data['remarks'] = $remark; //赔率等于他的上级代理 $user_data['price_banker'] = $user_info['price_banker']; $user_data['price_player'] = $user_info['price_player']; $user_data['price_tie_baccarat'] = $user_info['price_tie_baccarat']; $user_data['price_pair'] = $user_info['price_pair']; $user_data['price_luck_six_2'] = $user_info['price_luck_six_2']; $user_data['price_luck_six_3'] = $user_info['price_luck_six_3']; $user_data['price_dragon'] = $user_info['price_dragon']; $user_data['price_tiger'] = $user_info['price_tiger']; $user_data['price_tie_dt'] = $user_info['price_tie_dt']; $user_data['price_n0_n6'] = $user_info['price_n0_n6']; $user_data['price_n7_n9'] = $user_info['price_n7_n9']; $user_data['price_nn'] = $user_info['price_nn']; $user_data['price_5n'] = $user_info['price_5n']; $user_data['price_bomb'] = $user_info['price_bomb']; $user_data['price_tc_n1'] = $user_info['price_tc_n1']; $user_data['price_tc_n2'] = $user_info['price_tc_n2']; $user_data['price_tc_n3'] = $user_info['price_tc_n3']; $user_data['price_tc_n4'] = $user_info['price_tc_n4']; $user_data['price_tc_n5'] = $user_info['price_tc_n5']; $user_data['price_tc_n6'] = $user_info['price_tc_n6']; $user_data['price_tc_n7'] = $user_info['price_tc_n7']; $user_data['price_tc_n8'] = $user_info['price_tc_n8']; $user_data['price_tc_n9'] = $user_info['price_tc_n9']; $user_data['price_tc_nn'] = $user_info['price_tc_nn']; $user_data['price_tc_bz'] = $user_info['price_tc_bz']; $user_data['price_tc_ths'] = $user_info['price_tc_ths']; $user_data['price_tc_hjths'] = $user_info['price_tc_hjths']; $user_data['area_id'] = $agentParent['area_id']; $user_data['agent_commission'] = $user_info['agent_commission']; $user_data['agent_commission_dt'] = $user_info['agent_commission_dt']; $user_data['agent_commission_nn'] = $user_info['agent_commission_nn']; $user_data['agent_commission_tc'] = $user_info['agent_commission_tc']; $user_data['agent_commission_tc_banker'] = $user_info['agent_commission_tc_banker']; $user_data['referral_code'] = getRandCode(); $insertId = Db::name('user')->insertGetId($user_data); if($insertId){ // 写入管理员日志 insertAgentLog('添加代理','添加代理:| ID: '.$insertId.' | 账号: '.$username); Db::name('user')->where(array('id' => $insertId))->update(array('agent_parent_id_path' => $agentParent['agent_parent_id_path'] . ',' . $insertId)); // 生成U地址 总代为 现金线 波场类的支付渠道 $topAgentId = explode(',',$user_info['agent_parent_id_path'])[0]; $topAgent = Db::name('user')->where('id',$topAgentId)->find(); if($topAgent['agent_type'] == 1 && $topAgent['pay_channel'] == "USDT"){ $Usdt = new Usdt(); $result = $Usdt->newUserWallet(); if(isset($result['code']) && $result['code'] == 0){ $walletData = [ 'user_id' => $insertId, 'address' => $result['wallet']['address'], 'parent_id' => $result['wallet']['parent_id'], 'status' => $result['wallet']['status'], 'tid' => $result['wallet']['tid'], 'type' => $result['wallet']['type'], 'create_time' => time(), 'update_time' => time(), ]; Db::name('user_wallet')->insert($walletData); } } die(json_encode(['code'=>1,'msg'=>$lang['added_successfully']])); }else{ die(json_encode(['code'=>0,'msg'=>$lang['add_failed']])); } }else{ die(json_encode(['code'=>0,'msg'=>$lang['operation_error']])); } } // 编辑代理页面 public function edit(){ $langType = cookie('think_var'); $lang = Lang::get('agent'); $jsonlang = json_encode($lang); $this->assign('langType',$langType); $this->assign('lang',$lang); $this->assign('jsonlang',$jsonlang); $user_info = Session::get('user_info'); if($user_info['account_type'] == 2 || $user_info['account_type'] == 3){ return $lang['illegal_request']; } $account_type = $user_info['account_type']; $user_info['account_type'] = $account_type; // 接收需要修改的代理ID $user_id= Request::instance()->get('user_id'); $user = Db::name('user')->where('id',$user_id)->find(); // 总代性质 $topAgentId = explode(',',$user_info['agent_parent_id_path'])[0]; $topAgent = Db::name('user')->where('id',$topAgentId)->find(); $user['agent_type'] = $topAgent['agent_type']; //渲染参数和模板 $this->assign('user_info',$user_info); $this->assign('user',$user); return $this->fetch(); } // 处理编辑代理 public function do_edit(){ $langType = cookie('think_var'); $lang = Lang::get('agent'); $user_info = Session::get('user_info'); if($user_info['account_type'] == 2 || $user_info['account_type'] == 3){ die(json_encode(['code'=>0,'msg'=>$lang['illegal_request']])); } if(Request::instance()->post()){ // 接收参数 $parent_id = Request::instance()->post('parent_id'); $user_id = Request::instance()->post('user_id'); $nickname = Request::instance()->post('nickname'); $mobile = trim(Request::instance()->post('mobile')); //$bet_type = Request::instance()->post('bet_type'); $bet_type = 3; $remark = Request::instance()->post('remark'); $limit_low = round(Request::instance()->post('limit_low'),2); $limit_high = round(Request::instance()->post('limit_high'),2); $limit_low_tie = round(Request::instance()->post('limit_low_tie'),2); $limit_high_tie = round(Request::instance()->post('limit_high_tie'),2); $limit_low_pair = round(Request::instance()->post('limit_low_pair'),2); $limit_high_pair = round(Request::instance()->post('limit_high_pair'),2); $limit_low_nn = round(Request::instance()->post('limit_low_nn'),2); $limit_high_nn = round(Request::instance()->post('limit_high_nn'),2); $agent_ximalv = round(Request::instance()->post('agent_ximalv'),2); $agent_ximalv_dt = round(Request::instance()->post('agent_ximalv_dt'),2); $agent_ximalv_nn = round(Request::instance()->post('agent_ximalv_nn'),2); $agent_ximalv_tc = round(Request::instance()->post('agent_ximalv_tc'),2); $agent_cs = round(Request::instance()->post('agent_cs')); $rebate_rate = Request::instance()->post('rebate_rate'); // 验证数据 $user = Db::name('user')->where('id',$user_id)->find(); if(!$user || $user['agent'] == 0){ die(json_encode(['code'=>0,'msg'=>$lang['error_id']])); } if($parent_id <= 0){ die(json_encode(['code'=>0,'msg'=>$lang['parent_error']])); } $agentParent = Db::name('user')->where('id',$parent_id)->find(); if(!$agentParent || $agentParent['agent'] == 0){ die(json_encode(['code'=>0,'msg'=>$lang['parent_error']])); } if(!$nickname){ die(json_encode(['code'=>0,'msg'=>$lang['empty_nickname']])); } if($bet_type > 3 && $bet_type <= 0){ die(json_encode(['code'=>0,'msg'=>$lang['bet_type_error']])); } if($limit_low < 0){ die(json_encode(['code'=>0,'msg'=>$lang['min_limit_0']])); } if($limit_high < 0){ die(json_encode(['code'=>0,'msg'=>$lang['max_limit_0']])); } if($limit_low > $limit_high && $limit_low > 0 && $limit_high > 0){ die(json_encode(['code'=>0,'msg'=>$lang['min_limit_bigger_than_max_limit']])); } if($limit_low_tie < 0){ die(json_encode(['code'=>0,'msg'=>$lang['min_tie_limit_0']])); } if($limit_high_tie < 0){ die(json_encode(['code'=>0,'msg'=>$lang['max_tie_limit_0']])); } if($limit_low_tie > $limit_high_tie && $limit_low_tie > 0 && $limit_high_tie > 0){ die(json_encode(['code'=>0,'msg'=>$lang['min_tie_limit_bigger_than_max_tie_limit']])); } if($limit_low_pair < 0){ die(json_encode(['code'=>0,'msg'=>$lang['min_pair_limit_0']])); } if($limit_high_pair < 0){ die(json_encode(['code'=>0,'msg'=>$lang['max_pair_limit_0']])); } if($limit_low_pair > $limit_high_pair && $limit_low_pair > 0 && $limit_high_pair > 0){ die(json_encode(['code'=>0,'msg'=>$lang['min_pair_limit_bigger_than_max_tie_limit']])); } if($limit_low < $agentParent['limit_low'] || $limit_low > $agentParent['limit_high'] || $limit_high < $agentParent['limit_low'] || $limit_high > $agentParent['limit_high']){ die(json_encode(['code'=>0,'msg'=>$lang['limit_cannot_bigger'].' '.$agentParent['limit_low'].'-'.$agentParent['limit_high']])); } if($limit_low_tie < $agentParent['limit_low_tie'] || $limit_low_tie > $agentParent['limit_high_tie'] || $limit_high_tie < $agentParent['limit_low_tie'] || $limit_high_tie > $agentParent['limit_high_tie']){ die(json_encode(['code'=>0,'msg'=>$lang['tie_limit_cannot_bigger'].' '.$agentParent['limit_low_tie'].'-'.$agentParent['limit_high_tie']])); } if($limit_low_pair < $agentParent['limit_low_pair'] || $limit_low_pair > $agentParent['limit_high_pair'] || $limit_high_pair < $agentParent['limit_low_pair'] || $limit_high_pair > $agentParent['limit_high_pair']){ die(json_encode(['code'=>0,'msg'=>$lang['pair_limit_cannot_bigger'].' '.$agentParent['limit_low_pair'].'-'.$agentParent['limit_high_pair'].'范围'])); } if($limit_low_nn < 0){ die(json_encode(['code'=>0,'msg'=>$lang['min_nn_limit_0']])); } if($limit_high_nn < 0){ die(json_encode(['code'=>0,'msg'=>$lang['max_nn_limit_0']])); } if($limit_low_nn > $limit_high_nn && $limit_low_nn > 0 && $limit_high_nn > 0){ die(json_encode(['code'=>0,'msg'=>$lang['min_nn_limit_bigger_than_max']])); } if($limit_low_nn > 0 && $limit_high_nn > 0 && $agentParent['limit_low_nn'] > 0 && $agentParent['limit_high_nn'] > 0){ if($limit_low_nn < $agentParent['limit_low_nn'] || $limit_low_nn > $agentParent['limit_high_nn'] || $limit_high_nn < $agentParent['limit_low_nn'] || $limit_high_nn > $agentParent['limit_high_nn']){ die(json_encode(['code'=>0,'msg'=>$lang['nn_limit_cannot_bigger'].' '.$agentParent['limit_low_nn'].'-'.$agentParent['limit_high_nn']])); } } if($agent_ximalv > $agentParent['agent_ximalv']){ die(json_encode(['code'=>0,'msg'=>$lang['baccarat_cannot_bigger_agent'].' '.$agentParent['agent_ximalv'].'!'])); } if($agent_ximalv_dt > $agentParent['agent_ximalv_dt']){ die(json_encode(['code'=>0,'msg'=>$lang['dt_cannot_bigger_agent'].' '.$agentParent['agent_ximalv_dt'].'!'])); } if($agent_ximalv_nn > $agentParent['agent_ximalv_nn']){ die(json_encode(['code'=>0,'msg'=>$lang['cow_cannot_bigger_agent'].' '.$agentParent['agent_ximalv_nn'].'!'])); } if($agent_ximalv_tc > $agentParent['agent_ximalv_tc']){ die(json_encode(['code'=>0,'msg'=>$lang['tc_cannot_bigger_agent'].' '.$agentParent['agent_ximalv_tc'].'!'])); } if($agent_cs > $agentParent['agent_cs']){ die(json_encode(['code'=>0,'msg'=>$lang['proportion_cannot_bigger_agent'].' '.$agentParent['agent_cs'].'!'])); } if($rebate_rate > $agentParent['rebate_rate']){ die(json_encode(['code'=>0,'msg'=>$lang['rebate_cannot_bigger_agent'].' '.$agentParent['rebate_rate'].'!'])); } // 获取下级最高的洗码率和占股 $childWhere = array(); $childWhere['agent'] = 1; if($agentParent['agent_parent_id'] > 0){ $childWhere['agent_parent_id_path'] = array('like','%,'.$user_id.',%'); $childWhere['id'] = array('>',$user_id); }else{ $childWhere['agent_parent_id_path'] = array('like',$user_id.',%'); } $childMaxCs = Db::name('user')->where($childWhere)->max('agent_cs'); $childMaxXimalv = Db::name('user')->where($childWhere)->max('agent_ximalv'); $childMaxXimalvDt = Db::name('user')->where($childWhere)->max('agent_ximalv_dt'); $childMaxXimalvNn = Db::name('user')->where($childWhere)->max('agent_ximalv_nn'); $childMaxXimalvTc = Db::name('user')->where($childWhere)->max('agent_ximalv_tc'); $childMaxRebateRate = Db::name('user')->where($childWhere)->max('rebate_rate'); if($agent_cs < $childMaxCs){ die(json_encode(['code'=>0,'msg'=>$lang['proportion_cannot_lower_agent'].$childMaxCs.'%'])); } if($agent_ximalv < $childMaxXimalv){ die(json_encode(['code'=>0,'msg'=>$lang['baccarat_cannot_lower_agent'].' '.$childMaxXimalv.'%'])); } if($agent_ximalv_dt < $childMaxXimalvDt){ die(json_encode(['code'=>0,'msg'=>$lang['dt_cannot_lower_agent'].' '.$childMaxXimalvDt.'%'])); } if($agent_ximalv_nn < $childMaxXimalvNn){ die(json_encode(['code'=>0,'msg'=>$lang['cow_cannot_lower_agent'].' '.$childMaxXimalvNn.'%'])); } if($agent_ximalv_tc < $childMaxXimalvTc){ die(json_encode(['code'=>0,'msg'=>$lang['tc_cannot_lower_agent'].' '.$childMaxXimalvTc.'%'])); } if($rebate_rate < $childMaxRebateRate){ die(json_encode(['code'=>0,'msg'=>$lang['rebate_cannot_lower_agent'].' '.$childMaxRebateRate.'%'])); } // 拼装数据创建代理 $user_data = array(); $user_data['nickname'] = $nickname; $user_data['mobile'] = $mobile; $user_data['bet_type'] = $bet_type; $user_data['update_time'] = time(); $user_data['remarks'] = $remark; $user_data['limit_low'] = $limit_low; $user_data['limit_high'] = $limit_high; $user_data['limit_low_tie'] = $limit_low_tie; $user_data['limit_high_tie'] = $limit_high_tie; $user_data['limit_low_pair'] = $limit_low_pair; $user_data['limit_high_pair'] = $limit_high_pair; $user_data['limit_low_nn'] = $limit_low_nn; $user_data['limit_high_nn'] = $limit_high_nn; $user_data['agent_ximalv'] = $agent_ximalv; $user_data['agent_ximalv_dt'] = $agent_ximalv_dt; $user_data['agent_ximalv_nn'] = $agent_ximalv_nn; $user_data['agent_ximalv_tc'] = $agent_ximalv_tc; $user_data['agent_cs'] = $agent_cs; $user_data['rebate_rate'] = $rebate_rate; $result = Db::name('user')->where('id',$user_id)->update($user_data); if($result){ // 写入管理员日志 $user = Db::name('user')->where('id',$user_id)->find(); insertAgentLog('编辑代理','编辑代理:| ID: '.$user['id'].' | 账号: '.$user['username']); } die(json_encode(['code'=>1,'msg'=>$lang['edit_successfully']])); }else{ die(json_encode(['code'=>0,'msg'=>$lang['operation_error']])); } } /** * 生成用户钱包 * @param $userId */ public function createWallet() { $userId = Request::instance()->post('user_id'); if(empty($userId)){ die(json_encode(['code'=>0,'msg'=>'用户信息错误'])); } $address = Db::name('user_wallet')->where('user_id',$userId)->value('address'); if($address){ die(json_encode(['code'=>0,'msg'=>'已存在钱包地址'])); } // 生成U地址 $Usdt = new Usdt(); $result = $Usdt->newUserWallet(); if(isset($result['code']) && $result['code'] == 0){ $walletData = [ 'user_id' => $userId, 'address' => $result['wallet']['address'], 'parent_id' => $result['wallet']['parent_id'], 'status' => $result['wallet']['status'], 'tid' => $result['wallet']['tid'], 'type' => $result['wallet']['type'], 'create_time' => time(), 'update_time' => time(), ]; Db::name('user_wallet')->insert($walletData); die(json_encode(['code'=>1,'msg'=>'操作成功'])); }else{ die(json_encode(['code'=>1,'msg'=>'操作失败,请联系客服!'])); } } }