MoneyLog.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. class MoneyLog extends Model
  5. {
  6. // 表名
  7. protected $name = 'money_log';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'int';
  10. // 定义时间戳字段名
  11. protected $createTime = 'create_time';
  12. protected $updateTime = false;
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'create_time_text'
  17. ];
  18. //
  19. public function users()
  20. {
  21. return $this->hasOne('Users','id','user_id',[],'LEFT')->setEagerlyType(0);
  22. }
  23. public function fromuser()
  24. {
  25. return $this->hasOne('Users','id','from_id',[],'LEFT')->setEagerlyType(0);
  26. }
  27. public function getCreateTimeTextAttr($value, $data)
  28. {
  29. $value = $value ? $value : (isset($data['create_time']) ? $data['create_time'] : '');
  30. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  31. }
  32. protected function setCreateTimeAttr($value)
  33. {
  34. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  35. }
  36. }