7 changed files with 635 additions and 168 deletions
			
			
		- 
					18app/Admin/Controllers/HomeController.php
 - 
					13app/Admin/Metrics/Examples/Dashboard.php
 - 
					189app/Admin/Metrics/Examples/NewUsers.php
 - 
					160app/Admin/Metrics/Examples/OrderExamples.php
 - 
					203app/Admin/Metrics/Examples/ProductOrders.php
 - 
					177app/Admin/Metrics/Examples/SalesExamples.php
 - 
					43resources/views/admin/pages/admin-home.blade.php
 
@ -0,0 +1,13 @@ | 
			
		|||||
 | 
				<?php | 
			
		||||
 | 
				
 | 
			
		||||
 | 
				namespace App\Admin\Metrics\Examples; | 
			
		||||
 | 
				
 | 
			
		||||
 | 
				use Dcat\Admin\Admin; | 
			
		||||
 | 
				
 | 
			
		||||
 | 
				class Dashboard | 
			
		||||
 | 
				{ | 
			
		||||
 | 
				    public static function title() | 
			
		||||
 | 
				    { | 
			
		||||
 | 
				        return view('admin::pages.admin-home', ['admin' => Admin::user()]); | 
			
		||||
 | 
				    } | 
			
		||||
 | 
				} | 
			
		||||
