ViolationStore.php 7.7 KB

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