From dd24ab48f68aaf2ed64f5ae86ac4124a7e23e3c9 Mon Sep 17 00:00:00 2001 From: liuyu <33367671@qq.com> Date: Wed, 3 Aug 2022 18:03:03 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E6=95=B0=E6=8D=AE=E6=B8=B2?= =?UTF-8?q?=E6=9F=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- control/index.php | 2 +- model/mOrder.php | 77 ++++++++++---- view/templates/index/home.html | 224 +++++++++++++++++++++++++---------------- 3 files changed, 192 insertions(+), 111 deletions(-) diff --git a/control/index.php b/control/index.php index 240a86c..f409f35 100644 --- a/control/index.php +++ b/control/index.php @@ -16,7 +16,7 @@ class index extends publicBase { $this->view['menu_page'] = 'home'; } - public function ajax_get_data() { + public function ajax_get_charts_data() { $shopinfo = $this->get_shopinfo(); $uid = $shopinfo['uid']; $shop_id = $shopinfo['id']; diff --git a/model/mOrder.php b/model/mOrder.php index e74a0a0..42333a8 100644 --- a/model/mOrder.php +++ b/model/mOrder.php @@ -301,24 +301,33 @@ class mOrder extends mBase { } public function getSumData($uid, $shop_id, $day=7) { - $default_date = date("Y-m-d"); + $end_time = date("Y-m-d").' 23:59:59'; + + $dates = array(); if ($day == 7) { - $week = $this->getWeekStartEndDate($default_date); - $start_time = $week['start'].' 00:00:00'; - $end_time = $week['end'].' 23:59:59'; + $start_time = date("Y-m-d", strtotime('-6 day')).' 00:00:00'; + + for ($i=0;$i<7;$i++) { + $dates[] = date("Y-m-d", strtotime('-'.$i.' day')); + } - $sql = 'select sum(`pay_amount`) as sumgroup,DATE_FORMAT(`pay_time`,"%Y-%m-%d") as dategroup from '.$this->order.' where `uid`='.$uid.' and `shop_id`='.$shop_id.' and `pay_time`>="'.$start_time.'" and `pay_time`<="'.$end_time.'" group by DATE_FORMAT(`pay_time`,"%Y-%m-%d")'; + $sql = 'select IFNULL(sum(`pay_amount`), 0) as sumgroup,DATE_FORMAT(`pay_time`,"%Y-%m-%d") as dategroup from '.$this->order.' where `uid`='.$uid.' and `shop_id`='.$shop_id.' and `pay_time`>="'.$start_time.'" and `pay_time`<="'.$end_time.'" group by DATE_FORMAT(`pay_time`,"%Y-%m-%d")'; } elseif ($day == 30) { - $start_time = date("Y-m-01").' 00:00:00'; - $end_time = date("Y-m-t").' 23:59:59'; + $start_time = date("Y-m-d", strtotime('-29 day')).' 00:00:00'; + for ($i=0;$i<29;$i++) { + $dates[] = date("Y-m-d", strtotime('-'.$i.' day')); + } $sql = 'select sum(`pay_amount`) as sumgroup,DATE_FORMAT(`pay_time`,"%Y-%m-%d") as dategroup from '.$this->order.' where `uid`='.$uid.' and `shop_id`='.$shop_id.' and `pay_time`>="'.$start_time.'" and `pay_time`<="'.$end_time.'" group by DATE_FORMAT(`pay_time`,"%Y-%m-%d")'; } elseif ($day == 365) { - $start_time = date("Y-01-01").' 00:00:00'; - $end_time = date("Y-12-31").' 23:59:59'; + $start_time = date("Y-m-d", strtotime('-1 year')).' 00:00:00'; + + for ($i=0;$i<12;$i++) { + $dates[] = date("Y-m", strtotime('-'.$i.' month')); + } $sql = 'select sum(`pay_amount`) as sumgroup,DATE_FORMAT(`pay_time`,"%Y-%m") as dategroup from '.$this->order.' where `uid`='.$uid.' and `shop_id`='.$shop_id.' and `pay_time`>="'.$start_time.'" and `pay_time`<="'.$end_time.'" group by DATE_FORMAT(`pay_time`,"%Y-%m")'; @@ -328,49 +337,73 @@ class mOrder extends mBase { if (!$res) return array(); $date2sum = array(); - foreach ($res[0] as $info) { + foreach ($res as $info) { $date2sum[$info['dategroup']] = $info['sumgroup']; } + $dates = array_reverse($dates); + + $data = array(); + foreach ($dates as $date) { + $data[$date] = $date2sum[$date] ? $date2sum[$date] : 0; + } + unset($res); + unset($date2sum); - return $date2sum; + return $data; } public function getRefundCountData($uid, $shop_id, $day=7) { - $default_date = date("Y-m-d"); + $end_time = date("Y-m-d").' 23:59:59'; + + $dates = array(); if ($day == 7) { - $week = $this->getWeekStartEndDate($default_date); - $start_time = $week['start'].' 00:00:00'; - $end_time = $week['end'].' 23:59:59'; + $start_time = date("Y-m-d", strtotime('-6 day')).' 00:00:00'; + + for ($i=0;$i<7;$i++) { + $dates[] = date("Y-m-d", strtotime('-'.$i.' day')); + } $sql = 'select count(*) as countgroup,DATE_FORMAT(`pay_time`,"%Y-%m-%d") as dategroup from '.$this->order.' where `uid`='.$uid.' and `shop_id`='.$shop_id.' and `refund_status` != '.REFUND_STATUS_NO_AFTER_SALES.' and `pay_time`>="'.$start_time.'" and `pay_time`<="'.$end_time.'" group by DATE_FORMAT(`pay_time`,"%Y-%m-%d")'; } elseif ($day == 30) { - $start_time = date("Y-m-01").' 00:00:00'; - $end_time = date("Y-m-t").' 23:59:59'; + $start_time = date("Y-m-d", strtotime('-29 day')).' 00:00:00'; + for ($i=0;$i<29;$i++) { + $dates[] = date("Y-m-d", strtotime('-'.$i.' day')); + } $sql = 'select count(*) as countgroup,DATE_FORMAT(`pay_time`,"%Y-%m-%d") as dategroup from '.$this->order.' where `uid`='.$uid.' and `shop_id`='.$shop_id.' and `refund_status` != '.REFUND_STATUS_NO_AFTER_SALES.' and `pay_time`>="'.$start_time.'" and `pay_time`<="'.$end_time.'" group by DATE_FORMAT(`pay_time`,"%Y-%m-%d")'; } elseif ($day == 365) { - $start_time = date("Y-01-01").' 00:00:00'; - $end_time = date("Y-12-31").' 23:59:59'; + $start_time = date("Y-m-d", strtotime('-1 year')).' 00:00:00'; - $sql = 'select count(*) as countgroup,DATE_FORMAT(`pay_time`,"%Y-%m") as dategroup from '.$this->order.' where `uid`='.$uid.' and `shop_id`='.$shop_id.' and `refund_status` != '.REFUND_STATUS_NO_AFTER_SALES.' and `pay_time`>="'.$start_time.'" and `pay_time`<="'.$end_time.'" group by DATE_FORMAT(`pay_time`,"%Y-%m")'; + for ($i=0;$i<12;$i++) { + $dates[] = date("Y-m", strtotime('-'.$i.' month')); + } + $sql = 'select count(*) as countgroup,DATE_FORMAT(`pay_time`,"%Y-%m") as dategroup from '.$this->order.' where `uid`='.$uid.' and `shop_id`='.$shop_id.' and `refund_status` != '.REFUND_STATUS_NO_AFTER_SALES.' and `pay_time`>="'.$start_time.'" and `pay_time`<="'.$end_time.'" group by DATE_FORMAT(`pay_time`,"%Y-%m")'; } $res = $this->obj->execute($sql, true, true); if (!$res) return array(); $date2count = array(); - foreach ($res[0] as $info) { + foreach ($res as $info) { $date2count[$info['dategroup']] = $info['countgroup']; } + $dates = array_reverse($dates); + + $data = array(); + foreach ($dates as $date) { + $data[$date] = $date2count[$date] ? $date2count[$date] : 0; + } + unset($res); + unset($date2count); - return $date2count; + return $data; } } \ No newline at end of file diff --git a/view/templates/index/home.html b/view/templates/index/home.html index 10773b1..1db13bb 100644 --- a/view/templates/index/home.html +++ b/view/templates/index/home.html @@ -36,21 +36,21 @@