Browse Source

no message

xingzai 11 months ago
parent
commit
9a99b6f6c8

+ 0 - 1
controllers/user.go

@@ -171,7 +171,6 @@ func (this *UserController) Detail() {
 		br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
 		return
 	}
-	fmt.Println(utils.MD5(userDetail.Mobile))
 	if userDetail.Mobile != "" {
 		resp.InviteShareCode = services.GetInviteShareCode(userDetail.Mobile) //判断用户是否属于销售,并且获取对应加密的分享码
 	}

+ 1 - 1
models/admin.go

@@ -106,7 +106,7 @@ func GetSysAdminByMobile(mobile string) (item *Admin, err error) {
 	sql := ` SELECT  * FROM admin  WHERE
 				enabled = 1 
 				AND role_type_code IN ( 'admin', 'rai_seller', 'rai_group', 'rai_admin', 'rai_researcher' ) 
-				AND mobile = ? `
+				AND mobile = ?  LIMIT  1 `
 	err = o.Raw(sql, mobile).QueryRow(&item)
 	return
 }

+ 2 - 0
models/db.go

@@ -104,6 +104,8 @@ func init() {
 		new(CygxAskserieVideoCollect),
 		new(CygxVoiceAndVideoHistory),
 		new(CygxActivityVideoHistory),
+		new(CygxUserAdminShareHistory),
+		new(CygxUserAdminShareCode),
 	)
 	// 记录ORM查询日志
 	orm.Debug = true

+ 0 - 22
models/user_admin_share.go

@@ -1,22 +0,0 @@
-package models
-
-import "time"
-
-type CygxUserAdminShare struct {
-	UserAdminShareID int       `orm:"column(user_admin_share_id);pk";comment:"主键ID"`
-	Action           string    `comment:"动作内容"`
-	UserId           int       `comment:"用户ID"`
-	Mobile           string    `comment:"手机号"`
-	Email            string    `comment:"邮箱"`
-	CompanyId        int       `comment:"公司ID"`
-	CompanyName      string    `comment:"公司名称"`
-	RealName         string    `comment:"用户实际名称"`
-	SellerName       string    `comment:"所属销售名称"`
-	SellerId         int       `comment:"所属销售 ID"`
-	Source           string    `comment:"来源(article, activity, login)"`
-	SourceId         int       `comment:"来源 ID"`
-	SourceTitle      string    `comment:"来源名称,活动或者报告标题"`
-	RegisterPlatform int       `comment:"注册平台(1: 小程序, 2: 网页)"`
-	CreateTime       time.Time `comment:"创建时间"`
-	ModifyTime       time.Time `comment:"修改时间"`
-}

+ 30 - 0
models/user_admin_share_code.go

@@ -0,0 +1,30 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxUserAdminShareCode struct {
+	UserAdminCodeId int       `orm:"column(user_admin_share_code_id);pk";comment:"主键ID"`
+	SellerName      string    `comment:"所属销售"`
+	SellerId        int       `comment:"所属销售id"`
+	Mobile          string    `comment:"手机号"`
+	CreateTime      time.Time `comment:"创建时间"`
+	ModifyTime      time.Time `comment:"修改时间"`
+	ShareCode       string    `comment:"分享码,对seller_id进行MD5加密的结果"`
+}
+
+// 获取数量
+func GetCygxUserAdminShareCodeByShareCodeCount(chareCode string) (count int, err error) {
+	o := orm.NewOrm()
+	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_user_admin_share_code WHERE  share_code  = ? `
+	err = o.Raw(sqlCount, chareCode).QueryRow(&count)
+	return
+}
+
+func AddCygxUserAdminShareCode(item *CygxUserAdminShareCode) (err error) {
+	o := orm.NewOrm()
+	_, err = o.Insert(item)
+	return
+}

+ 22 - 0
models/user_admin_share_history.go

