xingzai 1 рік тому
батько
коміт
b25e3a6d55
2 змінених файлів з 29 додано та 5 видалено
  1. 20 4
      controllers/company_user.go
  2. 9 1
      services/aliyun.go

+ 20 - 4
controllers/company_user.go

@@ -579,7 +579,7 @@ func (this *CompanyUserController) AddUser() {
 		//如果百度未识别出来手机号或者公司名称,那么进行阿里识别
 		if !isFlag || (len(companyNameSlice) == 0 && crmConfig.ConfigValue == "true") {
 			//阿里云识别
-			aliyunResult, err := services.AliyunOcrBusinessCard(req.BusinessCardUrl)
+			aliyunResult, errMsg, err := services.AliyunOcrBusinessCard(req.BusinessCardUrl)
 			if err != nil {
 				br.Msg = "识别失败"
 				br.ErrMsg = "识别失败,Err:" + err.Error()
@@ -590,6 +590,10 @@ func (this *CompanyUserController) AddUser() {
 				br.ErrMsg = "识别失败"
 				return
 			}
+			if errMsg != "" {
+				br.Msg = errMsg
+				return
+			}
 			//如果百度没有识别出来手机号,那么还需要阿里识别出来的手机号校验下
 			if !isFlag {
 				if len(aliyunResult.TelCell) > 0 {
@@ -1972,7 +1976,7 @@ func (this *CompanyUserController) EditUser() {
 
 		if !isFlag {
 			//阿里云识别
-			aliyunResult, err := services.AliyunOcrBusinessCard(req.BusinessCardUrl)
+			aliyunResult, errMsg, err := services.AliyunOcrBusinessCard(req.BusinessCardUrl)
 			if err != nil {
 				br.Msg = "识别失败"
 				br.ErrMsg = "识别失败,Err:" + err.Error()
@@ -1983,6 +1987,10 @@ func (this *CompanyUserController) EditUser() {
 				br.ErrMsg = "识别失败"
 				return
 			}
+			if errMsg != "" {
+				br.Msg = errMsg
+				return
+			}
 
 			mobileStr := strings.Join(aliyunResult.TelCell, ",")
 			if req.MobileOne != "" {
@@ -2497,7 +2505,7 @@ func (this *CompanyController) PotentialUserMove() {
 			if !isFlag {
 				//阿里云识别
 				//if utils.RunMode == "release" {
-				aliyunResult, err := services.AliyunOcrBusinessCard(req.BusinessCardUrl)
+				aliyunResult, errMsg, err := services.AliyunOcrBusinessCard(req.BusinessCardUrl)
 				if err != nil {
 					br.Msg = "识别失败"
 					br.ErrMsg = "识别失败,Err:" + err.Error()
@@ -2508,6 +2516,10 @@ func (this *CompanyController) PotentialUserMove() {
 					br.ErrMsg = "识别失败"
 					return
 				}
+				if errMsg != "" {
+					br.Msg = errMsg
+					return
+				}
 				if len(aliyunResult.TelCell) > 0 {
 					mobileStr := strings.Join(aliyunResult.TelCell, ",")
 					if req.Mobile != "" {
@@ -5082,7 +5094,7 @@ func (this *CompanyController) ApplyRecordPotentialUserMove() {
 			if !isFlag {
 				//阿里云识别
 				//if utils.RunMode == "release" {
-				aliyunResult, err := services.AliyunOcrBusinessCard(req.BusinessCardUrl)
+				aliyunResult, errMsg, err := services.AliyunOcrBusinessCard(req.BusinessCardUrl)
 				if err != nil {
 					br.Msg = "识别失败"
 					br.ErrMsg = "识别失败,Err:" + err.Error()
@@ -5093,6 +5105,10 @@ func (this *CompanyController) ApplyRecordPotentialUserMove() {
 					br.ErrMsg = "识别失败"
 					return
 				}
+				if errMsg != "" {
+					br.Msg = errMsg
+					return
+				}
 				if len(aliyunResult.TelCell) > 0 {
 					mobileStr := strings.Join(aliyunResult.TelCell, ",")
 					if req.Mobile != "" {

+ 9 - 1
services/aliyun.go

@@ -180,7 +180,7 @@ type OcrBusinessCardResult struct {
 }
 
 // 阿里云名片识别更换2024-01-02
-func AliyunOcrBusinessCard(imageurl string) (result *OcrBusinessCardResult, err error) {
+func AliyunOcrBusinessCard(imageurl string) (result *OcrBusinessCardResult, errMsg string, err error) {
 	url := "https://bizcard.market.alicloudapi.com/rest/160601/ocr/ocr_business_card.json"
 	method := "POST"
 
@@ -229,6 +229,14 @@ func AliyunOcrBusinessCard(imageurl string) (result *OcrBusinessCardResult, err
 	}
 	result.TelCell = telCell
 
+	if len(result.Company) == 0 && len(result.TelCell) == 0 {
+		errMsg = "OCR识别失败"
+	} else if len(result.Company) == 0 {
+		errMsg = "名片中未识别到公司名称"
+	} else if len(result.TelCell) == 0 {
+		errMsg = " 名片中未识别到手机号"
+	}
+
 	logItem := new(cygx.AliyunOcrLog)
 	logItem.ImgUrl = imageurl
 	logItem.Result = string(body)