hrjy 2 years ago
parent
commit
e35bd96938
2 changed files with 250 additions and 251 deletions
  1. 199 200
      app/admin/controller/Index.php
  2. 51 51
      app/admin/view/index/main.php

+ 199 - 200
app/admin/controller/Index.php

@@ -2,6 +2,7 @@
 
 namespace app\admin\controller;
 
+use app\admin\model\water\WaterQuery;
 use FormBuilder\Json;
 use think\facade\Config;
 use app\admin\model\order\StoreOrder as StoreOrderModel;//订单
@@ -155,12 +156,12 @@ class Index extends AuthController
                 for ($i = -30; $i < 0; $i++) {
                     $datalist[date('m-d', strtotime($i . ' day'))] = date('m-d', strtotime($i . ' day'));
                 }
-                $order_list = StoreOrderModel::where('add_time', 'between time', [$datebefor, $dateafter])
-                    ->field("FROM_UNIXTIME(add_time,'%m-%d') as day,count(*) as count,sum(pay_price) as price")
-                    ->group("FROM_UNIXTIME(add_time, '%Y%m%d')")
-                    ->order('add_time asc')
+                $order_list = WaterQuery::where('create_time', 'between time', [$datebefor, $dateafter])
+                    ->field("FROM_UNIXTIME(create_time,'%m-%d') as day,count(*) as count")
+                    ->group("FROM_UNIXTIME(create_time, '%Y%m%d')")
+                    ->order('create_time asc')
                     ->select()->toArray();
-                if (empty($order_list)) return Json::fail('无数据');
+//                if (empty($order_list)) return Json::fail('无数据');
                 foreach ($order_list as $k => &$v) {
                     $order_list[$v['day']] = $v;
                 }
@@ -169,70 +170,67 @@ class Index extends AuthController
                     if (!empty($order_list[$dd])) {
                         $cycle_list[$dd] = $order_list[$dd];
                     } else {
-                        $cycle_list[$dd] = ['count' => 0, 'day' => $dd, 'price' => ''];
+                        $cycle_list[$dd] = ['count' => 0, 'day' => $dd];
                     }
                 }
                 $chartdata = [];
                 $data = [];//临时
                 $chartdata['yAxis']['maxnum'] = 0;//最大值数量
-                $chartdata['yAxis']['maxprice'] = 0;//最大值金额
                 foreach ($cycle_list as $k => $v) {
                     $data['day'][] = $v['day'];
                     $data['count'][] = $v['count'];
-                    $data['price'][] = round($v['price'], 2);
                     if ($chartdata['yAxis']['maxnum'] < $v['count'])
                         $chartdata['yAxis']['maxnum'] = $v['count'];//日最大订单数
-                    if ($chartdata['yAxis']['maxprice'] < $v['price'])
-                        $chartdata['yAxis']['maxprice'] = $v['price'];//日最大金额
                 }
-                $chartdata['legend'] = ['订单金额', '订单数'];//分类
+                $chartdata['legend'] = ['计算数'];//分类
                 $chartdata['xAxis'] = $data['day'];//X轴值
                 //,'itemStyle'=>$series
+
                 $series = ['normal' => ['label' => ['show' => true, 'position' => 'top']]];
-                $chartdata['series'][] = ['name' => $chartdata['legend'][0], 'type' => 'bar', 'itemStyle' => $series, 'data' => $data['price']];//分类1值
-                $chartdata['series'][] = ['name' => $chartdata['legend'][1], 'type' => 'bar', 'itemStyle' => $series, 'data' => $data['count']];//分类2值
-                //统计总数上期
-                $pre_total = StoreOrderModel::where('add_time', 'between time', [$pre_datebefor, $pre_dateafter])
-                    ->field("count(*) as count,sum(pay_price) as price")
-                    ->find();
-                if ($pre_total) {
-                    $chartdata['pre_cycle']['count'] = [
-                        'data' => $pre_total['count'] ?: 0
-                    ];
-                    $chartdata['pre_cycle']['price'] = [
-                        'data' => $pre_total['price'] ?: 0
-                    ];
-                }
-                //统计总数
-                $total = StoreOrderModel::where('add_time', 'between time', [$datebefor, $dateafter])
-                    ->field("count(*) as count,sum(pay_price) as price")
-                    ->find();
-                if ($total) {
-                    $cha_count = intval($pre_total['count']) - intval($total['count']);
-                    //$pre_total['count'] = $pre_total['count'] == 0 ? 1 : $pre_total['count'];
-                    $chartdata['cycle']['count'] = [
-                        'data' => $total['count'] ?: 0,
-                        'percent' => intval($pre_total['count']) == 0 ? 100 : round((abs($cha_count) / intval($pre_total['count']) * 100), 2),
-                        'is_plus' => $cha_count > 0 ? -1 : ($cha_count == 0 ? 0 : 1)
-                    ];
-                    $cha_price = round($pre_total['price'], 2) - round($total['price'], 2);
-                    //$pre_total['price'] = $pre_total['price'] == 0 ? 1 : $pre_total['price'];
-                    $chartdata['cycle']['price'] = [
-                        'data' => $total['price'] ?: 0,
-                        'percent' => (intval($pre_total['price']) == 0 || !$pre_total['price'] || $pre_total['price'] == 0.00) ? 100 : round(abs($cha_price) / $pre_total['price'] * 100, 2),
-                        'is_plus' => $cha_price > 0 ? -1 : ($cha_price == 0 ? 0 : 1)
-                    ];
-                }
+                $chartdata['series'][] = ['name' => $chartdata['legend'][0], 'type' => 'bar', 'itemStyle' => $series, 'data' => $data['count']];//分类1值
+//                //统计总数上期
+//                $pre_total = StoreOrderModel::where('add_time', 'between time', [$pre_datebefor, $pre_dateafter])
+//                    ->field("count(*) as count,sum(pay_price) as price")
+//                    ->find();
+//                if ($pre_total) {
+//                    $chartdata['pre_cycle']['count'] = [
+//                        'data' => $pre_total['count'] ?: 0
+//                    ];
+//                    $chartdata['pre_cycle']['price'] = [
+//                        'data' => $pre_total['price'] ?: 0
+//                    ];
+//                }
+//
+//                //统计总数
+//                $total = StoreOrderModel::where('add_time', 'between time', [$datebefor, $dateafter])
+//                    ->field("count(*) as count,sum(pay_price) as price")
+//                    ->find();
+//                if ($total) {
+//                    $cha_count = intval($pre_total['count']) - intval($total['count']);
+//                    //$pre_total['count'] = $pre_total['count'] == 0 ? 1 : $pre_total['count'];
+//                    $chartdata['cycle']['count'] = [
+//                        'data' => $total['count'] ?: 0,
+//                        'percent' => intval($pre_total['count']) == 0 ? 100 : round((abs($cha_count) / intval($pre_total['count']) * 100), 2),
+//                        'is_plus' => $cha_count > 0 ? -1 : ($cha_count == 0 ? 0 : 1)
+//                    ];
+//                    $cha_price = round($pre_total['price'], 2) - round($total['price'], 2);
+//                    //$pre_total['price'] = $pre_total['price'] == 0 ? 1 : $pre_total['price'];
+//                    $chartdata['cycle']['price'] = [
+//                        'data' => $total['price'] ?: 0,
+//                        'percent' => (intval($pre_total['price']) == 0 || !$pre_total['price'] || $pre_total['price'] == 0.00) ? 100 : round(abs($cha_price) / $pre_total['price'] * 100, 2),
+//                        'is_plus' => $cha_price > 0 ? -1 : ($cha_price == 0 ? 0 : 1)
+//                    ];
+//                }
                 return app('json')->success('ok', $chartdata);
                 break;
             case 'week':
                 $weekarray = array(['周日'], ['周一'], ['周二'], ['周三'], ['周四'], ['周五'], ['周六']);
                 $datebefor = date('Y-m-d', strtotime('-1 week Monday'));
                 $dateafter = date('Y-m-d', strtotime('-1 week Sunday'));
