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

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

  1 +<?php
  2 +
  3 +namespace app\admin\controller;
  4 +
  5 +use app\common\controller\Backend;
  6 +use app\admin\model\Temp;
  7 +use app\admin\model\Sell;
  8 +use app\admin\model\Assign;
  9 +use think\Db;
  10 +
  11 +/**
  12 + *
  13 + *
  14 + * @icon fa fa-circle-o
  15 + */
  16 +class Appoint extends Backend
  17 +{
  18 +
  19 + /**
  20 + * Staff模型对象
  21 + * @var \app\admin\model\Staff
  22 + */
  23 + protected $model = null;
  24 +
  25 + public function _initialize()
  26 + {
  27 + parent::_initialize();
  28 + $this->model = new \app\admin\model\Staff;
  29 + }
  30 +
  31 + /**
  32 + * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  33 + * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  34 + * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  35 + */
  36 +
  37 +
  38 + /**
  39 + * 查看
  40 + */
  41 + public function index($ids='')
  42 + {
  43 + $tempModel = new Temp();
  44 + $tempModel->where('id',1)->update(['s_id'=>$ids]);
  45 + //当前是否为关联查询
  46 + $this->relationSearch = true;
  47 + //设置过滤方法
  48 + $this->request->filter(['strip_tags']);
  49 + if ($this->request->isAjax())
  50 + {
  51 + //如果发送的来源是Selectpage,则转发到Selectpage
  52 + if ($this->request->request('keyField'))
  53 + {
  54 + return $this->selectpage();
  55 + }
  56 + list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  57 + $total = $this->model
  58 + ->with(['user'])
  59 + ->where($where)
  60 + ->order($sort, $order)
  61 + ->count();
  62 +
  63 + $list = $this->model
  64 + ->with(['user'])
  65 + ->where($where)
  66 + ->order($sort, $order)
  67 + ->limit($offset, $limit)
  68 + ->select();
  69 +
  70 + foreach ($list as $row) {
  71 +
  72 + $row->getRelation('user')->visible(['openid','username','nickname','avatar','mobile','type','inner_staff','start','address','money','score','status']);
  73 + }
  74 + $list = collection($list)->toArray();
  75 + $result = array("total" => $total, "rows" => $list);
  76 + return json($result);
  77 + }
  78 + $this->assignconfig("sid",$ids);
  79 + return $this->view->fetch();
  80 +
  81 + }
  82 +
  83 + //设置内部人员
  84 + public function appoint_staff($ids = ''){
  85 + if ($ids) {
  86 + $assignModel = new Assign();
  87 + $tempModel = new Temp();
  88 + $temp = $tempModel->where('id',1)->find();
  89 + $s_id = $temp['s_id'];
  90 + $result = $assignModel->save(['u_id'=>$ids,'s_id'=>$s_id]);
  91 + if ($result) {
  92 + $this->success('成功');
  93 + } else {
  94 + $this->error('失败');
  95 + }
  96 + }
  97 + $this->error(__('Parameter %s can not be empty', 'ids'));
  98 + }
  99 +}
@@ -66,7 +66,7 @@ class Sell extends Backend @@ -66,7 +66,7 @@ class Sell extends Backend
66 66
67 foreach ($list as $row) { 67 foreach ($list as $row) {
68 68
69 - $row->getRelation('user')->visible(['username','avatar']); 69 + $row->getRelation('user')->visible(['username','avatar','mobile']);
70 } 70 }
71 $list = collection($list)->toArray(); 71 $list = collection($list)->toArray();
72 $result = array("total" => $total, "rows" => $list); 72 $result = array("total" => $total, "rows" => $list);
  1 +<?php
  2 +
  3 +return [
  4 + 'Id' => 'ID',
  5 + 'User.username' => '用户名',
  6 + 'User.nickname' => '昵称',
  7 + 'User.type' => '类型',
  8 + 'User.mobile' => '手机号',
  9 + 'User.avatar' => '头像',
  10 + 'User.start' => '开工状态',
  11 + 'User.score' => '积分',
  12 + 'User.money' => '余额',
  13 + 'User.address' => '上门地址',
  14 + 'User.status' => '状态',
  15 +];
