ViolationStore.php 15 KB

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