Goods.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. $promoter = $this->request->param('promoter',0);
  49. // 商品详情
  50. $model = new GoodsModel;
  51. $goodsInfo = $model->getDetails($goodsId, $verifyStatus);
  52. $user = $this->getLoginUser();
  53. if (!empty($user)){
  54. }
  55. //如果已经登录,则可以记录推广人,如果没登录,需要前端继续保持此信息,登录后,下单时传给我
  56. return $this->renderSuccess(['detail' => $goodsInfo,'promoter'=>$promoter]);
  57. }
  58. /**
  59. * 获取商品详情(基础信息)
  60. * @param int $goodsId 商品ID
  61. * @param bool $verifyStatus 是否验证商品状态(上架)
  62. * @return Json
  63. * @throws BaseException
  64. */
  65. public function basic(int $goodsId, bool $verifyStatus = true): Json
  66. {
  67. // 获取商品详情
  68. $model = new GoodsModel;
  69. $detail = $model->getBasic($goodsId, $verifyStatus);
  70. return $this->renderSuccess(compact('detail'));
  71. }
  72. /**
  73. * 获取商品规格数据
  74. * @param int $goodsId
  75. * @return Json
  76. * @throws \think\db\exception\DataNotFoundException
  77. * @throws \think\db\exception\DbException
  78. * @throws \think\db\exception\ModelNotFoundException
  79. */
  80. public function specData(int $goodsId): Json
  81. {
  82. // 获取商品详情
  83. $model = new GoodsModel;
  84. $specData = $model->getSpecData($goodsId);
  85. return $this->renderSuccess(compact('specData'));
  86. }
  87. /**
  88. * 获取商品的指定SKU信息
  89. * @param int $goodsId 商品ID
  90. * @param string $goodsSkuId 商品SKU标识
  91. * @return Json
  92. */
  93. public function skuInfo(int $goodsId, string $goodsSkuId): Json
  94. {
  95. $skuInfo = GoodsService::getSkuInfo($goodsId, $goodsSkuId);
  96. return $this->renderSuccess(compact('skuInfo'));
  97. }
  98. public function promotionToFriend(int $goodsId, string $email): Json
  99. {
  100. $model = new GoodsModel;
  101. $goodsInfo = $model->getDetails($goodsId, true);
  102. $user = $this->getLoginUser();
  103. $userId = $user->id;
  104. $emailText = '你的朋友给你分享了一个好东西,点击去查看,https://ww.com?goodsId='.$goodsId.'promoter=' . $userId;
  105. return $this->renderSuccess(compact('emailText'));
  106. }
  107. }