-                $order_list = StoreOrderModel::where('add_time', 'between time', [$datebefor, $dateafter])
-                    ->field("FROM_UNIXTIME(add_time,'%w') as day,count(*) as count,sum(pay_price) as price")
-                    ->group("FROM_UNIXTIME(add_time, '%Y%m%e')")
-                    ->order('add_time asc')
+                $order_list = WaterQuery::where('create_time', 'between time', [$datebefor, $dateafter])
+                    ->field("FROM_UNIXTIME(create_time,'%w') as day,count(*) as count")
+                    ->group("FROM_UNIXTIME(create_time, '%Y%m%d')")
+                    ->order('create_time asc')
                     ->select()->toArray();
                 //数据查询重新处理
                 $new_order_list = [];
@@ -241,10 +239,10 @@ class Index extends AuthController
                 }
                 $now_datebefor = date('Y-m-d', (time() - ((date('w') == 0 ? 7 : date('w')) - 1) * 24 * 3600));
                 $now_dateafter = date('Y-m-d', strtotime("+1 day"));
-                $now_order_list = StoreOrderModel::where('add_time', 'between time', [$now_datebefor, $now_dateafter])
-                    ->field("FROM_UNIXTIME(add_time,'%w') as day,count(*) as count,sum(pay_price) as price")
-                    ->group("FROM_UNIXTIME(add_time, '%Y%m%e')")
-                    ->order('add_time asc')
+                $now_order_list = WaterQuery::where('create_time', 'between time', [$now_datebefor, $now_dateafter])
+                    ->field("FROM_UNIXTIME(create_time,'%w') as day,count(*) as count")
+                    ->group("FROM_UNIXTIME(create_time, '%Y%m%d')")
+                    ->order('create_time asc')
                     ->select()->toArray();
                 //数据查询重新处理 key 变为当前值
                 $new_now_order_list = [];
@@ -255,12 +253,12 @@ class Index extends AuthController
                     if (!empty($new_order_list[$dk])) {
                         $weekarray[$dk]['pre'] = $new_order_list[$dk];
                     } else {
-                        $weekarray[$dk]['pre'] = ['count' => 0, 'day' => $weekarray[$dk][0], 'price' => '0'];
+                        $weekarray[$dk]['pre'] = ['count' => 0, 'day' => $weekarray[$dk][0]];
                     }
                     if (!empty($new_now_order_list[$dk])) {
                         $weekarray[$dk]['now'] = $new_now_order_list[$dk];
                     } else {
-                        $weekarray[$dk]['now'] = ['count' => 0, 'day' => $weekarray[$dk][0], 'price' => '0'];
+                        $weekarray[$dk]['now'] = ['count' => 0, 'day' => $weekarray[$dk][0]];
                     }
                 }
                 $chartdata = [];
