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.
338 lines
11 KiB
338 lines
11 KiB
<?php
|
|
|
|
namespace App\Controller\v3;
|
|
|
|
use App\Constants\v3\ActivityType;
|
|
use App\Constants\v3\Banner;
|
|
use App\Constants\v3\OrderState;
|
|
use App\Constants\v3\OrderType;
|
|
use App\Constants\v3\SsdbKeys;
|
|
use App\Constants\v3\Tabs;
|
|
use App\Constants\v3\UserType;
|
|
use App\Controller\BaseController;
|
|
use App\Model\v3\FinancialRecord;
|
|
use App\Model\v3\Market;
|
|
use App\Model\v3\Store;
|
|
use App\Request\v3\StoreIndexRequest;
|
|
use App\Request\v3\UserIndexRequest;
|
|
use App\Service\v3\Interfaces\ActivityServiceInterface;
|
|
use App\Service\v3\Interfaces\BadgeServiceInterface;
|
|
use App\Service\v3\Interfaces\BannerServiceInterface;
|
|
use App\Service\v3\Interfaces\CategoryServiceInterface;
|
|
use App\Service\v3\Interfaces\CollectStoreServiceInterface;
|
|
use App\Service\v3\Interfaces\CouponRecServiceInterface;
|
|
use App\Service\v3\Interfaces\FinancialRecordServiceInterface;
|
|
use App\Service\v3\Interfaces\OrderOnlineServiceInterface;
|
|
use App\Service\v3\Interfaces\OrderStatisticsServiceInterface;
|
|
use App\Service\v3\Interfaces\RevenueListServiceInterface;
|
|
use App\Service\v3\Interfaces\ShareInfoServiceInterface;
|
|
use App\Service\v3\Interfaces\StoreServiceInterface;
|
|
use App\Service\v3\Interfaces\TabsServiceInterface;
|
|
use App\Service\v3\Interfaces\UserCenterBlockServiceInterface;
|
|
use App\Service\v3\Interfaces\UserInfoServiceInterface;
|
|
use App\TaskWorker\SSDBTask;
|
|
use EasyWeChat\Factory;
|
|
use Hyperf\Di\Annotation\Inject;
|
|
use Hyperf\Guzzle\CoroutineHandler;
|
|
use Hyperf\Redis\Redis;
|
|
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 CouponRecServiceInterface
|
|
*/
|
|
protected $couponRecService;
|
|
|
|
/**
|
|
* @Inject
|
|
* @var UserCenterBlockServiceInterface
|
|
*/
|
|
protected $userCenterBlockService;
|
|
|
|
/**
|
|
* @Inject
|
|
* @var StoreServiceInterface
|
|
*/
|
|
protected $storeService;
|
|
|
|
/**
|
|
* @Inject
|
|
* @var BannerServiceInterface
|
|
*/
|
|
protected $bannerService;
|
|
|
|
/**
|
|
* @Inject
|
|
* @var CategoryServiceInterface
|
|
*/
|
|
protected $categoryService;
|
|
|
|
/**
|
|
* @Inject
|
|
* @var ActivityServiceInterface
|
|
*/
|
|
protected $activityService;
|
|
|
|
/**
|
|
* @Inject
|
|
* @var TabsServiceInterface
|
|
*/
|
|
protected $tabsService;
|
|
|
|
/**
|
|
* @Inject
|
|
* @var OrderStatisticsServiceInterface
|
|
*/
|
|
protected $orderStatisticsService;
|
|
|
|
/**
|
|
* @Inject
|
|
* @var RevenueListServiceInterface
|
|
*/
|
|
protected $revenueListService;
|
|
|
|
/**
|
|
* @Inject
|
|
* @var BadgeServiceInterface
|
|
*/
|
|
protected $badgeService;
|
|
|
|
/**
|
|
* @Inject
|
|
* @var FinancialRecordServiceInterface
|
|
*/
|
|
protected $financialRecordService;
|
|
|
|
/**
|
|
* @Inject
|
|
* @var ShareInfoServiceInterface
|
|
*/
|
|
protected $shareInfoService;
|
|
|
|
/**
|
|
* 小程序首页,根据market_id
|
|
* 1.banner数据
|
|
* 2.一级分类
|
|
* 3.活动数据(秒杀、团购、新品、无)
|
|
* 4.tabs数据
|
|
*/
|
|
public function appletIndex()
|
|
{
|
|
$marketId = $this->request->input('market_id', -1);
|
|
$version = $this->request->input('version', -1);
|
|
$banners = $this->bannerService->all(Banner::TYPE_APPLET_INDEX, $marketId);
|
|
$categories = $this->categoryService->allForAppletIndex();
|
|
// $activity = $this->activityService->allForAppletIndex(env('APPLET_INDEX_ACTIVITY_TYPE'), $marketId);
|
|
$activity = $this->activityService->allSpecialForAppletIndex($marketId);
|
|
$tabs = $this->tabsService->allForAppletIndex($version);
|
|
$shareInfo = $this->shareInfoService->getForApplet();
|
|
|
|
return $this->success([
|
|
'banners' => $banners,
|
|
'categories' => $categories,
|
|
// 'activity' => ['type' => ActivityType::FLASH_SALE, 'goods' => $activity],
|
|
'activity' => $activity,
|
|
'tabs' => $tabs,
|
|
'share_info' => $shareInfo,
|
|
]);
|
|
|
|
}
|
|
|
|
/**
|
|
* 用户首页,我的页面
|
|
* 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']);
|
|
$store_info = $this->userInfoService->getStoreByUID($params['user_id']);
|
|
$employees = $this->userInfoService->getEmployeesByUID($params['user_id']);
|
|
|
|
$data['user']['store_info'] = $store_info;
|
|
$data['user']['sp_info'] = $employees;
|
|
|
|
|
|
$roles = [];
|
|
//角色判断
|
|
if($store_info){
|
|
$roles[] = [
|
|
'key'=>'store',
|
|
'title'=>'商家',
|
|
'color'=>'#0091FF',
|
|
'data'=>$store_info,
|
|
];
|
|
}
|
|
|
|
if($employees){
|
|
$roles[] = [
|
|
'key'=>'sp',
|
|
'title'=>'服务',
|
|
'color'=>'#0091FF',
|
|
'data'=>$employees,
|
|
];
|
|
}
|
|
|
|
$data['user']['collection_count'] = $this->collectStoreService->countByUser($params['user_id']);
|
|
$couponStatistics = $this->couponRecService->statistics($params['user_id']);
|
|
$data['user']['coupon_count'] = $couponStatistics['unused'];
|
|
$data['user']['role'] = $roles;
|
|
|
|
$data['badge'] = $this->badgeService->allByUserOrder($params['user_id']);
|
|
|
|
$data['block'] = $this->userCenterBlockService->all($roles);
|
|
|
|
// 返回用户是否已经关注公众号和查看时候跳转的文章地址
|
|
$config = config('wechat.official');
|
|
$app = Factory::officialAccount(['app_id' => $config['app_id'], 'secret' => $config['app_secret']]);
|
|
$app['guzzle_handler'] = CoroutineHandler::class;
|
|
$fansInfo = $app->user->get($data['user']['openid']);
|
|
|
|
$redis = ApplicationContext::getContainer()->get(Redis::class);
|
|
if ($fansInfo['subscribe'] == 1) {
|
|
$subscribeInfo = $redis->hGet('official:subscribe_info', 'subscribed');
|
|
} else {
|
|
$subscribeInfo = $redis->hGet('official:subscribe_info', 'not_subscribed');
|
|
}
|
|
|
|
$subscribeInfo = !empty($subscribeInfo) ? json_decode($subscribeInfo, true) : [];
|
|
$data['subscribe_info'] = array_merge($fansInfo, $subscribeInfo);
|
|
|
|
return $this->success($data);
|
|
}
|
|
|
|
/**
|
|
* 商家入口详情
|
|
*/
|
|
|
|
public function storeIndex(StoreIndexRequest $request)
|
|
{
|
|
$params = $request->validated();
|
|
$userId = Store::query()->where('id',$params['store_id'])->value('user_id');
|
|
//每日 每周 每月 开始结束时间
|
|
$dayStartTime = strtotime(date('Y-m-d'.' 00:00:00'));
|
|
$dayEndTime = strtotime(date('Y-m-d'.' 23:59:59'));
|
|
$weekStartTime = mktime(0,0,0,date('m'),date('d')-date('N')+1,date('y'));
|
|
//$weekEndTime = mktime(23,59,59,date('m'),date('d')-date('N')+7,date('Y'));
|
|
$monthStartTime = mktime(0,0,0,date('m'),1,date('Y'));
|
|
//$monthEndTime = mktime(23,59,59,date('m'),date('t'),date('Y'));
|
|
$data['detail'] = $this->storeService->detail($params['store_id']);
|
|
//当面付 and 线上订单个数统计
|
|
$data['order_online']['count'] = $this->orderStatisticsService->countOrder($params['store_id'],OrderType::ONLINE,$dayStartTime,$dayEndTime);
|
|
$data['order_offline']['count'] = $this->orderStatisticsService->countOrder($params['store_id'],OrderType::OFFLINE,$dayStartTime,$dayEndTime);
|
|
//统计订单金额
|
|
$type = [
|
|
FinancialRecord::MONEY_TYPE_STORE_OL_ORDER_COMP,
|
|
FinancialRecord::MONEY_TYPE_STORE_OFL_ORDER_COMP,
|
|
FinancialRecord::MONEY_TYPE_STORE_OL_ORDER_DIRECT_REFUND,
|
|
];
|
|
|
|
$sumAmounts = $this->financialRecordService->sumAmountGroup($userId, UserType::STORE, $type, $dayStartTime, $dayEndTime);
|
|
$data['order_online']['total'] = bcsub(
|
|
($sumAmounts[FinancialRecord::MONEY_TYPE_STORE_OL_ORDER_COMP]??'0'),
|
|
($sumAmounts[FinancialRecord::MONEY_TYPE_STORE_OL_ORDER_DIRECT_REFUND]??'0'),
|
|
2
|
|
);
|
|
$data['order_offline']['total'] = bcadd(
|
|
($sumAmounts[FinancialRecord::MONEY_TYPE_STORE_OFL_ORDER_COMP]??'0'),
|
|
'0',
|
|
2
|
|
);
|
|
// $revenueByOrder = $this->revenueListService->getRevenueByUser($userId,$type,$dayStartTime,$dayEndTime);
|
|
// foreach ($revenueByOrder as $order){
|
|
// if($order['money_type'] == FinancialRecord::MONEY_TYPE_STORE_OL_ORDER_COMP){
|
|
// //线上订单
|
|
// $data['order_online']['total'] = bcadd($data['order_online']['total'],$order['money'],2);
|
|
// }else if($order['money_type'] == FinancialRecord::MONEY_TYPE_STORE_OFL_ORDER_COMP){
|
|
// //线下订单
|
|
// $data['order_offline']['total'] = bcadd($data['order_offline']['total'],$order['money'],2);
|
|
// }
|
|
// }
|
|
//统计新增用户 无法筛选时间 所以和订单分开查询
|
|
$revenueByNewUsers = $this->revenueListService->getRevenueByUser($userId,[FinancialRecord::MONEY_TYPE_STORE_PLAT_NEW_USER]);
|
|
$data['new_user'] = [
|
|
'day' => 0,
|
|
'week' => 0,
|
|
'month' => 0,
|
|
'all' => 0
|
|
];
|
|
foreach ($revenueByNewUsers as $newUser)
|
|
{
|
|
if($newUser['created_at'] > $dayStartTime){
|
|
$data['new_user']['day']++;
|
|
}
|
|
if($newUser['created_at'] > $weekStartTime){
|
|
$data['new_user']['week']++;
|
|
}
|
|
if($newUser['created_at'] > $monthStartTime){
|
|
$data['new_user']['month']++;
|
|
}
|
|
$data['new_user']['all']++;
|
|
}
|
|
|
|
$data['badge'] = $this->badgeService->allByStoreOrder($params['store_id']);
|
|
|
|
return $this->success($data);
|
|
}
|
|
|
|
/**
|
|
* 关于懒族
|
|
* about lanzu
|
|
*/
|
|
public function aboutLanzu()
|
|
{
|
|
$data = [
|
|
[
|
|
'id' => 1,
|
|
'title' => '关于懒族',
|
|
'sub_title' => '懒族生活678',
|
|
'path' => 'https://mp.weixin.qq.com/s/tGKIILpL2extoeKXgYNYIA',
|
|
'path_type' => 'webview'
|
|
],
|
|
[
|
|
'id' => 1,
|
|
'title' => '隐私政策',
|
|
'sub_title' => '隐私政策123',
|
|
'path' => 'https://mp.weixin.qq.com/s/HQbJyUJVUYYMIJrHOZNbpA',
|
|
'path_type' => 'webview'
|
|
]
|
|
];
|
|
|
|
return $this->success(['data' => $data]);
|
|
}
|
|
|
|
/**
|
|
* 市场
|
|
*/
|
|
public function marketInfo()
|
|
{
|
|
$marketId = $this->request->input('market_id', 0);
|
|
return $this->success(['market' => Market::query()->find($marketId)]);
|
|
}
|
|
}
|