@@ -0,0 +1,22 @@
+package models
+
+import "time"
+
+type CygxUserAdminShareHistory struct {
+	UserAdminShareHistoryId int       `orm:"column(user_admin_share_history_id);pk";comment:"主键ID"`
+	Action                  string    `comment:"动作内容"`
+	UserId                  int       `comment:"用户ID"`
+	Mobile                  string    `comment:"手机号"`
+	Email                   string    `comment:"邮箱"`
+	CompanyId               int       `comment:"公司ID"`
+	CompanyName             string    `comment:"公司名称"`
+	RealName                string    `comment:"用户实际名称"`
+	SellerName              string    `comment:"所属销售名称"`
+	SellerId                int       `comment:"所属销售 ID"`
+	Source                  string    `comment:"来源(article, activity, login)"`
+	SourceId                int       `comment:"来源 ID"`
+	SourceTitle             string    `comment:"来源名称,活动或者报告标题"`
+	RegisterPlatform        int       `comment:"注册平台(1: 小程序, 2: 网页)"`
+	CreateTime              time.Time `comment:"创建时间"`
+	ModifyTime              time.Time `comment:"修改时间"`
+}

+ 0 - 139
services/aes.go

@@ -1,139 +0,0 @@
-package services
-
-// 加密解密
-import (
-	"crypto/aes"
-	"crypto/cipher"
-	"crypto/rand"
-	"encoding/base64"
-	"fmt"
-	"io"
-	"strconv"
-)
-
-var aseKey = []byte("kmk6ln3n4mibig8p") // 加密密钥(必须是16、24或32字节)
-
-// 加密
-func AseEncrypted(originalData int) (encryptedData string, err error) {
-	// 原始数据
-	//originalData := 123
-	// 加密数据
-	encryptedData, err = encrypt(originalData, aseKey)
-	//fmt.Println("加密后的数据:", encryptedData)
-
-	// 解密数据
-	//decryptedData, err := decrypt(encryptedData, aseKey)
-	//if err != nil {
-	//	fmt.Println("解密时出错:", err)
-	//	return
-	//}
-	//fmt.Println("解密后的数据:", decryptedData)
-	return
-}
-
-// 加密
-//func AseDecrypted(encryptedData string) (originalData int, err error) {
-//	// 原始数据
-//	//originalData := 123
-//	// 加密数据
-//	encryptedData, err = encrypt(originalData, aseKey)
-//	//fmt.Println("加密后的数据:", encryptedData)
-//
-//	// 解密数据
-//	//decryptedData, err := decrypt(encryptedData, aseKey)
-//	//if err != nil {
-//	//	fmt.Println("解密时出错:", err)
-//	//	return
-//	//}
-//	//fmt.Println("解密后的数据:", decryptedData)
-//	return
-//}
-
-//func init() {
-//	fmt.Println(AseEncrypted(106))
-//	//fmt.Println(decrypt(" m+v/mObub3ygVZrXdv0pX7kjNQ==", aseKey))
-//
-//	//decryptedData, err := decrypt("tIVURU5VYGSPVVFINXANpHQ2/w==", aseKey)
-//	decryptedData, err := decrypt("folm8/VB3NwxTVeTParQrosrVw==", aseKey)
-//	if err != nil {
-//		fmt.Println("解密时出错:", err)
-//		return
-//	}
-//	fmt.Println("解密后的数据:", decryptedData)
-//}
-
-// 加密
-func AseDecrypted(encryptedData string) (decryptedData int, err error) {
-	// 原始数据
-	//originalData := 123
-	// 加密数据
-	//originalData, err = decrypt(encryptedData, aseKey)
-	//fmt.Println("加密后的数据:", encryptedData)
-	//return
-	// 解密数据
-	decryptedData, err = decrypt(encryptedData, aseKey)
-	//if err != nil {
-	//	fmt.Println("解密时出错:", err)
-	//	return
-	//}
-	//fmt.Println("解密后的数据:", decryptedData)
-	return
-}
-
-func encrypt(data int, key []byte) (string, error) {
-	// 将数据转换为字节数组
-	dataBytes := []byte(fmt.Sprintf("%d", data))
-
-	// 创建一个新的 AES 块
-	block, err := aes.NewCipher(key)
-	if err != nil {
-		return "", err
-	}
-
-	// 创建一个加密流
-	ciphertext := make([]byte, aes.BlockSize+len(dataBytes))
-	iv := ciphertext[:aes.BlockSize]
-	if _, err := io.ReadFull(rand.Reader, iv); err != nil {
-		return "", err
-	}
-
-	// 使用密钥加密数据
-	stream := cipher.NewCFBEncrypter(block, iv)
-	stream.XORKeyStream(ciphertext[aes.BlockSize:], dataBytes)
-
-	// 返回加密后的数据(使用base64编码以便于传输)
-	return base64.StdEncoding.EncodeToString(ciphertext), nil
-}
-
-func decrypt(data string, key []byte) (int, error) {
-	// 解码base64数据
-	ciphertext, err := base64.StdEncoding.DecodeString(data)
-	if err != nil {
-		return 0, err
-	}
-
-	// 创建一个新的 AES 块
-	block, err := aes.NewCipher(key)
-	if err != nil {
-		return 0, err
-	}
-
-	// 解密流
-	if len(ciphertext) < aes.BlockSize {
-		return 0, fmt.Errorf("加密数据长度不够")
-	}
-	iv := ciphertext[:aes.BlockSize]
-	ciphertext = ciphertext[aes.BlockSize:]
-
-	// 解密数据
-	stream := cipher.NewCFBDecrypter(block, iv)
-	stream.XORKeyStream(ciphertext, ciphertext)
-
-	// 将解密的数据转换为int
-	decryptedData, err := strconv.Atoi(string(ciphertext))
-	if err != nil {
-		return 0, err
-	}
-
-	return decryptedData, nil
-}

