| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366 |
- <?php
- namespace App\Http\Controllers\Manager\WashConfig;
- use App\Http\Controllers\Controller;
- use App\Http\Requests\Manager\WashConfig\ViolationProduct as Request;
- use App\Models\Manager\WashConfig\ViolationProduct as ViolationProductModel;
- use App\Models\Manager\WashConfig\ViolationStore as ViolationStoreModel;
- use App\Models\Manager\WashConfig\ViolationProductCompany as ViolationProductCompanyModel;
- use App\Models\Manager\WashConfig\ProductCategory as ProductCategoryModel;
- use Illuminate\Support\Facades\DB;
- use App\Models\Manager\WashConfig\LowPriceGoods as LowPriceGoodsModel;
- use Illuminate\Support\Carbon;
- /**
- * 数据清洗-禁止产品配置
- * @author 唐远望
- * @version 1.0
- * @date 2025-12-03
- */
- class ViolationProduct extends Controller
- {
- /**
- * 列表
- * @author 唐远望
- * @version 1.0
- * @date 2025-12-03
- *
- */
- public function list(Request $request, ViolationProductModel $ViolationProductModel, ViolationStoreModel $ViolationStoreModel, ViolationProductCompanyModel $ViolationProductCompanyModel, ProductCategoryModel $ProductCategoryModel)
- {
- $request->scene('list')->validate();
- $admin_company_id = request('admin_company_id', '0');
- $company_id = request('access_token.company_id', '0');
- $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
- // 查询条件
- $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', '');
- $platform = request('platform', '');
- $store_scope = request('store_scope', '');
- $company_scope = request('company_scope', '');
- $category_id = request('category_id', '');
- // 时间条件
- 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%"];
- if ($platform) $map[] = ['platform', 'like', "%$platform%"];
- if ($store_scope) $map[] = ['store_scope', '=', $store_scope];
- if ($company_scope) $map[] = ['company_scope', '=', $company_scope];
- if ($category_id) $map[] = ['category_id', '=', $category_id];
- // 查询数据
- if ($is_admin != 1 && $company_id != 0) {
- $map[] = ['company_id', '=', $company_id];
- } else {
- $map[] = ['company_id', '=', $admin_company_id];
- }
- $result = $ViolationProductModel->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) {
- $result['data'][$key]['platform'] = isset($value['platform']) ? explode(',', $value['platform']) : '';
- $category_name = $value['category_id'] > 0 ? $ProductCategoryModel->where('id', $value['category_id'])->value('name') : '';
- $result['data'][$key]['category_name'] = $category_name;
- //查询店铺名称
- if (trim($value['store_scope']) == '') {
- $result['data'][$key]['store_name'] = ['全部店铺'];
- } else {
- $result['data'][$key]['store_name'] = '';
- }
- //查询公司名称
- if ($value['company_scope'] == '1') {
- $result['data'][$key]['company_name'] = ['全部公司'];
- } else {
- $company_data = $ViolationProductCompanyModel->where('violation_product_logid', $value['id'])
- ->join('washconfig_violation_store', 'washconfig_violation_store.id', '=', 'washconfig_violation_product_company.company_id')
- ->select(['washconfig_violation_store.id', 'washconfig_violation_store.company_name', 'washconfig_violation_product_company.company_id'])->get()->toArray();
- $result['data'][$key]['company_name'] = !empty($company_data) ? array_column($company_data, 'company_name') : '';
- }
- }
- }
- // 加载模板
- return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
- }
- /**
- * 详情
- * @author 唐远望
- * @version 1.0
- * @date 2025-12-03
- */
- public function detail(Request $request, ViolationProductModel $ViolationProductModel, ViolationProductCompanyModel $ViolationProductCompanyModel, ProductCategoryModel $ProductCategoryModel)
- {
- $request->scene('detail')->validate();
- $admin_company_id = request('admin_company_id', '0');
- $company_id = request('access_token.company_id', '0');
- $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
- // 接收参数
- $id = request('id', 0);
- $map = ['id' => $id];
- if ($is_admin != 1 && $company_id != 0) {
- $map['company_id'] = $company_id;
- } else {
- $map['company_id'] = $admin_company_id;
- }
- $data = $ViolationProductModel->where($map)->first();
- if (!$data) return json_send(['code' => 'error', 'msg' => '记录不存在']);
- //查询店铺名称
- if (trim($data['store_scope']) == '') {
- $data['store_name'] = ['全部店铺'];
- } else {
- $data['store_name'] = '';
- }
- //查询公司名称
- if ($data->company_scope == '1') {
- $data->company_name = ['全部公司'];
- $data->company_ids = '';
- } else {
- $company_data = $ViolationProductCompanyModel->where('violation_product_logid', $data->id)
- ->join('washconfig_violation_store', 'washconfig_violation_store.id', '=', 'washconfig_violation_product_company.company_id')
- ->select(['washconfig_violation_store.id', 'washconfig_violation_store.company_name', 'washconfig_violation_product_company.company_id'])->get()->toArray();
- $data->company_name = !empty($company_data) ? array_column($company_data, 'company_name') : '';
- $data->company_ids = !empty($company_data) ? array_column($company_data, 'company_id') : '';
- }
- $data->platform = isset($data->platform) ? explode(',', $data->platform) : '';
- $data->category_name = $data->category_id > 0 ? $ProductCategoryModel->where('id', $data->category_id)->value('name') : '';
- // 加载模板
- return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $data]);
- }
- /**
- * 添加
- * @author 唐远望
- * @version 1.0
- * @date 2025-12-03
- *
- */
- public function add(Request $request, ViolationProductModel $ViolationProductModel, LowPriceGoodsModel $LowPriceGoodsModel)
- {
- $request->scene('add')->validate();
- $admin_company_id = request('admin_company_id', '0');
- $company_id = request('access_token.company_id', '0');
- $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
- $status_where = ['status' => 0];
- if ($is_admin != 1 && $company_id != 0) {
- $status_where['company_id'] = $company_id;
- } else {
- $status_where['company_id'] = $admin_company_id;
- }
- //获取禁止商品启动数量
- $violation_product_count = $ViolationProductModel->where($status_where)->count();
- //获取低价挂网商品启用数量
- $lowprice_product_count = $LowPriceGoodsModel->where($status_where)->count();
- //计算总数量
- $product_totle = $violation_product_count + $lowprice_product_count;
- //判断是否超过限制
- if ($product_totle >= 50) {
- return json_send(['code' => 'error', 'msg' => '启用数量超过限制,低价挂网和禁止商品不能超过50条']);
- }
- // 接收数据
- $all_data = request()->all();
- $store_scope = request('store_scope', '');
- $all_data['store_scope'] = $store_scope;
- $company_scope = request('company_scope', '');
- $all_data['company_scope'] = $company_scope;
- $category_id = request('category_id', '');
- $all_data['category_id'] = $category_id;
- $specify_responsible_person = request('specify_responsible_person', '0');
- $all_data['specify_responsible_person'] = $specify_responsible_person;
- //查询是否存在
- $map = ['product_name' => $all_data['product_name'], 'product_specs' => $all_data['product_specs'], 'platform' => $all_data['platform']];
- if ($is_admin != 1 && $company_id != 0) {
- $map['company_id'] = $company_id;
- $all_data['company_id'] = $company_id;
- } else {
- $map['company_id'] = $admin_company_id;
- $all_data['company_id'] = $admin_company_id;
- }
- $data = $ViolationProductModel->where($map)->first();
- if ($data) return json_send(['code' => 'error', 'msg' => '记录已存在']);
- // 写入数据表
-
- $result = $ViolationProductModel->addViolationProduct($all_data);
- // 如果操作失败
- if (!$result) return json_send(['code' => 'error', 'msg' => '新增失败']);
- // 记录行为
- $admin_id = request('access_token.uid', 0); //用户ID
- $table_name = $ViolationProductModel->getTable();
- $notes_type = 1; //操作类型,1添加,2修改,3=删除
- $this->addAdminHistory('清洗配置-禁止商品管理', $company_id, $admin_id, $is_admin, $table_name, $notes_type, [], $all_data, '新增了禁止商品' . $all_data['product_name'] . '信息');
- // 告知结果
- return json_send(['code' => 'success', 'msg' => '新增成功']);
- }
- /**
- * 修改
- * @author 唐远望
- * @version 1.0
- * @date 2025-12-03
- *
- */
- public function edit(Request $request, ViolationProductModel $ViolationProductModel)
- {
- $request->scene('edit')->validate();
- $admin_company_id = request('admin_company_id', '0');
- $company_id = request('access_token.company_id', '0');
- $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
- // 接收参数
- $id = request('id', 0);
- // 接收数据
- $all_data = request()->all();
- $store_scope = request('store_scope', '');
- $all_data['store_scope'] = $store_scope;
- $company_scope = request('company_scope', '');
- $all_data['company_scope'] = $company_scope;
- $category_id = request('category_id', '');
- $all_data['category_id'] = $category_id;
- $specify_responsible_person = request('specify_responsible_person', '0');
- $all_data['specify_responsible_person'] = $specify_responsible_person;
- //查询是否存在
- $map = ['product_name' => $all_data['product_name'], 'product_specs' => $all_data['product_specs'], 'platform' => $all_data['platform']];
- if ($is_admin != 1 && $company_id != 0) {
- $map['company_id'] = $company_id;
- $all_data['company_id'] = $company_id;
- } else {
- $map['company_id'] = $admin_company_id;
- $all_data['company_id'] = $admin_company_id;
- }
- $data = $ViolationProductModel->where($map)->where('id', '!=', $id)->first();
- if ($data) return json_send(['code' => 'error', 'msg' => '记录已存在']);
- // 更新数据表
- $where = ['id' => $id];
- if ($is_admin != 1 && $company_id != 0) {
- $where['company_id'] = $company_id;
- } else {
- $where['company_id'] = $admin_company_id;
- }
- $ViolationProduct = $ViolationProductModel->where($where)->first();
- if (!$ViolationProduct) return json_send(['code' => 'error', 'msg' => '记录不存在']);
- $oldData = $ViolationProduct->toarray();
- $result = $ViolationProductModel->editViolationProduct_content($ViolationProduct, $all_data);
- // 如果操作失败
- if (!$result) return json_send(['code' => 'error', 'msg' => '修改失败']);
- // 记录行为
- $admin_id = request('access_token.uid', 0); //用户ID
- $table_name = $ViolationProductModel->getTable();
- $notes_type = 2; //操作类型,1添加,2修改,3=删除
- $this->addAdminHistory('清洗配置-禁止商品管理', $company_id, $admin_id, $is_admin, $table_name, $notes_type, $oldData, $all_data, '修改了禁止商品' . $oldData['product_name'] . '信息');
- // 告知结果
- return json_send(['code' => 'success', 'msg' => '修改成功']);
- }
- /**
- * 修改状态
- * @author 唐远望
- * @version 1.0
- * @date 2025-12-03
- *
- */
- public function set_status(Request $request, ViolationProductModel $ViolationProductModel, LowPriceGoodsModel $LowPriceGoodsModel)
- {
- // 验证参数
- $request->scene('set_status')->validate();
- $admin_company_id = request('admin_company_id', '0');
- $company_id = request('access_token.company_id', '0');
- $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
- // 接收数据
- $id = request('id', 0);
- $status = request('status', 0);
- if ($status == 0) {
- //获取禁止商品启动数量
- $violation_product_count = $ViolationProductModel->where('status', 0)->count();
- //获取低价挂网商品启用数量
- $lowprice_product_count = $LowPriceGoodsModel->where('status', 0)->count();
- //计算总数量
- $product_totle = $violation_product_count + $lowprice_product_count;
- //判断是否超过限制
- if ($product_totle >= 50) {
- return json_send(['code' => 'error', 'msg' => '启用数量超过限制,低价挂网和禁止商品不能超过50条']);
- }
- }
- // 查询用户
- $where = ['id' => $id];
- if ($is_admin != 1 && $company_id != 0) {
- $where['company_id'] = $company_id;
- } else {
- $where['company_id'] = $admin_company_id;
- }
- $ViolationProduct = $ViolationProductModel->where($where)->first();
- if (!$ViolationProduct) return json_send(['code' => 'error', 'msg' => '记录不存在']);
- // 执行修改
- $result = $ViolationProductModel->changeStatus($ViolationProduct, $status);
- // 提示新增失败
- if (!$result) return json_send(['code' => 'error', 'msg' => '设置失败']);
- // 记录行为
- $admin_id = request('access_token.uid', 0); //用户ID
- $table_name = $ViolationProductModel->getTable();
- $notes_type = 2; //操作类型,1添加,2修改,3=删除
- $this->addAdminHistory('清洗配置-禁止商品管理', $company_id, $admin_id, $is_admin, $table_name, $notes_type, [], ['status' => $status], '修改了禁止商品' . $ViolationProduct->product_name . '状态');
- // 告知结果
- return json_send(['code' => 'success', 'msg' => '设置成功']);
- }
- /**
- * 删除
- * @author 唐远望
- * @version 1.0
- * @date 2025-12-03
- *
- */
- public function delete(Request $request, ViolationProductModel $ViolationProductModel)
- {
- // 验证参数
- $request->scene('delete')->validate();
- $admin_company_id = request('admin_company_id', '0');
- $company_id = request('access_token.company_id', '0');
- $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
- // 接收数据
- $id = request('id', 0);
- // 查询用户
- $where = ['id' => $id];
- if ($is_admin != 1 && $company_id != 0) {
- $where['company_id'] = $company_id;
- } else {
- $where['company_id'] = $admin_company_id;
- }
- // 执行删除
- $ViolationProduct = $ViolationProductModel->where($where)->first();
- if (!$ViolationProduct) {
- return false;
- }
- $ViolationProduct_log = $ViolationProduct->toArray();
- DB::beginTransaction();
- try {
- $ViolationProductCompanyModel = new ViolationProductCompanyModel();
- $company_id_log = $ViolationProductCompanyModel->where('violation_product_logid', $ViolationProduct->id)->get();
- if (!empty($company_id_log)) {
- $ViolationProductCompanyModel->where('violation_product_logid', $ViolationProduct->id)->delete();
- }
- $ViolationProductModel->where($where)->delete();
- // 记录行为
- $admin_id = request('access_token.uid', 0); //用户ID
- $table_name = $ViolationProductModel->getTable();
- $notes_type = 3; //操作类型,1添加,2修改,3=删除
- $this->addAdminHistory('清洗配置-禁止商品管理', $company_id, $admin_id, $is_admin, $table_name, $notes_type, $ViolationProduct_log, [], '删除了禁止商品' . $ViolationProduct_log['product_name'] . '信息');
- // 告知结果
- DB::commit();
- return json_send(['code' => 'success', 'msg' => '删除成功']);
- // 成功处理...
- } catch (\Exception $e) {
- DB::rollBack();
- // 错误处理...
- return json_send(['code' => 'error', 'msg' => '删除失败', 'data' => $e->getMessage(), 'k' => $ViolationProduct_log]);
- }
- }
- }
|