package models

import (
	"github.com/beego/beego/v2/client/orm"
	"hongze/hongze_cygx/utils"
)

// 批量添加
func AddCygxActivityRestrictSignupList(items []*CygxActivityRestrictSignup) (lastId int64, err error) {
	lenitems := len(items)
	if lenitems == 0 {
		return
	}
	o := orm.NewOrm()
	_, err = o.InsertMulti(1, items)
	return
}

// 删除
func DeleteCygxActivityRestrictSignupByUserIds(userIdDelArr []int) (err error) {
	if len(userIdDelArr) == 0 {
		return
	}
	o := orm.NewOrm()
	sql := ` DELETE FROM cygx_activity_restrict_signup  WHERE  1= 1  AND user_id IN (` + utils.GetOrmInReplace(len(userIdDelArr)) + `)`
	_, err = o.Raw(sql, userIdDelArr).Exec()
	return
}

// 列表
func GetCygxActivityRestrictSignupList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxActivityRestrictSignup, err error) {
	o := orm.NewOrm()
	sql := `SELECT * FROM cygx_activity_restrict_signup as art WHERE 1= 1 `
	if condition != "" {
		sql += condition
	}
	sql += ` LIMIT ?,?  `
	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
	return
}