feat:完善项目
This commit is contained in:
@ -8,6 +8,8 @@ import (
|
||||
"SciencesServer/app/session"
|
||||
"SciencesServer/config"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Activity struct {
|
||||
@ -22,7 +24,8 @@ type (
|
||||
ActivityInfo struct {
|
||||
ID string `json:"id"`
|
||||
*model.ActivityInstanceInfo
|
||||
JoinStatus bool `json:"join_status"`
|
||||
IsJoin bool `json:"is_join"`
|
||||
Status int `json:"status"` // 状态(1:未开始,2:进行中,3:已结束)
|
||||
}
|
||||
// ActivityDetail 详细信息
|
||||
ActivityDetail struct {
|
||||
@ -33,16 +36,30 @@ type (
|
||||
)
|
||||
|
||||
// Instance 活动信息
|
||||
func (c *Activity) Instance(title string, page, pageSize int) (*controller.ReturnPages, error) {
|
||||
func (c *Activity) Instance(title, industry string, status, page, pageSize int) (*controller.ReturnPages, error) {
|
||||
mActivityInstance := model.NewActivityInstance()
|
||||
|
||||
var count int64
|
||||
now := time.Now()
|
||||
|
||||
where := []*model2.ModelWhere{model2.NewWhere("a.tenant_id", c.tenantID)}
|
||||
|
||||
if title != "" {
|
||||
where = append(where, model2.NewWhereLike("a.title", title))
|
||||
}
|
||||
if industry != "" {
|
||||
where = append(where, model2.NewWhereCondition("a.industry", "LIKE", "%"+fmt.Sprintf(`"%v`, industry)+"%"))
|
||||
}
|
||||
if status > 0 {
|
||||
if status == 1 {
|
||||
where = append(where, model2.NewWhereCondition("a.begin_at", ">", now))
|
||||
} else if status == 2 {
|
||||
where = append(where, model2.NewWhereCondition("a.begin_at", "<=", now),
|
||||
model2.NewWhereCondition("a.finish_at", ">=", now))
|
||||
} else {
|
||||
where = append(where, model2.NewWhereCondition("a.finish_at", "<", now))
|
||||
}
|
||||
}
|
||||
var count int64
|
||||
|
||||
out, err := mActivityInstance.Activity(c.UID, c.SelectIdentity, page, pageSize, &count, where...)
|
||||
|
||||
@ -53,9 +70,22 @@ func (c *Activity) Instance(title string, page, pageSize int) (*controller.Retur
|
||||
list := make([]*ActivityInfo, 0)
|
||||
|
||||
for _, v := range out {
|
||||
list = append(list, &ActivityInfo{
|
||||
ID: v.GetEncodeID(), ActivityInstanceInfo: v, JoinStatus: v.JoinID > 0,
|
||||
})
|
||||
data := &ActivityInfo{
|
||||
ID: v.GetEncodeID(), ActivityInstanceInfo: v, IsJoin: v.JoinID > 0, Status: 2,
|
||||
}
|
||||
|
||||
if now.After(v.BeginAt) {
|
||||
data.Status = 1
|
||||
goto CONTINUE
|
||||
}
|
||||
|
||||
if now.Before(v.FinishAt) {
|
||||
data.Status = 3
|
||||
goto CONTINUE
|
||||
}
|
||||
CONTINUE:
|
||||
|
||||
list = append(list, data)
|
||||
}
|
||||
return &controller.ReturnPages{Data: list, Count: count}, nil
|
||||
}
|
||||
|
55
app/api/website/controller/sys/industry.go
Normal file
55
app/api/website/controller/sys/industry.go
Normal file
@ -0,0 +1,55 @@
|
||||
package sys
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/model"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type Industry struct {
|
||||
}
|
||||
|
||||
type IndustryHandle func() *Industry
|
||||
|
||||
type (
|
||||
// IndustryInfo 行业领域信息
|
||||
IndustryInfo struct {
|
||||
ID string `json:"id"`
|
||||
ParentID string `json:"parent_id"`
|
||||
Name string `json:"name"`
|
||||
Children []*IndustryInfo `json:"children"`
|
||||
}
|
||||
)
|
||||
|
||||
func (c *Industry) tree(src []*model2.SysIndustry, parentID uint64) []*IndustryInfo {
|
||||
out := make([]*IndustryInfo, 0)
|
||||
|
||||
for _, v := range src {
|
||||
if v.ParentID == parentID {
|
||||
out = append(out, &IndustryInfo{
|
||||
ID: fmt.Sprintf("%d", v.ID),
|
||||
ParentID: fmt.Sprintf("%d", v.ParentID),
|
||||
Name: v.Name,
|
||||
Children: c.tree(src, v.ID),
|
||||
})
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// Instance 首页信息
|
||||
func (c *Industry) Instance() ([]*IndustryInfo, error) {
|
||||
mSysIndustry := model.NewSysIndustry()
|
||||
out := make([]*model2.SysIndustry, 0)
|
||||
|
||||
if err := model2.ScanFields(mSysIndustry.SysIndustry, &out, []string{"id", "parent_id", "name"}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return c.tree(out, 0), nil
|
||||
}
|
||||
|
||||
func NewIndustry() IndustryHandle {
|
||||
return func() *Industry {
|
||||
return &Industry{}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user