Ver Fonte

[智价云] 商品分类管理功能

tangyuanwang há 1 dia atrás
pai
commit
ae06ef3368

+ 201 - 0
app/Http/Controllers/Manager/WashConfig/ProductCategory.php

@@ -0,0 +1,201 @@
+<?php
+
+namespace App\Http\Controllers\manager\washConfig;
+
+use App\Http\Controllers\Controller;
+use App\Http\Requests\Manager\washConfig\ProductCategory as Request;
+use App\Models\Manager\washConfig\ProductCategory as ProductCategoryModel;
+
+/**
+ * 清洗配置-产品分类
+ * @author    唐远望
+ * @version   1.0
+ * @date      2025-12-18
+ */
+class ProductCategory extends Controller
+{
+    /**
+     * 列表
+     * @author    唐远望
+     * @version   1.0
+     * @date      2025-12-18
+     * 
+     */
+    public function list(Request $request, ProductCategoryModel $ProductCategoryModel)
+    {
+        $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 = $ProductCategoryModel->query()
+            ->where($map)
+            ->orderByDesc('id')
+            ->paginate($limit);
+        // 分配数据
+        if (!$result)  return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => []]);
+        // 加载模板
+        return        json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
+    }
+
+    /**
+     * 所有产品分类
+     * @author    唐远望
+     * @version   1.0
+     * @date      2025-12-08
+     * 
+     */
+    public function all(ProductCategoryModel $ProductCategoryModel)
+    {
+        $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 = $ProductCategoryModel->query()
+            ->where($map)
+            ->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      2025-12-18
+     */
+    public function detail(Request $request, ProductCategoryModel $ProductCategoryModel)
+    {
+        $request->scene('detail')->validate();
+        // 接收参数
+        $id = request('id', 0);
+        $map = ['id' => $id];
+        $data = $ProductCategoryModel->where($map)->first();
+        if (!$data)     return json_send(['code' => 'error', 'msg' => '记录不存在']);
+        // 加载模板
+        return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $data]);
+    }
+
+    /**
+     * 添加
+     * @author    唐远望
+     * @version   1.0
+     * @date      2025-12-18
+     * 
+     */
+    public function add(Request $request, ProductCategoryModel $ProductCategoryModel)
+    {
+        $request->scene('add')->validate();
+        // 接收数据
+        $all_data = request()->all();
+        $store_scope = request('store_scope', '');
+        $all_data['store_scope'] = $store_scope;
+        //查询是否存在
+        $map = ['name' => $all_data['name']];
+        $data = $ProductCategoryModel->where($map)->first();
+        if ($data)     return json_send(['code' => 'error', 'msg' => '记录已存在']);
+        // 写入数据表
+        $result     =  $ProductCategoryModel->addProductCategory($all_data);
+        // 如果操作失败
+        if (!$result)     return json_send(['code' => 'error', 'msg' => '新增失败']);
+        // 告知结果
+        return json_send(['code' => 'success', 'msg' => '新增成功']);
+    }
+
+    /**
+     * 修改
+     * @author    唐远望
+     * @version   1.0
+     * @date      2025-12-18
+     * 
+     */
+    public function edit(Request $request, ProductCategoryModel $ProductCategoryModel)
+    {
+        $request->scene('edit')->validate();
+        // 接收参数
+        $id         = request('id', 0);
+        // 接收数据
+        $all_data = request()->all();
+        $store_scope = request('store_scope', '');
+        $all_data['store_scope'] = $store_scope;
+        //查询是否存在
+        $map = ['name' => $all_data['name']];
+        $data = $ProductCategoryModel->where($map)->where('id', '!=', $id)->first();
+        if ($data)     return json_send(['code' => 'error', 'msg' => '记录已存在']);
+        // 更新数据表
+        $where = ['id' => $id];
+        $result =  $ProductCategoryModel->updateProductCategory($where, $all_data);
+        // 如果操作失败
+        if (!$result)     return json_send(['code' => 'error', 'msg' => '修改失败']);
+        // 告知结果
+        return json_send(['code' => 'success', 'msg' => '修改成功']);
+    }
+
+    /**
+     * 修改状态
+     * @author    唐远望
+     * @version   1.0
+     * @date      2025-12-18
+     * 
+     */
+    public function set_status(Request $request, ProductCategoryModel $ProductCategoryModel)
+    {
+        // 验证参数
+        $request->scene('set_status')->validate();
+        // 接收数据
+        $id                = request('id', 0);
+        $status            = request('status', 0);
+        // 查询用户
+        $where = ['id' => $id];
+        // 执行修改
+        $result            =  $ProductCategoryModel->changeStatus($where, $status);
+        // 提示新增失败
+        if (!$result)    return json_send(['code' => 'error', 'msg' => '设置失败']);
+        // 告知结果
+        return             json_send(['code' => 'success', 'msg' => '设置成功']);
+    }
+
+
+    /**
+     * 删除
+     * @author    唐远望
+     * @version   1.0
+     * @date      2025-12-18
+     * 
+     */
+    public function delete(Request $request, ProductCategoryModel $ProductCategoryModel)
+    {
+        // 验证参数
+        $request->scene('delete')->validate();
+        // 接收数据
+        $id = request('id', 0);
+        // 查询用户
+        $where = ['id' => $id];
+        // 执行删除
+        $result =  $ProductCategoryModel->deleteProductCategory($where);
+        // 提示删除失败
+        if (!$result)    return json_send(['code' => 'error', 'msg' => '删除失败']);
+        // 告知结果
+        return             json_send(['code' => 'success', 'msg' => '删除成功']);
+    }
+}

+ 78 - 0
app/Http/Requests/Manager/WashConfig/ProductCategory.php

