ViolationStore.php 7.5 KB

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