@ -0,0 +1,160 @@ | 
			
		|||||
 | 
				<?php | 
			
		||||
 | 
				
 | 
			
		||||
 | 
				namespace App\Admin\Metrics\Examples; | 
			
		||||
 | 
				
 | 
			
		||||
 | 
				use App\Common\OrderStatus; | 
			
		||||
 | 
				use App\Models\Order; | 
			
		||||
 | 
				use Carbon\Carbon; | 
			
		||||
 | 
				use Dcat\Admin\Admin; | 
			
		||||
 | 
				use Dcat\Admin\Widgets\Metrics\RadialBar; | 
			
		||||
 | 
				use Illuminate\Http\Request; | 
			
		||||
 | 
				use Illuminate\Support\Arr; | 
			
		||||
 | 
				use Illuminate\Support\Facades\DB; | 
			
		||||
 | 
				
 | 
			
		||||
 | 
				class OrderExamples extends RadialBar | 
			
		||||
 | 
				{ | 
			
		||||
 | 
					/** | 
			
		||||
 | 
					 * 初始化卡片内容 | 
			
		||||
 | 
					 */ | 
			
		||||
 | 
					protected function init() | 
			
		||||
 | 
					{ | 
			
		||||
 | 
						parent::init(); | 
			
		||||
 | 
				
 | 
			
		||||
 | 
						$this->title('订单统计'); | 
			
		||||
 | 
						$this->height(400); | 
			
		||||
 | 
						$this->chartHeight(300); | 
			
		||||
 | 
					} | 
			
		||||
 | 
				
 | 
			
		||||
 | 
					/** | 
			
		||||
 | 
					 * 处理请求 | 
			
		||||
 | 
					 * | 
			
		||||
 | 
					 * @param Request $request | 
			
		||||
 | 
					 * | 
			
		||||
 | 
					 * @return mixed|void | 
			
		||||
 | 
					 */ | 
			
		||||
 | 
					public function handle(Request $request) | 
			
		||||
 | 
					{ | 
			
		||||
 | 
						//总订单数
 | 
			
		||||
 | 
						$count = Order::query()->count(); | 
			
		||||
 | 
						// 卡片内容
 | 
			
		||||
 | 
						$this->withContent($count); | 
			
		||||
 | 
						// 卡片底部
 | 
			
		||||
 | 
						//今日订单
 | 
			
		||||
 | 
						$countToday = Order::query()->whereDate('created_at',Carbon::today())->count(); | 
			
		||||
 | 
						$countYesterday = Order::query()->whereDate('created_at',Carbon::yesterday())->count(); | 
			
		||||
 | 
						$price = Order::query()->where('status',OrderStatus::SUCCESS)->whereDate('created_at',Carbon::today())->sum('price'); | 
			
		||||
 | 
						$this->withFooter($countToday, $countYesterday, $price); | 
			
		||||
 | 
						$order = Order::query() | 
			
		||||
 | 
							->select('*') | 
			
		||||
 | 
							->addSelect(DB::raw("COUNT(id) as count_id,CONCAT(YEAR(created_at),'-',MONTH(created_at),'-',DAY(created_at)) AS statistics_time")) | 
			
		||||
 | 
							->limit(30) | 
			
		||||
 | 
							->orderBy('created_at', 'asc') | 
			
		||||
 | 
							->groupBy('statistics_time') | 
			
		||||
 | 
							->get() | 
			
		||||
 | 
							->toArray(); | 
			
		||||
 | 
				
 | 
			
		||||
 | 
						$categories = Arr::pluck($order,'statistics_time'); | 
			
		||||
 | 
						// 图表数据
 | 
			
		||||
 | 
						$data = Arr::pluck($order,'count_id'); | 
			
		||||
 | 
						$this->withChart($data,$categories); | 
			
		||||
 | 
				
 | 
			
		||||
 | 
					} | 
			
		||||
 | 
				
 | 
			
		||||
 | 
					/** | 
			
		||||
 | 
					 * 设置图表数据. | 
			
		||||
 | 
					 * | 
			
		||||
 | 
					 * @param int $data | 
			
		||||
 | 
					 * | 
			
		||||
 | 
					 * @return $this | 
			
		||||
 | 
					 */ | 
			
		||||
 | 
					public function withChart(array $data,array $categories) | 
			
		||||
 | 
					{ | 
			
		||||
 | 
						return $this->chart([ | 
			
		||||
 | 
							'series' => [ | 
			
		||||
 | 
								[ | 
			
		||||
 | 
									'name' => '订单量', | 
			
		||||
 | 
									'data' => $data | 
			
		||||
 | 
								] | 
			
		||||
 | 
							], | 
			
		||||
 | 
							'chart' => [ | 
			
		||||
 | 
								'type' => 'line', | 
			
		||||
 | 
								'zoom' => [ | 
			
		||||
 | 
									'enabled' => false | 
			
		||||
 | 
								], | 
			
		||||
 | 
								'toolbar' => [ | 
			
		||||
 | 
									'show' => false | 
			
		||||
 | 
								], | 
			
		||||
 | 
							], | 
			
		||||
 | 
							'colors' => [ | 
			
		||||
 | 
								Admin::color()->green(), | 
			
		||||
 | 
							], | 
			
		||||
 | 
							'dataLabels' => [ | 
			
		||||
 | 
								'enabled' => false | 
			
		||||
 | 
							], | 
			
		||||
 | 
							'stroke' => [ | 
			
		||||
 | 
								'curve' => 'smooth' | 
			
		||||
 | 
							], | 
			
		||||
 | 
							'legend' => [ | 
			
		||||
 | 
								'position' =>'top', | 
			
		||||
 | 
								//'horizontalAlign' => 'right'
 | 
			
		||||
 | 
							], | 
			
		||||
 | 
							'fill' => [ | 
			
		||||
 | 
								'opacity' => 1, | 
			
		||||
 | 
								'type' => 'solid', | 
			
		||||
 | 
							], | 
			
		||||
 | 
							'xaxis' => [ | 
			
		||||
 | 
								'categories' => $categories, | 
			
		||||
 | 
							] | 
			
		||||
 | 
						]); | 
			
		||||
 | 
					} | 
			
		||||
 | 
				
 | 
			
		||||
 | 
					/** | 
			
		||||
 | 
					 * 卡片内容 | 
			
		||||
 | 
					 * | 
			
		||||
 | 
					 * @param string $content | 
			
		||||
 | 
					 * | 
			
		||||
 | 
					 * @return $this | 
			
		||||
 | 
					 */ | 
			
		||||
 | 
					public function withContent($content) | 
			
		||||
 | 
					{ | 
			
		||||
 | 
						return $this->content( | 
			
		||||
 | 
							<<<HTML | 
			
		||||
 | 
				<div class="d-flex flex-column flex-wrap text-left p-1"> | 
			
		||||
 | 
				    <h1 class="font-lg-2 mt-2 mb-0">{$content}</h1> | 
			
		||||
 | 
				    <small>总订单数</small> | 
			
		||||
 | 
				</div> | 
			
		||||
 | 
				HTML | 
			
		||||
 | 
						); | 
			
		||||
 | 
					} | 
			
		||||
 | 
				
 | 
			
		||||
 | 
					/** | 
			
		||||
 | 
					 * 卡片底部内容. | 
			
		||||
 | 
					 * | 
			
		||||
 | 
					 * @param string $new | 
			
		||||
 | 
					 * @param string $open | 
			
		||||
 | 
					 * @param string $response | 
			
		||||
 | 
					 * | 
			
		||||
 | 
					 * @return $this | 
			
		||||
 | 
					 */ | 
			
		||||
 | 
					public function withFooter($new, $open, $response) | 
			
		||||
 | 
					{ | 
			
		||||
 | 
						return $this->footer( | 
			
		||||
 | 
							<<<HTML | 
			
		||||
 | 
				<div class="d-flex justify-content-between p-1" style="padding-top: 0!important;"> | 
			
		||||
 | 
				    <div class="text-center"> | 
			
		||||
 | 
				        <p>今日订单</p> | 
			
		||||
 | 
				        <span class="font-lg-1">{$new}</span> | 
			
		||||
 | 
				    </div> | 
			
		||||
 | 
				    <div class="text-center"> | 
			
		||||
 | 
				        <p>昨日订单</p> | 
			
		||||
 | 
				        <span class="font-lg-1">{$open}</span> | 
			
		||||
 | 
				    </div> | 
			
		||||
 | 
				    <div class="text-center"> | 
			
		||||
 | 
				        <p>今日成交(元)</p> | 
			
		||||
 | 
				        <span class="font-lg-1">{$response}</span> | 
			
		||||
 | 
				    </div> | 
			
		||||
 | 
				</div> | 
			
		||||
 | 
				HTML | 
			
		||||
 | 
						); | 
			
		||||
 | 
					} | 
			
		||||
 | 
				} | 
			
		||||
