Răsfoiți Sursa

[智价云] 平台管理

tangyuanwang 2 luni în urmă
părinte
comite
bb528208e1

+ 244 - 0
app/Http/Controllers/Manager/WashConfig/PlatForm.php

@@ -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' => '删除成功']);
+    }
+}

+ 80 - 0
app/Http/Requests/Manager/WashConfig/PlatForm.php

@@ -0,0 +1,80 @@
+<?php
+
+namespace App\Http\Requests\Manager\WashConfig;
+
+use App\Http\Requests\BaseRequest;
+
+/**
+ * 数据清洗-平台管理
+ * @author 唐远望
+ * @version 1.0
+ * @date 2026-01-06
+ * 
+ */
+class PlatForm extends BaseRequest
+{
+    /**
+     * 获取应用于请求的规则
+     *
+     * @return array
+     */
+    public function rules()
+    {
+        // 返回结果
+        return      [
+            'name'                 => 'required',
+            'id'                => 'required|integer|gt:0',
+            'status'            => 'required|integer|in:0,1',
+            'page'              => 'integer|min:1',
+            'limit'             => 'integer|min:1',
+            'image_url'         => 'required',
+            'link_url'          => 'required',
+            'sort'              => 'required|integer|min:0',
+            'mobile'            => 'required',
+            'department_id'     => 'required|integer|gt:0',
+            'role_id'           => 'required|integer|gt:0',
+            'password'          => 'required',
+            'open_notice'       => 'required|integer|in:0,1',
+            'employee_ids'      => 'required',
+        ];
+    }
+
+
+    // 场景列表
+    protected   $scenes         = [
+        'detail'             => ['id'],
+        'list'               => ['page', 'limit'],
+        'add'                      => ['name'],
+        'edit'                  => ['id','employee_ids'],
+        'set_status'              => ['id', 'status'],
+        'delete'                  => ['id'],
+    ];
+
+    /**
+     * 获取已定义验证规则的错误消息
+     *
+     * @return array
+     */
+    public function messages()
+    {
+        return [
+            'name.required'     => '平台名称必填',
+            'id.required'       => 'ID未知',
+            'id.integer'        => 'ID格式错误',
+            'id.gt'               => 'ID格式错误',
+            'status.required'   => '状态未知',
+            'status.integer'    => '状态格式错误',
+            'status.in'         => '状态格式错误',
+            'page.integer'      => '页码格式错误',
+            'page.min'          => '页码格式错误',
+            'limit.integer'     => '每页数量格式错误',
+            'limit.min'         => '每页数量格式错误',
+            'image_url.required'    => '图片链接未知',
+            'link_url.required'     => '链接地址未知',
+            'sort.required'         => '排序未知',
+            'sort.integer'          => '排序格式错误',
+            'sort.min'              => '排序格式错误',
+            'employee_ids.required' => '员工责任人未知',
+        ];
+    }
+}

+ 187 - 0
app/Models/Manager/WashConfig/PlatForm.php