+ 21 - 8
services/user_admin_share.go

@@ -5,6 +5,8 @@ import (
 	"fmt"
 	"hongze/hongze_web_mfyx/models"
 	"hongze/hongze_web_mfyx/utils"
+	"strconv"
+	"time"
 )
 
 // 判断用户是否属于销售,并且获取对应加密的分享码
@@ -21,21 +23,32 @@ func GetInviteShareCode(mobile string) (inviteShareCode string) {
 	}()
 	adminDetail, e := models.GetSysAdminByMobile(mobile)
 	if e != nil {
-		err = errors.New("GetCygxGoodsList, Err: " + e.Error())
+		err = errors.New("GetSysAdminByMobile, Err: " + e.Error())
 		return
 	}
 	if adminDetail == nil {
 		return
 	}
-	inviteShareCode, e = AseEncrypted(adminDetail.AdminId)
+	inviteShareCode = utils.MD5(strconv.Itoa(adminDetail.AdminId)) //MD5 对ID进行加密
+	total, e := models.GetCygxUserAdminShareCodeByShareCodeCount(inviteShareCode)
 	if e != nil {
-		err = errors.New("AseEncrypted, Err: " + e.Error())
+		err = errors.New("GetSysAdminByMobile, Err: " + e.Error())
 		return
 	}
+	//如果不存在就新增一个
+	if total == 0 {
+		item := new(models.CygxUserAdminShareCode)
+		item.SellerName = adminDetail.RealName
+		item.SellerId = adminDetail.AdminId
+		item.Mobile = adminDetail.Mobile
+		item.CreateTime = time.Now()
+		item.ModifyTime = time.Now()
+		item.ShareCode = inviteShareCode
+		e = models.AddCygxUserAdminShareCode(item)
+		if e != nil {
+			err = errors.New("AddCygxUserAdminShareCode, Err: " + e.Error())
+			return
+		}
+	}
 	return
 }
-
-//func init() {
-//	fmt.Println(GetInviteShareCode("15557270714"))
-//	fmt.Println(AseDecrypted("QZqxHK3ObVYm2DbN3ztbwSiF7Q=="))
-//}

+ 0 - 3
services/user_permission.go

@@ -2,7 +2,6 @@ package services
 
 import (
 	"errors"
-	"fmt"
 	"hongze/hongze_web_mfyx/models"
 	"hongze/hongze_web_mfyx/utils"
 	"strings"
@@ -256,7 +255,6 @@ func GetUserDetailPermissionCode(userId, companyId int) (permission int, err err
 		err = errors.New("获取用户申请信息失败, Err: " + e.Error())
 		return
 	}
-	fmt.Println("companyId", companyId)
 	if companyId == 1 {
 		// 潜在用户
 		if applyCount > 0 {
@@ -294,6 +292,5 @@ func GetUserDetailPermissionCode(userId, companyId int) (permission int, err err
 			}
 		}
 	}
-	fmt.Println("permission", permission)
 	return
 }