UserStatistic.php 4.3 KB

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