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.
 
 

227 lines
9.6 KiB

<?php
namespace App\Controller\v3;
use App\Constants\v3\ActivityType;
use App\Constants\v3\SsdbKeys;
use App\Constants\v3\Tabs;
use App\Controller\BaseController;
use App\Request\v3\UserIndexRequest;
use App\Service\v3\Interfaces\CollectStoreServiceInterface;
use App\Service\v3\Interfaces\CouponServiceInterface;
use App\Service\v3\Interfaces\UserCenterBlockServiceInterface;
use App\Service\v3\Interfaces\UserInfoServiceInterface;
use App\TaskWorker\SSDBTask;
use Hyperf\Di\Annotation\Inject;
use Hyperf\Utils\ApplicationContext;
/**
* 首页相关
* Class HomeController
* @package App\Controller\v3
*/
class HomeController extends BaseController
{
/**
* @Inject
* @var UserInfoServiceInterface
*/
protected $userInfoService;
/**
* @Inject
* @var CollectStoreServiceInterface
*/
protected $collectStoreService;
/**
* @Inject
* @var CouponServiceInterface
*/
protected $couponService;
/**
* @Inject
* @var UserCenterBlockServiceInterface
*/
protected $userCenterBlockService;
/**
* 小程序首页,根据market_id
* 1.banner数据
* 2.一级分类
* 3.活动数据(秒杀、团购、新品、无)
* 4.tabs数据
*/
public function appletIndex()
{
$seconds = 25600;
$days = bcdiv($seconds, 86400);
$leftSeconds = bcsub($seconds, bcmul($days,86400));
$hours = bcdiv($leftSeconds,3600);
$leftSeconds = bcsub($leftSeconds, bcmul($hours,3600));
$minutes = bcdiv($leftSeconds,60);
$leftSeconds = bcsub($leftSeconds, bcmul($minutes,60));
return $this->success([
'banners' => [
[
'id' => 2,
'img' => 'https://store.lanzu.vip/attachment/images/2/2020/06/nfXxIhEgH71hcSxSz2hHnaaEaF1g3A.jpg',
'title' => '懒族生活',
'subtitle' => '满足您的美味生活',
'redirect_type' => '',
'redirect_url' => '',
],
[
'id' => 3,
'img' => 'http://lanzutest.lanzulive.com/attachment/images/2/2020/08/PY55Y3Mz17yJo17rv1Z7vImX1V5159.jpg',
'title' => '鲜菜有爱',
'subtitle' => '很实在',
'redirect_type' => 'page',
'redirect_url' => '/pages/index',
],
],
'categories' => [
['id' => 1, 'icon' => config('alioss.img_host').'/attachment/types/卤菜.png', 'name' => '卤菜'],
['id' => 2, 'icon' => config('alioss.img_host').'/attachment/types/水果.png', 'name' => '水果'],
['id' => 3, 'icon' => config('alioss.img_host').'/attachment/types/肉.png', 'name' => '肉'],
['id' => 4, 'icon' => config('alioss.img_host').'/attachment/types/蔬菜.png', 'name' => '蔬菜'],
['id' => 5, 'icon' => config('alioss.img_host').'/attachment/types/蔬菜.png', 'name' => '蔬菜'],
['id' => 6, 'icon' => config('alioss.img_host').'/attachment/types/肉.png', 'name' => '肉'],
['id' => 7, 'icon' => config('alioss.img_host').'/attachment/types/水果.png', 'name' => '水果'],
['id' => 8, 'icon' => config('alioss.img_host').'/attachment/types/卤菜.png', 'name' => '卤菜'],
],
'activity' => [
'type' => ActivityType::FLASH_SALE,
'goods' => [
[
'id' => 1,
'store_id' => 111,
'cover_img' => config('alioss.img_host').'/attachment/types/c9b656181bbbc463624ca3803c5be7539f2fd62253f9a-cwVLri.png',
'name' => '【优质】大白菜',
'spec' => [
['key' => '净含量', 'value' => '500g']
],
'original_price' => 50.5,
'price' => 25.25,
'inventory' => 0,
'month_sales' => 20,
'total_sales' => 20,
'cart_num' => 0,
'is_effective' => 1,
'noneffective_note' => '已抢光',
'total_seconds' => $seconds,
'days' => $days,
'hours' => $hours,
'minutes' => $minutes,
'seconds' => $leftSeconds,
],[
'id' => 1,
'store_id' => 111,
'cover_img' => config('alioss.img_host').'/attachment/types/c9b656181bbbc463624ca3803c5be7539f2fd62253f9a-cwVLri.png',
'name' => '【优质】大白菜',
'spec' => [
['key' => '净含量', 'value' => '500g']
],
'original_price' => 50.5,
'price' => 25.25,
'inventory' => 0,
'month_sales' => 20,
'total_sales' => 20,
'cart_num' => 0,
'is_effective' => 1,
'noneffective_note' => '已抢光',
'total_seconds' => $seconds,
'days' => $days,
'hours' => $hours,
'minutes' => $minutes,
'seconds' => $leftSeconds,
],[
'id' => 1,
'store_id' => 111,
'cover_img' => config('alioss.img_host').'/attachment/types/c9b656181bbbc463624ca3803c5be7539f2fd62253f9a-cwVLri.png',
'name' => '【优质】大白菜',
'spec' => [
['key' => '净含量', 'value' => '500g']
],
'original_price' => 50.5,
'price' => 25.25,
'inventory' => 0,
'month_sales' => 20,
'total_sales' => 20,
'cart_num' => 0,
'is_effective' => 1,
'noneffective_note' => '已抢光',
'total_seconds' => $seconds,
'days' => $days,
'hours' => $hours,
'minutes' => $minutes,
'seconds' => $leftSeconds,
],[
'id' => 1,
'store_id' => 111,
'cover_img' => config('alioss.img_host').'/attachment/types/c9b656181bbbc463624ca3803c5be7539f2fd62253f9a-cwVLri.png',
'name' => '【优质】大白菜',
'spec' => [
['key' => '净含量', 'value' => '500g']
],
'original_price' => 50.5,
'price' => 25.25,
'inventory' => 0,
'month_sales' => 20,
'total_sales' => 20,
'cart_num' => 0,
'is_effective' => 1,
'noneffective_note' => '已抢光',
'total_seconds' => $seconds,
'days' => $days,
'hours' => $hours,
'minutes' => $minutes,
'seconds' => $leftSeconds,
],
]
],
'tabs' => [
['tab' => Tabs::APPLET_INDEX_RECOMMEND, 'title' => '推荐', 'subtitle' => '猜你喜欢', 'badge' => '', 'bg_color' => '#FF0000', 'font_color' => '#FFFFFF'],
['tab' => Tabs::APPLET_INDEX_NEW, 'title' => '懒族上新', 'subtitle' => '买点不一样', 'badge' => '限时', 'bg_color' => '#FF0000', 'font_color' => '#FFFFFF'],
['tab' => Tabs::APPLET_INDEX_FRESH, 'title' => '实时鲜货', 'subtitle' => '今天辛苦了', 'badge' => '好新鲜', 'bg_color' => '#FF0000', 'font_color' => '#FFFFFF'],
['tab' => Tabs::APPLET_INDEX_OFFICE, 'title' => '上班带餐', 'subtitle' => '轻奢快手菜', 'badge' => '不慌', 'bg_color' => '#FF0000', 'font_color' => '#FFFFFF'],
]
]);
}
/**
* 用户首页,我的页面
* 1、用户信息,id、昵称、名字、头像
* 2、收藏、红包、积分
* 3、badge角标,待付款、待收货、已完成、售后, SSDB维护
* 4、为你推荐的商品列表
* @param UserIndexRequest $request
*/
public function userIndex(UserIndexRequest $request)
{
$params = $request->validated();
$data['user'] = $this->userInfoService->detail($params['user_id']);
$data['user']['collection_count'] = $this->collectStoreService->countByUser($params['user_id']);
$data['user']['coupon_count'] = $this->couponService->countAvailableByUser($params['user_id']);
$ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);
$data['badge'] = [
'unpaid' => 0,
'receiving' => 0,
'completed' => 0,
'refund' => 0,
];
$badge = $ssdb->exec('hgetall', SsdbKeys::USER_ORDER_BADGE.$params['user_id']);
if (!empty($badge)) {
$data['badge'] = array_merge($data['badge'], $badge);
}
$data['block'] = $this->userCenterBlockService->all();
return $this->success($data);
}
}