PlatForm.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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. $result = $PlatFormModel->addPlatForm($all_data);
  133. // 如果操作失败
  134. if (!$result) return json_send(['code' => 'error', 'msg' => '新增失败']);
  135. // 记录行为
  136. $admin_id = request('access_token.uid', 0); //用户ID
  137. $table_name = $PlatFormModel->getTable();
  138. $notes_type = 1; //操作类型,1添加,2修改,3=删除
  139. $this->addAdminHistory('清洗配置-平台管理管理',$company_id, $admin_id, $is_admin, $table_name, $notes_type, [], $all_data, '新增了平台' . $all_data['name'] . '信息');
  140. // 告知结果
  141. return json_send(['code' => 'success', 'msg' => '新增成功']);
  142. }
  143. /**
  144. * 修改
  145. * @author 唐远望
  146. * @version 1.0
  147. * @date 2026-01-06
  148. *
  149. */
  150. public function edit(Request $request, PlatFormModel $PlatFormModel)
  151. {
  152. $request->scene('edit')->validate();
  153. $company_id = request('access_token.company_id', '0');
  154. $is_admin = request('access_token.is_admin', '0');//是否管理员操作 0=是1=否
  155. // 接收参数
  156. $id = request('id', 0);
  157. // 接收数据
  158. $all_data = request()->all();
  159. $employee_ids = request('employee_ids', '');
  160. $all_data['employee_ids'] = $employee_ids;
  161. // //查询是否存在
  162. // $map = ['name' => $all_data['name']];
  163. // $data = $PlatFormModel->where($map)->where('id', '!=', $id)->first();
  164. // if ($data) return json_send(['code' => 'error', 'msg' => '记录已存在']);
  165. // 更新数据表
  166. $where = ['id' => $id];
  167. $PlatForm = $PlatFormModel->where($where)->first();
  168. if (!$PlatForm) return json_send(['code' => 'error', 'msg' => '记录不存在']);
  169. $oldData = $PlatForm->toArray();
  170. $result = $PlatFormModel->updatePlatForm($PlatForm, $all_data);
  171. // 如果操作失败
  172. if (!$result) return json_send(['code' => 'error', 'msg' => '修改失败']);
  173. // 记录行为
  174. $admin_id = request('access_token.uid', 0); //用户ID
  175. $table_name = $PlatFormModel->getTable();
  176. $notes_type = 2; //操作类型,1添加,2修改,3=删除
  177. $this->addAdminHistory('清洗配置-平台管理管理',$company_id, $admin_id, $is_admin, $table_name, $notes_type, $oldData, $all_data, '修改了平台' . $oldData['name'] . '信息');
  178. // 告知结果
  179. return json_send(['code' => 'success', 'msg' => '修改成功']);
  180. }
  181. /**
  182. * 修改状态
  183. * @author 唐远望
  184. * @version 1.0
  185. * @date 2026-01-06
  186. *
  187. */
  188. public function set_status(Request $request, PlatFormModel $PlatFormModel)
  189. {
  190. // 验证参数
  191. $request->scene('set_status')->validate();
  192. $company_id = request('access_token.company_id', '0');
  193. $is_admin = request('access_token.is_admin', '0');//是否管理员操作 0=是1=否
  194. // 接收数据
  195. $id = request('id', 0);
  196. $status = request('status', 0);
  197. // 查询用户
  198. $where = ['id' => $id];
  199. $PlatForm = $PlatFormModel->where($where)->first();
  200. if (!$PlatForm) return json_send(['code' => 'error', 'msg' => '记录不存在']);
  201. // 执行修改
  202. $result = $PlatFormModel->changeStatus($PlatForm, $status);
  203. // 提示新增失败
  204. if (!$result) return json_send(['code' => 'error', 'msg' => '设置失败']);
  205. // 记录行为
  206. $admin_id = request('access_token.uid', 0); //用户ID
  207. $table_name = $PlatFormModel->getTable();
  208. $notes_type = 2; //操作类型,1添加,2修改,3=删除
  209. $this->addAdminHistory('清洗配置-平台管理管理',$company_id, $admin_id, $is_admin, $table_name, $notes_type, [], ['status' => $status], '修改了平台' . $PlatForm->name . '状态');
  210. // 告知结果
  211. return json_send(['code' => 'success', 'msg' => '设置成功']);
  212. }
  213. /**
  214. * 删除
  215. * @author 唐远望
  216. * @version 1.0
  217. * @date 2026-01-06
  218. *
  219. */
  220. public function delete(Request $request, PlatFormModel $PlatFormModel)
  221. {
  222. // 验证参数
  223. $request->scene('delete')->validate();
  224. $company_id = request('access_token.company_id', '0');
  225. $is_admin = request('access_token.is_admin', '0');//是否管理员操作 0=是1=否
  226. // 接收数据
  227. $id = request('id', 0);
  228. // 查询用户
  229. $where = ['id' => $id];
  230. // 执行删除
  231. $PlatForm = $PlatFormModel->where($where)->first();
  232. if (!$PlatForm) return json_send(['code' => 'error', 'msg' => '记录不存在']);
  233. $result = $PlatForm->delete();
  234. // 提示删除失败
  235. if (!$result) return json_send(['code' => 'error', 'msg' => '删除失败']);
  236. // 记录行为
  237. $admin_id = request('access_token.uid', 0); //用户ID
  238. $table_name = $PlatFormModel->getTable();
  239. $notes_type = 3; //操作类型,1添加,2修改,3=删除
  240. $this->addAdminHistory('清洗配置-平台管理管理',$company_id, $admin_id, $is_admin, $table_name, $notes_type, $PlatForm->toArray(), [], '删除了平台' . $PlatForm->name . '信息');
  241. // 告知结果
  242. return json_send(['code' => 'success', 'msg' => '删除成功']);
  243. }
  244. }