ProductDownload.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /**
  3. * Created by PhpStorm
  4. * DateTime: 2022/10/3 1:01
  5. *
  6. * @description
  7. */
  8. namespace App\Admin\Metrics\Examples;
  9. use App\Models\Product;
  10. use App\Models\StatProductDownload;
  11. use Dcat\Admin\Admin;
  12. use Dcat\Admin\Grid;
  13. use Dcat\Admin\Widgets\Metrics\Line;
  14. use Illuminate\Http\Request;
  15. use Illuminate\Support\Carbon;
  16. class ProductDownload extends Line
  17. {
  18. protected $title = '下载数据';
  19. /**
  20. * 初始化卡片内容
  21. */
  22. public function init()
  23. {
  24. parent::init();
  25. $color = Admin::color();
  26. // 标题
  27. $this->title($this->title);
  28. // $this->height(380);
  29. // $this->chartHeight(330);
  30. // $this->chartOption('chart.sparkline.enabled', false);
  31. // $this->chartOption('legend.position', 'top');
  32. // $this->chartColors([$color->primary(), $color]);
  33. //
  34. // $this->chartOption('stroke.width', [2.5, 2.5]);
  35. // $this->chartOption('stroke.dashArray', [0, 5]);
  36. //
  37. // $this->chartSmooth();
  38. //
  39. // // 卡片内容
  40. // $this->withContent(mt_rand(1000, 5000).'k');
  41. $this->content($this->grid());
  42. }
  43. public function grid()
  44. {
  45. $grid = new Grid();
  46. $grid->filter(function (Grid\Filter $filter) {
  47. $filter->panel();
  48. $filter->equal('product_id')->select(function (){
  49. return Product::select(['id','name'])->get()->pluck('name','id')->toArray();
  50. })->width(2);
  51. $filter->like('name')->width(2);
  52. });
  53. return $grid;
  54. }
  55. public function handle(Request $request)
  56. {
  57. // dd($contractNum);
  58. $this->withChart($this->contractNum, $this->receiptNum);
  59. }
  60. public function withContent($content)
  61. {
  62. return $this->content(
  63. <<<HTML
  64. <div class="d-flex justify-content-between align-items-center mt-1" style="margin-bottom: 2px">
  65. <h2 class="ml-1 font-lg-1">{$content}</h2>
  66. <span class="mb-0 mr-1 text-80">{$this->label}</span>
  67. </div>
  68. HTML
  69. );
  70. }
  71. public function withChart($series)
  72. {
  73. return $this->chart([
  74. 'series' => [$series],
  75. 'xaxis' => [
  76. 'categories' => $this->categories
  77. ],
  78. ]);
  79. }
  80. }