ShopGoods.php 854 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. declare(strict_types=1);
  3. namespace app\api\model;
  4. use app\common\model\ShopGoods as ShopGoodsModel;
  5. use app\common\exception\BaseException;
  6. /**
  7. * 门店商品模型
  8. * Class ShopGoods
  9. * @package app\store\model
  10. */
  11. class ShopGoods extends ShopGoodsModel
  12. {
  13. /**
  14. * 获取详情
  15. * @param int $id
  16. * @return mixed
  17. * @throws BaseException
  18. * @throws \think\db\exception\DataNotFoundException
  19. * @throws \think\db\exception\DbException
  20. * @throws \think\db\exception\ModelNotFoundException
  21. */
  22. public function getDetail(int $id)
  23. {
  24. // 关联查询
  25. $with = ['goods', 'shopGoodsSku.goodsSku'];
  26. // 获取商品记录
  27. $goodsInfo = self::with($with)->find($id);
  28. empty($goodsInfo) && throwError('很抱歉,商品信息不存在');
  29. return $goodsInfo;
  30. }
  31. }