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( + <<
{$this->labels[0]} @@ -94,7 +106,13 @@ class NewDevices extends Donut
{$mobile}
+
+
+ {$this->labels[2]} +
+
{$unkonw}
+
HTML - ); - } + ); + } } diff --git a/app/AdminAgent/Metrics/Examples/SalesExamples.php b/app/AdminAgent/Metrics/Examples/SalesExamples.php new file mode 100644 index 0000000..6097141 --- /dev/null +++ b/app/AdminAgent/Metrics/Examples/SalesExamples.php @@ -0,0 +1,179 @@ +colors = [$color->green(), $color->red(), $color->yellow(), $color->orange1(), $color->dark90(), $color->dark70(), $color->custom()]; + $this->contentWidth(3, 9); + $this->title('销售排行'); + //$this->chartPullRight = false; + //$this->subTitle('Last 30 days'); + $this->height = 280; + $this->chartHeight = 250; + // 设置图表颜色 + $this->chartColors($this->colors); + } + + /** + * 渲染模板 + * + * @return string + */ + public function render() + { + $this->fill(); + + return parent::render(); + } + + /** + * 写入数据. + * + * @return void + */ + public function fill() + { + $warehouse = Order::query() + ->with('agentProduct') + ->select('*') + ->addSelect(DB::raw('count(id) as count_id')) + ->where([ + //'status' => OrderStatus::SUCCESS, + 'agent_id' => Admin::user()->id, + ]) + ->orderByDesc('count_id') + ->groupBy('agent_product_id') + ->limit(5) + ->get(); + //$warehouse = []; + $data = $categories = []; + foreach ($warehouse as $v) { + array_push($this->labels, $v->title); + array_push($data, $v->count_id); + $categories[] = [$v->title]; + } + + $this->withChart($data, $categories); + //$this->chartLabels($this->labels); + + $count = Order::query() + ->where([ + //'status' => OrderStatus::SUCCESS, + 'agent_id' => Admin::user()->id, + ]) + ->count(); + //$count = 0; + if ($count > 0) { + array_unshift($data, $count); + array_unshift($this->labels, '总销售量'); + $color = Admin::color(); + array_unshift($this->colors, $color->primary()); + } + $this->withContent($data); + } + + /** + * 设置图表数据. + * + * @param array $data + * + * @return $this + */ + public function withChart($data, $categories) + { + return $this->chart([ + + 'series' => [[ + 'name' => '出库数量', + 'data' => $data + ]], + 'chart' => [ + //'width' => '180%', + 'type' => 'bar', + 'events' => [ + ], + 'toolbar' => ['show' => false], + ], + 'colors' => $this->colors, + 'plotOptions' => [ + 'bar' => [ + //'columnWidth' => '45%', + 'distributed' => true, + ] + ], + 'dataLabels' => [ + 'enabled' => false + ], + 'legend' => [ + 'show' => false + ], + 'xaxis' => [ + 'categories' => + $categories + , + 'labels' => [ + 'show' => false, + 'style' => [ + 'colors' => $this->colors, + 'fontSize' => '12px' + ] + ], + ], + 'yaxis' => [ + 'show' => false + ], + 'tooltip' => [ + 'x' => ['show' => true], + ], + + ]); + } + + /** + * 设置卡片头部内容. + * + * @param mixed $desktop + * @param mixed $mobile + * + * @return $this + */ + protected function withContent($data) + { + $content = ''; + foreach ($data as $k => $v) { + $content .= ' +
+
+ ' . $this->labels[$k] . ' +
' . $v . '
+
+
+ + '; + } + return $this->content( + <<mobile = $decryptedData['purePhoneNumber']; } + $user->unionid = $decryptedData['unionId'] ?? ''; + $user->country = $decryptedData['country'] ?? ''; + $user->province = $decryptedData['province'] ?? ''; + $user->city = $decryptedData['city'] ?? ''; + $user->gender = $decryptedData['gender'] ?? 0; + $user->language = $decryptedData['language'] ?? ''; $user->save(); } catch (\Exception | DecryptException $e) { return $this->error($e->getMessage());