You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

228 lines
9.0 KiB

<?php
namespace App\Controller\v3;
use App\Constants\v3\Tabs;
use App\Controller\BaseController;
/**
* 推荐商品相关
* Class GoodsRecommend
* @package App\Controller\v3
*/
class GoodsRecommendController extends BaseController
{
protected $data;
public function __construct()
{
$this->data = [
[
'goods' => [
'id' => 1,
'cover_img' => config('alioss.img_host').'/attachment/types/c9b656181bbbc463624ca3803c5be7539f2fd62253f9a-cwVLri.png',
'name' => '【优质】大白菜11',
'spec' => [
['key' => '净含量', 'value' => '500g']
],
'tags' => ['限时', '折扣'],
'original_price' => 50.5,
'price' => 25.25,
'inventory' => 10,
'month_sales' => 20,
'total_sales' => 20,
'cart_num' => 0,
'is_effective' => 2,
'noneffective_note' => '已卖完',
],
'store' => ['id' => 1, 'logo' => '', 'name' => '我是一个商家']
],
[
'goods' => [
'id' => 2,
'cover_img' => config('alioss.img_host').'/attachment/types/c9b656181bbbc463624ca3803c5be7539f2fd62253f9a-cwVLri.png',
'name' => '【优质】大白菜11',
'spec' => [
['key' => '净含量', 'value' => '500g']
],
'tags' => ['限时', '折扣'],
'original_price' => 50.5,
'price' => 25.25,
'inventory' => 10,
'month_sales' => 20,
'total_sales' => 20,
'cart_num' => 0,
'is_effective' => 2,
'noneffective_note' => '已卖完',
],
'store' => ['id' => 222, 'logo' => '', 'name' => '我是一个商家222']
],
[
'goods' => [
'id' => 3,
'cover_img' => config('alioss.img_host').'/attachment/types/c9b656181bbbc463624ca3803c5be7539f2fd62253f9a-cwVLri.png',
'name' => '【优质】大白菜11',
'spec' => [
['key' => '净含量', 'value' => '500g']
],
'tags' => ['限时', '折扣'],
'original_price' => 50.5,
'price' => 25.25,
'inventory' => 10,
'month_sales' => 20,
'total_sales' => 20,
'cart_num' => 0,
'is_effective' => 2,
'noneffective_note' => '已卖完',
],
'store' => ['id' => 2, 'logo' => '', 'name' => '我是一个商家333']
],
[
'goods' => [
'id' => 4,
'cover_img' => config('alioss.img_host').'/attachment/types/c9b656181bbbc463624ca3803c5be7539f2fd62253f9a-cwVLri.png',
'name' => '【优质】大白菜11',
'spec' => [
['key' => '净含量', 'value' => '500g']
],
'tags' => ['限时', '折扣'],
'original_price' => 50.5,
'price' => 25.25,
'inventory' => 10,
'month_sales' => 20,
'total_sales' => 20,
'cart_num' => 0,
'is_effective' => 2,
'noneffective_note' => '已卖完',
],
'store' => ['id' => 3, 'logo' => '', 'name' => '我是一个商家444']
]
];
parent::__construct();
}
/**
* 获取首页tabs推荐商品列表
* 1、前端上传tab标识
* 2、根据tab标识从Elasticsearch中获取商品IDs
* 3、根据IDs获取商品数据
* 4、返回数据,id、封面图、名称、原价、现价、库存、月销、tag、规格、购物车相关、商户id、商户avatar、商户名
*/
public function getByTabsForAppletIndex()
{
$tabsData = [
Tabs::APPLET_INDEX_RECOMMEND => [
[
'goods' => [
'id' => 1,
'cover_img' => config('alioss.img_host').'/attachment/types/c9b656181bbbc463624ca3803c5be7539f2fd62253f9a-cwVLri.png',
'name' => '【优质】大白菜11',
'spec' => [
['key' => '净含量', 'value' => '500g']
],
'tags' => ['限时', '折扣'],
'original_price' => 50.5,
'price' => 25.25,
'inventory' => 10,
'month_sales' => 20,
'total_sales' => 20,
'cart_num' => 0,
'is_effective' => 2,
'noneffective_note' => '已卖完',
],
'store' => ['id' => 1, 'logo' => '', 'name' => '我是一个商家']
],
],
Tabs::APPLET_INDEX_NEW => [
[
'goods' => [
'id' => 2,
'cover_img' => config('alioss.img_host').'/attachment/types/c9b656181bbbc463624ca3803c5be7539f2fd62253f9a-cwVLri.png',
'name' => '【优质】大白菜11',
'spec' => [
['key' => '净含量', 'value' => '500g']
],
'tags' => ['限时', '折扣'],
'original_price' => 50.5,
'price' => 25.25,
'inventory' => 10,
'month_sales' => 20,
'total_sales' => 20,
'cart_num' => 0,
'is_effective' => 2,
'noneffective_note' => '已卖完',
],
'store' => ['id' => 2, 'logo' => '', 'name' => '我是一个商家222']
],
],
Tabs::APPLET_INDEX_FRESH => [
[
'goods' => [
'id' => 3,
'cover_img' => config('alioss.img_host').'/attachment/types/c9b656181bbbc463624ca3803c5be7539f2fd62253f9a-cwVLri.png',
'name' => '【优质】大白菜11',
'spec' => [
['key' => '净含量', 'value' => '500g']
],
'tags' => ['限时', '折扣'],
'original_price' => 50.5,
'price' => 25.25,
'inventory' => 10,
'month_sales' => 20,
'total_sales' => 20,
'cart_num' => 0,
'is_effective' => 2,
'noneffective_note' => '已卖完',
],
'store' => ['id' => 3, 'logo' => '', 'name' => '我是一个商家333']
],
],
Tabs::APPLET_INDEX_OFFICE => [
[
'goods' => [
'id' => 4,
'cover_img' => config('alioss.img_host').'/attachment/types/c9b656181bbbc463624ca3803c5be7539f2fd62253f9a-cwVLri.png',
'name' => '【优质】大白菜11',
'spec' => [
['key' => '净含量', 'value' => '500g']
],
'tags' => ['限时', '折扣'],
'original_price' => 50.5,
'price' => 25.25,
'inventory' => 10,
'month_sales' => 20,
'total_sales' => 20,
'cart_num' => 0,
'is_effective' => 2,
'noneffective_note' => '已卖完',
],
'store' => ['id' => 4, 'logo' => '', 'name' => '我是一个商家444']
],
]
];
return $this->success([
'tab_data' => $tabsData[$this->request->post('tab', 'applet_index_recommend')]
]);
}
/**
* 获取搜索页推荐商品列表
* 1、前端上传标识
* recommend_search_goods
* recommend_search_stores
* recommend_user_index
* 2、根据标识从Elasticsearch中获取商品IDs
* 3、根据IDs获取商品数据
* 4、返回数据,id、封面图、名称、原价、现价、库存、月销、tag、规格、购物车相关、商户id、商户avatar、商户名
*/
public function getByTab()
{
return $this->success(['tab_data' => $this->data]);
}
}