PlatForm.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <?php
  2. namespace App\Http\Controllers\manager\washConfig;
  3. use App\Http\Controllers\Controller;
  4. use App\Http\Requests\Manager\WashConfig\PlatForm as Request;
  5. use App\Models\Manager\WashConfig\PlatForm as PlatFormModel;
  6. use App\Models\Manager\Personnel\Employee as EmployeeModel;
  7. /**
  8. * 清洗配置-平台管理
  9. * @author 唐远望
  10. * @version 1.0
  11. * @date 2026-01-06
  12. */
  13. class PlatForm extends Controller
  14. {
  15. /**
  16. * 列表
  17. * @author 唐远望
  18. * @version 1.0
  19. * @date 2026-01-06
  20. *
  21. */
  22. public function list(Request $request, PlatFormModel $PlatFormModel, EmployeeModel $EmployeeModel)
  23. {
  24. $request->scene('list')->validate();
  25. // 查询条件
  26. $map = [];
  27. $limit = request('limit', config('page_num', 10));
  28. $status = request('status', '');
  29. $start_time = request('start_time', '');
  30. $end_time = request('end_time', '');
  31. $name = request('name', '');
  32. // 时间条件
  33. if ($start_time) $map[] = ['insert_time', '>=', strtotime($start_time)];
  34. if ($end_time) $map[] = ['insert_time', '<=', strtotime($end_time)];
  35. // 其他条件
  36. if (is_numeric($status)) $map[] = ['status', '=', $status];
  37. if ($name) $map[] = ['name', 'like', "%$name%"];
  38. // 查询数据
  39. $result = $PlatFormModel->query()
  40. ->where($map)
  41. ->orderByDesc('id')
  42. ->paginate($limit)->toArray();
  43. // 分配数据
  44. if (!$result) return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => []]);
  45. if (isset($result['data']) && count($result['data']) > 0) {
  46. foreach ($result['data'] as $key => $value) {
  47. $employee_ids = $value['employee_ids'] != '' ? explode(',', $value['employee_ids']) : '';
  48. $result['data'][$key]['employee_ids'] = $employee_ids;
  49. $result['data'][$key]['employee_name'] = $employee_ids ? $EmployeeModel->whereIn('id', $employee_ids)->pluck('name')->toArray() : '';
  50. }
  51. }
  52. // 加载模板
  53. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  54. }
  55. /**
  56. * 所有平台
  57. * @author 唐远望
  58. * @version 1.0
  59. * @date 2025-12-08
  60. *
  61. */
  62. public function all(PlatFormModel $PlatFormModel)
  63. {
  64. $map = [];
  65. $status = request('status', '0');
  66. $start_time = request('start_time', '');
  67. $end_time = request('end_time', '');
  68. $name = request('name', '');
  69. // 时间条件
  70. if ($start_time) $map[] = ['insert_time', '>=', strtotime($start_time)];
  71. if ($end_time) $map[] = ['insert_time', '<=', strtotime($end_time)];
  72. // 其他条件
  73. if ($name) $map[] = ['name', 'like', "%$name%"];
  74. if (is_numeric($status)) $map[] = ['status', '=', $status];
  75. $result = $PlatFormModel->query()
  76. ->where($map)
  77. ->select(['id', 'name'])
  78. ->orderByDesc('id')
  79. ->get();
  80. // 分配数据
  81. if (!$result) return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => []]);
  82. // 加载模板
  83. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  84. }
  85. /**
  86. * 详情
  87. * @author 唐远望
  88. * @version 1.0
  89. * @date 2026-01-06
  90. */
  91. public function detail(Request $request, PlatFormModel $PlatFormModel, EmployeeModel $EmployeeModel)
  92. {
  93. $request->scene('detail')->validate();
  94. // 接收参数
  95. $id = request('id', 0);
  96. $map = ['id' => $id];
  97. $data = $PlatFormModel->where($map)->first();
  98. if (!$data) return json_send(['code' => 'error', 'msg' => '记录不存在']);
  99. $employee_ids = $data->employee_ids != '' ? explode(',', $data->employee_ids) : '';
  100. $data->employee_ids = $employee_ids;
  101. $data->employee_name = $employee_ids ? $EmployeeModel->whereIn('id', $employee_ids)->pluck('name')->toArray() : '';
  102. // 加载模板
  103. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $data]);
  104. }
  105. /**
  106. * 添加
  107. * @author 唐远望
  108. * @version 1.0
  109. * @date 2026-01-06
  110. *
  111. */
  112. public function add(Request $request, PlatFormModel $PlatFormModel)
  113. {
  114. $request->scene('add')->validate();
  115. // 接收数据
  116. $all_data = request()->all();
  117. $employee_ids = request('employee_ids', '');
  118. $all_data['employee_ids'] = $employee_ids;
  119. //查询是否存在
  120. $map = ['name' => $all_data['name']];
  121. $data = $PlatFormModel->where($map)->first();
  122. if ($data) return json_send(['code' => 'error', 'msg' => '记录已存在']);
  123. // 写入数据表
  124. $result = $PlatFormModel->addPlatForm($all_data);
  125. // 如果操作失败
  126. if (!$result) return json_send(['code' => 'error', 'msg' => '新增失败']);
  127. // 记录行为
  128. $admin_id = request('access_token.uid', 0); //用户ID
  129. $is_admin = request('access_token.is_admin'); //是否管理员操作 0=是1=否
  130. $table_name = $PlatFormModel->getTable();
  131. $notes_type = 1; //操作类型,1添加,2修改,3=删除
  132. $this->addAdminHistory('清洗配置-平台管理管理', $admin_id, $is_admin, $table_name, $notes_type, [], $all_data, '新增了平台' . $all_data['name'] . '信息');
  133. // 告知结果
  134. return json_send(['code' => 'success', 'msg' => '新增成功']);
  135. }
  136. /**
  137. * 修改
  138. * @author 唐远望
  139. * @version 1.0
  140. * @date 2026-01-06
  141. *
  142. */
  143. public function edit(Request $request, PlatFormModel $PlatFormModel)
  144. {
  145. $request->scene('edit')->validate();
  146. // 接收参数
  147. $id = request('id', 0);
  148. // 接收数据
  149. $all_data = request()->all();
  150. $employee_ids = request('employee_ids', '');
  151. $all_data['employee_ids'] = $employee_ids;
  152. // //查询是否存在
  153. // $map = ['name' => $all_data['name']];
  154. // $data = $PlatFormModel->where($map)->where('id', '!=', $id)->first();
  155. // if ($data) return json_send(['code' => 'error', 'msg' => '记录已存在']);
  156. // 更新数据表
  157. $where = ['id' => $id];
  158. $PlatForm = $PlatFormModel->where($where)->first();
  159. if (!$PlatForm) return json_send(['code' => 'error', 'msg' => '记录不存在']);
  160. $oldData = $PlatForm->toArray();
  161. $result = $PlatFormModel->updatePlatForm($PlatForm, $all_data);
  162. // 如果操作失败
  163. if (!$result) return json_send(['code' => 'error', 'msg' => '修改失败']);
  164. // 记录行为
  165. $admin_id = request('access_token.uid', 0); //用户ID
  166. $is_admin = request('access_token.is_admin'); //是否管理员操作 0=是1=否
  167. $table_name = $PlatFormModel->getTable();
  168. $notes_type = 2; //操作类型,1添加,2修改,3=删除
  169. $this->addAdminHistory('清洗配置-平台管理管理', $admin_id, $is_admin, $table_name, $notes_type, $oldData, $all_data, '修改了平台' . $oldData['name'] . '信息');
  170. // 告知结果
  171. return json_send(['code' => 'success', 'msg' => '修改成功']);
  172. }
  173. /**
  174. * 修改状态
  175. * @author 唐远望
  176. * @version 1.0
  177. * @date 2026-01-06
  178. *
  179. */
  180. public function set_status(Request $request, PlatFormModel $PlatFormModel)
  181. {
  182. // 验证参数
  183. $request->scene('set_status')->validate();
  184. // 接收数据
  185. $id = request('id', 0);
  186. $status = request('status', 0);
  187. // 查询用户
  188. $where = ['id' => $id];
  189. $PlatForm = $PlatFormModel->where($where)->first();
  190. if (!$PlatForm) return json_send(['code' => 'error', 'msg' => '记录不存在']);
  191. // 执行修改
  192. $result = $PlatFormModel->changeStatus($PlatForm, $status);
  193. // 提示新增失败
  194. if (!$result) return json_send(['code' => 'error', 'msg' => '设置失败']);
  195. // 记录行为
  196. $admin_id = request('access_token.uid', 0); //用户ID
  197. $is_admin = request('access_token.is_admin'); //是否管理员操作 0=是1=否
  198. $table_name = $PlatFormModel->getTable();
  199. $notes_type = 2; //操作类型,1添加,2修改,3=删除
  200. $this->addAdminHistory('清洗配置-平台管理管理', $admin_id, $is_admin, $table_name, $notes_type, [], ['status' => $status], '修改了平台' . $PlatForm->name . '状态');
  201. // 告知结果
  202. return json_send(['code' => 'success', 'msg' => '设置成功']);
  203. }
  204. /**
  205. * 删除
  206. * @author 唐远望
  207. * @version 1.0
  208. * @date 2026-01-06
  209. *
  210. */
  211. public function delete(Request $request, PlatFormModel $PlatFormModel)
  212. {
  213. // 验证参数
  214. $request->scene('delete')->validate();
  215. // 接收数据
  216. $id = request('id', 0);
  217. // 查询用户
  218. $where = ['id' => $id];
  219. // 执行删除
  220. $PlatForm = $PlatFormModel->where($where)->first();
  221. if (!$PlatForm) return json_send(['code' => 'error', 'msg' => '记录不存在']);
  222. $result = $PlatForm->delete();
  223. // 提示删除失败
  224. if (!$result) return json_send(['code' => 'error', 'msg' => '删除失败']);
  225. // 记录行为
  226. $admin_id = request('access_token.uid', 0); //用户ID
  227. $is_admin = request('access_token.is_admin'); //是否管理员操作 0=是1=否
  228. $table_name = $PlatFormModel->getTable();
  229. $notes_type = 3; //操作类型,1添加,2修改,3=删除
  230. $this->addAdminHistory('清洗配置-平台管理管理', $admin_id, $is_admin, $table_name, $notes_type, $PlatForm->toArray(), [], '删除了平台' . $PlatForm->name . '信息');
  231. // 告知结果
  232. return json_send(['code' => 'success', 'msg' => '删除成功']);
  233. }
  234. }