@@ -270,57 +268,57 @@ class Index extends AuthController
                 foreach ($weekarray as $k => $v) {
                     $data['day'][] = $v[0];
                     $data['pre']['count'][] = $v['pre']['count'];
-                    $data['pre']['price'][] = round($v['pre']['price'], 2);
+//                    $data['pre']['price'][] = round($v['pre']['price'], 2);
                     $data['now']['count'][] = $v['now']['count'];
-                    $data['now']['price'][] = round($v['now']['price'], 2);
+//                    $data['now']['price'][] = round($v['now']['price'], 2);
                     if ($chartdata['yAxis']['maxnum'] < $v['pre']['count'] || $chartdata['yAxis']['maxnum'] < $v['now']['count']) {
                         $chartdata['yAxis']['maxnum'] = $v['pre']['count'] > $v['now']['count'] ? $v['pre']['count'] : $v['now']['count'];//日最大订单数
                     }
-                    if ($chartdata['yAxis']['maxprice'] < $v['pre']['price'] || $chartdata['yAxis']['maxprice'] < $v['now']['price']) {
-                        $chartdata['yAxis']['maxprice'] = $v['pre']['price'] > $v['now']['price'] ? $v['pre']['price'] : $v['now']['price'];//日最大金额
-                    }
+//                    if ($chartdata['yAxis']['maxprice'] < $v['pre']['price'] || $chartdata['yAxis']['maxprice'] < $v['now']['price']) {
+//                        $chartdata['yAxis']['maxprice'] = $v['pre']['price'] > $v['now']['price'] ? $v['pre']['price'] : $v['now']['price'];//日最大金额
+//                    }
                 }
-                $chartdata['legend'] = ['上周金额', '本周金额', '上周订单数', '本周订单数'];//分类
+                $chartdata['legend'] = ['本周订单数'];//分类
                 $chartdata['xAxis'] = $data['day'];//X轴值
                 //,'itemStyle'=>$series
                 $series = ['normal' => ['label' => ['show' => true, 'position' => 'top']]];
-                $chartdata['series'][] = ['name' => $chartdata['legend'][0], 'type' => 'bar', 'itemStyle' => $series, 'data' => $data['pre']['price']];//分类1值
-                $chartdata['series'][] = ['name' => $chartdata['legend'][1], 'type' => 'bar', 'itemStyle' => $series, 'data' => $data['now']['price']];//分类1值
-                $chartdata['series'][] = ['name' => $chartdata['legend'][2], 'type' => 'line', 'itemStyle' => $series, 'data' => $data['pre']['count']];//分类2值
-                $chartdata['series'][] = ['name' => $chartdata['legend'][3], 'type' => 'line', 'itemStyle' => $series, 'data' => $data['now']['count']];//分类2值
+//                $chartdata['series'][] = ['name' => $chartdata['legend'][0], 'type' => 'bar', 'itemStyle' => $series, 'data' => $data['pre']['price']];//分类1值
+//                $chartdata['series'][] = ['name' => $chartdata['legend'][1], 'type' => 'bar', 'itemStyle' => $series, 'data' => $data['now']['price']];//分类1值
+//                $chartdata['series'][] = ['name' => $chartdata['legend'][0], 'type' => 'line', 'itemStyle' => $series, 'data' => $data['pre']['count']];//分类2值
+                $chartdata['series'][] = ['name' => $chartdata['legend'][0], 'type' => 'line', 'itemStyle' => $series, 'data' => $data['now']['count']];//分类2值
 
-                //统计总数上期
-                $pre_total = StoreOrderModel::where('add_time', 'between time', [$datebefor, $dateafter])
-                    ->field("count(*) as count,sum(pay_price) as price")
-                    ->find();
-                if ($pre_total) {
-                    $chartdata['pre_cycle']['count'] = [
-                        'data' => $pre_total['count'] ?: 0
-                    ];
-                    $chartdata['pre_cycle']['price'] = [
-                        'data' => $pre_total['price'] ?: 0
-                    ];
-                }
-                //统计总数
-                $total = StoreOrderModel::where('add_time', 'between time', [$now_datebefor, $now_dateafter])
-                    ->field("count(*) as count,sum(pay_price) as price")
-                    ->find();
-                if ($total) {
-                    $cha_count = intval($pre_total['count']) - intval($total['count']);
-                    //$pre_total['count'] = $pre_total['count'] == 0 ? 1 : $pre_total['count'];
-                    $chartdata['cycle']['count'] = [
-                        'data' => $total['count'] ?: 0,
-                        'percent' => intval($pre_total['count']) == 0 ? 100 : round((abs($cha_count) / intval($pre_total['count']) * 100), 2),
-                        'is_plus' => $cha_count > 0 ? -1 : ($cha_count == 0 ? 0 : 1)
-                    ];
-                    $cha_price = round($pre_total['price'], 2) - round($total['price'], 2);
-                    //$pre_total['price'] = $pre_total['price'] == 0 ? 1 : $pre_total['price'];
-                    $chartdata['cycle']['price'] = [
-                        'data' => $total['price'] ?: 0,
-                        'percent' => (intval($pre_total['price']) == 0 || !$pre_total['price'] || $pre_total['price'] == 0.00) ? 100 : round(abs($cha_price) / $pre_total['price'] * 100, 2),
-                        'is_plus' => $cha_price > 0 ? -1 : ($cha_price == 0 ? 0 : 1)
-                    ];
-                }
+//                //统计总数上期
+//                $pre_total = StoreOrderModel::where('add_time', 'between time', [$datebefor, $dateafter])
+//                    ->field("count(*) as count,sum(pay_price) as price")
+//                    ->find();
+//                if ($pre_total) {
+//                    $chartdata['pre_cycle']['count'] = [
+//                        'data' => $pre_total['count'] ?: 0
+//                    ];
+//                    $chartdata['pre_cycle']['price'] = [
+//                        'data' => $pre_total['price'] ?: 0
+//                    ];
+//                }
+//                //统计总数
+//                $total = StoreOrderModel::where('add_time', 'between time', [$now_datebefor, $now_dateafter])
+//                    ->field("count(*) as count,sum(pay_price) as price")
+//                    ->find();
+//                if ($total) {
+//                    $cha_count = intval($pre_total['count']) - intval($total['count']);
+//                    //$pre_total['count'] = $pre_total['count'] == 0 ? 1 : $pre_total['count'];
+//                    $chartdata['cycle']['count'] = [
+//                        'data' => $total['count'] ?: 0,
+//                        'percent' => intval($pre_total['count']) == 0 ? 100 : round((abs($cha_count) / intval($pre_total['count']) * 100), 2),
+//                        'is_plus' => $cha_count > 0 ? -1 : ($cha_count == 0 ? 0 : 1)
+//                    ];
+//                    $cha_price = round($pre_total['price'], 2) - round($total['price'], 2);
+//                    //$pre_total['price'] = $pre_total['price'] == 0 ? 1 : $pre_total['price'];
+//                    $chartdata['cycle']['price'] = [
+//                        'data' => $total['price'] ?: 0,
+//                        'percent' => (intval($pre_total['price']) == 0 || !$pre_total['price'] || $pre_total['price'] == 0.00) ? 100 : round(abs($cha_price) / $pre_total['price'] * 100, 2),
+//                        'is_plus' => $cha_price > 0 ? -1 : ($cha_price == 0 ? 0 : 1)
+//                    ];
+//                }
                 return app('json')->success('ok', $chartdata);
                 break;
             case 'month':
