Commit ae92e0d6 authored by hujun's avatar hujun

删除经纪人转表代码

parent c52fc7ab
......@@ -36,7 +36,8 @@ class Agent extends Basic
*
* @return \think\response\View3
*/
public function agent(){
public function agent()
{
return view('agent');
}
......@@ -45,7 +46,8 @@ class Agent extends Basic
*
* @return \think\response\View
*/
public function saveAgentIndex(){
public function saveAgentIndex()
{
return view('save_agent');
}
......@@ -57,74 +59,73 @@ class Agent extends Basic
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function AgentList(){
$table= new AAgents();
public function AgentList()
{
$table = new AAgents();
$data['status'] = 200;
$data['msg'] = '';
$data['msg'] = '';
//获取当前模块可操作按钮start********************************
$userRule = Session::get('userRule');
$data['cz']=$userRule['cz'];
$userRule = Session::get('userRule');
$data['cz'] = $userRule['cz'];
//获取当前模块可操作按钮end**********************************
$params = $this->request->param();
//获取操作权限
$userRule = Session::get('userRule');
$userRule = Session::get('userRule');
$data['userRule'] = $userRule;
$pageNo = empty($params['pageNo']) ? 1 : $params['pageNo'];
$pageSize = empty($params['pageSize']) ? 15 : $params['pageSize'];
$pageNo = empty($params['pageNo']) ? 1 : $params['pageNo'];
$pageSize = empty($params['pageSize']) ? 15 : $params['pageSize'];
//条件
$where = 'a.status in(0,1)';
$where = 'a.id != 1';
$search = $params['search'];
if(!empty($search)){
$where .= " and a.id='$search' or a.name like '%$search%' or a.phone like '%$search%' ";
if (!empty($search)) {
$where .= " and a.id='$search' or a.name like '%$search%' or a.phone like '%$search%' ";
$data['search'] = $search;
}
if(!empty($params['groupname'])){
$where .= " and g.title like '%{$params['groupname']}%' ";
if (!empty($params['groupname'])) {
$where .= " and g.title like '%{$params['groupname']}%' ";
$data['groupname'] = $params['groupname'];
}
if(!empty($params['store_name'])){
$where .=" and s.store_name like '%{$params['store_name']}%' ";
if (!empty($params['store_name'])) {
$where .= " and s.store_name like '%{$params['store_name']}%' ";
$data['store_name'] = $params['store_name'];
}
$field = "a.id,a.store_id,a.img,a.district_id,a.`level`,a.`name`,a.phone,a.`status`,a.inviter_id,a.create_time,
ifnull(s.store_name,'')store_name,ifnull(d.district_name,'')district_name,ifnull(g.title,'无')groupname";
$order = 'a.id DESC';
$join = [
['a_store s', ' a.store_id=s.id','left'],
['a_district d','a.district_id=d.id','left'],
['auth_group g','a.auth_group_id=g.id','left']
[ 'a_store s', ' a.store_id=s.id', 'left' ],
[ 'a_district d', 'a.district_id=d.id', 'left' ],
[ 'auth_group g', 'a.auth_group_id=g.id', 'left' ]
];
$data['list'] = $table->getListJoin($pageNo, $pageSize,$order,$field,$join, $where);
foreach ($data['list'] as $k=>$v) {
$data['list'][$k]['agent_img'] = $v['img'] ? AGENTHEADERIMGURL . $v['img'] : AGENTHEADERIMGURL . 'icon_head.png' ;
//$data['list'][$k]['agent_img'] = 'https://pre2.tonglianjituan.com/static/user_header/20180615/6528100f422ffa6f7d1cb1293c1eaaed.jpg' ;
$data['list'] = $table->getListJoin($pageNo, $pageSize, $order, $field, $join, $where);
foreach ($data['list'] as $k => $v) {
$data['list'][$k]['agent_img'] = $v['img'] ? AGENTHEADERIMGURL . $v['img'] : AGENTHEADERIMGURL . 'icon_head.png';
}
$data['total'] = $table->getTotal2($join,$where);
return $this->response(200,'成功',$data);
$data['total'] = $table->getTotal2($join, $where);
return $this->response(200, '成功', $data);
}
/*
/**
* 新增or修改or查看
* $group_id !=0为查看
* post存在id为新增
*
* */
/**
* @return \think\Response
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function saveAgent(){
public function saveAgent()
{
$m_agent = new AAgents();
$id = $this->params['id'];
$id = $this->params['id'];
if ($this->request->isPost()) {
if (empty($this->params['store_id'])) {
......@@ -138,22 +139,22 @@ class Agent extends Basic
$num = 0; //判断重复手机号
//新增或者编辑数据
if(empty($this->params['id'])) {
$num = $m_agent->getListDistrictTotal(['phone'=> $this->params['phone']]);
if (empty($this->params['id'])) {
$num = $m_agent->getListDistrictTotal([ 'phone' => $this->params['phone'] ]);
$data['create_time'] = date( 'Y-m-d H:i:s',time());
$data['update_time'] = date( 'Y-m-d H:i:s',time());
$id = 0;
$data['password'] = md5(substr($this->params['phone'], -6)); //默认号码后6位
$data['create_time'] = date('Y-m-d H:i:s', time());
$data['update_time'] = date('Y-m-d H:i:s', time());
$id = 0;
$data['password'] = md5(substr($this->params['phone'], -6)); //默认号码后6位
$data['auth_group_id'] = 5;
} else {
$agent_data = $m_agent->verifyUser('phone,password', '', ['id'=> $this->params['id']]);
$agent_data = $m_agent->verifyUser('phone,password', '', [ 'id' => $this->params['id'] ]);
if ($agent_data['phone'] != $this->params['phone']) {
$num = $m_agent->getListDistrictTotal(['phone'=>$this->params['phone']]);
$num = $m_agent->getListDistrictTotal([ 'phone' => $this->params['phone'] ]);
}
$data['update_time'] = date( 'Y-m-d H:i:s',time());
$data['update_time'] = date('Y-m-d H:i:s', time());
if (!empty($this->params['password']) && !empty($agent_data['password'])) {
$md5_password = md5($this->params['password']);
......@@ -163,17 +164,17 @@ class Agent extends Basic
}
}
if($num > 0) {
if ($num > 0) {
return $this->response(101, '手机号重复');
}
$data['district_id'] = $this->params['district_id'];
$data['name'] = trim($this->params['name']);
$data['store_id'] = $this->params['store_id'];
$data['phone'] = trim($this->params['phone']);
$data['admin_off'] = $this->params['admin_off'];
$data['sex'] = $this->params['sex'];
$data['remarks'] = $this->params['remarks'];
$data['name'] = trim($this->params['name']);
$data['store_id'] = $this->params['store_id'];
$data['phone'] = trim($this->params['phone']);
$data['admin_off'] = $this->params['admin_off'];
$data['sex'] = $this->params['sex'];
$data['remarks'] = $this->params['remarks'];
if ($m_agent->editData($data, $id)) {
return $this->response(200, '成功');
......@@ -182,7 +183,7 @@ class Agent extends Basic
}
} else {
//查看
$info = $m_agent->verifyUser('id,name,phone,password,district_id,store_id,sex,admin_off,remarks', '', ['id'=>$id]);
$info = $m_agent->verifyUser('id,name,phone,password,district_id,store_id,sex,admin_off,remarks', '', [ 'id' => $id ]);
return $this->response(200, '查看', $info);
}
}
......@@ -192,41 +193,44 @@ class Agent extends Basic
*
* @return \think\Response
*/
public function updateStatus(){
public function updateStatus()
{
$data = $this->request->param();
$ids = $data['ids'];
//排除超级管理员
if (is_array($ids)) {
if (in_array(1, $ids)) {
return $this->response(100,'超级管理员不允许操作',$data);
return $this->response(100, '超级管理员不允许操作', $data);
}
} else {
if ($ids === 1) {
return $this->response(100,'超级管理员不允许操作',$data);
return $this->response(100, '超级管理员不允许操作', $data);
}
}
$table = new AAgents();
if($table->saveStatus('status', $data['status'], $ids)){
return $this->response(200,'成功',$data);
}else{
return $this->response(100,'失败',$data);
if ($table->saveStatus('status', $data['status'], $ids)) {
return $this->response(200, '成功', $data);
} else {
return $this->response(100, '失败', $data);
}
}
/**
* 批量变更角色
*
* @post ids 用户组id
* @post group_id 变更的角色组id
*/
public function updateRole(){
*/
public function updateRole()
{
$table = New AAgents;
$data = $this->request->param();
$ids = trim($data['ids'],',');
$ids = trim($data['ids'], ',');
$code = 200;
if(!empty($ids) && !empty($data['group_id'])) {
if($table->saveStatus('auth_group_id', $data['group_id'], $ids)){
if (!empty($ids) && !empty($data['group_id'])) {
if ($table->saveStatus('auth_group_id', $data['group_id'], $ids)) {
$msg = '成功';
} else {
$code = 101;
......@@ -237,170 +241,6 @@ class Agent extends Basic
$code = 101;
}
return $this->response($code,$msg, $data);
}
/**
* 添加门店
* @throws \Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function shop_a_store(){
Db::table("agents")->execute('TRUNCATE `a_store`');
$field = '';
// $where='level=1';
$where['level'] = 1;
$where['father_id'] = 0;
$table = new AStore();
$region = new Regions();
$list = Db::table("agents")->field($field)->where($where)->select();
$data = [];
foreach ($list as $k=>$v){
//部门id
$district_id=Db::table("a_district")
->field('id')
->where("agent_id in(select agent_id from chiefs_agents where sub_agent_id='{$v['id']}')")
->value();
//去除无部门门店
if ($district_id == 0) {
continue;
}
$data[$k]['id']=$v['id'];/*id*/
if($district_id){
$data[$k]['district_id'] = $district_id;/*部门Id 对应部门表*/
}else{
$data[$k]['district_id']=0;/*部门Id 对应部门表*/
}
$data[$k]['store_name'] = trim($v['sub_shopname']);/*门店名*/
$data[$k]['scale'] = $v['scale'];/*门店规模 如1-22人*/
if ($v['province'] == '上海市') {
$data[$k]['province']= rtrim($v['province'], '市');/*省*/
}
if ($v['province'] == '南京市') {
$data[$k]['province']= '江苏省';/*省*/
}
$data[$k]['city']=$v['province'];/*市*/
$data[$k]['district']=$v['city'];/*区*/
$data[$k]['status']=$v['inuse'] == 1 ? 0 : $v['inuse'];/*状态 0 正常 1禁用*/
$code_arr = $region->getRegionsCodeByName($data[$k]['province'], $data[$k]['city'], $data[$k]['district']);
$data[$k]['code']=implode('##', $code_arr);
$data[$k]['address']=$v['address'];/*详细地址*/
$data[$k]['longitude']=$v['longitude'];/*经度*/
$data[$k]['latitude']=$v['latitude'];/*纬度*/
$data[$k]['create_time']=$v['created'];/**/
$data[$k]['update_time']=$v['modified'];/**/
}
var_dump($data);
$table->saveAll($data,false);
return $this->response($code, $msg, $data);
}
/**
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function agent_zhuan_aagent()
{
Db::table("a_agents")->execute('TRUNCATE `a_agents`');
$table2 = new Agents();
$field = 'id,device_id,father_id,role_id,level,realname,phone,password,sex,head_portrait,inuse,created,modified,is_inside';
$where['level'] = ['in','2,5'];
$where['father_id'] = ['<>', 0];
$list = $table2->field($field)->where($where)->select();
$li = collection($list)->toArray();//转化arr
$data=array();
foreach ($li as $k=> $v){
/*******************************************************************/
$district_id=Db::table("a_district")
->field('id')
->where("agent_id in(select agent_id from chiefs_agents where sub_agent_id='{$v['father_id']}')")
->value();
if($district_id){
$data[$k]['district_id']=$district_id;/*部门Id 对应部门表*/
}else{
continue;
$data[$k]['district_id']=0;/*部门Id 对应部门表*/
}
/*******************************************************************/
$data[$k]['id'] = $v['id'];/* '经济人表'*/
$data[$k]['device_id']=$v['device_id']; /* '设备id'*/
$data[$k]['store_id']=$v['father_id']; /* '门店id关联门店表'*/
switch ($v['role_id']){
case 6:/*旧总监*/
$data[$k]['auth_group_id']=4;
break;
case 4:/*旧店长*/
$data[$k]['auth_group_id']=3;
break;
case 7:/*业务员*/
$data[$k]['auth_group_id']=5;
break;
case 11:/*总负责人*/
$data[$k]['auth_group_id']=1;
break;
case 13:/*行政*/
$data[$k]['auth_group_id']=6;
break;
case 17:/*人事*/
$data[$k]['auth_group_id']=2;
break;
default :/*默认权限*/
$data[$k]['auth_group_id']=7;
}
/************************级别****************************************/
if($v['level']==2){
$data[$k]['level']=10;
}else if($v['level']==5){
$agent_id=Db::table("chieves")
->field('id')
->where("agent_id='{$v['id']}'")
->value();
if($agent_id){
$data[$k]['level']=40;
}else {
$data[$k]['level'] = 20;
}
}
/************************级别****************************************/
$data[$k]['name']=$v['realname']; /*'经济人姓名'*/
$data[$k]['phone']=$v['phone']; /*'手机号'*/
$data[$k]['password']=$v['password']; /*'登录密码'*/
$data[$k]['sex']=0; /*'性别 0保密 1男 2女'*/
$data[$k]['img']=$v['head_portrait']; /*'头像'*/
if($v['inuse']==1){
$data[$k]['status']=0; /*'账号状态,0正常 1冻结 2离职'*/
}else{
$data[$k]['status']=2;
}
$data[$k]['inviter_id']=0; /* '邀请人id'*/
$data[$k]['create_time']=$v['created'];
$data[$k]['update_time']=$v['modified']; /* 修改时间*/
$data[$k]['admin_off']=$v['is_inside']; /*'0可以访问后台,1不可以'*/
$data[$k]['remarks']=''; /*'备注'*/
// $data[$k]['last_login_ip']='';/* 'ip存入数字 php ip2long和long2ip转换'*/
// $data[$k]['last_login_time']=''; /*'最后登录时间'*/
// $data[$k]['quit_time']=''; /*'离职日期'*/
}
Db::table("a_agents")->insertAll($data);
var_dump($data);
}
}
\ No newline at end of file
......@@ -225,9 +225,6 @@ Route::group('index', [
'searchOrderAgents' => [ 'index/Finance/searchOrderAgents', [ 'method' => 'GET' ] ], //order_id获取盘方,客方,反签,独家,合作方
'getTallAgeList' => [ 'index/Finance/getTallAgeList', [ 'method' => 'GET' ] ], //税费承担明细表
'getCommissionTotalList' => [ 'index/Finance/getCommissionTotalList', [ 'method' => 'GET' ] ], //分佣提成汇总表
'test123' => [ 'index/WatchShop/test123', [ 'method' => 'get|post' ] ], //时间轴
'agent_zhuan_aagent' => [ 'index/agent/agent_zhuan_aagent', [ 'method' => 'post|get' ] ],//经纪人
'shop_a_store' => [ 'index/agent/shop_a_store', [ 'method' => 'post|get' ] ],//经纪人
'getCollection' => [ 'index/Collection/getCollection', [ 'method' => 'post|get' ] ],//收款记录
'addRealMoney' => [ 'index/Collection/addRealMoney', [ 'method' => 'post' ] ],//新增实收
'visitShop' => [ 'index/Supervise/visitShop', [ 'method' => 'get' ] ],//门店拜访
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment