ViolationStore.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  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\ViolationStoreMember as ViolationStoreMemberModel;
  7. use App\Facades\Servers\Logs\Log;
  8. use App\Models\Manager\Process\Notices as NoticesModel;
  9. /**
  10. * 违规处理-违规店铺模型
  11. * @author: 唐远望
  12. * @version: 1.0
  13. * @date: 2025-12-08
  14. */
  15. class ViolationStore extends Model
  16. {
  17. use HasFactory;
  18. // 与模型关联的表名
  19. protected $table = 'process_violation_store';
  20. // 是否主动维护时间戳
  21. public $timestamps = false;
  22. // 定义时间戳字段名
  23. // const CREATED_AT = 'insert_time';
  24. // const UPDATED_AT = 'update_time';
  25. /**
  26. * 添加
  27. * @author 唐远望
  28. * @version 1.0
  29. * @date 2025-12-08
  30. */
  31. public function addViolationStore_content($data)
  32. {
  33. $insert_data = [
  34. 'source_id' => $data['source_id'],
  35. 'first_responsible_person' => $data['first_responsible_person'] ? ',' . $data['first_responsible_person'] . ',' : '',
  36. 'responsible_person' => $data['responsible_person'] ? ',' . $data['responsible_person'] . ',' : '',
  37. 'platform' => $data['platform'],
  38. 'company_name' => $data['company_name'],
  39. 'social_credit_code' => $data['social_credit_code'],
  40. 'province_id' => $data['province_id'],
  41. 'province_name' => $data['province_name'],
  42. 'city_id' => $data['city_id'],
  43. 'city_name' => $data['city_name'],
  44. 'area_info' => $data['area_info'],
  45. 'link_url' => $data['link_url'],
  46. 'store_name' => $data['store_name'],
  47. 'source_responsible_person' => $data['source_responsible_person'] ? ',' . $data['source_responsible_person'] . ',' : '',
  48. 'company_category_name' => $data['company_category_name'] ? $data['company_category_name'] : '',
  49. 'processing_status' => '1',
  50. 'insert_time' => time(),
  51. 'scrape_date' => isset($data['scrape_date']) ? $data['scrape_date'] : '',
  52. ];
  53. $ViolationStore_id = $this->insertGetId($insert_data);
  54. return $ViolationStore_id;
  55. }
  56. /**
  57. * 写入数据
  58. * @author 唐远望
  59. * @version 1.0
  60. * @date 2025-12-08
  61. * @param $data
  62. * @return bool
  63. */
  64. public function addViolationStore($data)
  65. {
  66. $source_where[] = ['company_id', '=', $data['company_id']];
  67. $source_where[] = ['store_name', '=', $data['store_name']];
  68. $source_where[] = ['social_credit_code', '=', $data['social_credit_code']];
  69. $source_id_log = $this->where($source_where)->count();
  70. if ($source_id_log > 0) {
  71. return true;
  72. }
  73. DB::beginTransaction();
  74. try {
  75. $ViolationStoreMemberModel = new ViolationStoreMemberModel();
  76. $insert_data = [
  77. 'company_id' => $data['company_id'],
  78. 'source_id' => $data['source_id'],
  79. 'first_responsible_person' => $data['first_responsible_person'] ? ',' . $data['first_responsible_person'] . ',' : '',
  80. 'responsible_person' => $data['responsible_person'] ? ',' . $data['responsible_person'] . ',' : '',
  81. 'platform' => $data['platform'],
  82. 'company_name' => $data['company_name'],
  83. 'social_credit_code' => $data['social_credit_code'],
  84. 'province_id' => $data['province_id'],
  85. 'province_name' => $data['province_name'],
  86. 'city_id' => $data['city_id'],
  87. 'city_name' => $data['city_name'],
  88. 'area_info' => $data['area_info'],
  89. 'link_url' => $data['link_url'],
  90. 'store_name' => $data['store_name'],
  91. 'source_responsible_person' => $data['source_responsible_person'] ? ',' . $data['source_responsible_person'] . ',' : '',
  92. 'company_category_name' => $data['company_category_name'] ? $data['company_category_name'] : '',
  93. 'processing_status' => '1',
  94. 'insert_time' => time(),
  95. 'scrape_date' => isset($data['scrape_date']) ? $data['scrape_date'] : '',
  96. ];
  97. $ViolationStore_id = $this->insertGetId($insert_data);
  98. $first_responsible_persons = $data['first_responsible_person'] != '' ? explode(',', $data['first_responsible_person']) : [];
  99. $first_responsible_person_data = [];
  100. if (count($first_responsible_persons) > 0) {
  101. foreach ($first_responsible_persons as $key => $employee_id) {
  102. $first_responsible_person_data[] = [
  103. 'violation_store_logid' => $ViolationStore_id,
  104. 'employee_id' => $employee_id,
  105. 'duty_type' => 1, //责任类型1=第一责任人,2=责任人,3=溯源责任人
  106. ];
  107. }
  108. }
  109. $ViolationStoreMemberModel->insert($first_responsible_person_data);
  110. $responsible_persons = $data['responsible_person'] != '' ? explode(',', $data['responsible_person']) : [];
  111. $responsible_person_data = [];
  112. if (count($responsible_persons) > 0) {
  113. foreach ($responsible_persons as $key => $employee_id) {
  114. $responsible_person_data[] = [
  115. 'violation_store_logid' => $ViolationStore_id,
  116. 'employee_id' => $employee_id,
  117. 'duty_type' => 2, //责任类型1=第一责任人,2=责任人,3=溯源责任人
  118. ];
  119. }
  120. }
  121. $ViolationStoreMemberModel->insert($responsible_person_data);
  122. $source_responsible_persons = $data['source_responsible_person'] != '' ? explode(',', $data['source_responsible_person']) : [];
  123. $source_responsible_person_data = [];
  124. if (count($source_responsible_persons) > 0) {
  125. foreach ($source_responsible_persons as $key => $employee_id) {
  126. $source_responsible_person_data[] = [
  127. 'violation_store_logid' => $ViolationStore_id,
  128. 'employee_id' => $employee_id,
  129. 'duty_type' => 3, //责任类型1=第一责任人,2=责任人,3=溯源责任人
  130. ];
  131. }
  132. }
  133. $ViolationStoreMemberModel->insert($source_responsible_person_data);
  134. //添加通知
  135. $this->addNotices($insert_data, $ViolationStore_id);
  136. DB::commit();
  137. return true;
  138. // 成功处理...
  139. } catch (\Exception $e) {
  140. DB::rollBack();
  141. Log::info('job_error', '数据清洗-新增违规店铺处理记录失败', ['data' => $data, 'error' => $e->getMessage()]);
  142. // 错误处理...
  143. return false;
  144. }
  145. }
  146. /**
  147. * 处理通知消息
  148. * @author 唐远望
  149. * @version 1.0
  150. * @date 2026-03-21
  151. * @param $data
  152. * @return bool
  153. */
  154. public function addNotices($low_price_data, $data_logid)
  155. {
  156. //添加通知
  157. $NoticesModel = new NoticesModel();
  158. $notices_data = [];
  159. if ($low_price_data['first_responsible_person'] != '' && $low_price_data['responsible_person'] != '') {
  160. //合并数据并去重
  161. $first_responsible_persons = array_unique(explode(',', $low_price_data['first_responsible_person']));
  162. $responsible_persons = array_unique(explode(',', $low_price_data['responsible_person']));
  163. $all_persons = array_merge($first_responsible_persons, $responsible_persons);
  164. foreach ($all_persons as $key => $employee_id) {
  165. if ($employee_id == '' || is_null($employee_id)) continue;
  166. $notices_data[] = [
  167. 'company_id' => $low_price_data['company_id'],
  168. 'custom_uid' => $employee_id,
  169. 'title' => '您有一条新的低价商品待处理,请及时查看。',
  170. 'content_type' => '1', //内容类型1=低价挂网2=禁止挂网3=违规店铺
  171. 'data_logid' => $data_logid,
  172. 'insert_time' => time()
  173. ];
  174. }
  175. $NoticesModel->insert($notices_data);
  176. } else if ($low_price_data['first_responsible_person'] != '') {
  177. $first_responsible_persons = array_unique(explode(',', $low_price_data['first_responsible_person']));
  178. foreach ($first_responsible_persons as $key => $employee_id) {
  179. if ($employee_id == '' || is_null($employee_id)) continue;
  180. $notices_data[] = [
  181. 'company_id' => $low_price_data['company_id'],
  182. 'custom_uid' => $employee_id,
  183. 'title' => '您有一条新的低价商品待处理,请及时查看。',
  184. 'content_type' => '1', //内容类型1=低价挂网2=禁止挂网3=违规店铺
  185. 'data_logid' => $data_logid,
  186. 'insert_time' => time()
  187. ];
  188. }
  189. $NoticesModel->insert($notices_data);
  190. } else if ($low_price_data['responsible_person'] != '') {
  191. $responsible_persons = array_unique(explode(',', $low_price_data['responsible_person']));
  192. foreach ($responsible_persons as $key => $employee_id) {
  193. if ($employee_id == '' || is_null($employee_id)) continue;
  194. $notices_data[] = [
  195. 'company_id' => $low_price_data['company_id'],
  196. 'custom_uid' => $employee_id,
  197. 'title' => '您有一条新的低价商品待处理,请及时查看。',
  198. 'content_type' => '1', //内容类型1=低价挂网2=禁止挂网3=违规店铺
  199. 'data_logid' => $data_logid,
  200. 'insert_time' => time()
  201. ];
  202. }
  203. $NoticesModel->insert($notices_data);
  204. }
  205. return true;
  206. }
  207. /**
  208. * 编辑内容
  209. * @author 唐远望
  210. * @version 1.0
  211. * @date 2025-12-08
  212. * @param $data
  213. * @return bool
  214. */
  215. public function editViolationStore_content($where, $data)
  216. {
  217. $ViolationStore = $this->where($where)->first();
  218. if (!$ViolationStore) {
  219. return false;
  220. }
  221. $ViolationStore->company_id = $data['company_id'];
  222. $ViolationStore->first_responsible_person = $data['first_responsible_person'];
  223. $ViolationStore->responsible_person = $data['responsible_person'];
  224. $ViolationStore->platform = $data['platform'];
  225. $ViolationStore->company_name = $data['company_name'];
  226. $ViolationStore->social_credit_code = $data['social_credit_code'];
  227. $ViolationStore->link_url = $data['link_url'];
  228. $ViolationStore->store_name = $data['store_name'];
  229. $ViolationStore->source_responsible_person = $data['source_responsible_person'];
  230. $ViolationStore->update_time = time();
  231. $ViolationStore->save();
  232. return true;
  233. }
  234. /**
  235. * 更新数据
  236. * @author 唐远望
  237. * @version 1.0
  238. * @date 2025-12-08
  239. * @param $data
  240. * @return bool
  241. */
  242. public function updateViolationStore($where, $data)
  243. {
  244. DB::beginTransaction();
  245. try {
  246. $this->editViolationStore_content($where, $data);
  247. DB::commit();
  248. return true;
  249. // 成功处理...
  250. } catch (\Exception $e) {
  251. DB::rollBack();
  252. // 错误处理...
  253. return false;
  254. }
  255. }
  256. /**
  257. * 修改状态
  258. * @author 唐远望
  259. * @version 1.0
  260. * @date 2025-12-08
  261. * @param $id
  262. * @param $status
  263. * @return bool
  264. */
  265. public function changeStatus($where, $status)
  266. {
  267. $ViolationStore = $this->where($where)->first();
  268. if (!$ViolationStore) {
  269. return false;
  270. }
  271. $ViolationStore->status = $status;
  272. $ViolationStore->update_time = time();
  273. $ViolationStore->save();
  274. return true;
  275. }
  276. /**
  277. * 修改处理状态
  278. * @author 唐远望
  279. * @version 1.0
  280. * @date 2025-12-08
  281. * @param $id
  282. * @param $processing_status
  283. * @return bool
  284. */
  285. public function changeProcessingStatus($where, $processing_status)
  286. {
  287. $ViolationStore = $this->where($where)->first();
  288. if (!$ViolationStore) {
  289. return false;
  290. }
  291. $ViolationStore->processing_status = $processing_status;
  292. $ViolationStore->update_time = time();
  293. $ViolationStore->save();
  294. return true;
  295. }
  296. /**
  297. * 删除数据
  298. * @author 唐远望
  299. * @version 1.0
  300. * @date 2025-12-08
  301. * @param $id
  302. * @return bool
  303. */
  304. public function deleteViolationStore($where)
  305. {
  306. $ViolationStore = $this->where($where)->first();
  307. if (!$ViolationStore) {
  308. return false;
  309. }
  310. $ViolationStore->delete();
  311. return true;
  312. }
  313. }