@@ -328,10 +326,10 @@ class Index extends AuthController
 
                 $datebefor = date('Y-m-01', strtotime('-1 month'));
                 $dateafter = date('Y-m-d', strtotime(date('Y-m-01')));
-                $order_list = StoreOrderModel::where('add_time', 'between time', [$datebefor, $dateafter])
-                    ->field("FROM_UNIXTIME(add_time,'%d') as day,count(*) as count,sum(pay_price) as price")
-                    ->group("FROM_UNIXTIME(add_time, '%Y%m%e')")
-                    ->order('add_time asc')
+                $order_list = WaterQuery::where('create_time', 'between time', [$datebefor, $dateafter])
+                    ->field("FROM_UNIXTIME(create_time,'%d') as day,count(*) as count")
+                    ->group("FROM_UNIXTIME(create_time, '%Y%m%d')")
+                    ->order('create_time asc')
                     ->select()->toArray();
                 //数据查询重新处理
                 $new_order_list = [];
@@ -340,10 +338,10 @@ class Index extends AuthController
                 }
                 $now_datebefor = date('Y-m-01');
                 $now_dateafter = date('Y-m-d', strtotime("+1 day"));
-                $now_order_list = StoreOrderModel::where('add_time', 'between time', [$now_datebefor, $now_dateafter])
-                    ->field("FROM_UNIXTIME(add_time,'%d') as day,count(*) as count,sum(pay_price) as price")
-                    ->group("FROM_UNIXTIME(add_time, '%Y%m%e')")
-                    ->order('add_time asc')
+                $now_order_list = WaterQuery::where('create_time', 'between time', [$now_datebefor, $now_dateafter])
+                    ->field("FROM_UNIXTIME(create_time,'%d') as day,count(*) as count")
+                    ->group("FROM_UNIXTIME(create_time, '%Y%m%d')")
+                    ->order('create_time asc')
                     ->select()->toArray();
                 //数据查询重新处理 key 变为当前值
                 $new_now_order_list = [];
@@ -354,12 +352,12 @@ class Index extends AuthController
                     if (!empty($new_order_list[$dk])) {
                         $weekarray[$dk]['pre'] = $new_order_list[$dk];
                     } else {
-                        $weekarray[$dk]['pre'] = ['count' => 0, 'day' => $weekarray[$dk][0], 'price' => '0'];
+                        $weekarray[$dk]['pre'] = ['count' => 0, 'day' => $weekarray[$dk][0]];
                     }
                     if (!empty($new_now_order_list[$dk])) {
                         $weekarray[$dk]['now'] = $new_now_order_list[$dk];
                     } else {
-                        $weekarray[$dk]['now'] = ['count' => 0, 'day' => $weekarray[$dk][0], 'price' => '0'];
+                        $weekarray[$dk]['now'] = ['count' => 0, 'day' => $weekarray[$dk][0]];
                     }
                 }
                 $chartdata = [];
@@ -369,68 +367,68 @@ class Index extends AuthController
                 foreach ($weekarray as $k => $v) {
                     $data['day'][] = $v[0];
                     $data['pre']['count'][] = $v['pre']['count'];
-                    $data['pre']['price'][] = round($v['pre']['price'], 2);
+//                    $data['pre']['price'][] = round($v['pre']['price'], 2);
                     $data['now']['count'][] = $v['now']['count'];
-                    $data['now']['price'][] = round($v['now']['price'], 2);
+//                    $data['now']['price'][] = round($v['now']['price'], 2);
                     if ($chartdata['yAxis']['maxnum'] < $v['pre']['count'] || $chartdata['yAxis']['maxnum'] < $v['now']['count']) {
                         $chartdata['yAxis']['maxnum'] = $v['pre']['count'] > $v['now']['count'] ? $v['pre']['count'] : $v['now']['count'];//日最大订单数
                     }
-                    if ($chartdata['yAxis']['maxprice'] < $v['pre']['price'] || $chartdata['yAxis']['maxprice'] < $v['now']['price']) {
-                        $chartdata['yAxis']['maxprice'] = $v['pre']['price'] > $v['now']['price'] ? $v['pre']['price'] : $v['now']['price'];//日最大金额
-                    }
+//                    if ($chartdata['yAxis']['maxprice'] < $v['pre']['price'] || $chartdata['yAxis']['maxprice'] < $v['now']['price']) {
+//                        $chartdata['yAxis']['maxprice'] = $v['pre']['price'] > $v['now']['price'] ? $v['pre']['price'] : $v['now']['price'];//日最大金额
+//                    }
 
                 }
