印度包网
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

89 lines
2.9 KiB

package mysql
import (
"fmt"
"server/common"
"time"
)
// QueryMailList 查询玩家邮件列表
func (c *MysqlClient) QueryMailList(uid, page, num int, list *[]common.Mail, tag ...int) (count int64, err error) {
now := time.Now().Unix()
start := now - common.MailExpireTime
sql := fmt.Sprintf("receiver = %v and status <> %v and time <= %v and time >= %v", uid, common.MailStatusDelete, now, start)
if len(tag) > 0 {
sql += fmt.Sprintf(" and tag = %d", tag[0])
}
count, err = c.QueryList(page, num, sql, "status,time desc", &common.Mail{}, &list)
if count > common.MailMaxCount {
count = common.MailMaxCount
}
return
}
// // QueryNewMailCount 查询玩家未读邮件个数
func (c *MysqlClient) QueryNewMailCount(uid int) int64 {
now := time.Now().Unix()
start := now - common.MailExpireTime
sql := fmt.Sprintf("receiver = %v and status = %v and time <= %v and time >= %v", uid, common.MailStatusNew, now, start)
return c.Count(&common.Mail{}, sql)
}
// // ReadMail 查看一封邮件
// func (c *MysqlClient)ReadMail(id string) *common.Mail {
// one := new(common.Mail)
// if err := ES.QueryOne(common.ESIndexMail, elastic.NewTermQuery("_id", id), one); err != nil {
// log.Error("err:%v", err)
// return nil
// }
// if one.Status == common.MailStatusNew {
// q := elastic.NewBoolQuery()
// q.Must(elastic.NewTermQuery("_id", id), elastic.NewTermQuery("Status", common.MailStatusNew))
// ES.UpdateByScript(common.ESIndexMail, q, fmt.Sprintf("ctx._source.Status=%v", common.MailStatusRead))
// }
// return one
// }
// // DrawMail 领取一封邮件
// func (ES *EsClient) DrawMail(id string) error {
// q := elastic.NewBoolQuery()
// q.Must(elastic.NewTermQuery("_id", id), elastic.NewTermQuery("Status", common.MailStatusRead))
// res, err := ES.UpdateByScript(common.ESIndexMail, q, fmt.Sprintf("ctx._source.Status=%v", common.MailStatusDraw))
// if err != nil {
// return err
// }
// if res < 1 {
// return errors.New("not updated")
// }
// return nil
// }
// // DeleteMail 删除一封邮件
// func (ES *EsClient) DeleteMail(id string) error {
// q := elastic.NewBoolQuery()
// q.Must(elastic.NewTermQuery("_id", id))
// q.MustNot(elastic.NewTermQuery("Status", common.MailStatusDelete))
// res, err := ES.UpdateByScript(common.ESIndexMail, q, fmt.Sprintf("ctx._source.Status=%v", common.MailStatusDelete))
// if err != nil {
// return err
// }
// if res < 1 {
// return errors.New("not updated")
// }
// return nil
// }
// // DeleteMailAll 一键删除邮件
// func (ES *EsClient) DeleteMailAll(uid int) error {
// q := elastic.NewBoolQuery()
// q.Must(elastic.NewTermQuery("Receiver", uid))
// q.MustNot(elastic.NewTermQuery("Status", common.MailStatusDelete))
// res, err := ES.UpdateByScript(common.ESIndexMail, q, fmt.Sprintf("ctx._source.Status=%v", common.MailStatusDelete))
// if err != nil {
// return err
// }
// if res < 1 {
// return errors.New("not updated")
// }
// return nil
// }