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.
		
		
		
		
		
			
		
			
				
					
					
						
							168 lines
						
					
					
						
							5.5 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							168 lines
						
					
					
						
							5.5 KiB
						
					
					
				
								<?php
							 | 
						|
								
							 | 
						|
								namespace App\AdminAgent\Controllers;
							 | 
						|
								
							 | 
						|
								use App\AdminAgent\Metrics\Examples\FinanceStatistics;
							 | 
						|
								use App\Common\PayType;
							 | 
						|
								use App\Models\Order;
							 | 
						|
								use App\Models\OrderProductItem;
							 | 
						|
								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\Box;
							 | 
						|
								use Dcat\Admin\Widgets\Card;
							 | 
						|
								use Dcat\Admin\Widgets\Dropdown;
							 | 
						|
								use Illuminate\Support\Arr;
							 | 
						|
								use Illuminate\Support\Str;
							 | 
						|
								
							 | 
						|
								class FinanceStatisticsController extends AdminController
							 | 
						|
								{
							 | 
						|
									public function index(Content $content)
							 | 
						|
									{
							 | 
						|
										Admin::style(
							 | 
						|
											<<<CSS
							 | 
						|
								            .app-content > .content-wrapper > .content-header{display: none}
							 | 
						|
								            .col-sm-12.d-flex{
							 | 
						|
								                    display: inline-block !important;
							 | 
						|
								            }
							 | 
						|
								            CSS
							 | 
						|
										);
							 | 
						|
								
							 | 
						|
										//数据
							 | 
						|
								
							 | 
						|
										//金额
							 | 
						|
										//线下
							 | 
						|
										$price = Order::query()->where('agent_id',Admin::user()->id)->where('pay_type','=',PayType::OFFLINE)->complete();
							 | 
						|
										//线上
							 | 
						|
										$onlinePrice = Order::query()->where('agent_id',Admin::user()->id)->where('pay_type','!=',PayType::OFFLINE)->complete();
							 | 
						|
										//利润
							 | 
						|
										$costPrice = OrderProductItem::query()->where('agent_id',Admin::user()->id)->whereHas('order',function ($query) {
							 | 
						|
											$query->complete();
							 | 
						|
										});
							 | 
						|
								
							 | 
						|
										//已完成订单
							 | 
						|
										$count = Order::query()->where('agent_id',Admin::user()->id)->complete();
							 | 
						|
								
							 | 
						|
										$dateTime = request('created_at', 0);
							 | 
						|
										if ($dateTime) {
							 | 
						|
											$price->whereBetween('created_at',[$dateTime['start'] . ' 00:00:00',$dateTime['end'].' 23:59:59']);
							 | 
						|
											$costPrice->whereBetween('created_at',[$dateTime['start'] . ' 00:00:00',$dateTime['end'].' 23:59:59']);
							 | 
						|
											$count->whereBetween('created_at',[$dateTime['start'] . ' 00:00:00',$dateTime['end'].' 23:59:59']);
							 | 
						|
											$onlinePrice->whereBetween('created_at',[$dateTime['start'] . ' 00:00:00',$dateTime['end'].' 23:59:59']);
							 | 
						|
										}
							 | 
						|
								
							 | 
						|
										$price = $price->sum('price');
							 | 
						|
										$onlinePrice = $onlinePrice->sum('price');
							 | 
						|
										$costPrice = $costPrice->sum('price');
							 | 
						|
										$profit = bcsub(bcadd($price,$onlinePrice,6),$costPrice,2);
							 | 
						|
										$count = $count->count();
							 | 
						|
										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){
							 | 
						|
												$row->column(12,function (Column $column){
							 | 
						|
													$column->row(new \App\AdminAgent\Tools\DataReportDate('data_report'));
							 | 
						|
												});
							 | 
						|
								
							 | 
						|
											})
							 | 
						|
											->body(function (Row $row) use ($price, $profit, $count,$onlinePrice) {
							 | 
						|
								
							 | 
						|
												$row->column(3, function (Column $column) use ($onlinePrice) {
							 | 
						|
													$column->row(Card::make('线上金额', function () use ($onlinePrice) {
							 | 
						|
														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">$onlinePrice</h2>
							 | 
						|
								</div>
							 | 
						|
								HTML;
							 | 
						|
													}));
							 | 
						|
												});
							 | 
						|
								
							 | 
						|
												$row->column(3, function (Column $column) use ($price) {
							 | 
						|
													$column->row(Card::make('线下金额', function () use ($price) {
							 | 
						|
														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">$price</h2>
							 | 
						|
								</div>
							 | 
						|
								HTML;
							 | 
						|
													}));
							 | 
						|
												});
							 | 
						|
								
							 | 
						|
												$row->column(3, function (Column $column) use ($profit) {
							 | 
						|
													$column->row(Card::make('利润', function () use ($profit) {
							 | 
						|
														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">$profit</h2>
							 | 
						|
								</div>
							 | 
						|
								HTML;
							 | 
						|
													}));
							 | 
						|
								
							 | 
						|
												});
							 | 
						|
								
							 | 
						|
												$row->column(3, 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;
							 | 
						|
													}));
							 | 
						|
								
							 | 
						|
												});
							 | 
						|
								
							 | 
						|
											})
							 | 
						|
											->body(function (Row $row){
							 | 
						|
												// 构建下拉菜单,当点击菜单时发起请求获取数据重新渲染图表
							 | 
						|
												$menu = [
							 | 
						|
													'1' => '日',
							 | 
						|
													'30' => '月',
							 | 
						|
													'365' => '年',
							 | 
						|
												];
							 | 
						|
												$buttonName = '日';
							 | 
						|
												if (Arr::exists($menu, \request()->input('time_key', ''))) {
							 | 
						|
													$buttonName = $menu[\request()->input('time_key')];
							 | 
						|
												}
							 | 
						|
								
							 | 
						|
												$dropdown = Dropdown::make($menu)
							 | 
						|
													->button(current($menu))
							 | 
						|
													->button($buttonName)
							 | 
						|
													->click()
							 | 
						|
													->map(function ($v, $k) {
							 | 
						|
														$querys = \request()->all();
							 | 
						|
														$querys['time_key'] = $k;
							 | 
						|
														$queryString = http_build_query($querys);
							 | 
						|
														$str = Str::after(request()->path(),'/');
							 | 
						|
														$url = admin_url($str.'?'.$queryString);
							 | 
						|
														// 此处设置的 data-xxx 属性会作为post数据发送到后端api
							 | 
						|
														return "<a class='switch-bar' data-option='{$k}' href='$url'>{$v}</a>";
							 | 
						|
													});
							 | 
						|
								
							 | 
						|
												// 传递自定义参数
							 | 
						|
								
							 | 
						|
												$bar = FinanceStatistics::make()
							 | 
						|
													->fetching('$("#my-box").loading()') // 设置loading效果
							 | 
						|
													->fetched('$("#my-box").loading(false)') // 移除loading效果
							 | 
						|
													->click('.switch-bar'); // 设置图表点击菜单则重新发起请求,且被点击的目标元素上的 data-xxx 属性会被作为post数据发送到后端API
							 | 
						|
								
							 | 
						|
												$box = Box::make('财务统计图表', $bar)
							 | 
						|
													->id('my-box') // 设置盒子的ID
							 | 
						|
													->tool($dropdown); // 设置下拉菜单按钮
							 | 
						|
								
							 | 
						|
												$row->column(12, $box);
							 | 
						|
											});
							 | 
						|
								    }
							 | 
						|
								}
							 |