ViolationStore.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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. /**
  9. * 违规处理-违规店铺模型
  10. * @author: 唐远望
  11. * @version: 1.0
  12. * @date: 2025-12-08
  13. */
  14. class ViolationStore extends Model
  15. {
  16. use HasFactory;
  17. // 与模型关联的表名
  18. protected $table = 'process_violation_store';
  19. // 是否主动维护时间戳
  20. public $timestamps = false;
  21. // 定义时间戳字段名
  22. // const CREATED_AT = 'insert_time';
  23. // const UPDATED_AT = 'update_time';
  24. /**
  25. * 添加
  26. * @author 唐远望
  27. * @version 1.0
  28. * @date 2025-12-08
  29. */
  30. public function addViolationStore_content($data)
  31. {
  32. $insert_data = [
  33. 'source_id' => $data['source_id'],
  34. 'first_responsible_person' => $data['first_responsible_person'] ? ',' . $data['first_responsible_person'] . ',' : '',
  35. 'responsible_person' => $data['responsible_person'] ? ',' . $data['responsible_person'] . ',' : '',
  36. 'platform' => $data['platform'],
  37. 'company_name' => $data['company_name'],
  38. 'social_credit_code' => $data['social_credit_code'],
  39. 'province_id' => $data['province_id'],
  40. 'province_name' => $data['province_name'],
  41. 'city_id' => $data['city_id'],
  42. 'city_name' => $data['city_name'],
  43. 'area_info' => $data['area_info'],
  44. 'link_url' => $data['link_url'],
  45. 'store_name' => $data['store_name'],
  46. 'source_responsible_person' => $data['source_responsible_person'] ? ',' . $data['source_responsible_person'] . ',' : '',
  47. 'company_category_name' => $data['company_category_name'] ? $data['company_category_name'] : '',
  48. 'processing_status' => '1',
  49. 'insert_time' => time(),
  50. 'scrape_date' => isset($data['scrape_date']) ? $data['scrape_date'] : '',
  51. ];
  52. $ViolationStore_id = $this->insertGetId($insert_data);
  53. return $ViolationStore_id;
  54. }
  55. /**
  56. * 写入数据
  57. * @author 唐远望
  58. * @version 1.0
  59. * @date 2025-12-08
  60. * @param $data
  61. * @return bool
  62. */
  63. public function addViolationStore($data)
  64. {
  65. $source_where[] = ['company_id', '=', $data['company_id']];
  66. $source_where[] = ['store_name', '=', $data['store_name']];
  67. $source_where[] = ['social_credit_code', '=', $data['social_credit_code']];
  68. $source_id_log = $this->where($source_where)->count();
  69. if ($source_id_log > 0) {
  70. return true;
  71. }
  72. DB::beginTransaction();
  73. try {
  74. $ViolationStoreMemberModel = new ViolationStoreMemberModel();
  75. $insert_data = [
  76. 'company_id' => $data['company_id'],
  77. 'source_id' => $data['source_id'],
  78. 'first_responsible_person' => $data['first_responsible_person'] ? ',' . $data['first_responsible_person'] . ',' : '',
  79. 'responsible_person' => $data['responsible_person'] ? ',' . $data['responsible_person'] . ',' : '',
  80. 'platform' => $data['platform'],
  81. 'company_name' => $data['company_name'],
  82. 'social_credit_code' => $data['social_credit_code'],
  83. 'province_id' => $data['province_id'],
  84. 'province_name' => $data['province_name'],
  85. 'city_id' => $data['city_id'],
  86. 'city_name' => $data['city_name'],
  87. 'area_info' => $data['area_info'],
  88. 'link_url' => $data['link_url'],
  89. 'store_name' => $data['store_name'],
  90. 'source_responsible_person' => $data['source_responsible_person'] ? ',' . $data['source_responsible_person'] . ',' : '',
  91. 'company_category_name' => $data['company_category_name'] ? $data['company_category_name'] : '',
  92. 'processing_status' => '1',
  93. 'insert_time' => time(),
  94. 'scrape_date' => isset($data['scrape_date']) ? $data['scrape_date'] : '',
  95. ];
  96. $ViolationStore_id = $this->insertGetId($insert_data);
  97. $first_responsible_persons = $data['first_responsible_person'] != '' ? explode(',', $data['first_responsible_person']) : [];
  98. $first_responsible_person_data = [];
  99. if (count($first_responsible_persons) > 0) {
  100. foreach ($first_responsible_persons as $key => $employee_id) {
  101. $first_responsible_person_data[] = [
  102. 'violation_store_logid' => $ViolationStore_id,
  103. 'employee_id' => $employee_id,
  104. 'duty_type' => 1, //责任类型1=第一责任人,2=责任人,3=溯源责任人
  105. ];
  106. }
  107. }
  108. $ViolationStoreMemberModel->insert($first_responsible_person_data);
  109. $responsible_persons = $data['responsible_person'] != '' ? explode(',', $data['responsible_person']) : [];
  110. $responsible_person_data = [];
  111. if (count($responsible_persons) > 0) {
  112. foreach ($responsible_persons as $key => $employee_id) {
  113. $responsible_person_data[] = [
  114. 'violation_store_logid' => $ViolationStore_id,
  115. 'employee_id' => $employee_id,
  116. 'duty_type' => 2, //责任类型1=第一责任人,2=责任人,3=溯源责任人
  117. ];
  118. }
  119. }
  120. $ViolationStoreMemberModel->insert($responsible_person_data);
  121. $source_responsible_persons = $data['source_responsible_person'] != '' ? explode(',', $data['source_responsible_person']) : [];
  122. $source_responsible_person_data = [];
  123. if (count($source_responsible_persons) > 0) {
  124. foreach ($source_responsible_persons as $key => $employee_id) {
  125. $source_responsible_person_data[] = [
  126. 'violation_store_logid' => $ViolationStore_id,
  127. 'employee_id' => $employee_id,
  128. 'duty_type' => 3, //责任类型1=第一责任人,2=责任人,3=溯源责任人
  129. ];
  130. }
  131. }
  132. $ViolationStoreMemberModel->insert($source_responsible_person_data);
  133. DB::commit();
  134. return true;
  135. // 成功处理...
  136. } catch (\Exception $e) {
  137. DB::rollBack();
  138. Log::info('job_error', '数据清洗-新增违规店铺处理记录失败', ['data' => $data, 'error' => $e->getMessage()]);
  139. // 错误处理...
  140. return false;
  141. }
  142. }
  143. /**
  144. * 编辑内容
  145. * @author 唐远望
  146. * @version 1.0
  147. * @date 2025-12-08
  148. * @param $data
  149. * @return bool
  150. */
  151. public function editViolationStore_content($where, $data)
  152. {
  153. $ViolationStore = $this->where($where)->first();
  154. if (!$ViolationStore) {
  155. return false;
  156. }
  157. $ViolationStore->company_id = $data['company_id'];
  158. $ViolationStore->first_responsible_person = $data['first_responsible_person'];
  159. $ViolationStore->responsible_person = $data['responsible_person'];
  160. $ViolationStore->platform = $data['platform'];
  161. $ViolationStore->company_name = $data['company_name'];
  162. $ViolationStore->social_credit_code = $data['social_credit_code'];
  163. $ViolationStore->link_url = $data['link_url'];
  164. $ViolationStore->store_name = $data['store_name'];
  165. $ViolationStore->source_responsible_person = $data['source_responsible_person'];
  166. $ViolationStore->update_time = time();
  167. $ViolationStore->save();
  168. return true;
  169. }
  170. /**
  171. * 更新数据
  172. * @author 唐远望
  173. * @version 1.0
  174. * @date 2025-12-08
  175. * @param $data
  176. * @return bool
  177. */
  178. public function updateViolationStore($where, $data)
  179. {
  180. DB::beginTransaction();
  181. try {
  182. $this->editViolationStore_content($where, $data);
  183. DB::commit();
  184. return true;
  185. // 成功处理...
  186. } catch (\Exception $e) {
  187. DB::rollBack();
  188. // 错误处理...
  189. return false;
  190. }
  191. }
  192. /**
  193. * 修改状态
  194. * @author 唐远望
  195. * @version 1.0
  196. * @date 2025-12-08
  197. * @param $id
  198. * @param $status
  199. * @return bool
  200. */
  201. public function changeStatus($where, $status)
  202. {
  203. $ViolationStore = $this->where($where)->first();
  204. if (!$ViolationStore) {
  205. return false;
  206. }
  207. $ViolationStore->status = $status;
  208. $ViolationStore->update_time = time();
  209. $ViolationStore->save();
  210. return true;
  211. }
  212. /**
  213. * 修改处理状态
  214. * @author 唐远望
  215. * @version 1.0
  216. * @date 2025-12-08
  217. * @param $id
  218. * @param $processing_status
  219. * @return bool
  220. */
  221. public function changeProcessingStatus($where, $processing_status)
  222. {
  223. $ViolationStore = $this->where($where)->first();
  224. if (!$ViolationStore) {
  225. return false;
  226. }
  227. $ViolationStore->processing_status = $processing_status;
  228. $ViolationStore->update_time = time();
  229. $ViolationStore->save();
  230. return true;
  231. }
  232. /**
  233. * 删除数据
  234. * @author 唐远望
  235. * @version 1.0
  236. * @date 2025-12-08
  237. * @param $id
  238. * @return bool
  239. */
  240. public function deleteViolationStore($where)
  241. {
  242. $ViolationStore = $this->where($where)->first();
  243. if (!$ViolationStore) {
  244. return false;
  245. }
  246. $ViolationStore->delete();
  247. return true;
  248. }
  249. }