1 changed files with 128 additions and 0 deletions
@ -0,0 +1,128 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace App\Admin\Metrics\Examples; |
||||||
|
|
||||||
|
use App\Models\CompletedOfflineStep; |
||||||
|
use App\Models\Config; |
||||||
|
use App\Models\SelectedDormitory; |
||||||
|
use Dcat\Admin\Widgets\Metrics\Card; |
||||||
|
use Illuminate\Contracts\Support\Renderable; |
||||||
|
use Illuminate\Http\Request; |
||||||
|
|
||||||
|
class ReportRate extends Card |
||||||
|
{ |
||||||
|
/** |
||||||
|
* 卡片底部内容. |
||||||
|
* |
||||||
|
* @var string|Renderable|\Closure |
||||||
|
*/ |
||||||
|
protected $footer; |
||||||
|
|
||||||
|
/** |
||||||
|
* 初始化卡片. |
||||||
|
*/ |
||||||
|
protected function init() |
||||||
|
{ |
||||||
|
parent::init(); |
||||||
|
|
||||||
|
$this->title('新生总报道率'); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 处理请求. |
||||||
|
* |
||||||
|
* @param Request $request |
||||||
|
* |
||||||
|
* @return void |
||||||
|
*/ |
||||||
|
public function handle(Request $request) |
||||||
|
{ |
||||||
|
|
||||||
|
//取出当前年份 |
||||||
|
$config = Config::query()->where([ |
||||||
|
"unique_identification" => "annual_session" |
||||||
|
])->first(); |
||||||
|
|
||||||
|
//当前年份已完成二级学院扫码的学生 |
||||||
|
$allCount = CompletedOfflineStep::query()->where([ |
||||||
|
"annual_session" => $config->data, |
||||||
|
])->select("unique_number")->distinct()->get(); |
||||||
|
|
||||||
|
$this->content($allCount); |
||||||
|
|
||||||
|
if($allCount > 0){ |
||||||
|
$this->up($allCount); |
||||||
|
}else{ |
||||||
|
$this->down($allCount); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @param int $percent |
||||||
|
* |
||||||
|
* @return $this |
||||||
|
*/ |
||||||
|
public function up($percent) |
||||||
|
{ |
||||||
|
return $this->footer( |
||||||
|
"<i class=\"feather icon-trending-up text-success\"></i> {$percent}人 为当前年份已分配床位数" |
||||||
|
); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @param int $percent |
||||||
|
* |
||||||
|
* @return $this |
||||||
|
*/ |
||||||
|
public function down($percent) |
||||||
|
{ |
||||||
|
return $this->footer( |
||||||
|
"<i class=\"feather icon-trending-down text-danger\"></i> {$percent}人 为当前年份已分配床位数" |
||||||
|
); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 设置卡片底部内容. |
||||||
|
* |
||||||
|
* @param string|Renderable|\Closure $footer |
||||||
|
* |
||||||
|
* @return $this |
||||||
|
*/ |
||||||
|
public function footer($footer) |
||||||
|
{ |
||||||
|
$this->footer = $footer; |
||||||
|
|
||||||
|
return $this; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 渲染卡片内容. |
||||||
|
* |
||||||
|
* @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-lg-1">{$content}</h2> |
||||||
|
</div> |
||||||
|
<div class="ml-1 mt-1 font-weight-bold text-80"> |
||||||
|
{$this->renderFooter()} |
||||||
|
</div> |
||||||
|
HTML; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 渲染卡片底部内容. |
||||||
|
* |
||||||
|
* @return string |
||||||
|
*/ |
||||||
|
public function renderFooter() |
||||||
|
{ |
||||||
|
return $this->toString($this->footer); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue