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

127 lines
2.7 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
  1. <?php
  2. namespace App\AdminSupplier\Metrics\Examples;
  3. use App\Common\AgentType;
  4. use App\Common\ProductStatus;
  5. use App\Models\Agent as AgentModel;
  6. use Dcat\Admin\Admin;
  7. use Dcat\Admin\Widgets\Metrics\Donut;
  8. class NewDevices extends Donut
  9. {
  10. protected $labels = [];
  11. /**
  12. * 初始化卡片内容
  13. */
  14. protected function init()
  15. {
  16. parent::init();
  17. $this->labels = array_values(AgentType::array());
  18. $color = Admin::color();
  19. $colors = [$color->primary(), $color->alpha('blue2', 0.5),Admin::color()->yellow()];
  20. $this->title('代理商类型');;
  21. $this->chartLabels($this->labels);
  22. // 设置图表颜色
  23. $this->chartColors($colors);
  24. }
  25. /**
  26. * 渲染模板
  27. *
  28. * @return string
  29. */
  30. public function render()
  31. {
  32. $this->fill();
  33. return parent::render();
  34. }
  35. /**
  36. * 写入数据.
  37. *
  38. * @return void
  39. */
  40. public function fill()
  41. {
  42. $agent = AgentModel::whereHas('agentProduct', function($query) {
  43. //只统计在售产品的代理商
  44. return $query->where('status', ProductStatus::ON_SALE)
  45. ->whereHas('product', function ($query) {
  46. return $query->where(['supplier_id' => Admin::user()->id, 'status' => ProductStatus::ON_SALE]);
  47. });
  48. });
  49. $agent = $agent->pluck('type');
  50. $operator = $supplier = $cluster = 0;
  51. foreach ($agent as $v) {
  52. if ($v == AgentType::OPERATOR) {
  53. $operator++;
  54. } elseif ($v == AgentType::SUPPLIER) {
  55. $supplier++;
  56. } elseif($v == AgentType::CLUSTER) {
  57. $cluster++;
  58. }
  59. }
  60. $this->withContent($operator, $supplier, $cluster);
  61. // 图表数据
  62. $this->withChart([$operator,$supplier, $cluster]);
  63. }
  64. /**
  65. * 设置图表数据.
  66. *
  67. * @param array $data
  68. *
  69. * @return $this
  70. */
  71. public function withChart(array $data)
  72. {
  73. return $this->chart([
  74. 'series' => $data
  75. ]);
  76. }
  77. /**
  78. * 设置卡片头部内容.
  79. *
  80. * @param mixed $desktop
  81. * @param mixed $mobile
  82. *
  83. * @return $this
  84. */
  85. protected function withContent($desktop, $mobile, $unkonw)
  86. {
  87. $blue = Admin::color()->alpha('blue2', 0.5);
  88. $yellow = Admin::color()->yellow();
  89. $style = 'margin-bottom: 8px';
  90. $labelWidth = 120;
  91. return $this->content(
  92. <<<HTML
  93. <div class="d-flex pl-1 pr-1 pt-1" style="{$style}">
  94. <div style="width: {$labelWidth}px">
  95. <i class="fa fa-circle text-primary"></i> {$this->labels[0]}
  96. </div>
  97. <div>{$desktop}</div>
  98. </div>
  99. <div class="d-flex pl-1 pr-1" style="{$style}">
  100. <div style="width: {$labelWidth}px">
  101. <i class="fa fa-circle" style="color: $blue"></i> {$this->labels[1]}
  102. </div>
  103. <div>{$mobile}</div>
  104. </div>
  105. <div class="d-flex pl-1 pr-1" style="{$style}">
  106. <div style="width: {$labelWidth}px">
  107. <i class="fa fa-circle" style="color: $yellow"></i> {$this->labels[2]}
  108. </div>
  109. <div>{$unkonw}</div>
  110. </div>
  111. HTML
  112. );
  113. }
  114. }