ViolationStore.php 9.6 KB

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