@@ -11,5 +11,6 @@ return [ @@ -11,5 +11,6 @@ return [
11 'status' => '状态', 11 'status' => '状态',
12 'Createtime' => '创建时间', 12 'Createtime' => '创建时间',
13 'User.username' => '用户名', 13 'User.username' => '用户名',
14 - 'User.avatar' => '头像' 14 + 'User.avatar' => '头像',
  15 + 'User.mobile' => '手机号'
15 ]; 16 ];
  1 +<?php
  2 +
  3 +namespace app\admin\model;
  4 +
  5 +use think\Model;
  6 +
  7 +class Temp extends Model
  8 +{
  9 + // 表名
  10 + protected $name = 'temp';
  11 +
  12 + // 自动写入时间戳字段
  13 + protected $autoWriteTimestamp = 'int';
  14 +}
  1 +<div class="panel panel-default panel-intro">
  2 + {:build_heading()}
  3 +
  4 + <div class="panel-body">
  5 + <div id="myTabContent" class="tab-content">
  6 + <div class="tab-pane fade active in" id="one">
  7 + <div class="widget-body no-padding">
  8 + <div id="toolbar" class="toolbar">
  9 + <a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
  10 + <div class="dropdown btn-group {:$auth->check('staff/multi')?'':'hide'}">
  11 + <ul class="dropdown-menu text-left" role="menu">
  12 + <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>
  13 + <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>
  14 + </ul>
  15 + </div>
  16 + </div>
  17 + <table id="table" class="table table-striped table-bordered table-hover table-nowrap"
  18 + data-operate-edit="{:$auth->check('staff/edit')}"
  19 + data-operate-del="{:$auth->check('staff/del')}"
  20 + width="100%">
  21 + </table>
  22 + </div>
  23 + </div>
  24 +
  25 + </div>
  26 + </div>
  27 +</div>
@@ -7,6 +7,7 @@ @@ -7,6 +7,7 @@
7 <div class="widget-body no-padding"> 7 <div class="widget-body no-padding">
8 <div id="toolbar" class="toolbar"> 8 <div id="toolbar" class="toolbar">
9 <a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a> 9 <a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
  10 + <!--<a href="javascript:;" class="btn btn-success btn-disabled disabled {:$auth->check('sscore/edit')?'':'hide'}" title="{:__('选择人员')}" >{:__('选择人员')}</a>-->
10 <div class="dropdown btn-group {:$auth->check('staff/multi')?'':'hide'}"> 11 <div class="dropdown btn-group {:$auth->check('staff/multi')?'':'hide'}">
11 <ul class="dropdown-menu text-left" role="menu"> 12 <ul class="dropdown-menu text-left" role="menu">
12 <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> 13 <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 太大无法显示。
  1 +define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2 +
  3 + var Controller = {
  4 + index: function () {
  5 + // 初始化表格参数配置
  6 + Table.api.init({
  7 + extend: {
  8 + index_url: 'appoint/index',
  9 + // add_url: 'staff/add',
  10 + // edit_url: 'appoint/edit',
  11 + // del_url: 'staff/del',
  12 + // multi_url: 'staff/multi',
  13 + table: 'staff',
  14 + },
  15 + queryParams: function (params) { //自定义搜索条件
  16 + params.ids = Config.sid;//将搜索过滤器和操作方法 都转为JSON字符串
  17 + return params;
  18 + }
  19 + });
  20 +
  21 + var table = $("#table");
  22 +
  23 + // 初始化表格
  24 + table.bootstrapTable({
  25 + url: $.fn.bootstrapTable.defaults.extend.index_url,
  26 + pk: 'id',
  27 + sortName: 'id',
  28 + columns: [
  29 + [
  30 + {checkbox: true},
  31 + {field: 'id', title: __('Id')},
  32 + {field: 'user.username', title: __('User.username')},
  33 + {field: 'user.nickname', title: __('User.nickname')},
  34 + {field: 'user.type', title: __('User.type'),formatter: Table.api.formatter.label,searchList: {0: __('Person'), 1: __('Company')}},
  35 + {field: 'user.mobile', title: __('User.mobile')},
  36 + {field: 'user.avatar', title: __('User.avatar'),formatter: Table.api.formatter.image, operate: false},
  37 + {field: 'user.address', title: __('User.address')},
  38 + {field: 'user.start', title: __('User.start'),formatter: Table.api.formatter.label,searchList: {0: __('未开工'), 1: __('已开工')}},
  39 + {field: 'user.score', title: __('user.score'), operate: 'BETWEEN', sortable: true},
  40 + {field: 'user.money', title: __('User.money')},
  41 + {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,buttons:[
  42 + {
  43 + name: 'ajax',
  44 + text: __('指派'),
  45 + title: __('指派'),
  46 + classname: 'btn btn-xs btn-success btn-magic btn-ajax',
  47 + icon: 'fa',
  48 + url: 'appoint/appoint_staff',
  49 + confirm: '确认指派此人员',
  50 + success: function (data, ret) {
  51 + Layer.alert(ret.msg);
  52 + $(".btn-refresh").trigger("click");
  53 + //如果需要阻止成功提示,则必须使用return false;
  54 + //return false;
  55 + },
  56 + error: function (data, ret) {
  57 + Layer.alert(ret.msg);
  58 + return false;
  59 + },visible: function (row) {
  60 + if(row.user.start == 0){
  61 + return false;//隐藏
  62 + }else{
  63 + return true;
  64 + }
  65 + }
  66 + }
  67 + ]}
  68 + ]
  69 + ]
  70 + });
  71 +
  72 + // 为表格绑定事件
  73 + Table.api.bindevent(table);
  74 + },
  75 + add: function () {
  76 + Controller.api.bindevent();
  77 + },
  78 + edit: function () {
  79 + Controller.api.bindevent();
  80 + },
  81 + api: {
  82 + bindevent: function () {
  83 + Form.api.bindevent($("form[role=form]"));
  84 + }
  85 + }
  86 + };
  87 + return Controller;
  88 +});
