Supplier.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace app\shop\controller\statistics;
  3. use app\shop\controller\Controller;
  4. use app\shop\service\statistics\SupplierService;
  5. /**
  6. * 供应商数据控制器
  7. */
  8. class Supplier extends Controller
  9. {
  10. /**
  11. * 会员数据统计
  12. */
  13. public function index()
  14. {
  15. return $this->renderSuccess('', [
  16. // 供应商统计
  17. 'supplier' => (new SupplierService())->getData(),
  18. ]);
  19. }
  20. /**
  21. * 通过时间段查询
  22. * $type类型:new refund
  23. */
  24. public function data($search_time)
  25. {
  26. $days = $this->getDays($search_time);
  27. $data = (new SupplierService())->getDataByDate($days);
  28. return $this->renderSuccess('', [
  29. // 日期
  30. 'days' => $days,
  31. // 数据
  32. 'data' => $data,
  33. ]);
  34. }
  35. /**
  36. * 获取具体日期数组
  37. */
  38. private function getDays($search_time)
  39. {
  40. //搜索时间段
  41. if(!isset($search_time) || empty($search_time)){
  42. //没有传,则默认为最近7天
  43. $end_time = date('Y-m-d', time());
  44. $start_time = date('Y-m-d', strtotime('-7 day',time()));
  45. }else{
  46. $start_time = array_shift($search_time);
  47. $end_time = array_pop($search_time);
  48. }
  49. $dt_start = strtotime($start_time);
  50. $dt_end = strtotime($end_time);
  51. $date = [];
  52. $date[] = date('Y-m-d', strtotime($start_time));
  53. while($dt_start < $dt_end) {
  54. $date[] = date('Y-m-d', strtotime('+1 day',$dt_start));
  55. $dt_start = strtotime('+1 day',$dt_start);
  56. }
  57. return $date;
  58. }
  59. }