ApproveInfoLog.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. /**
  5. * 审批申请-审批人修改记录模型
  6. */
  7. class ApproveInfoLog extends Model
  8. {
  9. // 表名
  10. protected $name = 'approve_info_log';
  11. // 追加属性
  12. protected $append = [
  13. 'before_text',
  14. 'after_text',
  15. ];
  16. public function getBeforeTextAttr($value, $data)
  17. {
  18. $value = $value ? $value : (isset($data['before']) ? $data['before'] : '');
  19. return $value ? json_decode($value,true) : [];
  20. }
  21. public function getAfterTextAttr($value, $data)
  22. {
  23. $value = $value ? $value : (isset($data['after']) ? $data['after'] : '');
  24. return $value ? json_decode($value,true) : [];
  25. }
  26. // 关联用户 (后台)
  27. public function user()
  28. {
  29. return $this->belongsTo(User::class, 'user_id', 'userid');
  30. }
  31. protected static function init()
  32. {
  33. self::beforeInsert(function ($row) {
  34. $changed = $row->getChangedData();
  35. });
  36. self::beforeUpdate(function ($row) {
  37. $changed = $row->getChangedData();
  38. });
  39. self::afterInsert(function ($row) {
  40. $changed = $row->getChangedData();
  41. });
  42. self::afterUpdate(function ($row) {
  43. $changed = $row->getChangedData();
  44. });
  45. }
  46. }