orderChart.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. include_once dirname(__FILE__) . '/../main.php';
  3. $post = query_paras();
  4. $platform = $post["platform"];
  5. $startTime = $post["startTime"];
  6. $endTime = $post["endTime"];
  7. $endDate = strtotime("$endTime");
  8. $array = array();
  9. $labels = array();
  10. $totalPrize = 0;
  11. for ($i = 0; $i <= 399; $i++) {
  12. $iday = strtotime("$startTime +$i day");
  13. $day = date("Y-m-d", $iday);
  14. if ($iday > $endDate) {
  15. break;
  16. }
  17. if ($platform != "") {
  18. $prize = daoInst()->select('sum(`amount`) as amt')->from('tpl_order_tab')
  19. ->where('status')->eq(1)
  20. ->andWhere('channel')->eq($platform)
  21. ->andWhere('close_ts')->ge($iday)
  22. ->andWhere('close_ts')->lt(intval($iday + 86400))
  23. ->fetch('amt');
  24. } else {
  25. $prize = daoInst()->select('sum(`amount`) as amt')->from('tpl_order_tab')
  26. ->where('status')->eq(1)
  27. ->andWhere('close_ts')->ge($iday)
  28. ->andWhere('close_ts')->lt(intval($iday + 86400))
  29. ->fetch('amt');
  30. }
  31. $prize = ((int) $prize) / 100;
  32. $prize = (float) sprintf("%.2f", $prize);
  33. $array[] = $prize;
  34. $labels[] = $day;
  35. $totalPrize += $prize;
  36. }
  37. $result = new stdClass();
  38. $result->data = $array;
  39. $result->labels = $labels;
  40. $result->totalPrize = $totalPrize;
  41. echo json_encode($result);