ViolationStore.php 15 KB

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