package mysql import ( "fmt" "server/common" "server/util" "time" ) // QueryMailList 查询玩家邮件列表 func (c *MysqlClient) QueryMailList(uid, page, num int, birth, channelId, rechargeAmount int64, tag int, unRead bool, 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, ) if tag != -1 { sql += fmt.Sprintf(" and `tag` = %d ", tag) } if unRead { sql += fmt.Sprintf(" and `status` = %d ", common.MailStatusNew) } if page > 0 || num > 0 { count, err = c.QueryList(page, num, sql, "status,time desc", &common.Mail{}, &list) } else { count, err = c.QueryList(0, 0, 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 // }