PlatForm.php 11 KB

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