// +---------------------------------------------------------------------- namespace app\controller\api\v1\product; use app\Request; use app\services\product\category\StoreProductCategoryServices; use app\services\product\product\StoreProductRankServices; use app\services\product\product\StoreProductServices; use think\db\exception\DataNotFoundException; use think\db\exception\DbException; use think\db\exception\ModelNotFoundException; /** * 商品榜单 * Class StoreProductRank * @package app\api\controller\product */ class StoreProductRank { protected $services; public function __construct(StoreProductServices $services) { $this->services = $services; } /** * 获取绑定分类 * @param StoreProductCategoryServices $services * @return \think\Response * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException * @throws \ReflectionException */ public function rankCategory(StoreProductCategoryServices $services) { return app('json')->successful($services->getRankCategory()); } /** * 获取榜单列表 * @param Request $request * @param StoreProductCategoryServices $services * @param StoreProductRankServices $productRankServices * @param $type * @return \think\Response * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException * @throws \throwable */ public function rankList(Request $request, StoreProductCategoryServices $services, StoreProductRankServices $productRankServices,$type) { $where = $request->getMore([ [['selectId', 'd'], ''], ]); if ($where['selectId']) { $level = $services->value(['id' => (int)$where['selectId']], 'level') ?? 0; $levelArr = $services->cateField; $where[$levelArr[$level] ?? 'cid'] = $where['selectId']; unset($where['selectId']); } $uid = 0; if ($request->hasMacro('uid')) $uid = (int)$request->uid(); return app('json')->successful($productRankServices->getProductRankList($uid, (int)$type, $where)); } }