activity_voice_history.go 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type CygxActivityVoiceHistory struct {
  7. Id int `orm:"column(id);pk"`
  8. ActivityId int `description:"活动ID"`
  9. UserId int `description:"用户ID"`
  10. CreateTime time.Time `description:"创建时间"`
  11. Mobile string `description:"手机号"`
  12. Email string `description:"邮箱"`
  13. CompanyId int `description:"公司id"`
  14. CompanyName string `description:"公司名称"`
  15. RealName string `description:"用户实际名称"`
  16. SellerName string `description:"所属销售"`
  17. PlaySeconds string `description:"播放时间 单位s"`
  18. ModifyTime time.Time `description:"视频修改时间"`
  19. RegisterPlatform int // 来源 1小程序,2:网页
  20. }
  21. // 添加
  22. func AddCygxActivityVoiceHistory(item *CygxActivityVoiceHistory) (err error) {
  23. o := orm.NewOrm()
  24. _, err = o.Insert(item)
  25. return
  26. }
  27. func GetLastCygxActivityVoiceHistory(activityId, userId int) (item *CygxActivityVoiceHistory, err error) {
  28. o := orm.NewOrm()
  29. sql := ` SELECT * FROM cygx_activity_voice_history WHERE activity_id=? AND user_id=? AND register_platform = 1 ORDER BY create_time DESC limit 1 `
  30. err = o.Raw(sql, activityId, userId).QueryRow(&item)
  31. return
  32. }
  33. func UpdateLastCygxActivityVoiceHistory(playSeconds string, lastId int) (err error) {
  34. o := orm.NewOrm()
  35. sql := ` UPDATE cygx_activity_voice_history SET play_seconds = play_seconds +? WHERE id=? `
  36. _, err = o.Raw(sql, playSeconds, lastId).Exec()
  37. return
  38. }
  39. // 获取列表信息根据手机号分组
  40. func GetActivityVoiceHistoryByMobileList(condition string) (items []*CygxActivityVoiceHistory, err error) {
  41. o := orm.NewOrm()
  42. sql := `SELECT * FROM cygx_activity_voice_history WHERE 1 =1 ` + condition + ` GROUP BY user_id `
  43. _, err = o.Raw(sql).QueryRows(&items)
  44. return
  45. }
  46. // 修改用户浏览活动音频的相关信息
  47. func UpdateCygxActivityVoiceHistory(wxUser *WxUserItem) (err error) {
  48. o := orm.NewOrm()
  49. var sql string
  50. if wxUser.Mobile != "" {
  51. sql = `UPDATE cygx_activity_voice_history SET email=?,company_id=?,company_name=?,user_id=?,real_name=? WHERE mobile=? `
  52. _, err = o.Raw(sql, wxUser.Email, wxUser.CompanyId, wxUser.CompanyName, wxUser.UserId, wxUser.RealName, wxUser.Mobile).Exec()
  53. } else if wxUser.Email != "" {
  54. sql = `UPDATE cygx_activity_voice_history SET mobile=?,company_id=?,company_name=?,user_id=?,real_name=? WHERE email=? `
  55. _, err = o.Raw(sql, wxUser.Mobile, wxUser.CompanyId, wxUser.CompanyName, wxUser.UserId, wxUser.RealName, wxUser.Email).Exec()
  56. }
  57. return
  58. }