فهرست منبع

[智价云] 数据清洗-违规店铺接口

tangyuanwang 1 هفته پیش
والد
کامیت
f2dbdf8275

+ 176 - 0
app/Http/Controllers/Manager/WashConfig/ViolationStore.php

@@ -0,0 +1,176 @@
+<?php
+
+namespace App\Http\Controllers\Manager\WashConfig;
+
+use App\Http\Controllers\Controller;
+use App\Http\Requests\Manager\WashConfig\ViolationStore as Request;
+use App\Models\Manager\WashConfig\ViolationStore as ViolationStoreModel;
+
+
+/**
+ * 数据清洗-违规店铺配置
+ * @author    唐远望
+ * @version   1.0
+ * @date      2025-12-03
+ */
+class ViolationStore extends Controller
+{
+    /**
+     * 列表
+     * @author    唐远望
+     * @version   1.0
+     * @date      2025-12-03
+     * 
+     */
+    public function list(Request $request, ViolationStoreModel $ViolationStoreModel)
+    {
+        $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', '');
+        $store_name = request('store_name', '');
+        $company_name = request('company_name', '');
+        $social_credit_code = request('social_credit_code', '');
+        // 时间条件
+        if ($start_time) $map[] = ['insert_time', '>=', strtotime($start_time)];
+        if ($end_time) $map[]   = ['insert_time', '<=', strtotime($end_time)];
+        // 其他条件
+        if ($status) $map[] = ['status', '=', $status];
+        if ($social_credit_code) $map[] = ['social_credit_code', 'like', "%$social_credit_code%"];
+        if ($company_name) $map[] = ['company_name', 'like', "%$company_name%"];
+        if ($store_name) $map[] = ['store_name', 'like', "%$store_name%"];
+        // 查询数据
+        $result = $ViolationStoreModel->query()
+            ->where($map)
+            ->orderByDesc('id')
+            ->paginate($limit);
+        // 分配数据
+        if (!$result)  return json_send(['code' => 'error', 'msg' => '暂无数据']);
+        // 加载模板
+        return        json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
+    }
+
+    /**
+     * 详情
+     * @author    唐远望
+     * @version   1.0
+     * @date      2025-12-03
+     */
+    public function detail(Request $request, ViolationStoreModel $ViolationStoreModel)
+    {
+        $request->scene('detail')->validate();
+        // 接收参数
+        $id = request('id', 0);
+        $map = ['id' => $id];
+        $data = $ViolationStoreModel->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-03
+     * 
+     */
+    public function add(Request $request, ViolationStoreModel $ViolationStoreModel)
+    {
+        $request->scene('add')->validate();
+        // 接收数据
+        $all_data = request()->all();
+        $store_scope = request('store_scope', '');
+        $all_data['store_scope'] = $store_scope;
+        //查询是否存在
+        $map = ['store_name' => $all_data['store_name'], 'company_name' => $all_data['company_name']];
+        $data = $ViolationStoreModel->where($map)->first();
+        if ($data)     return json_send(['code' => 'error', 'msg' => '记录已存在']);
+        // 写入数据表
+        $result     =  $ViolationStoreModel->addViolationStore($all_data);
+        // 如果操作失败
+        if (!$result)     return json_send(['code' => 'error', 'msg' => '新增失败']);
+        // 告知结果
+        return json_send(['code' => 'success', 'msg' => '新增成功']);
+    }
+
+    /**
+     * 修改
+     * @author    唐远望
+     * @version   1.0
+     * @date      2025-12-03
+     * 
+     */
+    public function edit(Request $request, ViolationStoreModel $ViolationStoreModel)
+    {
+        $request->scene('edit')->validate();
+        // 接收参数
+        $id         = request('id', 0);
+        // 接收数据
+        $all_data = request()->all();
+        $store_scope = request('store_scope','');
+        $all_data['store_scope'] = $store_scope;
+                //查询是否存在
+         $map = ['store_name' => $all_data['store_name'], 'company_name' => $all_data['company_name']];
+        $data = $ViolationStoreModel->where($map)->where('id', '!=', $id)->first();
+        if ($data)     return json_send(['code' => 'error', 'msg' => '记录已存在']);
+        // 更新数据表
+        $where = ['id' => $id];
+        $result =  $ViolationStoreModel->updateViolationStore($where, $all_data);
+        // 如果操作失败
+        if (!$result)     return json_send(['code' => 'error', 'msg' => '修改失败']);
+        // 告知结果
+        return json_send(['code' => 'success', 'msg' => '修改成功']);
+    }
+
+    /**
+     * 修改状态
+     * @author    唐远望
+     * @version   1.0
+     * @date      2025-12-03
+     * 
+     */
+    public function set_status(Request $request, ViolationStoreModel $ViolationStoreModel)
+    {
+        // 验证参数
+        $request->scene('set_status')->validate();
+        // 接收数据
+        $id                = request('id', 0);
+        $status            = request('status', 0);
+        // 查询用户
+        $where = ['id' => $id];
+        // 执行修改
+        $result            =  $ViolationStoreModel->changeStatus($where, $status);
+        // 提示新增失败
+        if (!$result)    return json_send(['code' => 'error', 'msg' => '设置失败']);
+        // 告知结果
+        return             json_send(['code' => 'success', 'msg' => '设置成功']);
+    }
+
+
+    /**
+     * 删除
+     * @author    唐远望
+     * @version   1.0
+     * @date      2025-12-03
+     * 
+     */
+    public function delete(Request $request, ViolationStoreModel $ViolationStoreModel)
+    {
+        // 验证参数
+        $request->scene('delete')->validate();
+        // 接收数据
+        $id = request('id', 0);
+        // 查询用户
+        $where = ['id' => $id];
+        // 执行删除
+        $result =  $ViolationStoreModel->deleteViolationStore($where);
+        // 提示删除失败
+        if (!$result)    return json_send(['code' => 'error', 'msg' => '删除失败']);
+        // 告知结果
+        return             json_send(['code' => 'success', 'msg' => '删除成功']);
+    }
+}

+ 81 - 0
app/Http/Requests/Manager/WashConfig/ViolationStore.php

@@ -0,0 +1,81 @@
+<?php
+
+namespace App\Http\Requests\Manager\WashConfig;
+
+use App\Http\Requests\BaseRequest;
+
+/**
+ * 数据清洗配置-违规店铺
+ * @author 唐远望
+ * @version 1.0
+ * @date 2025-12-03
+ * 
+ */
+class ViolationStore 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',
+            'store_name'        => 'required',
+            'company_name'      => 'required',
+            'social_credit_code'    => 'required',
+            'store_type'        => 'required',
+        ];
+    }
+
+
+    // 场景列表
+    protected   $scenes         = [
+        'detail'             => ['id'],
+        'list'               => ['page', 'limit'],
+        'add'                      => ['store_name', 'company_name', 'social_credit_code', 'store_type'],
+        'edit'                  => ['id', 'store_name', 'company_name', 'social_credit_code', 'store_type'],
+        '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'              => '排序格式错误',
+            'store_name.required'    => '店铺名称未知',
+            'company_name.required'  => '公司名称未知',
+            'social_credit_code.required'  => '社会信用代码未知',
+            'store_type.required'    => '店铺类型未知',
+        ];
+    }
+}