@@ -0,0 +1,187 @@
+<?php
+
+namespace App\Models\manager\WashConfig;
+
+use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Support\Facades\DB;
+use App\Models\manager\WashConfig\PlatFormMember as PlatFormMemberModel;
+
+/**
+ * 平台配置模型
+ * @author: 唐远望
+ * @version: 1.0
+ * @date: 2026-01-06
+ */
+class PlatForm extends Model
+{
+    use HasFactory;
+    // 与模型关联的表名
+    protected $table = 'platform';
+    // 是否主动维护时间戳
+    public $timestamps = false;
+    // 定义时间戳字段名
+    // const CREATED_AT = 'insert_time';
+    // const UPDATED_AT = 'update_time';
+
+
+
+    /**
+     * 添加
+     * @author 唐远望
+     * @version 1.0
+     * @date 2026-01-06
+     */
+    public function addPlatForm_content($data)
+    {
+        $insert_data = [
+            'name' => $data['name'],
+            'employee_ids'  => $data['employee_ids'],
+            'insert_time' => time(),
+        ];
+        $PlatForm_id = $this->insertGetId($insert_data);
+        return $PlatForm_id;
+    }
+
+
+    /**
+     * 写入数据
+     * @author 唐远望
+     * @version 1.0
+     * @date 2026-01-06
+     * @param $data
+     * @return bool
+     */
+    public function addPlatForm($data)
+    {
+        DB::beginTransaction();
+        try {
+            $PlatFormMemberModel = new PlatFormMemberModel();
+            $insert_data = [
+                'platform' => $data['platform'],
+                'employee_ids'  => $data['employee_ids'],
+                'insert_time' => time(),
+            ];
+            $PlatForm_id = $this->insertGetId($insert_data);
+
+            if ($data['employee_ids'] != '') {
+                $insert_company_data = [];
+                $employee_ids = explode(',', $data['employee_ids']);
+                foreach ($employee_ids as $employee_id) {
+                    $insert_company_data[] = [
+                        'platform_id' => $PlatForm_id,
+                        'employee_id' => $employee_id,
+                    ];
+                }
+                $PlatFormMemberModel->insert($insert_company_data);
+            }
+            DB::commit();
+            return true;
+            // 成功处理...
+        } catch (\Exception $e) {
+            DB::rollBack();
+            // 错误处理...
+            return false;
+        }
+    }
+
+
+    /**
+     * 编辑内容
+     * @author 唐远望
+     * @version 1.0
+     * @date 2026-01-06
+     * @param $data
+     * @return bool
+     */
+    public function editPlatForm_content($where, $data)
+    {
+        $PlatForm = $this->where($where)->first();
+        if (!$PlatForm) {
+            return false;
+        }
+        // $PlatForm->name = $data['name'];
+        $PlatForm->employee_ids = $data['employee_ids'];
+        $PlatForm->update_time = time();
+        $PlatForm->save();
+        return true;
+    }
+
+
+
+    /**
+     * 更新数据
+     * @author 唐远望
+     * @version 1.0
+     * @date 2026-01-06
+     * @param $data
+     * @return bool
+     */
+    public function updatePlatForm($PlatForm, $data)
+    {
+        DB::beginTransaction();
+        try {
+            // $PlatForm->name = $data['name'];
+            $PlatForm->employee_ids = $data['employee_ids'];
+            $PlatForm->update_time = time();
+            $PlatForm->save();
+
+            $PlatFormMemberModel = new PlatFormMemberModel();
+            $PlatFormMemberModel->where('platform_id', $PlatForm->id)->delete();
+            if ($data['employee_ids'] != '') {
+                $insert_company_data = [];
+                $employee_ids = explode(',', $data['employee_ids']);
+                foreach ($employee_ids as $employee_id) {
+                    $insert_company_data[] = [
+                        'platform_id' => $PlatForm->id,
+                        'employee_id' => $employee_id,
+                    ];
+                }
+                $PlatFormMemberModel->insert($insert_company_data);
+            }
+            DB::commit();
+            return true;
+            // 成功处理...
+        } catch (\Exception $e) {
+            DB::rollBack();
+            // 错误处理...
+            return false;
+        }
+    }
+
+    /**
+     * 修改状态
+     * @author 唐远望
+     * @version 1.0
+     * @date 2026-01-06
+     * @param $id
+     * @param $status
+     * @return bool
+     */
+    public function changeStatus($PlatForm, $status)
+    {
+
+        $PlatForm->status = $status;
+        $PlatForm->update_time = time();
+        $PlatForm->save();
+        return true;
+    }
+
+    /**
+     * 删除数据
+     * @author 唐远望
+     * @version 1.0
+     * @date 2026-01-06
+     * @param $id
+     * @return bool
+     */
+    public function deletePlatForm($where)
+    {
+        $PlatForm = $this->where($where)->first();
+        if (!$PlatForm) {
+            return false;
+        }
+        $PlatForm->delete();
+        return true;
+    }
+}

+ 24 - 0
app/Models/Manager/WashConfig/PlatFormMember.php

@@ -0,0 +1,24 @@
+<?php
+
+namespace App\Models\manager\WashConfig;
+
+use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * 平台责任人模型
+ * @author 唐远望
+ * @version 1.0
+ * @date 2026-01-06
+ */
+class PlatFormMember extends Model
+{
+    use HasFactory;
+        // 与模型关联的表名
+    protected $table = 'platform_member';
+    // 是否主动维护时间戳
+    public $timestamps = false;
+    // 定义时间戳字段名
+    // const CREATED_AT = 'insert_time';
+    // const UPDATED_AT = 'update_time';
+}

+ 7 - 1
routes/manager.php

@@ -129,6 +129,13 @@ Route::any('violation_store/delete', [App\Http\Controllers\Manager\WashConfig\Vi
 // 违规店铺公司-全部
 Route::any('violation_store/all', [App\Http\Controllers\Manager\WashConfig\ViolationStore::class, 'all']);
 
+//平台管理-列表
+Route::any('platform/list', [App\Http\Controllers\Manager\WashConfig\Platform::class, 'list']);
+//平台管理-编辑
+Route::any('platform/edit', [App\Http\Controllers\Manager\WashConfig\Platform::class, 'edit']);
+//平台管理-详情
+Route::any('platform/detail', [App\Http\Controllers\Manager\WashConfig\Platform::class, 'detail']);
+
 // ------人员信息管理------
 // 员工管理-列表
 Route::any('personnel_employee/list', [App\Http\Controllers\Manager\Personnel\Employee::class, 'list']);
@@ -286,4 +293,3 @@ Route::any('collect/product/edit', [App\Http\Controllers\Manager\Collect\Product
 Route::any('collect/product/delete', [App\Http\Controllers\Manager\Collect\Product::class, 'delete']);
 //采集配置-商品管理-状态修改
 Route::any('collect/product/set_status', [App\Http\Controllers\Manager\Collect\Product::class,'set_status']);
-