ViolationStore.php 15 KB

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