|
|
<?phpnamespace 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;
public function __construct($title = null, $icon = null) { $this->title = $title; 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'); $this->content($this->orderNum('',$type)); }
public function orderNum($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; } $count = ImsCjdcOrderMain ::whereBetween('created_at',[$beginTime,$endTime]) ->whereIn('state',[3,4,5,10]) ->where($where) ->count();
return $count; }
/** * 渲染卡片内容 * @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; }}
|