-                $chartdata['legend'] = ['上月金额', '本月金额', '上月订单数', '本月订单数'];//分类
+                $chartdata['legend'] = ['上月订单数', '本月订单数'];//分类
                 $chartdata['xAxis'] = $data['day'];//X轴值
                 //,'itemStyle'=>$series
                 $series = ['normal' => ['label' => ['show' => true, 'position' => 'top']]];
-                $chartdata['series'][] = ['name' => $chartdata['legend'][0], 'type' => 'bar', 'itemStyle' => $series, 'data' => $data['pre']['price']];//分类1值
-                $chartdata['series'][] = ['name' => $chartdata['legend'][1], 'type' => 'bar', 'itemStyle' => $series, 'data' => $data['now']['price']];//分类1值
-                $chartdata['series'][] = ['name' => $chartdata['legend'][2], 'type' => 'line', 'itemStyle' => $series, 'data' => $data['pre']['count']];//分类2值
-                $chartdata['series'][] = ['name' => $chartdata['legend'][3], 'type' => 'line', 'itemStyle' => $series, 'data' => $data['now']['count']];//分类2值
+//                $chartdata['series'][] = ['name' => $chartdata['legend'][0], 'type' => 'bar', 'itemStyle' => $series, 'data' => $data['pre']['price']];//分类1值
+//                $chartdata['series'][] = ['name' => $chartdata['legend'][1], 'type' => 'bar', 'itemStyle' => $series, 'data' => $data['now']['price']];//分类1值
+                $chartdata['series'][] = ['name' => $chartdata['legend'][0], 'type' => 'line', 'itemStyle' => $series, 'data' => $data['pre']['count']];//分类2值
+                $chartdata['series'][] = ['name' => $chartdata['legend'][1], 'type' => 'line', 'itemStyle' => $series, 'data' => $data['now']['count']];//分类2值
 
-                //统计总数上期
-                $pre_total = StoreOrderModel::where('add_time', 'between time', [$datebefor, $dateafter])
-                    ->field("count(*) as count,sum(pay_price) as price")
-                    ->find();
-                if ($pre_total) {
-                    $chartdata['pre_cycle']['count'] = [
-                        'data' => $pre_total['count'] ?: 0
-                    ];
-                    $chartdata['pre_cycle']['price'] = [
-                        'data' => $pre_total['price'] ?: 0
-                    ];
-                }
-                //统计总数
-                $total = StoreOrderModel::where('add_time', 'between time', [$now_datebefor, $now_dateafter])
-                    ->field("count(*) as count,sum(pay_price) as price")
-                    ->find();
-                if ($total) {
-                    $cha_count = intval($pre_total['count']) - intval($total['count']);
-                    //$pre_total['count'] = $pre_total['count'] == 0 ? 1 : $pre_total['count'];
-                    $chartdata['cycle']['count'] = [
-                        'data' => $total['count'] ?: 0,
-                        'percent' => intval($pre_total['count']) == 0 ? 100 : round((abs($cha_count) / intval($pre_total['count']) * 100), 2),
-                        'is_plus' => $cha_count > 0 ? -1 : ($cha_count == 0 ? 0 : 1)
-                    ];
-                    $cha_price = round($pre_total['price'], 2) - round($total['price'], 2);
-                    //$pre_total['price'] = $pre_total['price'] == 0 ? 1 : $pre_total['price'];
-                    $chartdata['cycle']['price'] = [
-                        'data' => $total['price'] ?: 0,
-                        'percent' => (intval($pre_total['price']) == 0 || !$pre_total['price'] || $pre_total['price'] == 0.00) ? 100 : round(abs($cha_price) / $pre_total['price'] * 100, 2),
-                        'is_plus' => $cha_price > 0 ? -1 : ($cha_price == 0 ? 0 : 1)
-                    ];
-                }
+//                //统计总数上期
+//                $pre_total = StoreOrderModel::where('add_time', 'between time', [$datebefor, $dateafter])
+//                    ->field("count(*) as count,sum(pay_price) as price")
+//                    ->find();
+//                if ($pre_total) {
+//                    $chartdata['pre_cycle']['count'] = [
+//                        'data' => $pre_total['count'] ?: 0
+//                    ];
+//                    $chartdata['pre_cycle']['price'] = [
+//                        'data' => $pre_total['price'] ?: 0
+//                    ];
+//                }
+//                //统计总数
+//                $total = StoreOrderModel::where('add_time', 'between time', [$now_datebefor, $now_dateafter])
+//                    ->field("count(*) as count,sum(pay_price) as price")
+//                    ->find();
+//                if ($total) {
+//                    $cha_count = intval($pre_total['count']) - intval($total['count']);
+//                    //$pre_total['count'] = $pre_total['count'] == 0 ? 1 : $pre_total['count'];
+//                    $chartdata['cycle']['count'] = [
+//                        'data' => $total['count'] ?: 0,
+//                        'percent' => intval($pre_total['count']) == 0 ? 100 : round((abs($cha_count) / intval($pre_total['count']) * 100), 2),
+//                        'is_plus' => $cha_count > 0 ? -1 : ($cha_count == 0 ? 0 : 1)
+//                    ];
+//                    $cha_price = round($pre_total['price'], 2) - round($total['price'], 2);
+//                    //$pre_total['price'] = $pre_total['price'] == 0 ? 1 : $pre_total['price'];
+//                    $chartdata['cycle']['price'] = [
+//                        'data' => $total['price'] ?: 0,
+//                        'percent' => (intval($pre_total['price']) == 0 || !$pre_total['price'] || $pre_total['price'] == 0.00) ? 100 : round(abs($cha_price) / $pre_total['price'] * 100, 2),
+//                        'is_plus' => $cha_price > 0 ? -1 : ($cha_price == 0 ? 0 : 1)
+//                    ];
+//                }
                 return app('json')->success('ok', $chartdata);
                 break;
             case 'year':
                 $weekarray = array('01' => ['一月'], '02' => ['二月'], '03' => ['三月'], '04' => ['四月'], '05' => ['五月'], '06' => ['六月'], '07' => ['七月'], '08' => ['八月'], '09' => ['九月'], '10' => ['十月'], '11' => ['十一月'], '12' => ['十二月']);
                 $datebefor = date('Y-01-01', strtotime('-1 year'));
                 $dateafter = date('Y-12-31', strtotime('-1 year'));
