PlatForm.php 11 KB

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