Dashboard.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace app\controller\merchant;
  3. use app\extra\basic\Base;
  4. use app\middleware\AuthMiddleware;
  5. use app\model\saas\SaasOrder;
  6. use LinFly\Annotation\Attributes\Route\Controller;
  7. use LinFly\Annotation\Attributes\Route\GetMapping;
  8. use LinFly\Annotation\Attributes\Route\Middleware;
  9. use support\Request;
  10. /**
  11. * 统计
  12. */
  13. #[Controller("/api/merchant/dashboard"),Middleware(AuthMiddleware::class)]
  14. class Dashboard extends Base
  15. {
  16. #[GetMapping('list')]
  17. public function getData(Request $request)
  18. {
  19. try {
  20. $data = $moneys = $orders = [];
  21. $shopId = $request->user['store_id'];
  22. $mode = (new SaasOrder);
  23. $data = [
  24. "userNum" => $mode->whereDay("create_at")->where("poi_id",$shopId)->where('status','in',[1,3])->sum("money"), // 今日营业额
  25. "rechargeNum" => $mode->whereDay("create_at")->where("poi_id",$shopId)->where('status','in',[1,3])->count(), // 今日订单数
  26. "rechargeMoney" => $mode->whereDay("create_at")->where("poi_id",$shopId)->where('status',1)->count(), // 手机自助打印待处理
  27. ];
  28. $fields = ['ROUND(sum(money)/100,2)' => 'total','substr(create_at,1,10)' => 'mday'];
  29. $orderMoney = $mode->field($fields)->where("poi_id",$shopId)->where('status','in',[1,3])->whereTime('create_at', '-15 days')->group('mday')->select()->column(null, 'mday');
  30. for ($i = 15; $i >= 0; $i--) {
  31. $date = date('Y-m-d', strtotime("-{$i}days"));
  32. $moneys[] = [
  33. '当天日期' => date('Y-m-d', strtotime("-{$i}days")),
  34. '订单金额' => ($orderMoney[$date] ?? [])['total'] ?? 0,
  35. ];
  36. }
  37. $field = ['count(1)' => 'count', 'substr(create_at,1,10)' => 'mday'];
  38. $orderNum = $mode->field($field)->where("poi_id",$shopId)->where('status','in',[1,3])->whereTime('create_at', '-15 days')->group('mday')->select()->column(null, 'mday');
  39. for ($i = 15; $i >= 0; $i--) {
  40. $date = date('Y-m-d', strtotime("-{$i}days"));
  41. $orders[] = [
  42. '当天日期' => date('Y-m-d', strtotime("-{$i}days")),
  43. '订单数量' => ($orderNum[$date] ?? [])['count'] ?? 0,
  44. ];
  45. }
  46. return success("ok",compact("data","orders","moneys"));
  47. } catch (\Throwable $throwable) {
  48. }
  49. }
  50. }