|
|
@@ -0,0 +1,244 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace App\Http\Controllers\manager\washConfig;
|
|
|
+
|
|
|
+use App\Http\Controllers\Controller;
|
|
|
+use App\Http\Requests\Manager\WashConfig\PlatForm as Request;
|
|
|
+use App\Models\Manager\WashConfig\PlatForm as PlatFormModel;
|
|
|
+use App\Models\Manager\Personnel\Employee as EmployeeModel;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 清洗配置-平台管理
|
|
|
+ * @author 唐远望
|
|
|
+ * @version 1.0
|
|
|
+ * @date 2026-01-06
|
|
|
+ */
|
|
|
+class PlatForm extends Controller
|
|
|
+{
|
|
|
+ /**
|
|
|
+ * 列表
|
|
|
+ * @author 唐远望
|
|
|
+ * @version 1.0
|
|
|
+ * @date 2026-01-06
|
|
|
+ *
|
|
|
+ */
|
|
|
+ public function list(Request $request, PlatFormModel $PlatFormModel, EmployeeModel $EmployeeModel)
|
|
|
+ {
|
|
|
+ $request->scene('list')->validate();
|
|
|
+ // 查询条件
|
|
|
+ $map = [];
|
|
|
+ $limit = request('limit', config('page_num', 10));
|
|
|
+ $status = request('status', '');
|
|
|
+ $start_time = request('start_time', '');
|
|
|
+ $end_time = request('end_time', '');
|
|
|
+ $name = request('name', '');
|
|
|
+ // 时间条件
|
|
|
+ if ($start_time) $map[] = ['insert_time', '>=', strtotime($start_time)];
|
|
|
+ if ($end_time) $map[] = ['insert_time', '<=', strtotime($end_time)];
|
|
|
+ // 其他条件
|
|
|
+ if (is_numeric($status)) $map[] = ['status', '=', $status];
|
|
|
+ if ($name) $map[] = ['name', 'like', "%$name%"];
|
|
|
+ // 查询数据
|
|
|
+ $result = $PlatFormModel->query()
|
|
|
+ ->where($map)
|
|
|
+ ->orderByDesc('id')
|
|
|
+ ->paginate($limit)->toArray();
|
|
|
+ // 分配数据
|
|
|
+ if (!$result) return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => []]);
|
|
|
+ if (isset($result['data']) && count($result['data']) > 0) {
|
|
|
+ foreach ($result['data'] as $key => $value) {
|
|
|
+ $employee_ids = $value['employee_ids'] != '' ? explode(',', $value['employee_ids']) : '';
|
|
|
+ $result['data'][$key]['employee_ids'] = $employee_ids;
|
|
|
+ $result['data'][$key]['employee_name'] = $employee_ids ? $EmployeeModel->whereIn('id', $employee_ids)->pluck('name')->toArray() : '';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 加载模板
|
|
|
+ return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 所有平台
|
|
|
+ * @author 唐远望
|
|
|
+ * @version 1.0
|
|
|
+ * @date 2025-12-08
|
|
|
+ *
|
|
|
+ */
|
|
|
+ public function all(PlatFormModel $PlatFormModel)
|
|
|
+ {
|
|
|
+ $map = [];
|
|
|
+ $status = request('status', '0');
|
|
|
+ $start_time = request('start_time', '');
|
|
|
+ $end_time = request('end_time', '');
|
|
|
+ $name = request('name', '');
|
|
|
+ // 时间条件
|
|
|
+ if ($start_time) $map[] = ['insert_time', '>=', strtotime($start_time)];
|
|
|
+ if ($end_time) $map[] = ['insert_time', '<=', strtotime($end_time)];
|
|
|
+ // 其他条件
|
|
|
+ if ($name) $map[] = ['name', 'like', "%$name%"];
|
|
|
+ if (is_numeric($status)) $map[] = ['status', '=', $status];
|
|
|
+ $result = $PlatFormModel->query()
|
|
|
+ ->where($map)
|
|
|
+ ->select(['id', 'name'])
|
|
|
+ ->orderByDesc('id')
|
|
|
+ ->get();
|
|
|
+ // 分配数据
|
|
|
+ if (!$result) return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => []]);
|
|
|
+ // 加载模板
|
|
|
+ return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 详情
|
|
|
+ * @author 唐远望
|
|
|
+ * @version 1.0
|
|
|
+ * @date 2026-01-06
|
|
|
+ */
|
|
|
+ public function detail(Request $request, PlatFormModel $PlatFormModel, EmployeeModel $EmployeeModel)
|
|
|
+ {
|
|
|
+ $request->scene('detail')->validate();
|
|
|
+ // 接收参数
|
|
|
+ $id = request('id', 0);
|
|
|
+ $map = ['id' => $id];
|
|
|
+ $data = $PlatFormModel->where($map)->first();
|
|
|
+ if (!$data) return json_send(['code' => 'error', 'msg' => '记录不存在']);
|
|
|
+ $employee_ids = $data->employee_ids != '' ? explode(',', $data->employee_ids) : '';
|
|
|
+ $data->employee_ids = $employee_ids;
|
|
|
+ $data->employee_name = $employee_ids ? $EmployeeModel->whereIn('id', $employee_ids)->pluck('name')->toArray() : '';
|
|
|
+ // 加载模板
|
|
|
+ return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $data]);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加
|
|
|
+ * @author 唐远望
|
|
|
+ * @version 1.0
|
|
|
+ * @date 2026-01-06
|
|
|
+ *
|
|
|
+ */
|
|
|
+ public function add(Request $request, PlatFormModel $PlatFormModel)
|
|
|
+ {
|
|
|
+ $request->scene('add')->validate();
|
|
|
+ // 接收数据
|
|
|
+ $all_data = request()->all();
|
|
|
+ $employee_ids = request('employee_ids', '');
|
|
|
+ $all_data['employee_ids'] = $employee_ids;
|
|
|
+ //查询是否存在
|
|
|
+ $map = ['name' => $all_data['name']];
|
|
|
+ $data = $PlatFormModel->where($map)->first();
|
|
|
+ if ($data) return json_send(['code' => 'error', 'msg' => '记录已存在']);
|
|
|
+ // 写入数据表
|
|
|
+ $result = $PlatFormModel->addPlatForm($all_data);
|
|
|
+ // 如果操作失败
|
|
|
+ if (!$result) return json_send(['code' => 'error', 'msg' => '新增失败']);
|
|
|
+ // 记录行为
|
|
|
+ $admin_id = request('access_token.uid', 0); //用户ID
|
|
|
+ $is_admin = request('access_token.is_admin'); //是否管理员操作 0=是1=否
|
|
|
+ $table_name = $PlatFormModel->getTable();
|
|
|
+ $notes_type = 1; //操作类型,1添加,2修改,3=删除
|
|
|
+ $this->addAdminHistory('清洗配置-平台管理管理', $admin_id, $is_admin, $table_name, $notes_type, [], $all_data, '新增了平台' . $all_data['name'] . '信息');
|
|
|
+ // 告知结果
|
|
|
+ return json_send(['code' => 'success', 'msg' => '新增成功']);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改
|
|
|
+ * @author 唐远望
|
|
|
+ * @version 1.0
|
|
|
+ * @date 2026-01-06
|
|
|
+ *
|
|
|
+ */
|
|
|
+ public function edit(Request $request, PlatFormModel $PlatFormModel)
|
|
|
+ {
|
|
|
+ $request->scene('edit')->validate();
|
|
|
+ // 接收参数
|
|
|
+ $id = request('id', 0);
|
|
|
+ // 接收数据
|
|
|
+ $all_data = request()->all();
|
|
|
+ $employee_ids = request('employee_ids', '');
|
|
|
+ $all_data['employee_ids'] = $employee_ids;
|
|
|
+ // //查询是否存在
|
|
|
+ // $map = ['name' => $all_data['name']];
|
|
|
+ // $data = $PlatFormModel->where($map)->where('id', '!=', $id)->first();
|
|
|
+ // if ($data) return json_send(['code' => 'error', 'msg' => '记录已存在']);
|
|
|
+ // 更新数据表
|
|
|
+ $where = ['id' => $id];
|
|
|
+ $PlatForm = $PlatFormModel->where($where)->first();
|
|
|
+ if (!$PlatForm) return json_send(['code' => 'error', 'msg' => '记录不存在']);
|
|
|
+ $oldData = $PlatForm->toArray();
|
|
|
+ $result = $PlatFormModel->updatePlatForm($PlatForm, $all_data);
|
|
|
+ // 如果操作失败
|
|
|
+ if (!$result) return json_send(['code' => 'error', 'msg' => '修改失败']);
|
|
|
+ // 记录行为
|
|
|
+ $admin_id = request('access_token.uid', 0); //用户ID
|
|
|
+ $is_admin = request('access_token.is_admin'); //是否管理员操作 0=是1=否
|
|
|
+ $table_name = $PlatFormModel->getTable();
|
|
|
+ $notes_type = 2; //操作类型,1添加,2修改,3=删除
|
|
|
+ $this->addAdminHistory('清洗配置-平台管理管理', $admin_id, $is_admin, $table_name, $notes_type, $oldData, $all_data, '修改了平台' . $oldData['name'] . '信息');
|
|
|
+ // 告知结果
|
|
|
+ return json_send(['code' => 'success', 'msg' => '修改成功']);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改状态
|
|
|
+ * @author 唐远望
|
|
|
+ * @version 1.0
|
|
|
+ * @date 2026-01-06
|
|
|
+ *
|
|
|
+ */
|
|
|
+ public function set_status(Request $request, PlatFormModel $PlatFormModel)
|
|
|
+ {
|
|
|
+ // 验证参数
|
|
|
+ $request->scene('set_status')->validate();
|
|
|
+ // 接收数据
|
|
|
+ $id = request('id', 0);
|
|
|
+ $status = request('status', 0);
|
|
|
+ // 查询用户
|
|
|
+ $where = ['id' => $id];
|
|
|
+ $PlatForm = $PlatFormModel->where($where)->first();
|
|
|
+ if (!$PlatForm) return json_send(['code' => 'error', 'msg' => '记录不存在']);
|
|
|
+ // 执行修改
|
|
|
+ $result = $PlatFormModel->changeStatus($PlatForm, $status);
|
|
|
+ // 提示新增失败
|
|
|
+ if (!$result) return json_send(['code' => 'error', 'msg' => '设置失败']);
|
|
|
+ // 记录行为
|
|
|
+ $admin_id = request('access_token.uid', 0); //用户ID
|
|
|
+ $is_admin = request('access_token.is_admin'); //是否管理员操作 0=是1=否
|
|
|
+ $table_name = $PlatFormModel->getTable();
|
|
|
+ $notes_type = 2; //操作类型,1添加,2修改,3=删除
|
|
|
+ $this->addAdminHistory('清洗配置-平台管理管理', $admin_id, $is_admin, $table_name, $notes_type, [], ['status' => $status], '修改了平台' . $PlatForm->name . '状态');
|
|
|
+ // 告知结果
|
|
|
+ return json_send(['code' => 'success', 'msg' => '设置成功']);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除
|
|
|
+ * @author 唐远望
|
|
|
+ * @version 1.0
|
|
|
+ * @date 2026-01-06
|
|
|
+ *
|
|
|
+ */
|
|
|
+ public function delete(Request $request, PlatFormModel $PlatFormModel)
|
|
|
+ {
|
|
|
+ // 验证参数
|
|
|
+ $request->scene('delete')->validate();
|
|
|
+ // 接收数据
|
|
|
+ $id = request('id', 0);
|
|
|
+ // 查询用户
|
|
|
+ $where = ['id' => $id];
|
|
|
+ // 执行删除
|
|
|
+ $PlatForm = $PlatFormModel->where($where)->first();
|
|
|
+ if (!$PlatForm) return json_send(['code' => 'error', 'msg' => '记录不存在']);
|
|
|
+ $result = $PlatForm->delete();
|
|
|
+ // 提示删除失败
|
|
|
+ if (!$result) return json_send(['code' => 'error', 'msg' => '删除失败']);
|
|
|
+ // 记录行为
|
|
|
+ $admin_id = request('access_token.uid', 0); //用户ID
|
|
|
+ $is_admin = request('access_token.is_admin'); //是否管理员操作 0=是1=否
|
|
|
+ $table_name = $PlatFormModel->getTable();
|
|
|
+ $notes_type = 3; //操作类型,1添加,2修改,3=删除
|
|
|
+ $this->addAdminHistory('清洗配置-平台管理管理', $admin_id, $is_admin, $table_name, $notes_type, $PlatForm->toArray(), [], '删除了平台' . $PlatForm->name . '信息');
|
|
|
+ // 告知结果
|
|
|
+ return json_send(['code' => 'success', 'msg' => '删除成功']);
|
|
|
+ }
|
|
|
+}
|