LowPriceGoods.php 3.7 KB

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