ViolationStore.php 8.8 KB

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