apply_record.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type CygxApplyRecord struct {
  7. ApplyRecordId int `orm:"column(apply_record_id);pk" description:"申请试用id"`
  8. UserId int `description:"用户ID"`
  9. BusinessCardUrl string `description:"名片地址"`
  10. RealName string `description:"姓名"`
  11. CompanyName string `description:"公司名称"`
  12. CompanyIdPay int `description:"已付费客户公司id"`
  13. CompanyIdType int `description:"用户状态,1:潜在客户 、2:现有客户 、3:FICC客户 、4:现有客户(正式,无对应权限) 、5:现有客户(试用,无对应权限) 、6:现有客户(试用暂停) 、7:现有客户(冻结) 、8:现有客户(流失) "`
  14. CompanyNamePay string `description:"公司名称"`
  15. Mobile string `description:"手机号"`
  16. CreateTime time.Time `description:"创建时间"`
  17. ApplyMethod int `description:"1:已付费客户申请试用,2:非客户申请试用"`
  18. RegisterPlatform int `description:"来源 1小程序,2:网页"`
  19. InviteCompanySource int `description:"来源 1小程序,2:网页"`
  20. SourceId int `description:"资源ID"`
  21. Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial"`
  22. Title string `description:"标题"`
  23. }
  24. type CygxApplyRecordResp struct {
  25. ApplyRecordId int `orm:"column(apply_record_id);pk" description:"申请试用id"`
  26. UserId int `description:"用户ID"`
  27. BusinessCardUrl string `description:"名片地址"`
  28. RealName string `description:"姓名"`
  29. CompanyName string `description:"公司名称"`
  30. CompanyIdPay int `description:"已付费客户公司id"`
  31. CompanyIdType int `description:"用户状态,1:潜在客户 、2:现有客户 、3:FICC客户 、4:现有客户(正式,无对应权限) 、5:现有客户(试用,无对应权限) 、6:现有客户(试用暂停) 、7:现有客户(冻结) 、8:现有客户(流失) "`
  32. CompanyNamePay string `description:"公司名称"`
  33. Mobile string `description:"手机号"`
  34. CreateTime time.Time `description:"创建时间"`
  35. ApplyMethod int `description:"1:已付费客户申请试用,2:非客户申请试用"`
  36. RegisterPlatform int `description:"来源 1小程序,2:网页"`
  37. InviteCompanySource int `description:"三方来源 ,1:弘则本身,2:络町"`
  38. ApplicationSource string `description:"申请来源"`
  39. }
  40. func AddApplyRecord(item *CygxApplyRecord) (err error) {
  41. o, err := orm.NewOrm().Begin()
  42. if err != nil {
  43. return
  44. }
  45. defer func() {
  46. if err != nil {
  47. o.Rollback()
  48. } else {
  49. o.Commit()
  50. }
  51. }()
  52. _, err = o.Insert(item)
  53. if err != nil {
  54. return
  55. }
  56. ow := orm.NewOrmUsingDB("weekly_report")
  57. msql := `UPDATE wx_user
  58. SET
  59. note = ?,
  60. is_note = 1,
  61. apply_method = ?,
  62. real_name=?,
  63. mobile=?
  64. WHERE user_id = ? `
  65. _, err = ow.Raw(msql, item.CompanyName, item.ApplyMethod, item.RealName, item.Mobile, item.UserId).Exec()
  66. return
  67. }
  68. func GetApplyRecordCount(userId int) (count int, err error) {
  69. o := orm.NewOrm()
  70. sql := `SELECT COUNT(1) AS count FROM cygx_apply_record WHERE user_id=? AND status=0 `
  71. err = o.Raw(sql, userId).QueryRow(&count)
  72. return
  73. }
  74. // 获取客户的试用申请次数
  75. func GetApplyRecordCountByCompanyIdPay(companyIdPay int) (count int, err error) {
  76. o := orm.NewOrm()
  77. sql := `SELECT COUNT(1) AS count FROM cygx_apply_record WHERE company_id_pay = ? `
  78. err = o.Raw(sql, companyIdPay).QueryRow(&count)
  79. return
  80. }
  81. // 通过手机号获取详情
  82. func GetCygxApplyRecordByMobile(mobile string) (item *CygxApplyRecord, err error) {
  83. o := orm.NewOrm()
  84. sql := `SELECT * FROM cygx_apply_record WHERE mobile=? AND status=0 ORDER BY apply_record_id DESC LIMIT 1 `
  85. err = o.Raw(sql, mobile).QueryRow(&item)
  86. return
  87. }
  88. // 通过ID获取详情
  89. func GetCygxApplyRecordById(applyRecordId int) (item *CygxApplyRecordResp, err error) {
  90. o := orm.NewOrm()
  91. sql := `SELECT * FROM cygx_apply_record WHERE apply_record_id=? `
  92. err = o.Raw(sql, applyRecordId).QueryRow(&item)
  93. return
  94. }
  95. type CygxApplyRecordDetialResp struct {
  96. Detail *CygxApplyRecordResp
  97. }