Collect.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace app\admin\model\shop;
  3. use think\Model;
  4. use app\common\Enum\StatusEnum;
  5. class Collect extends Model
  6. {
  7. // 表名
  8. protected $name = 'shop_collect';
  9. // 自动写入时间戳字段
  10. protected $autoWriteTimestamp = 'int';
  11. // 定义时间戳字段名
  12. protected $createTime = 'createtime';
  13. protected $updateTime = 'updatetime';
  14. protected $deleteTime = false;
  15. // 追加属性
  16. protected $append = [
  17. 'status_text'
  18. ];
  19. public function getStatusList()
  20. {
  21. return StatusEnum::getMap();
  22. }
  23. public function getStatusTextAttr($value, $data)
  24. {
  25. $value = $value ?: ($data['status'] ?? '');
  26. $list = $this->getStatusList();
  27. return $list[$value] ?? '';
  28. }
  29. public function user()
  30. {
  31. return $this->hasOne('\\app\\common\\model\\User', 'id', 'user_id',[], 'LEFT')->setEagerlyType(0);
  32. }
  33. public function goods()
  34. {
  35. return $this->hasOne('Goods', 'id', 'goods_id',[], 'LEFT')->setEagerlyType(0);
  36. }
  37. }