+ 159 - 0
app/Models/Manager/WashConfig/ViolationStore.php

@@ -0,0 +1,159 @@
+<?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-03
+ */
+class ViolationStore extends Model
+{
+    use HasFactory;
+    // 与模型关联的表名
+    protected $table = 'washconfig_violation_store';
+    // 是否主动维护时间戳
+    public $timestamps = false;
+    // 定义时间戳字段名
+    // const CREATED_AT = 'insert_time';
+    // const UPDATED_AT = 'update_time';
+
+
+
+    /**
+     * 添加
+     * @author 唐远望
+     * @version 1.0
+     * @date 2025-12-03
+     */
+    public function addViolationStore_content($data)
+    {
+        $insert_data = [
+            'store_name' => $data['store_name'],
+            'company_name' => $data['company_name'],
+            'social_credit_code'    => $data['social_credit_code'],
+            'store_type'    => $data['store_type'],
+            'insert_time' => time(),
+        ];
+        $ViolationStore_id = $this->insertGetId($insert_data);
+        return $ViolationStore_id;
+    }
+
+
+    /**
+     * 写入数据
+     * @author 唐远望
+     * @version 1.0
+     * @date 2025-12-03
+     * @param $data
+     * @return bool
+     */
+    public function addViolationStore($data)
+    {
+        DB::beginTransaction();
+        try {
+            $this->addViolationStore_content($data);
+            DB::commit();
+            return true;
+            // 成功处理...
+        } catch (\Exception $e) {
+            DB::rollBack();
+            // 错误处理...
+            return false;
+        }
+    }
+
+
+    /**
+     * 编辑内容
+     * @author 唐远望
+     * @version 1.0
+     * @date 2025-12-03
+     * @param $data
+     * @return bool
+     */
+    public function editViolationStore_content($where, $data)
+    {
+        $ViolationStore = $this->where($where)->first();
+        if (!$ViolationStore) {
+            return false;
+        }
+        $ViolationStore->store_name = $data['store_name'];
+        $ViolationStore->company_name = $data['company_name'];
+        $ViolationStore->social_credit_code = $data['social_credit_code'];
+        $ViolationStore->store_type = $data['store_type'];
+        $ViolationStore->update_time = time();
+        $ViolationStore->save();
+        return true;
+    }
+
+
+
+    /**
+     * 更新数据
+     * @author 唐远望
+     * @version 1.0
+     * @date 2025-12-03
+     * @param $data
+     * @return bool
+     */
+    public function updateViolationStore($where, $data)
+    {
+        DB::beginTransaction();
+        try {
+            $this->editViolationStore_content($where, $data);
+            DB::commit();
+            return true;
+            // 成功处理...
+        } catch (\Exception $e) {
+            DB::rollBack();
+            // 错误处理...
+            return false;
+        }
+    }
+
+    /**
+     * 修改状态
+     * @author 唐远望
+     * @version 1.0
+     * @date 2025-12-03
+     * @param $id
+     * @param $status
+     * @return bool
+     */
+    public function changeStatus($where, $status)
+    {
+        $ViolationStore = $this->where($where)->first();
+        if (!$ViolationStore) {
+            return false;
+        }
+        $ViolationStore->status = $status;
+        $ViolationStore->update_time = time();
+        $ViolationStore->save();
+        return true;
+    }
+
+    /**
+     * 删除数据
+     * @author 唐远望
+     * @version 1.0
+     * @date 2025-12-03
+     * @param $id
+     * @return bool
+     */
+    public function deleteViolationStore($where)
+    {
+        $ViolationStore = $this->where($where)->first();
+        if (!$ViolationStore) {
+            return false;
+        }
+        $ViolationStore->delete();
+        return true;
+    }
+}

