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.

319 lines
10 KiB

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