浏览代码

Merge branch 'eta/1.4'

hsun 1 年之前
父节点
当前提交
5528073d74
共有 6 个文件被更改,包括 19 次插入7 次删除
  1. 7 4
      middleware/token.go
  2. 1 0
      models/crm/admin.go
  3. 1 0
      models/eta/admin.go
  4. 2 1
      routers/auth.go
  5. 6 2
      services/sys_user_sync.go
  6. 2 0
      utils/constants.go

+ 7 - 4
middleware/token.go

@@ -1,9 +1,9 @@
 package middleware
 
 import (
-	"fmt"
 	"github.com/gin-gonic/gin"
 	"hongze/hz_crm_eta/controller/resp"
+	"hongze/hz_crm_eta/utils"
 )
 
 func Token() gin.HandlerFunc {
@@ -16,12 +16,15 @@ func Token() gin.HandlerFunc {
 			}
 		}
 		if token == "" {
-			resp.TokenError(nil, "未登录或非法访问", "未登录或非法访问", c)
+			resp.TokenError(nil, "非法访问", "非法访问", c)
+			c.Abort()
+			return
+		}
+		if token != utils.CrmEtaAuthorization {
+			resp.TokenError(nil, "非法访问", "非法访问", c)
 			c.Abort()
 			return
 		}
-		fmt.Println("token:" + token)
-		//c.Set("adminInfo", admin)
 		c.Next()
 	}
 }

+ 1 - 0
models/crm/admin.go

@@ -42,6 +42,7 @@ type Admin struct {
 	City                      string    `gorm:"column:city;type:varchar(255);default:''" json:"city"`                                                     // 市
 	CityCode                  string    `gorm:"column:city_code;type:varchar(100);default:''" json:"city_code"`                                           // 市编码
 	EmployeeId                string    `gorm:"column:employee_id;type:varchar(64);not null;default:''" json:"employee_id"`                               // 员工工号(钉钉/每刻报销)
+	TelAreaCode               string    `gorm:"column:tel_area_code;type:varchar(32);not null;default:'86'" json:"tel_area_code"`                         // 手机号区号
 }
 
 func (m *Admin) TableName() string {

+ 1 - 0
models/eta/admin.go

@@ -42,6 +42,7 @@ type Admin struct {
 	City                      string    `gorm:"column:city;type:varchar(255);default:''" json:"city"`                                                     // 市
 	CityCode                  string    `gorm:"column:city_code;type:varchar(100);default:''" json:"city_code"`                                           // 市编码
 	EmployeeId                string    `gorm:"column:employee_id;type:varchar(64);not null;default:''" json:"employee_id"`                               // 员工工号(钉钉/每刻报销)
+	TelAreaCode               string    `gorm:"column:tel_area_code;type:varchar(32);not null;default:'86'" json:"tel_area_code"`                         // 手机号区号
 }
 
 func (m *Admin) TableName() string {

+ 2 - 1
routers/auth.go

@@ -3,12 +3,13 @@ package routers
 import (
 	"github.com/gin-gonic/gin"
 	"hongze/hz_crm_eta/controller"
+	"hongze/hz_crm_eta/middleware"
 )
 
 func InitAuth(r *gin.RouterGroup) {
 	//登录
 	authController := new(controller.AuthController)
-	authGroup := r.Group("auth/")
+	authGroup := r.Group("auth/").Use(middleware.Token())
 	authGroup.POST("auth_code", authController.CreateAuthCode)
 	authGroup.POST("eta_token", authController.GetEtaToken)
 	authGroup.POST("crm_token", authController.GetCrmToken)

+ 6 - 2
services/sys_user_sync.go

@@ -205,6 +205,7 @@ func HandleSyncAdmin(data SyncAdminData) (err error) {
 			newUser.City = crmUser.City
 			newUser.CityCode = crmUser.CityCode
 			newUser.EmployeeId = crmUser.EmployeeId
+			newUser.TelAreaCode = crmUser.TelAreaCode
 			e = newUser.Create()
 			if e != nil {
 				err = fmt.Errorf("新增ETA对应用户失败, Err: " + e.Error())
@@ -244,11 +245,12 @@ func HandleSyncAdmin(data SyncAdminData) (err error) {
 		etaUser.City = crmUser.City
 		etaUser.CityCode = crmUser.CityCode
 		etaUser.EmployeeId = crmUser.EmployeeId
+		etaUser.TelAreaCode = crmUser.TelAreaCode
 		cols := []string{
 			"AdminName", "AdminAvatar", "RealName", "Password", "LastUpdatedPasswordTime", "Enabled", "Email", "LastUpdatedTime",
 			"Role", "Mobile", "RoleType", "RoleId", "RoleName", "RoleTypeCode", "DepartmentId", "DepartmentName", "GroupId", "GroupName",
 			"Authority", "Position", "DirectorId", "DisableTime", "ChartPermission", "EdbPermission", "MysteelChemicalPermission", "OpenId",
-			"UnionId", "PredictEdbPermission", "Province", "ProvinceCode", "City", "CityCode", "EmployeeId",
+			"UnionId", "PredictEdbPermission", "Province", "ProvinceCode", "City", "CityCode", "EmployeeId", "TelAreaCode",
 		}
 		e = etaUser.Update(cols)
 		if e != nil {
@@ -310,6 +312,7 @@ func HandleSyncAdmin(data SyncAdminData) (err error) {
 		newUser.City = etaUser.City
 		newUser.CityCode = etaUser.CityCode
 		newUser.EmployeeId = etaUser.EmployeeId
+		newUser.TelAreaCode = etaUser.TelAreaCode
 		e = newUser.Create()
 		if e != nil {
 			err = fmt.Errorf("新增ETA对应用户失败, Err: " + e.Error())
@@ -349,11 +352,12 @@ func HandleSyncAdmin(data SyncAdminData) (err error) {
 	crmUser.City = etaUser.City
 	crmUser.CityCode = etaUser.CityCode
 	crmUser.EmployeeId = etaUser.EmployeeId
+	crmUser.TelAreaCode = etaUser.TelAreaCode
 	cols := []string{
 		"AdminName", "AdminAvatar", "RealName", "Password", "LastUpdatedPasswordTime", "Enabled", "Email", "LastUpdatedTime",
 		"Role", "Mobile", "RoleType", "RoleId", "RoleName", "RoleTypeCode", "DepartmentId", "DepartmentName", "GroupId", "GroupName",
 		"Authority", "Position", "DirectorId", "DisableTime", "ChartPermission", "EdbPermission", "MysteelChemicalPermission", "OpenId",
-		"UnionId", "PredictEdbPermission", "Province", "ProvinceCode", "City", "CityCode", "EmployeeId",
+		"UnionId", "PredictEdbPermission", "Province", "ProvinceCode", "City", "CityCode", "EmployeeId", "TelAreaCode",
 	}
 	e = crmUser.Update(cols)
 	if e != nil {

+ 2 - 0
utils/constants.go

@@ -86,3 +86,5 @@ const (
 	CACHE_SYNC_DEPARTMENT = "hz_crm_eta:sync_department"
 	CACHE_SYNC_GROUP      = "hz_crm_eta:sync_group"
 )
+
+const CrmEtaAuthorization = "NIi1RbEmH0C2rksXtPGDPBBgRgTZY87Q"