-                $order_list = StoreOrderModel::where('add_time', 'between time', [$datebefor, $dateafter])
-                    ->field("FROM_UNIXTIME(add_time,'%m') as day,count(*) as count,sum(pay_price) as price")
-                    ->group("FROM_UNIXTIME(add_time, '%Y%m')")
-                    ->order('add_time asc')
+                $order_list = WaterQuery::where('create_time', 'between time', [$datebefor, $dateafter])
+                    ->field("FROM_UNIXTIME(create_time,'%m') as day,count(*) as count")
+                    ->group("FROM_UNIXTIME(create_time, '%Y%m%d')")
+                    ->order('create_time asc')
                     ->select()->toArray();
                 //数据查询重新处理
                 $new_order_list = [];
@@ -439,10 +437,10 @@ class Index extends AuthController
                 }
                 $now_datebefor = date('Y-01-01');
                 $now_dateafter = date('Y-m-d');
-                $now_order_list = StoreOrderModel::where('add_time', 'between time', [$now_datebefor, $now_dateafter])
-                    ->field("FROM_UNIXTIME(add_time,'%m') as day,count(*) as count,sum(pay_price) as price")
-                    ->group("FROM_UNIXTIME(add_time, '%Y%m')")
-                    ->order('add_time asc')
+                $now_order_list = WaterQuery::where('create_time', 'between time', [$now_datebefor, $now_dateafter])
+                    ->field("FROM_UNIXTIME(create_time,'%m') as day,count(*) as count")
+                    ->group("FROM_UNIXTIME(create_time, '%Y%m%d')")
+                    ->order('create_time asc')
                     ->select()->toArray();
                 //数据查询重新处理 key 变为当前值
                 $new_now_order_list = [];
@@ -453,12 +451,12 @@ class Index extends AuthController
                     if (!empty($new_order_list[$dk])) {
                         $weekarray[$dk]['pre'] = $new_order_list[$dk];
                     } else {
-                        $weekarray[$dk]['pre'] = ['count' => 0, 'day' => $weekarray[$dk][0], 'price' => '0'];
+                        $weekarray[$dk]['pre'] = ['count' => 0, 'day' => $weekarray[$dk][0]];
                     }
                     if (!empty($new_now_order_list[$dk])) {
                         $weekarray[$dk]['now'] = $new_now_order_list[$dk];
                     } else {
-                        $weekarray[$dk]['now'] = ['count' => 0, 'day' => $weekarray[$dk][0], 'price' => '0'];
+                        $weekarray[$dk]['now'] = ['count' => 0, 'day' => $weekarray[$dk][0]];
                     }
                 }
                 $chartdata = [];
@@ -468,57 +466,58 @@ class Index extends AuthController
                 foreach ($weekarray as $k => $v) {
                     $data['day'][] = $v[0];
                     $data['pre']['count'][] = $v['pre']['count'];
-                    $data['pre']['price'][] = round($v['pre']['price'], 2);
+//                    $data['pre']['price'][] = round($v['pre']['price'], 2);
                     $data['now']['count'][] = $v['now']['count'];
-                    $data['now']['price'][] = round($v['now']['price'], 2);
+//                    $data['now']['price'][] = round($v['now']['price'], 2);
                     if ($chartdata['yAxis']['maxnum'] < $v['pre']['count'] || $chartdata['yAxis']['maxnum'] < $v['now']['count']) {
                         $chartdata['yAxis']['maxnum'] = $v['pre']['count'] > $v['now']['count'] ? $v['pre']['count'] : $v['now']['count'];//日最大订单数
                     }
-                    if ($chartdata['yAxis']['maxprice'] < $v['pre']['price'] || $chartdata['yAxis']['maxprice'] < $v['now']['price']) {
-                        $chartdata['yAxis']['maxprice'] = $v['pre']['price'] > $v['now']['price'] ? $v['pre']['price'] : $v['now']['price'];//日最大金额
-                    }
+//                    if ($chartdata['yAxis']['maxprice'] < $v['pre']['price'] || $chartdata['yAxis']['maxprice'] < $v['now']['price']) {
+//                        $chartdata['yAxis']['maxprice'] = $v['pre']['price'] > $v['now']['price'] ? $v['pre']['price'] : $v['now']['price'];//日最大金额
+//                    }
                 }
-                $chartdata['legend'] = ['去年金额', '今年金额', '去年订单数', '今年订单数'];//分类
+                $chartdata['legend'] = ['去年订单数', '今年订单数'];//分类
                 $chartdata['xAxis'] = $data['day'];//X轴值
                 //,'itemStyle'=>$series
                 $series = ['normal' => ['label' => ['show' => true, 'position' => 'top']]];