@ -0,0 +1,177 @@ | 
			
		|||||
 | 
				<?php | 
			
		||||
 | 
				
 | 
			
		||||
 | 
				namespace App\Admin\Metrics\Examples; | 
			
		||||
 | 
				
 | 
			
		||||
 | 
				use App\Common\OrderStatus; | 
			
		||||
 | 
				use App\Models\Order; | 
			
		||||
 | 
				use Dcat\Admin\Admin; | 
			
		||||
 | 
				use Dcat\Admin\Widgets\Metrics\Bar; | 
			
		||||
 | 
				
 | 
			
		||||
 | 
				use Illuminate\Support\Facades\DB; | 
			
		||||
 | 
				
 | 
			
		||||
 | 
				class SalesExamples extends Bar | 
			
		||||
 | 
				{ | 
			
		||||
 | 
					protected $labels = []; | 
			
		||||
 | 
					protected $colors; | 
			
		||||
 | 
				
 | 
			
		||||
 | 
					/** | 
			
		||||
 | 
					 * 初始化卡片内容 | 
			
		||||
 | 
					 */ | 
			
		||||
 | 
					protected function init() | 
			
		||||
 | 
					{ | 
			
		||||
 | 
						parent::init(); | 
			
		||||
 | 
				
 | 
			
		||||
 | 
						$color = Admin::color(); | 
			
		||||
 | 
						$this->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, | 
			
		||||
 | 
							]) | 
			
		||||
 | 
							->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, | 
			
		||||
 | 
							]) | 
			
		||||
 | 
							->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 .= ' | 
			
		||||
 | 
				            <div class="d-flex pl-1 mt-2"> | 
			
		||||
 | 
				       <div style="width:100%;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;"> | 
			
		||||
 | 
				            <i class="fa fa-circle" style="color:' . $this->colors[$k] . '"></i> ' . $this->labels[$k] . ' | 
			
		||||
 | 
				             <div style="display:inline-block">' . $v . '</div> | 
			
		||||
 | 
				    </div> | 
			
		||||
 | 
				    </div> | 
			
		||||
 | 
				
 | 
			
		||||
 | 
				         '; | 
			
		||||
 | 
						} | 
			
		||||
 | 
						return $this->content( | 
			
		||||
 | 
							<<<HTML | 
			
		||||
 | 
				                $content | 
			
		||||
 | 
				        HTML | 
			
		||||
 | 
						); | 
			
		||||
 | 
					} | 
			
		||||
 | 
				} | 
			
		||||
