链街Dcat后台
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.
 
 
 
 

129 lines
3.7 KiB

<?php
namespace App\Admin\Metrics\Examples\Order;
use App\Models\ImsCjdcOrder;
use App\Models\ImsCjdcOrderMain;
use Dcat\Admin\Widgets\Metrics\Card;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class OrderData extends Card
{
protected $title;
protected $data_type;
protected $market_id;
public function __construct($data_type=null,$market_id=null,$title = null, $icon = null)
{
$this->title = $title;
$this->data_type = $data_type;
$this->market_id = $market_id;
parent::__construct($title, $icon);
}
public function init()
{
parent::init(); // TODO: Change the autogenerated stub
$this->dropdown([
'1'=>'今日',
'-1'=>'昨日',
'7'=>'过去一周',
'30'=>'本月',
'-30'=>'上月'
]);
}
public function handle(Request $request)
{
$type = $request->get('option');//数据选项
$data_type = $request->get('data_type');//数据类型
$market_id = $request->get('market_id');//市场id
$this->content($this->orderNum($data_type,$type,$market_id));
}
public function orderDataBuild($type=null,$marketId=null)
{
$where = [];
$where['type'] = 1;
if ($marketId){
if (is_array($marketId)){
$where[] = ['in'=>['market_id'=>$marketId]];
}else{
$where['market_id'] = $marketId;
}
}
switch ($type){
case '1':
$beginTime=mktime(0,0,0,date('m'),date('d'),date('Y'));
$endTime=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
break;
case '-1':
$beginTime=mktime(0,0,0,date('m'),date('d')-1,date('Y'));
$endTime=mktime(0,0,0,date('m'),date('d'),date('Y'))-1;
break;
case '7':
$beginTime=mktime(0,0,0,date('m'),date('d')-7,date('Y'));
$endTime=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
break;
case '30':
$beginTime=mktime(0,0,0,date('m'),1,date('Y'));
$endTime=mktime(23,59,59,date('m'),date('t'),date('Y'));
break;
case '-30':
$beginTime=mktime(0,0,0,date('m')-1,1,date('Y'));
$endTime=strtotime(date("Y-m-d H:i:s",mktime(23,59,59,date("m") ,0,date("Y"))));
break;
default:
$beginTime=mktime(0,0,0,date('m'),date('d'),date('Y'));
$endTime=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
break;
}
$build = ImsCjdcOrderMain
::whereBetween('created_at',[$beginTime,$endTime])
->whereIn('state',[3,4,5,10])
->where($where);
return $build;
}
public function orderNum($data_type,$type,$marketId)
{
$build = $this->orderDataBuild($type,$marketId);
if ($data_type=='number'){
$result = $build->count();
}elseif ($data_type=='amount'){
$result = $build->sum('money');
}else{
$result = 0;
}
return $result;
}
// 传递自定义参数到 handle 方法
public function parameters() : array
{
return [
'data_type'=>$this->data_type,
'market_id'=>$this->market_id,
];
}
/**
* 渲染卡片内容
* @return string
*/
public function renderContent()
{
$content = parent::renderContent();
return <<<HTML
<div class="d-flex justify-content-between bg-primary align-items-center mt-1" style="margin-bottom: 2px">
<h2 class="ml-1 font-large-1">{$content}</h2>
</div>
HTML;
}
}