sms_record.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type SmsRecord struct {
  7. Id int `orm:"column(id);pk"`
  8. Body string
  9. Mobile string
  10. SmsDate string
  11. IsSend int
  12. CreateTime time.Time
  13. ModifyTime time.Time
  14. SmsDateTime time.Time
  15. UnionCode string
  16. }
  17. // 新增记录
  18. func AddSmsRecord(item *SmsRecord) (newId int64, err error) {
  19. o := orm.NewOrm()
  20. newId, err = o.Insert(item)
  21. return
  22. }
  23. // 批量新增记录
  24. func AddSmsRecordMulti(items []*SmsRecord) (newId int64, err error) {
  25. o := orm.NewOrm()
  26. newId, err = o.InsertMulti(len(items), items)
  27. return
  28. }
  29. func GetSmsRecordCount(unionCode string) (count int, err error) {
  30. o := orm.NewOrm()
  31. sql := `SELECT COUNT(1) AS count
  32. FROM sms_record AS a
  33. WHERE union_code=? `
  34. err = o.Raw(sql, unionCode).QueryRow(&count)
  35. return
  36. }
  37. func ModifySmsRecordIsSend(mobile, smsDate string) (err error) {
  38. o := orm.NewOrm()
  39. sql := `UPDATE sms_record SET is_send=1,modify_time=NOW() WHERE mobile=? AND sms_date=? `
  40. _, err = o.Raw(sql, mobile, smsDate).Exec()
  41. return
  42. }
  43. func GetSmsRecord() (items []*SmsRecord, err error) {
  44. o := orm.NewOrm()
  45. sql := ` SELECT * FROM sms_record WHERE is_send=0 AND body<>'测试' ORDER BY sms_date_time ASC `
  46. _, err = o.Raw(sql).QueryRows(&items)
  47. return
  48. }
  49. type SmsReq struct {
  50. Body string
  51. Address string
  52. Date string
  53. Sign string
  54. }
  55. func ModifySmsRecordUnicode(unionCode string, id int) (err error) {
  56. o := orm.NewOrm()
  57. sql := `UPDATE sms_record SET union_code=? WHERE id=? `
  58. _, err = o.Raw(sql, unionCode, id).Exec()
  59. return
  60. }
  61. func GetSmsRecordList() (list []*SmsRecord, err error) {
  62. o := orm.NewOrm()
  63. sql := `SELECT * FROM sms_record WHERE union_code='' `
  64. _, err = o.Raw(sql).QueryRows(&list)
  65. return
  66. }