ShopGoods.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. declare (strict_types=1);
  3. namespace app\common\model;
  4. use think\Paginator;
  5. use think\model\Collection;
  6. use app\common\library\helper;
  7. use app\store\model\GoodsCategoryRel as GoodsCategoryRelModel;
  8. use app\common\enum\goods\Status as GoodsStatusEnum;
  9. use think\facade\Db;
  10. /**
  11. * 门店自提商品模型
  12. * Class ShopGoods
  13. * @package app\common\model
  14. */
  15. class ShopGoods extends BaseModel
  16. {
  17. // 定义表名
  18. protected $name = 'shop_goods';
  19. // 定义主键
  20. protected $pk = 'id';
  21. // 追加字段
  22. protected $append = [];
  23. public function goods()
  24. {
  25. return $this->belongsTo("Goods")->with(['images' => ['file']]);
  26. }
  27. /**
  28. * 关联门店商品规格表
  29. * @return \think\model\relation\HasMany
  30. */
  31. public function shopGoodsSku()
  32. {
  33. return $this->hasMany('ShopGoodsSku', 'shop_goods_id')
  34. ->order(['id' => 'asc']);
  35. }
  36. /**
  37. * 关联商品图片表
  38. * @return \think\model\relation\HasMany
  39. */
  40. public function images()
  41. {
  42. return $this->hasMany('GoodsImage')->order(['id']);
  43. }
  44. public function shops()
  45. {
  46. return $this->hasOne('Shops', 'shop_id', 'shop_id');
  47. }
  48. }