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.
190 lines
7.3 KiB
190 lines
7.3 KiB
<?php
|
|
|
|
|
|
namespace App\Admin\Controllers\v3;
|
|
|
|
|
|
|
|
use App\Admin\Actions\Tools\DataReportDate;
|
|
use App\Admin\Actions\Tools\DataReportOption;
|
|
use App\Admin\Common\Order;
|
|
use App\Admin\Extensions\Chart\Bar\OrderBar;
|
|
use App\Models\ImsCjdcMarket;
|
|
use App\Models\LanzuStore;
|
|
use App\Models\v3\User;
|
|
use Dcat\Admin\Form;
|
|
use Dcat\Admin\Grid;
|
|
use Dcat\Admin\Layout\Column;
|
|
use Dcat\Admin\Layout\Content;
|
|
use Dcat\Admin\Layout\Row;
|
|
use Dcat\Admin\Widgets\Card;
|
|
use http\Message\Body;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class DataReport
|
|
{
|
|
/**
|
|
* 数据报表
|
|
* @param Content $content
|
|
* @return Content
|
|
*/
|
|
protected $_amount;
|
|
protected $_number;
|
|
protected $_count_user;
|
|
public function __construct()
|
|
{
|
|
$option = request()->get('option',1);
|
|
$this->_amount = Order::getOrderData([
|
|
'user_type'=>'market_service',//谁取数据 user_type 用户类型
|
|
'data_type'=>'amount',//取什么数据 data_type 数据类型
|
|
'market_id'=>'',//取哪个市场数据
|
|
'condition'=>1,//取数据维度 condition
|
|
'user_ids'=>null
|
|
],$option);
|
|
$this->_number = Order::getOrderData([
|
|
'user_type'=>'market_service',//谁取数据 user_type 用户类型
|
|
'data_type'=>'number',//取什么数据 data_type 数据类型
|
|
'market_id'=>'',//取哪个市场数据
|
|
'condition'=>1,//取数据维度 condition
|
|
'user_ids'=>null
|
|
],$option);
|
|
$this->_count_user = Order::getOrderData([
|
|
'user_type'=>'market_service',//谁取数据 user_type 用户类型
|
|
'data_type'=>'count_user',//取什么数据 data_type 数据类型
|
|
'market_id'=>'',//取哪个市场数据
|
|
'condition'=>1,//取数据维度 condition
|
|
'user_ids'=>null
|
|
],$option);
|
|
}
|
|
|
|
public function index(Content $content)
|
|
{
|
|
return $content
|
|
->header('数据统计')
|
|
->body(function (Row $row){
|
|
$row->column(4,function (Column $column){
|
|
$column->row(new \App\Admin\Actions\Tools\DataReportTime('data_report'));
|
|
});
|
|
$row->column(2,function (Column $column){
|
|
$markets = ImsCjdcMarket::getMarket();
|
|
$data = [['value'=>0,'label'=>'全部市场']];
|
|
foreach ($markets as $key=>$val){
|
|
$item = [];
|
|
$item['value'] = $key;
|
|
$item['label'] = $val;
|
|
$data[] = $item;
|
|
}
|
|
$column->row(new DataReportOption('data_report',$data));
|
|
});
|
|
|
|
$row->column(6,function (Column $column){
|
|
$column->row(new DataReportDate('data_report'));
|
|
});
|
|
|
|
})->body('<hr />')
|
|
->body(function (Row $row){
|
|
$row->column(2,function (Column $column){
|
|
$title = "订单总额(元)";
|
|
$value = $this->_amount;
|
|
$card = Card::make("<span style='color: #ffffff'>{$title}</span>","<span style='color: #ffffff'>{$value}</span>");
|
|
$card->style('background-color:#4e9876');
|
|
$column->row($card);
|
|
});
|
|
$row->column(2,function (Column $column){
|
|
$title = "订单数";
|
|
$value = $this->_number;
|
|
$card = Card::make("<span style='color: #ffffff'>{$title}</span>","<span style='color: #ffffff'>{$value}</span>");
|
|
$card->style('background-color:#4e9876');
|
|
$column->row($card);
|
|
});
|
|
$row->column(2,function (Column $column) {
|
|
$title = "下单人数";
|
|
$value =$this->_count_user;
|
|
$card = Card::make("<span style='color: #ffffff'>{$title}</span>","<span style='color: #ffffff'>{$value}</span>");
|
|
$card->style('background-color:#4e9876');
|
|
$column->row($card);
|
|
});
|
|
$row->column(2,function (Column $column){
|
|
$title = "人均单价(元)";
|
|
if ($this->_amount){
|
|
$value = sprintf("%.2f",$this->_amount/$this->_count_user);
|
|
}else{
|
|
$value=0;
|
|
}
|
|
|
|
$card = Card::make("<span style='color: #ffffff'>{$title}</span>","<span style='color: #ffffff'>{$value}</span>");
|
|
$card->style('background-color:#4e9876');
|
|
$column->row($card);
|
|
});
|
|
$row->column(2,function (Column $column){
|
|
$title = "有效用户总数";
|
|
$value = User::where('nick_name','!=','')->count();
|
|
$card = Card::make("<span style='color: #ffffff'>{$title}</span>","<span style='color: #ffffff'>{$value}</span>");
|
|
$card->style('background-color:#4e9876');
|
|
$column->row($card);
|
|
});
|
|
$row->column(2,function (Column $column){
|
|
$title = "佣金收入(元)";
|
|
$value = 0;
|
|
$card = Card::make("<span style='color: #ffffff'>{$title}</span>","<span style='color: #ffffff'>{$value}</span>");
|
|
$card->style('background-color:#4e9876');
|
|
$column->row($card);
|
|
});
|
|
})
|
|
->body(function (Row $row){
|
|
$row->column(8,function (Column $column){
|
|
$card = new Card();
|
|
$card->title('订单图表');
|
|
$card->tool(new \App\Admin\Actions\Tools\DataReportOrder('data_report'));
|
|
$card->content(OrderBar::make($this->orderData(['type'=>1])));
|
|
$column->row($card);
|
|
});
|
|
$row->column(4,function (Column $column){
|
|
$card1 = Card::make('1111');
|
|
$card1->style("height:162px");
|
|
$column->row($card1);
|
|
$card2 = Card::make('222');
|
|
$card2->style("height:162px");
|
|
$column->row($card2);
|
|
$card3 = Card::make('222');
|
|
$card3->style("height:162px");
|
|
$column->row($card3);
|
|
});
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 订单数据
|
|
* @param array $params
|
|
* @return array[]|string[]
|
|
*/
|
|
public function orderData($params=[])
|
|
{
|
|
$where['type'] = $params['type'];
|
|
$data = DB::table('lanzu_order_main')
|
|
->select('money')
|
|
->selectRaw("FROM_UNIXTIME(created_at,'%Y-%m-%d') as add_time")
|
|
->where($where)
|
|
->get();
|
|
$time = $num = $amount = [];
|
|
if ($data){
|
|
$data = $data->groupBy('add_time')->toArray();
|
|
foreach ($data as $key=>$val){
|
|
$time[] = $key;
|
|
$num[] = intval(count($val));
|
|
$amount[] = sprintf("%.2f",array_sum(array_column($val,'money')));
|
|
}
|
|
return ['time'=>$time,'num'=>$num,'amount'=>$amount];
|
|
}
|
|
return ['time'=>'','num'=>'','amount'=>''];
|
|
|
|
}
|
|
|
|
|
|
public function getOrderData()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
}
|