Goods.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2023 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. /**
  17. * 商品控制器
  18. * Class Goods
  19. * @package app\api\controller
  20. */
  21. class Goods extends Controller
  22. {
  23. /**
  24. * 商品列表
  25. * @return \think\response\Json
  26. * @throws \think\db\exception\DbException
  27. */
  28. public function list(): \think\response\Json
  29. {
  30. // 获取列表数据
  31. $model = new GoodsModel;
  32. $list = $model->getList($this->request->param());
  33. return $this->renderSuccess(compact('list'));
  34. }
  35. /**
  36. * 获取商品详情
  37. * @param int $goodsId
  38. * @return \think\response\Json
  39. * @throws \cores\exception\BaseException
  40. * @throws \think\db\exception\DataNotFoundException
  41. * @throws \think\db\exception\DbException
  42. * @throws \think\db\exception\ModelNotFoundException
  43. */
  44. public function detail(int $goodsId): \think\response\Json
  45. {
  46. // 商品详情
  47. $model = new GoodsModel;
  48. $goodsInfo = $model->getDetails($goodsId);
  49. return $this->renderSuccess(['detail' => $goodsInfo]);
  50. }
  51. /**
  52. * 获取商品详情(基础信息)
  53. * @param int $goodsId
  54. * @param bool $verifyStatus
  55. * @return \think\response\Json
  56. * @throws \cores\exception\BaseException
  57. */
  58. public function basic(int $goodsId, bool $verifyStatus = true): \think\response\Json
  59. {
  60. // 获取商品详情
  61. $model = new GoodsModel;
  62. $detail = $model->getBasic($goodsId, $verifyStatus);
  63. return $this->renderSuccess(compact('detail'));
  64. }
  65. /**
  66. * 获取商品规格数据
  67. * @param int $goodsId 商品ID
  68. * @return \think\response\Json
  69. * @throws \think\db\exception\DataNotFoundException
  70. * @throws \think\db\exception\DbException
  71. * @throws \think\db\exception\ModelNotFoundException
  72. */
  73. public function specData(int $goodsId): \think\response\Json
  74. {
  75. // 获取商品详情
  76. $model = new GoodsModel;
  77. $specData = $model->getSpecData($goodsId);
  78. return $this->renderSuccess(compact('specData'));
  79. }
  80. /**
  81. * 获取商品的指定SKU信息
  82. * @param int $goodsId 商品ID
  83. * @param string $goodsSkuId 商品SKU标识
  84. * @return Json
  85. */
  86. public function skuInfo(int $goodsId, string $goodsSkuId): Json
  87. {
  88. $skuInfo = GoodsService::getSkuInfo($goodsId, $goodsSkuId);
  89. return $this->renderSuccess(compact('skuInfo'));
  90. }
  91. }