package model import ( "SciencesServer/app/common/model" "SciencesServer/serve/orm" "fmt" "time" ) type ActivityJoin struct { *model.ActivityJoin } type ActivityJoinInfo struct { model.Model Identity int `json:"identity"` Name string `json:"name"` Mobile string `json:"mobile"` CreatedAt time.Time `json:"created_at"` } func (m *ActivityJoin) Join(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*ActivityJoinInfo, error) { db := orm.GetDB().Table(m.TableName()+" AS j"). Select("j.id", "j.identity", "u_i.name", "u.mobile", "j.created_at"). Joins(fmt.Sprintf("LEFT JOIN %s AS u_i ON j.uid = u_i.uid AND j.identity = u_i.identity", model.NewUserIdentity().TableName())). Joins(fmt.Sprintf("LEFT JOIN %s AS u ON j.uid = u.uuid", model.NewUserInstance().TableName())). Where("j.is_deleted = ?", model.DeleteStatusForNot). Where("j.status = ?", model.ActivityJoinStatusForSuccess) if len(where) > 0 { for _, v := range where { db = db.Where(v.Condition, v.Value) } } out := make([]*ActivityJoinInfo, 0) if err := db.Count(count).Error; err != nil { return nil, err } if err := db.Order("j.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil { return nil, err } return out, nil } func NewActivityJoin() *ActivityJoin { return &ActivityJoin{model.NewActivityJoin()} }