382 lines
14 KiB
PHP
382 lines
14 KiB
PHP
<?php
|
|
namespace app\agent\controller;
|
|
use pay\Usdt;
|
|
use \think\Controller;
|
|
use think\Lang;
|
|
use \think\Session;
|
|
use \think\Request;
|
|
use \think\Db;
|
|
class Index Extends Common{
|
|
public function get_session_id(){
|
|
$user_info = Session::get('user_info');
|
|
$user = Db::name('user')->where(array('id' => $user_info['id']))->find();
|
|
return json(array('code' => 1, 'session_id' => $user['session_id']));
|
|
}
|
|
public function index(){
|
|
// 获取登录信息
|
|
$user_info = Session::get('user_info');
|
|
$account_type = $user_info['account_type'];
|
|
$sub_name = $user_info['sub_name'];
|
|
$user_info = Db::name('user')->where('id',$user_info['id'])->find();
|
|
$user_info['account_type'] = $account_type;
|
|
$user_info['sub_name'] = $sub_name;
|
|
|
|
// $show_market = $user_info['area_id']>0?1:0;
|
|
$show_market = 1;
|
|
|
|
$all_wt_agent = ALLOW_WT_SET;
|
|
$wt_agent = Db::connect('DB2')->name('table')->where(array('status' => 1))->order('id asc')->limit(1)->value('wt_agent');
|
|
$wt_agent_info = DB::name('user')->where('username',$wt_agent)->find();
|
|
if($wt_agent_info['agent_parent_id'] == 0){
|
|
$is_under = Db::name('user')->where('agent_parent_id_path','like',$wt_agent_info['id'].',%')->whereOr('id',$user_info['id'])->find();
|
|
}else{
|
|
$is_under = Db::name('user')->where('agent_parent_id_path','like','%,'.$wt_agent_info['id'].',%')->whereOr('agent_parent_id',$wt_agent_info['id'])->where('id',$user_info['id'])->find();
|
|
}
|
|
if($is_under){
|
|
$is_show_marketing = 1;
|
|
}else{
|
|
$is_show_marketing = 0;
|
|
}
|
|
|
|
//判断是否属于line投代理
|
|
$zdlIdArr = explode(',',$user_info['agent_parent_id_path']);
|
|
$isLine = false;
|
|
foreach(config('limit_list')['line_referral'] as $allowAgentId){
|
|
if(in_array($allowAgentId,$zdlIdArr)){
|
|
$isLine = true;
|
|
}
|
|
}
|
|
// 总代支付渠道关联
|
|
$parentIds = Db::name('user')->whereIn('id',$user_info['agent_parent_id_path'])->column('id');
|
|
$user_info['top_agent_type'] = Db::name('user')->where('id',$parentIds[0])->value('agent_type');
|
|
$user_info['pay_channel'] = Db::name('user_pay_channel')->where('user_id',$parentIds[0])->column('pay_channel_key');
|
|
|
|
// 渲染参数和模板
|
|
$langType = cookie('think_var');
|
|
$lang = Lang::get('agent');
|
|
$jsonlang = json_encode($lang);
|
|
$this->assign('langType',$langType);
|
|
$this->assign('lang',$lang);
|
|
$this->assign('jsonlang',$jsonlang);
|
|
$this->assign('show_market',$show_market);
|
|
$this->assign('all_wt_agent',$all_wt_agent);
|
|
$this->assign('user_info',$user_info);
|
|
$this->assign('is_show_marketing',$is_show_marketing);
|
|
$this->assign('isLine',$isLine);
|
|
return $this->fetch();
|
|
}
|
|
|
|
// 个人中心
|
|
public function admin(){
|
|
// 获取登录信息
|
|
$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;
|
|
if( $user_info['agent_last_login_time'] > 0){
|
|
$user_info['agent_last_login_time'] = date('Y-m-d H:i:s',$user_info['agent_last_login_time']);
|
|
}
|
|
|
|
// 今日时间
|
|
$startTime = strtotime(date('Y-m-d',time()));
|
|
$endTime = $startTime + 60*60*24 - 1;
|
|
$dateWhere = array();
|
|
$dateWhere['create_time'] = array('between',[$startTime,$endTime]);
|
|
|
|
// 洗码率
|
|
if($user_info['type_xima'] == 1){
|
|
/*
|
|
$user_info['ximalv'] = $user_info['agent_ximalv'].' / '.$user_info['agent_ximalv_dt']. ' / '.$user_info['agent_ximalv_nn']. ' / '.$user_info['agent_ximalv_tc'];*/
|
|
|
|
$user_info['ximalv'] = $user_info['agent_ximalv'].' / '.$user_info['agent_ximalv_dt']. ' / '.$user_info['agent_ximalv_nn'];
|
|
}else{
|
|
/*$user_info['ximalv'] = $user_info['agent_ximalv_single'].' / '.$user_info['agent_ximalv_dt_single']. ' / '.$user_info['agent_ximalv_nn_single']. ' / '.$user_info['agent_ximalv_tc_single'];*/
|
|
$user_info['ximalv'] = $user_info['agent_ximalv_single'].' / '.$user_info['agent_ximalv_dt_single']. ' / '.$user_info['agent_ximalv_nn_single'];
|
|
}
|
|
|
|
// 下属代理总数
|
|
if($user_info['agent_parent_id'] == 0){
|
|
// 管理员为 总代
|
|
// 代理 会员 总数
|
|
$underAgentCount = Db::name('user')->where('agent_parent_id_path','like',$user_info['id'].',%')->where('agent',1)->count();
|
|
$underMemberCount = Db::name('user')->where('agent_parent_id_path','like',$user_info['id'].',%')->where('agent',0)->count();
|
|
|
|
// 今日新增代理 会员
|
|
$time = time();
|
|
$underAgentCountToday = Db::name('user')->where('agent_parent_id_path','like',$user_info['id'].',%')->where('agent',1)->where('reg_time','>=',$time)->count();
|
|
$underMemberCountToday = Db::name('user')->where('agent_parent_id_path','like',$user_info['id'].',%')->where('agent',0)->where('reg_time','>=',$time)->count();
|
|
}else{
|
|
// 管理员为 非总代
|
|
// 代理 会员 总数
|
|
$underAgentCount = Db::name('user')->where('agent_parent_id_path','like','%,'.$user_info['id'].',%')->where('agent',1)->count();
|
|
$underMemberCount = Db::name('user')->where('agent_parent_id_path','like','%,'.$user_info['id'].',%')->where('agent',0)->count();
|
|
|
|
// 今日新增代理 会员
|
|
$time = time();
|
|
$underAgentCountToday = Db::name('user')->where('agent_parent_id_path','like','%,'.$user_info['id'].',%')->where('agent',1)->where('reg_time','>=',$time)->count();
|
|
$underMemberCountToday = Db::name('user')->where('agent_parent_id_path','like','%,'.$user_info['id'].',%')->where('agent',0)->where('reg_time','>=',$time)->count();
|
|
}
|
|
|
|
// 渲染参数和模板
|
|
$langType = cookie('think_var');
|
|
$lang = Lang::get('agent');
|
|
$jsonlang = json_encode($lang);
|
|
|
|
$this->assign('langType',$langType);
|
|
$this->assign('lang',$lang);
|
|
$this->assign('jsonlang',$jsonlang);
|
|
$this->assign('user_info',$user_info);
|
|
$this->assign('underAgentCount',$underAgentCount);
|
|
$this->assign('underAgentCountToday',$underAgentCountToday);
|
|
$this->assign('underMemberCount',$underMemberCount);
|
|
$this->assign('underMemberCountToday',$underMemberCountToday);
|
|
return $this->fetch();
|
|
}
|
|
|
|
// 修改管理员密码弹窗页面
|
|
public function password(){
|
|
// 获取登录信息
|
|
$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;
|
|
|
|
// 渲染参数和模板
|
|
$langType = cookie('think_var');
|
|
$lang = Lang::get('agent');
|
|
$jsonlang = json_encode($lang);
|
|
|
|
$this->assign('langType',$langType);
|
|
$this->assign('lang',$lang);
|
|
$this->assign('jsonlang',$jsonlang);
|
|
$this->assign('user_info',$user_info);
|
|
return $this->fetch();
|
|
}
|
|
|
|
//处理修改管理员密码
|
|
public function change_password(){
|
|
if(Request::instance()->post()){
|
|
// 获取参数
|
|
$user_info = Session::get('user_info');
|
|
$password = Request::instance()->post('password');
|
|
$newPassword = Request::instance()->post('newPassword');
|
|
$reNewPassword = Request::instance()->post('reNewPassword');
|
|
|
|
$langType = cookie('think_var');
|
|
$lang = Lang::get('agent');
|
|
|
|
// 验证参数 拼装数据
|
|
$result = array();
|
|
if(empty($password) || empty($newPassword)){
|
|
$result['code'] = 0;
|
|
$result['msg'] = $lang['enter_old_and_new'];
|
|
die(json_encode($result));
|
|
}
|
|
if(strlen($newPassword) < 6){
|
|
$result['code'] = 0;
|
|
$result['msg'] = $lang['new_pass_limit'];
|
|
die(json_encode($result));
|
|
}
|
|
if($newPassword != $reNewPassword){
|
|
$result['code'] = 0;
|
|
$result['msg'] = $lang['pass_diff'];
|
|
die(json_encode($result));
|
|
}
|
|
|
|
// 查询管理员信息及更改密码
|
|
$find = Db::name('user')->where(array('id' => $user_info['id']))->find();
|
|
if(think_ucenter_md5($password, UC_AUTH_KEY) === $find['password'] && $find['password']){
|
|
$updateRes = Db::name('user')->where(array('id' => $user_info['id']))->update(array('password' => think_ucenter_md5($newPassword, UC_AUTH_KEY)));
|
|
if($updateRes){
|
|
insertAgentLog('修改密码');
|
|
$result['code'] = 1;
|
|
$result['msg'] = $lang['success_edit_pass'];
|
|
die(json_encode($result));
|
|
}else{
|
|
$result['code'] = 0;
|
|
$result['msg'] = $lang['error_edit_pass'];
|
|
die(json_encode($result));
|
|
}
|
|
}else{
|
|
$result['code'] = 0;
|
|
$result['msg'] = $lang['original_password_error'];
|
|
die(json_encode($result));
|
|
}
|
|
}
|
|
}
|
|
|
|
// 修改下级代理和会员密码弹窗页面
|
|
public function password_child(){
|
|
// 接收要修改的下属ID
|
|
$user_id = Request::instance()->get('id');
|
|
$user_info = Db::name('user')->where('id',$user_id)->find();
|
|
|
|
// 渲染参数和模板
|
|
$langType = cookie('think_var');
|
|
$lang = Lang::get('agent');
|
|
$jsonlang = json_encode($lang);
|
|
|
|
$this->assign('langType',$langType);
|
|
$this->assign('lang',$lang);
|
|
$this->assign('jsonlang',$jsonlang);
|
|
$this->assign('user_info',$user_info);
|
|
return $this->fetch();
|
|
}
|
|
|
|
// 处理修改下级代理和会员密码
|
|
public function change_password_child(){
|
|
if(Request::instance()->post()){
|
|
$langType = cookie('think_var');
|
|
$lang = Lang::get('agent');
|
|
|
|
// 获取参数
|
|
$user_id = Request::instance()->post('user_id');
|
|
$username = Request::instance()->post('username');
|
|
$newPassword = Request::instance()->post('newPassword');
|
|
$reNewPassword = Request::instance()->post('reNewPassword');
|
|
|
|
// 验证参数 拼装数据
|
|
$user_info = Db::name('user')->where('id',$user_id)->find();
|
|
if(!$user_info){
|
|
die(json_encode(['code'=>0,'msg'=>$username.' '.$lang['exist']]));
|
|
}
|
|
if(empty($newPassword)){
|
|
die(json_encode(['code'=>0,'msg'=> $lang['enter_original_password']]));
|
|
}
|
|
if(strlen($newPassword) < 6){
|
|
die(json_encode(['code'=>0,'msg'=> $lang['new_pass_limit'] ]));
|
|
}
|
|
if($newPassword != $reNewPassword){
|
|
die(json_encode(['code'=>0,'msg'=> $lang['pass_diff']]));
|
|
}
|
|
if(think_ucenter_md5($newPassword, UC_AUTH_KEY) == $user_info['password']){
|
|
die(json_encode(['code'=>0,'msg'=> $lang['sam_new_old']]));
|
|
}
|
|
|
|
// 更改下属的密码
|
|
$updateRes = Db::name('user')->where(array('id' => $user_info['id']))->update(array('password' => think_ucenter_md5($newPassword, UC_AUTH_KEY)));
|
|
if($updateRes){
|
|
insertAgentLog('修改密码');
|
|
die(json_encode(['code'=>1,'msg'=> $lang['success_edit_pass']]));
|
|
}else{
|
|
die(json_encode(['code'=>0,'msg'=> $lang['error_edit_pass']]));
|
|
}
|
|
}
|
|
}
|
|
|
|
// 启用/禁用 下级代理和会员
|
|
public function change_status_child(){
|
|
$user_info = Session::get('user_info');
|
|
$langType = cookie('think_var');
|
|
$lang = Lang::get('agent');
|
|
if($user_info['account_type'] == 2 || $user_info['account_type'] == 3){
|
|
return $lang['illegal_request'];
|
|
}
|
|
if(Request::instance()->post()){
|
|
// 获取参数
|
|
$username = Request::instance()->post('username');
|
|
$user_id = Request::instance()->post('user_id');
|
|
$status = Request::instance()->post('status');
|
|
|
|
// 验证参数 拼装数据
|
|
$user_info = Db::name('user')->where('id',$user_id)->find();
|
|
if(!$user_info){
|
|
die(json_encode(['code'=>0,'msg'=> $lang['username'].' '.$username.' '.$lang['exist']]));
|
|
}
|
|
if( !($status == 0 || $status == 1)){
|
|
die(json_encode(['code'=>0,'msg'=> $lang['status_code_error']]));
|
|
}
|
|
if($status == 1){
|
|
// 由启用改为禁用
|
|
$updateStatus = 0;
|
|
$msg = $lang['account_is_disabled'];
|
|
}else{
|
|
// 由禁用改为启用
|
|
$updateStatus = 1;
|
|
$msg = $lang['account_enabled'];
|
|
}
|
|
|
|
// 更新自己的状态
|
|
Db::name('user')->where('id',$user_id)->update(['status'=>$updateStatus]);
|
|
$agentChilds = array();
|
|
// 更新自己及所有下属状态
|
|
if($user_info['agent'] == 1){
|
|
$agentParentIds = explode(',',$user_info['agent_parent_id_path']);
|
|
if($agentParentIds[0] == $user_info['id']){
|
|
// 总代
|
|
$agentChilds = Db::name('user')->where('agent_parent_id_path','like',$user_info['id'].',%')->where('is_delete',0)->select();
|
|
$count = Db::name('user')->where('agent_parent_id_path','like',$user_info['id'].',%')->where('is_delete',0)->count();
|
|
}else{
|
|
// 非总代
|
|
$agentChilds = Db::name('user')->where('agent_parent_id_path','like','%,'.$user_info['id'].',%')->where('is_delete',0)->select();
|
|
$count = Db::name('user')->where('agent_parent_id_path','like','%,'.$user_info['id'].',%')->where('is_delete',0)->count();
|
|
}
|
|
foreach($agentChilds as $v){
|
|
Db::name('user')->where('id',$v['id'])->update(['status'=>$updateStatus]);
|
|
if($v['agent'] == 0 && $updateStatus == 0){
|
|
Db::name('user')->where('id',$v['id'])->update(['isout'=>1]);
|
|
}
|
|
}
|
|
$count += 1;
|
|
if($user_info['agent'] == 1){
|
|
if($status == 1){
|
|
// 由启用改为禁用
|
|
$msg = $lang['batch_ban'].':'.$count;
|
|
}else{
|
|
// 由禁用改为启用
|
|
$msg = $lang['batch_enable'].':'.$count;
|
|
}
|
|
}
|
|
}else{
|
|
if($updateStatus == 0){
|
|
Db::name('user')->where('id',$user_id)->update(['isout'=>1]);
|
|
}
|
|
}
|
|
// 将自己也加入
|
|
$agentChilds[] = $user_info;
|
|
|
|
die(json_encode(['code'=>1,'msg'=>$msg,'updateStatus'=>$updateStatus,'agentChilds'=>$agentChilds]));
|
|
}
|
|
}
|
|
|
|
// 关系链
|
|
public function relation(){
|
|
$langType = cookie('think_var');
|
|
$lang = Lang::get('agent');
|
|
$jsonlang = json_encode($lang);
|
|
|
|
$this->assign('langType',$langType);
|
|
$this->assign('lang',$lang);
|
|
$this->assign('jsonlang',$jsonlang);
|
|
$userInfo = Session::get('user_info');
|
|
// 接收要修改的下属ID
|
|
$user_id = Request::instance()->get('id');
|
|
$user_info = Db::name('user')->where('id',$user_id)->find();
|
|
|
|
// 查询代理路径
|
|
$agentParentPath = explode(',',$user_info['agent_parent_id_path']);
|
|
$relation = array();
|
|
foreach($agentParentPath as $k => $v){
|
|
if($v >= $userInfo['id']){
|
|
$user = Db::name('user')->where('id',$v)->find();
|
|
$data = array();
|
|
$data['username'] = $user['username'];
|
|
$data['nickname'] = $user['nickname'];
|
|
$data['reg_time'] = date('Y-m-d H:i:s',$user['reg_time']);
|
|
if($user['agent'] == 1){
|
|
$data['agent'] = $lang['agent'];
|
|
$data['color'] = '#FF5722';
|
|
}else{
|
|
$data['agent'] = $lang['member'];
|
|
$data['color'] = '#008dfd';
|
|
}
|
|
$relation[] = $data;
|
|
}
|
|
}
|
|
|
|
// 渲染参数和模板
|
|
$this->assign('relation',$relation);
|
|
return $this->fetch();
|
|
}
|
|
}
|