ProductStatistic.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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\ProductStatisticServices;
  14. use think\facade\App;
  15. /**
  16. * Class ProductStatistic
  17. * @package app\adminapi\controller\v1\statistic
  18. */
  19. class ProductStatistic extends AuthController
  20. {
  21. /**
  22. * ProductStatistic constructor.
  23. * @param App $app
  24. * @param ProductStatisticServices $services
  25. */
  26. public function __construct(App $app, ProductStatisticServices $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. ['data', '', '', 'time']
  39. ]);
  40. return app('json')->success($this->services->getBasic($where));
  41. }
  42. /**
  43. * 商品趋势
  44. * @return mixed
  45. */
  46. public function getTrend()
  47. {
  48. $where = $this->request->getMore([
  49. ['data', '', '', 'time']
  50. ]);
  51. $where['time'] = $this->getDay($where['time']);
  52. return app('json')->success($this->services->getTrend($where));
  53. }
  54. /**
  55. * 商品排行
  56. * @return mixed
  57. */
  58. public function getProductRanking()
  59. {
  60. $where = $this->request->getMore([
  61. ['data', '', '', 'time'],
  62. ['sort', '']
  63. ]);
  64. $where['time'] = $this->getDay($where['time']);
  65. return app('json')->success($this->services->getProductRanking($where));
  66. }
  67. /**
  68. * 导出
  69. * @return mixed
  70. */
  71. public function getExcel()
  72. {
  73. $where = $this->request->getMore([
  74. ['data', '', '', 'time']
  75. ]);
  76. $where['time'] = $this->getDay($where['time']);
  77. return app('json')->success($this->services->getTrend($where, true));
  78. }
  79. /**
  80. * 格式化时间
  81. * @param $time
  82. * @return string
  83. */
  84. public function getDay($time)
  85. {
  86. if (strstr($time, '-') !== false) {
  87. [$startTime, $endTime] = explode('-', $time);
  88. if (!$startTime || !$endTime) {
  89. return date("Y/m/d 00:00:00", strtotime("-30 days", time())) . '-' . date("Y/m/d 23:59:59", time());
  90. } else {
  91. return date('Y/m/d 00:00:00', strtotime($startTime)).'-'.date('Y/m/d 23:59:59', strtotime($endTime));
  92. }
  93. } else {
  94. return date("Y/m/d 00:00:00", strtotime("-30 days", time())) . '-' . date("Y/m/d 23:59:59", time());
  95. }
  96. }
  97. }