ViolationProduct.php 18 KB

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