package models import ( "github.com/beego/beego/v2/client/orm" "time" ) type SmsRecord struct { Id int `orm:"column(id);pk"` Body string Mobile string SmsDate string IsSend int CreateTime time.Time ModifyTime time.Time SmsDateTime time.Time UnionCode string } // 新增记录 func AddSmsRecord(item *SmsRecord) (newId int64, err error) { o := orm.NewOrm() newId, err = o.Insert(item) return } // 批量新增记录 func AddSmsRecordMulti(items []*SmsRecord) (newId int64, err error) { o := orm.NewOrm() newId, err = o.InsertMulti(len(items), items) return } func GetSmsRecordCount(unionCode string) (count int, err error) { o := orm.NewOrm() sql := `SELECT COUNT(1) AS count FROM sms_record AS a WHERE union_code=? ` err = o.Raw(sql, unionCode).QueryRow(&count) return } func ModifySmsRecordIsSend(mobile, smsDate string) (err error) { o := orm.NewOrm() sql := `UPDATE sms_record SET is_send=1,modify_time=NOW() WHERE mobile=? AND sms_date=? ` _, err = o.Raw(sql, mobile, smsDate).Exec() return } func GetSmsRecord() (items []*SmsRecord, err error) { o := orm.NewOrm() sql := ` SELECT * FROM sms_record WHERE is_send=0 AND body<>'测试' ORDER BY sms_date_time ASC ` _, err = o.Raw(sql).QueryRows(&items) return } type SmsReq struct { Body string Address string Date string Sign string } func ModifySmsRecordUnicode(unionCode string, id int) (err error) { o := orm.NewOrm() sql := `UPDATE sms_record SET union_code=? WHERE id=? ` _, err = o.Raw(sql, unionCode, id).Exec() return } func GetSmsRecordList() (list []*SmsRecord, err error) { o := orm.NewOrm() sql := `SELECT * FROM sms_record WHERE union_code='' ` _, err = o.Raw(sql).QueryRows(&list) return }