@@ -28,6 +28,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin @@ -28,6 +28,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
28 {field: 'fullname', title: __('Fullname')}, 28 {field: 'fullname', title: __('Fullname')},
29 {field: 'user.username', title: __('User.username')}, 29 {field: 'user.username', title: __('User.username')},
30 {field: 'user.avatar', title: __('User.avatar'), formatter: Table.api.formatter.image}, 30 {field: 'user.avatar', title: __('User.avatar'), formatter: Table.api.formatter.image},
  31 + {field: 'user.mobile', title: __('User.mobile')},
31 {field: 'address', title: __('Address')}, 32 {field: 'address', title: __('Address')},
32 {field: 'pre_date', title: __('Pre_date'), operate:'RANGE', addclass:'datetimerange'}, 33 {field: 'pre_date', title: __('Pre_date'), operate:'RANGE', addclass:'datetimerange'},
33 {field: 'pre_time', title: __('Pre_time')}, 34 {field: 'pre_time', title: __('Pre_time')},
@@ -83,6 +84,24 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin @@ -83,6 +84,24 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
83 return true; 84 return true;
84 } 85 }
85 } 86 }
  87 + },
  88 + {
  89 + name: 'staff',
  90 + text: '指派',
  91 + title: '指派',
  92 + icon: 'fa fa-list',
  93 + classname: 'btn btn-xs btn-success btn-dialog',
  94 + url: "appoint/index",
  95 + // url:function(row){
  96 + // return 'appoint/appoint_index?s_id='+row.id;
  97 + // },
  98 + visible: function (row) {
  99 + if(row.status == 1){
  100 + return true;
  101 + }else{
  102 + return false;//隐藏
  103 + }
  104 + }
86 } 105 }
87 ]} 106 ]}
88 ] 107 ]
@@ -30,11 +30,20 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin @@ -30,11 +30,20 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
30 {field: 'user.type', title: __('User.type'),formatter: Table.api.formatter.label,searchList: {0: __('Person'), 1: __('Company')}}, 30 {field: 'user.type', title: __('User.type'),formatter: Table.api.formatter.label,searchList: {0: __('Person'), 1: __('Company')}},
31 {field: 'user.mobile', title: __('User.mobile')}, 31 {field: 'user.mobile', title: __('User.mobile')},
32 {field: 'user.avatar', title: __('User.avatar'),formatter: Table.api.formatter.image, operate: false}, 32 {field: 'user.avatar', title: __('User.avatar'),formatter: Table.api.formatter.image, operate: false},
  33 + {field: 'user.address', title: __('User.address')},
33 {field: 'user.start', title: __('User.start'),formatter: Table.api.formatter.label,searchList: {0: __('未开工'), 1: __('已开工')}}, 34 {field: 'user.start', title: __('User.start'),formatter: Table.api.formatter.label,searchList: {0: __('未开工'), 1: __('已开工')}},
34 {field: 'user.score', title: __('user.score'), operate: 'BETWEEN', sortable: true}, 35 {field: 'user.score', title: __('user.score'), operate: 'BETWEEN', sortable: true},
35 {field: 'user.money', title: __('User.money')}, 36 {field: 'user.money', title: __('User.money')},
36 - {field: 'user.address', title: __('User.address')},  
37 - // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate} 37 + {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,buttons:[
  38 + {
  39 + name: 'assign',
  40 + text: '我的分配',
  41 + title: '我的分配',
  42 + icon: 'fa fa-list',
  43 + classname: 'btn btn-xs btn-success btn-dialog',
  44 + url: "assign/index"
  45 + },
  46 + ]}
38 ] 47 ]
39 ] 48 ]
40 }); 49 });