yb_apply.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. package services
  2. import (
  3. "hongze/hongze_api/models"
  4. "hongze/hongze_api/utils"
  5. "strings"
  6. "time"
  7. )
  8. // AddYbApply FICC客户申请
  9. func AddYbApply(userId int, companyId int, mobile, email string, applyInfo models.YbApplyReq) ( err error, brMsg, brErrMsg string) {
  10. sellerName := ``
  11. status := `潜在用户`
  12. companyName := applyInfo.CompanyName
  13. ybApplyRecord := new(models.YbApplyRecord)
  14. tmpmYbApplyRecord, tErr := models.GetLastApplyRecordNotOpRecordByUserId(userId)
  15. if tErr == nil {
  16. ybApplyRecord = tmpmYbApplyRecord // 申请来源每一种只存在一条数据
  17. return
  18. } else {
  19. if tErr.Error() != utils.ErrNoRow() {
  20. err = tErr
  21. return
  22. }
  23. }
  24. // 联系人信息
  25. wxUserInfo, err := models.GetWxUserItemByUserId(userId)
  26. if err != nil {
  27. return
  28. }
  29. if companyId > 1 {
  30. //客户信息
  31. companyInfo, tmpErr := models.GetCompanyInfoById(companyId)
  32. if tmpErr != nil {
  33. err = tmpErr
  34. return
  35. }
  36. companyName = companyInfo.CompanyName
  37. //客户产品权限
  38. companyProductList, tmpErr := models.GetCompanyById(companyId)
  39. if tmpErr != nil {
  40. err = tmpErr
  41. return
  42. }
  43. sellerNameList := make([]string, 0)
  44. statusList := make([]string, 0)
  45. for _, companyProductInfo := range companyProductList {
  46. if companyProductInfo.ProductId == 1 {
  47. sellerName = companyProductInfo.SellerName
  48. status = companyProductInfo.Status
  49. if companyProductInfo.IsSuspend == 1 && status== "试用"{
  50. status = `试用暂停`
  51. }
  52. }
  53. }
  54. if len(sellerNameList) > 0 && len(statusList) > 0 {
  55. sellerName = strings.Join(sellerNameList, ",")
  56. status = strings.Join(statusList, ",")
  57. }
  58. if strings.Contains("正式,永续,试用", status){
  59. //brMsg ="正式、永续、试用状态 无需申请"
  60. return
  61. }
  62. }
  63. applyMethod := wxUserInfo.ApplyMethod //0:未申请,1:已付费客户申请试用,2:非客户申请试用
  64. applyMethod = 2
  65. if sellerName != "" {
  66. applyMethod = 1
  67. }
  68. ybApplyRecord = &models.YbApplyRecord{
  69. UserID: userId,
  70. //BusinessCardURL: applyInfo.BusinessCardUrl,
  71. RealName: applyInfo.RealName,
  72. CompanyName: applyInfo.CompanyName,
  73. Mobile: mobile,
  74. Email: email,
  75. //Permission: applyInfo.Permission,
  76. SellerName: sellerName,
  77. Status: status,
  78. CompanyIDPay: companyId,
  79. CompanyNamePay: companyName,
  80. CreateTime: time.Now(),
  81. // Source: applyInfo.Source,
  82. SourceAgent: 3, //申请入口来源,1:小程序,2:pc,3:弘则研究公众号"
  83. // FromPage: applyInfo.FromPage,
  84. }
  85. err = models.AddYbApplyRecord(ybApplyRecord)
  86. if err != nil {
  87. return
  88. }
  89. // 修改客户信息
  90. wxUserInfo.RealName = applyInfo.RealName
  91. wxUserInfo.Note = applyInfo.CompanyName
  92. wxUserInfo.IsNote = 1
  93. wxUserInfo.ApplyMethod = applyMethod
  94. err = models.ModifyWxUserNameApplyMethod(wxUserInfo.UserId, wxUserInfo.RealName, wxUserInfo.Note, wxUserInfo.IsNote, wxUserInfo.ApplyMethod)
  95. return
  96. }
  97. // AddUserApply 权益研报过来的用户直接走原先的申请逻辑
  98. func AddUserApply(req models.YbApplyReq, applyMethod int, userInfo *models.WxUserItem) (err error, brMsg, brErrMsg string) {
  99. realName := req.RealName
  100. if applyMethod == 2 {
  101. if realName == "" {
  102. brMsg ="姓名不能为空!"
  103. return
  104. }
  105. }
  106. err = models.Apply(userInfo.UserId, applyMethod, userInfo.Mobile, userInfo.Email, req.CompanyName, realName, userInfo.OpenId)
  107. if err != nil {
  108. brMsg = "申请失败!"
  109. brErrMsg = "申请失败,Err:" + err.Error()
  110. return
  111. }
  112. return
  113. }