Data.php 1.9 KB

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