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.
106 lines
3.4 KiB
106 lines
3.4 KiB
package mysql |
|
|
|
import ( |
|
"fmt" |
|
"server/common" |
|
"server/util" |
|
"time" |
|
) |
|
|
|
// QueryMailList 查询玩家邮件列表 |
|
func (c *MysqlClient) QueryMailList(uid, page, num int, birth, channelId, rechargeAmount int64, tag int, list *[]common.Mail) (count int64, err error) { |
|
now := time.Now().Unix() |
|
start := now - common.MailExpireTime |
|
today := util.GetZeroTime(time.Now()) |
|
sql := fmt.Sprintf(` receiver = %v and status <> %v and time <= %v and time >= %v |
|
and ( |
|
user_tag = 0 |
|
or (user_tag = 1 and max_birth_at >= %v) |
|
or (user_tag = 2 and %v > 0) |
|
or (user_tag = 3 and %v > %v) |
|
or (user_tag = 4 and %v < %v) |
|
or (user_tag = 5 and %v >= recharge_amount) |
|
or (user_tag = 6 and JSON_CONTAINS(channel_id, CAST(%v AS JSON))) |
|
) `, |
|
uid, common.MailStatusDelete, now, start, |
|
birth, |
|
rechargeAmount, |
|
birth, today.Unix(), |
|
birth, today.Unix(), |
|
rechargeAmount, |
|
channelId, |
|
) |
|
sql += fmt.Sprintf(" and `tag` = %d ", tag) |
|
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 |
|
// }
|
|
|