|
|
@@ -0,0 +1,61 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace app\controller;
|
|
|
+
|
|
|
+use app\extra\basic\Base;
|
|
|
+use app\middleware\AuthMiddleware;
|
|
|
+use app\model\saas\SaasOrderLife;
|
|
|
+use app\model\saas\SaasStore;
|
|
|
+use LinFly\Annotation\Route\Controller;
|
|
|
+use LinFly\Annotation\Route\Middleware;
|
|
|
+use LinFly\Annotation\Route\Route;
|
|
|
+use support\Response;
|
|
|
+
|
|
|
+
|
|
|
+#[Controller(prefix: "/api/dashboard"),Middleware(AuthMiddleware::class)]
|
|
|
+class Dashboard extends Base
|
|
|
+{
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @return Response
|
|
|
+ */
|
|
|
+ #[Route(path: "manage",methods: "get")]
|
|
|
+ public function getManageData(): Response
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ $total = (new SaasOrderLife)->where("status","in",[1,2,3,6])->whereDay("create_at")->field("ROUND(sum(pay_amount)/100,2) as money,count(id) as num")->find();
|
|
|
+ $today = [
|
|
|
+ "order_money" => $total['money']??0, // 营业额
|
|
|
+ "order_num" => $total['num']??0, // 订单数
|
|
|
+ "order_done" => "", // 已核销
|
|
|
+ "order_send" => "", // 待发货
|
|
|
+ "store_num" => (new SaasStore)->count(), // 总店铺数量
|
|
|
+ ];
|
|
|
+ $moneys = $orders = [];
|
|
|
+ $fields = ['ROUND(sum(pay_amount)/100,2)' => 'total','substr(create_at,1,10)' => 'mday'];
|
|
|
+ $orderMoney = (new SaasOrderLife)->field($fields)->where("status","in",[1,3,4,5])->whereTime('create_at', '-15 days')->group('mday')->select()->column(null, 'mday');
|
|
|
+ for ($i = 15; $i >= 0; $i--) {
|
|
|
+ $date = date('Y-m-d', strtotime("-{$i}days"));
|
|
|
+ $moneys[] = [
|
|
|
+ '当天日期' => date('Y-m-d', strtotime("-{$i}days")),
|
|
|
+ '订单金额' => ($orderMoney[$date] ?? [])['total'] ?? 0,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ $field = ['count(1)' => 'count', 'substr(create_at,1,10)' => 'mday'];
|
|
|
+ $orderNum = (new SaasOrderLife)->field($field)->where("status","in",[1,3,4,5])->whereTime('create_at', '-15 days')->group('mday')->select()->column(null, 'mday');
|
|
|
+ for ($i = 15; $i >= 0; $i--) {
|
|
|
+ $date = date('Y-m-d', strtotime("-{$i}days"));
|
|
|
+ $orders[] = [
|
|
|
+ '当天日期' => date('Y-m-d', strtotime("-{$i}days")),
|
|
|
+ '订单数量' => ($orderNum[$date] ?? [])['count'] ?? 0,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ return success("ok",compact("today","moneys","orders"));
|
|
|
+ } catch (\Throwable $throwable) {
|
|
|
+ return error($throwable->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|