apply_record.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. CompanyNamePay string `description:"公司名称"`
  12. Mobile string `description:"手机号"`
  13. CreateTime time.Time `description:"创建时间"`
  14. ApplyMethod int `description:"1:已付费客户申请试用,2:非客户申请试用"`
  15. RegisterPlatform int `description:"来源 1小程序,2:网页"`
  16. }
  17. func AddApplyRecord(item *ApplyTryReq, mobile, companyNamePay string, userId, companyIdPay, CompanyIdType int) (err error) {
  18. o, err := orm.NewOrm().Begin()
  19. if err != nil {
  20. return
  21. }
  22. defer func() {
  23. if err != nil {
  24. o.Rollback()
  25. } else {
  26. o.Commit()
  27. }
  28. }()
  29. 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)
  30. VALUES(?,?,?,?,?,?,?,?,?,?) `
  31. _, err = o.Raw(sql, userId, item.BusinessCardUrl, item.RealName, item.CompanyName, mobile, time.Now(), item.ApplyMethod, companyIdPay, companyNamePay, CompanyIdType).Exec()
  32. if err != nil {
  33. return
  34. }
  35. msql := `UPDATE wx_user
  36. SET
  37. note = ?,
  38. is_note = 1,
  39. apply_method = ?,
  40. real_name=?,
  41. mobile=?
  42. WHERE user_id = ? `
  43. _, err = o.Raw(msql, item.CompanyName, item.ApplyMethod, item.RealName, mobile, userId).Exec()
  44. return
  45. }
  46. func GetApplyRecordCount(userId int) (count int, err error) {
  47. o := orm.NewOrm()
  48. sql := `SELECT COUNT(1) AS count FROM cygx_apply_record WHERE user_id=? AND status=0 `
  49. err = o.Raw(sql, userId).QueryRow(&count)
  50. return
  51. }
  52. // 通过手机号获取详情
  53. func GetCygxApplyRecordByMobile(mobile string) (item *CygxApplyRecord, err error) {
  54. o := orm.NewOrm()
  55. sql := `SELECT * FROM cygx_apply_record WHERE mobile=? AND status=0 ORDER BY apply_record_id DESC LIMIT 1 `
  56. err = o.Raw(sql, mobile).QueryRow(&item)
  57. return
  58. }
  59. // 通过ID获取详情
  60. func GetCygxApplyRecordById(applyRecordId int) (item *CygxApplyRecord, err error) {
  61. o := orm.NewOrm()
  62. sql := `SELECT * FROM cygx_apply_record WHERE apply_record_id=? `
  63. err = o.Raw(sql, applyRecordId).QueryRow(&item)
  64. return
  65. }
  66. type CygxApplyRecordResp struct {
  67. Detail *CygxApplyRecord
  68. }