ControlGoods.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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 ControlGoods extends Model
  13. {
  14. use HasFactory;
  15. // 与模型关联的表名
  16. protected $table = 'washconfig_control_product';
  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 addControlGoods_content($data)
  29. {
  30. $insert_data = [
  31. 'platform' => $data['platform'],
  32. 'product_name' => $data['product_name'],
  33. 'product_specs' => $data['product_specs'],
  34. 'store_scope' => $data['store_scope'],
  35. 'insert_time' => time(),
  36. ];
  37. $ControlGoods_id = $this->insertGetId($insert_data);
  38. return $ControlGoods_id;
  39. }
  40. /**
  41. * 写入数据
  42. * @author 唐远望
  43. * @version 1.0
  44. * @date 2025-12-03
  45. * @param $data
  46. * @return bool
  47. */
  48. public function addControlGoods($data)
  49. {
  50. DB::beginTransaction();
  51. try {
  52. $this->addControlGoods_content($data);
  53. DB::commit();
  54. return true;
  55. // 成功处理...
  56. } catch (\Exception $e) {
  57. DB::rollBack();
  58. // 错误处理...
  59. return false;
  60. }
  61. }
  62. /**
  63. * 编辑内容
  64. * @author 唐远望
  65. * @version 1.0
  66. * @date 2025-12-03
  67. * @param $data
  68. * @return bool
  69. */
  70. public function editControlGoods_content($where, $data)
  71. {
  72. $ControlGoods = $this->where($where)->first();
  73. if (!$ControlGoods) {
  74. return false;
  75. }
  76. $ControlGoods->platform = $data['platform'];
  77. $ControlGoods->product_name = $data['product_name'];
  78. $ControlGoods->product_specs = $data['product_specs'];
  79. $ControlGoods->store_scope = $data['store_scope'];
  80. $ControlGoods->update_time = time();
  81. $ControlGoods->save();
  82. return true;
  83. }
  84. /**
  85. * 更新数据
  86. * @author 唐远望
  87. * @version 1.0
  88. * @date 2025-12-03
  89. * @param $data
  90. * @return bool
  91. */
  92. public function updateControlGoods($where, $data)
  93. {
  94. DB::beginTransaction();
  95. try {
  96. $this->editControlGoods_content($where, $data);
  97. DB::commit();
  98. return true;
  99. // 成功处理...
  100. } catch (\Exception $e) {
  101. DB::rollBack();
  102. // 错误处理...
  103. return false;
  104. }
  105. }
  106. /**
  107. * 修改状态
  108. * @author 唐远望
  109. * @version 1.0
  110. * @date 2025-12-03
  111. * @param $id
  112. * @param $status
  113. * @return bool
  114. */
  115. public function changeStatus($where, $status)
  116. {
  117. $ControlGoods = $this->where($where)->first();
  118. if (!$ControlGoods) {
  119. return false;
  120. }
  121. $ControlGoods->status = $status;
  122. $ControlGoods->update_time = time();
  123. $ControlGoods->save();
  124. return true;
  125. }
  126. /**
  127. * 删除数据
  128. * @author 唐远望
  129. * @version 1.0
  130. * @date 2025-12-03
  131. * @param $id
  132. * @return bool
  133. */
  134. public function deleteControlGoods($where)
  135. {
  136. $ControlGoods = $this->where($where)->first();
  137. if (!$ControlGoods) {
  138. return false;
  139. }
  140. $ControlGoods->delete();
  141. return true;
  142. }
  143. }