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.
 
 

173 lines
5.2 KiB

<?php
namespace App\Controller\v3;
use App\Constants\v3\ActivityType;
use App\Constants\v3\Banner;
use App\Constants\v3\SsdbKeys;
use App\Constants\v3\Tabs;
use App\Controller\BaseController;
use App\Request\v3\UserIndexRequest;
use App\Service\v3\Interfaces\ActivityServiceInterface;
use App\Service\v3\Interfaces\BannerServiceInterface;
use App\Service\v3\Interfaces\CategoryServiceInterface;
use App\Service\v3\Interfaces\CollectStoreServiceInterface;
use App\Service\v3\Interfaces\CouponServiceInterface;
use App\Service\v3\Interfaces\StoreInfoServiceInterface;
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;
use Psr\Http\Message\ResponseInterface;
/**
* 首页相关
* 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;
/**
* @Inject
* @var StoreInfoServiceInterface
*/
protected $storeInfoService;
/**
* @Inject
* @var BannerServiceInterface
*/
protected $bannerService;
/**
* @Inject
* @var CategoryServiceInterface
*/
protected $categoryService;
/**
* @Inject
* @var ActivityServiceInterface
*/
protected $activityService;
/**
* 小程序首页,根据market_id
* 1.banner数据
* 2.一级分类
* 3.活动数据(秒杀、团购、新品、无)
* 4.tabs数据
*/
public function appletIndex()
{
$marketId = $this->request->input('market_id', 0);
$banners = $this->bannerService->all(Banner::TYPE_APPLET_INDEX, $marketId);
$categories = $this->categoryService->allForAppletIndex();
$activity = $this->activityService->allForAppletIndex(ActivityType::FLASH_SALE, $marketId);
return $this->success([
'banners' => $banners,
'categories' => $categories,
'activity' => ['type' => ActivityType::FLASH_SALE, 'goods' => $activity],
'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
* @return ResponseInterface
*/
public function userIndex(UserIndexRequest $request)
{
$params = $request->validated();
$data['user'] = $this->userInfoService->detail($params['user_id']);
$data['user']['role'] = '商家';
$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);
}
/**
* 商家入口详情
*/
public function storeIndex()
{
$data['detail'] = $this->storeInfoService->detail();
$data['order_online'] = [
'count' => 6549,
'total' => 12654.12
];
$data['order_offline'] = [
'count' => 3639,
'total' => 89563.12
];
$data['new_user'] = [
'day' => 10,
'week' => 15,
'month' => 25,
'all' => 50
];
$data['badge'] = [
'unpaid' => 0,
'receiving' => 0,
'completed' => 0,
'refund' => 0,
];
return $this->success($data);
}
}