ViolationStore.php 8.7 KB

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