-                $chartdata['series'][] = ['name' => $chartdata['legend'][0], 'type' => 'bar', 'itemStyle' => $series, 'data' => $data['pre']['price']];//分类1值
-                $chartdata['series'][] = ['name' => $chartdata['legend'][1], 'type' => 'bar', 'itemStyle' => $series, 'data' => $data['now']['price']];//分类1值
-                $chartdata['series'][] = ['name' => $chartdata['legend'][2], 'type' => 'line', 'itemStyle' => $series, 'data' => $data['pre']['count']];//分类2值
-                $chartdata['series'][] = ['name' => $chartdata['legend'][3], 'type' => 'line', 'itemStyle' => $series, 'data' => $data['now']['count']];//分类2值
+//                $chartdata['series'][] = ['name' => $chartdata['legend'][0], 'type' => 'bar', 'itemStyle' => $series, 'data' => $data['pre']['price']];//分类1值
+//                $chartdata['series'][] = ['name' => $chartdata['legend'][1], 'type' => 'bar', 'itemStyle' => $series, 'data' => $data['now']['price']];//分类1值
+                $chartdata['series'][] = ['name' => $chartdata['legend'][0], 'type' => 'line', 'itemStyle' => $series, 'data' => $data['pre']['count']];//分类2值
+                $chartdata['series'][] = ['name' => $chartdata['legend'][1], 'type' => 'line', 'itemStyle' => $series, 'data' => $data['now']['count']];//分类2值
 
                 //统计总数上期
-                $pre_total = StoreOrderModel::where('add_time', 'between time', [$datebefor, $dateafter])
-                    ->field("count(*) as count,sum(pay_price) as price")
-                    ->find();
-                if ($pre_total) {
-                    $chartdata['pre_cycle']['count'] = [
-                        'data' => $pre_total['count'] ?: 0
-                    ];
-                    $chartdata['pre_cycle']['price'] = [
-                        'data' => $pre_total['price'] ?: 0
-                    ];
-                }
-                //统计总数
-                $total = StoreOrderModel::where('add_time', 'between time', [$now_datebefor, $now_dateafter])
-                    ->field("count(*) as count,sum(pay_price) as price")
-                    ->find();
-                if ($total) {
-                    $cha_count = intval($pre_total['count']) - intval($total['count']);
-                    //$pre_total['count'] = $pre_total['count'] == 0 ? 1 : $pre_total['count'];
-                    $chartdata['cycle']['count'] = [
-                        'data' => $total['count'] ?: 0,
-                        'percent' => intval($pre_total['count']) == 0 ? 100 : round((abs($cha_count) / intval($pre_total['count']) * 100), 2),
-                        'is_plus' => $cha_count > 0 ? -1 : ($cha_count == 0 ? 0 : 1)
-                    ];
-                    $cha_price = round($pre_total['price'], 2) - round($total['price'], 2);
-                    //$pre_total['price'] = $pre_total['price'] == 0 ? 1 : $pre_total['price'];
-                    $chartdata['cycle']['price'] = [
-                        'data' => $total['price'] ?: 0,
-                        'percent' => (intval($pre_total['price']) == 0 || !$pre_total['price'] || $pre_total['price'] == 0.00) ? 100 : round(abs($cha_price) / $pre_total['price'] * 100, 2),
-                        'is_plus' => $cha_price > 0 ? -1 : ($cha_price == 0 ? 0 : 1)
-                    ];
-                }
+//                $pre_total = StoreOrderModel::where('add_time', 'between time', [$datebefor, $dateafter])
+//                    ->field("count(*) as count,sum(pay_price) as price")
+//                    ->find();
+//                if ($pre_total) {
+//                    $chartdata['pre_cycle']['count'] = [
+//                        'data' => $pre_total['count'] ?: 0
+//                    ];
+//                    $chartdata['pre_cycle']['price'] = [
+//                        'data' => $pre_total['price'] ?: 0
+//                    ];
+//                }
+//                //统计总数
+//                $total = StoreOrderModel::where('add_time', 'between time', [$now_datebefor, $now_dateafter])
+//                    ->field("count(*) as count,sum(pay_price) as price")
+//                    ->find();
+//                if ($total) {
+//                    $cha_count = intval($pre_total['count']) - intval($total['count']);
+//                    //$pre_total['count'] = $pre_total['count'] == 0 ? 1 : $pre_total['count'];
+//                    $chartdata['cycle']['count'] = [
+//                        'data' => $total['count'] ?: 0,
+//                        'percent' => intval($pre_total['count']) == 0 ? 100 : round((abs($cha_count) / intval($pre_total['count']) * 100), 2),
+//                        'is_plus' => $cha_count > 0 ? -1 : ($cha_count == 0 ? 0 : 1)
+//                    ];
+//                    $cha_price = round($pre_total['price'], 2) - round($total['price'], 2);
+//                    //$pre_total['price'] = $pre_total['price'] == 0 ? 1 : $pre_total['price'];
+//                    $chartdata['cycle']['price'] = [
+//                        'data' => $total['price'] ?: 0,
+//                        'percent' => (intval($pre_total['price']) == 0 || !$pre_total['price'] || $pre_total['price'] == 0.00) ? 100 : round(abs($cha_price) / $pre_total['price'] * 100, 2),
+//                        'is_plus' => $cha_price > 0 ? -1 : ($cha_price == 0 ? 0 : 1)
+//                    ];
+//                }
+
                 return app('json')->success('ok', $chartdata);
                 break;
             default:

+ 51 - 51
app/admin/view/index/main.php

