rdluck преди 4 години
родител
ревизия
349c8c4913
променени са 3 файла, в които са добавени 48 реда и са изтрити 26 реда
  1. 40 21
      controllers/user.go
  2. 4 1
      models/company.go
  3. 4 4
      models/user.go

+ 40 - 21
controllers/user.go

@@ -143,34 +143,53 @@ func (this *UserController) Detail() {
 		br.Ret = 408
 		return
 	}
-	item, err := models.GetUserDetailByUserId(user.UserId)
+	uid := user.UserId
+	item, err := models.GetUserDetailByUserId(uid)
 	if err != nil {
 		br.Msg = "获取信息失败"
 		br.ErrMsg = "获取信息失败,Err:" + err.Error()
 		return
 	}
-	companyItem, err := models.GetCompanyDetailById(user.CompanyId)
-	if err != nil && err.Error() != utils.ErrNoRow() {
-		br.Msg = "获取信息失败"
-		br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
-		return
-	}
-	if companyItem != nil {
-		item.CompanyName = companyItem.CompanyName
-		var hasPermission bool
-		if companyItem.Status == "试用" || companyItem.Status == "永续" || companyItem.Status == "正式" {
-			hasPermission = true
-			permissionStr, err := models.GetCompanyPermission(companyItem.CompanyId)
-			if err != nil {
-				br.Msg = "获取信息失败"
-				br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
-				return
+
+	var hasPermission int
+	if user.CompanyId > 0 {
+		companyItem, err := models.GetCompanyDetailById(user.CompanyId)
+		if err != nil && err.Error() != utils.ErrNoRow() {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
+			return
+		}
+		if companyItem != nil {
+			item.CompanyName = companyItem.CompanyName
+			if companyItem.Status == "试用" || companyItem.Status == "永续" || companyItem.Status == "正式" {
+				hasPermission = 1
+				permissionStr, err := models.GetCompanyPermission(companyItem.CompanyId)
+				if err != nil {
+					br.Msg = "获取信息失败"
+					br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
+					return
+				}
+				item.PermissionName = permissionStr
 			}
-			item.PermissionName = permissionStr
+			item.HasPermission = hasPermission
+
+			item.SellerName = companyItem.SellerName
+			item.SellerMobile = companyItem.Mobile
+		}
+	} else {
+		//判断是否已经申请过
+		applyCount, err := models.GetApplyRecordCount(uid)
+		if err != nil && err.Error() != utils.ErrNoRow() {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
+			return
+		}
+		if applyCount > 0 {
+			hasPermission = 3
+		} else {
+			hasPermission = 2
 		}
-		item.HasPermission = hasPermission
 	}
-
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "获取成功"
@@ -617,7 +636,7 @@ func (this *UserController) ApplyTryOut() {
 		}
 		sellerMobile = sellerItem.Mobile
 	}
-	err = models.AddApplyRecord(&req, user.Mobile,user.CompanyName, user.UserId,user.CompanyId)
+	err = models.AddApplyRecord(&req, user.Mobile, user.CompanyName, user.UserId, user.CompanyId)
 	if err != nil {
 		br.Msg = "申请失败"
 		br.ErrMsg = "申请失败,Err:" + err.Error()

+ 4 - 1
models/company.go

@@ -8,11 +8,14 @@ type CompanyDetail struct {
 	Status      string `description:"客户状态"`
 	SellerId    int    `description:"销售id"`
 	SellerName  string `description:"销售名称"`
+	Mobile      string `description:"销售手机号"`
 }
 
 func GetCompanyDetailById(companyId int) (item *CompanyDetail, err error) {
-	sql := ` SELECT a.company_id,a.company_name,b.status,b.seller_id,b.seller_name FROM company AS a
+	sql := ` SELECT a.company_id,a.company_name,b.status,b.seller_id,b.seller_name,c.mobile 
+            FROM company AS a
 			INNER JOIN company_product AS b ON a.company_id=b.company_id
+			INNER JOIN admin AS c ON b.seller_id=c.admin_id
 			WHERE a.company_id=? AND  b.product_id=2 `
 	o := orm.NewOrm()
 	err = o.Raw(sql, companyId).QueryRow(&item)

+ 4 - 4
models/user.go

@@ -15,7 +15,9 @@ type UserDetail struct {
 	RealName       string `description:"用户实际名称"`
 	CompanyName    string `description:"公司名称"`
 	PermissionName string `description:"拥有权限分类,多个用英文逗号分隔"`
-	HasPermission  bool   `description:"true:有权限,false:无权限"`
+	HasPermission  int    `description:"1:有权限,2:潜在客户,未提交过申请,3:潜在客户,已提交过申请"`
+	SellerMobile   string `description:"销售手机号"`
+	SellerName     string `description:"销售名称"`
 }
 
 func GetUserDetailByUserId(userId int) (item *UserDetail, err error) {
@@ -200,7 +202,5 @@ type ApplyTryReq struct {
 	BusinessCardUrl string `description:"名片地址"`
 	RealName        string `description:"姓名"`
 	CompanyName     string `description:"公司名称"`
-	ApplyMethod     int    `description:"1:已付费客户申请试用,2:非客户申请试用"`
+	ApplyMethod     int    `description:"1:已付费客户申请试用,2:非客户申请试用,3:非客户申请试用(ficc下,不需要进行数据校验)"`
 }
-
-