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.
120 lines
3.4 KiB
120 lines
3.4 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;
|
|
|
|
class OrderData extends Card
|
|
{
|
|
protected $title;
|
|
protected $data_type;
|
|
public function __construct($data_type=null,$title = null, $icon = null)
|
|
{
|
|
$this->title = $title;
|
|
$this->data_type = $data_type;
|
|
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');//数据类型
|
|
$this->content($this->orderNum($data_type,$type));
|
|
}
|
|
|
|
public function orderNumBuild($marketId=null,$type=null)
|
|
{
|
|
|
|
$where = [];
|
|
$where['type'] = 1;
|
|
if ($marketId){
|
|
$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)
|
|
{
|
|
$build = $this->orderNumBuild($marketId=null,$type);
|
|
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
|
|
];
|
|
}
|
|
|
|
/**
|
|
* 渲染卡片内容
|
|
* @return string
|
|
*/
|
|
public function renderContent()
|
|
{
|
|
$content = parent::renderContent();
|
|
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">{$content}</h2>
|
|
</div>
|
|
HTML;
|
|
}
|
|
}
|