海南旅游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.

117 lines
2.4 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
  1. <?php
  2. namespace App\AdminSupplier\Metrics\Examples;
  3. use App\Common\DataTime;
  4. use App\Models\OrderProductItem;
  5. use App\Models\User;
  6. use Carbon\Carbon;
  7. use Dcat\Admin\Admin;
  8. use Dcat\Admin\Widgets\Metrics\Line;
  9. use Illuminate\Http\Request;
  10. use Illuminate\Support\Arr;
  11. use Illuminate\Support\Facades\DB;
  12. class NewUsers extends Line
  13. {
  14. /**
  15. * 初始化卡片内容
  16. *
  17. * @return void
  18. */
  19. protected function init()
  20. {
  21. parent::init();
  22. $this->title('现金流水');
  23. $this->dropdown([
  24. //'day' => '本日',
  25. 'week' => '本周',
  26. 'month' => '本月',
  27. //'year' => '今年',
  28. ]);
  29. }
  30. /**
  31. * 处理请求
  32. *
  33. * @param Request $request
  34. *
  35. * @return mixed|void
  36. */
  37. public function handle(Request $request)
  38. {
  39. $order = OrderProductItem::query()
  40. ->where('supplier_id',Admin::user()->id);
  41. switch ($request->get('option')) {
  42. case 'day':
  43. $order->whereDate('created_at', Carbon::today());
  44. break;
  45. case 'week':
  46. $time = DataTime::beginAndEnd('week');
  47. $order->whereBetween('created_at', $time);
  48. break;
  49. case 'month':
  50. $order->whereMonth('created_at', Carbon::now()->month);
  51. break;
  52. case 'year':
  53. $order->whereYear('created_at', Carbon::now()->year);
  54. break;
  55. default:
  56. $time = DataTime::beginAndEnd('week');
  57. $order->whereBetween('created_at', $time);
  58. }
  59. $countOrder = clone $order;
  60. $count = $order->sum('price');
  61. $this->withContent($count);
  62. $countOrder = $countOrder->select('*')
  63. ->addSelect(DB::raw("sum(price) as sum_price,CONCAT(YEAR(created_at),'-',MONTH(created_at),'-',DAY(created_at)) AS statistics_time"))
  64. ->limit(30)
  65. ->groupBy('statistics_time')
  66. ->get()
  67. ->toArray();
  68. // 图表数据
  69. $this->chartLabels(Arr::pluck($countOrder, 'statistics_time'));
  70. $this->withChart(Arr::pluck($countOrder, 'sum_price'));
  71. }
  72. /**
  73. * 设置图表数据.
  74. *
  75. * @param array $data
  76. *
  77. * @return \App\AdminSupplier\Metrics\Examples\NewUsers
  78. */
  79. public function withChart(array $data)
  80. {
  81. return $this->chart([
  82. 'series' => [
  83. [
  84. 'name' => $this->title,
  85. 'data' => $data,
  86. ],
  87. ],
  88. ]);
  89. }
  90. /**
  91. * 设置卡片内容.
  92. *
  93. * @param string $content
  94. *
  95. * @return $this
  96. */
  97. public function withContent($content)
  98. {
  99. return $this->content(
  100. <<<HTML
  101. <div class="d-flex justify-content-between align-items-center mt-1" style="margin-bottom: 2px">
  102. <h2 class="ml-1 font-lg-1">{$content}</h2>
  103. <span class="mb-0 mr-1 text-80">{$this->title}</span>
  104. </div>
  105. HTML
  106. );
  107. }
  108. }