ViolationProduct.php 32 KB

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