ViolationStore.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. namespace App\Models\Manager\WashConfig;
  3. use Illuminate\Database\Eloquent\Factories\HasFactory;
  4. use Illuminate\Database\Eloquent\Model;
  5. use Illuminate\Support\Facades\DB;
  6. /**
  7. * 清洗配置-违规店铺
  8. * @author: 唐远望
  9. * @version: 1.0
  10. * @date: 2025-12-03
  11. */
  12. class ViolationStore extends Model
  13. {
  14. use HasFactory;
  15. // 与模型关联的表名
  16. protected $table = 'washconfig_violation_store';
  17. // 是否主动维护时间戳
  18. public $timestamps = false;
  19. // 定义时间戳字段名
  20. // const CREATED_AT = 'insert_time';
  21. // const UPDATED_AT = 'update_time';
  22. /**
  23. * 添加
  24. * @author 唐远望
  25. * @version 1.0
  26. * @date 2025-12-03
  27. */
  28. public function addViolationStore_content($data)
  29. {
  30. $insert_data = [
  31. 'company_name' => $data['company_name'],
  32. 'social_credit_code' => $data['social_credit_code'],
  33. 'store_type' => $data['store_type'],
  34. 'insert_time' => time(),
  35. ];
  36. $ViolationStore_id = $this->insertGetId($insert_data);
  37. return $ViolationStore_id;
  38. }
  39. /**
  40. * 写入数据
  41. * @author 唐远望
  42. * @version 1.0
  43. * @date 2025-12-03
  44. * @param $data
  45. * @return bool
  46. */
  47. public function addViolationStore($data)
  48. {
  49. DB::beginTransaction();
  50. try {
  51. $this->addViolationStore_content($data);
  52. DB::commit();
  53. return true;
  54. // 成功处理...
  55. } catch (\Exception $e) {
  56. DB::rollBack();
  57. // 错误处理...
  58. return false;
  59. }
  60. }
  61. /**
  62. * 编辑内容
  63. * @author 唐远望
  64. * @version 1.0
  65. * @date 2025-12-03
  66. * @param $data
  67. * @return bool
  68. */
  69. public function editViolationStore_content($where, $data)
  70. {
  71. $ViolationStore = $this->where($where)->first();
  72. if (!$ViolationStore) {
  73. return false;
  74. }
  75. $ViolationStore->company_name = $data['company_name'];
  76. $ViolationStore->social_credit_code = $data['social_credit_code'];
  77. $ViolationStore->store_type = $data['store_type'];
  78. $ViolationStore->update_time = time();
  79. $ViolationStore->save();
  80. return true;
  81. }
  82. /**
  83. * 更新数据
  84. * @author 唐远望
  85. * @version 1.0
  86. * @date 2025-12-03
  87. * @param $data
  88. * @return bool
  89. */
  90. public function updateViolationStore($where, $data)
  91. {
  92. DB::beginTransaction();
  93. try {
  94. $this->editViolationStore_content($where, $data);
  95. DB::commit();
  96. return true;
  97. // 成功处理...
  98. } catch (\Exception $e) {
  99. DB::rollBack();
  100. // 错误处理...
  101. return false;
  102. }
  103. }
  104. /**
  105. * 修改状态
  106. * @author 唐远望
  107. * @version 1.0
  108. * @date 2025-12-03
  109. * @param $id
  110. * @param $status
  111. * @return bool
  112. */
  113. public function changeStatus($where, $status)
  114. {
  115. $ViolationStore = $this->where($where)->first();
  116. if (!$ViolationStore) {
  117. return false;
  118. }
  119. $ViolationStore->status = $status;
  120. $ViolationStore->update_time = time();
  121. $ViolationStore->save();
  122. return true;
  123. }
  124. /**
  125. * 删除数据
  126. * @author 唐远望
  127. * @version 1.0
  128. * @date 2025-12-03
  129. * @param $id
  130. * @return bool
  131. */
  132. public function deleteViolationStore($where)
  133. {
  134. $ViolationStore = $this->where($where)->first();
  135. if (!$ViolationStore) {
  136. return false;
  137. }
  138. $ViolationStore->delete();
  139. return true;
  140. }
  141. }