Collection.php 851 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace addons\cms\model;
  3. use think\Model;
  4. /**
  5. * 收藏模型
  6. */
  7. class Collection extends Model
  8. {
  9. protected $name = "cms_collection";
  10. // 开启自动写入时间戳字段
  11. protected $autoWriteTimestamp = 'int';
  12. // 定义时间戳字段名
  13. protected $createTime = 'createtime';
  14. protected $updateTime = 'updatetime';
  15. // 追加属性
  16. protected $append = [
  17. 'create_date',
  18. ];
  19. protected static $config = [];
  20. public function getCreateDateAttr($value, $data)
  21. {
  22. $value = $value ? $value : (isset($data['createtime']) ? $data['createtime'] : '');
  23. return date('Y-m-d H:i:s', $value);
  24. }
  25. /**
  26. * 关联模型
  27. */
  28. public function user()
  29. {
  30. return $this->belongsTo("\app\common\model\User", 'user_id', 'id', [], 'LEFT')->setEagerlyType(1);
  31. }
  32. }