123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- <?php
- // +----------------------------------------------------------------------
- // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
- // +----------------------------------------------------------------------
- // | Author: CRMEB Team <admin@crmeb.com>
- // +----------------------------------------------------------------------
- namespace app\controller\api\pc;
- use app\Request;
- use app\services\pc\ProductServices;
- use app\services\product\category\StoreProductCategoryServices;
- use app\services\product\product\StoreProductServices;
- use crmeb\services\SystemConfigService;
- /**
- * 商品
- * Class ProductController
- * @package app\controller\api\pc
- */
- class ProductController
- {
- protected $services;
- public function __construct(ProductServices $services)
- {
- $this->services = $services;
- }
- /**
- * 获取商品列表
- * @param Request $request
- * @param StoreProductCategoryServices $services
- * @return mixed
- */
- public function getProductList(Request $request, StoreProductCategoryServices $services)
- {
- $where = $request->getMore([
- [['sid', 'd'], 0],
- [['cid', 'd'], 0],
- ['keyword', '', '', 'store_name'],
- ['priceOrder', ''],
- ['salesOrder', ''],
- [['news', 'd'], 0, '', 'timeOrder'],
- [['type', ''], '', '', 'status'],
- ['ids', ''],
- ['selectId', ''],
- ['brand_id', '']
- ]);
- if ($where['selectId'] && (!$where['sid'] || !$where['cid'])) {
- if ($services->value(['id' => $where['selectId']], 'pid')) {
- $where['sid'] = $where['selectId'];
- } else {
- $where['cid'] = $where['selectId'];
- }
- }
- $where['ids'] = stringToArray($where['ids']);
- $where['brand_id'] = stringToArray($where['brand_id']);
- if (!$where['ids']) {
- unset($where['ids']);
- }
- $where['type'] = [0, 2];
- if ($where['store_name']) {//搜索
- $where['type'] = [];
- $where['pid'] = 0;
- }
- return app('json')->successful($this->services->getProductList($where, $request->uid()));
- }
- /**
- * PC端商品详情小程序码
- * @param Request $request
- * @return mixed
- */
- public function getProductRoutineCode(Request $request)
- {
- [$product_id] = $request->getMore([
- ['product_id', 0],
- ], true);
- $data = SystemConfigService::more(['product_phone_buy_url', 'site_url']);
- $routineCode = '';
- if (isset($data['product_phone_buy_url']) && $data['product_phone_buy_url'] == 2) {//小程序
- $routineCode = $this->services->getProductRoutineCode((int)$product_id);
- }
- return app('json')->successful(['site_url' => $data['site_url'], 'routineCode' => $routineCode]);
- }
- /**
- * 推荐商品
- * @param Request $request
- * @param $type
- * @return mixed
- */
- public function getRecommendList(Request $request, $type)
- {
- /** @var StoreProductServices $product */
- $product = app()->make(StoreProductServices::class);
- $uid = (int)$request->uid();
- $data = [];
- $data['list'] = [];
- $where['is_show'] = 1;
- $where['is_del'] = 0;
- if ($type == 1) {// 精品推荐
- $where['is_best'] = 1;
- } else if ($type == 2) {// 热门榜单
- $where['is_hot'] = 1;
- } else if ($type == 3) {// 首发新品
- $where['is_new'] = 1;
- } else if ($type == 4) {// 促销单品
- $where['is_benefit'] = 1;
- }
- $data['list'] = $product->getRecommendProduct($uid, $where, 0, 'mid');
- foreach ($data['list'] as &$item) {
- if (isset($item['star']) && count($item['star'])) {
- $item['star'] = bcdiv((string)array_sum(array_column($item['star'], 'product_score')), (string)count($item['star']), 1);
- } else {
- $item['star'] = config('admin.product_default_star');
- }
- }
- $data['count'] = $product->getCount($where);
- return app('json')->successful($data);
- }
- /**
- * 获取优品推荐
- * @return mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function getGoodProduct()
- {
- /** @var StoreProductServices $product */
- $product = app()->make(StoreProductServices::class);
- $list = get_thumb_water($product->getProducts(['store_label_id' => 5, 'is_del' => 0, 'is_show' => 1, 'is_verify' => 1, 'type' => [0, 2]], '', 0, ['couponId']), 'mid');
- return app('json')->successful(compact('list'));
- }
- }
|