ViolationProduct.php 31 KB

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