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.
124 lines
2.5 KiB
124 lines
2.5 KiB
<?php |
|
|
|
namespace App\Admin\Metrics\Examples; |
|
|
|
use App\Models\UsersMember; |
|
use Dcat\Admin\Widgets\Metrics\Card; |
|
use Illuminate\Contracts\Support\Renderable; |
|
use Illuminate\Http\Request; |
|
|
|
class TotalUsers 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) |
|
{ |
|
|
|
//注册总人数 |
|
$allCount = UsersMember::query()->count(); |
|
$this->content($allCount); |
|
|
|
//取出开始到前一天的注册人数 |
|
$today = date("Y-m-d"); |
|
$yesterday = date("Y-m-d 23:59:59", strtotime("-1 day", strtotime($today))); |
|
$yeserCount = UsersMember::query()->whereBetween("create_time", [0, strtotime($yesterday)])->count(); |
|
|
|
$num = $allCount - $yeserCount; |
|
if($num > 0 ){ |
|
$this->up($num); |
|
}else{ |
|
$this->down($num); |
|
} |
|
|
|
} |
|
|
|
/** |
|
* @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); |
|
} |
|
}
|
|
|