'0', '淘宝' => '1', '京东' => '2', '拼多多' => '3', '美团' => '4', '药师帮' => '5', '1药城' => '6', '药九九' => '7', '药易购' => '8', '药帮忙' => '9', '熊猫药药' => '10', '药房网' => '11' ]; return $platform_data; } /** * 添加 * @author 唐远望 * @version 1.0 * @date 2025-12-08 */ public function addViolationProduct_content($data) { $insert_data = [ 'company_id' => $data['company_id'], 'source_id' => $data['source_id'], 'first_responsible_person' => $data['first_responsible_person'] ? ',' . $data['first_responsible_person'] . ',' : '', 'responsible_person' => $data['responsible_person'] ? ',' . $data['responsible_person'] . ',' : '', 'platform' => $data['platform'], 'company_name' => $data['company_name'], 'product_brand' => isset($data['product_brand']) ? $data['product_brand'] : '', 'product_name' => $data['product_name'], 'product_specs' => $data['product_specs'], 'online_posting_count' => isset($data['online_posting_count']) && is_numeric($data['online_posting_count']) ? $data['online_posting_count'] : 1, 'continuous_listing_count' => isset($data['continuous_listing_count']) && is_numeric($data['continuous_listing_count']) ? $data['continuous_listing_count'] : 1, 'social_credit_code' => $data['social_credit_code'], 'province_id' => $data['province_id'], 'province_name' => isset($data['province_name']) ? $data['province_name'] : '', 'city_id' => $data['city_id'], 'city_name' => isset($data['city_name']) ? $data['city_name'] : '', 'area_info' => $data['area_info'], 'link_url' => $data['link_url'], 'store_name' => $data['store_name'], 'anonymous_store_name' => isset($data['anonymous_store_name']) ? $data['anonymous_store_name'] : '', 'source_responsible_person' => $data['source_responsible_person'] ? ',' . $data['source_responsible_person'] . ',' : '', 'category_name' => $data['category_name'], 'company_category_name' => $data['company_category_name'], 'processing_status' => '1', 'insert_time' => time(), 'scrape_date' => isset($data['scrape_date']) ? $data['scrape_date'] : '', 'collection_time' => isset($data['collection_time']) ? $data['collection_time'] : '', 'shipment_province_id' => isset($data['shipment_province_id']) ? $data['shipment_province_id'] : '0', // 发货省份id 'shipment_province_name' => isset($data['shipment_province_name']) ? $data['shipment_province_name'] : '', // 发货省份 'shipment_city_id' => isset($data['shipment_city_id']) ? $data['shipment_city_id'] : '0', // 发货城市id 'shipment_city_name' => isset($data['shipment_city_name']) ? $data['shipment_city_name'] : '', // 发货城市 ]; $ViolationProduct_id = $this->insertGetId($insert_data); return $ViolationProduct_id; } /** * 写入数据 * @author 唐远望 * @version 1.0 * @date 2025-12-08 * @param $data * @return bool */ public function addViolationProduct($data, $is_import = false) { if ($is_import == false) { //去重规则:品牌方公司ID+店铺公司名称+店铺名称+品牌名称+商品名称+规格+盒数(针对采集) $source_where[] = ['company_id', '=', $data['company_id']]; //品牌方公司ID $source_where[] = ['company_name', '=', $data['company_name']]; //店铺公司名称 $source_where[] = ['store_name', '=', $data['store_name']]; //店铺名称 $source_where[] = ['product_brand', '=', $data['product_brand']]; //品牌名称 $source_where[] = ['product_name', '=', $data['product_name']]; //商品名称 $source_where[] = ['product_specs', '=', $data['product_specs']]; //规格 $source_id_log = $this->where($source_where)->count(); if ($source_id_log > 0) { return true; } } DB::beginTransaction(); try { //执行挂网数据统计 $data = $this->handleCountData($data); $ViolationProductMemberModel = new ViolationProductMemberModel(); $insert_data = [ 'company_id' => $data['company_id'], 'source_id' => $data['source_id'], 'first_responsible_person' => $data['first_responsible_person'] ? ',' . $data['first_responsible_person'] . ',' : '', 'responsible_person' => $data['responsible_person'] ? ',' . $data['responsible_person'] . ',' : '', 'platform' => $data['platform'], 'company_name' => $data['company_name'], 'product_brand' => isset($data['product_brand']) ? $data['product_brand'] : '', 'product_name' => $data['product_name'], 'product_specs' => $data['product_specs'], 'online_posting_count' => isset($data['online_posting_count']) && is_numeric($data['online_posting_count']) ? $data['online_posting_count'] : 1, 'continuous_listing_count' => isset($data['continuous_listing_count']) && is_numeric($data['continuous_listing_count']) ? $data['continuous_listing_count'] : 1, 'social_credit_code' => $data['social_credit_code'], 'province_id' => $data['province_id'], 'province_name' => isset($data['province_name']) ? $data['province_name'] : '', 'city_id' => $data['city_id'], 'city_name' => isset($data['city_name']) ? $data['city_name'] : '', 'area_info' => $data['area_info'], 'link_url' => $data['link_url'], 'store_name' => $data['store_name'], 'anonymous_store_name' => isset($data['anonymous_store_name']) ? $data['anonymous_store_name'] : '', 'source_responsible_person' => $data['source_responsible_person'] ? ',' . $data['source_responsible_person'] . ',' : '', 'category_name' => $data['category_name'], 'company_category_name' => $data['company_category_name'], 'processing_status' => '1', 'insert_time' => time(), 'scrape_date' => isset($data['scrape_date']) ? $data['scrape_date'] : '', 'collection_time' => isset($data['collection_time']) ? $data['collection_time'] : '', 'shipment_province_id' => isset($data['shipment_province_id']) ? $data['shipment_province_id'] : '0', // 发货省份id 'shipment_province_name' => isset($data['shipment_province_name']) ? $data['shipment_province_name'] : '', // 发货省份 'shipment_city_id' => isset($data['shipment_city_id']) ? $data['shipment_city_id'] : '0', // 发货城市id 'shipment_city_name' => isset($data['shipment_city_name']) ? $data['shipment_city_name'] : '', // 发货城市 ]; $ViolationProduct_id = $this->insertGetId($insert_data); $first_responsible_persons = $data['first_responsible_person'] != '' ? explode(',', $data['first_responsible_person']) : []; $first_responsible_person_data = []; if (count($first_responsible_persons) > 0) { foreach ($first_responsible_persons as $key => $employee_id) { //如果不是数字或者为空,则跳过 if ($employee_id == '' || is_null($employee_id) || !is_numeric($employee_id)) continue; $first_responsible_person_data[] = [ 'violation_product_logid' => $ViolationProduct_id, 'employee_id' => $employee_id, 'duty_type' => 1, //责任类型1=第一责任人,2=责任人,3=溯源责任人 ]; } } $ViolationProductMemberModel->insert($first_responsible_person_data); $responsible_persons = $data['responsible_person'] != '' ? explode(',', $data['responsible_person']) : []; $responsible_person_data = []; if (count($responsible_persons) > 0) { foreach ($responsible_persons as $key => $employee_id) { //如果不是数字或者为空,则跳过 if ($employee_id == '' || is_null($employee_id) || !is_numeric($employee_id)) continue; $responsible_person_data[] = [ 'violation_product_logid' => $ViolationProduct_id, 'employee_id' => $employee_id, 'duty_type' => 2, //责任类型1=第一责任人,2=责任人,3=溯源责任人 ]; } } $ViolationProductMemberModel->insert($responsible_person_data); $source_responsible_persons = $data['source_responsible_person'] != '' ? explode(',', $data['source_responsible_person']) : []; $source_responsible_person_data = []; if (count($source_responsible_persons) > 0) { foreach ($source_responsible_persons as $key => $employee_id) { //如果不是数字或者为空,则跳过 if ($employee_id == '' || is_null($employee_id) || !is_numeric($employee_id)) continue; $source_responsible_person_data[] = [ 'violation_product_logid' => $ViolationProduct_id, 'employee_id' => $employee_id, 'duty_type' => 3, //责任类型1=第一责任人,2=责任人,3=溯源责任人 ]; } } $ViolationProductMemberModel->insert($source_responsible_person_data); //添加通知 // $this->addNotices($insert_data, $ViolationProduct_id); DB::commit(); return true; // 成功处理... } catch (\Exception $e) { DB::rollBack(); // 错误处理... Log::info('job_error', '数据清洗-新增违规商品处理记录失败', ['data' => $data, 'error' => $e->getMessage()]); return false; } } /** * 处理连续挂网&累计挂网数据统计 * @author 唐远望 * @version 1.0 * @date 2026-05-07 * */ public function handleCountData($product_data_info) { $collect_config_info = $product_data_info['collect_config_info']; if (trim($collect_config_info) == '') return $product_data_info; $collect_config_info = json_decode($collect_config_info, true); //{"sampling_cycle": "", "sampling_start_time": "", "sampling_end_time": ""} //采集周期 $sampling_cycle = isset($collect_config_info['sampling_cycle']) ? $collect_config_info['sampling_cycle'] : ''; //采集开始时间 $sampling_start_time = isset($collect_config_info['sampling_start_time']) ? $collect_config_info['sampling_start_time'] : ''; //采集结束时间 $sampling_end_time = isset($collect_config_info['sampling_end_time']) ? $collect_config_info['sampling_end_time'] : ''; if (!is_numeric($sampling_cycle)) return $product_data_info; $current_time = time(); //如果当前时间在采集开始时间结束时间范围内,则进行连续挂网和累计挂网统计 if ($sampling_start_time != '' && $sampling_end_time != '' && $current_time >= $sampling_start_time && $current_time <= $sampling_end_time) { //查询当前商品是否在上一个周期采集中过 $up_scrape_date_time = $current_time - $sampling_cycle * 24 * 3600; $up_scrape_date = date('Y-m-d', $up_scrape_date_time); $source_last_week_where[] = ['company_id', '=', $product_data_info['company_id']]; //品牌方公司ID $source_last_week_where[] = ['platform', '=', $product_data_info['platform']]; //挂网平台ID $source_last_week_where[] = ['company_name', '=', $product_data_info['company_name']]; //店铺公司名称 $source_last_week_where[] = ['store_name', '=', $product_data_info['store_name']]; //店铺名称 $source_last_week_where[] = ['product_brand', '=', $product_data_info['product_brand']]; //品牌名称 $source_last_week_where[] = ['product_name', '=', $product_data_info['product_name']]; //商品名称 $source_last_week_where[] = ['product_specs', '=', $product_data_info['product_specs']]; //规格 $source_last_week_where[] = ['scrape_date', '=', $up_scrape_date]; //上个周期采集日期 $source_last_week_log = $this->where($source_last_week_where)->count(); if ($source_last_week_log > 0) { $product_data_info['continuous_listing_count'] = $product_data_info['continuous_listing_count'] + 1; //连续挂网次数+1 } //查询当前商品上次连续挂网次数 $source_last_time_where[] = ['company_id', '=', $product_data_info['company_id']]; //品牌方公司ID $source_last_time_where[] = ['platform', '=', $product_data_info['platform']]; //挂网平台ID $source_last_time_where[] = ['company_name', '=', $product_data_info['company_name']]; //店铺公司名称 $source_last_time_where[] = ['store_name', '=', $product_data_info['store_name']]; //店铺名称 $source_last_time_where[] = ['product_brand', '=', $product_data_info['product_brand']]; //品牌名称 $source_last_time_where[] = ['product_name', '=', $product_data_info['product_name']]; //商品名称 $source_last_time_where[] = ['product_specs', '=', $product_data_info['product_specs']]; //规格 $source_last_time_log = $this->where($source_last_time_where)->orderbyDesc('scrape_date')->first(); if (!empty($source_last_time_log)) { $product_data_info['online_posting_count'] = $source_last_time_log->online_posting_count + 1; //累计挂网次数+1 } } else if ($sampling_start_time != '' && $sampling_end_time == '' && $current_time >= $sampling_start_time) { //如果当前时间在采集开始时间结束时间未设置,则进行连续挂网和累计挂网统计 //查询当前商品上次采集记录 $up_scrape_date_time = $current_time - $sampling_cycle * 24 * 3600; $up_scrape_date = date('Y-m-d', $up_scrape_date_time); $source_last_week_where[] = ['company_id', '=', $product_data_info['company_id']]; //品牌方公司ID $source_last_week_where[] = ['platform', '=', $product_data_info['platform']]; //挂网平台ID $source_last_week_where[] = ['company_name', '=', $product_data_info['company_name']]; //店铺公司名称 $source_last_week_where[] = ['store_name', '=', $product_data_info['store_name']]; //店铺名称 $source_last_week_where[] = ['product_brand', '=', $product_data_info['product_brand']]; //品牌名称 $source_last_week_where[] = ['product_name', '=', $product_data_info['product_name']]; //商品名称 $source_last_week_where[] = ['product_specs', '=', $product_data_info['product_specs']]; //规格 $source_last_week_where[] = ['scrape_date', '=', $up_scrape_date]; //上个周期采集日期 $source_last_week_log = $this->where($source_last_week_where)->count(); if ($source_last_week_log > 0) { $product_data_info['continuous_listing_count'] = $product_data_info['continuous_listing_count'] + 1; //连续挂网次数+1 } //查询当前商品上次连续挂网次数 $source_last_time_where[] = ['company_id', '=', $product_data_info['company_id']]; //品牌方公司ID $source_last_time_where[] = ['platform', '=', $product_data_info['platform']]; //挂网平台ID $source_last_time_where[] = ['company_name', '=', $product_data_info['company_name']]; //店铺公司名称 $source_last_time_where[] = ['store_name', '=', $product_data_info['store_name']]; //店铺名称 $source_last_time_where[] = ['product_brand', '=', $product_data_info['product_brand']]; //品牌名称 $source_last_time_where[] = ['product_name', '=', $product_data_info['product_name']]; //商品名称 $source_last_time_where[] = ['product_specs', '=', $product_data_info['product_specs']]; //规格 $source_last_time_log = $this->where($source_last_time_where)->orderbyDesc('scrape_date')->first(); if (!empty($source_last_time_log)) { $product_data_info['online_posting_count'] = $source_last_time_log->online_posting_count + 1; //累计挂网次数+1 } } return $product_data_info; } /** * 处理通知消息 * @author 唐远望 * @version 1.0 * @date 2026-03-21 * @param $data * @return bool */ public function addNotices($low_price_data, $data_logid) { //添加通知 $NoticesModel = new NoticesModel(); $EmployeeModel = new EmployeeModel(); $notices_data = []; if ($low_price_data['first_responsible_person'] != '' && $low_price_data['responsible_person'] != '') { //合并数据并去重 $first_responsible_persons = array_unique(explode(',', $low_price_data['first_responsible_person'])); $responsible_persons = array_unique(explode(',', $low_price_data['responsible_person'])); $all_persons = array_merge($first_responsible_persons, $responsible_persons); //查询已已经开启通知设置的用户 $employee_ids = $EmployeeModel->whereIn('id', $all_persons)->where('open_notice', 0)->pluck('id')->toArray(); if (count($employee_ids) == 0) return true; foreach ($employee_ids as $key => $employee_id) { if ($employee_id == '' || is_null($employee_id)) continue; $notices_data[] = [ 'company_id' => $low_price_data['company_id'], 'custom_uid' => $employee_id, 'title' => '您有一条新的禁止商品待处理,请及时查看。', 'content_type' => '2', //内容类型1=低价挂网2=禁止挂网3=违规店铺 'data_logid' => $data_logid, 'insert_time' => time() ]; } $NoticesModel->insert($notices_data); } else if ($low_price_data['first_responsible_person'] != '') { $first_responsible_persons = array_unique(explode(',', $low_price_data['first_responsible_person'])); //查询已已经开启通知设置的用户 $employee_ids = $EmployeeModel->whereIn('id', $first_responsible_persons)->where('open_notice', 0)->pluck('id')->toArray(); if (count($employee_ids) == 0) return true; foreach ($employee_ids as $key => $employee_id) { if ($employee_id == '' || is_null($employee_id)) continue; $notices_data[] = [ 'company_id' => $low_price_data['company_id'], 'custom_uid' => $employee_id, 'title' => '您有一条新的禁止商品待处理,请及时查看。', 'content_type' => '2', //内容类型1=低价挂网2=禁止挂网3=违规店铺 'data_logid' => $data_logid, 'insert_time' => time() ]; } $NoticesModel->insert($notices_data); } else if ($low_price_data['responsible_person'] != '') { $responsible_persons = array_unique(explode(',', $low_price_data['responsible_person'])); //查询已已经开启通知设置的用户 $employee_ids = $EmployeeModel->whereIn('id', $responsible_persons)->where('open_notice', 0)->pluck('id')->toArray(); if (count($employee_ids) == 0) return true; foreach ($employee_ids as $key => $employee_id) { if ($employee_id == '' || is_null($employee_id)) continue; $notices_data[] = [ 'company_id' => $low_price_data['company_id'], 'custom_uid' => $employee_id, 'title' => '您有一条新的禁止商品待处理,请及时查看。', 'content_type' => '2', //内容类型1=低价挂网2=禁止挂网3=违规店铺 'data_logid' => $data_logid, 'insert_time' => time() ]; } $NoticesModel->insert($notices_data); } return true; } /** * 编辑内容 * @author 唐远望 * @version 1.0 * @date 2025-12-08 * @param $data * @return bool */ public function editViolationProduct_content($where, $data) { $ViolationProduct = $this->where($where)->first(); if (!$ViolationProduct) { return false; } $ViolationProduct->company_id = $data['company_id']; $ViolationProduct->first_responsible_person = $data['first_responsible_person']; $ViolationProduct->responsible_person = $data['responsible_person']; $ViolationProduct->platform = $data['platform']; $ViolationProduct->company_name = $data['company_name']; $ViolationProduct->product_name = $data['product_name']; $ViolationProduct->product_specs = $data['product_specs']; $ViolationProduct->online_posting_count = $data['online_posting_count']; $ViolationProduct->link_url = $data['link_url']; $ViolationProduct->store_name = $data['store_name']; $ViolationProduct->source_responsible_person = $data['source_responsible_person']; $ViolationProduct->update_time = time(); $ViolationProduct->save(); return true; } /** * 更新数据 * @author 唐远望 * @version 1.0 * @date 2025-12-08 * @param $data * @return bool */ public function updateViolationProduct($where, $data) { DB::beginTransaction(); try { $this->editViolationProduct_content($where, $data); DB::commit(); return true; // 成功处理... } catch (\Exception $e) { DB::rollBack(); // 错误处理... return false; } } /** * 修改状态 * @author 唐远望 * @version 1.0 * @date 2025-12-08 * @param $id * @param $status * @return bool */ public function changeStatus($where, $status) { $ViolationProduct = $this->where($where)->first(); if (!$ViolationProduct) { return false; } $ViolationProduct->status = $status; $ViolationProduct->update_time = time(); $ViolationProduct->save(); return true; } /** * 修改处理状态 * @author 唐远望 * @version 1.0 * @date 2025-12-08 * @param $id * @param $processing_status * @return bool */ public function changeProcessingStatus($where, $processing_status) { $ViolationProduct = $this->where($where)->first(); if (!$ViolationProduct) { return false; } $ViolationProduct->processing_status = $processing_status; $ViolationProduct->update_time = time(); $ViolationProduct->save(); return true; } /** * 删除数据 * @author 唐远望 * @version 1.0 * @date 2025-12-08 * @param $id * @return bool */ public function deleteViolationProduct($where) { $ViolationProduct = $this->where($where)->first(); if (!$ViolationProduct) { return false; } $ViolationProduct->delete(); return true; } }