ExecuteLog.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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 ExecuteLog extends Model
  13. {
  14. use HasFactory;
  15. // 与模型关联的表名
  16. protected $table = 'process_execute_log';
  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 addExecuteLog_content($data)
  29. {
  30. $insert_data = [
  31. 'name' => $data['name'],
  32. 'code' => $data['code'],
  33. 'admin_id' => $data['admin_id'],
  34. 'insert_time' => time(),
  35. ];
  36. $ExecuteLog_id = $this->insertGetId($insert_data);
  37. return $ExecuteLog_id;
  38. }
  39. /**
  40. * 写入数据
  41. * @author 唐远望
  42. * @version 1.0
  43. * @date 2025-12-09
  44. * @param $data
  45. * @return bool
  46. */
  47. public function addExecuteLog($data)
  48. {
  49. DB::beginTransaction();
  50. try {
  51. $this->addExecuteLog_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-09
  66. * @param $data
  67. * @return bool
  68. */
  69. public function editExecuteLog_content($where, $data)
  70. {
  71. $ExecuteLog = $this->where($where)->first();
  72. if (!$ExecuteLog) {
  73. return false;
  74. }
  75. $ExecuteLog->name = $data['name'];
  76. $ExecuteLog->code = $data['responsible_person'];
  77. $ExecuteLog->admin_id = $data['product_name'];
  78. $ExecuteLog->update_time = time();
  79. $ExecuteLog->save();
  80. return true;
  81. }
  82. /**
  83. * 更新数据
  84. * @author 唐远望
  85. * @version 1.0
  86. * @date 2025-12-09
  87. * @param $data
  88. * @return bool
  89. */
  90. public function updateExecuteLog($where, $data)
  91. {
  92. DB::beginTransaction();
  93. try {
  94. $this->editExecuteLog_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-09
  109. * @param $id
  110. * @param $status
  111. * @return bool
  112. */
  113. public function changeStatus($where, $status)
  114. {
  115. $ExecuteLog = $this->where($where)->first();
  116. if (!$ExecuteLog) {
  117. return false;
  118. }
  119. $ExecuteLog->status = $status;
  120. $ExecuteLog->update_time = time();
  121. $ExecuteLog->save();
  122. return true;
  123. }
  124. /**
  125. * 删除数据
  126. * @author 唐远望
  127. * @version 1.0
  128. * @date 2025-12-09
  129. * @param $id
  130. * @return bool
  131. */
  132. public function deleteExecuteLog($where)
  133. {
  134. $ExecuteLog = $this->where($where)->first();
  135. if (!$ExecuteLog) {
  136. return false;
  137. }
  138. $ExecuteLog->delete();
  139. return true;
  140. }
  141. }