ViolationProduct.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  1. <?php
  2. namespace App\Models\Manager\Process;
  3. use Illuminate\Database\Eloquent\Factories\HasFactory;
  4. use Illuminate\Database\Eloquent\Model;
  5. use Illuminate\Support\Facades\DB;
  6. use App\Models\Manager\Process\ViolationProductMember as ViolationProductMemberModel;
  7. use App\Facades\Servers\Logs\Log;
  8. use App\Models\Manager\Process\Notices as NoticesModel;
  9. use App\Models\Manager\Personnel\Employee as EmployeeModel;
  10. /**
  11. * 违规处理-违规商品模型
  12. * @author: 唐远望
  13. * @version: 1.0
  14. * @date: 2025-12-08
  15. */
  16. class ViolationProduct extends Model
  17. {
  18. use HasFactory;
  19. // 与模型关联的表名
  20. protected $table = 'process_violation_product';
  21. // 是否主动维护时间戳
  22. public $timestamps = false;
  23. // 定义时间戳字段名
  24. // const CREATED_AT = 'insert_time';
  25. // const UPDATED_AT = 'update_time';
  26. /**
  27. * 平台定义
  28. * @author 唐远望
  29. * @version 1.0
  30. * @date 2025-12-31
  31. */
  32. public function platform_data()
  33. {
  34. //平台0=全部,1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药九九,8=药易购,9=药帮忙,10=熊猫药药11=药房网
  35. $platform_data = [
  36. '全部' => '0',
  37. '淘宝' => '1',
  38. '京东' => '2',
  39. '拼多多' => '3',
  40. '美团' => '4',
  41. '药师帮' => '5',
  42. '1药城' => '6',
  43. '药九九' => '7',
  44. '药易购' => '8',
  45. '药帮忙' => '9',
  46. '熊猫药药' => '10',
  47. '药房网' => '11'
  48. ];
  49. return $platform_data;
  50. }
  51. /**
  52. * 添加
  53. * @author 唐远望
  54. * @version 1.0
  55. * @date 2025-12-08
  56. */
  57. public function addViolationProduct_content($data)
  58. {
  59. $insert_data = [
  60. 'company_id' => $data['company_id'],
  61. 'source_id' => $data['source_id'],
  62. 'first_responsible_person' => $data['first_responsible_person'] ? ',' . $data['first_responsible_person'] . ',' : '',
  63. 'responsible_person' => $data['responsible_person'] ? ',' . $data['responsible_person'] . ',' : '',
  64. 'platform' => $data['platform'],
  65. 'company_name' => $data['company_name'],
  66. 'product_brand' => isset($data['product_brand']) ? $data['product_brand'] : '',
  67. 'product_name' => $data['product_name'],
  68. 'product_specs' => $data['product_specs'],
  69. 'online_posting_count' => isset($data['online_posting_count']) && is_numeric($data['online_posting_count']) ? $data['online_posting_count'] : 1,
  70. 'continuous_listing_count' => isset($data['continuous_listing_count']) && is_numeric($data['continuous_listing_count']) ? $data['continuous_listing_count'] : 1,
  71. 'social_credit_code' => $data['social_credit_code'],
  72. 'province_id' => $data['province_id'],
  73. 'province_name' => isset($data['province_name']) ? $data['province_name'] : '',
  74. 'city_id' => $data['city_id'],
  75. 'city_name' => isset($data['city_name']) ? $data['city_name'] : '',
  76. 'area_info' => $data['area_info'],
  77. 'link_url' => $data['link_url'],
  78. 'store_name' => $data['store_name'],
  79. 'anonymous_store_name' => isset($data['anonymous_store_name']) ? $data['anonymous_store_name'] : '',
  80. 'source_responsible_person' => $data['source_responsible_person'] ? ',' . $data['source_responsible_person'] . ',' : '',
  81. 'category_name' => $data['category_name'],
  82. 'company_category_name' => $data['company_category_name'],
  83. 'processing_status' => '1',
  84. 'insert_time' => time(),
  85. 'scrape_date' => isset($data['scrape_date']) ? $data['scrape_date'] : '',
  86. 'collection_time' => isset($data['collection_time']) ? $data['collection_time'] : '',
  87. 'shipment_province_id' => isset($data['shipment_province_id']) ? $data['shipment_province_id'] : '0', // 发货省份id
  88. 'shipment_province_name' => isset($data['shipment_province_name']) ? $data['shipment_province_name'] : '', // 发货省份
  89. 'shipment_city_id' => isset($data['shipment_city_id']) ? $data['shipment_city_id'] : '0', // 发货城市id
  90. 'shipment_city_name' => isset($data['shipment_city_name']) ? $data['shipment_city_name'] : '', // 发货城市
  91. 'merge_city_id' => $data['merge_city_id'],
  92. 'merge_province_id' => $data['merge_province_id'],
  93. 'merge_city_name' => $data['merge_city_name'],
  94. 'merge_province_name' => $data['merge_province_name'],
  95. 'snapshot_url' => isset($data['snapshot_url']) ? $data['snapshot_url'] : '', // 商品快照地址
  96. 'specify_responsible_person' => isset($data['specify_responsible_person']) ? $data['specify_responsible_person'] : '1', // 指派责任人 0=开启 1=关闭
  97. ];
  98. $ViolationProduct_id = $this->insertGetId($insert_data);
  99. return $ViolationProduct_id;
  100. }
  101. /**
  102. * 写入数据
  103. * @author 唐远望
  104. * @version 1.0
  105. * @date 2025-12-08
  106. * @param $data
  107. * @return bool
  108. */
  109. public function addViolationProduct($data, $is_import = false)
  110. {
  111. if ($is_import == false) {
  112. //检查是否重复清洗
  113. $source_data_log = $this->where([['company_id','=', $data['company_id']],['source_id','=', $data['source_id']]])->count();
  114. if(!empty($source_data_log) && $source_data_log > 0) return true;
  115. // 如果是美团跟拼多多链接为动态
  116. if (in_array($data['platform'], ['3', '4'])) {
  117. //去重规则:品牌方公司ID+店铺公司名称+店铺名称+品牌名称+商品名称+规格+盒数(针对采集)
  118. $source_where[] = ['company_id', '=', $data['company_id']]; //品牌方公司ID
  119. $source_where[] = ['platform', '=', $data['platform']]; //平台ID
  120. $source_where[] = ['company_name', '=', $data['company_name']]; //店铺名称
  121. $source_where[] = ['store_name', '=', $data['store_name']]; //店铺名称
  122. $source_where[] = ['product_brand', '=', $data['product_brand']]; //品牌名称
  123. $source_where[] = ['product_name', '=', $data['product_name']]; //商品名称
  124. $source_where[] = ['product_specs', '=', $data['product_specs']]; //规格
  125. $source_where[] = ['scrape_date', '=', $data['scrape_date']]; //采集日期
  126. } else {
  127. $source_where[] = ['link_url', '=', $data['link_url']]; //链接地址
  128. $source_where[] = ['scrape_date', '=', $data['scrape_date']]; //链接地址
  129. }
  130. $source_id_log = $this->where($source_where)->count();
  131. if ($source_id_log > 0) {
  132. return true;
  133. }
  134. }
  135. DB::beginTransaction();
  136. try {
  137. //执行挂网数据统计
  138. $data = $this->handleCountData($data);
  139. $insert_data = [
  140. 'company_id' => $data['company_id'],
  141. 'source_id' => $data['source_id'],
  142. 'first_responsible_person' => $data['first_responsible_person'] ? ',' . $data['first_responsible_person'] . ',' : '',
  143. 'responsible_person' => $data['responsible_person'] ? ',' . $data['responsible_person'] . ',' : '',
  144. 'platform' => $data['platform'],
  145. 'company_name' => $data['company_name'],
  146. 'product_brand' => isset($data['product_brand']) ? $data['product_brand'] : '',
  147. 'product_name' => $data['product_name'],
  148. 'product_specs' => $data['product_specs'],
  149. 'online_posting_count' => isset($data['online_posting_count']) && is_numeric($data['online_posting_count']) ? $data['online_posting_count'] : 1,
  150. 'continuous_listing_count' => isset($data['continuous_listing_count']) && is_numeric($data['continuous_listing_count']) ? $data['continuous_listing_count'] : 1,
  151. 'social_credit_code' => $data['social_credit_code'],
  152. 'province_id' => $data['province_id'],
  153. 'province_name' => isset($data['province_name']) ? $data['province_name'] : '',
  154. 'city_id' => $data['city_id'],
  155. 'city_name' => isset($data['city_name']) ? $data['city_name'] : '',
  156. 'area_info' => $data['area_info'],
  157. 'link_url' => $data['link_url'],
  158. 'store_name' => $data['store_name'],
  159. 'anonymous_store_name' => isset($data['anonymous_store_name']) ? $data['anonymous_store_name'] : '',
  160. 'source_responsible_person' => $data['source_responsible_person'] ? ',' . $data['source_responsible_person'] . ',' : '',
  161. 'category_name' => $data['category_name'],
  162. 'company_category_name' => $data['company_category_name'],
  163. 'processing_status' => '1',
  164. 'insert_time' => time(),
  165. 'scrape_date' => isset($data['scrape_date']) ? $data['scrape_date'] : '',
  166. 'collection_time' => isset($data['collection_time']) ? $data['collection_time'] : '',
  167. 'shipment_province_id' => isset($data['shipment_province_id']) ? $data['shipment_province_id'] : '0', // 发货省份id
  168. 'shipment_province_name' => isset($data['shipment_province_name']) ? $data['shipment_province_name'] : '', // 发货省份
  169. 'shipment_city_id' => isset($data['shipment_city_id']) ? $data['shipment_city_id'] : '0', // 发货城市id
  170. 'shipment_city_name' => isset($data['shipment_city_name']) ? $data['shipment_city_name'] : '', // 发货城市
  171. 'merge_city_id' => $data['merge_city_id'],
  172. 'merge_province_id' => $data['merge_province_id'],
  173. 'merge_city_name' => $data['merge_city_name'],
  174. 'merge_province_name' => $data['merge_province_name'],
  175. 'snapshot_url' => isset($data['snapshot_url']) ? $data['snapshot_url'] : '', // 商品快照地址
  176. 'specify_responsible_person' => isset($data['specify_responsible_person']) ? $data['specify_responsible_person'] : '1', // 指派责任人 0=开启 1=关闭
  177. ];
  178. $ViolationProduct_id = $this->insertGetId($insert_data);
  179. $first_responsible_persons = $data['first_responsible_person'] != '' ? explode(',', $data['first_responsible_person']) : [];
  180. $first_responsible_person_data = [];
  181. if (count($first_responsible_persons) > 0) {
  182. //去除重复的责任人
  183. $first_responsible_persons = array_unique($first_responsible_persons);
  184. //移除数组内的空值
  185. $first_responsible_persons = array_filter($first_responsible_persons);
  186. $EmployeeModel = new EmployeeModel();
  187. $employee_user_list = $EmployeeModel->whereIn('id', $first_responsible_persons)->select(['id', 'name'])->get()->toarray();
  188. $employee_user_list_name = [];
  189. if (!empty($employee_user_list)) {
  190. foreach ($employee_user_list as $key => $employee_user_info) {
  191. $employee_id = $employee_user_info['id'];
  192. $employee_user_list_name[$employee_id] = $employee_user_info['name'];
  193. }
  194. }
  195. foreach ($first_responsible_persons as $key => $employee_id) {
  196. //如果不是数字或者为空,则跳过
  197. if ($employee_id == '' || is_null($employee_id) || !is_numeric($employee_id)) continue;
  198. $first_responsible_person_data[] = [
  199. 'violation_product_logid' => $ViolationProduct_id,
  200. 'employee_id' => $employee_id,
  201. 'employee_name' => isset($employee_user_list_name[$employee_id]) ? $employee_user_list_name[$employee_id] : '',
  202. 'duty_type' => 1, //责任类型1=第一责任人,2=责任人,3=溯源责任人
  203. ];
  204. }
  205. }
  206. $ViolationProductMemberModel = new ViolationProductMemberModel();
  207. $ViolationProductMemberModel->insert($first_responsible_person_data);
  208. $responsible_persons = $data['responsible_person'] != '' ? explode(',', $data['responsible_person']) : [];
  209. $responsible_person_data = [];
  210. if (count($responsible_persons) > 0) {
  211. //去除重复的责任人
  212. $responsible_persons = array_unique($responsible_persons);
  213. //移除数组内的空值
  214. $responsible_persons = array_filter($responsible_persons);
  215. $EmployeeModel = new EmployeeModel();
  216. $employee_user_list = $EmployeeModel->whereIn('id', $responsible_persons)->select(['id', 'name'])->get()->toarray();
  217. $employee_user_list_name = [];
  218. if (!empty($employee_user_list)) {
  219. foreach ($employee_user_list as $key => $employee_user_info) {
  220. $employee_id = $employee_user_info['id'];
  221. $employee_user_list_name[$employee_id] = $employee_user_info['name'];
  222. }
  223. }
  224. foreach ($responsible_persons as $key => $employee_id) {
  225. //如果不是数字或者为空,则跳过
  226. if ($employee_id == '' || is_null($employee_id) || !is_numeric($employee_id)) continue;
  227. $responsible_person_data[] = [
  228. 'violation_product_logid' => $ViolationProduct_id,
  229. 'employee_id' => $employee_id,
  230. 'employee_name' => isset($employee_user_list_name[$employee_id]) ? $employee_user_list_name[$employee_id] : '',
  231. 'duty_type' => 2, //责任类型1=第一责任人,2=责任人,3=溯源责任人
  232. ];
  233. }
  234. }
  235. $ViolationProductMemberModel = new ViolationProductMemberModel();
  236. $ViolationProductMemberModel->insert($responsible_person_data);
  237. $source_responsible_persons = $data['source_responsible_person'] != '' ? explode(',', $data['source_responsible_person']) : [];
  238. $source_responsible_person_data = [];
  239. if (count($source_responsible_persons) > 0) {
  240. //去除重复的责任人
  241. $source_responsible_persons = array_unique($source_responsible_persons);
  242. //移除数组内的空值
  243. $source_responsible_persons = array_filter($source_responsible_persons);
  244. $EmployeeModel = new EmployeeModel();
  245. $employee_user_list = $EmployeeModel->whereIn('id', $source_responsible_persons)->select(['id', 'name'])->get()->toarray();
  246. $employee_user_list_name = [];
  247. if (!empty($employee_user_list)) {
  248. foreach ($employee_user_list as $key => $employee_user_info) {
  249. $employee_id = $employee_user_info['id'];
  250. $employee_user_list_name[$employee_id] = $employee_user_info['name'];
  251. }
  252. }
  253. foreach ($source_responsible_persons as $key => $employee_id) {
  254. //如果不是数字或者为空,则跳过
  255. if ($employee_id == '' || is_null($employee_id) || !is_numeric($employee_id)) continue;
  256. $source_responsible_person_data[] = [
  257. 'violation_product_logid' => $ViolationProduct_id,
  258. 'employee_id' => $employee_id,
  259. 'employee_name' => isset($employee_user_list_name[$employee_id]) ? $employee_user_list_name[$employee_id] : '',
  260. 'duty_type' => 3, //责任类型1=第一责任人,2=责任人,3=溯源责任人
  261. ];
  262. }
  263. }
  264. $ViolationProductMemberModel = new ViolationProductMemberModel();
  265. $ViolationProductMemberModel->insert($source_responsible_person_data);
  266. //添加通知
  267. // $this->addNotices($insert_data, $ViolationProduct_id);
  268. DB::commit();
  269. return true;
  270. // 成功处理...
  271. } catch (\Exception $e) {
  272. DB::rollBack();
  273. // 错误处理...
  274. Log::info('job_error', '数据清洗-新增违规商品处理记录失败', ['data' => $data, 'error' => $e->getMessage()]);
  275. return false;
  276. }
  277. }
  278. function getLastSamplingInfo($currentWeek, $samplingCycle)
  279. {
  280. // 获取所有小于当前星期的配置
  281. $previousWeeks = array_filter($samplingCycle, function ($week) use ($currentWeek) {
  282. return $week < $currentWeek;
  283. });
  284. if (!empty($previousWeeks)) {
  285. // 存在小于当前星期的配置,取最大值
  286. $lastWeek = max($previousWeeks);
  287. $daysToSubtract = $currentWeek - $lastWeek;
  288. } else {
  289. // 不存在(当前是最小的),取最大的配置星期(跨周)
  290. $lastWeek = max($samplingCycle);
  291. $daysToSubtract = $currentWeek + (7 - $lastWeek);
  292. }
  293. return [
  294. 'last_week' => $lastWeek,
  295. 'days_to_subtract' => $daysToSubtract
  296. ];
  297. }
  298. /**
  299. * 处理连续挂网&累计挂网数据统计
  300. * @author 唐远望
  301. * @version 1.0
  302. * @date 2026-05-07
  303. *
  304. */
  305. public function handleCountData($product_data_info)
  306. {
  307. //查询当前商品上次连续挂网次数
  308. if (in_array($product_data_info['platform'], ['3', '4'])) {
  309. $source_last_time_where[] = ['company_id', '=', $product_data_info['company_id']]; //品牌方公司ID
  310. $source_last_time_where[] = ['platform', '=', $product_data_info['platform']]; //挂网平台ID
  311. $source_last_time_where[] = ['company_name', '=', $product_data_info['company_name']]; //店铺公司名称
  312. $source_last_time_where[] = ['store_name', '=', $product_data_info['store_name']]; //店铺名称
  313. $source_last_time_where[] = ['product_brand', '=', $product_data_info['product_brand']]; //品牌名称
  314. $source_last_time_where[] = ['product_name', '=', $product_data_info['product_name']]; //商品名称
  315. $source_last_time_where[] = ['product_specs', '=', $product_data_info['product_specs']]; //规格
  316. $source_last_time_where[] = ['scrape_date', '<', $product_data_info['scrape_date']]; //采集日期
  317. } else {
  318. $source_last_time_where[] = ['company_id', '=', $product_data_info['company_id']]; //品牌方公司ID
  319. $source_last_time_where[] = ['link_url', '=', $product_data_info['link_url']]; //链接地址
  320. $source_last_time_where[] = ['scrape_date', '<', $product_data_info['scrape_date']]; //采集日期
  321. }
  322. $online_posting_count = $this->where($source_last_time_where)->count();
  323. $product_data_info['online_posting_count'] = $online_posting_count + 1; //累计挂网次数+1
  324. //连续挂网默认值为1
  325. $product_data_info['continuous_listing_count'] = 1;
  326. $collect_config_info = isset($product_data_info['collect_config_info']) ? $product_data_info['collect_config_info'] : ''; //采集配置信息
  327. if (trim($collect_config_info) == '') return $product_data_info;
  328. $collect_config_info = json_decode($collect_config_info, true);
  329. //采集周期
  330. $sampling_cycle = isset($collect_config_info['sampling_cycle']) ? explode(',', $collect_config_info['sampling_cycle']) : '';
  331. //采集开始时间
  332. $sampling_start_time = isset($collect_config_info['sampling_start_time']) ? $collect_config_info['sampling_start_time'] : '';
  333. //采集结束时间
  334. $sampling_end_time = isset($collect_config_info['sampling_end_time']) ? $collect_config_info['sampling_end_time'] : '';
  335. if (!is_array($sampling_cycle)) return $product_data_info;
  336. $current_time = $product_data_info['collection_time'];
  337. //如果当前时间在采集开始时间结束时间范围内,则进行连续挂网和累计挂网统计
  338. if ($sampling_start_time != '' && $sampling_end_time != '' && $current_time >= $sampling_start_time && $current_time <= $sampling_end_time) {
  339. // 获取采集时间是星期几
  340. $now_week = date('w', $current_time);
  341. if ($now_week == 0) {
  342. $now_week = 7;
  343. }
  344. if (!in_array($now_week, $sampling_cycle)) {
  345. return $product_data_info;
  346. }
  347. //排序$sampling_cycle从小到大
  348. sort($sampling_cycle);
  349. // 使用
  350. $result = $this->getLastSamplingInfo($now_week, $sampling_cycle);
  351. $days_to_subtract = isset($result['days_to_subtract']) ? $result['days_to_subtract'] : 0;
  352. // echo "往前推 {$result['days_to_subtract']} 天";
  353. //查询当前商品是否在上一个周期采集中过
  354. $up_scrape_date_time = $current_time - $days_to_subtract * 24 * 3600; //查询上周这个时间点
  355. $up_scrape_date = date('Y-m-d', $up_scrape_date_time);
  356. if (in_array($product_data_info['platform'], ['3', '4'])) {
  357. $source_last_week_where[] = ['company_id', '=', $product_data_info['company_id']]; //品牌方公司ID
  358. $source_last_week_where[] = ['platform', '=', $product_data_info['platform']]; //挂网平台ID
  359. $source_last_week_where[] = ['company_name', '=', $product_data_info['company_name']]; //店铺公司名称
  360. $source_last_week_where[] = ['store_name', '=', $product_data_info['store_name']]; //店铺名称
  361. $source_last_week_where[] = ['product_brand', '=', $product_data_info['product_brand']]; //品牌名称
  362. $source_last_week_where[] = ['product_name', '=', $product_data_info['product_name']]; //商品名称
  363. $source_last_week_where[] = ['product_specs', '=', $product_data_info['product_specs']]; //规格
  364. $source_last_week_where[] = ['scrape_date', '=', $up_scrape_date]; //上个周期采集日期
  365. } else {
  366. $source_last_week_where[] = ['link_url', '=', $product_data_info['link_url']]; //链接地址
  367. $source_last_week_where[] = ['scrape_date', '=', $up_scrape_date]; //上个周期采集日期
  368. }
  369. $source_last_week_log = $this->where($source_last_week_where)->count();
  370. if ($source_last_week_log > 0) {
  371. $product_data_info['continuous_listing_count'] = $product_data_info['continuous_listing_count'] + 1; //连续挂网次数+1
  372. }
  373. } else if ($sampling_start_time != '' && $sampling_end_time == '0' && $current_time >= $sampling_start_time) {
  374. //如果当前时间在采集开始时间结束时间未设置,则进行连续挂网和累计挂网统计
  375. // 获取采集时间是星期几
  376. $collection_time = strtotime($product_data_info['collection_time']);
  377. $now_week = date('w', $collection_time);
  378. if ($now_week == 0) {
  379. $now_week = 7;
  380. }
  381. if (!in_array($now_week, $sampling_cycle)) {
  382. return $product_data_info;
  383. }
  384. //排序$sampling_cycle从小到大
  385. sort($sampling_cycle);
  386. // 使用
  387. $result = $this->getLastSamplingInfo($now_week, $sampling_cycle);
  388. $days_to_subtract = isset($result['days_to_subtract']) ? $result['days_to_subtract'] : 0;
  389. $up_scrape_date_time = $collection_time - $days_to_subtract * 24 * 3600; //查询上周这个时间点
  390. //查询当前商品上次采集记录
  391. $up_scrape_date = date('Y-m-d', $up_scrape_date_time);
  392. if (in_array($product_data_info['platform'], ['3', '4'])) {
  393. $source_last_week_where[] = ['company_id', '=', $product_data_info['company_id']]; //品牌方公司ID
  394. $source_last_week_where[] = ['platform', '=', $product_data_info['platform']]; //挂网平台ID
  395. $source_last_week_where[] = ['company_name', '=', $product_data_info['company_name']]; //店铺公司名称
  396. $source_last_week_where[] = ['store_name', '=', $product_data_info['store_name']]; //店铺名称
  397. $source_last_week_where[] = ['product_brand', '=', $product_data_info['product_brand']]; //品牌名称
  398. $source_last_week_where[] = ['product_name', '=', $product_data_info['product_name']]; //商品名称
  399. $source_last_week_where[] = ['product_specs', '=', $product_data_info['product_specs']]; //规格
  400. $source_last_week_where[] = ['scrape_date', '=', $up_scrape_date]; //上个周期采集日期
  401. }else{
  402. $source_last_week_where[] = ['link_url', '=', $product_data_info['link_url']]; //链接地址
  403. $source_last_week_where[] = ['scrape_date', '=', $up_scrape_date]; //上个周期采集日期
  404. }
  405. $source_last_week_log = $this->where($source_last_week_where)->count();
  406. if ($source_last_week_log > 0) {
  407. $product_data_info['continuous_listing_count'] = $product_data_info['continuous_listing_count'] + 1; //连续挂网次数+1
  408. }
  409. }
  410. return $product_data_info;
  411. }
  412. /**
  413. * 处理通知消息
  414. * @author 唐远望
  415. * @version 1.0
  416. * @date 2026-03-21
  417. * @param $data
  418. * @return bool
  419. */
  420. public function addNotices($low_price_data, $data_logid)
  421. {
  422. //添加通知
  423. $NoticesModel = new NoticesModel();
  424. $EmployeeModel = new EmployeeModel();
  425. $notices_data = [];
  426. if ($low_price_data['first_responsible_person'] != '' && $low_price_data['responsible_person'] != '') {
  427. //合并数据并去重
  428. $first_responsible_persons = array_unique(explode(',', $low_price_data['first_responsible_person']));
  429. $responsible_persons = array_unique(explode(',', $low_price_data['responsible_person']));
  430. $all_persons = array_merge($first_responsible_persons, $responsible_persons);
  431. //查询已已经开启通知设置的用户
  432. $employee_ids = $EmployeeModel->whereIn('id', $all_persons)->where('open_notice', 0)->pluck('id')->toArray();
  433. if (count($employee_ids) == 0) return true;
  434. foreach ($employee_ids as $key => $employee_id) {
  435. if ($employee_id == '' || is_null($employee_id)) continue;
  436. $notices_data[] = [
  437. 'company_id' => $low_price_data['company_id'],
  438. 'custom_uid' => $employee_id,
  439. 'title' => '您有一条新的禁止商品待处理,请及时查看。',
  440. 'content_type' => '2', //内容类型1=低价挂网2=禁止挂网3=违规店铺
  441. 'data_logid' => $data_logid,
  442. 'insert_time' => time()
  443. ];
  444. }
  445. $NoticesModel->insert($notices_data);
  446. } else if ($low_price_data['first_responsible_person'] != '') {
  447. $first_responsible_persons = array_unique(explode(',', $low_price_data['first_responsible_person']));
  448. //查询已已经开启通知设置的用户
  449. $employee_ids = $EmployeeModel->whereIn('id', $first_responsible_persons)->where('open_notice', 0)->pluck('id')->toArray();
  450. if (count($employee_ids) == 0) return true;
  451. foreach ($employee_ids as $key => $employee_id) {
  452. if ($employee_id == '' || is_null($employee_id)) continue;
  453. $notices_data[] = [
  454. 'company_id' => $low_price_data['company_id'],
  455. 'custom_uid' => $employee_id,
  456. 'title' => '您有一条新的禁止商品待处理,请及时查看。',
  457. 'content_type' => '2', //内容类型1=低价挂网2=禁止挂网3=违规店铺
  458. 'data_logid' => $data_logid,
  459. 'insert_time' => time()
  460. ];
  461. }
  462. $NoticesModel->insert($notices_data);
  463. } else if ($low_price_data['responsible_person'] != '') {
  464. $responsible_persons = array_unique(explode(',', $low_price_data['responsible_person']));
  465. //查询已已经开启通知设置的用户
  466. $employee_ids = $EmployeeModel->whereIn('id', $responsible_persons)->where('open_notice', 0)->pluck('id')->toArray();
  467. if (count($employee_ids) == 0) return true;
  468. foreach ($employee_ids as $key => $employee_id) {
  469. if ($employee_id == '' || is_null($employee_id)) continue;
  470. $notices_data[] = [
  471. 'company_id' => $low_price_data['company_id'],
  472. 'custom_uid' => $employee_id,
  473. 'title' => '您有一条新的禁止商品待处理,请及时查看。',
  474. 'content_type' => '2', //内容类型1=低价挂网2=禁止挂网3=违规店铺
  475. 'data_logid' => $data_logid,
  476. 'insert_time' => time()
  477. ];
  478. }
  479. $NoticesModel->insert($notices_data);
  480. }
  481. return true;
  482. }
  483. /**
  484. * 编辑内容
  485. * @author 唐远望
  486. * @version 1.0
  487. * @date 2025-12-08
  488. * @param $data
  489. * @return bool
  490. */
  491. public function editViolationProduct_content($where, $data)
  492. {
  493. $ViolationProduct = $this->where($where)->first();
  494. if (!$ViolationProduct) {
  495. return false;
  496. }
  497. $ViolationProduct->company_id = $data['company_id'];
  498. $ViolationProduct->first_responsible_person = $data['first_responsible_person'];
  499. $ViolationProduct->responsible_person = $data['responsible_person'];
  500. $ViolationProduct->platform = $data['platform'];
  501. $ViolationProduct->company_name = $data['company_name'];
  502. $ViolationProduct->product_name = $data['product_name'];
  503. $ViolationProduct->product_specs = $data['product_specs'];
  504. $ViolationProduct->online_posting_count = $data['online_posting_count'];
  505. $ViolationProduct->link_url = $data['link_url'];
  506. $ViolationProduct->store_name = $data['store_name'];
  507. $ViolationProduct->source_responsible_person = $data['source_responsible_person'];
  508. $ViolationProduct->update_time = time();
  509. $ViolationProduct->save();
  510. return true;
  511. }
  512. /**
  513. * 更新数据
  514. * @author 唐远望
  515. * @version 1.0
  516. * @date 2025-12-08
  517. * @param $data
  518. * @return bool
  519. */
  520. public function updateViolationProduct($where, $data)
  521. {
  522. DB::beginTransaction();
  523. try {
  524. $this->editViolationProduct_content($where, $data);
  525. DB::commit();
  526. return true;
  527. // 成功处理...
  528. } catch (\Exception $e) {
  529. DB::rollBack();
  530. // 错误处理...
  531. return false;
  532. }
  533. }
  534. /**
  535. * 修改状态
  536. * @author 唐远望
  537. * @version 1.0
  538. * @date 2025-12-08
  539. * @param $id
  540. * @param $status
  541. * @return bool
  542. */
  543. public function changeStatus($where, $status)
  544. {
  545. $ViolationProduct = $this->where($where)->first();
  546. if (!$ViolationProduct) {
  547. return false;
  548. }
  549. $ViolationProduct->status = $status;
  550. $ViolationProduct->update_time = time();
  551. $ViolationProduct->save();
  552. return true;
  553. }
  554. /**
  555. * 修改处理状态
  556. * @author 唐远望
  557. * @version 1.0
  558. * @date 2025-12-08
  559. * @param $id
  560. * @param $processing_status
  561. * @return bool
  562. */
  563. public function changeProcessingStatus($where, $processing_status)
  564. {
  565. $ViolationProduct = $this->where($where)->first();
  566. if (!$ViolationProduct) {
  567. return false;
  568. }
  569. $ViolationProduct->processing_status = $processing_status;
  570. $ViolationProduct->update_time = time();
  571. $ViolationProduct->save();
  572. return true;
  573. }
  574. /**
  575. * 删除数据
  576. * @author 唐远望
  577. * @version 1.0
  578. * @date 2025-12-08
  579. * @param $id
  580. * @return bool
  581. */
  582. public function deleteViolationProduct($where)
  583. {
  584. $ViolationProduct = $this->where($where)->first();
  585. if (!$ViolationProduct) {
  586. return false;
  587. }
  588. $ViolationProduct->delete();
  589. return true;
  590. }
  591. }