stringsql=$@"SELECT ChapterNo FROM rb_scroll_appointment WHERE Group_Id ={groupId} and State <>5 and GuestId ={guestId} and CourseEndTime <= NOW() ORDER BY CourseEndTime DESC LIMIT 1";
varrobj=ExecuteScalar(sql);
returnrobj==null?0:Convert.ToInt32(robj);
}
else{
//下一次约课
stringsql=$@"SELECT ChapterNo FROM rb_scroll_appointment WHERE Group_Id ={groupId} and State <>5 and GuestId ={guestId} and CourseEndTime > NOW() ORDER BY CourseEndTime ASC LIMIT 1";
WHERE og.Status =0 and g.`Status` =0 and o.Group_Id ={group_Id} and o.OrderState <>3 and o.OrderType =1 and g.TotalHours > g.CompleteHours and og.Student_Id ={accountId}{(guestId>0?"and og.GuestId ="+guestId:"")}
WHERE og.Status =0 and g.`Status` =0 and o.Group_Id ={group_Id} and o.OrderState <>3 and o.OrderType =1 {(guestId>0?"":"and g.TotalHours > g.CompleteHours")} and og.Student_Id ={accountId}{(guestId>0?"and og.GuestId ="+guestId:"")}
stringsql=$@"SELECT sog.Student_Id,sog.GuestId,sog.OrderId,cou.CourseName,s.StuName as GuestName,og.CourseChapterNo,sa.AppointNum,ss.MakeUpNum FROM rb_student_orderguest sog
INNER JOIN rb_order_guest og on sog.GuestId = og.Id
INNER JOIN rb_order o on sog.OrderId = o.OrderId
INNER JOIN rb_course cou on o.CourseId = cou.CourseId
INNER JOIN rb_student s on sog.Student_Id = s.StuId
INNER JOIN rb_class c on o.ClassId = c.ClassId
inner join rb_course_chapter cc on o.CourseId = cc.CourseId and cc.ParentId =0 and cc.ChapterGradeNo ={NextChapterGradeNo} and cc.CourseRate ={CourseGradeId}
LEFT JOIN (
SELECT sa1.StuId,COUNT(0) as AppointNum FROM rb_scroll_appointment sa1
INNER JOIN rb_student s1 on sa1.StuId = s1.StuId
WHERE sa1.`Status` =0 and sa1.State <>5 and sa1.Group_Id ={group_Id} and s1.StuName LIKE '%{stuName}%' and sa1.CourseGradeId ={CourseGradeId} and sa1.CourseGradeNo ={NextChapterGradeNo} GROUP BY sa1.StuId
) sa on sog.Student_Id = sa.StuId
LEFT JOIN (
SELECT ss1.StuId,COUNT(0) as MakeUpNum FROM rb_scroll_skipcourse ss1
INNER JOIN rb_student s1 on ss1.StuId = s1.StuId
WHERE ss1.`Status` =0 and ss1.State =1 and ss1.Group_Id ={group_Id} and s1.StuName LIKE '%{stuName}%' and ss1.CourseGradeId ={CourseGradeId} and ss1.CourseGradeNo ={NextChapterGradeNo} GROUP BY ss1.StuId
) ss on sog.Student_Id = ss.StuId
WHERE o.Group_Id ={group_Id} and sog.`Status` =0 and og.GuestState <>2 and o.OrderState <>3 and c.ClassScrollType =2 and s.StuName LIKE '%{stuName}%'";