@ -0,0 +1,43 @@ | 
			
		|||||
 | 
				<style> | 
			
		||||
 | 
				    .dashboard-title .links { | 
			
		||||
 | 
				        text-align: center; | 
			
		||||
 | 
				        margin-bottom: 2.5rem; | 
			
		||||
 | 
				    } | 
			
		||||
 | 
				    .dashboard-title .links > a { | 
			
		||||
 | 
				        padding: 0 25px; | 
			
		||||
 | 
				        font-size: 12px; | 
			
		||||
 | 
				        font-weight: 600; | 
			
		||||
 | 
				        letter-spacing: .1rem; | 
			
		||||
 | 
				        text-decoration: none; | 
			
		||||
 | 
				        text-transform: uppercase; | 
			
		||||
 | 
				        color: #fff;
 | 
			
		||||
 | 
				    } | 
			
		||||
 | 
				    .dashboard-title h1 { | 
			
		||||
 | 
				        font-weight: 200; | 
			
		||||
 | 
				        font-size: 2.5rem; | 
			
		||||
 | 
				    } | 
			
		||||
 | 
				    .dashboard-title .avatar { | 
			
		||||
 | 
				        background: #fff;
 | 
			
		||||
 | 
				        border: 2px solid #fff;
 | 
			
		||||
 | 
				        width: 70px; | 
			
		||||
 | 
				        height: 70px; | 
			
		||||
 | 
				    } | 
			
		||||
 | 
				</style> | 
			
		||||
 | 
				
 | 
			
		||||
 | 
				<div class="dashboard-title card bg-primary"> | 
			
		||||
 | 
				    <div class="card-body"> | 
			
		||||
 | 
				        <div class="text-center "> | 
			
		||||
 | 
				            <img class="avatar img-circle shadow mt-1" src="{{config('filesystems.disks.oss.cdnDomain').'/'.$admin->avatar}}"> | 
			
		||||
 | 
				
 | 
			
		||||
 | 
				            <div class="text-center mb-1"> | 
			
		||||
 | 
				                <h1 class="mb-3 mt-2 text-white">{{$admin->name}}</h1> | 
			
		||||
 | 
				                <div class="links"> | 
			
		||||
 | 
				                    <a href="{{ admin_url('/supplier/list') }}">供应商管理</a> | 
			
		||||
 | 
				                    <a href="{{ admin_url('/agent/list') }}" id="doc-link">代理商管理</a> | 
			
		||||
 | 
				                    <a href="{{ admin_url('/guide/list') }}" id="demo-link">地接管理</a> | 
			
		||||
 | 
				                    <a href="{{ admin_url('/product/audit') }}" id="demo-link">产品审核</a> | 
			
		||||
 | 
				                </div> | 
			
		||||
 | 
				            </div> | 
			
		||||
 | 
				        </div> | 
			
		||||
 | 
				    </div> | 
			
		||||
 | 
				</div> | 
			
		||||
						Write
						Preview
					
					
					Loading…
					
					Cancel
						Save
					
		Reference in new issue