PlatForm.php 12 KB

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