Browse Source

完成新增数据概览

master
崔茂正 11 months ago
parent
commit
f766a0d226
  1. 28
      app/Admin/Controllers/HomeController.php
  2. 3
      app/Admin/Metrics/Chart/ColumnCharts.php
  3. 112
      app/Admin/Metrics/Chart/FemaleColumnCharts.php
  4. 118
      app/Admin/Metrics/Chart/FullPaymentRateColumnCharts.php
  5. 112
      app/Admin/Metrics/Chart/MaleColumnCharts.php
  6. 1
      app/Admin/Metrics/Chart/Registering.php
  7. 154
      app/Admin/Metrics/Examples/FemaleRegistering.php
  8. 164
      app/Admin/Metrics/Examples/FullPaymentRate.php
  9. 154
      app/Admin/Metrics/Examples/MaleRegistering.php
  10. 11
      app/Admin/Metrics/Examples/NewUsers.php
  11. 29
      app/Admin/Metrics/Examples/ReportRate.php
  12. 3
      app/Models/AdmissionNewStudents.php

28
app/Admin/Controllers/HomeController.php

@ -3,7 +3,9 @@ @@ -3,7 +3,9 @@
namespace App\Admin\Controllers;
use App\Admin\Metrics\Chart\ColumnCharts;
use App\Admin\Metrics\Chart\Registering;
use App\Admin\Metrics\Chart\FemaleColumnCharts;
use App\Admin\Metrics\Chart\FullPaymentRateColumnCharts;
use App\Admin\Metrics\Chart\MaleColumnCharts;
use App\Admin\Metrics\Examples;
use App\Admin\Metrics\Examples\AdmissionExcelUsers;
use App\Admin\Metrics\Examples\AdmissionOnLineUser;
@ -29,17 +31,21 @@ class HomeController extends Controller @@ -29,17 +31,21 @@ class HomeController extends Controller
$row->column(12, function (Column $column) {
$column->row(function (Row $row) {
$row->column(6, new Examples\NewUsers());
$row->column(6, new TotalUsers());
$row->column(6, new AdmissionExcelUsers());
$row->column(6, new AdmissionOnLineUser());
$row->column(4, new AdmissionStepUsers());
$row->column(4, new SelectedDormitoryTotal());
$row->column(4, new Examples\ReportRate());
// $row->column(6, new Examples\ProductOrders());
// $row->column(6, new Examples\Sessions());
// $row->column(6, Card::make('各学院报到率',Registering::make()));
$row->column(2, new Examples\NewUsers());
$row->column(2, new TotalUsers());
$row->column(2, new AdmissionExcelUsers());
$row->column(2, new AdmissionOnLineUser());
$row->column(2, new AdmissionStepUsers());
$row->column(2, new SelectedDormitoryTotal());
$row->column(3, new Examples\ReportRate()); //新生总报到率
$row->column(3, new Examples\FullPaymentRate()); //全额缴费率
$row->column(3, new Examples\MaleRegistering()); //男生报到率
$row->column(3, new Examples\FemaleRegistering()); //女生报到率
$row->column(6, Card::make('各学院报到率',ColumnCharts::make()));
$row->column(6, Card::make('各学院全额缴费率',FullPaymentRateColumnCharts::make()));
$row->column(6, Card::make('各学院男生报到率',MaleColumnCharts::make()));
$row->column(6, Card::make('各学院女生报到率',FemaleColumnCharts::make()));
});

3
app/Admin/Metrics/Chart/ColumnCharts.php

@ -64,6 +64,7 @@ class ColumnCharts extends Chart @@ -64,6 +64,7 @@ class ColumnCharts extends Chart
$importStudents = AdmissionNewStudents::query()->where([
"annual_session" => $config->data,
"status" => AdmissionNewStudents::STATUS_YES,
"is_new_student" => AdmissionNewStudents::IS_NEW_STUDENT_YES,
])->whereIn("speciality_id", $specialityIds)->get("idCard")->toArray();
if(!empty($importStudents)){
$idcardList = array_column($importStudents, "idCard");
@ -73,7 +74,7 @@ class ColumnCharts extends Chart @@ -73,7 +74,7 @@ class ColumnCharts extends Chart
$userList = array_column($userList, "unique_number");
//线下迎新有几步
$stepCount = OfflineStep::query()->where("status", OfflineStep::STATUS_YES)->count();
//检测是否存在线下报到步骤,存在则视为已到校
//检测是否存在线下报到步骤,存在则视为已到校(实际报到学生)
$completedOfflineStep = CompletedOfflineStep::query()->whereIn("unique_number", $userList)->where("annual_session", $config->data)->where("step_id",">=",$stepCount)->count();
//报到率

112
app/Admin/Metrics/Chart/FemaleColumnCharts.php

@ -0,0 +1,112 @@ @@ -0,0 +1,112 @@
<?php
namespace App\Admin\Metrics\Chart;
use App\Models\AdmissionNewStudents;
use App\Models\CompletedOfflineStep;
use App\Models\Config;
use App\Models\OfflineStep;
use App\Models\PaymentList;
use App\Models\SecondaryCollege;
use App\Models\Speciality;
use App\Models\UsersMember;
use Dcat\Admin\Widgets\ApexCharts\Chart;
use Illuminate\Support\Facades\DB;
class FemaleColumnCharts extends Chart
{
//各二级学院女生报道率
public function __construct($containerSelector = null, $options = [])
{
parent::__construct($containerSelector, $options);
$this->setUpOptions();
}
//初始化方法,主要是调用$this->options()方法,执行整个option的初始化操作。
protected function setUpOptions()
{
$this->options([
"chart"=>[
"height"=>350, //高度
"type"=>"bar", //chart 类型
],
]);
$data = [[
"name" => "报道率",
"data" => [],
]];
$label = [];
// 执行你的数据查询逻辑
//取出当前年份
$config = Config::query()->where([
"unique_identification" => "annual_session"
])->first();
//二级学院
$list = SecondaryCollege::query()->where([
"status" => SecondaryCollege::STATUS_YES
])->get(["id", "name"])->toArray();
//不为空时
if(!empty($list)){
foreach($list as $key => $item){
//取出该学院下的专业
$speciality = Speciality::query()->where([
"status" => Speciality::STATUS_YES,
"secondary_college_id" => $item["id"],
])->get()->toArray();
//专业ID
$specialityIds = array_column($speciality, "id");
//二级学院已录入的学生
$importStudents = AdmissionNewStudents::query()->where([
"annual_session" => $config->data,
"status" => AdmissionNewStudents::STATUS_YES,
"is_new_student" => AdmissionNewStudents::IS_NEW_STUDENT_YES,
"sex" => AdmissionNewStudents::FEMALE,
])->whereIn("speciality_id", $specialityIds)->get("idCard")->toArray();
if(!empty($importStudents)){
$idcardList = array_column($importStudents, "idCard");
//根据身份证集取出已注册的用户
$userList = UsersMember::query()->whereIn("idcard", $idcardList)->where("status", UsersMember::STATUS_YES)->get("unique_number")->toArray();
if(!empty($userList)){
$userList = array_column($userList, "unique_number");
//线下迎新有几步
$stepCount = OfflineStep::query()->where("status", OfflineStep::STATUS_YES)->count();
//检测是否存在线下报到步骤,存在则视为已到校(实际报到学生)
$completedOfflineStep = CompletedOfflineStep::query()->whereIn("unique_number", $userList)->where("annual_session", $config->data)->where("step_id",">=",$stepCount)->count();
$studentsNum = count($importStudents);
//报到率
$registering = (($completedOfflineStep / $studentsNum) * 100) ;
$list[$key]["registering"] = $registering;
}
}
}
foreach($list as $item){
array_push($label, $item["name"]);
if(!empty($item["registering"])){
array_push($data[0]["data"], $item["registering"]);
}else{
array_push($data[0]["data"], 0);
}
}
}
$this->option("series",$data);
$this->option("labels",$label);
$this->option("yaxis",["max" => 100]); //Y轴最大值
}
}

118
app/Admin/Metrics/Chart/FullPaymentRateColumnCharts.php

@ -0,0 +1,118 @@ @@ -0,0 +1,118 @@
<?php
namespace App\Admin\Metrics\Chart;
use App\Models\AdmissionNewStudents;
use App\Models\CompletedOfflineStep;
use App\Models\Config;
use App\Models\OfflineStep;
use App\Models\PaymentList;
use App\Models\SecondaryCollege;
use App\Models\Speciality;
use App\Models\UsersMember;
use Dcat\Admin\Widgets\ApexCharts\Chart;
use Illuminate\Support\Facades\DB;
class FullPaymentRateColumnCharts extends Chart
{
//各二级学院缴费率
public function __construct($containerSelector = null, $options = [])
{
parent::__construct($containerSelector, $options);
$this->setUpOptions();
}
//初始化方法,主要是调用$this->options()方法,执行整个option的初始化操作。
protected function setUpOptions()
{
$this->options([
"chart"=>[
"height"=>350, //高度
"type"=>"bar", //chart 类型
],
]);
$data = [[
"name" => "缴费率",
"data" => [],
]];
$label = [];
// 执行你的数据查询逻辑
//取出当前年份
$config = Config::query()->where([
"unique_identification" => "annual_session"
])->first();
//二级学院
$list = SecondaryCollege::query()->where([
"status" => SecondaryCollege::STATUS_YES
])->get(["id", "name"])->toArray();
//不为空时
if(!empty($list)){
foreach($list as $key => $item){
//取出该学院下的专业
$speciality = Speciality::query()->where([
"status" => Speciality::STATUS_YES,
"secondary_college_id" => $item["id"],
])->get()->toArray();
//专业ID
$specialityIds = array_column($speciality, "id");
//二级学院已录入的学生
$importStudents = AdmissionNewStudents::query()->where([
"annual_session" => $config->data,
"status" => AdmissionNewStudents::STATUS_YES,
"is_new_student" => AdmissionNewStudents::IS_NEW_STUDENT_YES,
])->whereIn("speciality_id", $specialityIds)->get("idCard")->toArray();
if(!empty($importStudents)){
$idcardList = array_column($importStudents, "idCard");
//根据身份证集取出已注册的用户
$userList = UsersMember::query()->whereIn("idcard", $idcardList)->where("status", UsersMember::STATUS_YES)->get("unique_number")->toArray();
if(!empty($userList)){
$userList = array_column($userList, "unique_number");
//线下迎新有几步
$stepCount = OfflineStep::query()->where("status", OfflineStep::STATUS_YES)->count();
//检测是否存在线下报到步骤,存在则视为已到校(实际报到学生)
$completedOfflineStep = CompletedOfflineStep::query()->whereIn("unique_number", $userList)->where("annual_session", $config->data)->where("step_id",">=",$stepCount)->count();
//全额缴费人数
$paymentList = PaymentList::query()->where("annual_session", $config->data)
->whereIn("unique_number", $userList)
->select('unique_number', DB::raw('SUM(amount) as total_amount'))
->groupBy('unique_number')
->havingRaw('total_amount = ?', [0])
->get()->toArray();
$studentsNum = count($paymentList);
//报到率
$registering = (($studentsNum / $completedOfflineStep ) * 100) ;
$list[$key]["registering"] = $registering;
}
}
}
foreach($list as $item){
array_push($label, $item["name"]);
if(!empty($item["registering"])){
array_push($data[0]["data"], $item["registering"]);
}else{
array_push($data[0]["data"], 0);
}
}
}
$this->option("series",$data);
$this->option("labels",$label);
$this->option("yaxis",["max" => 100]); //Y轴最大值
}
}

112
app/Admin/Metrics/Chart/MaleColumnCharts.php

@ -0,0 +1,112 @@ @@ -0,0 +1,112 @@
<?php
namespace App\Admin\Metrics\Chart;
use App\Models\AdmissionNewStudents;
use App\Models\CompletedOfflineStep;
use App\Models\Config;
use App\Models\OfflineStep;
use App\Models\PaymentList;
use App\Models\SecondaryCollege;
use App\Models\Speciality;
use App\Models\UsersMember;
use Dcat\Admin\Widgets\ApexCharts\Chart;
use Illuminate\Support\Facades\DB;
class MaleColumnCharts extends Chart
{
//各二级学院男生报道率
public function __construct($containerSelector = null, $options = [])
{
parent::__construct($containerSelector, $options);
$this->setUpOptions();
}
//初始化方法,主要是调用$this->options()方法,执行整个option的初始化操作。
protected function setUpOptions()
{
$this->options([
"chart"=>[
"height"=>350, //高度
"type"=>"bar", //chart 类型
],
]);
$data = [[
"name" => "报道率",
"data" => [],
]];
$label = [];
// 执行你的数据查询逻辑
//取出当前年份
$config = Config::query()->where([
"unique_identification" => "annual_session"
])->first();
//二级学院
$list = SecondaryCollege::query()->where([
"status" => SecondaryCollege::STATUS_YES
])->get(["id", "name"])->toArray();
//不为空时
if(!empty($list)){
foreach($list as $key => $item){
//取出该学院下的专业
$speciality = Speciality::query()->where([
"status" => Speciality::STATUS_YES,
"secondary_college_id" => $item["id"],
])->get()->toArray();
//专业ID
$specialityIds = array_column($speciality, "id");
//二级学院已录入的学生
$importStudents = AdmissionNewStudents::query()->where([
"annual_session" => $config->data,
"status" => AdmissionNewStudents::STATUS_YES,
"is_new_student" => AdmissionNewStudents::IS_NEW_STUDENT_YES,
"sex" => AdmissionNewStudents::MALE,
])->whereIn("speciality_id", $specialityIds)->get("idCard")->toArray();
if(!empty($importStudents)){
$idcardList = array_column($importStudents, "idCard");
//根据身份证集取出已注册的用户
$userList = UsersMember::query()->whereIn("idcard", $idcardList)->where("status", UsersMember::STATUS_YES)->get("unique_number")->toArray();
if(!empty($userList)){
$userList = array_column($userList, "unique_number");
//线下迎新有几步
$stepCount = OfflineStep::query()->where("status", OfflineStep::STATUS_YES)->count();
//检测是否存在线下报到步骤,存在则视为已到校(实际报到学生)
$completedOfflineStep = CompletedOfflineStep::query()->whereIn("unique_number", $userList)->where("annual_session", $config->data)->where("step_id",">=",$stepCount)->count();
$studentsNum = count($importStudents);
//报到率
$registering = (($completedOfflineStep / $studentsNum) * 100) ;
$list[$key]["registering"] = $registering;
}
}
}
foreach($list as $item){
array_push($label, $item["name"]);
if(!empty($item["registering"])){
array_push($data[0]["data"], $item["registering"]);
}else{
array_push($data[0]["data"], 0);
}
}
}
$this->option("series",$data);
$this->option("labels",$label);
$this->option("yaxis",["max" => 100]); //Y轴最大值
}
}

1
app/Admin/Metrics/Chart/Registering.php

@ -5,6 +5,7 @@ use Dcat\Admin\Widgets\ApexCharts\Chart; @@ -5,6 +5,7 @@ use Dcat\Admin\Widgets\ApexCharts\Chart;
class Registering extends Chart
{
//饼状图(测试用)
public function __construct($containerSelector = null, $options = [])
{
parent::__construct($containerSelector, $options);

154
app/Admin/Metrics/Examples/FemaleRegistering.php

@ -0,0 +1,154 @@ @@ -0,0 +1,154 @@
<?php
namespace App\Admin\Metrics\Examples;
use App\Models\AdmissionNewStudents;
use App\Models\CompletedOfflineStep;
use App\Models\Config;
use App\Models\PaymentList;
use App\Models\UsersMember;
use Dcat\Admin\Widgets\Metrics\Card;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
/**
* 女生报到率
*/
class FemaleRegistering 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)
{
$number = 0;
$studentsNum = 0;
//取出当前年份
$config = Config::query()->where([
"unique_identification" => "annual_session"
])->first();
//取出当前年份录入的女学生
$importStudents = AdmissionNewStudents::query()->where([
"annual_session" => $config->data,
"status" => AdmissionNewStudents::STATUS_YES,
"is_new_student" => AdmissionNewStudents::IS_NEW_STUDENT_YES,
"sex" => AdmissionNewStudents:: FEMALE,
])->get("idCard")->toArray();
if(!empty($importStudents)){
$idcardList = array_column($importStudents, "idCard");
//根据身份证集取出已注册的用户
$userList = UsersMember::query()->whereIn("idcard", $idcardList)->where("status", UsersMember::STATUS_YES)->get("unique_number")->toArray();
if(!empty($userList)){
$userList = array_column($userList, "unique_number");
//当前年份已完成二级学院扫码的学生(实际报道人数)
$allCount = CompletedOfflineStep::query()->where([
"annual_session" => $config->data,
])->whereIn("unique_number", $userList)->select("unique_number")->distinct()->get()->toArray();
$number = count($allCount);
}
$studentsNum = count($importStudents);
}
if($number == 0 || $studentsNum == 0){
$this->content("0%");
}else{
$this->content((($number / $studentsNum) * 100)."%");
}
}
/**
* @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);
}
}

164
app/Admin/Metrics/Examples/FullPaymentRate.php

@ -0,0 +1,164 @@ @@ -0,0 +1,164 @@
<?php
namespace App\Admin\Metrics\Examples;
use App\Models\AdmissionNewStudents;
use App\Models\CompletedOfflineStep;
use App\Models\Config;
use App\Models\OfflineStep;
use App\Models\PaymentList;
use App\Models\UsersMember;
use Dcat\Admin\Widgets\Metrics\Card;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class FullPaymentRate 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)
{
$number = 0;
$studentsNum = 0;
//取出当前年份
$config = Config::query()->where([
"unique_identification" => "annual_session"
])->first();
//当前年份已完成二级学院扫码的学生(实际报道人数)
$allCount = CompletedOfflineStep::query()->where([
"annual_session" => $config->data,
])->select("unique_number")->distinct()->get()->toArray();
if(!empty($allCount)){
$number = count($allCount);
}
//取出当前年份录入的学生
$importStudents = AdmissionNewStudents::query()->where([
"annual_session" => $config->data,
"status" => AdmissionNewStudents::STATUS_YES,
"is_new_student" => AdmissionNewStudents::IS_NEW_STUDENT_YES,
])->get("idCard")->toArray();
if(!empty($importStudents)){
$idcardList = array_column($importStudents, "idCard");
//根据身份证集取出已注册的用户
$userList = UsersMember::query()->whereIn("idcard", $idcardList)->where("status", UsersMember::STATUS_YES)->get("unique_number")->toArray();
if(!empty($userList)){
$userList = array_column($userList, "unique_number");
//全额缴费人数
$paymentList = PaymentList::query()->where("annual_session", $config->data)
->whereIn("unique_number", $userList)
->select('unique_number', DB::raw('SUM(amount) as total_amount'))
->groupBy('unique_number')
->havingRaw('total_amount = ?', [0])
->get()->toArray();
$studentsNum = count($paymentList);
}
}
if($number == 0 || $studentsNum == 0){
$this->content("0%");
}else{
$this->content((($studentsNum / $number) * 100)."%");
}
}
/**
* @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);
}
}

154
app/Admin/Metrics/Examples/MaleRegistering.php

@ -0,0 +1,154 @@ @@ -0,0 +1,154 @@
<?php
namespace App\Admin\Metrics\Examples;
use App\Models\AdmissionNewStudents;
use App\Models\CompletedOfflineStep;
use App\Models\Config;
use App\Models\PaymentList;
use App\Models\UsersMember;
use Dcat\Admin\Widgets\Metrics\Card;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
/**
* 男生报到率
*/
class MaleRegistering 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)
{
$number = 0;
$studentsNum = 0;
//取出当前年份
$config = Config::query()->where([
"unique_identification" => "annual_session"
])->first();
//取出当前年份录入的男学生
$importStudents = AdmissionNewStudents::query()->where([
"annual_session" => $config->data,
"status" => AdmissionNewStudents::STATUS_YES,
"is_new_student" => AdmissionNewStudents::IS_NEW_STUDENT_YES,
"sex" => AdmissionNewStudents:: MALE,
])->get("idCard")->toArray();
if(!empty($importStudents)){
$idcardList = array_column($importStudents, "idCard");
//根据身份证集取出已注册的用户
$userList = UsersMember::query()->whereIn("idcard", $idcardList)->where("status", UsersMember::STATUS_YES)->get("unique_number")->toArray();
if(!empty($userList)){
$userList = array_column($userList, "unique_number");
//当前年份已完成二级学院扫码的学生(实际报道人数)
$allCount = CompletedOfflineStep::query()->where([
"annual_session" => $config->data,
])->whereIn("unique_number", $userList)->select("unique_number")->distinct()->get()->toArray();
$number = count($allCount);
}
$studentsNum = count($importStudents);
}
if($number == 0 || $studentsNum == 0){
$this->content("0%");
}else{
$this->content((($number / $studentsNum) * 100)."%");
}
}
/**
* @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);
}
}

11
app/Admin/Metrics/Examples/NewUsers.php

@ -20,10 +20,10 @@ class NewUsers extends Line @@ -20,10 +20,10 @@ class NewUsers extends Line
{
parent::init();
$this->title('该时间内注册');
$this->title('七天内注册');
#日期选择开始
$id = $this->id();
/*$id = $this->id();
$this->datepicker($id)
->click("#{$id} .datepicker .btn-primary")
->addVariables([
@ -31,7 +31,7 @@ class NewUsers extends Line @@ -31,7 +31,7 @@ class NewUsers extends Line
'start' => date('Y-m-d', strtotime('-7 days')),
'end' => date('Y-m-d', time()),
]
]);
]);*/
#日期选择结束
}
@ -44,12 +44,13 @@ class NewUsers extends Line @@ -44,12 +44,13 @@ class NewUsers extends Line
*/
public function handle(Request $request)
{
$start = $request->get('started');
$end = $request->get('ended');
$start = $request->get('started', date('Y-m-d', strtotime('-7 days')));
$end = $request->get('ended', date('Y-m-d', time()));
if(empty($start) && empty($end)){
$start = date("Y-m-d 00:00:00", strtotime('-7 days'));
$end = date("Y-m-d 23:59:59", time());
//取出今日注册量
$todayNum = UsersMember::query()->whereBetween("create_time", [strtotime($start), strtotime($end)])->count();
$this->withContent($todayNum.'人');

29
app/Admin/Metrics/Examples/ReportRate.php

@ -5,7 +5,6 @@ namespace App\Admin\Metrics\Examples; @@ -5,7 +5,6 @@ namespace App\Admin\Metrics\Examples;
use App\Models\AdmissionNewStudents;
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;
@ -40,6 +39,9 @@ class ReportRate extends Card @@ -40,6 +39,9 @@ class ReportRate extends Card
public function handle(Request $request)
{
$number = 0;
$studentsNum = 0;
//取出当前年份
$config = Config::query()->where([
"unique_identification" => "annual_session"
@ -48,18 +50,27 @@ class ReportRate extends Card @@ -48,18 +50,27 @@ class ReportRate extends Card
//当前年份已完成二级学院扫码的学生
$allCount = CompletedOfflineStep::query()->where([
"annual_session" => $config->data,
])->select("unique_number")->distinct()->get();
$number = count($allCount);
])->select("unique_number")->distinct()->get()->toArray();
if(!empty($allCount)){
$number = count($allCount);
}
//取出当前年份录入的学生
$studentsList = AdmissionNewStudents::query()->where([
"annual_session" => $config->data,
"status" => AdmissionNewStudents::STATUS_YES
])->select("idCard")->distinct()->get();
$studentsNum = count($studentsList);
$this->content((($number / $studentsNum) * 100)."%");
"status" => AdmissionNewStudents::STATUS_YES,
"is_new_student" => AdmissionNewStudents::IS_NEW_STUDENT_YES
])->select("idCard")->distinct()->get()->toArray();
if(!empty($studentsList)){
$studentsNum = count($studentsList);
}
if($number == 0 || $studentsNum == 0){
$this->content("0%");
}else{
$this->content((($number / $studentsNum) * 100)."%");
}
}

3
app/Models/AdmissionNewStudents.php

@ -35,4 +35,7 @@ class AdmissionNewStudents extends Model @@ -35,4 +35,7 @@ class AdmissionNewStudents extends Model
const STATUS_YES = 1; //状态 1正常 2禁用
const STATUS_NO = 2;
const MALE = 1; //性别 1男 2女
const FEMALE = 2;
}

Loading…
Cancel
Save