Share.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace app\admin\model\shopro;
  3. use think\Model;
  4. /**
  5. * 分享模型
  6. */
  7. class Share extends Model
  8. {
  9. // 表名,不含前缀
  10. protected $name = 'shopro_share';
  11. // 自动写入时间戳字段
  12. protected $autoWriteTimestamp = 'int';
  13. // 定义时间戳字段名
  14. protected $createTime = 'createtime';
  15. protected $updateTime = false;
  16. protected $deleteTime = false;
  17. // 追加属性
  18. protected $append = [
  19. 'type_text',
  20. ];
  21. public function getTypeList()
  22. {
  23. return ['index' => __('Type index'), 'goods' => __('Type goods'), 'groupon' => __('Type groupon')];
  24. }
  25. public function getTypeTextAttr($value, $data)
  26. {
  27. $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
  28. $list = $this->getTypeList();
  29. return isset($list[$value]) ? $list[$value] : '';
  30. }
  31. public function user()
  32. {
  33. return $this->belongsTo('\app\admin\model\shopro\user\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
  34. }
  35. }