作者 jinglong
1 个管道 的构建 通过 耗费 9 秒

增加后台内部人员管理

<?php
namespace app\admin\controller;
use app\common\controller\Backend;
use app\admin\model\User;
use think\Db;
/**
*
*
* @icon fa fa-circle-o
*/
class Staff 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()
{
//当前是否为关联查询
$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);
}
return $this->view->fetch();
}
//设置内部人员
public function set($ids){
if ($ids) {
$userModel = new User();
$pk = $userModel->getPk();
//设置成为内部人员
$result2 = $userModel->where($pk, '=', $ids)->where(['status' => 'normal','inner_staff'=>0])->update(['inner_staff' => 1]);
//插入内部人员数据
$result = $this->model->save(['uid'=>$ids]);
if ($result2 && $result) {
$this->success('成功');
} else {
$this->error('失败');
}
}
$this->error(__('Parameter %s can not be empty', 'ids'));
}
}
... ...
<?php
return [
'Id' => 'ID',
'User.username' => '用户名',
'User.nickname' => '昵称',
'User.type' => '类型',
'User.mobile' => '手机号',
'User.avatar' => '头像',
'User.start' => '开工状态',
'User.score' => '积分',
'User.money' => '余额',
'User.address' => '上门地址',
'User.status' => '状态',
];
... ...
<?php
namespace app\admin\model;
use think\Model;
class Staff extends Model
{
// 表名
protected $name = 'staff';
// 自动写入时间戳字段
protected $autoWriteTimestamp = false;
// 定义时间戳字段名
protected $createTime = false;
protected $updateTime = false;
// 追加属性
protected $append = [
];
public function user()
{
return $this->belongsTo('User', 'uid', 'id', [], 'LEFT')->setEagerlyType(0);
}
}
... ...
<?php
namespace app\admin\validate;
use think\Validate;
class Staff extends Validate
{
/**
* 验证规则
*/
protected $rule = [
];
/**
* 提示消息
*/
protected $message = [
];
/**
* 验证场景
*/
protected $scene = [
'add' => [],
'edit' => [],
];
}
... ...
<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>
... ...
... ... @@ -46,6 +46,7 @@ class Person extends Api
"license_img": ""//公司营业执照
"money":100//账户余额
"avatar"://头像
"start"://是否开工 0:下班 1:上班
}
})
*/
... ... @@ -53,7 +54,7 @@ class Person extends Api
if($this->request->isGet()){
$data = Db::table('gc_user')
->where(['id'=>$this->user_id])
->field('id,nickname,username,mobile,type,address,id_num,id_img,company_name,license_num,license_img,money,avatar')
->field('id,nickname,username,mobile,type,address,id_num,id_img,company_name,license_num,license_img,money,avatar,start')
->find();
$this->success('成功', $data);
}else{
... ... @@ -396,4 +397,37 @@ class Person extends Api
return true;
}
/**
* @ApiTitle (开工)
* @ApiSummary (开工)
* @ApiMethod (POST)
* @ApiRoute (/api/person/start)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="status", type="integer", required=true, description="是否开工 0:下班;1:上班")
* @ApiReturn ({
"code": 1,
"msg": "成功",
"time": "1555652055",
"data": null
})
*/
public function start(){
if($this->request->isPost()) {
$status = $this->request->post('status');//状态 0:下班,1:上班
$rule = config('site.start');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['status'=>$status])) {
$this->error($validate->getError());
}
$user = new \app\admin\model\User();
$data1 = $user->where(['id'=>$this->user_id])->update(['start'=>$status]);
if($data1){
$this->success('成功');
}else{
$this->error('失败');
}
}else{
$this->error('请求方式错误');
}
}
}
... ...
... ... @@ -331,4 +331,13 @@ return array (
'id.require' => '购物车id不能为空',
]
],
'start' => [
'rule' => [
'status' => 'require|number',
],
'msg' => [
'status.require' => '开工状态不能为空',
'status.number' => '开工状态必须为数字',
]
],
);
\ No newline at end of file
... ...
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
var Controller = {
index: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'staff/index',
// add_url: 'staff/add',
// edit_url: 'staff/edit',
// del_url: 'staff/del',
multi_url: 'staff/multi',
table: 'staff',
}
});
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.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}
]
]
});
// 为表格绑定事件
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
... ...
... ... @@ -36,6 +36,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
{field: 'money', title: __('Money')},
// {field: 'level', title: __('Level'), operate: 'BETWEEN', sortable: true},
{field: 'address', title: __('Address')},//上门地址
{field: 'inner_staff', title: __('是否是内部人员'),formatter: Table.api.formatter.label,searchList: {0: __('非'), 1: __('是')}},
// {field: 'gender', title: __('Gender'), visible: false, searchList: {1: __('Male'), 0: __('Female')}},
// {field: 'successions', title: __('Successions'), visible: false, operate: 'BETWEEN', sortable: true},
// {field: 'maxsuccessions', title: __('Maxsuccessions'), visible: false, operate: 'BETWEEN', sortable: true},
... ... @@ -45,7 +46,39 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
// {field: 'joinip', title: __('Joinip'), formatter: Table.api.formatter.search},
{field: 'status', title: __('Status'), formatter: Table.api.formatter.status, searchList: {normal: __('Normal'), hidden: __('Hidden')}},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,buttons: [
{name: 'offline', text: '我的团队', title: '我的团队', icon: 'fa fa-list', classname: 'btn btn-xs btn-success btn-dialog', url: "off/line/offline"}
{
name: 'offline',
text: '我的团队',
title: '我的团队',
icon: 'fa fa-list',
classname: 'btn btn-xs btn-success btn-dialog',
url: "off/line/offline"
},
{
name: 'ajax',
text: __('设置'),
title: __('设置'),
classname: 'btn btn-xs btn-success btn-magic btn-ajax',
icon: 'fa',
url: 'staff/set',
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.inner_staff == 1){
return false;//隐藏
}else{
return true;
}
}
}
]}
]
]
... ...