|
@ -2,8 +2,11 @@ package homework |
|
|
|
|
|
|
|
|
import ( |
|
|
import ( |
|
|
"context" |
|
|
"context" |
|
|
|
|
|
"fmt" |
|
|
"github.com/gogf/gf/v2/os/gtime" |
|
|
"github.com/gogf/gf/v2/os/gtime" |
|
|
|
|
|
"link_homework/api/v1/homework" |
|
|
"link_homework/internal/dao" |
|
|
"link_homework/internal/dao" |
|
|
|
|
|
"link_homework/internal/model/do" |
|
|
"link_homework/internal/model/entity" |
|
|
"link_homework/internal/model/entity" |
|
|
"link_homework/internal/service" |
|
|
"link_homework/internal/service" |
|
|
) |
|
|
) |
|
@ -34,3 +37,47 @@ func (s *sHomework) GetHomeworkList(ctx context.Context, pageNo int, pageSize in |
|
|
} |
|
|
} |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (s *sHomework) AddHomework(ctx context.Context, req *homework.AddHomeworkReq) (err error) { |
|
|
|
|
|
status := 0 |
|
|
|
|
|
if req.StartDate.Before(gtime.Now()) { |
|
|
|
|
|
if req.EndDate.Before(gtime.Now()) { |
|
|
|
|
|
status = 2 |
|
|
|
|
|
} else { |
|
|
|
|
|
status = 1 |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
var Id int64 |
|
|
|
|
|
if req.ArticleId == 0 { |
|
|
|
|
|
Id, err = dao.ActivityInteractiveGroup.Ctx(ctx).Data(do.ActivityInteractiveGroup{ |
|
|
|
|
|
Name: req.Name, |
|
|
|
|
|
Status: status, |
|
|
|
|
|
ClubType: req.ClubType, |
|
|
|
|
|
LiveId: req.LiveId, |
|
|
|
|
|
StartDate: req.StartDate, |
|
|
|
|
|
EndDate: req.EndDate, |
|
|
|
|
|
}).InsertAndGetId() |
|
|
|
|
|
} else if req.LiveId == 0 { |
|
|
|
|
|
Id, err = dao.ActivityInteractiveGroup.Ctx(ctx).Data(do.ActivityInteractiveGroup{ |
|
|
|
|
|
Name: req.Name, |
|
|
|
|
|
Status: status, |
|
|
|
|
|
ClubType: req.ClubType, |
|
|
|
|
|
ArticleId: req.ArticleId, |
|
|
|
|
|
StartDate: req.StartDate, |
|
|
|
|
|
EndDate: req.EndDate, |
|
|
|
|
|
}).InsertAndGetId() |
|
|
|
|
|
} else { |
|
|
|
|
|
return fmt.Errorf("不能同时关联文章和直播!") |
|
|
|
|
|
} |
|
|
|
|
|
for _, v := range req.Questions { |
|
|
|
|
|
_, err = dao.ActivityInteractiveForm.Ctx(ctx).Data(do.ActivityInteractiveForm{ |
|
|
|
|
|
Name: req.Name, |
|
|
|
|
|
Description: v.Description, |
|
|
|
|
|
Content: v.Content, |
|
|
|
|
|
Status: status, |
|
|
|
|
|
Type: v.Type, |
|
|
|
|
|
GroupId: Id, |
|
|
|
|
|
}).Insert() |
|
|
|
|
|
} |
|
|
|
|
|
return |
|
|
|
|
|
} |