|
@@ -2,7 +2,9 @@ package controllers
|
|
|
|
|
|
import (
|
|
|
"encoding/json"
|
|
|
+ "fmt"
|
|
|
"hongze/hongze_clpt/models"
|
|
|
+ "hongze/hongze_clpt/services"
|
|
|
"hongze/hongze_clpt/utils"
|
|
|
"strconv"
|
|
|
"strings"
|
|
@@ -131,3 +133,250 @@ func (this *UserController) Detail() {
|
|
|
br.Msg = "获取成功"
|
|
|
br.Data = resp
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (this *UserController) ApplyTryOut() {
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
+ defer func() {
|
|
|
+ this.Data["json"] = br
|
|
|
+ this.ServeJSON()
|
|
|
+ }()
|
|
|
+ user := this.User
|
|
|
+ if user == nil {
|
|
|
+ br.Msg = "请登录"
|
|
|
+ br.ErrMsg = "请登录,SysUser Is Empty"
|
|
|
+ br.Ret = 408
|
|
|
+ return
|
|
|
+ }
|
|
|
+ mobile := user.Mobile
|
|
|
+ var req models.ApplyTryReq
|
|
|
+ err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "参数解析异常!"
|
|
|
+ br.ErrMsg = "参数解析失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if req.RealName == "" {
|
|
|
+ req.RealName = user.RealName
|
|
|
+ }
|
|
|
+ if req.CompanyName == "" {
|
|
|
+ req.CompanyName = user.CompanyName
|
|
|
+ }
|
|
|
+ uid := user.UserId
|
|
|
+
|
|
|
+ var title string
|
|
|
+ tryType := req.TryType
|
|
|
+ detailId := req.DetailId
|
|
|
+ if tryType == "Article" {
|
|
|
+ detail, err := models.GetArticleDetailById(detailId)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取信息失败"
|
|
|
+ br.ErrMsg = "获取信息失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ title = detail.Title
|
|
|
+ }
|
|
|
+
|
|
|
+ fmt.Println(title)
|
|
|
+
|
|
|
+ cacheKey := fmt.Sprint("xygx:apply_record:add:", uid)
|
|
|
+ ttlTime := utils.Rc.GetRedisTTL(cacheKey)
|
|
|
+ if ttlTime > 0 {
|
|
|
+ br.Msg = "申请失败,申请过于频繁"
|
|
|
+ br.ErrMsg = "申请失败,申请过于频繁"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ utils.Rc.SetNX(cacheKey, user.Mobile, time.Second*10)
|
|
|
+
|
|
|
+
|
|
|
+ applyCount, err := models.GetApplyRecordCount(uid)
|
|
|
+ if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
+ br.Msg = "获取信息失败"
|
|
|
+ br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if applyCount > 0 {
|
|
|
+ br.Msg = "您已提交申请,请耐心等待。"
|
|
|
+ br.IsSendEmail = false
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ var sellerMobile string
|
|
|
+ if req.ApplyMethod == 2 {
|
|
|
+ if req.BusinessCardUrl == "" {
|
|
|
+ br.Msg = "请上传名片"
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if req.RealName == "" {
|
|
|
+ br.Msg = "请输入姓名"
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if req.CompanyName == "" {
|
|
|
+ br.Msg = "请输入公司名称"
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if req.BusinessCardUrl != "" && utils.RunMode == "release" {
|
|
|
+ card, err := services.GetBusinessCard(req.BusinessCardUrl)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "名片识别失败"
|
|
|
+ br.ErrMsg = "名片识别失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ mobileStr := strings.Join(card.WordsResult.MOBILE, ",")
|
|
|
+ isFlag := true
|
|
|
+ if mobile != "" {
|
|
|
+ if strings.Contains(mobileStr, mobile) || mobileStr == "" {
|
|
|
+ isFlag = true
|
|
|
+ } else {
|
|
|
+ isFlag = false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if !isFlag {
|
|
|
+
|
|
|
+ if utils.RunMode == "release" {
|
|
|
+ aliyunResult, err := services.AliyunBusinessCard(req.BusinessCardUrl)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "识别失败"
|
|
|
+ br.ErrMsg = "识别失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if !aliyunResult.Success {
|
|
|
+ br.Msg = "识别失败"
|
|
|
+ br.ErrMsg = "识别失败"
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ mobileStr := strings.Join(aliyunResult.TelCell, ",")
|
|
|
+ if mobile != "" {
|
|
|
+ if strings.Contains(mobileStr, mobile) {
|
|
|
+ isFlag = true
|
|
|
+ } else {
|
|
|
+ isFlag = false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if !isFlag {
|
|
|
+ br.Msg = "名片手机号与所填手机号不匹配,请重新填写"
|
|
|
+ br.ErrMsg = "mobile:" + mobile
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
|
|
|
+ if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
+ br.Msg = "申请失败"
|
|
|
+ br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if sellerItem != nil {
|
|
|
+ sellerMobile = sellerItem.Mobile
|
|
|
+
|
|
|
+ mobile := user.Mobile
|
|
|
+ if mobile == "" {
|
|
|
+ mobile = user.Email
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ CompanyIdType := 1
|
|
|
+ applyMethod := ""
|
|
|
+ cnf, _ := models.GetConfigByCode("tpl_msg")
|
|
|
+ if cnf != nil {
|
|
|
+ if sellerItem != nil {
|
|
|
+ cnf.ConfigValue = sellerItem.Mobile
|
|
|
+ companyItem, err := models.GetCompanyDetailById(user.CompanyId)
|
|
|
+ if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
+ br.Msg = "获取信息失败"
|
|
|
+ br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if companyItem != nil && companyItem.CompanyId > 0 {
|
|
|
+ companyProduct, err := models.GetCompanyProductDetail(user.CompanyId, 2)
|
|
|
+ if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
+ br.Msg = "获取信息失败"
|
|
|
+ br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if companyProduct != nil && companyProduct.IsSuspend == 1 {
|
|
|
+ CompanyIdType = 6
|
|
|
+ } else {
|
|
|
+ switch companyItem.Status {
|
|
|
+ case "正式":
|
|
|
+ CompanyIdType = 4
|
|
|
+ case "试用":
|
|
|
+ CompanyIdType = 5
|
|
|
+ case "冻结":
|
|
|
+ CompanyIdType = 7
|
|
|
+ case "流失":
|
|
|
+ CompanyIdType = 8
|
|
|
+ }
|
|
|
+ }
|
|
|
+ applyMethod = companyItem.Status + "客户申请"
|
|
|
+ if detailId > 0 {
|
|
|
+ if companyProduct != nil && companyProduct.IsSuspend == 1 {
|
|
|
+ applyMethod = "试用暂停客户"
|
|
|
+ } else {
|
|
|
+ if companyItem.Status == "正式" || companyItem.Status == "试用" {
|
|
|
+ applyMethod = companyItem.Status + "客户申请,无对应权限"
|
|
|
+ } else if companyItem.Status == "冻结" || companyItem.Status == "流失" {
|
|
|
+ applyMethod = companyItem.Status + "客户"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ applyMethod = applyMethod + "," + title
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+
|
|
|
+ sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 1)
|
|
|
+ if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
+ br.Msg = "申请失败"
|
|
|
+ br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if sellerItem != nil {
|
|
|
+ CompanyIdType = 3
|
|
|
+ applyMethod = "FICC客户"
|
|
|
+ } else {
|
|
|
+ CompanyIdType = 1
|
|
|
+ applyMethod = "潜在客户"
|
|
|
+ }
|
|
|
+ if detailId > 0 {
|
|
|
+ applyMethod = applyMethod + "," + title
|
|
|
+ }
|
|
|
+ }
|
|
|
+ openIpItem, _ := models.GetUserRecordByMobile(4, cnf.ConfigValue)
|
|
|
+ if openIpItem != nil && openIpItem.OpenId != "" {
|
|
|
+ if req.ApplyMethod != 2 {
|
|
|
+ req.RealName = user.RealName
|
|
|
+ req.CompanyName = user.CompanyName
|
|
|
+ }
|
|
|
+ utils.FileLog.Info("推送消息 %s %s,%s,%s,%s", req.RealName, req.CompanyName, mobile, openIpItem.OpenId, applyMethod)
|
|
|
+ go services.SendPermissionApplyTemplateMsg(req.RealName, req.CompanyName, mobile, applyMethod, openIpItem)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ err = models.AddApplyRecord(&req, user.Mobile, user.CompanyName, uid, user.CompanyId, CompanyIdType)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "申请失败"
|
|
|
+ br.ErrMsg = "申请失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ br.Msg = "申请成功!"
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Data = sellerMobile
|
|
|
+}
|