作者 景龙
1 个管道 的构建 通过 耗费 5 秒

修改指派人员,增加内部人员管理

<?php
namespace app\admin\controller;
use app\common\controller\Backend;
use app\admin\model\Temp;
use app\admin\model\Sell;
use app\admin\model\Assign;
use think\Db;
/**
*
*
* @icon fa fa-circle-o
*/
class Appoint extends Backend
{
/**
* Staff模型对象
* @var \app\admin\model\Staff
*/
protected $model = null;
public function _initialize()
{
parent::_initialize();
$this->model = new \app\admin\model\Staff;
}
/**
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
*/
/**
* 查看
*/
public function index($ids='')
{
$tempModel = new Temp();
$tempModel->where('id',1)->update(['s_id'=>$ids]);
//当前是否为关联查询
$this->relationSearch = true;
//设置过滤方法
$this->request->filter(['strip_tags']);
if ($this->request->isAjax())
{
//如果发送的来源是Selectpage,则转发到Selectpage
if ($this->request->request('keyField'))
{
return $this->selectpage();
}
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$total = $this->model
->with(['user'])
->where($where)
->order($sort, $order)
->count();
$list = $this->model
->with(['user'])
->where($where)
->order($sort, $order)
->limit($offset, $limit)
->select();
foreach ($list as $row) {
$row->getRelation('user')->visible(['openid','username','nickname','avatar','mobile','type','inner_staff','start','address','money','score','status']);
}
$list = collection($list)->toArray();
$result = array("total" => $total, "rows" => $list);
return json($result);
}
$this->assignconfig("sid",$ids);
return $this->view->fetch();
}
//设置内部人员
public function appoint_staff($ids = ''){
if ($ids) {
$assignModel = new Assign();
$tempModel = new Temp();
$temp = $tempModel->where('id',1)->find();
$s_id = $temp['s_id'];
$result = $assignModel->save(['u_id'=>$ids,'s_id'=>$s_id]);
if ($result) {
$this->success('成功');
} else {
$this->error('失败');
}
}
$this->error(__('Parameter %s can not be empty', 'ids'));
}
}
... ...
... ... @@ -66,7 +66,7 @@ class Sell extends Backend
foreach ($list as $row) {
$row->getRelation('user')->visible(['username','avatar']);
$row->getRelation('user')->visible(['username','avatar','mobile']);
}
$list = collection($list)->toArray();
$result = array("total" => $total, "rows" => $list);
... ...
<?php
return [
'Id' => 'ID',
'User.username' => '用户名',
'User.nickname' => '昵称',
'User.type' => '类型',
'User.mobile' => '手机号',
'User.avatar' => '头像',
'User.start' => '开工状态',
'User.score' => '积分',
'User.money' => '余额',
'User.address' => '上门地址',
'User.status' => '状态',
];
... ...
... ... @@ -11,5 +11,6 @@ return [
'status' => '状态',
'Createtime' => '创建时间',
'User.username' => '用户名',
'User.avatar' => '头像'
'User.avatar' => '头像',
'User.mobile' => '手机号'
];
... ...
<?php
namespace app\admin\model;
use think\Model;
class Temp extends Model
{
// 表名
protected $name = 'temp';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
}
... ...
<div class="panel panel-default panel-intro">
{:build_heading()}
<div class="panel-body">
<div id="myTabContent" class="tab-content">
<div class="tab-pane fade active in" id="one">
<div class="widget-body no-padding">
<div id="toolbar" class="toolbar">
<a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
<div class="dropdown btn-group {:$auth->check('staff/multi')?'':'hide'}">
<ul class="dropdown-menu text-left" role="menu">
<li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=normal"><i class="fa fa-eye"></i> {:__('Set to normal')}</a></li>
<li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=hidden"><i class="fa fa-eye-slash"></i> {:__('Set to hidden')}</a></li>
</ul>
</div>
</div>
<table id="table" class="table table-striped table-bordered table-hover table-nowrap"
data-operate-edit="{:$auth->check('staff/edit')}"
data-operate-del="{:$auth->check('staff/del')}"
width="100%">
</table>
</div>
</div>
</div>
</div>
</div>
... ...
... ... @@ -7,6 +7,7 @@
<div class="widget-body no-padding">
<div id="toolbar" class="toolbar">
<a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
<!--<a href="javascript:;" class="btn btn-success btn-disabled disabled {:$auth->check('sscore/edit')?'':'hide'}" title="{:__('选择人员')}" >{:__('选择人员')}</a>-->
<div class="dropdown btn-group {:$auth->check('staff/multi')?'':'hide'}">
<ul class="dropdown-menu text-left" role="menu">
<li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=normal"><i class="fa fa-eye"></i> {:__('Set to normal')}</a></li>
... ...
此 diff 太大无法显示。
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
var Controller = {
index: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'appoint/index',
// add_url: 'staff/add',
// edit_url: 'appoint/edit',
// del_url: 'staff/del',
// multi_url: 'staff/multi',
table: 'staff',
},
queryParams: function (params) { //自定义搜索条件
params.ids = Config.sid;//将搜索过滤器和操作方法 都转为JSON字符串
return params;
}
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
columns: [
[
{checkbox: true},
{field: 'id', title: __('Id')},
{field: 'user.username', title: __('User.username')},
{field: 'user.nickname', title: __('User.nickname')},
{field: 'user.type', title: __('User.type'),formatter: Table.api.formatter.label,searchList: {0: __('Person'), 1: __('Company')}},
{field: 'user.mobile', title: __('User.mobile')},
{field: 'user.avatar', title: __('User.avatar'),formatter: Table.api.formatter.image, operate: false},
{field: 'user.address', title: __('User.address')},
{field: 'user.start', title: __('User.start'),formatter: Table.api.formatter.label,searchList: {0: __('未开工'), 1: __('已开工')}},
{field: 'user.score', title: __('user.score'), operate: 'BETWEEN', sortable: true},
{field: 'user.money', title: __('User.money')},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,buttons:[
{
name: 'ajax',
text: __('指派'),
title: __('指派'),
classname: 'btn btn-xs btn-success btn-magic btn-ajax',
icon: 'fa',
url: 'appoint/appoint_staff',
confirm: '确认指派此人员',
success: function (data, ret) {
Layer.alert(ret.msg);
$(".btn-refresh").trigger("click");
//如果需要阻止成功提示,则必须使用return false;
//return false;
},
error: function (data, ret) {
Layer.alert(ret.msg);
return false;
},visible: function (row) {
if(row.user.start == 0){
return false;//隐藏
}else{
return true;
}
}
}
]}
]
]
});
// 为表格绑定事件
Table.api.bindevent(table);
},
add: function () {
Controller.api.bindevent();
},
edit: function () {
Controller.api.bindevent();
},
api: {
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
}
}
};
return Controller;
});
\ No newline at end of file
... ...
... ... @@ -28,6 +28,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
{field: 'fullname', title: __('Fullname')},
{field: 'user.username', title: __('User.username')},
{field: 'user.avatar', title: __('User.avatar'), formatter: Table.api.formatter.image},
{field: 'user.mobile', title: __('User.mobile')},
{field: 'address', title: __('Address')},
{field: 'pre_date', title: __('Pre_date'), operate:'RANGE', addclass:'datetimerange'},
{field: 'pre_time', title: __('Pre_time')},
... ... @@ -83,6 +84,24 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
return true;
}
}
},
{
name: 'staff',
text: '指派',
title: '指派',
icon: 'fa fa-list',
classname: 'btn btn-xs btn-success btn-dialog',
url: "appoint/index",
// url:function(row){
// return 'appoint/appoint_index?s_id='+row.id;
// },
visible: function (row) {
if(row.status == 1){
return true;
}else{
return false;//隐藏
}
}
}
]}
]
... ...
... ... @@ -30,11 +30,20 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
{field: 'user.type', title: __('User.type'),formatter: Table.api.formatter.label,searchList: {0: __('Person'), 1: __('Company')}},
{field: 'user.mobile', title: __('User.mobile')},
{field: 'user.avatar', title: __('User.avatar'),formatter: Table.api.formatter.image, operate: false},
{field: 'user.address', title: __('User.address')},
{field: 'user.start', title: __('User.start'),formatter: Table.api.formatter.label,searchList: {0: __('未开工'), 1: __('已开工')}},
{field: 'user.score', title: __('user.score'), operate: 'BETWEEN', sortable: true},
{field: 'user.money', title: __('User.money')},
{field: 'user.address', title: __('User.address')},
// {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,buttons:[
{
name: 'assign',
text: '我的分配',
title: '我的分配',
icon: 'fa fa-list',
classname: 'btn btn-xs btn-success btn-dialog',
url: "assign/index"
},
]}
]
]
});
... ...