|
|
|
|
@ -21,22 +21,16 @@ class CourseAppointmentTotal extends SoftDeletesModel
|
|
|
|
|
*/
|
|
|
|
|
public static function addByCourse($courseId)
|
|
|
|
|
{
|
|
|
|
|
// 判断课程是否已生成预约次数
|
|
|
|
|
// $has = self::where('course_id', $courseId)->first();
|
|
|
|
|
// if ($has) return true;
|
|
|
|
|
// 没有正常则生成预约次数
|
|
|
|
|
$course = Course::find($courseId);
|
|
|
|
|
if (empty($course)) return false;
|
|
|
|
|
$courseType = CourseType::find($course->type);
|
|
|
|
|
if (empty($courseType)) return false;
|
|
|
|
|
$start_date = $course->start_date;
|
|
|
|
|
if (empty($start_date)) return false;
|
|
|
|
|
// 获取一年后的日期
|
|
|
|
|
$oneYearLaterTimestamp = strtotime($start_date) + (365 * 24 * 60 * 60);
|
|
|
|
|
// 获取所有合格学员
|
|
|
|
|
if ($course->is_fee == 1) {
|
|
|
|
|
$courseSigns = CourseSign::where('fee_status', 1)->where('course_id', $courseId)->get();
|
|
|
|
|
} else {
|
|
|
|
|
$courseSigns = CourseSign::where('status', 1)->where('course_id', $courseId)->get();
|
|
|
|
|
}
|
|
|
|
|
// 获取所有审核通过学员。预约次数与是否缴费解耦,统一按审核通过发放。
|
|
|
|
|
$courseSigns = CourseSign::where('status', 1)->where('course_id', $courseId)->get();
|
|
|
|
|
foreach ($courseSigns as $courseSign) {
|
|
|
|
|
$where = [
|
|
|
|
|
'user_id' => $courseSign->user_id,
|
|
|
|
|
@ -67,10 +61,13 @@ class CourseAppointmentTotal extends SoftDeletesModel
|
|
|
|
|
}
|
|
|
|
|
// 加预约次数
|
|
|
|
|
$courseSign = CourseSign::find($course_sign_id);
|
|
|
|
|
if (empty($courseSign)) return false;
|
|
|
|
|
$course = Course::find($courseSign->course_id);
|
|
|
|
|
if (empty($course)) return false;
|
|
|
|
|
$courseType = CourseType::whereHas('courses', function ($query) use ($courseSign) {
|
|
|
|
|
$query->where('id', $courseSign->course_id);
|
|
|
|
|
})->first();
|
|
|
|
|
if (empty($courseType)) return false;
|
|
|
|
|
$start_date = $course->start_date;
|
|
|
|
|
if (empty($start_date)) $start_date = date('Y-m-d H:i:s');
|
|
|
|
|
// 获取一年后的日期
|
|
|
|
|
@ -100,4 +97,3 @@ class CourseAppointmentTotal extends SoftDeletesModel
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|