Browse Source

完善功能

gorden 11 months ago
parent
commit
2b3c26c957

+ 30 - 0
app/admin/controller/dashboard/DashboardController.php

@@ -0,0 +1,30 @@
+<?php
+
+namespace app\admin\controller\dashboard;
+
+use app\admin\service\statistics\AppointmentService;
+use app\admin\service\statistics\CustomerService;
+use app\admin\service\statistics\DeviceService;
+use app\admin\service\statistics\GoodsService;
+use app\admin\service\statistics\MemberService;
+use app\admin\service\statistics\OrderService;
+
+class DashboardController
+{
+    public function index()
+    {
+        $data['customer'] = CustomerService::getCustomer();
+        // 用户  会员+业主
+        $data['member'] = MemberService::getMember();
+        // 设备
+        $data['device'] = DeviceService::getDevice();
+        // 预约
+        $data['appointment'] = AppointmentService::getAppointment();
+        // 订单
+        $data['order'] = OrderService::getOrder();
+        // 商品
+        $data['goods'] = GoodsService::getGoods();
+
+        return json_success('', $data);
+    }
+}

+ 24 - 0
app/admin/service/statistics/AppointmentService.php

@@ -0,0 +1,24 @@
+<?php
+
+namespace app\admin\service\statistics;
+
+use app\model\Appointment;
+use support\Db;
+
+class AppointmentService
+{
+    public static function getAppointment()
+    {
+        // 待确认
+        $data['waiting'] = Appointment::where('appointment_status', 'WAITING')->count('appointment_id');
+        // 待服务
+        $data['append'] = Appointment::where('appointment_status', 'PENDING')->count('appointment_id');
+        // 今日预约
+        $data['todayAppointment'] = Appointment::where('appointment_datetime', date('Y-m-d'))->count('appointment_id');
+        // 今日服务
+        $today = Db::select("select service_time,count(*) as total from (select left(appointment_doing_datetime,10) as service_time from app_appointment where appointment_doing_datetime != '') as appointment where service_time =".date('Y-m-d'));
+        $data['todayService'] = $today[0]->total;
+
+        return $data;
+    }
+}

+ 16 - 0
app/admin/service/statistics/CustomerService.php

@@ -0,0 +1,16 @@
+<?php
+
+namespace app\admin\service\statistics;
+
+use app\model\Customer;
+
+class CustomerService
+{
+    public static function getCustomer()
+    {
+        $todayTimeUnix = strtotime(date('Y-m-d'));
+        $data['todayCount'] = Customer::where('created_at', '>', $todayTimeUnix)->count();
+
+        return $data;
+    }
+}

+ 17 - 0
app/admin/service/statistics/DeviceService.php

@@ -0,0 +1,17 @@
+<?php
+
+namespace app\admin\service\statistics;
+
+use app\model\Device;
+
+class DeviceService
+{
+    public static function getDevice()
+    {
+        $data['activeCount'] = Device::where('device_status','ACTIVED')->count('device_id');
+
+        $data['count'] = Device::count('device_id');
+
+        return $data;
+    }
+}

+ 16 - 0
app/admin/service/statistics/GoodsService.php

@@ -0,0 +1,16 @@
+<?php
+
+namespace app\admin\service\statistics;
+
+use app\model\Goods;
+use app\model\GoodsRunning;
+
+class GoodsService
+{
+    public static function getGoods()
+    {
+        $data['storageWarning'] = GoodsRunning::where("goods_running_storage",'<=',10)->count();
+
+        return $data;
+    }
+}

+ 71 - 0
app/admin/service/statistics/MemberService.php

