4 changed files with 194 additions and 1 deletions
			
			
		- 
					80app/AdminAgent/Controllers/FinanceStatisticsController.php
 - 
					112app/AdminAgent/Metrics/Examples/FinanceStatistics.php
 - 
					2app/AdminAgent/routes.php
 - 
					1resources/lang/zh_CN/global.php
 
@ -0,0 +1,80 @@ | 
				
			|||
<?php | 
				
			|||
 | 
				
			|||
namespace App\AdminAgent\Controllers; | 
				
			|||
 | 
				
			|||
use App\AdminAgent\Metrics\Examples\FinanceStatistics; | 
				
			|||
use Dcat\Admin\Admin; | 
				
			|||
use Dcat\Admin\Layout\Column; | 
				
			|||
use Dcat\Admin\Layout\Content; | 
				
			|||
use Dcat\Admin\Layout\Row; | 
				
			|||
use Dcat\Admin\Http\Controllers\AdminController; | 
				
			|||
use Dcat\Admin\Widgets\Card; | 
				
			|||
 | 
				
			|||
class FinanceStatisticsController extends AdminController | 
				
			|||
{ | 
				
			|||
	public function index(Content $content) | 
				
			|||
	{ | 
				
			|||
		Admin::style( | 
				
			|||
			<<<CSS | 
				
			|||
            .col-sm-12.d-flex{ | 
				
			|||
                    display: inline-block !important; | 
				
			|||
            } | 
				
			|||
            CSS | 
				
			|||
		); | 
				
			|||
		$count = $total = $totalNon = 0; | 
				
			|||
		return $content | 
				
			|||
			->body( | 
				
			|||
				<<<HTML | 
				
			|||
                    <div class="content-header"> | 
				
			|||
                                <section class="content-header breadcrumbs-top"> | 
				
			|||
                                        <h1 class=" float-left"> | 
				
			|||
                                    <span class="text-capitalize">财务统计</span> | 
				
			|||
 | 
				
			|||
                                </h1> | 
				
			|||
                    <div class="clearfix"></div> | 
				
			|||
 | 
				
			|||
                        </section> | 
				
			|||
                        </div> | 
				
			|||
                HTML | 
				
			|||
 | 
				
			|||
			) | 
				
			|||
			->body(function (Row $row) use ($count, $total, $totalNon) { | 
				
			|||
 | 
				
			|||
				$row->column(4, function (Column $column) use ($count) { | 
				
			|||
					$column->row(Card::make('金额', function () use ($count) { | 
				
			|||
						return <<<HTML | 
				
			|||
<div class="d-flex justify-content-between align-items-center mt-1" style="margin-bottom: 2px"> | 
				
			|||
    <h2 class="ml-1 font-large-1 text-primary">$count</h2> | 
				
			|||
</div> | 
				
			|||
HTML; | 
				
			|||
					})); | 
				
			|||
				}); | 
				
			|||
 | 
				
			|||
				$row->column(4, function (Column $column) use ($total) { | 
				
			|||
					$column->row(Card::make('利润', function () use ($total) { | 
				
			|||
						return <<<HTML | 
				
			|||
<div class="d-flex justify-content-between align-items-center mt-1" style="margin-bottom: 2px"> | 
				
			|||
    <h2 class="ml-1 font-large-1 text-primary">$total</h2> | 
				
			|||
</div> | 
				
			|||
HTML; | 
				
			|||
					})); | 
				
			|||
 | 
				
			|||
				}); | 
				
			|||
 | 
				
			|||
				$row->column(4, function (Column $column) use ($totalNon) { | 
				
			|||
					$column->row(Card::make('已完成订单', function () use ($totalNon) { | 
				
			|||
						return <<<HTML | 
				
			|||
<div class="d-flex justify-content-between align-items-center mt-1" style="margin-bottom: 2px"> | 
				
			|||
    <h2 class="ml-1 font-large-1 text-primary">$totalNon</h2> | 
				
			|||
</div> | 
				
			|||
HTML; | 
				
			|||
					})); | 
				
			|||
 | 
				
			|||
				}); | 
				
			|||
 | 
				
			|||
			}) | 
				
			|||
			->body(function (Row $row){ | 
				
			|||
			$row->column(12,new FinanceStatistics()); | 
				
			|||
		}); | 
				
			|||
    } | 
				
			|||
} | 
				
			|||
@ -0,0 +1,112 @@ | 
				
			|||
<?php | 
				
			|||
 | 
				
			|||
namespace App\AdminAgent\Metrics\Examples; | 
				
			|||
 | 
				
			|||
use Dcat\Admin\Admin; | 
				
			|||
use Dcat\Admin\Widgets\Metrics\Bar; | 
				
			|||
use Illuminate\Http\Request; | 
				
			|||
 | 
				
			|||
class FinanceStatistics extends Bar | 
				
			|||
{ | 
				
			|||
    /** | 
				
			|||
     * 初始化卡片内容 | 
				
			|||
     */ | 
				
			|||
    protected function init() | 
				
			|||
    { | 
				
			|||
        parent::init(); | 
				
			|||
 | 
				
			|||
        $color = Admin::color(); | 
				
			|||
        // 卡片内容宽度
 | 
				
			|||
        $this->contentWidth(0, 12); | 
				
			|||
        // 标题
 | 
				
			|||
        //$this->title('财务统计');
 | 
				
			|||
		$this->chartHeight = 500; | 
				
			|||
        // 设置下拉选项
 | 
				
			|||
        $this->dropdown([ | 
				
			|||
            '7' => '日', | 
				
			|||
            '30' => '月', | 
				
			|||
            '365' => '年', | 
				
			|||
        ]); | 
				
			|||
        // 设置图表颜色
 | 
				
			|||
        $this->chartColors([ | 
				
			|||
			$color->green(), | 
				
			|||
        ]); | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * 处理请求 | 
				
			|||
     * | 
				
			|||
     * @param Request $request | 
				
			|||
     * | 
				
			|||
     * @return mixed|void | 
				
			|||
     */ | 
				
			|||
    public function handle(Request $request) | 
				
			|||
    { | 
				
			|||
        switch ($request->get('option')) { | 
				
			|||
            case '7': | 
				
			|||
            default: | 
				
			|||
 | 
				
			|||
 | 
				
			|||
                // 图表数据
 | 
				
			|||
                $this->withChart( | 
				
			|||
                    [75, 125, 225, 175, 125, 75, 25] | 
				
			|||
                ); | 
				
			|||
        } | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * 设置图表数据. | 
				
			|||
     * | 
				
			|||
     * @param array $data | 
				
			|||
     * | 
				
			|||
     * @return $this | 
				
			|||
     */ | 
				
			|||
    public function withChart(array $data) | 
				
			|||
    { | 
				
			|||
		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' => | 
				
			|||
					[75, 125, 225, 175, 125, 75, 25] | 
				
			|||
				, | 
				
			|||
				'labels' => [ | 
				
			|||
					'show' => true, | 
				
			|||
					'style' => [ | 
				
			|||
						'colors' => $this->colors, | 
				
			|||
						'fontSize' => '12px' | 
				
			|||
					] | 
				
			|||
				], | 
				
			|||
			], | 
				
			|||
			'yaxis' => [ | 
				
			|||
				'show' => true | 
				
			|||
			], | 
				
			|||
			'tooltip' => [ | 
				
			|||
				'x' => ['show' => true], | 
				
			|||
			], | 
				
			|||
 | 
				
			|||
		]); | 
				
			|||
    } | 
				
			|||
} | 
				
			|||
						Write
						Preview
					
					
					Loading…
					
					Cancel
						Save
					
		Reference in new issue