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.

275 lines
8.6 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. <?php
  2. namespace App\Controller\v3;
  3. use App\Constants\v3\ActivityType;
  4. use App\Constants\v3\Banner;
  5. use App\Constants\v3\OrderState;
  6. use App\Constants\v3\OrderType;
  7. use App\Constants\v3\SsdbKeys;
  8. use App\Constants\v3\Tabs;
  9. use App\Controller\BaseController;
  10. use App\Model\v3\FinancialRecord;
  11. use App\Request\v3\StoreIndexRequest;
  12. use App\Request\v3\UserIndexRequest;
  13. use App\Service\v3\Interfaces\ActivityServiceInterface;
  14. use App\Service\v3\Interfaces\BadgeServiceInterface;
  15. use App\Service\v3\Interfaces\BannerServiceInterface;
  16. use App\Service\v3\Interfaces\CategoryServiceInterface;
  17. use App\Service\v3\Interfaces\CollectStoreServiceInterface;
  18. use App\Service\v3\Interfaces\CouponServiceInterface;
  19. use App\Service\v3\Interfaces\OrderOnlineServiceInterface;
  20. use App\Service\v3\Interfaces\OrderStatisticsServiceInterface;
  21. use App\Service\v3\Interfaces\RevenueListServiceInterface;
  22. use App\Service\v3\Interfaces\StoreServiceInterface;
  23. use App\Service\v3\Interfaces\TabsServiceInterface;
  24. use App\Service\v3\Interfaces\UserCenterBlockServiceInterface;
  25. use App\Service\v3\Interfaces\UserInfoServiceInterface;
  26. use App\TaskWorker\SSDBTask;
  27. use Hyperf\Di\Annotation\Inject;
  28. use Hyperf\Redis\Redis;
  29. use Hyperf\Utils\ApplicationContext;
  30. use Psr\Http\Message\ResponseInterface;
  31. /**
  32. * 首页相关
  33. * Class HomeController
  34. * @package App\Controller\v3
  35. */
  36. class HomeController extends BaseController
  37. {
  38. /**
  39. * @Inject
  40. * @var UserInfoServiceInterface
  41. */
  42. protected $userInfoService;
  43. /**
  44. * @Inject
  45. * @var CollectStoreServiceInterface
  46. */
  47. protected $collectStoreService;
  48. /**
  49. * @Inject
  50. * @var CouponServiceInterface
  51. */
  52. protected $couponService;
  53. /**
  54. * @Inject
  55. * @var UserCenterBlockServiceInterface
  56. */
  57. protected $userCenterBlockService;
  58. /**
  59. * @Inject
  60. * @var StoreServiceInterface
  61. */
  62. protected $storeService;
  63. /**
  64. * @Inject
  65. * @var BannerServiceInterface
  66. */
  67. protected $bannerService;
  68. /**
  69. * @Inject
  70. * @var CategoryServiceInterface
  71. */
  72. protected $categoryService;
  73. /**
  74. * @Inject
  75. * @var ActivityServiceInterface
  76. */
  77. protected $activityService;
  78. /**
  79. * @Inject
  80. * @var TabsServiceInterface
  81. */
  82. protected $tabsService;
  83. /**
  84. * @Inject
  85. * @var OrderStatisticsServiceInterface
  86. */
  87. protected $orderStatisticsService;
  88. /**
  89. * @Inject
  90. * @var RevenueListServiceInterface
  91. */
  92. protected $revenueListService;
  93. /**
  94. * @Inject
  95. * @var BadgeServiceInterface
  96. */
  97. protected $badgeService;
  98. /**
  99. * 小程序首页,根据market_id
  100. * 1.banner数据
  101. * 2.一级分类
  102. * 3.活动数据(秒杀、团购、新品、无)
  103. * 4.tabs数据
  104. */
  105. public function appletIndex()
  106. {
  107. $marketId = $this->request->input('market_id', -1);
  108. $banners = $this->bannerService->all(Banner::TYPE_APPLET_INDEX, $marketId);
  109. $categories = $this->categoryService->allForAppletIndex();
  110. $activity = $this->activityService->allForAppletIndex(env('APPLET_INDEX_ACTIVITY_TYPE'), $marketId);
  111. $tabs = $this->tabsService->allForAppletIndex();
  112. return $this->success([
  113. 'banners' => $banners,
  114. 'categories' => $categories,
  115. 'activity' => ['type' => ActivityType::FLASH_SALE, 'goods' => $activity],
  116. 'tabs' => $tabs,
  117. ]);
  118. }
  119. /**
  120. * 用户首页,我的页面
  121. * 1、用户信息,id、昵称、名字、头像
  122. * 2、收藏、红包、积分
  123. * 3、badge角标,待付款、待收货、已完成、售后, SSDB维护
  124. * 4、为你推荐的商品列表
  125. * @param UserIndexRequest $request
  126. * @return ResponseInterface
  127. */
  128. public function userIndex(UserIndexRequest $request)
  129. {
  130. $params = $request->validated();
  131. $data['user'] = $this->userInfoService->detail($params['user_id']);
  132. $store_info = $this->userInfoService->getStoreByUID($params['user_id']);
  133. $sp_info = $this->userInfoService->getServicePersonnelByUID($params['user_id']);
  134. $data['user']['store_info'] = $store_info;
  135. $data['user']['sp_info'] = $sp_info;
  136. $roles = [];
  137. //角色判断
  138. if($store_info){
  139. $roles[] = [
  140. 'key'=>'store',
  141. 'title'=>'商家',
  142. 'color'=>'#0091FF',
  143. 'data'=>$store_info,
  144. ];
  145. }
  146. if($sp_info){
  147. $roles[] = [
  148. 'key'=>'sp',
  149. 'title'=>'服务',
  150. 'color'=>'#0091FF',
  151. 'data'=>$sp_info,
  152. ];
  153. }
  154. $data['user']['collection_count'] = $this->collectStoreService->countByUser($params['user_id']);
  155. $data['user']['coupon_count'] = $this->couponService->countAvailableByUser($params['user_id']);
  156. $data['user']['role'] = $roles;
  157. $data['badge'] = $this->badgeService->allByUserOrder($params['user_id']);
  158. $data['block'] = $this->userCenterBlockService->all($roles);
  159. return $this->success($data);
  160. }
  161. /**
  162. * 商家入口详情
  163. */
  164. public function storeIndex(StoreIndexRequest $request)
  165. {
  166. $params = $request->validated();
  167. //每日 每周 每月 开始结束时间
  168. $dayStartTime = strtotime(date('Y-m-d'.' 00:00:00'));
  169. $dayEndTime = strtotime(date('Y-m-d'.' 23:59:59'));
  170. $weekStartTime = mktime(0,0,0,date('m'),date('d')-date('N')+1,date('y'));
  171. //$weekEndTime = mktime(23,59,59,date('m'),date('d')-date('N')+7,date('Y'));
  172. $monthStartTime = mktime(0,0,0,date('m'),1,date('Y'));
  173. //$monthEndTime = mktime(23,59,59,date('m'),date('t'),date('Y'));
  174. $data['detail'] = $this->storeService->detail($params['store_id']);
  175. //当面付 and 线上订单个数统计
  176. $data['order_online']['count'] = $this->orderStatisticsService->countOrder($params['store_id'],OrderType::ONLINE,$dayStartTime,$dayEndTime);
  177. $data['order_offline']['count'] = $this->orderStatisticsService->countOrder($params['store_id'],OrderType::OFFLINE,$dayStartTime,$dayEndTime);
  178. //统计订单金额
  179. $type = [
  180. FinancialRecord::MONEY_TYPE_STORE_OL_ORDER_COMP,
  181. FinancialRecord::MONEY_TYPE_STORE_OFL_ORDER_COMP
  182. ];
  183. $data['order_online']['total'] = 0;
  184. $data['order_offline']['total'] = 0;
  185. $revenueByOrder = $this->revenueListService->getRevenueByUser($params['user_id'],$type,$dayStartTime,$dayEndTime);
  186. foreach ($revenueByOrder as $order){
  187. if($order['money_type'] == FinancialRecord::MONEY_TYPE_STORE_OL_ORDER_COMP){
  188. //线上订单
  189. $data['order_online']['total'] = bcadd($data['order_online']['total'],$order['money'],2);
  190. }else if($order->money_type == FinancialRecord::MONEY_TYPE_STORE_OFL_ORDER_COMP){
  191. //线下订单
  192. $data['order_offline']['total'] = bcadd($data['order_online']['total'],$order['money'],2);
  193. }
  194. }
  195. //统计新增用户 无法筛选时间 所以和订单分开查询
  196. $revenueByNewUsers = $this->revenueListService->getRevenueByUser($params['user_id'],[FinancialRecord::MONEY_TYPE_STORE_PLAT_NEW_USER]);
  197. $data['new_user'] = [
  198. 'day' => 0,
  199. 'week' => 0,
  200. 'month' => 0,
  201. 'all' => 0
  202. ];
  203. foreach ($revenueByNewUsers as $newUser)
  204. {
  205. if($newUser['created_at'] > $dayStartTime){
  206. $data['new_user']['day']++;
  207. }
  208. if($newUser['created_at'] > $weekStartTime){
  209. $data['new_user']['week']++;
  210. }
  211. if($newUser['created_at'] > $monthStartTime){
  212. $data['new_user']['month']++;
  213. }
  214. $data['new_user']['all']++;
  215. }
  216. $data['badge'] = $this->badgeService->allByStoreOrder($params['store_id']);
  217. return $this->success($data);
  218. }
  219. /**
  220. * 关于懒族
  221. * about lanzu
  222. */
  223. public function aboutLanzu()
  224. {
  225. $data = [
  226. [
  227. 'id' => 1,
  228. 'title' => '关于懒族',
  229. 'sub_title' => '懒族生活678',
  230. 'path' => 'https://www.baidu.com/s?wd=%E6%87%92%E6%97%8F%E7%94%9F%E6%B4%BB',
  231. 'path_type' => 'webview'
  232. ],
  233. [
  234. 'id' => 1,
  235. 'title' => '隐私政策',
  236. 'sub_title' => '隐私政策123',
  237. 'path' => 'https://www.baidu.com/s?wd=%E9%9A%90%E7%A7%81%E6%94%BF%E7%AD%96',
  238. 'path_type' => 'webview'
  239. ]
  240. ];
  241. return $this->success(['data' => $data]);
  242. }
  243. }