package db

import (
	"applet/app/db/model"
	"applet/app/utils"
	"xorm.io/xorm"
)

func GetBankNotice(eg *xorm.Engine, args map[string]string) *[]model.CommunityTeamStoreNotice {
	var data []model.CommunityTeamStoreNotice
	size := utils.StrToInt(args["size"])
	start := (utils.StrToInt(args["p"]) - 1) * size
	err := eg.Where("uid=?", args["uid"]).Limit(size, start).OrderBy("id desc").Find(&data)
	if err != nil {
		return nil
	}
	return &data
}
func GetBankNoticeAll(eg *xorm.Engine, args map[string]string) (*[]model.CommunityTeamStoreNotice, int64) {
	var data []model.CommunityTeamStoreNotice
	size := utils.StrToInt(args["size"])
	start := (utils.StrToInt(args["p"]) - 1) * size
	sess := eg.Where("uid=?", args["uid"])
	if args["title"] != "" {
		sess.And("title like ?", "%"+args["title"]+"%")
	}
	count, err := sess.Limit(size, start).OrderBy("id desc").FindAndCount(&data)
	if err != nil {
		return nil, count
	}
	return &data, count
}
func GetNotice(eg *xorm.Engine, id string) *model.CommunityTeamStoreNotice {
	var data model.CommunityTeamStoreNotice
	get, err := eg.Where("id=?", id).Get(&data)
	if get == false || err != nil {
		return nil
	}
	return &data
}
