scene('list')->validate(); // 查询条件 $map = []; $limit = request('limit', config('page_num', 10)); $status = request('status', ''); $start_time = request('start_time', ''); $end_time = request('end_time', ''); $product_name = request('product_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 ($product_name) $map[] = ['product_name', 'like', "%$product_name%"]; // 查询数据 $result = $LowPriceGoodsModel->query() ->where($map) ->orderByDesc('id') ->paginate($limit)->toarray(); // 分配数据 if (!$result) return json_send(['code' => 'error', 'msg' => '暂无数据']); if(isset($result['data']) && count($result['data']) > 0){ foreach ($result['data'] as $key => $value) { $result['data'][$key]['platform'] = isset($value['platform']) ? explode(',',$value['platform']) : ''; //查询店铺名称 if(trim($value['store_scope']) == ''){ $result['data'][$key]['store_name'] =['全部店铺']; }else{ $store_scope = explode(',',$value['store_scope']); $store_name = $ViolationStoreModel->whereIn('id',$store_scope)->pluck('store_name'); $result['data'][$key]['store_name'] = $store_name; } } } // 加载模板 return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]); } /** * 详情 * @author 唐远望 * @version 1.0 * @date 2025-12-02 */ public function detail(Request $request, LowPriceGoodsModel $LowPriceGoodsModel,ViolationStoreModel $ViolationStoreModel) { $request->scene('detail')->validate(); // 接收参数 $id = request('id', 0); $map = ['id' => $id]; $data = $LowPriceGoodsModel->where($map)->first(); if (!$data) return json_send(['code' => 'error', 'msg' => '记录不存在']); //查询店铺名称 if(trim($data['store_scope']) == ''){ $data['store_name'] = ['全部店铺']; }else{ $store_scope = explode(',',$data['store_scope']); $store_name = $ViolationStoreModel->whereIn('id',$store_scope)->pluck('store_name'); $data['store_name'] = $store_name; } $data->platform = isset($data->platform) ? explode(',',$data->platform) : ''; // 加载模板 return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $data]); } /** * 添加 * @author 唐远望 * @version 1.0 * @date 2025-12-02 * */ public function add(Request $request, LowPriceGoodsModel $LowPriceGoodsModel) { $request->scene('add')->validate(); // 接收数据 $all_data = request()->all(); $store_scope = request('store_scope', ''); $all_data['store_scope'] = $store_scope; //查询是否存在 $map = ['product_name' => $all_data['product_name'], 'product_specs' => $all_data['product_specs']]; $data = $LowPriceGoodsModel->where($map)->first(); if ($data) return json_send(['code' => 'error', 'msg' => '记录已存在']); // 写入数据表 $result = $LowPriceGoodsModel->addLowProduct($all_data); // 如果操作失败 if (!$result) return json_send(['code' => 'error', 'msg' => '新增失败']); // 告知结果 return json_send(['code' => 'success', 'msg' => '新增成功']); } /** * 修改 * @author 唐远望 * @version 1.0 * @date 2025-12-02 * */ public function edit(Request $request, LowPriceGoodsModel $LowPriceGoodsModel) { $request->scene('edit')->validate(); // 接收参数 $id = request('id', 0); // 接收数据 $all_data = request()->all(); $store_scope = request('store_scope',''); $all_data['store_scope'] = $store_scope; //查询是否存在 $map = ['product_name' => $all_data['product_name'], 'product_specs' => $all_data['product_specs']]; $data = $LowPriceGoodsModel->where($map)->where('id', '!=', $id)->first(); if ($data) return json_send(['code' => 'error', 'msg' => '记录已存在']); // 更新数据表 $where = ['id' => $id]; $result = $LowPriceGoodsModel->updateLowProduct($where, $all_data); // 如果操作失败 if (!$result) return json_send(['code' => 'error', 'msg' => '修改失败']); // 告知结果 return json_send(['code' => 'success', 'msg' => '修改成功']); } /** * 修改状态 * @author 唐远望 * @version 1.0 * @date 2025-12-02 * */ public function set_status(Request $request, LowPriceGoodsModel $LowPriceGoodsModel) { // 验证参数 $request->scene('set_status')->validate(); // 接收数据 $id = request('id', 0); $status = request('status', 0); // 查询用户 $where = ['id' => $id]; // 执行修改 $result = $LowPriceGoodsModel->changeStatus($where, $status); // 提示新增失败 if (!$result) return json_send(['code' => 'error', 'msg' => '设置失败']); // 告知结果 return json_send(['code' => 'success', 'msg' => '设置成功']); } /** * 删除 * @author 唐远望 * @version 1.0 * @date 2025-12-02 * */ public function delete(Request $request, LowPriceGoodsModel $LowPriceGoodsModel) { // 验证参数 $request->scene('delete')->validate(); // 接收数据 $id = request('id', 0); // 查询用户 $where = ['id' => $id]; // 执行删除 $result = $LowPriceGoodsModel->deleteLowProduct($where); // 提示删除失败 if (!$result) return json_send(['code' => 'error', 'msg' => '删除失败']); // 告知结果 return json_send(['code' => 'success', 'msg' => '删除成功']); } }