|
|
|
|
@ -182,49 +182,4 @@ class User extends Authenticatable implements Auditable
|
|
|
|
|
return $user->appointment_total - $useTotal >= 0 ? $user->appointment_total - $useTotal : 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 更新用户编号
|
|
|
|
|
*/
|
|
|
|
|
public static function updateNo($userId)
|
|
|
|
|
{
|
|
|
|
|
// todo::编号可能回重复,还需要详细排查
|
|
|
|
|
$user = self::find($userId);
|
|
|
|
|
if (!empty($user->no)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
// 获取最早一条审核通过的报名数据
|
|
|
|
|
$courseSigns = CourseSign::with('course')
|
|
|
|
|
->where('user_id', $userId)
|
|
|
|
|
->where('status', 1)
|
|
|
|
|
->orderBy('created_at', 'asc')
|
|
|
|
|
->first();
|
|
|
|
|
if (empty($courseSigns)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (empty($courseSigns->course->start_date)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
// 编号前缀
|
|
|
|
|
$prefix = date('Ymd', strtotime($courseSigns->course->start_date));
|
|
|
|
|
// 获取同一天开始的所有课程
|
|
|
|
|
$course = Course::where('start_date', $courseSigns->course->start_date)->orderBy('created_at', 'asc')->get();
|
|
|
|
|
// 获取同一天开始所有课程的报名信息
|
|
|
|
|
$courseSignsList = CourseSign::whereIn('id', function ($query) use ($course) {
|
|
|
|
|
$query->from('course_signs')
|
|
|
|
|
->where('status', 1)
|
|
|
|
|
->whereIn('course_id', $course->pluck('id'))
|
|
|
|
|
->selectRaw('MIN(id)')
|
|
|
|
|
->groupBy('user_id');
|
|
|
|
|
})->orderBy('created_at', 'asc')->get();
|
|
|
|
|
|
|
|
|
|
// 获取当前用户id在$courseSigns中第几位
|
|
|
|
|
$index = $courseSignsList->search(function ($item) use ($user) {
|
|
|
|
|
return $item->user_id == $user->id;
|
|
|
|
|
});
|
|
|
|
|
$no = $prefix . str_pad($index + 1, 3, '0', STR_PAD_LEFT);
|
|
|
|
|
$user->no = $no;
|
|
|
|
|
$user->save();
|
|
|
|
|
return $user->no;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|