李浩杰 4 éve
szülő
commit
d9e3a1eae9

+ 1 - 1
app/Http/Controllers/Admin/TestController.php

xqd
@@ -17,7 +17,7 @@ class TestController extends Controller
 {
     public function index(Request $request)
     {
-        dd(count('1111'));
+        dd(User::all()->min('created_at'));
     	return view('admin.test.index');
     }
 }

+ 64 - 0
app/Http/Controllers/Api/mini/DataController.php

xqd xqd
@@ -122,6 +122,7 @@ class DataController extends BaseController
     {
         if(!$request->input('project_ids')) return $this->error(['msg' => '']);
         if($request->input('chart_type') == 'pie') return $this->getPieData($request);
+        else if($request->input('chart_type') == 'radar') return $this->getRadarData($request);
         $orders = $this->getOrders($request);
         if(!$orders) return $this->error(['msg' => '']);
         $names = [];
@@ -149,6 +150,69 @@ class DataController extends BaseController
         return $this->success(['data' => compact('values', 'names', 'legends')]);
     }
 
+    public function getRadarData(Request $request)
+    {
+        $orders = $this->getOrders($request);
+        if(!$orders) return $this->error(['msg' => '']);
+
+        $data = [];
+        $projects = Project::whereIn('id', $request->input('project_ids'))->get();
+        $indicator = [
+            ['name' => '累计租赁花费', 'max' => 0],
+            ['name' => '累计租赁数量', 'max' => 0],
+            ['name' => '平均月消费', 'max' => 0],
+            ['name' => '租赁次数', 'max' => 0],
+            ['name' => '租赁天数', 'max' => 0]
+        ];
+        $legends = [];
+
+        foreach($projects as $key => $project) {
+            $tmp_orders = $orders->where('project_id', $project->id);
+            $total_money = $tmp_orders->sum('money') / 100;
+            $total_num = OrderDevice::whereIn('order_id', $orders->where('project_id', $project->id)->pluck('id'))->count();
+            $months = $this->getMonths($tmp_orders);
+            $mean_month = $total_money / $months;
+            $rent_times = $tmp_orders->count();
+            $rent_days = $this->getRentDays($tmp_orders);
+            $indicator[0]['max'] = max($indicator[0]['max'], $total_money);
+            $indicator[1]['max'] = max($indicator[1]['max'], $total_num);
+            $indicator[2]['max'] = max($indicator[2]['max'], $mean_month);
+            $indicator[3]['max'] = max($indicator[3]['max'], $rent_times);
+            $indicator[4]['max'] = max($indicator[4]['max'], $rent_days);
+
+            array_push($data, [
+                'name' => $project->name,
+                'value' => [$total_money, $total_num, $mean_month, $rent_times, $rent_days]
+            ]);
+
+            array_push($legends, $project->name);
+        }
+
+        return $this->success(['data' => compact('data', 'legends', 'indicator')]);
+    }
+
+    public function getMonths($orders)
+    {
+        $min_at = $orders->min('created_at');
+        $max_at = $orders->max('updated_at');
+        if($max_at && $max_at) $months = $min_at->diffInMonths($max_at);
+        else $months = 1;
+        return $months ? $months : 1;
+    }
+
+    public function getRentDays($orders)
+    {
+        $order_ids = $orders->pluck('id');
+        $order_devices = OrderDevice::whereId('order_id', $order_ids)->get();
+        $days = 0;
+        foreach($order_devices as $order_device) {
+            if($order_device->start_date && $order_device->end_date) {
+                $days = $days + Carbon::createFromTimeString($order_device->start_date . ' 00:00:00')->diffInDays($order_device->end_date);
+            }
+        }
+        return $days;
+    }
+
     public function getPieData(Request $request)
     {
         $order_ids = $this->getOrderIds($request);

+ 1 - 1
mini/app.json

xqd
@@ -1,7 +1,7 @@
 {
   "pages": [
-    "pages/data/index",
     "pages/index/index",
+    "pages/data/index",
     "pages/order-inner/index",
     "pages/order/index",
     "pages/notification/index",

+ 45 - 28
mini/pages/data/index.js

xqd xqd xqd xqd xqd xqd xqd xqd xqd
@@ -112,31 +112,36 @@ Page({
     app.resetDataFilter()
   },
 
-  switchCheck: function(e) {
+  switchCheck: function (e) {
     var index = e.currentTarget.dataset.index
     var projects = this.data.projects
     projects[index].checked = projects[index].checked ? false : true
-    this.setData({projects})
+    this.setData({
+      projects
+    })
   },
 
-  closeProject: function(e) {
+  closeProject: function (e) {
     var project_ids = []
     var project_names = []
     var projects = this.data.projects
-    for(var i = 0; i < projects.length; ++i) {
-      if(projects[i].checked) {
+    for (var i = 0; i < projects.length; ++i) {
+      if (projects[i].checked) {
         project_ids.push(projects[i].id)
         project_names.push(projects[i].name)
       }
     }
     project_names = project_names.join(',')
-    this.setData({project_ids, project_names})
+    this.setData({
+      project_ids,
+      project_names
+    })
     this.switchShow(e)
     this.getData()
     this.getTotalInfo()
   },
 
-  getSearchItems: function() {
+  getSearchItems: function () {
     var ids = this.data.project_ids
     if (ids.length <= 0) return false
     var filter = this.data.filter
@@ -162,8 +167,8 @@ Page({
     http({
       url: 'data/getTotalInfo',
       data: data,
-      success: function(res) {
-        if(res.code == 0) {
+      success: function (res) {
+        if (res.code == 0) {
           that.setData(res.data)
         }
       }
@@ -176,8 +181,8 @@ Page({
     http({
       url: 'data/getDetailData',
       data: data,
-      success: function(res) {
-        if(res.code == 0) {
+      success: function (res) {
+        if (res.code == 0) {
           that.setData({
             detail_data: res.data
           })
@@ -189,19 +194,21 @@ Page({
   getData() {
     var data = this.getSearchItems()
     var that = this
-    if(!data.project_ids || data.project_ids.length <= 0) return false
+    if (!data.project_ids || data.project_ids.length <= 0) return false
     var chart_type = this.data.charts[this.data.chartIndex]
     http({
       url: 'data/getStat',
       data: data,
-      success: function(res) {
-        if(res.code == 0) {
-          if(chart_type == 'detail') {
+      success: function (res) {
+        if (res.code == 0) {
+          if (chart_type == 'detail') {
             that.setData({
               detail_data: res.data
             })
           } else {
-            that.setData({data: res.data})
+            that.setData({
+              data: res.data
+            })
             that.updateChart()
           }
         }
@@ -225,30 +232,30 @@ Page({
   onChange: function (e) {
     var value = e.detail.value
     var name = e.currentTarget.dataset.name
-    if(this.data[name] == value) return false;
+    if (this.data[name] == value) return false;
     this.setData({
       [name]: value
     })
-    if(name == 'chartIndex') {
+    if (name == 'chartIndex') {
       var chart = this.data.charts[this.data.chartIndex]
-      if(chart.type == 'detail') {
+      if (chart.type == 'detail') {
         this.getDetailData()
       } else {
         this.getData()
       }
-    } else if(name == 'date') {
+    } else if (name == 'date') {
       this.getTotalInfo()
     }
   },
-  updateChart: function() {
+  updateChart: function () {
     var data = this.data.data
     option.xAxis.data = data.names;
     option.legend = {
       data: data.legends
     }
-    
+
     var type = this.data.charts[this.data.chartIndex].type
-    if(type == 'pie') {
+    if (type == 'pie') {
       option.series = [{
         data: data.data,
         type: type,
@@ -258,10 +265,20 @@ Page({
         }
       }]
       option.xAxis.show = false
+    } else if (type == 'radar') {
+      option.xAxis.show = false
+      option.radar = {
+        // shape: 'circle',
+        indicator: data.indicator
+      }
+      option.series = [{
+        type: type,
+        data: data.data
+      }]
     } else {
       option.xAxis.show = true
       var values = data.values
-      for(var i = 0; i < values.length; ++i) {
+      for (var i = 0; i < values.length; ++i) {
         option.series[i] = {
           label: {
             show: true,
@@ -273,13 +290,13 @@ Page({
         }
       }
     }
-    
+
     chart.setOption(option)
   },
 
   radioChange: function (e) {
     var dateIndex = e.currentTarget.dataset.index
-    if(dateIndex == this.data.dateIndex) return false
+    if (dateIndex == this.data.dateIndex) return false
     var start_date = this.data.start_date
     var end_date = this.data.end_date
     var start_date = dateIndex == 1 ? start_date + '-01' : start_date.substr(0, 7)
@@ -297,7 +314,7 @@ Page({
     this.setData({
       [name]: show
     })
-    if(name == 'dateShow' && !show) {
+    if (name == 'dateShow' && !show) {
       this.getData()
     }
   },
@@ -320,7 +337,7 @@ Page({
     this.getData()
   },
 
-  navigate: function(e) {
+  navigate: function (e) {
     var url = e.currentTarget.dataset.url
     wx.navigateTo({
       url: url,

+ 1 - 1
mini/utils/env.js

xqd
@@ -1,4 +1,4 @@
-const isTest = true;
+const isTest = false;
 const baseUrl = isTest ? 'http://app.rt/api/mini/' : 'http://t18.9026.com/api/mini/';
 
 export default baseUrl