diff --git a/app/AdminAgent/Controllers/HomeController.php b/app/AdminAgent/Controllers/HomeController.php index 495802c..ac492f2 100644 --- a/app/AdminAgent/Controllers/HomeController.php +++ b/app/AdminAgent/Controllers/HomeController.php @@ -18,7 +18,11 @@ class HomeController extends Controller .col-sm-10.d-flex{ display: inline-block !important; } - CSS ); + .col-sm-9.d-flex{ + display: inline-block !important; + } + CSS + ); return $content ->header('代理商后台') ->description('数据详情') @@ -34,7 +38,7 @@ class HomeController extends Controller $row->column(6, new Examples\NewDevices()); }); - $column->row(new Examples\Sessions()); + $column->row(new Examples\SalesExamples()); $column->row(new Examples\ProductOrders()); }); }); diff --git a/app/AdminAgent/Metrics/Examples/NewDevices.php b/app/AdminAgent/Metrics/Examples/NewDevices.php index 7ea611f..5526e38 100644 --- a/app/AdminAgent/Metrics/Examples/NewDevices.php +++ b/app/AdminAgent/Metrics/Examples/NewDevices.php @@ -2,86 +2,98 @@ namespace App\AdminAgent\Metrics\Examples; +use App\Models\User; use Dcat\Admin\Admin; use Dcat\Admin\Widgets\Metrics\Donut; +use Illuminate\Support\Arr; class NewDevices extends Donut { - protected $labels = ['Desktop', 'Mobile']; + protected $labels = ['男性', '女性', '未知']; - /** - * 初始化卡片内容 - */ - protected function init() - { - parent::init(); + /** + * 初始化卡片内容 + */ + protected function init() + { + parent::init(); - $color = Admin::color(); - $colors = [$color->primary(), $color->alpha('blue2', 0.5)]; + $color = Admin::color(); + $colors = [$color->primary(), $color->alpha('blue2', 0.5)]; - $this->title('New Devices'); - $this->subTitle('Last 30 days'); - $this->chartLabels($this->labels); - // 设置图表颜色 - $this->chartColors($colors); - } + $this->title('用户性别');; + $this->chartLabels($this->labels); + // 设置图表颜色 + $this->chartColors($colors); + } - /** - * 渲染模板 - * - * @return string - */ - public function render() - { - $this->fill(); + /** + * 渲染模板 + * + * @return string + */ + public function render() + { + $this->fill(); - return parent::render(); - } + return parent::render(); + } - /** - * 写入数据. - * - * @return void - */ - public function fill() - { - $this->withContent(44.9, 28.6); + /** + * 写入数据. + * + * @return void + */ + public function fill() + { + $gender = User::query()->where('agent_id', Admin::user()->id)->pluck('gender'); + $man = $woman = $unkonw = 0; + foreach ($gender as $v) { + if ($v == 1) { + $man++; + } elseif ($v == 2) { + $woman++; + } else { + $unkonw++; + } + } + $this->withContent($man, $woman, $unkonw); - // 图表数据 - $this->withChart([44.9, 28.6]); - } + // 图表数据 + $this->withChart([$man,$woman, $unkonw]); + } - /** - * 设置图表数据. - * - * @param array $data - * - * @return $this - */ - public function withChart(array $data) - { - return $this->chart([ - 'series' => $data - ]); - } + /** + * 设置图表数据. + * + * @param array $data + * + * @return $this + */ + public function withChart(array $data) + { + return $this->chart([ + 'series' => $data + ]); + } - /** - * 设置卡片头部内容. - * - * @param mixed $desktop - * @param mixed $mobile - * - * @return $this - */ - protected function withContent($desktop, $mobile) - { - $blue = Admin::color()->alpha('blue2', 0.5); + /** + * 设置卡片头部内容. + * + * @param mixed $desktop + * @param mixed $mobile + * + * @return $this + */ + protected function withContent($desktop, $mobile, $unkonw) + { + $blue = Admin::color()->alpha('blue2', 0.5); + $yellow = Admin::color()->yellow(); + $style = 'margin-bottom: 8px'; + $labelWidth = 120; - $style = 'margin-bottom: 8px'; - $labelWidth = 120; - - return $this->content( - <<content( + <<