Browse Source

收藏应用列表,展示应用列表,取消收藏

huangyan 9 months ago
parent
commit
0370cdd91d

+ 52 - 14
app/controller/appUser.go

@@ -31,6 +31,55 @@ func RegistApply(c *gin.Context) {
 	e.ResponseWithMsg(c, user, user.GetMsg())
 }
 
+// LoginAppUser 用户登录-账号密码登录
+func LoginAppUser(c *gin.Context) {
+	var appuser model.AppUserRegist
+	if err := c.ShouldBindJSON(&appuser); err != nil {
+		e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg())
+		return
+	}
+	validate := validator.New()
+	err := validate.Struct(appuser)
+	if err != nil {
+		e.ResponseWithMsg(c, e.PleaseCheckTherRquiredFields, e.PleaseCheckTherRquiredFields.GetMsg())
+		return
+	}
+	login, token := AppUser.AccountLogin(appuser)
+	if login == e.NOTTABLE {
+		e.ResponseWithMsg(c, e.SUCCESS, e.NOTTABLE.GetMsg())
+		return
+	}
+	if login == e.SUCCESS {
+		e.ResponseSuccess(c, token)
+		return
+	}
+	e.ResponseWithMsg(c, login, login.GetMsg())
+}
+
+// LoginAppUserByCode 验证码登录
+func LoginAppUserByCode(c *gin.Context) {
+	var appuser model.AppUserRegist
+	if err := c.ShouldBindJSON(&appuser); err != nil {
+		e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg())
+		return
+	}
+	validate := validator.New()
+	err := validate.Var(appuser.Code, "required")
+	err = validate.Var(appuser.Phone, "required")
+	err = validate.Var(appuser.AppID, "required")
+	if err != nil {
+		e.ResponseWithMsg(c, e.PleaseCheckTherRquiredFields, e.PleaseCheckTherRquiredFields.GetMsg())
+		return
+	}
+	login, s := AppUser.CodeLogin(appuser)
+	if login == e.SUCCESS {
+
+		e.ResponseSuccess(c, s)
+		return
+	}
+	e.ResponseWithMsg(c, login, login.GetMsg())
+}
+
 // AddAppUser 添加用户
 func AddAppUser(c *gin.Context) {
 	var appuser model.AppUser
@@ -43,10 +92,6 @@ func AddAppUser(c *gin.Context) {
 	if err != nil {
 		e.ResponseWithMsg(c, e.JSONParsingFailed, err.Error())
 	}
-	//if err := validate.Struct(appuser); err != nil {
-	//	e.ResponseWithMsg(c, e.JSONParsingFailed, err.Error())
-	//	return
-	//}
 	user := AppUser.AddAppUser(appuser)
 	if user == e.SUCCESS {
 		e.ResponseWithMsg(c, e.SUCCESS, e.SUCCESS.GetMsg())
@@ -57,19 +102,12 @@ func AddAppUser(c *gin.Context) {
 
 // GetAppUserList 获取用户列表
 func GetAppUserList(c *gin.Context) {
-	var params unity.QueryPageParams
+	var params unity.CapQueryPageParams
 	if err := c.ShouldBindJSON(&params); err != nil {
 		e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg())
 		return
 	}
-	app_id := c.Query("app_id")
-	validate := validator.New()
-	err := validate.Var(app_id, "required")
-	if err != nil {
-		e.ResponseWithMsg(c, e.JSONParsingFailed, "缺少appid")
-		return
-	}
-	tableName := "appuser_" + app_id
+	tableName := "appuser_" + params.AppId
 	queryCond := "username like ?"
 	params.Query = "%" + params.Query + "%"
 	result, total, err := AppUser.GetAppUserList(params, tableName, queryCond)
@@ -81,7 +119,7 @@ func GetAppUserList(c *gin.Context) {
 		e.ResponseWithMsg(c, e.PaginationFailed, e.PaginationFailed.GetMsg())
 		return
 	}
-	e.ResPonsePage(c, result, total, params)
+	e.CapResPonsePage(c, result, total, params)
 }
 
 // UpdateAppUser 更新用户信息

+ 19 - 1
app/controller/apply.go

@@ -140,15 +140,33 @@ func GetApplyByAPPID(c *gin.Context) {
 // GetApplyByName 未登录状态下的模糊查询获取应用
 func GetApplyByName(c *gin.Context) {
 	appname := c.Query("appname")
+	value, _ := c.Get("phone")
 	validate := validator.New()
 	if err := validate.Var(appname, "required"); err != nil {
 		e.ResponseWithMsg(c, e.ERROR, err.Error())
 		return
 	}
-	apply, err := Apply.QueryApplyByAppName(appname)
+	apply, err := Apply.QueryApplyByAppName(appname, value.(string))
 	if err != nil {
 		e.ResponseWithMsg(c, e.ERROR, "未查找到相关应用")
 		return
 	}
 	e.ResponseSuccess(c, apply)
 }
+
+// GetApplyByNameAll 未登录状态下获取所有应用列表
+func GetApplyByNameAll(c *gin.Context) {
+	var params unity.QueryPageParams
+	var apply model.Apply
+	if err := c.ShouldBindJSON(&params); err != nil {
+		e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg())
+		return
+	}
+	phone, _ := c.Get("phone")
+	result, total, err := Apply.CollectionList(params, apply, phone.(string))
+	if err != nil {
+		e.ResponseWithMsg(c, e.PaginationFailed, e.PaginationFailed.GetMsg())
+		return
+	}
+	e.ResPonsePage(c, result, total, params)
+}

+ 0 - 2
app/controller/applyCap.go

@@ -86,7 +86,6 @@ func UpDateApplyCapSort(c *gin.Context) {
 		return
 	}
 	e.ResponseSuccess(c, nil)
-
 }
 
 // DeleteApplyCap 删除应用能力
@@ -124,5 +123,4 @@ func GetCapDetailByCapID(c *gin.Context) {
 		return
 	}
 	e.ResponseSuccess(c, id)
-
 }

+ 6 - 7
app/controller/capabilities.go

@@ -92,16 +92,15 @@ func AdminUpdateCapabilities(c *gin.Context) {
 
 // AdminDeleteCap 删除功能
 func AdminDeleteCap(c *gin.Context) {
-	capid := c.Query("capid")
-	err := validator.New().Var(capid, "required")
-	if err != nil {
-		e.ResponseWithMsg(c, e.PleaseCheckTherRquiredFields, e.PleaseCheckTherRquiredFields.GetMsg())
+	var capabilities model.Capabilities
+	if err := c.ShouldBindJSON(&capabilities); err != nil {
+		e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg())
 		return
 	}
-	capabilities := Capabilities.DeleteCapabilities(capid)
-	if capabilities == e.SUCCESS {
+	capre := Capabilities.DeleteCapabilities(capabilities.CapId)
+	if capre == e.SUCCESS {
 		e.ResponseSuccess(c, nil)
 		return
 	}
-	e.ResponseWithMsg(c, capabilities, capabilities.GetMsg())
+	e.ResponseWithMsg(c, capre, capre.GetMsg())
 }

+ 28 - 0
app/controller/user.go

@@ -49,3 +49,31 @@ func Login(c *gin.Context) {
 		e.ResponseSuccess(c, token)
 	}
 }
+
+// CollectionApp 收藏应用
+func CollectionApp(c *gin.Context) {
+	var user model.CollectionAppDto
+	if err := c.ShouldBind(&user); err != nil {
+		e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg())
+		return
+	}
+	value, _ := c.Get("phone")
+	user.Phone = value.(string)
+	app := User.CollectionApp(user)
+	if app != e.SUCCESS {
+		e.ResponseWithMsg(c, app, app.GetMsg())
+		return
+	}
+	e.ResponseSuccess(c, nil)
+}
+
+// CollectionList 展示收藏列表
+func CollectionList(c *gin.Context) {
+	value, _ := c.Get("phone")
+	list, applies := User.CollectionList(value.(string))
+	if list != e.SUCCESS {
+		e.ResponseWithMsg(c, list, list.GetMsg())
+		return
+	}
+	e.ResponseSuccess(c, applies)
+}

+ 8 - 0
app/e/code_msg.go

@@ -5,6 +5,7 @@ type Rescode int64
 const (
 	SUCCESS Rescode = 200 + iota
 	ERROR
+	NOTTABLE
 )
 
 const (
@@ -37,11 +38,15 @@ const (
 	CAPISNOT
 	ThereAreNoFeatures
 	FINDFAIL
+	LOGINFAIL
+	NOTREGIST
+	CollectionFAIL
 )
 
 var MsgFlags = map[Rescode]string{
 	SUCCESS:                       "ok",
 	ERROR:                         "fail",
+	NOTTABLE:                      "该资源不存在",
 	DELETEFAIL:                    "删除失败",
 	TheUserAlreadyExists:          "用户已存在",
 	TheSystemIsAbnormal:           "系统异常",
@@ -71,6 +76,9 @@ var MsgFlags = map[Rescode]string{
 	CAPISNOT:                     "该功能不存在",
 	ThereAreNoFeatures:           "该系统未配置功能项,请前往添加",
 	FINDFAIL:                     "查询失败",
+	LOGINFAIL:                    "登录失败",
+	NOTREGIST:                    "未注册请前往注册",
+	CollectionFAIL:               "收藏失败",
 }
 
 func (c Rescode) GetMsg() string {

+ 4 - 3
app/middleware/logon_middeware.go

@@ -15,11 +15,12 @@ func LogonMiddeware() gin.HandlerFunc {
 			e.ResponseWithMsg(c, e.TokenIsInvalid, e.TokenIsInvalid.GetMsg())
 			c.Abort()
 		} else {
-			_, err := utils.ParseToken(split[1])
-			if err != nil {
-				e.ResponseWithMsg(c, e.TokenIsInvalid, err.Error())
+			user, err := utils.ParseToken(split[1])
+			if err != e.SUCCESS {
+				e.ResponseWithMsg(c, err, err.GetMsg())
 				c.Abort()
 			} else {
+				c.Set("phone", user.UserName)
 				c.Next()
 			}
 		}

+ 60 - 4
app/model/appUser.go

@@ -19,18 +19,18 @@ type AppUser struct {
 	Nickname      string     `gorm:"type:varchar(50);" json:"nickname"`                                            // 昵称
 	Password      string     `gorm:"type:varchar(50);" json:"password"`                                            // 密码
 	LastLoginTime utils.Time `gorm:"type:datetime;" json:"last_login_time"`                                        // 最后登录时间
-	State         int        `gorm:"type:int;" json:"state"`                                                       // 状态 0:正常 1:禁用
+	State         int        `gorm:"type:int;" json:"state"`                                                       // 状态 1:正常 2:禁用
 	AppID         string     `gorm:"type:varchar(50);" json:"app_id" validate:"required"`                          // 应用id
 	RegistMethod  int        `gorm:"type:int;" json:"regist_method"`                                               // 注册方式 1 短信登录 2 微信登录 3 系统添加
 }
 
 type AppUserRegist struct {
 	Username     string `gorm:"type:varchar(50);index:username_name,unique" json:"username" validate:"required" min:"3" max:"50"` // 用户名
-	Phone        string `gorm:"type:varchar(50);" json:"phone" validate:"required" min:"11" max:"11"`                             // 手机号
+	Phone        string `gorm:"type:varchar(50);" json:"phone"`                                                                   // 手机号
 	Nickname     string `gorm:"type:varchar(50);" json:"nickname"`                                                                // 昵称
 	Password     string `gorm:"type:varchar(50);" json:"password" validate:"required" min:"6" max:"20"`                           // 密码
 	AppID        string `gorm:"type:varchar(50);not null;unique" json:"app_id" validate:"required"`                               // 应用id
-	Code         string `json:"code" validate:"required" min:"6" max:"6"`                                                         // 验证码
+	Code         string `json:"code"`                                                                                             // 验证码
 	RegistMethod int    `gorm:"type:int;" json:"regist_method"`                                                                   // 注册方式 1 短信登录 2 微信登录 3 系统添加
 }
 type AppUserDel struct {
@@ -38,6 +38,59 @@ type AppUserDel struct {
 	AppID string `json:"app_id" validate:"required"`
 }
 
+// AccountLogin 账号登录
+func (a AppUser) AccountLogin(appUser AppUserRegist) (e.Rescode, string) {
+	//TODO implement me
+	tableName := "appUser_" + appUser.AppID
+	tx := global.DBLink.Table(tableName)
+	if tx.Error != nil {
+		if strings.Contains(tx.Error.Error(), "Error 1146 (42S02)") {
+			return e.NOTTABLE, ""
+		}
+		return e.LOGINFAIL, ""
+	}
+	md5 := utils.MD5(appUser.Password)
+	tx.Select("username", "id", "password", "nickname", "phone").
+		Where("username=? and password=?", appUser.Username, md5).
+		Where("state=?", 1).First(&a)
+	token, err := utils.CreateToken(a.ID, a.Username, "user")
+	token = "interior:" + token
+	if err != nil {
+		return e.TokenIsFaild, ""
+	}
+	if tx.RowsAffected > 0 {
+		global.DBLink.Table(tableName).Where("id=?", a.ID).Update("last_login_time", utils.Time(time.Now()))
+		return e.SUCCESS, token
+	}
+	return e.ThePasswordIsWrongOrThePhoneNumberIsIncorrect, ""
+}
+
+// CodeLogin 验证码登录
+func (a AppUser) CodeLogin(appUser AppUserRegist) (e.Rescode, string) {
+	//TODO implement me
+	result, err := global.Rdb.Get(context.Background(), appUser.Phone).Result()
+	if err != nil {
+		return e.TheVerificationCodeWasNotSent, ""
+	}
+	if result != appUser.Code {
+		return e.CodeIsError, ""
+	}
+	tableName := "appUser_" + appUser.AppID
+	tx := global.DBLink.Table(tableName)
+	tx.Select("username", "id", "password", "nickname", "phone").
+		Where("phone=?", appUser.Phone).First(&a)
+	token, err := utils.CreateToken(a.ID, a.Username, "user")
+	token = "interior:" + token
+	if a.Phone != "" {
+		global.DBLink.Table(tableName).Where("id=?", a.ID).Update("last_login_time", utils.Time(time.Now()))
+		return e.SUCCESS, token
+	} else {
+		return e.NOTREGIST, ""
+	}
+
+}
+
+// DeleteAppUserByID 删除用户
 func (a AppUser) DeleteAppUserByID(id int, tableName string) e.Rescode {
 	//TODO implement me
 	tx := global.DBLink.Table(tableName).Where("id=?", id).Delete(&a)
@@ -46,6 +99,8 @@ func (a AppUser) DeleteAppUserByID(id int, tableName string) e.Rescode {
 	}
 	return e.SUCCESS
 }
+
+// UpdateAppUser 更新用户
 func (a AppUser) UpdateAppUser(appUser AppUser, tabaleName string) e.Rescode {
 	//TODO implement me
 	tx := global.DBLink.Table(tabaleName).Updates(appUser)
@@ -55,7 +110,8 @@ func (a AppUser) UpdateAppUser(appUser AppUser, tabaleName string) e.Rescode {
 	return e.SUCCESS
 }
 
-func (a AppUser) GetAppUserList(params unity.QueryPageParams, tableName string, queryCond string) (result []AppUser, total int64, err error) {
+// GetAppUserList 获取用户列表
+func (a AppUser) GetAppUserList(params unity.CapQueryPageParams, tableName string, queryCond string) (result []AppUser, total int64, err error) {
 	query := global.DBLink.Table(tableName)
 	if params.Query != "%%" {
 		query = query.Where(queryCond, params.Query)

+ 54 - 7
app/model/apply.go

@@ -5,7 +5,6 @@ import (
 	"encoding/json"
 	"fmt"
 	"gorm.io/gorm"
-	"log"
 	"project_management/app/e"
 	"project_management/global"
 	"project_management/unity"
@@ -34,6 +33,7 @@ type Apply struct {
 	BackgroundImageObscure *float32     `gorm:"type:double;" json:"background_image_obscure"`                                                // 背景图模糊度
 	TopicPC                *int         `gorm:"type:int;" json:"topic_pc"`                                                                   // 主题pc
 	TopicMobile            *int         `gorm:"type:int;" json:"topic_mobile"`                                                               // 主题移动
+	IsCollection           int          `gorm:"type:int;" json:"is_collection"`                                                              // 是否收藏 1 代表已收藏
 }
 
 type LoginMethod []int
@@ -97,13 +97,26 @@ func (a Apply) GetApplyAminList(params unity.QueryPageParams, apply Apply, query
 func (a Apply) TableName() string {
 	return "applies"
 }
-func (a Apply) QueryApplyByAppName(appName string) ([]Apply, error) {
+func (a Apply) QueryApplyByAppName(appName, phone string) ([]Apply, error) {
 	//TODO implement me
 	var app []Apply
+	var user User
 	tx := global.DBLink.
-		Select("app_name", "icon", "app_description", "app_id", "user_name").
 		Where("app_name like ?", "%"+appName+"%").
 		Find(&app)
+	first := global.DBLink.Table(user.TableName()).Where("phone = ?", phone).First(&user)
+	if first.Error != nil {
+		return nil, first.Error
+	}
+	colls := make(map[string]bool)
+	for _, s := range user.Collection {
+		colls[s] = true
+	}
+	for i, _ := range app {
+		if colls[app[i].AppID] {
+			app[i].IsCollection = 1
+		}
+	}
 	if tx.Error != nil {
 		return nil, tx.Error
 	}
@@ -129,7 +142,6 @@ func (a Apply) GetApplyById(appid string) (Apply, error) {
 
 func (a Apply) UserUpdateApply(apply Apply) e.Rescode {
 	//TODO implement me
-	log.Print(apply)
 	tx := global.DBLink.Where("id=?", apply.ID).Where("user_id=?", apply.UserId).Updates(&apply)
 	if tx.Error != nil {
 		return e.ERROR
@@ -237,9 +249,18 @@ func (a Apply) AddApply(apply Apply) e.Rescode {
 	apply.CertificationTime = utils.Time(tiem)
 	apply.State = 1
 	apply.Icon = global.IconSetting.IconPath
-	*apply.BackgroundImageObscure = 0.5
-	*apply.TopicPC = 1
-	*apply.TopicMobile = 1
+	if apply.BackgroundImageObscure == nil {
+		apply.BackgroundImageObscure = new(float32)
+		*apply.BackgroundImageObscure = 0.5
+	}
+	if apply.TopicPC == nil {
+		apply.TopicPC = new(int)
+		*apply.TopicPC = 1
+	}
+	if apply.TopicMobile == nil {
+		apply.TopicMobile = new(int)
+		*apply.TopicMobile = 1
+	}
 	tx := global.DBLink.Create(&apply)
 	if tx.Error != nil {
 		errMsg := tx.Error.Error()
@@ -318,3 +339,29 @@ func (a Apply) UpDateApplyCap(applycap ApplyCapabilities) e.Rescode {
 	}
 	return e.UPDATEFAIL
 }
+func (a Apply) CollectionList(params unity.QueryPageParams, apply Apply, phone string) (result []AppDto, total int64, err error) {
+	//TODO implement me
+	var user User
+	query := global.DBLink.Table(apply.TableName())
+	if err = query.Count(&total).Where("state = ?", 1).Error; err != nil {
+		return nil, 0, err
+	}
+	offset := (params.Page - 1) * params.Size
+	if err = query.Offset(offset).Limit(params.Size).Order(params.Desc).Find(&result).Where("state = ?", 1).Error; err != nil {
+		return nil, 0, err
+	}
+	first := global.DBLink.Table(user.TableName()).Where("phone = ?", phone).First(&user)
+	if first.Error != nil {
+		return nil, 0, err
+	}
+	colls := make(map[string]bool)
+	for _, s := range user.Collection {
+		colls[s] = true
+	}
+	for i, _ := range result {
+		if colls[result[i].AppID] {
+			result[i].IsCollection = 1
+		}
+	}
+	return result, total, nil
+}

+ 118 - 8
app/model/user.go

@@ -2,42 +2,152 @@ package model
 
 import (
 	"context"
+	"database/sql/driver"
+	"encoding/json"
+	"fmt"
 	"gorm.io/gorm"
+	"project_management/app/e"
 	"project_management/global"
 	"project_management/utils"
 )
 
 type User struct {
 	gorm.Model
-	Phone string `gorm:"type:varchar(50);" json:"phone" validate:"required" min:"11" max:"11"`
+	Phone      string     `gorm:"type:varchar(50);" json:"phone" validate:"required" min:"11" max:"11"`
+	Collection collection `gorm:"type:json" json:"collection"` // 收藏系统
 }
+type CollectionAppDto struct {
+	Phone      string     `gorm:"type:varchar(50);" json:"phone" validate:"required" min:"11" max:"11"`
+	Collection collection `gorm:"type:json" json:"collection"` // 收藏系统
+	State      int        `gorm:"type:int;" json:"state"`
+}
+
+func (u User) TableName() string {
+	return "users"
+}
+
 type UserRegist struct {
 	Phone string `json:"phone" validate:"required" min:"11" max:"11"`
 	Code  string `json:"code" validate:"required" min:"6" max:"6"`
+	Token string `json:"token"`
 }
+type collection []string
 
-func (u User) Login(user UserRegist) (string, string) {
+func (lo collection) Value() (driver.Value, error) {
+	return json.Marshal(lo)
+}
+
+func (fn *collection) Scan(src interface{}) error {
+	if src == nil {
+		*fn = make(collection, 0)
+		return nil
+	}
+	var u []byte
+	switch v := src.(type) {
+	case string:
+		u = []byte(v)
+	case []byte:
+		u = v
+	default:
+		return fmt.Errorf("unsupported type: %T", src)
+	}
+	return json.Unmarshal(u, (*[]string)(fn))
+}
+
+// Login 登录
+func (u User) Login(user UserRegist) (UserRegist, string) {
 	//TODO implement me
+	var usere UserRegist
 	tx := global.DBLink.Where("phone = ?", user.Phone).First(&u)
 	ctx := context.Background()
 	result, err := global.Rdb.Get(ctx, user.Phone).Result()
 	if err != nil {
-		return "", "验证验证码失败请联系管理员"
+		return UserRegist{}, "验证验证码失败请联系管理员"
 	} else if result != user.Code {
-		return "", "验证码错误"
+		return UserRegist{}, "验证码错误"
 	}
 	token, err := utils.CreateToken(u.ID, u.Phone, "user")
 	token = "interior:" + token
 	if err != nil {
-		return "", "创建令牌失败"
+		return UserRegist{}, "创建令牌失败"
 	}
+	usere.Phone = user.Phone
+	usere.Token = token
 	if tx.RowsAffected == 0 {
 		u.Phone = user.Phone
 		create := global.DBLink.Create(&u)
 		if create.Error != nil {
-			return "", "登录失败"
+			return UserRegist{}, "登录失败"
+		}
+		return usere, ""
+	} else {
+		return usere, ""
+	}
+}
+func (u User) CollectionApp(user CollectionAppDto) e.Rescode {
+	//TODO implement me
+	tx := global.DBLink.Table(u.TableName())
+	if tx.Error != nil {
+		return e.CollectionFAIL
+	}
+	tx.Where("phone = ?", user.Phone).First(&u)
+	u.Collection = append(u.Collection)
+	capIdsMap := make(map[string]bool)
+	if user.State == 1 {
+		for _, v := range u.Collection {
+			capIdsMap[v] = true
+		}
+		for _, s := range user.Collection {
+			if _, ok := capIdsMap[s]; !ok {
+				u.Collection = append(u.Collection, s)
+			}
+		}
+	} else if user.State == 0 {
+		strings := removeDuplicates(u.Collection, user.Collection)
+		u.Collection = strings
+	}
+	updates := tx.Where("phone = ?", user.Phone).
+		Updates(map[string]interface{}{"collection": u.Collection})
+
+	if updates.Error != nil {
+		return e.CollectionFAIL
+	}
+	if updates.RowsAffected > 0 {
+		return e.SUCCESS
+	}
+	return e.CollectionFAIL
+
+}
+func (u User) CollectionList(phone string) (e.Rescode, []Apply) {
+	//TODO implement me
+	var applys []Apply
+	tx := global.DBLink.Table(u.TableName())
+	if tx.Error != nil {
+		return e.FINDFAIL, applys
+	}
+	tx.Where("phone = ?", phone).First(&u)
+	for _, s := range u.Collection {
+		var apply Apply
+		find := global.DBLink.Table(Apply{}.TableName()).Where("app_id = ?", s).Find(&apply)
+		if find.Error != nil {
+			return e.FINDFAIL, applys
+		} else if find.RowsAffected > 0 {
+			applys = append(applys, apply)
+		}
+	}
+	return e.SUCCESS, applys
+}
+
+func removeDuplicates(slice1, slice2 []string) []string {
+	exclusionMap := make(map[string]bool)
+	for _, item := range slice2 {
+		exclusionMap[item] = true
+	}
+	var result []string
+	for _, item := range slice1 {
+		if !exclusionMap[item] {
+			result = append(result, item)
 		}
-		return token, ""
 	}
-	return token, ""
+	return result
 }

+ 1 - 1
app/router.go

@@ -15,7 +15,7 @@ func InitRouter() error {
 	//第三方用户登录
 	engine.Use(middlewares.LogonMiddeware())
 	routers.AppUserRouter(engine)
-	routers.ApplyNotLogin(engine)
+	routers.ClientApply(engine)
 	//用户登录
 	engine.Use(middlewares.LoginMiddleware())
 	routers.ApplyCapRouter(engine)

+ 2 - 0
app/routers/appUser.go

@@ -12,4 +12,6 @@ func AppUserRouter(r *gin.Engine) {
 	group.POST("/appuserlist", controller.GetAppUserList)
 	group.PUT("/appuser", controller.UpdateAppUser)
 	group.DELETE("/appuser", controller.DeleteAppUserByID)
+	group.POST("/accountlogin", controller.LoginAppUser)
+	group.POST("/codelogin", controller.LoginAppUserByCode)
 }

+ 0 - 12
app/routers/applynotlogin.go

@@ -1,12 +0,0 @@
-package routers
-
-import (
-	"github.com/gin-gonic/gin"
-	"project_management/app/controller"
-)
-
-func ApplyNotLogin(r *gin.Engine) {
-	group := r.Group("/api")
-	group.GET("/applyname", controller.GetApplyByName)
-
-}

+ 15 - 0
app/routers/clientApply.go

@@ -0,0 +1,15 @@
+package routers
+
+import (
+	"github.com/gin-gonic/gin"
+	"project_management/app/controller"
+)
+
+func ClientApply(r *gin.Engine) {
+	group := r.Group("/api")
+	group.GET("/applyname", controller.GetApplyByName)
+	group.POST("/user/collection", controller.CollectionApp)
+	group.GET("/user/collectionlist", controller.CollectionList)
+	group.POST("/user/applylist", controller.GetApplyByNameAll)
+
+}

+ 3 - 1
app/services/appUser.go

@@ -9,7 +9,9 @@ import (
 type AppUser interface {
 	AddAppUser(appUser model.AppUser) e.Rescode
 	RegistAppUser(appUser model.AppUserRegist) e.Rescode
-	GetAppUserList(params unity.QueryPageParams, tableName string, queryCond string) (result []model.AppUser, total int64, err error)
+	GetAppUserList(params unity.CapQueryPageParams, tableName string, queryCond string) (result []model.AppUser, total int64, err error)
 	UpdateAppUser(appUser model.AppUser, tabaleName string) e.Rescode
 	DeleteAppUserByID(id int, tableName string) e.Rescode
+	AccountLogin(appUser model.AppUserRegist) (e.Rescode, string)
+	CodeLogin(appUser model.AppUserRegist) (e.Rescode, string)
 }

+ 2 - 1
app/services/apply.go

@@ -11,8 +11,9 @@ type Apply interface {
 	GetApplyList(params unity.QueryPageParams, apply model.Apply, queryCond string) (result []model.Apply, total int64, err error)
 	UserUpdateApply(apply model.Apply) e.Rescode
 	GetApplyById(appid string) (model.Apply, error)
-	QueryApplyByAppName(appName string) ([]model.Apply, error)
+	QueryApplyByAppName(appName, phone string) ([]model.Apply, error)
 	GetApplyAminList(params unity.QueryPageParams, apply model.Apply, queryCond string) (result []model.AppDto, total int64, err error)
 	ApplyAddCap(applycap model.ApplyCapabilities) e.Rescode
 	UpDateApplyCap(applycap model.ApplyCapabilities) e.Rescode
+	CollectionList(params unity.QueryPageParams, apply model.Apply, queryCond string) (result []model.AppDto, total int64, err error)
 }

+ 4 - 1
app/services/user.go

@@ -1,9 +1,12 @@
 package services
 
 import (
+	"project_management/app/e"
 	"project_management/app/model"
 )
 
 type User interface {
-	Login(user model.UserRegist) (string, string)
+	Login(user model.UserRegist) (model.UserRegist, string)
+	CollectionApp(user model.CollectionAppDto) e.Rescode
+	CollectionList(phone string) (e.Rescode, []model.Apply)
 }

+ 1 - 0
configs/config.yaml

@@ -48,5 +48,6 @@ qiniu:
   accessKeyID: "-8ezB_d-8-eUFTMvhOGbGzgeQRPeKQnaQ3DBcUxo"
   accessKeySecret: "KFhkYxTAJ2ZPN3ZS3euTsfWk8-C92rKgkhAMkDRN"
   bucketName: "bzdcdn"
+#  应用默认图标
 Icon:
   iconPath: "icon/icon.png"

+ 7 - 6
utils/create_token.go

@@ -3,6 +3,7 @@ package utils
 import (
 	"errors"
 	"github.com/golang-jwt/jwt/v4"
+	"project_management/app/e"
 	"project_management/global"
 	"time"
 )
@@ -30,7 +31,7 @@ func CreateToken(userId uint, userName, role string) (string, error) {
 	token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
 	return token.SignedString(mySerect)
 }
-func ParseToken(tokenStr string) (*MyClaims, error) {
+func ParseToken(tokenStr string) (*MyClaims, e.Rescode) {
 	// 使用全局配置中的密钥对token进行解析。
 	var mySecret = []byte(global.JwtSetting.Secret)
 
@@ -42,18 +43,18 @@ func ParseToken(tokenStr string) (*MyClaims, error) {
 
 	if err != nil {
 		if errors.Is(err, jwt.ErrSignatureInvalid) || errors.Is(err, jwt.ErrInvalidKey) {
-			return nil, errors.New("无效的签名或密钥")
+			return nil, e.TokenIsInvalid
 		} else if ve, ok := err.(*jwt.ValidationError); ok && ve.Errors&jwt.ValidationErrorExpired != 0 {
-			return nil, errors.New("令牌已过期")
+			return nil, e.TokenIsExpired
 		}
-		return nil, errors.New("令牌解析失败")
+		return nil, e.TokenIsInvalid
 	}
 
 	// 验证令牌是否有效。
 	if !token.Valid {
-		return nil, errors.New("无效的令牌")
+		return nil, e.TokenIsInvalid
 	}
 
 	// 如果令牌有效,则返回解析出的声明信息。
-	return claims, nil
+	return claims, e.SUCCESS
 }