ExecuteLog.php 3.5 KB

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