package services import ( "hongze/hongze_api/models" "hongze/hongze_api/utils" "strings" "time" ) // AddYbApply FICC客户申请 func AddYbApply(userId int, companyId int, mobile, email string, applyInfo models.YbApplyReq) ( err error, brMsg, brErrMsg string) { sellerName := `` status := `潜在用户` companyName := applyInfo.CompanyName ybApplyRecord := new(models.YbApplyRecord) tmpmYbApplyRecord, tErr := models.GetLastApplyRecordNotOpRecordByUserId(userId) if tErr == nil { ybApplyRecord = tmpmYbApplyRecord // 申请来源每一种只存在一条数据 return } else { if tErr.Error() != utils.ErrNoRow() { err = tErr return } } // 联系人信息 wxUserInfo, err := models.GetWxUserItemByUserId(userId) if err != nil { return } if companyId > 1 { //客户信息 companyInfo, tmpErr := models.GetCompanyInfoById(companyId) if tmpErr != nil { err = tmpErr return } companyName = companyInfo.CompanyName //客户产品权限 companyProductList, tmpErr := models.GetCompanyById(companyId) if tmpErr != nil { err = tmpErr return } sellerNameList := make([]string, 0) statusList := make([]string, 0) for _, companyProductInfo := range companyProductList { if companyProductInfo.ProductId == 1 { sellerName = companyProductInfo.SellerName status = companyProductInfo.Status if companyProductInfo.IsSuspend == 1 && status== "试用"{ status = `试用暂停` } } } if len(sellerNameList) > 0 && len(statusList) > 0 { sellerName = strings.Join(sellerNameList, ",") status = strings.Join(statusList, ",") } if strings.Contains("正式,永续,试用", status){ //brMsg ="正式、永续、试用状态 无需申请" return } } applyMethod := wxUserInfo.ApplyMethod //0:未申请,1:已付费客户申请试用,2:非客户申请试用 applyMethod = 2 if sellerName != "" { applyMethod = 1 } ybApplyRecord = &models.YbApplyRecord{ UserID: userId, //BusinessCardURL: applyInfo.BusinessCardUrl, RealName: applyInfo.RealName, CompanyName: applyInfo.CompanyName, Mobile: mobile, Email: email, //Permission: applyInfo.Permission, SellerName: sellerName, Status: status, CompanyIDPay: companyId, CompanyNamePay: companyName, CreateTime: time.Now(), // Source: applyInfo.Source, SourceAgent: 3, //申请入口来源,1:小程序,2:pc,3:弘则研究公众号" // FromPage: applyInfo.FromPage, } err = models.AddYbApplyRecord(ybApplyRecord) if err != nil { return } // 修改客户信息 wxUserInfo.RealName = applyInfo.RealName wxUserInfo.Note = applyInfo.CompanyName wxUserInfo.IsNote = 1 wxUserInfo.ApplyMethod = applyMethod err = models.ModifyWxUserNameApplyMethod(wxUserInfo.UserId, wxUserInfo.RealName, wxUserInfo.Note, wxUserInfo.IsNote, wxUserInfo.ApplyMethod) return } // AddUserApply 权益研报过来的用户直接走原先的申请逻辑 func AddUserApply(req models.YbApplyReq, applyMethod int, userInfo *models.WxUserItem) (err error, brMsg, brErrMsg string) { realName := req.RealName if applyMethod == 2 { if realName == "" { brMsg ="姓名不能为空!" return } } err = models.Apply(userInfo.UserId, applyMethod, userInfo.Mobile, userInfo.Email, req.CompanyName, realName, userInfo.OpenId) if err != nil { brMsg = "申请失败!" brErrMsg = "申请失败,Err:" + err.Error() return } return }