ViolationProduct.php 31 KB

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