72 lines
2.3 KiB
Go
72 lines
2.3 KiB
Go
package model
|
|
|
|
import (
|
|
"SciencesServer/app/common/model"
|
|
"SciencesServer/serve/orm"
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
type ActivityApply struct {
|
|
*model.ActivityApply
|
|
}
|
|
|
|
type (
|
|
// ActivityApplyInfo 详细信息
|
|
ActivityApplyInfo struct {
|
|
*model.ActivityApply
|
|
Username string `json:"username"`
|
|
model.Area
|
|
Handler string `json:"handler"`
|
|
HandleRemark string `json:"handle_remark"`
|
|
HandleCreatedAt time.Time `json:"handle_created_at"`
|
|
}
|
|
)
|
|
|
|
// Apply 申请信息
|
|
func (m *ActivityApply) Apply(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*ActivityApplyInfo, error) {
|
|
db := orm.GetDB().Table(m.TableName()+" AS a").
|
|
Select("a.id", "a.tenant_id", "a.identity", "a.image", "a.title", "a.contact", "a.contact_mobile", "a.begin_at",
|
|
"a.finish_at", "a.amount", "a.max_number", "a.status", "a.created_at",
|
|
"t.province", "t.city", "l.name AS handler", "l.remark AS handle_remark", "l.created_at AS handle_created_at").
|
|
Joins(fmt.Sprintf("LEFT JOIN %s AS t ON a.tenant_id = t.id", model.NewSysTenant().TableName())).
|
|
Joins(fmt.Sprintf("LEFT JOIN (SELECT a.apply_id, MAX(a.id) AS id, MAX(a.created_at) AS created_at, MAX(a.remark) AS remark, "+
|
|
"MAX(u.`name`) AS name FROM %s AS a LEFT JOIN %s AS u ON a.uid = u.uuid WHERE a.is_deleted = %d GROUP BY a.apply_id) AS l ON a.id = l.apply_id",
|
|
model.NewActivityApplyLog().TableName(), model.NewSysUser().TableName(), model.DeleteStatusForNot)).
|
|
Where("a.is_deleted = ?", model.DeleteStatusForNot)
|
|
|
|
if len(where) > 0 {
|
|
for _, v := range where {
|
|
db = db.Where(v.Condition, v.Value)
|
|
}
|
|
}
|
|
out := make([]*ActivityApplyInfo, 0)
|
|
|
|
if err := db.Count(count).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
if err := db.Order("a.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
// Detail 详细信息
|
|
func (m *ActivityApply) Detail(id uint64) (*ActivityApplyInfo, error) {
|
|
db := orm.GetDB().Table(m.TableName()+" AS a").
|
|
Select("a.*", "u.name AS username").
|
|
Joins(fmt.Sprintf("LEFT JOIN %s AS u ON a.uid = u.uuid", model.NewUserInstance().TableName())).
|
|
Where("a.id = ?", id)
|
|
|
|
out := new(ActivityApplyInfo)
|
|
|
|
err := db.Scan(out).Error
|
|
|
|
return out, err
|
|
|
|
}
|
|
|
|
func NewActivityApply() *ActivityApply {
|
|
return &ActivityApply{model.NewActivityApply()}
|
|
}
|