Product.php 994 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace addons\qingdongams\model;
  3. use addons\qingdongams\model\File;
  4. use think\Model;
  5. use traits\model\SoftDelete;
  6. /**
  7. *产品表
  8. */
  9. class Product Extends Model
  10. {
  11. use SoftDelete;
  12. // 表名,不含前缀
  13. protected $name = 'qingdongams_product';
  14. // 开启自动写入时间戳字段
  15. protected $autoWriteTimestamp = 'int';
  16. // 定义时间戳字段名
  17. protected $createTime = 'createtime';
  18. protected $updateTime = 'updatetime';
  19. protected $deleteTime = 'deletetime';
  20. public function getImgAttr($value) {
  21. if ($value) {
  22. return cdnurl(File::getUrl($value), true);
  23. } else {
  24. return $value;
  25. }
  26. }
  27. public function producttype(){
  28. return $this->belongsTo(Producttype::class, 'type_id', 'id')->field('id,name');
  29. }
  30. //商品
  31. public function goods(){
  32. return $this->belongsTo(Goods::class, 'goods_id', 'id')->field('id,name');
  33. }
  34. }