Goods.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2024 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\api\controller;
  13. use think\response\Json;
  14. use app\api\model\{Goods as GoodsModel};
  15. use app\api\service\{Goods as GoodsService};
  16. use cores\exception\BaseException;
  17. /**
  18. * 商品控制器
  19. * Class Goods
  20. * @package app\api\controller
  21. */
  22. class Goods extends Controller
  23. {
  24. /**
  25. * 商品列表
  26. * @return Json
  27. * @throws \think\db\exception\DbException
  28. */
  29. public function list(): Json
  30. {
  31. // 获取列表数据
  32. $model = new GoodsModel;
  33. $list = $model->getList($this->request->param());
  34. return $this->renderSuccess(compact('list'));
  35. }
  36. /**
  37. * 获取商品详情(详细信息)
  38. * @param int $goodsId 商品ID
  39. * @param bool $verifyStatus 是否验证商品状态(上架)
  40. * @return Json
  41. * @throws \think\db\exception\DataNotFoundException
  42. * @throws \think\db\exception\DbException
  43. * @throws \think\db\exception\ModelNotFoundException
  44. * @throws BaseException
  45. */
  46. public function detail(int $goodsId, bool $verifyStatus = true): Json
  47. {
  48. // 商品详情
  49. $model = new GoodsModel;
  50. $goodsInfo = $model->getDetails($goodsId, $verifyStatus);
  51. return $this->renderSuccess(['detail' => $goodsInfo]);
  52. }
  53. /**
  54. * 获取商品详情(基础信息)
  55. * @param int $goodsId 商品ID
  56. * @param bool $verifyStatus 是否验证商品状态(上架)
  57. * @return Json
  58. * @throws BaseException
  59. */
  60. public function basic(int $goodsId, bool $verifyStatus = true): Json
  61. {
  62. // 获取商品详情
  63. $model = new GoodsModel;
  64. $detail = $model->getBasic($goodsId, $verifyStatus);
  65. return $this->renderSuccess(compact('detail'));
  66. }
  67. /**
  68. * 获取商品规格数据
  69. * @param int $goodsId
  70. * @return Json
  71. * @throws \think\db\exception\DataNotFoundException
  72. * @throws \think\db\exception\DbException
  73. * @throws \think\db\exception\ModelNotFoundException
  74. */
  75. public function specData(int $goodsId): Json
  76. {
  77. // 获取商品详情
  78. $model = new GoodsModel;
  79. $specData = $model->getSpecData($goodsId);
  80. return $this->renderSuccess(compact('specData'));
  81. }
  82. /**
  83. * 获取商品的指定SKU信息
  84. * @param int $goodsId 商品ID
  85. * @param string $goodsSkuId 商品SKU标识
  86. * @return Json
  87. */
  88. public function skuInfo(int $goodsId, string $goodsSkuId): Json
  89. {
  90. $skuInfo = GoodsService::getSkuInfo($goodsId, $goodsSkuId);
  91. return $this->renderSuccess(compact('skuInfo'));
  92. }
  93. }