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.

285 lines
8.9 KiB

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