@@ -0,0 +1,52 @@
|
||||
package taskser
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"91porn-server/common/stderr"
|
||||
"91porn-server/models/v/taskmod"
|
||||
)
|
||||
|
||||
func AddConfig(in taskmod.AddConfigCond) stderr.Code {
|
||||
if err := taskmod.AddConfig(taskmod.TaskConfig{
|
||||
Title: in.Title,
|
||||
Desc: in.Desc,
|
||||
Type: in.Type,
|
||||
Detail: in.Detail,
|
||||
Link: in.Link,
|
||||
Status: in.Status,
|
||||
UpdateTime: time.Now(),
|
||||
CreateTime: time.Now(),
|
||||
}); err != nil {
|
||||
return stderr.ErrDbInsertError
|
||||
}
|
||||
return stderr.Success
|
||||
}
|
||||
|
||||
func ModifyConfig(in *taskmod.ModifyConfigCond) stderr.Code {
|
||||
if err := taskmod.ModifyConfig(in.Cond(), in.Bson()); err != nil {
|
||||
return stderr.ErrDbUpdateError
|
||||
}
|
||||
return stderr.Success
|
||||
}
|
||||
|
||||
func QueryAllConfig(in *taskmod.QueryAllConfigCond) (interface{}, stderr.Code) {
|
||||
var data map[string]interface{} = map[string]interface{}{
|
||||
"list": []interface{}{},
|
||||
"count": 0,
|
||||
}
|
||||
count, err := taskmod.CountConfig(in.Query())
|
||||
if err != nil {
|
||||
return nil, stderr.ErrDbQueryError
|
||||
}
|
||||
if count == 0 {
|
||||
return data, stderr.Success
|
||||
}
|
||||
data["count"] = count
|
||||
list, err := taskmod.QueryAllConfig(in.Query(), in.Options())
|
||||
if err != nil {
|
||||
return nil, stderr.ErrDbQueryError
|
||||
}
|
||||
data["list"] = list
|
||||
return data, stderr.Success
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
package taskser
|
||||
|
||||
import (
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
"time"
|
||||
|
||||
"91porn-server/models/commod"
|
||||
"91porn-server/models/v/dailytaskmod"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
)
|
||||
|
||||
type DailyTaskListReq struct {
|
||||
commod.Page
|
||||
Status *bool `form:"status" json:"status" binding:"-"`
|
||||
}
|
||||
|
||||
func GetDailyTaskList(p DailyTaskListReq) ([]dailytaskmod.DailyTask, bool, error) {
|
||||
opt := options.Find()
|
||||
opt.SetLimit(p.Limit64()).SetSkip(p.Skip64())
|
||||
opt.SetSort(bson.D{{"sortNum", 1}})
|
||||
filter := bson.M{}
|
||||
if p.Status != nil {
|
||||
filter["status"] = *p.Status
|
||||
}
|
||||
ot, next, err := dailytaskmod.GetTasks(filter, opt)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
return ot, next, nil
|
||||
}
|
||||
|
||||
func AddDailyTask(adt dailytaskmod.AddDailyTaskReq) error {
|
||||
var dt dailytaskmod.DailyTask
|
||||
i := 0
|
||||
if adt.Title != nil {
|
||||
dt.Title = *adt.Title
|
||||
i++
|
||||
}
|
||||
if adt.Desc != nil {
|
||||
dt.Desc = *adt.Desc
|
||||
i++
|
||||
}
|
||||
if adt.Img != nil {
|
||||
dt.Img = *adt.Img
|
||||
i++
|
||||
}
|
||||
if len(adt.Detail) != 0 {
|
||||
dt.Detail = adt.Detail
|
||||
i++
|
||||
}
|
||||
if adt.Type != nil {
|
||||
dt.Type = *adt.Type
|
||||
i++
|
||||
}
|
||||
if adt.Link != nil {
|
||||
dt.Link = *adt.Link
|
||||
i++
|
||||
}
|
||||
if adt.Status != nil {
|
||||
dt.Status = *adt.Status
|
||||
i++
|
||||
}
|
||||
if adt.SortNum != nil {
|
||||
dt.SortNum = *adt.SortNum
|
||||
i++
|
||||
}
|
||||
if i == 0 {
|
||||
return nil
|
||||
}
|
||||
now := time.Now()
|
||||
dt.CreatedAt = now
|
||||
dt.UpdatedAt = now
|
||||
if err := dailytaskmod.AddDailyTask(nil, dt); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func EditDailyTask(edtr dailytaskmod.EditDailyTaskReq) error {
|
||||
if edtr.ID.IsZero() {
|
||||
return nil
|
||||
}
|
||||
b := make(bson.M)
|
||||
if edtr.Title != nil {
|
||||
b["title"] = *edtr.Title
|
||||
}
|
||||
if edtr.Desc != nil {
|
||||
b["desc"] = *edtr.Desc
|
||||
}
|
||||
if edtr.Img != nil {
|
||||
b["img"] = *edtr.Img
|
||||
}
|
||||
if len(edtr.Detail) != 0 {
|
||||
b["detail"] = edtr.Detail
|
||||
}
|
||||
if edtr.Type != nil {
|
||||
b["type"] = *edtr.Type
|
||||
}
|
||||
if edtr.Link != nil {
|
||||
b["link"] = *edtr.Link
|
||||
}
|
||||
if edtr.Status != nil {
|
||||
b["status"] = *edtr.Status
|
||||
}
|
||||
if edtr.SortNum != nil {
|
||||
b["sortNum"] = *edtr.SortNum
|
||||
}
|
||||
if len(b) == 0 {
|
||||
return nil
|
||||
}
|
||||
b["updatedAt"] = time.Now()
|
||||
return dailytaskmod.EditDailyTask(nil, edtr.ID, b)
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
package taskser
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"91porn-server/models/commod"
|
||||
"91porn-server/models/v/oncetaskmod"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
)
|
||||
|
||||
func GetOnceTaskList(p commod.Page) ([]oncetaskmod.OnceTask, bool, error) {
|
||||
ot, err := oncetaskmod.GetOnceTaskAll(nil)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
skip := p.Skip()
|
||||
if uint64(len(ot)) <= skip {
|
||||
return nil, false, nil
|
||||
}
|
||||
ot = ot[skip:]
|
||||
if uint64(len(ot)) <= p.Limit() {
|
||||
return ot, false, nil
|
||||
}
|
||||
return ot[:p.Limit()], true, nil
|
||||
}
|
||||
|
||||
func AddOnceTask(aor oncetaskmod.AddOnceReq) error {
|
||||
var ot oncetaskmod.OnceTask
|
||||
i := 0
|
||||
if aor.Title != nil {
|
||||
ot.Title = *aor.Title
|
||||
i++
|
||||
}
|
||||
if aor.Desc != nil {
|
||||
ot.Desc = *aor.Desc
|
||||
i++
|
||||
}
|
||||
if aor.Img != nil {
|
||||
ot.Img = *aor.Img
|
||||
i++
|
||||
}
|
||||
if len(aor.Prizes) != 0 {
|
||||
ot.Prizes = aor.Prizes
|
||||
i++
|
||||
}
|
||||
if aor.Type != nil {
|
||||
ot.Type = *aor.Type
|
||||
i++
|
||||
}
|
||||
if aor.FinishCondition != nil {
|
||||
ot.FinishCondition = *aor.FinishCondition
|
||||
i++
|
||||
}
|
||||
if aor.Link != nil {
|
||||
ot.Link = *aor.Link
|
||||
i++
|
||||
}
|
||||
if aor.Status != nil {
|
||||
ot.Status = *aor.Status
|
||||
i++
|
||||
}
|
||||
if aor.SortNum != nil {
|
||||
ot.SortNum = *aor.SortNum
|
||||
i++
|
||||
}
|
||||
if i == 0 {
|
||||
return nil
|
||||
}
|
||||
now := time.Now()
|
||||
ot.CreatedAt = now
|
||||
ot.UpdatedAt = now
|
||||
if err := oncetaskmod.AddOnceTask(nil, ot); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func EditOnceTask(eor oncetaskmod.EditOnceReq) error {
|
||||
if eor.ID.IsZero() {
|
||||
return nil
|
||||
}
|
||||
b := make(bson.M)
|
||||
if eor.Title != nil {
|
||||
b["title"] = *eor.Title
|
||||
}
|
||||
if eor.Desc != nil {
|
||||
b["desc"] = *eor.Desc
|
||||
}
|
||||
if eor.Img != nil {
|
||||
b["img"] = *eor.Img
|
||||
}
|
||||
if len(eor.Prizes) != 0 {
|
||||
b["prizes"] = eor.Prizes
|
||||
}
|
||||
if eor.Type != nil {
|
||||
b["type"] = *eor.Type
|
||||
}
|
||||
if eor.FinishCondition != nil {
|
||||
b["finishCondition"] = *eor.FinishCondition
|
||||
}
|
||||
if eor.Link != nil {
|
||||
b["link"] = *eor.Link
|
||||
}
|
||||
if eor.Status != nil {
|
||||
b["status"] = *eor.Status
|
||||
}
|
||||
if eor.SortNum != nil {
|
||||
b["sortNum"] = *eor.SortNum
|
||||
}
|
||||
if len(b) == 0 {
|
||||
return nil
|
||||
}
|
||||
b["updatedAt"] = time.Now()
|
||||
return oncetaskmod.UpdateOnceTask(nil, eor.ID, b)
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package taskser
|
||||
|
||||
import (
|
||||
"91porn-server/common/stderr"
|
||||
"91porn-server/models/v/signtaskmod"
|
||||
"time"
|
||||
)
|
||||
|
||||
func SignAddConfig(in signtaskmod.AddConfigCond) stderr.Code {
|
||||
if err := signtaskmod.AddConfig(signtaskmod.TaskConfig{
|
||||
Title: in.Title,
|
||||
Desc: in.Desc,
|
||||
Img: in.Img,
|
||||
FinishCondition: in.FinishCondition,
|
||||
Link: in.Link,
|
||||
Prizes: in.Prizes,
|
||||
ExtraPrizes: in.ExtraPrizes,
|
||||
Status: in.Status,
|
||||
UpdateTime: time.Now(),
|
||||
CreateTime: time.Now(),
|
||||
}); err != nil {
|
||||
return stderr.ErrDbInsertError
|
||||
}
|
||||
return stderr.Success
|
||||
}
|
||||
|
||||
func SignModifyConfig(in *signtaskmod.ModifyConfigCond) stderr.Code {
|
||||
if err := signtaskmod.ModifyConfig(in.Cond(), in.Bson()); err != nil {
|
||||
return stderr.ErrDbUpdateError
|
||||
}
|
||||
return stderr.Success
|
||||
}
|
||||
|
||||
type SignQueryAllConfigResp struct {
|
||||
Count int64 `json:"count"`
|
||||
List []*signtaskmod.TaskConfig `json:"list"`
|
||||
}
|
||||
|
||||
func SignQueryAllConfig(in *signtaskmod.QueryAllConfigCond) (SignQueryAllConfigResp, stderr.Code) {
|
||||
var data SignQueryAllConfigResp
|
||||
count, err := signtaskmod.CountConfig(in.Query())
|
||||
if err != nil {
|
||||
return data, stderr.ErrDbQueryError
|
||||
}
|
||||
if count == 0 {
|
||||
return data, stderr.Success
|
||||
}
|
||||
data.Count = count
|
||||
list, err := signtaskmod.QueryAllConfig(in.Query(), in.Options())
|
||||
if err != nil {
|
||||
return data, stderr.ErrDbQueryError
|
||||
}
|
||||
data.List = list
|
||||
return data, stderr.Success
|
||||
}
|
||||
Reference in New Issue
Block a user