Browse Source

取消节点重复判断

rdluck 4 years ago
parent
commit
240d4e5fb7

+ 19 - 2
controllers/article.go

@@ -46,8 +46,9 @@ func (this *ArticleController) Detail() {
 
 	collectCount, err := models.GetArticleCollectCount(uid, articleId)
 	if err != nil && err.Error() != utils.ErrNoRow() {
-		br.Msg = "判断是否已收藏失败"
+		br.Msg = "获取信息失败"
 		br.ErrMsg = "判断是否已收藏失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
+		return
 	}
 
 	if collectCount > 0 {
@@ -56,19 +57,35 @@ func (this *ArticleController) Detail() {
 
 	interviewApplyCount, err := models.GetArticleInterviewApplyCount(uid, articleId)
 	if err != nil && err.Error() != utils.ErrNoRow() {
-		br.Msg = "判断是否已申请访谈失败"
+		br.Msg = "获取信息失败"
 		br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
+		return
 	}
 
 	if interviewApplyCount > 0 {
 		detail.IsInterviewApply = true
 	}
+	var status int
+
+
+	//GetCompanyPermission
+	companyPermission,err:=models.GetCompanyPermission(user.CompanyId)
+	if err!=nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
+		return
+	}
+
 	//新增浏览记录
 	{
 		record := new(models.CygxArticleViewRecord)
 		record.UserId = uid
 		record.ArticleId = articleId
 		record.CreateTime = time.Now()
+		record.Mobile=user.Mobile
+		record.Email=user.Email
+		record.CompanyId=user.CompanyId
+		record.CompanyName=user.CompanyName
 		go models.AddCygxArticleViewRecord(record)
 	}
 	br.Ret = 200

+ 61 - 50
controllers/user.go

@@ -542,70 +542,80 @@ func (this *UserController) ApplyTryOut() {
 		br.ErrMsg = "参数解析失败,Err:" + err.Error()
 		return
 	}
+	var sellerMobile string
+	if req.ApplyMethod == 2 {
+		if req.BusinessCardUrl == "" {
+			br.Msg = "请上传名片"
+			return
+		}
 
-	if req.BusinessCardUrl == "" {
-		br.Msg = "请上传名片"
-		return
-	}
-
-	if req.RealName == "" {
-		br.Msg = "请输入姓名"
-		return
-	}
-
-	if req.CompanyName == "" {
-		br.Msg = "请输入公司名称"
-		return
-	}
+		if req.RealName == "" {
+			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()
+		if req.CompanyName == "" {
+			br.Msg = "请输入公司名称"
 			return
 		}
-		mobileStr := strings.Join(card.WordsResult.MOBILE, ",")
-		isFlag := true
-		if mobile != "" {
-			if strings.Contains(mobileStr, mobile) || mobileStr == "" {
-				isFlag = true
-			} else {
-				isFlag = false
+
+		if req.BusinessCardUrl != "" && utils.RunMode == "release" {
+			card, err := services.GetBusinessCard(req.BusinessCardUrl)
+			if err != nil {
+				br.Msg = "名片识别失败"
+				br.ErrMsg = "名片识别失败,Err:" + err.Error()
+				return
 			}
-		}
-		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(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
+					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
+			}
 		}
-		if !isFlag {
-			br.Msg = "名片手机号与所填手机号不匹配,请重新填写"
-			br.ErrMsg = "mobile:" + mobile
+	} else {
+		//获取销售信息
+		sellerItem, err := models.GetSellerByCompanyId(user.CompanyId)
+		if err != nil {
+			br.Msg = "申请失败"
+			br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
 			return
 		}
+		sellerMobile = sellerItem.Mobile
 	}
-
 	err = models.AddApplyRecord(&req, user.Mobile, user.UserId)
 	if err != nil {
 		br.Msg = "申请失败"
@@ -615,4 +625,5 @@ func (this *UserController) ApplyTryOut() {
 	br.Msg = "申请成功!"
 	br.Ret = 200
 	br.Success = true
+	br.Data = sellerMobile
 }

+ 9 - 0
models/article.go

@@ -58,3 +58,12 @@ func GetArticleDetailByIdStr(articleIdStr string) (items []*ArticleDetail, err e
 	_, err = o.Raw(sql).QueryRows(&items)
 	return
 }
+
+func GetArticlePermission(categoryName string) (item *ChartPermission, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT b.* FROM cygx_permission_mapping AS a
+			INNER JOIN chart_permission AS b ON a.chart_permission_id=b.chart_permission_id
+			WHERE a.sub_category_name=? `
+	err = o.Raw(sql, categoryName).QueryRow(&item)
+	return
+}

+ 9 - 5
models/article_view_record.go

@@ -6,10 +6,14 @@ import (
 )
 
 type CygxArticleViewRecord struct {
-	Id              int `orm:"column(id);pk"`
-	ArticleId       int
-	UserId          int
-	CreateTime      time.Time
+	Id          int `orm:"column(id);pk"`
+	ArticleId   int
+	UserId      int
+	CreateTime  time.Time
+	Mobile      string `description:"手机号"`
+	Email       string `description:"邮箱"`
+	CompanyId   int    `description:"公司id"`
+	CompanyName string `description:"公司名称"`
 }
 
 //添加收藏信息
@@ -17,4 +21,4 @@ func AddCygxArticleViewRecord(item *CygxArticleViewRecord) (lastId int64, err er
 	o := orm.NewOrm()
 	lastId, err = o.Insert(item)
 	return
-}
+}

+ 23 - 2
models/industry_map.go

@@ -12,9 +12,30 @@ type CygxIndustryMap struct {
 	CreateTime      time.Time
 }
 
-func GetCygxIndustryMapByName(industryName string) (items *CygxIndustryMap, err error) {
+func GetCygxIndustryMapByName(industryName string) (item *CygxIndustryMap, err error) {
 	o := orm.NewOrm()
 	sql := ` SELECT * FROM cygx_industry_map WHERE industry_map_name=? ORDER BY parent_id ASC LIMIT 1 `
-	err = o.Raw(sql, industryName).QueryRow(&items)
+	err = o.Raw(sql, industryName).QueryRow(&item)
 	return
 }
+
+func GetCygxIndustryMapAll() (items []*CygxIndustryMapItems, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT * FROM cygx_industry_map WHERE parent_id<>0`
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}
+
+type CygxIndustryMapItems struct {
+	IndustryMapId   int `orm:"column(industry_map_id);" description:"行业图谱id"`
+	IndustryMapName string
+	ParentId        int
+	Children        []*CygxIndustryMapItems
+}
+
+func GetCygxIndustryMapByParentId(parentId int) (items []*CygxIndustryMapItems, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT * FROM cygx_industry_map WHERE parent_id=?`
+	_, err = o.Raw(sql, parentId).QueryRows(&items)
+	return
+}

+ 27 - 0
models/seller.go

@@ -0,0 +1,27 @@
+package models
+
+import "rdluck_tools/orm"
+
+type AdminItem struct {
+	AdminId        int    `description:"系统用户id"`
+	RealName       string `description:"系统用户姓名"`
+	Mobile         string `description:"手机号"`
+	RoleType       int    `description:"角色类型:1需要录入指标,0:不需要"`
+	RoleId         int    `description:"角色id"`
+	RoleName       string `description:"角色名称"`
+	RoleTypeCode   string `description:"角色编码"`
+	DepartmentId   int    `description:"部门id"`
+	DepartmentName string `json:"-" description:"部门名称"`
+	GroupId        int    `description:"分组id"`
+	GroupName      string `json:"-" description:"分组名称"`
+	Authority      int    `description:"管理权限,0:无,1:部门负责人,2:小组负责人"`
+}
+
+func GetSellerByCompanyId(companyId int) (item *AdminItem, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT b.* FROM company_product AS a
+			INNER JOIN admin AS b ON a.seller_id=b.admin_id
+			WHERE a.company_id=? AND a.product_id=2 `
+	err = o.Raw(sql, companyId).QueryRow(&item)
+	return
+}

+ 5 - 2
models/wx_user.go

@@ -70,6 +70,7 @@ type WxUserItem struct {
 	CreatedTime     time.Time `description:"创建时间"`
 	LastUpdatedTime time.Time `description:"最近一次修改时间"`
 	SessionKey      string    `description:"微信小程序会话密钥"`
+	CompanyName     string    `description:"公司名称"`
 }
 
 func GetWxUserItemByUnionid(unionid string) (item *WxUserItem, err error) {
@@ -79,7 +80,9 @@ func GetWxUserItemByUnionid(unionid string) (item *WxUserItem, err error) {
 }
 
 func GetWxUserItemByUserId(userId int) (item *WxUserItem, err error) {
-	sql := `SELECT * FROM wx_user WHERE user_id=? `
+	sql := `SELECT a.*,b.company_name FROM wx_user AS a
+			LEFT JOIN company AS b on a.company_id=b.company_id
+			WHERE a.user_id=? `
 	err = orm.NewOrm().Raw(sql, userId).QueryRow(&item)
 	return
 }
@@ -148,7 +151,7 @@ type WxGetUserInfoResp struct {
 	//Language      string    `description:"语言"`
 	//Appid         string    `description:"Appid"`
 	//Timestamp     int64     `description:"时间戳"`
-	Authorization string    `description:"登陆凭证,后续接口调用时,带在请求头里面Key:Authorization"`
+	Authorization string `description:"登陆凭证,后续接口调用时,带在请求头里面Key:Authorization"`
 }
 
 type WxGetPhoneNumberReq struct {

+ 55 - 0
services/industry_map.go

@@ -0,0 +1,55 @@
+package services
+
+import (
+	"encoding/json"
+	"fmt"
+	"hongze/hongze_cygx/models"
+	"hongze/hongze_cygx/utils"
+)
+
+
+func MakeTree(allNode []*models.CygxIndustryMapItems, node *models.CygxIndustryMapItems) {
+	childs, _ := haveChild(allNode, node) //判断节点是否有子节点并返回
+	if len(childs) > 0 {
+		node.Children = append(node.Children, childs[0:]...) //添加子节点
+		for _, v := range childs {                           //查询子节点的子节点,并添加到子节点
+			_, has := haveChild(allNode, v)
+			if has {
+				MakeTree(allNode, v) //递归添加节点
+			}
+		}
+	}
+}
+
+func haveChild(allNode []*models.CygxIndustryMapItems, node *models.CygxIndustryMapItems) (childs []*models.CygxIndustryMapItems, yes bool) {
+	for _, v := range allNode {
+		if v.ParentId == node.IndustryMapId {
+			childs = append(childs, v)
+		}
+	}
+	if len(childs) > 0 {
+		yes = true
+	}
+	return
+}
+
+
+func GetIndustryMap() {
+	fmt.Println("start")
+	list, err := models.GetCygxIndustryMapByParentId(0)
+	if err != nil {
+		fmt.Println("GetCygxIndustryMapByParentId Err:",err.Error())
+		return
+	}
+	rootNode := list[0]
+	allNodes, err := models.GetCygxIndustryMapAll()
+	if err != nil {
+		fmt.Println("GetCygxIndustryMapAll Err:"+err.Error())
+		return
+	}
+	MakeTree(allNodes, rootNode)
+	resultJson,err:=json.Marshal(rootNode)
+	fmt.Println("Err:",err)
+	utils.FileLog.Info("allNodes:%s",string(resultJson))
+	fmt.Println("end")
+}

+ 1 - 0
services/task.go

@@ -10,5 +10,6 @@ func Task() {
 	//pageSize := 20
 	//SearchByKeyWord(keyWord, pageSize)
 	//SaveData()
+	//GetIndustryMap()
 	fmt.Println("end")
 }