Goods.php 2.8 KB

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