海南旅游SAAS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

139 lines
4.2 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. <?php
  2. namespace App\AdminAgent\Controllers;
  3. use App\AdminAgent\Metrics\Examples\OrderStatistics;
  4. use App\Common\OrderStatus;
  5. use App\Models\Order;
  6. use Dcat\Admin\Admin;
  7. use Dcat\Admin\Layout\Column;
  8. use Dcat\Admin\Layout\Content;
  9. use Dcat\Admin\Layout\Row;
  10. use Dcat\Admin\Http\Controllers\AdminController;
  11. use Dcat\Admin\Widgets\Box;
  12. use Dcat\Admin\Widgets\Card;
  13. use Dcat\Admin\Widgets\Dropdown;
  14. use Illuminate\Support\Arr;
  15. use Illuminate\Support\Str;
  16. class OrderStatisticsController extends AdminController
  17. {
  18. public function index(Content $content)
  19. {
  20. Admin::style(
  21. <<<CSS
  22. .app-content > .content-wrapper > .content-header{display: none}
  23. .col-sm-12.d-flex{
  24. display: inline-block !important;
  25. }
  26. CSS
  27. );
  28. //数据
  29. //订单
  30. return $content
  31. ->body(
  32. <<<HTML
  33. <div class="content-header">
  34. <section class="content-header breadcrumbs-top">
  35. <h1 class=" float-left">
  36. <span class="text-capitalize">订单统计</span>
  37. </h1>
  38. <div class="clearfix"></div>
  39. </section>
  40. </div>
  41. HTML
  42. )
  43. ->body(function (Row $row){
  44. $row->column(12,function (Column $column){
  45. $column->row(new \App\AdminAgent\Tools\DataReportDate('data_report'));
  46. });
  47. })
  48. ->body(function (Row $row) {
  49. $count = Order::query()->where('agent_id',Admin::user()->id);
  50. $dateTime = request('created_at', 0);
  51. if ($dateTime) {
  52. $count->whereBetween('created_at',[$dateTime['start'] . ' 00:00:00',$dateTime['end'].' 23:59:59']);
  53. }
  54. $count = $count->count();
  55. $row->column(3, function (Column $column) use ($count) {
  56. $column->row(Card::make('总数', function () use ($count) {
  57. return <<<HTML
  58. <div class="d-flex justify-content-between align-items-center mt-1" style="margin-bottom: 2px">
  59. <h2 class="ml-1 font-large-1 text-primary">$count</h2>
  60. </div>
  61. HTML;
  62. }));
  63. });
  64. $arr = OrderStatus::array();
  65. [$keys, $values] = Arr::divide($arr);
  66. foreach ($keys as $v){
  67. $orders = Order::query()->where('agent_id',Admin::user()->id)->where('status',$v);
  68. if ($dateTime) {
  69. $orders->whereBetween('created_at',[$dateTime['start'] . ' 00:00:00',$dateTime['end'].' 23:59:59']);
  70. }
  71. $orders = $orders->count();
  72. $row->column(3, function (Column $column) use ($arr,$orders,$v) {
  73. $column->row(Card::make($arr[$v], function () use ($orders) {
  74. return <<<HTML
  75. <div class="d-flex justify-content-between align-items-center mt-1" style="margin-bottom: 2px">
  76. <h2 class="ml-1 font-large-1 text-primary">$orders</h2>
  77. </div>
  78. HTML;
  79. }));
  80. });
  81. }
  82. //
  83. })
  84. ->body(function (Row $row){
  85. // 构建下拉菜单,当点击菜单时发起请求获取数据重新渲染图表
  86. $menu = [
  87. '1' => '日',
  88. '30' => '月',
  89. '365' => '年',
  90. ];
  91. $buttonName = '日';
  92. if (Arr::exists($menu, \request()->input('time_key', ''))) {
  93. $buttonName = $menu[\request()->input('time_key')];
  94. }
  95. $dropdown = Dropdown::make($menu)
  96. ->button(current($menu))
  97. ->button($buttonName)
  98. ->click()
  99. ->map(function ($v, $k) {
  100. $querys = \request()->all();
  101. $querys['time_key'] = $k;
  102. $queryString = http_build_query($querys);
  103. $str = Str::after(request()->path(),'/');
  104. $url = admin_url($str.'?'.$queryString);
  105. // 此处设置的 data-xxx 属性会作为post数据发送到后端api
  106. return "<a class='switch-bar' data-option='{$k}' href='$url'>{$v}</a>";
  107. });
  108. // 传递自定义参数
  109. $bar = OrderStatistics::make()
  110. ->fetching('$("#my-box").loading()') // 设置loading效果
  111. ->fetched('$("#my-box").loading(false)') // 移除loading效果
  112. ->click('.switch-bar'); // 设置图表点击菜单则重新发起请求,且被点击的目标元素上的 data-xxx 属性会被作为post数据发送到后端API
  113. $box = Box::make('订单统计图表', $bar)
  114. ->id('my-box') // 设置盒子的ID
  115. ->tool($dropdown); // 设置下拉菜单按钮
  116. $row->column(12, $box);
  117. });
  118. }
  119. }