@@ -0,0 +1,71 @@
+<?php
+
+namespace app\admin\service\statistics;
+
+use app\model\Member;
+use support\Db;
+
+class MemberService
+{
+    public static function getMember(){
+        $data = [];
+
+        // 会员数量
+        $data['memberCount'] = Member::where('member_is_owner', 'N')->count();
+        // 业主数量
+        $data['ownerCount'] = Member::where('member_is_owner', 'Y')->count();
+        // 用户总数
+        $data['userCount'] = $data['memberCount'] + $data['ownerCount'];
+        // 今日新增用户数
+        $todayTime = strtotime(date('Y-m-d 00:00:00'));
+        $data['todayCount'] = Member::where('member_addtimes', '>', $todayTime)->where('member_is_owner', 'N')->count();
+        // 本月新增用户数
+        $monthTime = strtotime(date('Y-m-01 00:00:00'));
+        $data['monthCount'] = Member::where('member_addtimes', '>', $monthTime)->where('member_is_owner', 'N')->count();
+
+        // 折线图
+        $newAddition = Db::select("SELECT DATE_FORMAT(FROM_UNIXTIME(member_addtimes), '%Y/%m') AS `month`,count(*) as `num` FROM app_member group by month");
+        $newAdditionData = [];
+        foreach ($newAddition as $item) {
+            $newAdditionData['category'][] = $item->month;
+            $newAdditionData['data'][] = $item->num;
+        }
+        $data['addition'] = $newAdditionData;
+
+        // 饼图
+        $newAdditionBing = Db::select("
+            SELECT CASE
+                WHEN TIMESTAMPDIFF(YEAR, member_cert_birth, CURDATE()) BETWEEN 0 AND 1 THEN '0'
+                WHEN TIMESTAMPDIFF(YEAR, member_cert_birth, CURDATE()) BETWEEN 1 AND 39 THEN '39'
+                WHEN TIMESTAMPDIFF(YEAR, member_cert_birth, CURDATE()) BETWEEN 40 AND 50 THEN '41-50'
+                WHEN TIMESTAMPDIFF(YEAR, member_cert_birth, CURDATE()) BETWEEN 51 AND 60 THEN '51-60'
+                WHEN TIMESTAMPDIFF(YEAR, member_cert_birth, CURDATE()) BETWEEN 61 AND 70 THEN '61-70'
+                WHEN TIMESTAMPDIFF(YEAR, member_cert_birth, CURDATE()) BETWEEN 71 AND 80 THEN '71-80'
+                ELSE '81以上'
+              END AS age_group,
+              COUNT(*) AS number_of_people
+            FROM
+              app_member_cert
+            GROUP BY
+              age_group
+            ORDER BY
+              age_group;
+        ");
+        $newAdditionBingData = [];
+        foreach ($newAdditionBing as $item) {
+            if ($item->age_group == '0') {
+                $item->age_group = '未知';
+            }elseif ($item->age_group == '39'){
+                $item->age_group = '40以下';
+            }
+            $newAdditionBingData[] = [
+                'name' => $item->age_group,
+                'value' => $item->number_of_people
+            ];
+        }
+
+        $data['additionBing'] = $newAdditionBingData;
+
+        return $data;
+    }
+}

+ 96 - 0
app/admin/service/statistics/OrderService.php

@@ -0,0 +1,96 @@
+<?php
+
+namespace app\admin\service\statistics;
+
+use app\model\Order;
+use app\model\OrderReturn;
+use support\Db;
+
+class OrderService
+{
+    public static function getOrder()
+    {
+        // 今日订单
+        $todayTimeUnix = strtotime(date('Y-m-d'));
+        // 今日订单
+        $data['todayOrder'] = Order::where('order_addtimes', '>', $todayTimeUnix)->count();
+        // 今日收入
+        $data['todayRevenue'] = Order::where('order_status_payment', 'SUCCESS')
+            ->where('order_addtimes', '>', $todayTimeUnix)
+            ->sum('order_amount_pay');
+        // 今日退单
+        $data['todayRefund'] = OrderReturn::where('order_return_addtimes', '>', $todayTimeUnix)->count();
+
+
+        // 柱状图
+        // 产品订单
+        $newAddition = Db::select("SELECT DATE_FORMAT(FROM_UNIXTIME(order_addtimes), '%Y/%m') AS `month`,count(*) as `num` FROM app_order group by month");
+//        $newAddition = Db::select("
+//            SELECT DATE_FORMAT(FROM_UNIXTIME(order_sheet_addtimes), '%Y/%m') AS `month`,count(*) as `num` FROM app_order_sheet as s
+//                left join app_goods as g on s.join_sheet_goods_id = g.goods_id
+//                    where g.goods_classify = 'GOODS'
+//                group by month
+//        ");
+        $category = [];
+        $newAdditionData = [];
+        foreach ($newAddition as $item) {
+            if (!in_array($item->month, $category)) {
+                $category[] = $item->month;
+            }
+//            $newAdditionData['category'][] = $item->month;
+//            $newAdditionData['data'][] = $item->num;
+        }
+
+        // 服务订单
+        $newAdditionService = Db::select("
+            SELECT DATE_FORMAT(FROM_UNIXTIME(order_sheet_addtimes), '%Y/%m') AS `month`,count(*) as `num` FROM app_order_sheet as s 
+                left join app_goods as g on s.join_sheet_goods_id = g.goods_id
+                    where g.goods_classify = 'SERVICE'
+                group by month
+        ");
+        $newAdditionServiceData = [];
+        foreach ($newAdditionService as $item) {
+            if (!in_array($item->month, $category)) {
+                $category[] = $item->month;
+            }
+//            $newAdditionServiceData['category'][] = $item->month;
+//            $newAdditionServiceData['data'][] = $item->num;
+        }
+
+        sort($category);
+
+        foreach ($category as $item2){
+            $isHaveService = false;
+            $isHaveGoods = false;
+            foreach ($newAdditionService as $item){
+                if ($item2 == $item->month){
+                    $isHaveService = true;
+                    $newAdditionServiceData['category'][] = $item->month;
+                    $newAdditionServiceData['data'][] = $item->num;
+                }
+            }
+            foreach ($newAddition as $item3){
+                if ($item2 == $item3->month){
+                    $isHaveGoods = true;
+                    $newAdditionData['category'][] = $item3->month;
+                    $newAdditionData['data'][] = $item3->num;
+                }
+            }
+            if (!$isHaveService){
+                $newAdditionServiceData['category'][] = $item2;//['month'=>$item2,'num'=>0];
+                $newAdditionServiceData['data'][] = 0;
+            }
+
+            if (!$isHaveGoods){
+                $newAdditionData['category'][] = $item2;//['month'=>$item2,'num'=>0];
+                $newAdditionData['data'][] = 0;
+            }
+
+        }
+
+        $data['addition']['goods'] = $newAdditionData;
+        $data['addition']['service'] = $newAdditionServiceData;
+
+        return $data;
+    }
+}

+ 5 - 1
route/admin.php

@@ -499,7 +499,7 @@ Route::group('/admin', function () {
         ]);
         Route::group('/account', function () {
             Route::get('/my/{id:\w+}', [\app\admin\controller\member\AccountController::class, 'my']);
-            Route::post('/incomeExpend',[\app\admin\controller\member\AccountController::class,'incomeExpend']);
+            Route::post('/incomeExpend', [\app\admin\controller\member\AccountController::class, 'incomeExpend']);
         })->middleware([
             \app\middleware\AdminAuthCheck::class
         ]);
@@ -740,4 +740,8 @@ Route::group('/admin', function () {
             ]);
         });
     });
+
+    Route::group('/dashboard', function () {
+        Route::get('/',[\app\admin\controller\dashboard\DashboardController::class,'index']);
+    });
 });