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.

443 lines
17 KiB

6 months ago
<?php
namespace App\Models;
4 weeks ago
use Illuminate\Support\Facades\Log;
6 months ago
use OwenIt\Auditing\Models\Audit;
class CourseSign extends SoftDeletesModel
{
protected $casts = ['file_ids' => 'json', 'fee_file_ids' => 'json', 'data' => 'json', 'change_data' => 'json'];
protected $appends = ['files', 'fee_files', 'status_text', 'fee_status_text'];
public static $intToString = [
'status' => [
0 => '待审核',
1 => '审核通过',
2 => '审核不通过',
3 => '备选',
4 => '已取消',
5 => '主动放弃',
6 => '黑名单'
],
'fee_status' => [
0 => '未缴费',
1 => '缴费成功',
2 => '缴费失败',
3 => '待确认'
],
];
public function getStatusTextAttribute($value)
{
return self::$intToString['status'][$this->status] ?? '';
}
public function getFeeStatusTextAttribute($value)
{
return self::$intToString['fee_status'][$this->fee_status] ?? '';
}
public function getFilesAttribute($value)
{
3 months ago
if (empty($this->file_ids))
return [];
6 months ago
return Upload::whereIn('id', $this->file_ids)->get();
}
public function getFeeFilesAttribute($value)
{
3 months ago
if (empty($this->fee_file_ids))
return [];
6 months ago
return Upload::whereIn('id', $this->fee_file_ids)->get();
}
public function course()
{
return $this->hasOne(Course::class, 'id', 'course_id');
}
public function user()
{
return $this->hasOne(User::class, 'id', 'user_id');
}
/**
* 第三方日志记录
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function thirdAppointmentLogs()
{
return $this->hasMany(ThirdAppointmentLog::class, 'course_sign_id', 'id');
}
3 months ago
/**
2 weeks ago
* 获取学员列表数据
3 months ago
*/
2 weeks ago
public static function getStudentList($start_date = null, $end_date = null, $status = null, $course_ids = null)
3 months ago
{
2 weeks ago
$baseQuery = CourseSign::where(function ($query) use ($course_ids, $status) {
if ($status) {
$query->where('status', $status);
}
if (isset($course_ids)) {
$query->whereIn('course_id', $course_ids);
}
})->whereHas('course', function ($query) use ($start_date, $end_date) {
// 开始结束日期的筛选。or查询
if ($start_date && $end_date) {
$query->whereBetween('start_date', [$start_date, $end_date])
->orWhereBetween('end_date', [$start_date, $end_date]);
}
})->whereNotIn('status', [4, 5, 6]);
2 weeks ago
return $baseQuery;
}
/**
* 指定时间内的报名信息(未去重)
*/
public static function courseSignsTotal($start_date, $end_date, $status = null, $course_ids = null, $retList = false)
{
$totalQuery = self::getStudentList($start_date, $end_date, $status, $course_ids);
3 weeks ago
if ($retList) {
// 返回列表
2 weeks ago
return $totalQuery->get();
3 weeks ago
} else {
2 weeks ago
// 基础数据
2 weeks ago
$baseTotal = $totalQuery->count();
2 weeks ago
// 历史数据
$historyTotal = HistoryCourse::where(function ($query) use ($start_date, $end_date) {
// 开始结束日期的筛选。or查询
2 weeks ago
$query->whereBetween('start_time', [$start_date, $end_date])
->orWhereBetween('end_time', [$start_date, $end_date]);
2 weeks ago
})->where('type', request('course_type_id', 0))->sum('course_type_signs_pass');
3 weeks ago
// 返回统计数据
2 weeks ago
return $historyTotal + $baseTotal;
3 weeks ago
}
3 months ago
}
/**
* 指定时间内的报名信息(去重)
*/
2 weeks ago
public static function courseSignsTotalByUnique($start_date, $end_date, $status = null, $course_ids = null, $retList = false)
3 months ago
{
2 weeks ago
$totalQuery = self::getStudentList($start_date, $end_date, $status, $course_ids);
$user = User::whereIn('id', $totalQuery->get()->pluck('user_id'))->groupBy('mobile')->get();
3 weeks ago
if ($retList) {
// 列表
2 weeks ago
return $user;
3 weeks ago
} else {
2 weeks ago
$baseTotal = $user->count();
// 历史数据
$historyTotal = HistoryCourse::where(function ($query) use ($start_date, $end_date) {
// 开始结束日期的筛选。or查询
2 weeks ago
$query->whereBetween('start_time', [$start_date, $end_date])
->orWhereBetween('end_time', [$start_date, $end_date]);
2 weeks ago
})->where('type', request('course_type_id', 0))->sum('course_type_signs_pass_unique');
3 weeks ago
// 统计数据
2 weeks ago
return $baseTotal + $historyTotal;
3 weeks ago
}
3 months ago
}
3 weeks ago
/**
* 指定时间内的被投企业
*/
2 weeks ago
public static function yhInvested($start_date = null, $end_date = null, $retList = false)
3 weeks ago
{
2 weeks ago
$courseSignByTypeQuery = self::getStudentList($start_date, $end_date, 1, null);
2 weeks ago
$list = Company::whereHas('users', function ($query) use ($courseSignByTypeQuery) {
$query->whereIn('id', $courseSignByTypeQuery->get()->pluck('user_id'));
3 weeks ago
})->where('is_yh_invested', 1)->get();
if ($retList) {
// 返回列表
return $list;
} else {
// 返回统计数据
2 weeks ago
return $list->count();
3 weeks ago
}
3 weeks ago
}
3 weeks ago
/**
* 跟班学员(统计或列表)
* @param string $start_date 开始日期
* @param string $end_date 结束日期
* @param array|null $course_ids 课程ID数组不传则统计所有课程
* @param bool $retList 是否返回列表false返回数量true返回列表
* @return int|\Illuminate\Database\Eloquent\Collection
*/
2 weeks ago
public static function genban($start_date, $end_date, $course_ids = null, $retList = false)
3 weeks ago
{
2 weeks ago
$courseSignsQuery = self::getStudentList($start_date, $end_date, 1, $course_ids);
2 weeks ago
$courseSigns = $courseSignsQuery->whereHas('user', function ($query) {
2 weeks ago
$query->where('from', '%' . '跟班学员' . '%');
2 weeks ago
})->get();
3 weeks ago
if ($retList) {
2 weeks ago
return User::with('company')->whereIn('id', $courseSigns->pluck('user_id'))->get();
3 weeks ago
} else {
2 weeks ago
return User::whereIn('id', $courseSigns->pluck('user_id'))->count();
3 weeks ago
}
}
/**
* 入学后上市公司数量(在指定时间范围内报名的学员所在公司中,在入学后上市的公司数量)
* @param string $start_date 开始日期
* @param string $end_date 结束日期
* @param array|null $course_ids 课程ID数组不传则统计所有课程
* @param bool $retList 是否返回列表false返回数量true返回列表
* @return int|array
*/
public static function companyMarketAfterEnrollment($start_date, $end_date, $course_ids = null, $retList = false)
{
2 weeks ago
$courseSignsQuery = self::getStudentList($start_date, $end_date, null, $course_ids);
$courseSignsForStock = $courseSignsQuery->with('user.company')->get();
3 weeks ago
$companiesAfterEnrollment = [];
foreach ($courseSignsForStock as $sign) {
if ($sign->user && $sign->user->company && $sign->user->company->company_market == 1) {
$signDate = \Carbon\Carbon::parse($sign->created_at)->format('Y-m-d');
$stockDate = $sign->user->company->stock_date;
if ($stockDate && $stockDate >= $signDate) {
$companyId = $sign->user->company->id;
if (!isset($companiesAfterEnrollment[$companyId])) {
$companiesAfterEnrollment[$companyId] = [
'company' => $sign->user->company,
'first_sign_date' => $signDate,
'users' => [],
];
}
if ($retList) {
$companiesAfterEnrollment[$companyId]['users'][] = $sign->user;
}
}
}
}
if ($retList) {
return $companiesAfterEnrollment;
} else {
return count($companiesAfterEnrollment);
}
}
2 weeks ago
/**
* 入学后被投企业数量(在指定时间范围内报名的学员所在公司中,在入学后被投的公司数量)
* @param string $start_date 开始日期
* @param string $end_date 结束日期
* @param array|null $course_ids 课程ID数组不传则统计所有课程
* @param bool $retList 是否返回列表false返回数量true返回列表
* @return int|array
*/
public static function companyInvestedAfterEnrollment($start_date, $end_date, $course_ids = null, $retList = false)
{
$courseSignsQuery = self::getStudentList($start_date, $end_date, 1, $course_ids);
$courseSignsForInvest = $courseSignsQuery->with('user.company')->get();
$companiesAfterEnrollment = [];
foreach ($courseSignsForInvest as $sign) {
if ($sign->user && $sign->user->company && $sign->user->company->is_yh_invested == 1) {
$signDate = \Carbon\Carbon::parse($sign->created_at)->format('Y-m-d');
// 从 project_users 中获取最早的被投时间
$projectUsers = $sign->user->company->project_users;
$investDate = null;
if (!empty($projectUsers) && is_array($projectUsers)) {
foreach ($projectUsers as $projectUser) {
if (!empty($projectUser['investDate'])) {
if ($investDate === null || $projectUser['investDate'] < $investDate) {
$investDate = $projectUser['investDate'];
}
}
}
}
// 被投时间 >= 报名时间,说明是入学后被投
if ($investDate && $investDate >= $signDate) {
$companyId = $sign->user->company->id;
if (!isset($companiesAfterEnrollment[$companyId])) {
$companiesAfterEnrollment[$companyId] = [
'company' => $sign->user->company,
'first_sign_date' => $signDate,
'invest_date' => $investDate,
'users' => [],
];
}
if ($retList) {
$companiesAfterEnrollment[$companyId]['users'][] = $sign->user;
}
}
}
}
if ($retList) {
return $companiesAfterEnrollment;
} else {
return count($companiesAfterEnrollment);
}
}
2 weeks ago
/**
* 区域统计
* @param string $start_date 开始日期
* @param string $end_date 结束日期
* @param array|null $course_ids 课程ID数组不传则统计所有课程
* @param bool $retList 是否返回列表false返回详情true返回列表
*/
public static function area($start_date, $end_date, $status = null, $course_ids = null, $retList = false)
{
2 weeks ago
$courseSignList = self::getStudentList($start_date, $end_date, $status, $course_ids);
2 weeks ago
2 weeks ago
// 地区
$suzhouArea = Company::where('company_city', '苏州市')->pluck('company_area')->unique();
$list = [];
foreach ($suzhouArea as $area) {
2 weeks ago
$sourseSignList2 = (clone $courseSignList)->whereHas('user', function ($query) use ($area) {
$query->whereHas('company', function ($query) use ($area) {
$query->where('company_area', $area);
});
})->get();
2 weeks ago
$list[] = [
'area' => $area,
2 weeks ago
// 未去重
'total' => $sourseSignList2->count(),
// 已去重
2 weeks ago
'total_unique' => User::whereIn('id', $sourseSignList2->pluck('user_id'))->groupBy('mobile')->get()->count(),
2 weeks ago
];
}
2 weeks ago
$courseSignList3 = (clone $courseSignList)->whereHas('user', function ($query) {
$query->whereHas('company', function ($query) {
$query->where('company_city', '!=', '苏州市');
});
})->get();
2 weeks ago
$list[] = [
'area' => '苏州市外',
2 weeks ago
'total' => $courseSignList3->count(),
// 已去重
2 weeks ago
'total_unique' => User::groupBy('mobile')->whereIn('id', $courseSignList3->pluck('user_id'))->get()->count(),
2 weeks ago
];
if ($retList) {
// 返回列表
return $list;
} else {
// 返回统计数据
return $courseSignList->get();
}
}
2 weeks ago
/**
2 weeks ago
* 元和员工参与人员
2 weeks ago
*/
public static function companyJoin($start_date = null, $end_date = null, $course_ids = null, $retList = false)
{
$courseSignsQuery = self::getStudentList($start_date, $end_date, 1, $course_ids);
$courseSignByType = $courseSignsQuery->get();
// 检测关键词
$companyNameKeyword = [
'元禾控股', '元禾原点', '元禾厚望', '元禾重元',
'元禾璞华', '元禾谷风', '元禾绿柳', '元禾辰坤', '元禾沙湖',
'禾裕集团', '苏州科服', '信诚管理咨询',
'集成电路公司', '常州团队', '国企元禾'
];
2 weeks ago
$list = User::whereHas('company', function ($query) use ($companyNameKeyword) {
2 weeks ago
$query->where(function ($q) use ($companyNameKeyword) {
foreach ($companyNameKeyword as $item) {
$q->orWhere('company_name', 'like', '%' . $item . '%');
}
});
})->whereIn('id', $courseSignByType->pluck('user_id'))->get();
2 weeks ago
if ($retList) {
// 返回列表
return $list;
} else {
// 返回统计数据
return $list->count();
}
}
/**
* 干部参与(统计或列表)
* @param string $start_date 开始日期
* @param string $end_date 结束日期
* @param array|null $course_ids 课程ID数组不传则统计所有课程
* @param bool $retList 是否返回列表false返回数量true返回列表
* @return int|\Illuminate\Database\Eloquent\Collection
*/
public static function ganbu($start_date = null, $end_date = null, $course_ids = null, $retList = false)
{
$courseSignsQuery = self::getStudentList($start_date, $end_date, 1, $course_ids);
$courseSigns = $courseSignsQuery->whereHas('user', function ($query) {
2 weeks ago
$query->where('from', '%' . '跟班学员' . '%');
2 weeks ago
})->get();
if ($retList) {
return User::with('company')->whereIn('id', $courseSigns->pluck('user_id'))->get();
} else {
return User::whereIn('id', $courseSigns->pluck('user_id'))->count();
}
}
/**
* 头部企业(统计或列表)
* @param string $start_date 开始日期
* @param string $end_date 结束日期
* @param array|null $course_ids 课程ID数组不传则统计所有课程
* @param bool $retList 是否返回列表false返回数量true返回列表
* @return int|\Illuminate\Database\Eloquent\Collection
*/
public static function toubuqiye($start_date = null, $end_date = null, $course_ids = null, $retList = false)
{
$courseSignsQuery = self::getStudentList($start_date, $end_date, 1, $course_ids);
$courseSignByType = $courseSignsQuery->get();
$list = Company::whereHas('users', function ($query) use ($courseSignByType) {
$query->whereIn('id', $courseSignByType->pluck('user_id'));
})->where('company_tag', 'like', '%' . '高新技术企业' . '%')->get();
if ($retList) {
// 返回列表
return $list;
} else {
// 返回统计数据
return $list->count();
}
}
/**
* 高层次人才
*/
public static function rencai($start_date = null, $end_date = null, $course_ids = null, $retList = false)
{
$courseSignsQuery = self::getStudentList($start_date, $end_date, 1, $course_ids);
2 weeks ago
$courseSigns = $courseSignsQuery->whereHas('course', function ($query) {
2 weeks ago
$query->whereHas('typeDetail', function ($q) {
2 weeks ago
$q->where('name', '人才培训');
});
})->get();
if ($retList) {
return User::whereIn('id', $courseSigns->pluck('user_id'))->get();
} else {
return User::whereIn('id', $courseSigns->pluck('user_id'))->count();
}
}
/**
* 重点上市公司
*/
public static function shangshi($start_date = null, $end_date = null, $course_ids = null, $retList = false)
{
$courseSignsQuery = self::getStudentList($start_date, $end_date, 1, $course_ids);
$list = Company::whereHas('users', function ($query) use ($courseSignsQuery) {
$query->whereIn('id', $courseSignsQuery->get()->pluck('user_id'));
})->where('company_market', 1)->get();
if ($retList) {
2 weeks ago
return $list;
2 weeks ago
} else {
return $list->count();
}
}
6 months ago
}