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.
114 lines
3.2 KiB
114 lines
3.2 KiB
<?php
|
|
|
|
|
|
namespace App\Admin\Metrics\Examples\ServiceCard;
|
|
|
|
|
|
use App\Models\ImsCjdcStore;
|
|
use App\Models\LanzuMmInfo;
|
|
use App\Models\LanzuStore;
|
|
use Dcat\Admin\Admin;
|
|
use Dcat\Admin\Widgets\Metrics\Card;
|
|
use Illuminate\Http\Request;
|
|
|
|
class TotalStore extends Card
|
|
{
|
|
|
|
protected $title;
|
|
protected $market_id;
|
|
public function __construct($market_id=null,$title = null, $icon = null)
|
|
{
|
|
$this->title = $title;
|
|
$this->market_id = $market_id;
|
|
parent::__construct($title, $icon);
|
|
}
|
|
protected function init()
|
|
{
|
|
parent::init();
|
|
$this->dropdown([
|
|
'0'=>'全部',
|
|
'1'=>'今日新增',
|
|
'-1'=>'昨日新增',
|
|
'7'=>'过去一周新增',
|
|
'30'=>'本月新增',
|
|
'-30'=>'上月新增'
|
|
]);
|
|
}
|
|
|
|
public function handle(Request $request)
|
|
{
|
|
$type = $request->get('option');//数据选项
|
|
$market_id = $request->get('market_id');//市场id
|
|
$this->content($this->storeNum($type,$market_id));
|
|
}
|
|
|
|
public function storeBuild($type=null,$marketId=null)
|
|
{
|
|
$where = ['status'=>2];
|
|
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=0;
|
|
$endTime=999999999999999;
|
|
break;
|
|
}
|
|
|
|
$build = LanzuStore
|
|
::whereBetween('created_at',[$beginTime,$endTime])
|
|
->where($where);
|
|
return $build;
|
|
}
|
|
|
|
|
|
public function storeNum($type,$marketId)
|
|
{
|
|
$build = $this->storeBuild($type,$marketId);
|
|
$result = $build->count();
|
|
return $result;
|
|
}
|
|
|
|
// 传递自定义参数到 handle 方法
|
|
public function parameters() : array
|
|
{
|
|
return [
|
|
'market_id'=>$this->market_id,
|
|
];
|
|
}
|
|
|
|
|
|
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 text-primary">{$content}</h2>
|
|
</div>
|
|
HTML;
|
|
}
|
|
}
|