@@ -126,7 +126,7 @@
         <div class="col-lg-12">
             <div class="ibox float-e-margins">
                 <div class="ibox-title">
-                    <h5>订单</h5>
+                    <h5>计算</h5>
                     <div class="pull-right">
                         <div class="btn-group">
                             <button type="button" class="btn btn-xs btn-white" :class="{'active': active == 'thirtyday'}" v-on:click="getlist('thirtyday')">30天</button>
@@ -141,56 +141,56 @@
                         <div class="col-lg-9">
                             <div class="flot-chart-content echarts" ref="order_echart" id="flot-dashboard-chart1"></div>
                         </div>
-                        <div class="col-lg-3">
-                            <ul class="stat-list">
-                                <li>
-                                    <h2 class="no-margins ">{{pre_cycleprice}}</h2>
-                                    <small>{{precyclename}}销售额</small>
-                                </li>
-                                <li>
-                                    <h2 class="no-margins ">{{cycleprice}}</h2>
-                                    <small>{{cyclename}}销售额</small>
-                                    <div class="stat-percent text-navy" v-if='cycleprice_is_plus ===1'>
-                                        {{cycleprice_percent}}%
-                                        <i  class="fa fa-level-up"></i>
-                                    </div>
-                                    <div class="stat-percent text-danger" v-else-if='cycleprice_is_plus === -1'>
-                                        {{cycleprice_percent}}%
-                                        <i class="fa fa-level-down"></i>
-                                    </div>
-                                    <div class="stat-percent" v-else>
-                                        {{cycleprice_percent}}%
-                                    </div>
-                                    <div class="progress progress-mini">
-                                        <div :style="{width:cycleprice_percent+'%'}" class="progress-bar box"></div>
-                                    </div>
-                                </li>
-                                <li>
-                                    <h2 class="no-margins ">{{pre_cyclecount}}</h2>
-                                    <small>{{precyclename}}订单总数</small>
-                                </li>
-                                <li>
-                                    <h2 class="no-margins">{{cyclecount}}</h2>
-                                    <small>{{cyclename}}订单总数</small>
-                                    <div class="stat-percent text-navy" v-if='cyclecount_is_plus ===1'>
-                                        {{cyclecount_percent}}%
-                                        <i class="fa fa-level-up"></i>
-                                    </div>
-                                    <div class="stat-percent text-danger" v-else-if='cyclecount_is_plus === -1'>
-                                        {{cyclecount_percent}}%
-                                        <i  class="fa fa-level-down"></i>
-                                    </div>
-                                    <div class="stat-percent " v-else>
-                                        {{cyclecount_percent}}%
-                                    </div>
-                                    <div class="progress progress-mini">
-                                        <div :style="{width:cyclecount_percent+'%'}" class="progress-bar box"></div>
-                                    </div>
-                                </li>
-
-
-                            </ul>
-                        </div>
+<!--                        <div class="col-lg-3">-->
+<!--                            <ul class="stat-list">-->
+<!--                                <li>-->
+<!--                                    <h2 class="no-margins ">{{pre_cycleprice}}</h2>-->
+<!--                                    <small>{{precyclename}}销售额</small>-->
+<!--                                </li>-->
+<!--                                <li>-->
+<!--                                    <h2 class="no-margins ">{{cycleprice}}</h2>-->
+<!--                                    <small>{{cyclename}}销售额</small>-->
+<!--                                    <div class="stat-percent text-navy" v-if='cycleprice_is_plus ===1'>-->
+<!--                                        {{cycleprice_percent}}%-->
+<!--                                        <i  class="fa fa-level-up"></i>-->
+<!--                                    </div>-->
+<!--                                    <div class="stat-percent text-danger" v-else-if='cycleprice_is_plus === -1'>-->
+<!--                                        {{cycleprice_percent}}%-->
+<!--                                        <i class="fa fa-level-down"></i>-->
+<!--                                    </div>-->
+<!--                                    <div class="stat-percent" v-else>-->
+<!--                                        {{cycleprice_percent}}%-->
+<!--                                    </div>-->
+<!--                                    <div class="progress progress-mini">-->
+<!--                                        <div :style="{width:cycleprice_percent+'%'}" class="progress-bar box"></div>-->
+<!--                                    </div>-->
+<!--                                </li>-->
+<!--                                <li>-->
+<!--                                    <h2 class="no-margins ">{{pre_cyclecount}}</h2>-->
+<!--                                    <small>{{precyclename}}订单总数</small>-->
+<!--                                </li>-->
+<!--                                <li>-->
+<!--                                    <h2 class="no-margins">{{cyclecount}}</h2>-->
+<!--                                    <small>{{cyclename}}订单总数</small>-->
+<!--                                    <div class="stat-percent text-navy" v-if='cyclecount_is_plus ===1'>-->
+<!--                                        {{cyclecount_percent}}%-->
+<!--                                        <i class="fa fa-level-up"></i>-->
+<!--                                    </div>-->
+<!--                                    <div class="stat-percent text-danger" v-else-if='cyclecount_is_plus === -1'>-->
+<!--                                        {{cyclecount_percent}}%-->
+<!--                                        <i  class="fa fa-level-down"></i>-->
+<!--                                    </div>-->
+<!--                                    <div class="stat-percent " v-else>-->
+<!--                                        {{cyclecount_percent}}%-->
+<!--                                    </div>-->
+<!--                                    <div class="progress progress-mini">-->
+<!--                                        <div :style="{width:cyclecount_percent+'%'}" class="progress-bar box"></div>-->
+<!--                                    </div>-->
+<!--                                </li>-->
+<!---->
+<!---->
+<!--                            </ul>-->
+<!--                        </div>-->
                     </div>
                 </div>
             </div>