ViolationStore.php 14 KB

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