Commit 5ea6ecbe authored by zfc's avatar zfc Committed by hujun

经纪人列表接口

parent 29c59b60
......@@ -26,6 +26,7 @@ use app\index\extend\Basic;
use app\model\AuthGroup;
use app\model\AuthRule;
use app\model\AAgents;
use app\model\AuthGroupAccess;
use think\Db;
use think\Session;
......@@ -88,16 +89,102 @@ class Agent extends Basic
return $this->response(200,'成功',$data);
}
//新增or修改
public function saveAgent(){
/*
* 新增or修改or查看
* $group_id !=0为查看
* post存在id为新增
*
* */
public function saveAgent($group_id=0){
$table= New AAgents;
if (IS_POST && $group_id==0) {
$data = input('post.');
$id = isset($data['id']) && $data['id']>0 ? $data['id']:false;
//判断name是否重复
if($table->repetition('phone',$data['phone'])&& empty($id)){
return $this->response(100, '存在重复值');
}
//新增或者编辑数据
//prt($data);
if ($table->editData($data,$id)) {
return $this->response(200, '成功');
} else {
return $this->response(100, '无修改');
}
} else {
//查看
$info= $table->where('id',$group_id)->find();
//echo $table->getLastSql();
return $this->response(200, '查看', $info);
}
}
//删除(冻结)
public function updateStatus(){
$data=$this->request->param();
$ids=$data['ids'];
//排除超级管理员
if (is_array($ids)) {
if (in_array(1, $ids)) {
return $this->response(100,'超级管理员不允许操作',$data);
}
} else {
if ($ids === 1) {
return $this->response(100,'超级管理员不允许操作',$data);
}
}
$table= New AAgents;
if($table->saveStatus($data['name'],$data['k'],$ids)){
return $this->response(200,'成功',$data);
}else{
return $this->response(100,'失败',$data);
}
}
//批量变更角色
/**
* 批量变更角色
* @post ids 用户组id
* @post idname 实际id名(auth_group_access表无id)
* @post group_id 变更的角色组id
*/
public function updateRole(){
$table=New AAgents;
$table2=New AuthGroupAccess;
$data=$this->request->param();
$ids=$data['ids'];
//1.清空原有数据
if(!empty($ids)&&!empty($data['group_id'])&&!empty($data['idname'])){
if($table2->delUid($data['idname'],$ids)){
//2.从新分发角色
$data2['group_id']=$data['group_id'];
if($table->addAllAccess($ids,$data2)){
return $this->response(200,'成功',$data);
}else{
return $this->response(100,'失败',$data);
}
}
}
}
//
......
......@@ -88,10 +88,13 @@ class Auth extends Basic
}
//添加角色
/*
* 新增or修改or查看
* $group_id !=0为查看
* post存在id为新增
*
* */
public function addAuth($group_id=0){
$data['status'] = 200;
$data['msg'] = '';
$title = $group_id ? '编辑':'新增';
$table= New AuthGroup();
......
......@@ -60,6 +60,7 @@ class Basic extends Controller
}
/**
* 验证登录时效
*/
......
......@@ -30,5 +30,45 @@ public function saveList(){
return $data;
}
/**
*检查重复
*
*/
public function repetition($name,$key){
$r=$this->field($name)
->where($name,'=',$key)
->select();
//$this->getLastSql();
if($r){
return true;
}else{
return false;
}
}
//更新数据
public function saveStatus($name,$key,$ids){
$r = $this->save([$name,$key],["id",'in',$ids]);
return $r;
}
//删除数据
public function delUid($name,$ids){
$this->where($name,'in',$ids)->delete();
}
//通过ids批量添加数据
public function addAllAccess($ids,$data){
$idarr=explode($ids);
if(is_array($idarr)){
$arr=array();
foreach ($idarr as $v){
$data['uid']=$v;
$arr[]=$data;
}
$r= $this->saveAll($arr);
}else{
$data['uid']=$ids;
$r= $this->save($data);
}
return $r;
}
}
\ No newline at end of file
<?php
// 权限模型
namespace app\admin\model;
namespace app\model;
class AuthGroupAccess extends Base
use think\Model;
class AuthGroupAccess extends BaseModel
{
// 设置完整的数据表(包含前缀)
// protected $table = 'think_access';
......@@ -33,7 +35,13 @@ class AuthGroupAccess extends Base
return false;
}
public function delUid($name,$ids){
$r=$this->where($name,'in',$ids)->delete();
return $r;
}
/**
* 获取组对应的用户Uids
* @param string $group_id [description]
......
......@@ -4,9 +4,9 @@
[% for(var item in it){ %]
[% if(it[item]['pid']!=0){ %]
<option value="[%= it[item]['id'] %]">&nbsp;&nbsp;[%= it[item]["title"] %]&nbsp;</option>
<option value="[%= it[item]['id'] %]">[%= it[item]["title_show"] %]</option>
[% }else{ %]
<option value="[%= it[item]['id'] %]">[%= it[item]["title"] %]&nbsp;</option>
<option value="[%= it[item]['id'] %]">[%= it[item]["title_show"] %]</option>
[% } %]
[% } %]
......
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