+ 27 - 1
routes/manager.php

@@ -44,4 +44,30 @@ Route::any('low_price_goods/edit', [App\Http\Controllers\Manager\WashConfig\LowP
 // 低价商品-状态
 Route::any('low_price_goods/set_status', [App\Http\Controllers\Manager\WashConfig\LowPriceGoods::class, 'set_status']);
 // 低价商品-删除
-Route::any('low_price_goods/delete', [App\Http\Controllers\Manager\WashConfig\LowPriceGoods::class, 'delete']);
+Route::any('low_price_goods/delete', [App\Http\Controllers\Manager\WashConfig\LowPriceGoods::class, 'delete']);
+
+// 违规商品-列表
+Route::any('violation_goods/list', [App\Http\Controllers\Manager\WashConfig\ViolationProduct::class, 'list']);
+// 违规商品-详情
+Route::any('violation_goods/detail', [App\Http\Controllers\Manager\WashConfig\ViolationProduct::class, 'detail']);
+// 违规商品-添加
+Route::any('violation_goods/add', [App\Http\Controllers\Manager\WashConfig\ViolationProduct::class, 'add']);
+// 违规商品-修改
+Route::any('violation_goods/edit', [App\Http\Controllers\Manager\WashConfig\ViolationProduct::class, 'edit']);
+// 违规商品-状态
+Route::any('violation_goods/set_status', [App\Http\Controllers\Manager\WashConfig\ViolationProduct::class, 'set_status']);
+// 违规商品-删除
+Route::any('violation_goods/delete', [App\Http\Controllers\Manager\WashConfig\ViolationProduct::class, 'delete']);
+
+// 违规店铺-列表
+Route::any('violation_store/list', [App\Http\Controllers\Manager\WashConfig\ViolationStore::class, 'list']);
+// 违规店铺-详情
+Route::any('violation_store/detail', [App\Http\Controllers\Manager\WashConfig\ViolationStore::class, 'detail']);
+// 违规店铺-添加
+Route::any('violation_store/add', [App\Http\Controllers\Manager\WashConfig\ViolationStore::class, 'add']);
+// 违规店铺-修改
+Route::any('violation_store/edit', [App\Http\Controllers\Manager\WashConfig\ViolationStore::class, 'edit']);
+// 违规店铺-状态
+Route::any('violation_store/set_status', [App\Http\Controllers\Manager\WashConfig\ViolationStore::class, 'set_status']);
+// 违规店铺-删除
+Route::any('violation_store/delete', [App\Http\Controllers\Manager\WashConfig\ViolationStore::class, 'delete']);