@@ -0,0 +1,78 @@
+<?php
+
+namespace App\Http\Requests\Manager\WashConfig;
+
+use App\Http\Requests\BaseRequest;
+
+/**
+ * 数据清洗-产品分类
+ * @author 唐远望
+ * @version 1.0
+ * @date 2025-12-18
+ * 
+ */
+class ProductCategory 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',
+        ];
+    }
+
+
+    // 场景列表
+    protected   $scenes         = [
+        'detail'             => ['id'],
+        'list'               => ['page', 'limit'],
+        'add'                      => ['name'],
+        'edit'                  => ['id','name'],
+        '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'              => '排序格式错误',
+        ];
+    }
+}

+ 151 - 0
app/Models/Manager/WashConfig/ProductCategory.php

@@ -0,0 +1,151 @@
+<?php
+
+namespace App\Models\manager\washConfig;
+
+use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Support\Facades\DB;
+
+/**
+ * 商品分类模型
+ * @author 唐远望
+ * @version 1.0
+ * @date 2025-12-18
+ */
+class ProductCategory extends Model
+{
+    use HasFactory;
+    // 与模型关联的表名
+    protected $table = 'washconfig_product_category';
+    // 是否主动维护时间戳
+    public $timestamps = false;
+    // 定义时间戳字段名
+    // const CREATED_AT = 'insert_time';
+    // const UPDATED_AT = 'update_time';
+
+
+    /**
+     * 添加
+     * @author 唐远望
+     * @version 1.0
+     * @date 2025-12-18
+     */
+    public function addProductCategory_content($data)
+    {
+        $insert_data = [
+            'name' => $data['name'],
+            'insert_time' => time(),
+        ];
+        $ProductCategory_id = $this->insertGetId($insert_data);
+        return $ProductCategory_id;
+    }
+
+
+    /**
+     * 写入数据
+     * @author 唐远望
+     * @version 1.0
+     * @date 2025-12-18
+     * @param $data
+     * @return bool
+     */
+    public function addProductCategory($data)
+    {
+        DB::beginTransaction();
+        try {
+            $this->addProductCategory_content($data);
+            DB::commit();
+            return true;
+            // 成功处理...
+        } catch (\Exception $e) {
+            DB::rollBack();
+            // 错误处理...
+            return false;
+        }
+    }
+
+
+    /**
+     * 编辑内容
+     * @author 唐远望
+     * @version 1.0
+     * @date 2025-12-18
+     * @param $data
+     * @return bool
+     */
+    public function editProductCategory_content($where, $data)
+    {
+        $ProductCategory = $this->where($where)->first();
+        if (!$ProductCategory) {
+            return false;
+        }
+        $ProductCategory->name = $data['name'];
+        $ProductCategory->update_time = time();
+        $ProductCategory->save();
+        return true;
+    }
+
+
+
+    /**
+     * 更新数据
+     * @author 唐远望
+     * @version 1.0
+     * @date 2025-12-18
+     * @param $data
+     * @return bool
+     */
+    public function updateProductCategory($where, $data)
+    {
+        DB::beginTransaction();
+        try {
+            $this->editProductCategory_content($where, $data);
+            DB::commit();
+            return true;
+            // 成功处理...
+        } catch (\Exception $e) {
+            DB::rollBack();
+            // 错误处理...
+            return false;
+        }
+    }
+
+    /**
+     * 修改状态
+     * @author 唐远望
+     * @version 1.0
+     * @date 2025-12-18
+     * @param $id
+     * @param $status
+     * @return bool
+     */
+    public function changeStatus($where, $status)
+    {
+        $ProductCategory = $this->where($where)->first();
+        if (!$ProductCategory) {
+            return false;
+        }
+        $ProductCategory->status = $status;
+        $ProductCategory->update_time = time();
+        $ProductCategory->save();
+        return true;
+    }
+
+    /**
+     * 删除数据
+     * @author 唐远望
+     * @version 1.0
+     * @date 2025-12-18
+     * @param $id
+     * @return bool
+     */
+    public function deleteProductCategory($where)
+    {
+        $ProductCategory = $this->where($where)->first();
+        if (!$ProductCategory) {
+            return false;
+        }
+        $ProductCategory->delete();
+        return true;
+    }
+}

+ 15 - 0
routes/manager.php

@@ -47,6 +47,21 @@ Route::any('admin_user/set_status', [App\Http\Controllers\Manager\AdminUser::cla
 Route::any('admin_user/alter_password', [App\Http\Controllers\Manager\AdminUser::class, 'alter_password']);
 
 // ------数据清洗配置------
+//商品分类-列表
+Route::any('product_category/list', [App\Http\Controllers\Manager\WashConfig\ProductCategory::class, 'list']);
+//商品分类-详情
+Route::any('product_category/detail', [App\Http\Controllers\Manager\WashConfig\ProductCategory::class, 'detail']);
+//商品分类-添加
+Route::any('product_category/add', [App\Http\Controllers\Manager\WashConfig\ProductCategory::class, 'add']);
+//商品分类-修改
+Route::any('product_category/edit', [App\Http\Controllers\Manager\WashConfig\ProductCategory::class, 'edit']);
+//商品分类-状态
+Route::any('product_category/set_status', [App\Http\Controllers\Manager\WashConfig\ProductCategory::class, 'set_status']);
+//商品分类-删除
+Route::any('product_category/delete', [App\Http\Controllers\Manager\WashConfig\ProductCategory::class, 'delete']);
+//商品分类-全部
+Route::any('product_category/all', [App\Http\Controllers\Manager\WashConfig\ProductCategory::class, 'all']);
+
 // 低价商品-列表
 Route::any('low_price_goods/list', [App\Http\Controllers\Manager\WashConfig\LowPriceGoods::class, 'list']);
 // 低价商品-详情