Data.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types = 1);
  12. namespace app\store\controller\statistics;
  13. use app\store\controller\Controller;
  14. use app\store\service\statistics\Data as StatisticsDataService;
  15. /**
  16. * 数据概况
  17. * Class Data
  18. * @package app\store\controller\statistics
  19. */
  20. class Data extends Controller
  21. {
  22. // 数据概况服务类
  23. /* @var $service StatisticsDataService */
  24. private $service;
  25. /**
  26. * 构造方法
  27. * @throws \app\common\exception\BaseException
  28. * @throws \think\db\exception\DataNotFoundException
  29. * @throws \think\db\exception\DbException
  30. * @throws \think\db\exception\ModelNotFoundException
  31. */
  32. public function initialize()
  33. {
  34. parent::initialize();
  35. // 实例化数据概况服务类
  36. $this->service = new StatisticsDataService;
  37. }
  38. /**
  39. * 数据统计主页
  40. * @return array
  41. * @throws \think\db\exception\DataNotFoundException
  42. * @throws \think\db\exception\DbException
  43. * @throws \think\db\exception\ModelNotFoundException
  44. */
  45. public function data()
  46. {
  47. // 获取数据
  48. $data = [
  49. // 数据概况
  50. 'overview' => $this->service->getSurveyData(),
  51. // 近七日交易走势
  52. 'tradeTrend' => $this->service->getTransactionTrend(),
  53. // 商品销售榜
  54. 'goodsRanking' => $this->service->getGoodsRanking(),
  55. // 用户消费榜
  56. 'userExpendRanking' => $this->service->geUserExpendRanking(),
  57. ];
  58. return $this->renderSuccess(compact('data'));
  59. }
  60. /**
  61. * 数据概况API
  62. * @param null $startDate
  63. * @param null $endDate
  64. * @return array
  65. */
  66. public function survey($startDate = null, $endDate = null)
  67. {
  68. // 获取数据概况
  69. $data = $this->service->getSurveyData($startDate, $endDate);
  70. return $this->renderSuccess($data);
  71. }
  72. }