UserStatistic.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\admin\v1\statistic;
  12. use app\controller\admin\AuthController;
  13. use app\services\statistic\UserStatisticServices;
  14. use think\facade\App;
  15. /**
  16. * Class UserStatistic
  17. * @package app\controller\admin\v1\statistic
  18. */
  19. class UserStatistic extends AuthController
  20. {
  21. /**
  22. * UserStatistic constructor.
  23. * @param App $app
  24. * @param UserStatisticServices $services
  25. */
  26. public function __construct(App $app, UserStatisticServices $services)
  27. {
  28. parent::__construct($app);
  29. $this->services = $services;
  30. }
  31. /**
  32. * 用户基础信息
  33. * @return mixed
  34. */
  35. public function getBasic()
  36. {
  37. $where = $this->request->getMore([
  38. ['channel_type', ''],
  39. ['data', '', '', 'time']
  40. ]);
  41. $where['time'] = $this->getDay($where['time']);
  42. return $this->success($this->services->getBasic($where));
  43. }
  44. /**
  45. * 用户趋势
  46. * @return mixed
  47. */
  48. public function getTrend()
  49. {
  50. $where = $this->request->getMore([
  51. ['channel_type', ''],
  52. ['data', '', '', 'time']
  53. ]);
  54. $where['time'] = $this->getDay($where['time']);
  55. return $this->success($this->services->getTrend($where));
  56. }
  57. /**
  58. * 微信用户信息
  59. * @return mixed
  60. */
  61. public function getWechat()
  62. {
  63. $where = $this->request->getMore([
  64. ['channel_type', ''],
  65. ['data', '', '', 'time']
  66. ]);
  67. $where['time'] = $this->getDay($where['time']);
  68. return $this->success($this->services->getWechat($where));
  69. }
  70. /**
  71. * 微信用户趋势
  72. * @return mixed
  73. */
  74. public function getWechatTrend()
  75. {
  76. $where = $this->request->getMore([
  77. ['channel_type', ''],
  78. ['data', '', '', 'time']
  79. ]);
  80. $where['time'] = $this->getDay($where['time']);
  81. return $this->success($this->services->getWechatTrend($where));
  82. }
  83. /**
  84. * 用户地域
  85. * @return mixed
  86. */
  87. public function getRegion()
  88. {
  89. $where = $this->request->getMore([
  90. ['channel_type', ''],
  91. ['data', '', '', 'time'],
  92. ['sort', 'allNum']
  93. ]);
  94. $where['time'] = $this->getDay($where['time']);
  95. return $this->success($this->services->getRegionV1($where));
  96. }
  97. /**
  98. * 用户性别
  99. * @return mixed
  100. */
  101. public function getSex()
  102. {
  103. $where = $this->request->getMore([
  104. ['channel_type', ''],
  105. ['data', '', '', 'time']
  106. ]);
  107. $where['time'] = $this->getDay($where['time']);
  108. return $this->success($this->services->getSex($where));
  109. }
  110. /**
  111. * 用户统计导出
  112. * @return mixed
  113. */
  114. public function getExcel()
  115. {
  116. $where = $this->request->getMore([
  117. ['channel_type', ''],
  118. ['data', '', '', 'time']
  119. ]);
  120. $where['time'] = $this->getDay($where['time']);
  121. return $this->success($this->services->getTrend($where, true));
  122. }
  123. /**
  124. * 格式化时间
  125. * @param $time
  126. * @return string
  127. */
  128. public function getDay($time)
  129. {
  130. if (strstr($time, '-') !== false) {
  131. [$startTime, $endTime] = explode('-', $time);
  132. if (!$startTime && !$endTime) {
  133. return date("Y/m/d", strtotime("-30 days", time())) . '-' . date("Y/m/d", time());
  134. } else {
  135. return $startTime . '-' . $endTime;
  136. }
  137. } else {
  138. return date("Y/m/d", strtotime("-30 days", time())) . '-' . date("Y/m/d", time());
  139. }
  140. }
  141. }