ViolationStore.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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. $notices_data[] = [
  166. 'company_id' => $low_price_data['company_id'],
  167. 'custom_uid' => $employee_id,
  168. 'title' => '您有一条新的低价商品待处理,请及时查看。',
  169. 'content_type' => '1', //内容类型1=低价挂网2=禁止挂网3=违规店铺
  170. 'data_logid' => $data_logid,
  171. 'insert_time' => time()
  172. ];
  173. }
  174. $NoticesModel->insert($notices_data);
  175. } else if ($low_price_data['first_responsible_person'] != '') {
  176. $first_responsible_persons = array_unique(explode(',', $low_price_data['first_responsible_person']));
  177. foreach ($first_responsible_persons as $key => $employee_id) {
  178. $notices_data[] = [
  179. 'company_id' => $low_price_data['company_id'],
  180. 'custom_uid' => $employee_id,
  181. 'title' => '您有一条新的低价商品待处理,请及时查看。',
  182. 'content_type' => '1', //内容类型1=低价挂网2=禁止挂网3=违规店铺
  183. 'data_logid' => $data_logid,
  184. 'insert_time' => time()
  185. ];
  186. }
  187. $NoticesModel->insert($notices_data);
  188. } else if ($low_price_data['responsible_person'] != '') {
  189. $responsible_persons = array_unique(explode(',', $low_price_data['responsible_person']));
  190. foreach ($responsible_persons as $key => $employee_id) {
  191. $notices_data[] = [
  192. 'company_id' => $low_price_data['company_id'],
  193. 'custom_uid' => $employee_id,
  194. 'title' => '您有一条新的低价商品待处理,请及时查看。',
  195. 'content_type' => '1', //内容类型1=低价挂网2=禁止挂网3=违规店铺
  196. 'data_logid' => $data_logid,
  197. 'insert_time' => time()
  198. ];
  199. }
  200. $NoticesModel->insert($notices_data);
  201. }
  202. return true;
  203. }
  204. /**
  205. * 编辑内容
  206. * @author 唐远望
  207. * @version 1.0
  208. * @date 2025-12-08
  209. * @param $data
  210. * @return bool
  211. */
  212. public function editViolationStore_content($where, $data)
  213. {
  214. $ViolationStore = $this->where($where)->first();
  215. if (!$ViolationStore) {
  216. return false;
  217. }
  218. $ViolationStore->company_id = $data['company_id'];
  219. $ViolationStore->first_responsible_person = $data['first_responsible_person'];
  220. $ViolationStore->responsible_person = $data['responsible_person'];
  221. $ViolationStore->platform = $data['platform'];
  222. $ViolationStore->company_name = $data['company_name'];
  223. $ViolationStore->social_credit_code = $data['social_credit_code'];
  224. $ViolationStore->link_url = $data['link_url'];
  225. $ViolationStore->store_name = $data['store_name'];
  226. $ViolationStore->source_responsible_person = $data['source_responsible_person'];
  227. $ViolationStore->update_time = time();
  228. $ViolationStore->save();
  229. return true;
  230. }
  231. /**
  232. * 更新数据
  233. * @author 唐远望
  234. * @version 1.0
  235. * @date 2025-12-08
  236. * @param $data
  237. * @return bool
  238. */
  239. public function updateViolationStore($where, $data)
  240. {
  241. DB::beginTransaction();
  242. try {
  243. $this->editViolationStore_content($where, $data);
  244. DB::commit();
  245. return true;
  246. // 成功处理...
  247. } catch (\Exception $e) {
  248. DB::rollBack();
  249. // 错误处理...
  250. return false;
  251. }
  252. }
  253. /**
  254. * 修改状态
  255. * @author 唐远望
  256. * @version 1.0
  257. * @date 2025-12-08
  258. * @param $id
  259. * @param $status
  260. * @return bool
  261. */
  262. public function changeStatus($where, $status)
  263. {
  264. $ViolationStore = $this->where($where)->first();
  265. if (!$ViolationStore) {
  266. return false;
  267. }
  268. $ViolationStore->status = $status;
  269. $ViolationStore->update_time = time();
  270. $ViolationStore->save();
  271. return true;
  272. }
  273. /**
  274. * 修改处理状态
  275. * @author 唐远望
  276. * @version 1.0
  277. * @date 2025-12-08
  278. * @param $id
  279. * @param $processing_status
  280. * @return bool
  281. */
  282. public function changeProcessingStatus($where, $processing_status)
  283. {
  284. $ViolationStore = $this->where($where)->first();
  285. if (!$ViolationStore) {
  286. return false;
  287. }
  288. $ViolationStore->processing_status = $processing_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. * @return bool
  300. */
  301. public function deleteViolationStore($where)
  302. {
  303. $ViolationStore = $this->where($where)->first();
  304. if (!$ViolationStore) {
  305. return false;
  306. }
  307. $ViolationStore->delete();
  308. return true;
  309. }
  310. }