ControlGoods.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <?php
  2. namespace App\Models\Api\Process;
  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-09
  11. */
  12. class ControlGoods extends Model
  13. {
  14. use HasFactory;
  15. // 与模型关联的表名
  16. protected $table = 'process_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-09
  27. */
  28. public function addControlGoods_content($data)
  29. {
  30. $insert_data = [
  31. 'first_responsible_person' => $data['first_responsible_person'],
  32. 'responsible_person' => $data['responsible_person'],
  33. 'platform' => $data['platform'],
  34. 'company_name' => $data['company_name'],
  35. 'product_name' => $data['product_name'],
  36. 'product_specs' => $data['product_specs'],
  37. 'suggested_price' => $data['suggested_price'],
  38. 'online_posting_price' => $data['online_posting_price'],
  39. 'online_posting_cunt' => $data['online_posting_cunt'],
  40. 'link_url' => $data['link_url'],
  41. 'store_name' => $data['store_name'],
  42. 'source_responsible_person' => $data['source_responsible_person'],
  43. 'processing_status' => '1',
  44. 'insert_time' => time(),
  45. ];
  46. $ControlGoods_id = $this->insertGetId($insert_data);
  47. return $ControlGoods_id;
  48. }
  49. /**
  50. * 写入数据
  51. * @author 唐远望
  52. * @version 1.0
  53. * @date 2025-12-09
  54. * @param $data
  55. * @return bool
  56. */
  57. public function addControlGoods($data)
  58. {
  59. DB::beginTransaction();
  60. try {
  61. $this->addControlGoods_content($data);
  62. DB::commit();
  63. return true;
  64. // 成功处理...
  65. } catch (\Exception $e) {
  66. DB::rollBack();
  67. // 错误处理...
  68. return false;
  69. }
  70. }
  71. /**
  72. * 编辑内容
  73. * @author 唐远望
  74. * @version 1.0
  75. * @date 2025-12-09
  76. * @param $data
  77. * @return bool
  78. */
  79. public function editControlGoods_content($where, $data)
  80. {
  81. $ControlGoods = $this->where($where)->first();
  82. if (!$ControlGoods) {
  83. return false;
  84. }
  85. $ControlGoods->first_responsible_person = $data['first_responsible_person'];
  86. $ControlGoods->responsible_person = $data['responsible_person'];
  87. $ControlGoods->platform = $data['platform'];
  88. $ControlGoods->company_name = $data['company_name'];
  89. $ControlGoods->product_name = $data['product_name'];
  90. $ControlGoods->product_specs = $data['product_specs'];
  91. $ControlGoods->suggested_price = $data['suggested_price'];
  92. $ControlGoods->online_posting_price = $data['online_posting_price'];
  93. $ControlGoods->online_posting_cunt = $data['online_posting_cunt'];
  94. $ControlGoods->link_url = $data['link_url'];
  95. $ControlGoods->store_name = $data['store_name'];
  96. $ControlGoods->source_responsible_person = $data['source_responsible_person'];
  97. $ControlGoods->update_time = time();
  98. $ControlGoods->save();
  99. return true;
  100. }
  101. /**
  102. * 更新数据
  103. * @author 唐远望
  104. * @version 1.0
  105. * @date 2025-12-09
  106. * @param $data
  107. * @return bool
  108. */
  109. public function updateControlGoods($where, $data)
  110. {
  111. DB::beginTransaction();
  112. try {
  113. $this->editControlGoods_content($where, $data);
  114. DB::commit();
  115. return true;
  116. // 成功处理...
  117. } catch (\Exception $e) {
  118. DB::rollBack();
  119. // 错误处理...
  120. return false;
  121. }
  122. }
  123. /**
  124. * 修改状态
  125. * @author 唐远望
  126. * @version 1.0
  127. * @date 2025-12-09
  128. * @param $id
  129. * @param $status
  130. * @return bool
  131. */
  132. public function changeStatus($where, $status)
  133. {
  134. $ControlGoods = $this->where($where)->first();
  135. if (!$ControlGoods) {
  136. return false;
  137. }
  138. $ControlGoods->status = $status;
  139. $ControlGoods->update_time = time();
  140. $ControlGoods->save();
  141. return true;
  142. }
  143. /**
  144. * 修改处理状态
  145. * @author 唐远望
  146. * @version 1.0
  147. * @date 2025-12-09
  148. * @param $id
  149. * @param $processing_status
  150. * @return bool
  151. */
  152. public function changeProcessingStatus($where, $processing_status)
  153. {
  154. $ControlGoods = $this->where($where)->first();
  155. if (!$ControlGoods) {
  156. return false;
  157. }
  158. $ControlGoods->processing_status = $processing_status;
  159. $ControlGoods->update_time = time();
  160. $ControlGoods->save();
  161. return true;
  162. }
  163. /**
  164. * 删除数据
  165. * @author 唐远望
  166. * @version 1.0
  167. * @date 2025-12-09
  168. * @param $id
  169. * @return bool
  170. */
  171. public function deleteControlGoods($where)
  172. {
  173. $ControlGoods = $this->where($where)->first();
  174. if (!$ControlGoods) {
  175. return false;
  176. }
  177. $ControlGoods->delete();
  178. return true;
  179. }
  180. }