ViolationProduct.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  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. ];
  92. $ViolationProduct_id = $this->insertGetId($insert_data);
  93. return $ViolationProduct_id;
  94. }
  95. /**
  96. * 写入数据
  97. * @author 唐远望
  98. * @version 1.0
  99. * @date 2025-12-08
  100. * @param $data
  101. * @return bool
  102. */
  103. public function addViolationProduct($data, $is_import = false)
  104. {
  105. if ($is_import == false) {
  106. //去重规则:品牌方公司ID+店铺公司名称+店铺名称+品牌名称+商品名称+规格+盒数(针对采集)
  107. $source_where[] = ['company_id', '=', $data['company_id']]; //品牌方公司ID
  108. $source_where[] = ['company_name', '=', $data['company_name']]; //店铺公司名称
  109. $source_where[] = ['store_name', '=', $data['store_name']]; //店铺名称
  110. $source_where[] = ['product_brand', '=', $data['product_brand']]; //品牌名称
  111. $source_where[] = ['product_name', '=', $data['product_name']]; //商品名称
  112. $source_where[] = ['product_specs', '=', $data['product_specs']]; //规格
  113. $source_id_log = $this->where($source_where)->count();
  114. if ($source_id_log > 0) {
  115. return true;
  116. }
  117. }
  118. DB::beginTransaction();
  119. try {
  120. $ViolationProductMemberModel = new ViolationProductMemberModel();
  121. $insert_data = [
  122. 'company_id' => $data['company_id'],
  123. 'source_id' => $data['source_id'],
  124. 'first_responsible_person' => $data['first_responsible_person'] ? ',' . $data['first_responsible_person'] . ',' : '',
  125. 'responsible_person' => $data['responsible_person'] ? ',' . $data['responsible_person'] . ',' : '',
  126. 'platform' => $data['platform'],
  127. 'company_name' => $data['company_name'],
  128. 'product_brand' => isset($data['product_brand']) ? $data['product_brand'] : '',
  129. 'product_name' => $data['product_name'],
  130. 'product_specs' => $data['product_specs'],
  131. 'online_posting_count' => isset($data['online_posting_count']) && is_numeric($data['online_posting_count']) ? $data['online_posting_count'] : 1,
  132. 'continuous_listing_count' => isset($data['continuous_listing_count']) && is_numeric($data['continuous_listing_count']) ? $data['continuous_listing_count'] : 1,
  133. 'social_credit_code' => $data['social_credit_code'],
  134. 'province_id' => $data['province_id'],
  135. 'province_name' => isset($data['province_name']) ? $data['province_name'] : '',
  136. 'city_id' => $data['city_id'],
  137. 'city_name' => isset($data['city_name']) ? $data['city_name'] : '',
  138. 'area_info' => $data['area_info'],
  139. 'link_url' => $data['link_url'],
  140. 'store_name' => $data['store_name'],
  141. 'anonymous_store_name' => isset($data['anonymous_store_name']) ? $data['anonymous_store_name'] : '',
  142. 'source_responsible_person' => $data['source_responsible_person'] ? ',' . $data['source_responsible_person'] . ',' : '',
  143. 'category_name' => $data['category_name'],
  144. 'company_category_name' => $data['company_category_name'],
  145. 'processing_status' => '1',
  146. 'insert_time' => time(),
  147. 'scrape_date' => isset($data['scrape_date']) ? $data['scrape_date'] : '',
  148. 'collection_time' => isset($data['collection_time']) ? $data['collection_time'] : '',
  149. 'shipment_province_id' => isset($data['shipment_province_id']) ? $data['shipment_province_id'] : '0', // 发货省份id
  150. 'shipment_province_name' => isset($data['shipment_province_name']) ? $data['shipment_province_name'] : '', // 发货省份
  151. 'shipment_city_id' => isset($data['shipment_city_id']) ? $data['shipment_city_id'] : '0', // 发货城市id
  152. 'shipment_city_name' => isset($data['shipment_city_name']) ? $data['shipment_city_name'] : '', // 发货城市
  153. ];
  154. $ViolationProduct_id = $this->insertGetId($insert_data);
  155. $first_responsible_persons = $data['first_responsible_person'] != '' ? explode(',', $data['first_responsible_person']) : [];
  156. $first_responsible_person_data = [];
  157. if (count($first_responsible_persons) > 0) {
  158. foreach ($first_responsible_persons as $key => $employee_id) {
  159. //如果不是数字或者为空,则跳过
  160. if ($employee_id == '' || is_null($employee_id) || !is_numeric($employee_id)) continue;
  161. $first_responsible_person_data[] = [
  162. 'violation_product_logid' => $ViolationProduct_id,
  163. 'employee_id' => $employee_id,
  164. 'duty_type' => 1, //责任类型1=第一责任人,2=责任人,3=溯源责任人
  165. ];
  166. }
  167. }
  168. $ViolationProductMemberModel->insert($first_responsible_person_data);
  169. $responsible_persons = $data['responsible_person'] != '' ? explode(',', $data['responsible_person']) : [];
  170. $responsible_person_data = [];
  171. if (count($responsible_persons) > 0) {
  172. foreach ($responsible_persons as $key => $employee_id) {
  173. //如果不是数字或者为空,则跳过
  174. if ($employee_id == '' || is_null($employee_id) || !is_numeric($employee_id)) continue;
  175. $responsible_person_data[] = [
  176. 'violation_product_logid' => $ViolationProduct_id,
  177. 'employee_id' => $employee_id,
  178. 'duty_type' => 2, //责任类型1=第一责任人,2=责任人,3=溯源责任人
  179. ];
  180. }
  181. }
  182. $ViolationProductMemberModel->insert($responsible_person_data);
  183. $source_responsible_persons = $data['source_responsible_person'] != '' ? explode(',', $data['source_responsible_person']) : [];
  184. $source_responsible_person_data = [];
  185. if (count($source_responsible_persons) > 0) {
  186. foreach ($source_responsible_persons as $key => $employee_id) {
  187. //如果不是数字或者为空,则跳过
  188. if ($employee_id == '' || is_null($employee_id) || !is_numeric($employee_id)) continue;
  189. $source_responsible_person_data[] = [
  190. 'violation_product_logid' => $ViolationProduct_id,
  191. 'employee_id' => $employee_id,
  192. 'duty_type' => 3, //责任类型1=第一责任人,2=责任人,3=溯源责任人
  193. ];
  194. }
  195. }
  196. $ViolationProductMemberModel->insert($source_responsible_person_data);
  197. //添加通知
  198. // $this->addNotices($insert_data, $ViolationProduct_id);
  199. DB::commit();
  200. return true;
  201. // 成功处理...
  202. } catch (\Exception $e) {
  203. DB::rollBack();
  204. // 错误处理...
  205. Log::info('job_error', '数据清洗-新增违规商品处理记录失败', ['data' => $data, 'error' => $e->getMessage()]);
  206. return false;
  207. }
  208. }
  209. /**
  210. * 处理通知消息
  211. * @author 唐远望
  212. * @version 1.0
  213. * @date 2026-03-21
  214. * @param $data
  215. * @return bool
  216. */
  217. public function addNotices($low_price_data, $data_logid)
  218. {
  219. //添加通知
  220. $NoticesModel = new NoticesModel();
  221. $EmployeeModel = new EmployeeModel();
  222. $notices_data = [];
  223. if ($low_price_data['first_responsible_person'] != '' && $low_price_data['responsible_person'] != '') {
  224. //合并数据并去重
  225. $first_responsible_persons = array_unique(explode(',', $low_price_data['first_responsible_person']));
  226. $responsible_persons = array_unique(explode(',', $low_price_data['responsible_person']));
  227. $all_persons = array_merge($first_responsible_persons, $responsible_persons);
  228. //查询已已经开启通知设置的用户
  229. $employee_ids = $EmployeeModel->whereIn('id', $all_persons)->where('open_notice', 0)->pluck('id')->toArray();
  230. if (count($employee_ids) == 0) return true;
  231. foreach ($employee_ids as $key => $employee_id) {
  232. if ($employee_id == '' || is_null($employee_id)) continue;
  233. $notices_data[] = [
  234. 'company_id' => $low_price_data['company_id'],
  235. 'custom_uid' => $employee_id,
  236. 'title' => '您有一条新的禁止商品待处理,请及时查看。',
  237. 'content_type' => '2', //内容类型1=低价挂网2=禁止挂网3=违规店铺
  238. 'data_logid' => $data_logid,
  239. 'insert_time' => time()
  240. ];
  241. }
  242. $NoticesModel->insert($notices_data);
  243. } else if ($low_price_data['first_responsible_person'] != '') {
  244. $first_responsible_persons = array_unique(explode(',', $low_price_data['first_responsible_person']));
  245. //查询已已经开启通知设置的用户
  246. $employee_ids = $EmployeeModel->whereIn('id', $first_responsible_persons)->where('open_notice', 0)->pluck('id')->toArray();
  247. if (count($employee_ids) == 0) return true;
  248. foreach ($employee_ids as $key => $employee_id) {
  249. if ($employee_id == '' || is_null($employee_id)) continue;
  250. $notices_data[] = [
  251. 'company_id' => $low_price_data['company_id'],
  252. 'custom_uid' => $employee_id,
  253. 'title' => '您有一条新的禁止商品待处理,请及时查看。',
  254. 'content_type' => '2', //内容类型1=低价挂网2=禁止挂网3=违规店铺
  255. 'data_logid' => $data_logid,
  256. 'insert_time' => time()
  257. ];
  258. }
  259. $NoticesModel->insert($notices_data);
  260. } else if ($low_price_data['responsible_person'] != '') {
  261. $responsible_persons = array_unique(explode(',', $low_price_data['responsible_person']));
  262. //查询已已经开启通知设置的用户
  263. $employee_ids = $EmployeeModel->whereIn('id', $responsible_persons)->where('open_notice', 0)->pluck('id')->toArray();
  264. if (count($employee_ids) == 0) return true;
  265. foreach ($employee_ids as $key => $employee_id) {
  266. if ($employee_id == '' || is_null($employee_id)) continue;
  267. $notices_data[] = [
  268. 'company_id' => $low_price_data['company_id'],
  269. 'custom_uid' => $employee_id,
  270. 'title' => '您有一条新的禁止商品待处理,请及时查看。',
  271. 'content_type' => '2', //内容类型1=低价挂网2=禁止挂网3=违规店铺
  272. 'data_logid' => $data_logid,
  273. 'insert_time' => time()
  274. ];
  275. }
  276. $NoticesModel->insert($notices_data);
  277. }
  278. return true;
  279. }
  280. /**
  281. * 编辑内容
  282. * @author 唐远望
  283. * @version 1.0
  284. * @date 2025-12-08
  285. * @param $data
  286. * @return bool
  287. */
  288. public function editViolationProduct_content($where, $data)
  289. {
  290. $ViolationProduct = $this->where($where)->first();
  291. if (!$ViolationProduct) {
  292. return false;
  293. }
  294. $ViolationProduct->company_id = $data['company_id'];
  295. $ViolationProduct->first_responsible_person = $data['first_responsible_person'];
  296. $ViolationProduct->responsible_person = $data['responsible_person'];
  297. $ViolationProduct->platform = $data['platform'];
  298. $ViolationProduct->company_name = $data['company_name'];
  299. $ViolationProduct->product_name = $data['product_name'];
  300. $ViolationProduct->product_specs = $data['product_specs'];
  301. $ViolationProduct->online_posting_count = $data['online_posting_count'];
  302. $ViolationProduct->link_url = $data['link_url'];
  303. $ViolationProduct->store_name = $data['store_name'];
  304. $ViolationProduct->source_responsible_person = $data['source_responsible_person'];
  305. $ViolationProduct->update_time = time();
  306. $ViolationProduct->save();
  307. return true;
  308. }
  309. /**
  310. * 更新数据
  311. * @author 唐远望
  312. * @version 1.0
  313. * @date 2025-12-08
  314. * @param $data
  315. * @return bool
  316. */
  317. public function updateViolationProduct($where, $data)
  318. {
  319. DB::beginTransaction();
  320. try {
  321. $this->editViolationProduct_content($where, $data);
  322. DB::commit();
  323. return true;
  324. // 成功处理...
  325. } catch (\Exception $e) {
  326. DB::rollBack();
  327. // 错误处理...
  328. return false;
  329. }
  330. }
  331. /**
  332. * 修改状态
  333. * @author 唐远望
  334. * @version 1.0
  335. * @date 2025-12-08
  336. * @param $id
  337. * @param $status
  338. * @return bool
  339. */
  340. public function changeStatus($where, $status)
  341. {
  342. $ViolationProduct = $this->where($where)->first();
  343. if (!$ViolationProduct) {
  344. return false;
  345. }
  346. $ViolationProduct->status = $status;
  347. $ViolationProduct->update_time = time();
  348. $ViolationProduct->save();
  349. return true;
  350. }
  351. /**
  352. * 修改处理状态
  353. * @author 唐远望
  354. * @version 1.0
  355. * @date 2025-12-08
  356. * @param $id
  357. * @param $processing_status
  358. * @return bool
  359. */
  360. public function changeProcessingStatus($where, $processing_status)
  361. {
  362. $ViolationProduct = $this->where($where)->first();
  363. if (!$ViolationProduct) {
  364. return false;
  365. }
  366. $ViolationProduct->processing_status = $processing_status;
  367. $ViolationProduct->update_time = time();
  368. $ViolationProduct->save();
  369. return true;
  370. }
  371. /**
  372. * 删除数据
  373. * @author 唐远望
  374. * @version 1.0
  375. * @date 2025-12-08
  376. * @param $id
  377. * @return bool
  378. */
  379. public function deleteViolationProduct($where)
  380. {
  381. $ViolationProduct = $this->where($where)->first();
  382. if (!$ViolationProduct) {
  383. return false;
  384. }
  385. $ViolationProduct->delete();
  386. return true;
  387. }
  388. }