浏览代码

完善截止创建项目所有接口

Ohio-HYF 3 年之前
父节点
当前提交
ba1f48e415

+ 2 - 2
db/enterprise.go

@@ -16,7 +16,7 @@ func CreateEnterprise(ctx context.Context, newEnterprise gorm_model.Enterprise)
 	return &newEnterprise.EnterpriseID, nil
 }
 
-func GetEnterpriseByUID(ctx context.Context, userID int64) (*int64, error) {
+func GetEnterpriseByUID(ctx context.Context, userID int64) (*gorm_model.Enterprise, error) {
 	db := GetReadDB(ctx)
 	enterprise := gorm_model.Enterprise{}
 	err := db.Where("user_id = ?", userID).First(&enterprise).Error
@@ -27,5 +27,5 @@ func GetEnterpriseByUID(ctx context.Context, userID int64) (*int64, error) {
 			return nil, err
 		}
 	}
-	return &enterprise.EnterpriseID, nil
+	return &enterprise, nil
 }

+ 3 - 3
db/product.go

@@ -25,7 +25,7 @@ func UpdateProduct(ctx context.Context, product gorm_model.YounggeeProduct) (*in
 	return &product.ProductID, nil
 }
 
-func FindAllProduct(ctx context.Context, enterpriseID int64) ([]gorm_model.YounggeeProduct, error) {
+func GetProductByEnterpriseID(ctx context.Context, enterpriseID int64) ([]gorm_model.YounggeeProduct, error) {
 	db := GetReadDB(ctx)
 	products := []gorm_model.YounggeeProduct{}
 	err := db.Where("enterprise_id = ?", enterpriseID).Find(&products).Error
@@ -35,7 +35,7 @@ func FindAllProduct(ctx context.Context, enterpriseID int64) ([]gorm_model.Young
 	return products, nil
 }
 
-func FindProductByID(ctx context.Context, productID int64) (*gorm_model.YounggeeProduct, error) {
+func GetProductByID(ctx context.Context, productID int64) (*gorm_model.YounggeeProduct, error) {
 	db := GetReadDB(ctx)
 	product := &gorm_model.YounggeeProduct{}
 	err := db.First(&product, productID).Error
@@ -49,7 +49,7 @@ func FindProductByID(ctx context.Context, productID int64) (*gorm_model.Younggee
 	return product, nil
 }
 
-func FindProductByName(ctx context.Context, brandName string, productName string) (*int64, error) {
+func GetProductIDByName(ctx context.Context, brandName string, productName string) (*int64, error) {
 	db := GetReadDB(ctx)
 	product := &gorm_model.YounggeeProduct{}
 	err := db.Where("product_name = ? AND brand_name = ?", productName, brandName).First(&product).Error

+ 2 - 2
db/product_photo.go

@@ -14,7 +14,7 @@ func CreateProductPhoto(ctx context.Context, productPhotos []gorm_model.Younggee
 	return nil
 }
 
-func FindAllProductPhoto(ctx context.Context, productID int64) ([]gorm_model.YounggeeProductPhoto, error) {
+func GetProductPhotoByProductID(ctx context.Context, productID int64) ([]gorm_model.YounggeeProductPhoto, error) {
 	db := GetReadDB(ctx)
 	productPhotos := []gorm_model.YounggeeProductPhoto{}
 	err := db.Where("product_id = ?", productID).Find(&productPhotos).Error
@@ -24,7 +24,7 @@ func FindAllProductPhoto(ctx context.Context, productID int64) ([]gorm_model.You
 	return productPhotos, nil
 }
 
-func DeletePhoto(ctx context.Context, productID int64) error {
+func DeleteProductPhotoByProductID(ctx context.Context, productID int64) error {
 	db := GetReadDB(ctx)
 	err := db.Where("product_id = ?", productID).Delete(&gorm_model.YounggeeProductPhoto{}).Error
 	if err != nil {

+ 2 - 0
db/user.go

@@ -2,6 +2,7 @@ package db
 
 import (
 	"context"
+	"fmt"
 	"youngee_b_api/model/gorm_model"
 
 	"gorm.io/gorm"
@@ -23,6 +24,7 @@ func GetUserByPhone(ctx context.Context, phone string) (*gorm_model.User, error)
 	err := db.Model(user).Where("phone = ?", phone).First(user).Error
 	if err != nil {
 		if err == gorm.ErrRecordNotFound {
+			fmt.Println("record not found")
 			return nil, nil
 		}
 		return nil, err

+ 11 - 7
handler/Register.go

@@ -7,6 +7,7 @@ import (
 	"youngee_b_api/util"
 
 	"github.com/sirupsen/logrus"
+	log "github.com/sirupsen/logrus"
 
 	"github.com/gin-gonic/gin"
 )
@@ -42,23 +43,26 @@ func (h *RegisterHandler) getResponse() interface{} {
 func (h *RegisterHandler) run() {
 	data := http_model.RegisterRequest{}
 	data = *h.req
-	userID, err := service.Register.Register(h.ctx, data.Phone, data.Code)
+	message, err := service.Register.AuthRegister(h.ctx, data.Phone, data.Code)
 	if err != nil {
-		logrus.Errorf("[RegisterHandler] call RegisterUser err:%+v\n", err)
-		util.HandlerPackErrorResp(h.resp, consts.ErrorInternal)
+		logrus.Errorf("[RegisterHandler] call AuthRegister err:%+v\n", err)
+		util.HandlerPackErrorResp(h.resp, consts.ErrorInternal, "")
+		log.Info("Register fail,req:%+v", h.req)
 		return
-	} else if userID != nil {
+	} else if message == "" {
 		// 3. 先后在user表和enterprise表中增加账号信息
 		res, err := service.Enterprise.CreateEnterpriseUser(h.ctx, data)
 		if err != nil {
-			logrus.Errorf("[RegisterHandler] call RegisterUser err:%+v\n", err)
-			util.HandlerPackErrorResp(h.resp, consts.ErrorInternal)
+			logrus.Errorf("[RegisterHandler] call CreateEnterpriseUser err:%+v\n", err)
+			util.HandlerPackErrorResp(h.resp, consts.ErrorInternal, "")
+			log.Info("Register fail,req:%+v", h.req)
 			return
 		}
+		h.resp.Message = "注册成功"
 		// 4. 返回ok
 		h.resp.Data = res
 	} else {
-		h.resp.Message = "验证码错误"
+		util.HandlerPackErrorResp(h.resp, consts.ErrorInternal, message)
 		return
 	}
 }

+ 57 - 0
handler/code_login.go

@@ -0,0 +1,57 @@
+package handler
+
+import (
+	"youngee_b_api/consts"
+	"youngee_b_api/model/http_model"
+	"youngee_b_api/service"
+	"youngee_b_api/util"
+
+	"github.com/gin-gonic/gin"
+	"github.com/sirupsen/logrus"
+	log "github.com/sirupsen/logrus"
+)
+
+func WrapCodeLoginHandler(ctx *gin.Context) {
+	handler := newCodeLoginHandler(ctx)
+	baseRun(handler)
+}
+
+func newCodeLoginHandler(ctx *gin.Context) *CodeLoginHandler {
+	return &CodeLoginHandler{
+		req:  http_model.NewCodeLoginRequest(),
+		resp: http_model.NewCodeLoginResponse(),
+		ctx:  ctx,
+	}
+}
+
+type CodeLoginHandler struct {
+	req  *http_model.CodeLoginRequest
+	resp *http_model.CommonResponse
+	ctx  *gin.Context
+}
+
+func (h *CodeLoginHandler) getRequest() interface{} {
+	return h.req
+}
+func (h *CodeLoginHandler) getContext() *gin.Context {
+	return h.ctx
+}
+func (h *CodeLoginHandler) getResponse() interface{} {
+	return h.resp
+}
+func (h *CodeLoginHandler) run() {
+	token, err := service.LoginAuth.AuthCode(h.ctx, h.req.Phone, h.req.Code)
+	if err != nil {
+		logrus.Errorf("[CodeLoginHandler] call AuthCode err:%+v\n", err)
+		util.HandlerPackErrorResp(h.resp, consts.ErrorInternal, token)
+		log.Info("login fail,req:%+v", h.req)
+		return
+	}
+	data := http_model.CodeLoginData{}
+	data.Token = token
+	h.resp.Message = "登陆成功"
+	h.resp.Data = data
+}
+func (h *CodeLoginHandler) checkParam() error {
+	return nil
+}

+ 0 - 62
handler/password_login.go

@@ -1,62 +0,0 @@
-package handler
-
-import (
-	"youngee_b_api/consts"
-	"youngee_b_api/model/http_model"
-	"youngee_b_api/service"
-	"youngee_b_api/util"
-
-	"github.com/gin-gonic/gin"
-	log "github.com/sirupsen/logrus"
-)
-
-func WrapPasswordLoginHandler(ctx *gin.Context) {
-	handler := newPasswordLoginHandler(ctx)
-	baseRun(handler)
-}
-
-func newPasswordLoginHandler(ctx *gin.Context) *PasswordLoginHandler {
-	return &PasswordLoginHandler{
-		req:  http_model.NewPasswordLoginRequest(),
-		resp: http_model.NewPasswordLoginResponse(),
-		ctx:  ctx,
-	}
-}
-
-type PasswordLoginHandler struct {
-	req  *http_model.PasswordLoginRequest
-	resp *http_model.CommonResponse
-	ctx  *gin.Context
-}
-
-func (h *PasswordLoginHandler) getRequest() interface{} {
-	return h.req
-}
-func (h *PasswordLoginHandler) getContext() *gin.Context {
-	return h.ctx
-}
-func (h *PasswordLoginHandler) getResponse() interface{} {
-	return h.resp
-}
-func (h *PasswordLoginHandler) run() {
-	// 登录接口处理流程
-	// 1. 在redis中查找验证码,判断验证码是否正确,若正确进行下一步,否则返回error
-	// 2. 在user表中查找phone,判断手机号是否存在,若存在进行下一步,否则返回error,message:账号不存在
-	// 3. 更新user表中登陆时间
-	// 4. 生成tocken
-	// 5. 将用户信息和tocken存到redis
-	// 6. 返回tocken
-
-	data := http_model.PasswordLoginData{}
-	token, err := service.LoginAuth.AuthMSG(h.ctx, h.req.UserPhone, h.req.UserPasswd)
-	if err != nil {
-		util.HandlerPackErrorResp(h.resp, consts.ErrorInternal)
-		log.Info("login fail,req:%+v", h.req)
-		return
-	}
-	data.Token = token
-	h.resp.Data = data
-}
-func (h *PasswordLoginHandler) checkParam() error {
-	return nil
-}

+ 11 - 5
handler/product_create.go

@@ -9,6 +9,7 @@ import (
 
 	"github.com/gin-gonic/gin"
 	"github.com/sirupsen/logrus"
+	log "github.com/sirupsen/logrus"
 )
 
 func WrapCreateProductHandler(ctx *gin.Context) {
@@ -47,8 +48,9 @@ func (h *CreateProductHandler) run() {
 	//根据品牌名和商品名查询商品是否存在,若存在则更新,否则新增
 	productID, err := service.Product.FindByName(h.ctx, data.BrandName, data.ProductName)
 	if err != nil {
-		logrus.Errorf("[CreateProductHandler] call Create err:%+v\n", err)
-		util.HandlerPackErrorResp(h.resp, consts.ErrorInternal)
+		logrus.Errorf("[CreateProductHandler] call FindByName err:%+v\n", err)
+		util.HandlerPackErrorResp(h.resp, consts.ErrorInternal, "")
+		log.Info("CreateProduct fail,req:%+v", h.req)
 		return
 	} else {
 		if productID != nil {
@@ -56,19 +58,23 @@ func (h *CreateProductHandler) run() {
 			data.ProductId = *productID
 			res, err := service.Product.Update(h.ctx, data, enterpriseID)
 			if err != nil {
-				logrus.Errorf("[CreateProductHandler] call Create err:%+v\n", err)
-				util.HandlerPackErrorResp(h.resp, consts.ErrorInternal)
+				logrus.Errorf("[CreateProductHandler] call Update err:%+v\n", err)
+				util.HandlerPackErrorResp(h.resp, consts.ErrorInternal, "")
+				log.Info("CreateProduct fail,req:%+v", h.req)
 				return
 			}
+			h.resp.Message = "成功更新商品信息"
 			h.resp.Data = res
 		} else {
 			// 商品不存在,新增
 			res, err := service.Product.Create(h.ctx, data, enterpriseID)
 			if err != nil {
 				logrus.Errorf("[CreateProductHandler] call Create err:%+v\n", err)
-				util.HandlerPackErrorResp(h.resp, consts.ErrorInternal)
+				util.HandlerPackErrorResp(h.resp, consts.ErrorInternal, "")
+				log.Info("CreateProduct fail,req:%+v", h.req)
 				return
 			}
+			h.resp.Message = "成功新增商品信息"
 			h.resp.Data = res
 		}
 	}

+ 4 - 2
handler/product_find.go

@@ -8,6 +8,7 @@ import (
 
 	"github.com/gin-gonic/gin"
 	"github.com/sirupsen/logrus"
+	log "github.com/sirupsen/logrus"
 )
 
 func WrapFindProductHandler(ctx *gin.Context) {
@@ -44,8 +45,9 @@ func (h *FindProductHandler) run() {
 	res, err := service.Product.FindByID(h.ctx, data.ProductID)
 	if err != nil {
 		// 数据库查询失败,返回5001
-		logrus.Errorf("[FindProductHandler] call Find err:%+v\n", err)
-		util.HandlerPackErrorResp(h.resp, consts.ErrorInternal)
+		logrus.Errorf("[FindProductHandler] call FindByID err:%+v\n", err)
+		util.HandlerPackErrorResp(h.resp, consts.ErrorInternal, "")
+		log.Info("FindProduct fail,req:%+v", h.req)
 		return
 	}
 	h.resp.Data = res

+ 3 - 1
handler/product_findAll.go

@@ -9,6 +9,7 @@ import (
 
 	"github.com/gin-gonic/gin"
 	"github.com/sirupsen/logrus"
+	log "github.com/sirupsen/logrus"
 )
 
 func WrapFindAllProductHandler(ctx *gin.Context) {
@@ -46,7 +47,8 @@ func (h *FindAllProductHandler) run() {
 	if err != nil {
 		// 数据库查询失败,返回5001
 		logrus.Errorf("[FindAllProductHandler] call FindAll err:%+v\n", err)
-		util.HandlerPackErrorResp(h.resp, consts.ErrorInternal)
+		util.HandlerPackErrorResp(h.resp, consts.ErrorInternal, "")
+		log.Info("FindAllProduct fail,req:%+v", h.req)
 		return
 	}
 	h.resp.Data = res

+ 7 - 4
handler/project_create.go

@@ -9,6 +9,7 @@ import (
 
 	"github.com/gin-gonic/gin"
 	"github.com/sirupsen/logrus"
+	log "github.com/sirupsen/logrus"
 )
 
 func WrapCreateProjectHandler(ctx *gin.Context) {
@@ -44,12 +45,14 @@ func (h *CreateProjectHandler) run() {
 	data = *h.req
 	auth := middleware.GetSessionAuth(h.ctx)
 	enterpriseID := auth.EnterpriseID
-	res, err := service.Project.CreateProject(h.ctx, data, enterpriseID)
-	if res != nil {
-		logrus.Errorf("[CreateProjectHandler] call CreateProject err:%+v\n", err)
-		util.HandlerPackErrorResp(h.resp, consts.ErrorInternal)
+	res, err := service.Project.Create(h.ctx, data, enterpriseID)
+	if err != nil {
+		logrus.Errorf("[CreateProjectHandler] call Create err:%+v\n", err)
+		util.HandlerPackErrorResp(h.resp, consts.ErrorInternal, "")
+		log.Info("CreateProject fail,req:%+v", h.req)
 		return
 	}
+	h.resp.Message = "成功创建项目"
 	h.resp.Data = res
 }
 func (h *CreateProjectHandler) checkParam() error {

+ 7 - 8
handler/send_code.go

@@ -8,6 +8,8 @@ import (
 	"youngee_b_api/util"
 
 	"github.com/gin-gonic/gin"
+	"github.com/sirupsen/logrus"
+	log "github.com/sirupsen/logrus"
 )
 
 func WrapSendCodeHandler(ctx *gin.Context) {
@@ -39,25 +41,22 @@ func (h *SendCodeHandler) getResponse() interface{} {
 	return h.resp
 }
 func (h *SendCodeHandler) run() {
-
 	data := http_model.SendCodeRequest{}
 	data = *h.req
-	fmt.Println(data.UserPhone)
 	// 1. 生成验证码
 	vcode := service.SendCode.GetCode(h.ctx)
 	// 2. 发送验证码
 	fmt.Println(vcode)
 
 	// 3. {phone:code}存到redis
-	err := service.SendCode.SetSession(h.ctx, data.UserPhone, vcode)
+	err := service.SendCode.SetSession(h.ctx, data.Phone, vcode)
 	if err != nil {
-		util.HandlerPackErrorResp(h.resp, consts.ErrorInternal)
+		logrus.Errorf("[SendeCodeHandler] call SetSession err:%+v\n", err)
+		util.HandlerPackErrorResp(h.resp, consts.ErrorInternal, "")
+		log.Info("SendeCode fail,req:%+v", h.req)
 		return
 	}
-	res := http_model.SendCodeData{
-		UserPhone: data.UserPhone,
-	}
-	h.resp.Data = res
+	h.resp.Message = "验证码发送成功,请注意查收"
 }
 func (h *SendCodeHandler) checkParam() error {
 	return nil

+ 19 - 0
model/http_model/code_login.go

@@ -0,0 +1,19 @@
+package http_model
+
+type CodeLoginRequest struct {
+	Phone string `json:"phone"`
+	Code  string `json:"code"`
+}
+
+type CodeLoginData struct {
+	Token string `json:"token"`
+}
+
+func NewCodeLoginRequest() *CodeLoginRequest {
+	return new(CodeLoginRequest)
+}
+func NewCodeLoginResponse() *CommonResponse {
+	resp := new(CommonResponse)
+	resp.Data = new(CodeLoginData)
+	return resp
+}

+ 1 - 2
model/http_model/send_code.go

@@ -1,11 +1,10 @@
 package http_model
 
 type SendCodeRequest struct {
-	UserPhone string `json:"user_phone"`
+	Phone string `json:"phone"`
 }
 
 type SendCodeData struct {
-	UserPhone string `json:"user_phone"`
 }
 
 func NewSendCodeRequest() *SendCodeRequest {

+ 2 - 2
model/redis_model/auth.go

@@ -3,12 +3,12 @@ package redis_model
 // redis 存放的企业用户信息Session
 type Auth struct {
 	Phone        string `json:"phone"`
-	ID           int64  `json:"id"` // 用户表id
-	EnterpriseID int64  `json:"enterprise_id"`
+	ID           int64  `json:"id"`        // 用户表id
 	User         string `json:"user"`      // 账号
 	Username     string `json:"username"`  // 后台用户名
 	RealName     string `json:"real_name"` // 真实姓名
 	Role         string `json:"role"`      // 角色 1,超级管理员; 2,管理员;3,企业用户
 	Email        string `json:"email"`     // 电子邮件
 	Token        string `json:"token"`
+	EnterpriseID int64  `json:"enterprise_id"`
 }

+ 1 - 1
route/init.go

@@ -12,7 +12,7 @@ func InitRoute(r *gin.Engine) {
 
 	r.POST("/register", handler.WrapRegisterHandler)
 	r.POST("/sendCode", handler.WrapSendCodeHandler)
-	r.POST("/login", handler.WrapPasswordLoginHandler)
+	r.POST("/login", handler.WrapCodeLoginHandler)
 	//r.GET("/test/ping", func(c *gin.Context) {
 	//	resp := http_model.CommonResponse{
 	//		Status:  0,

+ 9 - 8
service/enterprise.go

@@ -2,6 +2,7 @@ package service
 
 import (
 	"context"
+	"time"
 	"youngee_b_api/db"
 	"youngee_b_api/model/gorm_model"
 	"youngee_b_api/model/http_model"
@@ -16,14 +17,14 @@ type enterprise struct {
 
 func (*enterprise) CreateEnterpriseUser(ctx context.Context, newEnterprise http_model.RegisterRequest) (*http_model.RegisterData, error) {
 	user := gorm_model.User{
-		Phone:    newEnterprise.Phone,
-		User:     "1001",
-		Username: newEnterprise.BusinessName,
-		Password: "1001",
-		RealName: newEnterprise.RealName,
-		Role:     "3",
-		Email:    newEnterprise.Email,
-		// LastLoginTime: time.Now().UTC().Local(),
+		Phone:         newEnterprise.Phone,
+		User:          "1001",
+		Username:      newEnterprise.BusinessName,
+		Password:      "1001",
+		RealName:      newEnterprise.RealName,
+		Role:          "3",
+		Email:         newEnterprise.Email,
+		LastLogintime: time.Now().UTC().Local(),
 	}
 	userId, err := db.CreateUser(ctx, user)
 	if err != nil {

+ 19 - 11
service/login_auth.go

@@ -36,7 +36,7 @@ func (l *loginAuth) AuthToken(ctx context.Context, token string) (*redis_model.A
 		logrus.Debug("token格式错误:%+v", token)
 		return nil, err
 	}
-	auth, err := l.getSession(ctx, phone)
+	auth, err := l.getSessionAuth(ctx, phone)
 	if err != nil {
 		logrus.Debug("获取session redis错误: token:%+v,err:%+v", token, err)
 		return nil, err
@@ -48,35 +48,43 @@ func (l *loginAuth) AuthToken(ctx context.Context, token string) (*redis_model.A
 	return auth, nil
 }
 
-func (l *loginAuth) AuthMSG(ctx context.Context, phone string, vcode string) (string, error) {
-	// 验证是否存在
+func (l *loginAuth) AuthCode(ctx context.Context, phone string, code string) (string, error) {
 	user, err := db.GetUserByPhone(ctx, phone)
 	if err != nil {
 		return "", err
+	} else if user == nil {
+		// 账号不存在
+		logrus.Debugf("[AuthCode] auth fail,phone:%+v", phone)
+		return "账号不存在", errors.New("auth fail")
+	} else if string(user.Role) != consts.BRole {
+		// 账号权限有误
+		logrus.Debugf("[AuthCode] auth fail,phone:%+v", phone)
+		return "权限错误,请登录企业账号", errors.New("auth fail")
 	}
-	code, err := l.getSessionCode(ctx, phone)
+	vcode, err := l.getSessionCode(ctx, phone)
 	if err != nil {
 		return "", err
 	}
-	if user == nil || string(user.Role) != consts.BRole || *code != vcode { // 登录失败
-		logrus.Debugf("[AuthPassword] auth fail,phone:%+v", phone)
-		return "", errors.New("auth fail")
+	if *vcode != code {
+		// 验证码错误
+		logrus.Debugf("[AuthCode] auth fail,phone:%+v", phone)
+		return "验证码有误", errors.New("auth fail")
 	}
-	enterpriseID, err := db.GetEnterpriseByUID(ctx, user.ID)
+	token := l.getToken(ctx, phone)
+	enterprise, err := db.GetEnterpriseByUID(ctx, user.ID)
 	if err != nil {
 		return "", err
 	}
-	token := l.getToken(ctx, phone)
 	auth := &redis_model.Auth{
 		Phone:        phone,
 		ID:           user.ID,
-		EnterpriseID: *enterpriseID,
 		User:         user.User,
 		Username:     user.Username,
 		RealName:     user.RealName,
 		Role:         user.Role,
 		Email:        user.Email,
 		Token:        token,
+		EnterpriseID: enterprise.EnterpriseID,
 	}
 	if err := l.setSession(ctx, phone, auth); err != nil {
 		fmt.Printf("setSession error\n")
@@ -135,7 +143,7 @@ func (l *loginAuth) getSessionCode(ctx context.Context, phone string) (*string,
 	return &value, nil
 }
 
-func (l *loginAuth) getSession(ctx context.Context, phone string) (*redis_model.Auth, error) {
+func (l *loginAuth) getSessionAuth(ctx context.Context, phone string) (*redis_model.Auth, error) {
 	value, err := redis.Get(ctx, l.getRedisKey(phone))
 	if err != nil {
 		if err == consts.RedisNil {

+ 5 - 5
service/product.go

@@ -62,7 +62,7 @@ func (*product) Update(ctx context.Context, newProduct http_model.CreateProductR
 		return nil, err
 	}
 	// 删除该商品之前的所有图片
-	err = db.DeletePhoto(ctx, *productID)
+	err = db.DeleteProductPhotoByProductID(ctx, *productID)
 	if err != nil {
 		return nil, err
 	}
@@ -87,7 +87,7 @@ func (*product) Update(ctx context.Context, newProduct http_model.CreateProductR
 }
 
 func (*product) FindAll(ctx context.Context, enterpriseID int64) (*http_model.FindAllProductData, error) {
-	products, err := db.FindAllProduct(ctx, enterpriseID)
+	products, err := db.GetProductByEnterpriseID(ctx, enterpriseID)
 	if err != nil {
 		// 数据库查询error
 		return nil, err
@@ -105,11 +105,11 @@ func (*product) FindAll(ctx context.Context, enterpriseID int64) (*http_model.Fi
 }
 
 func (*product) FindByID(ctx context.Context, productID int64) (*http_model.FindProductData, error) {
-	product, err := db.FindProductByID(ctx, productID)
+	product, err := db.GetProductByID(ctx, productID)
 	if err != nil {
 		return nil, err
 	}
-	productPhotos, err := db.FindAllProductPhoto(ctx, productID)
+	productPhotos, err := db.GetProductPhotoByProductID(ctx, productID)
 	if err != nil {
 		return nil, err
 	}
@@ -134,7 +134,7 @@ func (*product) FindByID(ctx context.Context, productID int64) (*http_model.Find
 }
 
 func (*product) FindByName(ctx context.Context, brandName string, productName string) (*int64, error) {
-	productID, err := db.FindProductByName(ctx, brandName, productName)
+	productID, err := db.GetProductIDByName(ctx, brandName, productName)
 	if err != nil {
 		return nil, err
 	}

+ 1 - 1
service/project.go

@@ -13,7 +13,7 @@ var Project *project
 type project struct {
 }
 
-func (*project) CreateProject(ctx context.Context, newProject http_model.CreateProjectRequest, enterpriseID int64) (*http_model.CreateProjectData, error) {
+func (*project) Create(ctx context.Context, newProject http_model.CreateProjectRequest, enterpriseID int64) (*http_model.CreateProjectData, error) {
 	// build gorm_model.ProjectInfo
 	projectInfo := gorm_model.ProjectInfo{
 		ProjectName:     newProject.ProjectName,

+ 8 - 9
service/register.go

@@ -15,22 +15,21 @@ type register struct {
 	sessionTTL time.Duration
 }
 
-func (r *register) Register(ctx context.Context, phone string, vcode string) (*int64, error) {
+func (r *register) AuthRegister(ctx context.Context, phone string, code string) (string, error) {
 	user, err := db.GetUserByPhone(ctx, phone)
 	if err != nil {
-		return nil, err
+		return "", err
 	} else if user != nil {
-		return &user.ID, nil
+		return "手机号已存在", nil
 	} else {
-		code, err := r.getSession(ctx, phone)
+		vcode, err := r.getSession(ctx, phone)
 		if err != nil {
-			return nil, err
+			return "", err
 		} else {
-			fmt.Printf("%+v", code)
-			if *code != vcode {
-				return &user.ID, nil
+			if *vcode != code {
+				return "验证码有误", nil
 			} else {
-				return nil, nil
+				return "", nil
 			}
 		}
 	}

+ 0 - 1
service/send_code.go

@@ -29,7 +29,6 @@ func (s *sendCode) GetCode(ctx context.Context) string {
 }
 
 func (s *sendCode) SetSession(ctx context.Context, phone string, vcode string) error {
-	fmt.Println(phone)
 	err := redis.Set(ctx, s.getRedisKey(phone), vcode, s.sessionTTL)
 	if err != nil {
 		return err

+ 0 - 1
service/user.go

@@ -1 +0,0 @@
-package service

+ 6 - 2
util/resp.go

@@ -16,7 +16,11 @@ func PackErrorResp(c *gin.Context, status int32) {
 	}
 	c.JSON(http.StatusOK, resp)
 }
-func HandlerPackErrorResp(resp *http_model.CommonResponse, status int32) {
+func HandlerPackErrorResp(resp *http_model.CommonResponse, status int32, message string) {
 	resp.Status = status
-	resp.Message = consts.GetErrorToast(status)
+	if message != "" {
+		resp.Message = message
+	} else {
+		resp.Message = consts.GetErrorToast(status)
+	}
 }