Data.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace app\store\controller\statistics;
  3. use app\store\controller\Controller;
  4. use app\store\service\statistics\Data as StatisticsDataService;
  5. /**
  6. * 数据概况
  7. * Class Data
  8. * @package app\store\controller\statistics
  9. */
  10. class Data extends Controller
  11. {
  12. /* @var $statisticsDataService StatisticsDataService 数据概况服务类 */
  13. private $statisticsDataService;
  14. /**
  15. * 构造方法
  16. * @throws \app\common\exception\BaseException
  17. * @throws \think\db\exception\DataNotFoundException
  18. * @throws \think\db\exception\ModelNotFoundException
  19. * @throws \think\exception\DbException
  20. */
  21. public function _initialize()
  22. {
  23. parent::_initialize();
  24. $this->statisticsDataService = new StatisticsDataService;
  25. }
  26. /**
  27. * 数据统计主页
  28. * @return mixed
  29. * @throws \think\Exception
  30. */
  31. public function index()
  32. {
  33. return $this->fetch('index', [
  34. // 数据概况
  35. 'survey' => $this->statisticsDataService->getSurveyData(),
  36. // 近七日交易走势
  37. 'echarts7days' => $this->statisticsDataService->getTransactionTrend(),
  38. // 商品销售榜
  39. 'goodsRanking' => $this->statisticsDataService->getGoodsRanking(),
  40. // 用户消费榜
  41. 'userExpendRanking' => $this->statisticsDataService->geUserExpendRanking(),
  42. ]);
  43. }
  44. /**
  45. * 数据概况API
  46. * @param null $startDate
  47. * @param null $endDate
  48. * @return array
  49. * @throws \think\Exception
  50. */
  51. public function survey($startDate = null, $endDate = null)
  52. {
  53. return $this->renderSuccess('', '',
  54. $this->statisticsDataService->getSurveyData($startDate, $endDate));
  55. }
  56. }