apply_record.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. BusinessCardUrl string `description:"名片地址"`
  9. RealName string `description:"姓名"`
  10. CompanyName string `description:"公司名称"`
  11. Mobile string `description:"手机号"`
  12. CreateTime time.Time `description:"创建时间"`
  13. ApplyMethod int `description:"1:已付费客户申请试用,2:非客户申请试用"`
  14. }
  15. func AddApplyRecord(item *ApplyTryReq, mobile, companyNamePay string, userId, companyIdPay, CompanyIdType int) (err error) {
  16. o, err := orm.NewOrm().Begin()
  17. if err != nil {
  18. return
  19. }
  20. defer func() {
  21. if err != nil {
  22. o.Rollback()
  23. } else {
  24. o.Commit()
  25. }
  26. }()
  27. sql := `INSERT INTO cygx_apply_record (user_id,business_card_url, real_name,company_name, mobile,create_time, apply_method,company_id_pay,company_name_pay,company_id_type)
  28. VALUES(?,?,?,?,?,?,?,?,?,?) `
  29. _, err = o.Raw(sql, userId, item.BusinessCardUrl, item.RealName, item.CompanyName, mobile, time.Now(), item.ApplyMethod, companyIdPay, companyNamePay, CompanyIdType).Exec()
  30. if err != nil {
  31. return
  32. }
  33. msql := `UPDATE wx_user
  34. SET
  35. note = ?,
  36. is_note = 1,
  37. apply_method = ?,
  38. real_name=?,
  39. mobile=?
  40. WHERE user_id = ? `
  41. _, err = o.Raw(msql, item.CompanyName, item.ApplyMethod, item.RealName, mobile, userId).Exec()
  42. return
  43. }
  44. func GetApplyRecordCount(userId int) (count int, err error) {
  45. o := orm.NewOrm()
  46. sql := `SELECT COUNT(1) AS count FROM cygx_apply_record WHERE user_id=? AND status=0 `
  47. err = o.Raw(sql, userId).QueryRow(&count)
  48. return
  49. }