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.

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