ViolationProduct.php 18 KB

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