Files
cas_tt_cloud_backend/app/api/admin/model/activity_apply.go

72 lines
2.3 KiB
Go
Raw Normal View History

2022-01-12 15:05:14 +08:00
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
2022-01-13 15:23:27 +08:00
Handler string `json:"handler"`
2022-01-12 15:05:14 +08:00
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").
2022-01-12 17:29:05 +08:00
Select("a.id", "a.tenant_id", "a.identity", "a.image", "a.title", "a.contact", "a.contact_mobile", "a.begin_at",
2022-01-12 15:05:14 +08:00
"a.finish_at", "a.amount", "a.max_number", "a.status", "a.created_at",
2022-01-13 15:23:27 +08:00
"t.province", "t.city", "l.name AS handler", "l.remark AS handle_remark", "l.created_at AS handle_created_at").
2022-01-12 17:29:05 +08:00
Joins(fmt.Sprintf("LEFT JOIN %s AS t ON a.tenant_id = t.id", model.NewSysTenant().TableName())).
2022-01-13 15:23:27 +08:00
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",
2022-01-12 15:05:14 +08:00
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()}
}