ViolationStore.php 9.4 KB

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