MonthlyGarments.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. use think\Request;
  6. class MonthlyGarments extends Api
  7. {
  8. protected $noNeedLogin = ['*'];
  9. protected $noNeedRight = ['*'];
  10. public function _initialize()
  11. {
  12. if (isset($_SERVER['HTTP_ORIGIN'])) {
  13. header('Access-Control-Expose-Headers: __token__');
  14. }
  15. check_cors_request();
  16. parent::_initialize();
  17. }
  18. /**
  19. * 样衣进度左侧数据
  20. */
  21. public function getDateTree()
  22. {
  23. if (!$this->request->isGet()) {
  24. $this->error('请求错误');
  25. }
  26. $results = \db('月度样衣进度')
  27. ->field([
  28. 'DATE_FORMAT(下单日期, "%Y-%m-%d")' => '日期',
  29. 'DATE_FORMAT(下单日期, "%Y-%m")' => '年月'
  30. ])
  31. ->whereNull('Mod_rq')
  32. ->whereNotNull('下单日期')
  33. ->order('下单日期 ASC')
  34. ->select();
  35. $formattedData = [];
  36. foreach ($results as $row) {
  37. $yearMonth = $row['年月'];
  38. $monthDay = $row['日期'];
  39. if (!isset($formattedData[$yearMonth])) {
  40. $formattedData[$yearMonth] = [];
  41. }
  42. if (!in_array($monthDay, $formattedData[$yearMonth])) {
  43. $formattedData[$yearMonth][] = $monthDay;
  44. }
  45. }
  46. krsort($formattedData);
  47. foreach ($formattedData as &$dates) {
  48. rsort($dates);
  49. }
  50. $this->success('成功', $formattedData);
  51. }
  52. }