Notices.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. /**
  7. * 通知消息模型
  8. * @author: 唐远望
  9. * @version: 1.0
  10. * @date: 2025-12-29
  11. */
  12. class Notices extends Model
  13. {
  14. use HasFactory;
  15. // 与模型关联的表名
  16. protected $table = 'process_notices';
  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-29
  27. */
  28. public function addNotices_content($data)
  29. {
  30. $insert_data = [
  31. 'title' => $data['title'],
  32. 'content' => $data['content'],
  33. 'msg_type' => $data['msg_type'],
  34. 'custom_uid' => $data['custom_uid'],
  35. ];
  36. $Notices_id = $this->insertGetId($insert_data);
  37. return $Notices_id;
  38. }
  39. /**
  40. * 写入数据
  41. * @author 唐远望
  42. * @version 1.0
  43. * @date 2025-12-29
  44. * @param $data
  45. * @return bool
  46. */
  47. public function addNotices($data)
  48. {
  49. DB::beginTransaction();
  50. try {
  51. $this->addNotices_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-29
  66. * @param $data
  67. * @return bool
  68. */
  69. public function editNotices_content($where, $data)
  70. {
  71. $Notices = $this->where($where)->first();
  72. if (!$Notices) {
  73. return false;
  74. }
  75. $Notices->title = $data['title'];
  76. $Notices->content = $data['content'];
  77. $Notices->msg_type = $data['msg_type'];
  78. $Notices->custom_uid = $data['custom_uid'];
  79. $Notices->save();
  80. return true;
  81. }
  82. /**
  83. * 更新数据
  84. * @author 唐远望
  85. * @version 1.0
  86. * @date 2025-12-29
  87. * @param $data
  88. * @return bool
  89. */
  90. public function updateNotices($where, $data)
  91. {
  92. DB::beginTransaction();
  93. try {
  94. $this->editNotices_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-29
  109. * @param $id
  110. * @return bool
  111. */
  112. public function deleteNotices($where)
  113. {
  114. $Notices = $this->where($where)->first();
  115. if (!$Notices) {
  116. return false;
  117. }
  118. $Notices->delete();
  119. return true;
  120. }
  121. }