|
@@ -1,12 +1,12 @@
|
|
|
<?php
|
|
<?php
|
|
|
// +----------------------------------------------------------------------
|
|
// +----------------------------------------------------------------------
|
|
|
-// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
|
|
|
|
|
|
+// | 商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
|
|
// +----------------------------------------------------------------------
|
|
// +----------------------------------------------------------------------
|
|
|
-// | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
|
|
|
|
|
|
|
+// | Copyright (c) 2017~2021 https://www.thinkphp.com All rights reserved.
|
|
|
// +----------------------------------------------------------------------
|
|
// +----------------------------------------------------------------------
|
|
|
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
|
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
|
|
// +----------------------------------------------------------------------
|
|
// +----------------------------------------------------------------------
|
|
|
-// | Author: 萤火科技 <admin@yiovo.com>
|
|
|
|
|
|
|
+// | Author: thinkphp <admin@yiovo.com>
|
|
|
// +----------------------------------------------------------------------
|
|
// +----------------------------------------------------------------------
|
|
|
declare (strict_types=1);
|
|
declare (strict_types=1);
|
|
|
|
|
|
|
@@ -14,7 +14,7 @@ namespace app\api\model;
|
|
|
|
|
|
|
|
use app\api\service\Goods as GoodsService;
|
|
use app\api\service\Goods as GoodsService;
|
|
|
use app\api\service\user\Grade as UserGradeService;
|
|
use app\api\service\user\Grade as UserGradeService;
|
|
|
-use app\api\model\GoodsSku as GoodsSkuModel;
|
|
|
|
|
|
|
+use app\api\model\GoodsSku as GoodsSkuModel;
|
|
|
use app\api\model\GoodsSpecRel as GoodsSpecRelModel;
|
|
use app\api\model\GoodsSpecRel as GoodsSpecRelModel;
|
|
|
use app\common\model\Goods as GoodsModel;
|
|
use app\common\model\Goods as GoodsModel;
|
|
|
use app\common\enum\goods\Status as GoodsStatusEnum;
|
|
use app\common\enum\goods\Status as GoodsStatusEnum;
|
|
@@ -92,80 +92,80 @@ class Goods extends GoodsModel
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 获取商品详情 (详细数据用于页面展示)
|
|
* 获取商品详情 (详细数据用于页面展示)
|
|
|
- * @param int $goodsId 商品ID
|
|
|
|
|
- * @param bool $verifyStatus 是否验证商品状态(上架)
|
|
|
|
|
|
|
+ * @param int $goodsId 商品ID
|
|
|
|
|
+ * @param bool $verifyStatus 是否验证商品状态(上架)
|
|
|
* @return mixed
|
|
* @return mixed
|
|
|
* @throws BaseException
|
|
* @throws BaseException
|
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\DbException
|
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
|
*/
|
|
*/
|
|
|
- public function getDetails(int $goodsId, bool $verifyStatus = true)
|
|
|
|
|
|
|
+ public function getDetails(int $goodsId, bool $verifyStatus = true)
|
|
|
{
|
|
{
|
|
|
- // 关联查询(商品图片、sku列表)
|
|
|
|
|
|
|
+ // 关联查询(商品图片、sku列表)
|
|
|
$with = ['images.file', 'skuList.image', 'video', 'videoCover'];
|
|
$with = ['images.file', 'skuList.image', 'video', 'videoCover'];
|
|
|
// 获取商品记录
|
|
// 获取商品记录
|
|
|
- $goodsInfo = $this->getGoodsMain($goodsId, $with, $verifyStatus);
|
|
|
|
|
|
|
+ $goodsInfo = $this->getGoodsMain($goodsId, $with, $verifyStatus);
|
|
|
// 商品规格列表
|
|
// 商品规格列表
|
|
|
$goodsInfo['specList'] = GoodsSpecRelModel::getSpecList($goodsInfo['goods_id']);
|
|
$goodsInfo['specList'] = GoodsSpecRelModel::getSpecList($goodsInfo['goods_id']);
|
|
|
- return $goodsInfo->hidden(array_merge($this->hidden, ['images']));
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 获取商品详情 (仅包含主商品信息和商品图片)
|
|
|
|
|
- * @param int $goodsId 商品ID
|
|
|
|
|
- * @param bool $verifyStatus 是否验证商品状态(上架)
|
|
|
|
|
- * @return mixed
|
|
|
|
|
- * @throws BaseException
|
|
|
|
|
- */
|
|
|
|
|
- public function getBasic(int $goodsId, bool $verifyStatus = true)
|
|
|
|
|
- {
|
|
|
|
|
- // 关联查询(商品图片)
|
|
|
|
|
- $with = ['images.file'];
|
|
|
|
|
- // 获取商品记录
|
|
|
|
|
- return $this->getGoodsMain($goodsId, $with, $verifyStatus);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 获取商品规格数据
|
|
|
|
|
- * @param int $goodsId
|
|
|
|
|
- * @return array
|
|
|
|
|
- * @throws \think\db\exception\DataNotFoundException
|
|
|
|
|
- * @throws \think\db\exception\DbException
|
|
|
|
|
- * @throws \think\db\exception\ModelNotFoundException
|
|
|
|
|
- */
|
|
|
|
|
- public function getSpecData(int $goodsId): array
|
|
|
|
|
- {
|
|
|
|
|
- $data = [];
|
|
|
|
|
- // 商品SKU列表
|
|
|
|
|
- $data['skuList'] = GoodsSkuModel::getSkuList($goodsId);
|
|
|
|
|
- // 商品规格列表
|
|
|
|
|
- $data['specList'] = GoodsSpecRelModel::getSpecList($goodsId);
|
|
|
|
|
- return $data;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 获取商品主体信息
|
|
|
|
|
- * @param int $goodsId 商品ID
|
|
|
|
|
- * @param array $with 关联查询
|
|
|
|
|
- * @param bool $verifyStatus 是否验证商品状态(上架)
|
|
|
|
|
- * @return mixed
|
|
|
|
|
- * @throws BaseException
|
|
|
|
|
- */
|
|
|
|
|
- private function getGoodsMain(int $goodsId, array $with = [], bool $verifyStatus = true)
|
|
|
|
|
- {
|
|
|
|
|
- // 获取商品记录
|
|
|
|
|
- $goodsInfo = static::detail($goodsId, $with);
|
|
|
|
|
- // 判断商品是否存在
|
|
|
|
|
- if (empty($goodsInfo) || $goodsInfo['is_delete']) {
|
|
|
|
|
- throwError('很抱歉,商品信息不存在');
|
|
|
|
|
- }
|
|
|
|
|
- // 判断商品状态(上架)
|
|
|
|
|
- if ($verifyStatus && $goodsInfo['status'] == GoodsStatusEnum::OFF_SALE) {
|
|
|
|
|
- throwError('很抱歉,当前商品已下架');
|
|
|
|
|
- }
|
|
|
|
|
- // 整理商品数据并返回
|
|
|
|
|
- return $this->setGoodsDataFromApi($goodsInfo);
|
|
|
|
|
|
|
+ return $goodsInfo->hidden(array_merge($this->hidden, ['images']));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取商品详情 (仅包含主商品信息和商品图片)
|
|
|
|
|
+ * @param int $goodsId 商品ID
|
|
|
|
|
+ * @param bool $verifyStatus 是否验证商品状态(上架)
|
|
|
|
|
+ * @return mixed
|
|
|
|
|
+ * @throws BaseException
|
|
|
|
|
+ */
|
|
|
|
|
+ public function getBasic(int $goodsId, bool $verifyStatus = true)
|
|
|
|
|
+ {
|
|
|
|
|
+ // 关联查询(商品图片)
|
|
|
|
|
+ $with = ['images.file'];
|
|
|
|
|
+ // 获取商品记录
|
|
|
|
|
+ return $this->getGoodsMain($goodsId, $with, $verifyStatus);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取商品规格数据
|
|
|
|
|
+ * @param int $goodsId
|
|
|
|
|
+ * @return array
|
|
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
|
|
+ * @throws \think\db\exception\DbException
|
|
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
|
|
+ */
|
|
|
|
|
+ public function getSpecData(int $goodsId): array
|
|
|
|
|
+ {
|
|
|
|
|
+ $data = [];
|
|
|
|
|
+ // 商品SKU列表
|
|
|
|
|
+ $data['skuList'] = GoodsSkuModel::getSkuList($goodsId);
|
|
|
|
|
+ // 商品规格列表
|
|
|
|
|
+ $data['specList'] = GoodsSpecRelModel::getSpecList($goodsId);
|
|
|
|
|
+ return $data;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取商品主体信息
|
|
|
|
|
+ * @param int $goodsId 商品ID
|
|
|
|
|
+ * @param array $with 关联查询
|
|
|
|
|
+ * @param bool $verifyStatus 是否验证商品状态(上架)
|
|
|
|
|
+ * @return mixed
|
|
|
|
|
+ * @throws BaseException
|
|
|
|
|
+ */
|
|
|
|
|
+ private function getGoodsMain(int $goodsId, array $with = [], bool $verifyStatus = true)
|
|
|
|
|
+ {
|
|
|
|
|
+ // 获取商品记录
|
|
|
|
|
+ $goodsInfo = static::detail($goodsId, $with);
|
|
|
|
|
+ // 判断商品是否存在
|
|
|
|
|
+ if (empty($goodsInfo) || $goodsInfo['is_delete']) {
|
|
|
|
|
+ throwError('很抱歉,商品信息不存在');
|
|
|
|
|
+ }
|
|
|
|
|
+ // 判断商品状态(上架)
|
|
|
|
|
+ if ($verifyStatus && $goodsInfo['status'] == GoodsStatusEnum::OFF_SALE) {
|
|
|
|
|
+ throwError('很抱歉,当前商品已下架');
|
|
|
|
|
+ }
|
|
|
|
|
+ // 整理商品数据并返回
|
|
|
|
|
+ return $this->setGoodsDataFromApi($goodsInfo);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|