Commit e9ba5d9b authored by hujun's avatar hujun

经纪人编辑和权限控制

parent ad458d8b
......@@ -117,41 +117,42 @@ class Agent extends Basic
*/
public function saveAgent(){
$m_agent = new AAgents();
$m_agent = new AAgents();
$id = $this->params['id'];
if ($this->request->isPost()) {
if (empty($this->params['store_id'])) {
return $this->response(101, '门店id为空!');
}
$password = $m_agent->verifyUser('password', '', ['phone'=> $this->params['phone']]);
//新增或者编辑数据
if(empty($this->params['id'])) {
//判断name是否重复
if(!empty($password)) {
return $this->response(101, '手机号重复');
}
$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['password'], -6)); //默认号码后6位
} else {
$data['update_time'] = date( 'Y-m-d H:i:s',time());
$id = $this->params['id'];
}
//判断name是否重复
if(empty($id)) {
$num = $m_agent->getListDistrictTotal(['phone'=> $this->params['phone']]);
if ($num > 0) {
return $this->response(101, '手机号重复');
if (!empty($this->params['password'])) {
$md5_password = md5($this->params['password']);
if (($md5_password != $password['password']) && ($password['password'] != $this->params['password'])) {
$data['password'] = $md5_password;
}
}
}
if (empty($this->params['store_id'])) {
return $this->response(101, '门店id为空!');
}
$store = new AStore();
$store = new AStore();
$data['district_id'] = $store->getStoreKeyById('district_id', ['id'=>$this->params['store_id']]);
if (empty($data['password'])) {
$data['password'] = md5(substr($this->params['password'], -6));
} else {
$data['password'] = md5($this->params['password']);
}
$data['name'] = trim($this->params['name']);
$data['store_id'] = $this->params['store_id'];
$data['phone'] = trim($this->params['phone']);
......@@ -159,7 +160,7 @@ class Agent extends Basic
$data['sex'] = $this->params['sex'];
$data['remarks'] = $this->params['remarks'];
$data['auth_group_id'] = $this->params['auth_group_id'];
dump($this->params);die;
if ($m_agent->editData($data, $id)) {
return $this->response(200, '成功');
} else {
......@@ -167,7 +168,7 @@ class Agent extends Basic
}
} else {
//查看
$info = $m_agent->where('id',$group_id)->find();
$info = $m_agent->verifyUser('id,name,phone,password,store_id,sex,admin_off,remarks', '', ['id'=>$id]);
return $this->response(200, '查看', $info);
}
}
......@@ -214,23 +215,17 @@ class Agent extends Basic
if($table->saveStatus('auth_group_id', $data['group_id'], $ids)){
$msg = '成功';
} else {
$code = '100';
$code = 101;
$msg = '失败';
}
} else {
$msg = '数据为空';
$code = 100;
$code = 101;
}
return $this->response($code,$msg, $data);
}
//
public function shop_district(){
}
/**
* 添加门店
* @throws \Exception
......
......@@ -77,8 +77,8 @@
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
×
</button>
<h4 class="modal-title">
经纪人信息
<h4 class="modal-title" id="title">
经纪人编辑
</h4>
</div>
<div class="modal-body">
......@@ -94,7 +94,7 @@
</div>
<div class="form-group hide">
<label class="col-sm-3 control-label">密码:</label>
<input type="number" class="form-control btn6" name="password" id="password" value="" placeholder="填写密码">
<input type="text" class="form-control btn6" name="password" id="password" value="44444" placeholder="填写密码">
</div>
<div class="form-group">
<label class="col-sm-3 control-label">绑定门店ID:</label>
......@@ -169,7 +169,7 @@
<form class="form-horizontal">
<div class="form-group">
<label class="col-sm-3 control-label">权限角色:</label>
<select name="status" class="form-control btn6" id="User_add">
<select name="status" class="form-control btn6" id="edit_role">
</select>
</div>
</form>
......
define(['doT', 'text!temp/agent_template_tpl.html', 'css!style/home.css', 'pagination', 'bootstrapJs'], function (doT, template) {
var agent = {
pageNo: 1,
pageSize: 15,
pageNo : 1,
pageSize : 15,
agent_id : 0,
init: function () {
//初始化dot
$("body").append(template);
......@@ -19,37 +20,34 @@ define(['doT', 'text!temp/agent_template_tpl.html', 'css!style/home.css', 'pagin
});
$(document).delegate(".agent_add", "click", function () {//新增
$("#title").html("新增经纪人");
$("#password").parent().addClass('hide'); //新增不显示密码
$(".form-horizontal")[0].reset(); //重置表单
});
$(document).delegate(".edit", "click", function () {//点击编辑
$("#title").html("编辑经纪人");
$(".form-horizontal")[0].reset(); //重置表单
agent.house_id = $(this).attr("data-id");
agent.agent_id = $(this).attr("data-id");
$("#password").parent().removeClass('hide'); //编辑显示密码
agent.Edit();
});
$(document).delegate("#password", "click",function () {
$(this).val('').attr('type','password');
});
$(document).delegate(".submit_edit", "click", function () {//提交编辑
agent.Submit_edit();
});
$(document).delegate(".User_add", "click", function () {//点击变更
var vv = '';
var _idsv = '';
$("input[name=ids]:checked").each(function (i) {
vv += ',' + $(this).val();
_idsv = vv.substring(1);
});
if (_idsv == "0" || _idsv == "") {
alert("你还没有选择");
} else {
agent.User_add();
}
$(document).delegate("#role", "click", function () {//变更角色
agent.agent_id = $(this).attr("data-id");
agent.getRole();
});
$(document).delegate(".submit_user", "click", function () {//提交变更
agent.Submit_user();
agent.getList();
});
$(document).delegate(".is_show", "click", function () {//点击禁用
......@@ -63,9 +61,11 @@ define(['doT', 'text!temp/agent_template_tpl.html', 'css!style/home.css', 'pagin
params.id = $(this).attr("data-id");
var str = $.trim($(this).html());
if (str === "正常") {
$(this).attr('class','btn1 btn-default is_show');
params.type = 1;
$(this).html('冻结');
} else if (str === "冻结") {
$(this).attr('class','btn1 btn-info is_show');
params.type = 0;
$(this).html('正常');
} else {
......@@ -82,24 +82,18 @@ define(['doT', 'text!temp/agent_template_tpl.html', 'css!style/home.css', 'pagin
}
}
});
});
},
Submit_user: function () {//提交变更的信息
var v = '';
var _ids = '';
$("input[name=ids]:checked").each(function (i) {
v += ',' + $(this).val();
_ids = v.substring(1);
})
var group_id = $("#User_add").val();
var group_id = $("#edit_role").val();
$.ajax({
'type': 'POST',
'url': '/index/updateRole',
data: { 'ids': _ids, 'group_id': group_id },
data: { 'ids': agent.agent_id, 'group_id': group_id },
dataType: "json",
success: function (data) {
if (data.code == 200) {
agent.getList(1);
} else {
alert("重复提交");
}
......@@ -110,7 +104,7 @@ define(['doT', 'text!temp/agent_template_tpl.html', 'css!style/home.css', 'pagin
$.ajax({
'type': 'GET',
'url': '/index/saveAgent',//获取编辑数据
data: { "id": agent.house_id },
data: { "id": agent.agent_id },
dataType: "json",
success: function (data) {
......@@ -121,6 +115,7 @@ define(['doT', 'text!temp/agent_template_tpl.html', 'css!style/home.css', 'pagin
$("input[name = store_id]").val(data.data.store_id);
$("#admin_off").val(data.data.admin_off);
$("#remarks").val(data.data.remarks);
$("#password").val(data.data.password);
$("input[name='password']").attr('form-group');
if (data.data.sex == '0') {
$("#sex0").attr('checked', true);
......@@ -139,7 +134,7 @@ define(['doT', 'text!temp/agent_template_tpl.html', 'css!style/home.css', 'pagin
Submit_edit: function () {
//提交编辑的信息
var params = {}
params.id = agent.house_id;
params.id = agent.agent_id;
params.name = $("input[name = name]").val();
params.password = $("#password").val();
params.store_id = $("input[name = store_id]").val();
......@@ -175,7 +170,7 @@ define(['doT', 'text!temp/agent_template_tpl.html', 'css!style/home.css', 'pagin
dataType: "json",
success: function (data) {
if (data.code == 200) {
$("#modal-edit").model('hide');
$("#modal-edit").modal('hide');
agent.getList(1);
} else {
alert(data.msg);
......@@ -206,6 +201,23 @@ define(['doT', 'text!temp/agent_template_tpl.html', 'css!style/home.css', 'pagin
add_page(data.data.total, pageNo, agent.pageSize, agent.getList);
}
})
},
getRole : function () {
$.ajax({
url: '/index/getAuth2',
type: 'GET',
data:{},
async: true,
dataType: 'json',
success: function (data) {
var User_add="";
$.each(data.data.list,function(i,item){
User_add+='<option value="'+item.id+'">'+item.title+'</option>';
});
$("#edit_role").html(User_add);
}
});
}
};
return agent;
......
......@@ -17,11 +17,14 @@
[% if(it[item]["status"] == 0) { %]
<a class="btn1 btn-info is_show" data-toggle="modal" data-id='[%= it[item]["id"] %]'>正常</a>
[% }else if(it[item]["status"] == 1) { %]
<a class="btn1 btn-info is_show" data-toggle="modal" data-id='[%= it[item]["id"] %]'>冻结</a>
<a class="btn1 btn-default is_show" data-toggle="modal" data-id='[%= it[item]["id"] %]'>冻结</a>
[% }else{ %]
<a class="btn1 btn-default" data-toggle="modal" data-id='[%= it[item]["id"] %]'>离职</a>
[% } %]
<a href="#modal-user" class="btn1 btn-danger" href="#modal-edit" data-toggle="modal" data-id='[%= it[item]["id"] %]'>角色设置</a>
[% if(check_auth('index/updateRole')) {%]
<a href="#modal-user" class="btn1 btn-danger" id='role' href="#modal-edit" data-toggle="modal" data-id='[%= it[item]["id"] %]'>角色设置</a>
[% } %]
</td>
</tr>
[% } %]
......
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