Staff.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. <?php
  2. namespace app\admin\controller\equipment;
  3. use app\admin\model\equipment\Department;
  4. use app\common\controller\Backend;
  5. use think\Validate;
  6. /**
  7. * 员工管理管理
  8. *
  9. * @icon fa fa-circle-o
  10. */
  11. class Staff extends Backend
  12. {
  13. /**
  14. * Staff模型对象
  15. * @var \app\admin\model\equipment\Staff
  16. */
  17. protected $model = null;
  18. public function _initialize()
  19. {
  20. parent::_initialize();
  21. $this->model = new \app\admin\model\equipment\Staff;
  22. $this->view->assign("statusList", $this->model->getStatusList());
  23. }
  24. public function import()
  25. {
  26. parent::import();
  27. }
  28. /**
  29. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  30. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  31. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  32. */
  33. /**
  34. * 查看
  35. */
  36. public function index()
  37. {
  38. $this->relationSearch = true;
  39. //设置过滤方法
  40. $this->request->filter(['strip_tags', 'trim']);
  41. // 获取链接地址参数
  42. $param = $this->request->param();
  43. $departmentId = isset($param['department_id']) ? $param['department_id'] : '';
  44. if ($this->request->isAjax()) {
  45. //如果发送的来源是Selectpage,则转发到Selectpage
  46. if ($this->request->request('keyField')) {
  47. return $this->selectpage();
  48. }
  49. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  50. $andWhere = [];
  51. if (!empty($departmentId)) {
  52. $andWhere['department_id'] = $departmentId;
  53. }
  54. $list = $this->model
  55. ->with(['user', 'department'])
  56. ->where($where)
  57. ->where($andWhere)
  58. ->order($sort, $order)
  59. ->paginate($limit);
  60. $result = array("total" => $list->total(), "rows" => $list->items());
  61. return json($result);
  62. }
  63. $this->assignconfig('departmentId', $departmentId);
  64. return $this->view->fetch();
  65. }
  66. /**
  67. * 回收站
  68. */
  69. public function recyclebin()
  70. {
  71. //设置过滤方法
  72. $this->request->filter(['strip_tags', 'trim']);
  73. if ($this->request->isAjax()) {
  74. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  75. $list = $this->model
  76. ->onlyTrashed()
  77. ->with(['user'])
  78. ->where($where)
  79. ->order($sort, $order)
  80. ->paginate($limit);
  81. $result = array("total" => $list->total(), "rows" => $list->items());
  82. return json($result);
  83. }
  84. return $this->view->fetch();
  85. }
  86. /**
  87. * 员工单选列表页
  88. */
  89. public function picker()
  90. {
  91. $this->relationSearch = true;
  92. //设置过滤方法
  93. $this->request->filter(['strip_tags', 'trim']);
  94. // 获取链接地址参数
  95. $param = $this->request->param();
  96. $parentId = isset($param['parent_id']) ? $param['parent_id'] : '';
  97. $parentType = isset($param['parent_type']) ? $param['parent_type'] : '';
  98. $infoText = $parentType == 'repair' ? '仅显示有设备管理权限的部门人员' : '';
  99. if ($this->request->isAjax()) {
  100. //如果发送的来源是Selectpage,则转发到Selectpage
  101. if ($this->request->request('keyField')) {
  102. return $this->selectpage();
  103. }
  104. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  105. $andWhere = [];
  106. if ($parentType == 'repair') {
  107. $andWhere['department.equipment_manage'] = 1;
  108. }
  109. $list = $this->model
  110. ->with(['user', 'department'])
  111. ->where($where)
  112. ->where($andWhere)
  113. ->order($sort, $order)
  114. ->paginate($limit);
  115. $result = array("total" => $list->total(), "rows" => $list->items());
  116. return json($result);
  117. }
  118. $this->assignconfig('parent_id', $parentId);
  119. $this->assignconfig('parent_type', $parentType);
  120. $this->view->assign('info_text', $infoText);
  121. return $this->view->fetch();
  122. }
  123. /**
  124. * 员工单选列表页
  125. */
  126. public function pickerDeal()
  127. {
  128. //设置过滤方法
  129. $this->request->filter(['strip_tags', 'trim']);
  130. // 获取链接地址参数
  131. $param = $this->request->param();
  132. $staffId = $param['id'] ?: '';
  133. $userId = $param['user_id'] ?: '';
  134. $parentId = $param['parent_id'] ?: '';
  135. $parentType = $param['parent_type'] ?: '';
  136. if (empty($parentType)) {
  137. $this->error(__('Parameter %s can not be empty', ''));
  138. }
  139. // 维修工单指派
  140. if ($parentType == 'repair') {
  141. if (!$userId || !$parentId) {
  142. $this->error(__('Parameter %s can not be empty', ''));
  143. }
  144. $repairModel = new \app\admin\model\equipment\Repair();
  145. $result = $repairModel->assignStaff($parentId, $userId);
  146. if ($result === true) {
  147. $this->success();
  148. } else {
  149. $this->error($result);
  150. }
  151. }
  152. // 派单通知人员添加
  153. if ($parentType == 'assign_remind') {
  154. if (!$staffId) {
  155. $this->error(__('Parameter %s can not be empty', ''));
  156. }
  157. $reminderUsersModel = new \app\admin\model\equipment\ReminderUsers();
  158. $where = ['staff_id' => $staffId, 'type' => 'assign_repair'];
  159. $reminderUser = $reminderUsersModel->where($where)->find();
  160. if ($reminderUser) {
  161. $this->error(__('This staff has been added'));
  162. }
  163. $result = $reminderUsersModel->isUpdate(false)->data($where)->save();
  164. if ($result) {
  165. $this->success();
  166. } else {
  167. $this->error($reminderUsersModel->getError());
  168. }
  169. }
  170. // 设备档案选择员工
  171. if ($parentType == 'archive') {
  172. $data = [
  173. 'staff_id' => $staffId,
  174. 'user_id' => $userId
  175. ];
  176. $this->success('', '', $data);
  177. }
  178. }
  179. /**
  180. * 添加
  181. */
  182. public function add()
  183. {
  184. if ($this->request->isPost()) {
  185. $this->token();
  186. $params = $this->request->post("row/a");
  187. if ($params) {
  188. if (!Validate::is($params['password'], '\S{6,16}')) {
  189. $this->error(__("Please input correct password"));
  190. }
  191. $result = $this->model->addStaff($params);
  192. if ($result > 0) {
  193. $this->success();
  194. } else {
  195. $this->error($result);
  196. }
  197. }
  198. $this->error(__('Parameter %s can not be empty', ''));
  199. }
  200. // 获取链接地址参数
  201. $param = $this->request->param();
  202. $departmentId = !empty($param['department_id']) ? $param['department_id'] : '';
  203. $departmentModel = new Department();
  204. $this->view->assign('departmentList', build_select('row[department_id]', $departmentModel->getSelectpicker(), $departmentId, ['class' => 'form-control selectpicker', 'data-rule' => 'required']));
  205. return parent::add();
  206. }
  207. /**
  208. * 编辑
  209. */
  210. public function edit($ids = null)
  211. {
  212. if ($this->request->isPost()) {
  213. $this->token();
  214. $params = $this->request->post("row/a");
  215. $result = $this->model->editStaff($params, $ids);
  216. if ($result === true) {
  217. $this->success();
  218. } else {
  219. $this->error($result);
  220. }
  221. }
  222. $row = $this->model->get($ids);
  223. if (!$row) {
  224. $this->error(__('No Results were found'));
  225. }
  226. $departmentModel = new Department();
  227. $this->view->assign('rawData', json_encode($row));
  228. $this->view->assign('departmentList', build_select('row[department_id]', $departmentModel->getSelectpicker(), $row['department_id'], ['class' => 'form-control selectpicker', 'data-rule' => 'required']));
  229. return parent::edit($ids);
  230. }
  231. public function getPlanSelectpage()
  232. {
  233. $list = [];
  234. $keyword = [];
  235. if ($this->request->request('keyField')) {
  236. $this->request->filter(['trim', 'strip_tags', 'htmlspecialchars']);
  237. $keyword = (array)$this->request->request("q_word/a");
  238. }
  239. $result = $this->model->getSelectpicker($keyword, 1);
  240. foreach ($result as $key => $value) {
  241. $list[] = [
  242. 'id' => $key,
  243. 'title' => $value
  244. ];
  245. }
  246. return [
  247. 'list' => $list,
  248. 'total' => count($list)
  249. ];
  250. }
  251. public function unbind($ids = null)
  252. {
  253. $row = $this->model->get($ids);
  254. if (!$row) {
  255. $this->error(__('No Results were found'));
  256. }
  257. if (empty($row['openid'])) {
  258. $this->success();
  259. }
  260. $result = $this->model->save(['openid' => ''], ['id' => $ids]);
  261. if ($result) {
  262. $this->success();
  263. } else {
  264. $this->error($this->model->getError());
  265. }
  266. }
  267. }