浏览代码

Merge branch 'develop' of HolaBIP/youngee_b_api into master

houyunfeng 3 年之前
父节点
当前提交
51a4e6e4dd
共有 47 个文件被更改,包括 1648 次插入107 次删除
  1. 3 0
      .gitignore
  2. 1 0
      config/init.go
  3. 2 0
      consts/session.go
  4. 31 0
      db/enterprise.go
  5. 64 0
      db/product.go
  6. 34 0
      db/product_photo.go
  7. 15 0
      db/project.go
  8. 15 0
      db/project_photo.go
  9. 15 0
      db/recruit_strategy.go
  10. 12 0
      db/user.go
  11. 7 19
      go.mod
  12. 74 1
      go.sum
  13. 72 0
      handler/Register.go
  14. 57 0
      handler/code_login.go
  15. 0 54
      handler/password_login.go
  16. 84 0
      handler/product_create.go
  17. 57 0
      handler/product_find.go
  18. 59 0
      handler/product_findAll.go
  19. 60 0
      handler/project_create.go
  20. 63 0
      handler/send_code.go
  21. 18 13
      main_test.go
  22. 2 0
      middleware/login_auth.go
  23. 23 0
      model/gorm_model/enterprise.go
  24. 25 0
      model/gorm_model/product.go
  25. 20 0
      model/gorm_model/product_photo.go
  26. 28 0
      model/gorm_model/project.go
  27. 19 0
      model/gorm_model/project_photo.go
  28. 19 0
      model/gorm_model/recruit_strategy.go
  29. 2 2
      model/gorm_model/user.go
  30. 19 0
      model/http_model/code_login.go
  31. 0 1
      model/http_model/password_login.go
  32. 32 0
      model/http_model/product_create.go
  33. 33 0
      model/http_model/product_find.go
  34. 23 0
      model/http_model/product_findall.go
  35. 45 0
      model/http_model/project_create.go
  36. 26 0
      model/http_model/register.go
  37. 17 0
      model/http_model/send_code.go
  38. 9 1
      model/redis_model/auth.go
  39. 27 2
      route/init.go
  40. 53 0
      service/enterprise.go
  41. 136 12
      service/login_auth.go
  42. 151 0
      service/product.go
  43. 82 0
      service/project.go
  44. 51 0
      service/register.go
  45. 41 0
      service/send_code.go
  46. 16 0
      util/encoding.go
  47. 6 2
      util/resp.go

+ 3 - 0
.gitignore

@@ -0,0 +1,3 @@
+.idea/
+.vscode/
+output/

+ 1 - 0
config/init.go

@@ -34,6 +34,7 @@ func loadExternelConfig(config *system_model.Config) {
 	db.Init(config.Mysql)
 	redis.Init(config.Redis)
 	service.LoginAuthInit(config.Server.Session)
+	service.SendCodeInit(config.Server.Session)
 }
 
 func getEnv() string {

+ 2 - 0
consts/session.go

@@ -2,3 +2,5 @@ package consts
 
 const SessionAuthSchema = "session_auth"
 const SessionRedisPrefix = "b_user:"
+const AuthSalt = "fa2tg4y"
+const BRole = "3"

+ 31 - 0
db/enterprise.go

@@ -0,0 +1,31 @@
+package db
+
+import (
+	"context"
+	"youngee_b_api/model/gorm_model"
+
+	"gorm.io/gorm"
+)
+
+func CreateEnterprise(ctx context.Context, newEnterprise gorm_model.Enterprise) (*int64, error) {
+	db := GetReadDB(ctx)
+	err := db.Create(&newEnterprise).Error
+	if err != nil {
+		return nil, err
+	}
+	return &newEnterprise.EnterpriseID, nil
+}
+
+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
+	if err != nil {
+		if err == gorm.ErrRecordNotFound {
+			return nil, nil
+		} else {
+			return nil, err
+		}
+	}
+	return &enterprise, nil
+}

+ 64 - 0
db/product.go

@@ -0,0 +1,64 @@
+package db
+
+import (
+	"context"
+	"youngee_b_api/model/gorm_model"
+
+	"gorm.io/gorm"
+)
+
+func CreateProduct(ctx context.Context, product gorm_model.YounggeeProduct) (*int64, error) {
+	db := GetReadDB(ctx)
+	err := db.Create(&product).Error
+	if err != nil {
+		return nil, err
+	}
+	return &product.ProductID, nil
+}
+
+func UpdateProduct(ctx context.Context, product gorm_model.YounggeeProduct) (*int64, error) {
+	db := GetReadDB(ctx)
+	err := db.Model(&product).Updates(product).Error
+	if err != nil {
+		return nil, err
+	}
+	return &product.ProductID, nil
+}
+
+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
+	if err != nil {
+		return nil, err
+	}
+	return products, nil
+}
+
+func GetProductByID(ctx context.Context, productID int64) (*gorm_model.YounggeeProduct, error) {
+	db := GetReadDB(ctx)
+	product := &gorm_model.YounggeeProduct{}
+	err := db.First(&product, productID).Error
+	if err != nil {
+		if err == gorm.ErrRecordNotFound {
+			return nil, nil
+		} else {
+			return nil, err
+		}
+	}
+	return product, nil
+}
+
+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
+	if err != nil {
+		if err == gorm.ErrRecordNotFound {
+			return nil, nil
+		} else {
+			return nil, err
+		}
+	}
+	return &product.ProductID, nil
+}

+ 34 - 0
db/product_photo.go

@@ -0,0 +1,34 @@
+package db
+
+import (
+	"context"
+	"youngee_b_api/model/gorm_model"
+)
+
+func CreateProductPhoto(ctx context.Context, productPhotos []gorm_model.YounggeeProductPhoto) error {
+	db := GetReadDB(ctx)
+	err := db.Create(&productPhotos).Error
+	if err != nil {
+		return err
+	}
+	return nil
+}
+
+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
+	if err != nil {
+		return nil, err
+	}
+	return productPhotos, nil
+}
+
+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 {
+		return err
+	}
+	return nil
+}

+ 15 - 0
db/project.go

@@ -0,0 +1,15 @@
+package db
+
+import (
+	"context"
+	"youngee_b_api/model/gorm_model"
+)
+
+func CreateProject(ctx context.Context, projectInfo gorm_model.ProjectInfo) (*int64, error) {
+	db := GetReadDB(ctx)
+	err := db.Create(&projectInfo).Error
+	if err != nil {
+		return nil, err
+	}
+	return &projectInfo.ProjectID, nil
+}

+ 15 - 0
db/project_photo.go

@@ -0,0 +1,15 @@
+package db
+
+import (
+	"context"
+	"youngee_b_api/model/gorm_model"
+)
+
+func CreateProjectPhoto(ctx context.Context, projectPhotos []gorm_model.ProjectPhoto) error {
+	db := GetReadDB(ctx)
+	err := db.Create(&projectPhotos).Error
+	if err != nil {
+		return err
+	}
+	return nil
+}

+ 15 - 0
db/recruit_strategy.go

@@ -0,0 +1,15 @@
+package db
+
+import (
+	"context"
+	"youngee_b_api/model/gorm_model"
+)
+
+func CreateRecruitStrategy(ctx context.Context, recruitStrategys []gorm_model.RecruitStrategy) error {
+	db := GetReadDB(ctx)
+	err := db.Create(&recruitStrategys).Error
+	if err != nil {
+		return err
+	}
+	return nil
+}

+ 12 - 0
db/user.go

@@ -2,17 +2,29 @@ package db
 
 import (
 	"context"
+	"fmt"
 	"youngee_b_api/model/gorm_model"
 
 	"gorm.io/gorm"
 )
 
+func CreateUser(ctx context.Context, user gorm_model.User) (*int64, error) {
+	db := GetReadDB(ctx)
+	err := db.Create(&user).Error
+	if err != nil {
+		return nil, err
+	}
+	return &user.ID, nil
+}
+
+//GetUserByPhone 查不到返回空
 func GetUserByPhone(ctx context.Context, phone string) (*gorm_model.User, error) {
 	db := GetReadDB(ctx)
 	user := &gorm_model.User{}
 	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

+ 7 - 19
go.mod

@@ -1,6 +1,6 @@
 module youngee_b_api
 
-go 1.17
+go 1.16
 
 require (
 	github.com/GUAIK-ORG/go-snowflake v0.0.0-20200116064823-220c4260e85f
@@ -9,30 +9,18 @@ require (
 )
 
 require (
-	github.com/cespare/xxhash/v2 v2.1.2 // indirect
-	github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
-	github.com/gin-contrib/sse v0.1.0 // indirect
-	github.com/go-playground/locales v0.14.0 // indirect
-	github.com/go-playground/universal-translator v0.18.0 // indirect
 	github.com/go-playground/validator/v10 v10.10.1 // indirect
-	github.com/go-redis/redis/v8 v8.11.5 // indirect
-	github.com/go-sql-driver/mysql v1.6.0 // indirect
-	github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b // indirect
-	github.com/golang/protobuf v1.5.2 // indirect
-	github.com/jinzhu/inflection v1.0.0 // indirect
+	github.com/go-redis/redis/v8 v8.11.5
 	github.com/jinzhu/now v1.1.5 // indirect
 	github.com/json-iterator/go v1.1.12 // indirect
-	github.com/leodido/go-urn v1.2.1 // indirect
 	github.com/mattn/go-isatty v0.0.14 // indirect
 	github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
-	github.com/modern-go/reflect2 v1.0.2 // indirect
-	github.com/sirupsen/logrus v1.8.1 // indirect
-	github.com/ugorji/go/codec v1.2.7 // indirect
+	github.com/sirupsen/logrus v1.8.1
+	github.com/ugorji/go v1.2.7 // indirect
 	golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd // indirect
 	golang.org/x/sys v0.0.0-20220318055525-2edf467146b5 // indirect
-	golang.org/x/text v0.3.7 // indirect
 	google.golang.org/protobuf v1.27.1 // indirect
-	gopkg.in/yaml.v2 v2.4.0 // indirect
-	gorm.io/driver/mysql v1.3.2 // indirect
-	gorm.io/gorm v1.23.3 // indirect
+	gopkg.in/yaml.v2 v2.4.0
+	gorm.io/driver/mysql v1.3.2
+	gorm.io/gorm v1.23.3
 )

+ 74 - 1
go.sum

@@ -2,12 +2,18 @@ github.com/GUAIK-ORG/go-snowflake v0.0.0-20200116064823-220c4260e85f h1:RDkg3pyE
 github.com/GUAIK-ORG/go-snowflake v0.0.0-20200116064823-220c4260e85f/go.mod h1:zA7AF9RTfpluCfz0omI4t5KCMaWHUMicsZoMccnaT44=
 github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE=
 github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
+github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
+github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
+github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
 github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
 github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
 github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
+github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
+github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
+github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
 github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
 github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
 github.com/gin-gonic/gin v1.7.7 h1:3DoBmSbJbZAWqXJC3SLjAPfutPJJRN1U5pALB7EeTTs=
@@ -27,17 +33,31 @@ github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC
 github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo=
 github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
 github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
+github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
 github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58=
 github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
+github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
 github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
+github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
+github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
+github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
+github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
+github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
+github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
 github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
 github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
 github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
+github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
+github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
+github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
 github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
 github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
 github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
+github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
 github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
 github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
+github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
+github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
 github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
 github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
 github.com/jinzhu/now v1.1.4/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
@@ -66,6 +86,20 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJ
 github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
 github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
 github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
+github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
+github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
+github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
+github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
+github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
+github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0=
+github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
+github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
+github.com/onsi/ginkgo/v2 v2.0.0/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c=
+github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
+github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
+github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=
+github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
+github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs=
 github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
@@ -78,6 +112,7 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
 github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
 github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
 github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
+github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
 github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
 github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
 github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
@@ -87,33 +122,66 @@ github.com/ugorji/go v1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6
 github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
 github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0=
 github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY=
+github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
 golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
+golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
 golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
 golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
 golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd h1:XcWmESyNjXJMLahc3mqVQJcgSTDxFxhETVlfk9uGc38=
 golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
+golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
+golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
 golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
+golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
+golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
+golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
+golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk=
+golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 h1:CIJ76btIcR3eFI5EgSo6k1qKw9KJexJuRLI9G7Hp5wE=
 golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
+golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
 golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
 golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.0.0-20220318055525-2edf467146b5 h1:saXMvIOKvRFwbOMicHXr0B1uwoxq9dGmLe5ExMES6c4=
 golang.org/x/sys v0.0.0-20220318055525-2edf467146b5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
 golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
 golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
+golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
 golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
 golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
 golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
 golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
-golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
+golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
+golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
+golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
+golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
+google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
+google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
+google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
+google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
+google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
 google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
 google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
 google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ=
@@ -123,8 +191,13 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8
 gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
 gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
 gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
+gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
+gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
+gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
 gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
+gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
 gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
+gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
 gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
 gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
 gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

+ 72 - 0
handler/Register.go

@@ -0,0 +1,72 @@
+package handler
+
+import (
+	"youngee_b_api/consts"
+	"youngee_b_api/model/http_model"
+	"youngee_b_api/service"
+	"youngee_b_api/util"
+
+	"github.com/sirupsen/logrus"
+	log "github.com/sirupsen/logrus"
+
+	"github.com/gin-gonic/gin"
+)
+
+func WrapRegisterHandler(ctx *gin.Context) {
+	handler := newRegisterHandler(ctx)
+	baseRun(handler)
+}
+
+func newRegisterHandler(ctx *gin.Context) *RegisterHandler {
+	return &RegisterHandler{
+		req:  http_model.NewRegisterRequest(),
+		resp: http_model.NewRegisterResponse(),
+		ctx:  ctx,
+	}
+}
+
+type RegisterHandler struct {
+	req  *http_model.RegisterRequest
+	resp *http_model.CommonResponse
+	ctx  *gin.Context
+}
+
+func (h *RegisterHandler) getRequest() interface{} {
+	return h.req
+}
+func (h *RegisterHandler) getContext() *gin.Context {
+	return h.ctx
+}
+func (h *RegisterHandler) getResponse() interface{} {
+	return h.resp
+}
+func (h *RegisterHandler) run() {
+	data := http_model.RegisterRequest{}
+	data = *h.req
+	message, err := service.Register.AuthRegister(h.ctx, data.Phone, data.Code)
+	if err != nil {
+		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 message == "" {
+		// 3. 先后在user表和enterprise表中增加账号信息
+		res, err := service.Enterprise.CreateEnterpriseUser(h.ctx, data)
+		if err != nil {
+			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 {
+		util.HandlerPackErrorResp(h.resp, consts.ErrorInternal, message)
+		return
+	}
+}
+
+func (h *RegisterHandler) checkParam() error {
+	return nil
+}

+ 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 - 54
handler/password_login.go

@@ -1,54 +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() {
-	data := http_model.PasswordLoginData{}
-	data.Token = h.req.UserPhone
-	auth := service.LoginAuth.AuthPassword(h.ctx, h.req.UserPhone, h.req.UserPasswd)
-	if auth == nil {
-		util.HandlerPackErrorResp(h.resp, consts.ErrorInternal)
-		log.Info("login fail,req:%+v", h.req)
-		return
-	}
-	h.resp.Data = data
-}
-func (h *PasswordLoginHandler) checkParam() error {
-	return nil
-}

+ 84 - 0
handler/product_create.go

@@ -0,0 +1,84 @@
+package handler
+
+import (
+	"youngee_b_api/consts"
+	"youngee_b_api/middleware"
+	"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 WrapCreateProductHandler(ctx *gin.Context) {
+	handler := newCreateProductHandler(ctx)
+	baseRun(handler)
+}
+
+func newCreateProductHandler(ctx *gin.Context) *CreateProductHandler {
+	return &CreateProductHandler{
+		req:  http_model.NewCreateProductRequest(),
+		resp: http_model.NewCreateProductResponse(),
+		ctx:  ctx,
+	}
+}
+
+type CreateProductHandler struct {
+	req  *http_model.CreateProductRequest
+	resp *http_model.CommonResponse
+	ctx  *gin.Context
+}
+
+func (h *CreateProductHandler) getRequest() interface{} {
+	return h.req
+}
+func (h *CreateProductHandler) getContext() *gin.Context {
+	return h.ctx
+}
+func (h *CreateProductHandler) getResponse() interface{} {
+	return h.resp
+}
+func (h *CreateProductHandler) run() {
+	data := http_model.CreateProductRequest{}
+	data = *h.req
+	auth := middleware.GetSessionAuth(h.ctx)
+	enterpriseID := auth.EnterpriseID
+	//根据品牌名和商品名查询商品是否存在,若存在则更新,否则新增
+	productID, err := service.Product.FindByName(h.ctx, data.BrandName, data.ProductName)
+	if err != nil {
+		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 {
+			// 该商品存在,更新
+			data.ProductId = *productID
+			res, err := service.Product.Update(h.ctx, data, enterpriseID)
+			if err != nil {
+				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, "")
+				log.Info("CreateProduct fail,req:%+v", h.req)
+				return
+			}
+			h.resp.Message = "成功新增商品信息"
+			h.resp.Data = res
+		}
+	}
+}
+func (h *CreateProductHandler) checkParam() error {
+	return nil
+}

+ 57 - 0
handler/product_find.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 WrapFindProductHandler(ctx *gin.Context) {
+	handler := newFindProductHandler(ctx)
+	baseRun(handler)
+}
+
+func newFindProductHandler(ctx *gin.Context) *FindProductHandler {
+	return &FindProductHandler{
+		req:  http_model.NewFindProductRequest(),
+		resp: http_model.NewFindProductResponse(),
+		ctx:  ctx,
+	}
+}
+
+type FindProductHandler struct {
+	req  *http_model.FindProductRequest
+	resp *http_model.CommonResponse
+	ctx  *gin.Context
+}
+
+func (h *FindProductHandler) getRequest() interface{} {
+	return h.req
+}
+func (h *FindProductHandler) getContext() *gin.Context {
+	return h.ctx
+}
+func (h *FindProductHandler) getResponse() interface{} {
+	return h.resp
+}
+func (h *FindProductHandler) run() {
+	data := *&http_model.FindProductRequest{}
+	data = *h.req
+	res, err := service.Product.FindByID(h.ctx, data.ProductID)
+	if err != nil {
+		// 数据库查询失败,返回5001
+		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
+}
+func (h *FindProductHandler) checkParam() error {
+	return nil
+}

+ 59 - 0
handler/product_findAll.go

@@ -0,0 +1,59 @@
+package handler
+
+import (
+	"youngee_b_api/consts"
+	"youngee_b_api/middleware"
+	"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 WrapFindAllProductHandler(ctx *gin.Context) {
+	handler := newFindAllProductHandler(ctx)
+	baseRun(handler)
+}
+
+func newFindAllProductHandler(ctx *gin.Context) *FindAllProductHandler {
+	return &FindAllProductHandler{
+		req:  http_model.NewFindAllProductRequest(),
+		resp: http_model.NewFindAllProductResponse(),
+		ctx:  ctx,
+	}
+}
+
+type FindAllProductHandler struct {
+	req  *http_model.FindAllProductRequest
+	resp *http_model.CommonResponse
+	ctx  *gin.Context
+}
+
+func (h *FindAllProductHandler) getRequest() interface{} {
+	return h.req
+}
+func (h *FindAllProductHandler) getContext() *gin.Context {
+	return h.ctx
+}
+func (h *FindAllProductHandler) getResponse() interface{} {
+	return h.resp
+}
+func (h *FindAllProductHandler) run() {
+	auth := middleware.GetSessionAuth(h.ctx)
+	enterpriseID := auth.EnterpriseID
+	res, err := service.Product.FindAll(h.ctx, enterpriseID)
+	if err != nil {
+		// 数据库查询失败,返回5001
+		logrus.Errorf("[FindAllProductHandler] call FindAll err:%+v\n", err)
+		util.HandlerPackErrorResp(h.resp, consts.ErrorInternal, "")
+		log.Info("FindAllProduct fail,req:%+v", h.req)
+		return
+	}
+	// h.resp.Message = "查询成功"
+	h.resp.Data = res
+}
+func (h *FindAllProductHandler) checkParam() error {
+	return nil
+}

+ 60 - 0
handler/project_create.go

@@ -0,0 +1,60 @@
+package handler
+
+import (
+	"youngee_b_api/consts"
+	"youngee_b_api/middleware"
+	"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 WrapCreateProjectHandler(ctx *gin.Context) {
+	handler := newCreateProjectHandler(ctx)
+	baseRun(handler)
+}
+
+func newCreateProjectHandler(ctx *gin.Context) *CreateProjectHandler {
+	return &CreateProjectHandler{
+		req:  http_model.NewCreateProjectRequest(),
+		resp: http_model.NewCreateProjectResponse(),
+		ctx:  ctx,
+	}
+}
+
+type CreateProjectHandler struct {
+	req  *http_model.CreateProjectRequest
+	resp *http_model.CommonResponse
+	ctx  *gin.Context
+}
+
+func (h *CreateProjectHandler) getRequest() interface{} {
+	return h.req
+}
+func (h *CreateProjectHandler) getContext() *gin.Context {
+	return h.ctx
+}
+func (h *CreateProjectHandler) getResponse() interface{} {
+	return h.resp
+}
+func (h *CreateProjectHandler) run() {
+	data := http_model.CreateProjectRequest{}
+	data = *h.req
+	auth := middleware.GetSessionAuth(h.ctx)
+	enterpriseID := auth.EnterpriseID
+	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 {
+	return nil
+}

+ 63 - 0
handler/send_code.go

@@ -0,0 +1,63 @@
+package handler
+
+import (
+	"fmt"
+	"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 WrapSendCodeHandler(ctx *gin.Context) {
+	handler := newSendCodeHandler(ctx)
+	baseRun(handler)
+}
+
+func newSendCodeHandler(ctx *gin.Context) *SendCodeHandler {
+	return &SendCodeHandler{
+		req:  http_model.NewSendCodeRequest(),
+		resp: http_model.NewSendCodeResponse(),
+		ctx:  ctx,
+	}
+}
+
+type SendCodeHandler struct {
+	req  *http_model.SendCodeRequest
+	resp *http_model.CommonResponse
+	ctx  *gin.Context
+}
+
+func (h *SendCodeHandler) getRequest() interface{} {
+	return h.req
+}
+func (h *SendCodeHandler) getContext() *gin.Context {
+	return h.ctx
+}
+func (h *SendCodeHandler) getResponse() interface{} {
+	return h.resp
+}
+func (h *SendCodeHandler) run() {
+	data := http_model.SendCodeRequest{}
+	data = *h.req
+	// 1. 生成验证码
+	vcode := service.SendCode.GetCode(h.ctx)
+	// 2. 发送验证码
+	fmt.Println(vcode)
+
+	// 3. {phone:code}存到redis
+	err := service.SendCode.SetSession(h.ctx, data.Phone, vcode)
+	if err != nil {
+		logrus.Errorf("[SendeCodeHandler] call SetSession err:%+v\n", err)
+		util.HandlerPackErrorResp(h.resp, consts.ErrorInternal, "")
+		log.Info("SendeCode fail,req:%+v", h.req)
+		return
+	}
+	h.resp.Message = "验证码发送成功,请注意查收"
+}
+func (h *SendCodeHandler) checkParam() error {
+	return nil
+}

+ 18 - 13
main_test.go

@@ -1,22 +1,27 @@
 package main
 
 import (
-	"context"
-	"fmt"
 	"testing"
-	"youngee_b_api/config"
-	"youngee_b_api/db"
 )
 
 func TestGormUser(t *testing.T) {
-	ctx := context.Background()
-	config.Init()
-	res, err := db.GetUserByPhone(ctx, "123")
-	if err != nil {
-		panic(err)
-	} else {
-		fmt.Printf("%+v", res)
-	}
+
 }
 
-//
+// func TestDbCreateEnterprise(t *testing.T) {
+// 	ctx := context.Background()
+// 	config.Init()
+// 	newEnterprise := http_model.CreateEnterpriseRequest{
+// 		Industry:     2,
+// 		BusinessName: "Test公司",
+// 		RealName:     "测试员",
+// 		Phone:        "13010101010",
+// 		Email:        "test@younggee.com",
+// 	}
+// 	res := service.CreateEnterprise.CreateEnterpriseUser(ctx, newEnterprise)
+// 	if res != nil {
+// 		fmt.Printf("%+v\n", res)
+// 	} else {
+// 		fmt.Printf("error\n")
+// 	}
+// }

+ 2 - 0
middleware/login_auth.go

@@ -1,6 +1,7 @@
 package middleware
 
 import (
+	"fmt"
 	"youngee_b_api/consts"
 	"youngee_b_api/model/redis_model"
 	"youngee_b_api/service"
@@ -14,6 +15,7 @@ import (
 func LoginAuthMiddleware(c *gin.Context) {
 	token := c.Request.Header.Get("Authorization")
 	if token != "" {
+		fmt.Println(token)
 		if auth, err := service.LoginAuth.AuthToken(c, token); err == nil {
 			c.Set(consts.SessionAuthSchema, auth)
 			c.Next()

+ 23 - 0
model/gorm_model/enterprise.go

@@ -0,0 +1,23 @@
+// Code generated by sql2gorm. DO NOT EDIT.
+package gorm_model
+
+import (
+	"time"
+)
+
+type Enterprise struct {
+	EnterpriseID     int64       `gorm:"column:enterprise_id"` // 企业id
+	Industry         int64       `gorm:"column:industry"`                                 // 行业,1-14分别代表能源、化工、材料、机械设备/军工、企业服务/造纸印刷、运输设备、旅游酒店、媒体/信息通信服务、批发/零售、消费品、卫生保健/医疗、金融、建材/建筑/房地产、公共事业
+	BusinessName     string    `gorm:"column:business_name"`                            // 公司或组织名称
+	UserID           int64       `gorm:"column:user_id"`                                  // 对应用户id
+	Balance          int64       `gorm:"column:balance"`                                  // 账户余额
+	FrozenBalance    int64       `gorm:"column:frozen_balance"`                           // 冻结余额
+	AvailableBalance int64       `gorm:"column:available_balance"`                        // 可用余额
+	CreatedAt        time.Time `gorm:"column:created_at"`                               // 创建时间
+	UpdatedAt        time.Time `gorm:"column:updated_at"`                               // 更新时间
+}
+
+func (m *Enterprise) TableName() string {
+	return "enterprise"
+}
+

+ 25 - 0
model/gorm_model/product.go

@@ -0,0 +1,25 @@
+// Code generated by sql2gorm. DO NOT EDIT.
+package gorm_model
+
+import (
+	"time"
+)
+
+type YounggeeProduct struct {
+	ProductID     int64       `gorm:"column:product_id;primary_key;AUTO_INCREMENT"` // 商品id
+	ProductName   string    `gorm:"column:product_name"`                          // 商品名称
+	ProductType   int64       `gorm:"column:product_type"`                          // 商品类型
+	ShopAddress   string    `gorm:"column:shop_address"`                          // 店铺地址,商品类型为线下品牌时需填写
+	ProductPrice  int64     `gorm:"column:product_price"`                         // 商品价值
+	ProductDetail string    `gorm:"column:product_detail"`
+	ProductUrl    string    `gorm:"column:product_url"`   // 商品链接,可为电商网址、公司官网、大众点评的店铺地址等可以说明商品信息或者品牌信息的线上地址;
+	EnterpriseID  int64       `gorm:"column:enterprise_id"` // 所属企业id
+	CreatedAt     time.Time `gorm:"column:created_at"`    // 创建时间
+	UpdatedAt     time.Time `gorm:"column:updated_at"`    // 更新时间
+	BrandName     string    `gorm:"column:brand_name"`
+}
+
+func (m *YounggeeProduct) TableName() string {
+	return "younggee_product"
+}
+

+ 20 - 0
model/gorm_model/product_photo.go

@@ -0,0 +1,20 @@
+// Code generated by sql2gorm. DO NOT EDIT.
+package gorm_model
+
+import (
+	"time"
+)
+
+type YounggeeProductPhoto struct {
+	ProductPhotoID int64       `gorm:"column:product_photo_id;primary_key;AUTO_INCREMENT"` // 商品图片id
+	PhotoUrl       string    `gorm:"column:photo_url"`                                   // 图片或视频url
+	PhotoUid       string    `gorm:"column:photo_uid"`
+	Symbol         int64       `gorm:"column:symbol"`     // 图片为主图或详情图标志位,1为主图,2为详情图,3为视频
+	ProductID      int64       `gorm:"column:product_id"` // 所属商品id
+	CreatedAt      time.Time `gorm:"column:created_at"` // 创建时间
+}
+
+func (m *YounggeeProductPhoto) TableName() string {
+	return "younggee_product_photo"
+}
+

+ 28 - 0
model/gorm_model/project.go

@@ -0,0 +1,28 @@
+// Code generated by sql2gorm. DO NOT EDIT.
+package gorm_model
+
+import (
+	"time"
+)
+
+type ProjectInfo struct {
+	ProjectID       int64       `gorm:"column:project_id;primary_key;AUTO_INCREMENT"` // 项目id
+	ProjectName     string    `gorm:"column:project_name"`           // 项目名称
+	ProjectStatus   int64       `gorm:"column:project_status"`         // 项目状态,1-7分别代表创建中、待审核、招募中、待支付、失效、执行中、已结案
+	ProjectType     int64       `gorm:"column:project_type"`           // 项目类型,1代表全流程项目,2代表专项项目
+	ProjectPlatform int64       `gorm:"column:project_platform"`       // 项目平台,1-7分别代表小红书、抖音、微博、快手、b站、大众点评、知乎
+	ProjectForm     int64       `gorm:"column:project_form"`           // 项目形式,1-4分别代表实体商品寄拍、虚拟产品测评、线下探店打卡、素材微原创
+	TalentType      string       `gorm:"column:talent_type"`            // 达人类型
+	RecruitDdl      time.Time `gorm:"column:recruit_ddl"`            // 招募截止时间
+	ContentType     int64       `gorm:"column:content_type"`           // 内容形式,1代表图文,2代表视频
+	ProjectDetail   string    `gorm:"column:project_detail"`         // 项目详情
+	EnterpriseID    int64       `gorm:"column:enterprise_id"`          // 所属企业id
+	ProductID       int64       `gorm:"column:product_id"`             // 关联商品id
+	CreatedAt       time.Time `gorm:"column:created_at"`             // 创建时间
+	UpdatedAt       time.Time `gorm:"column:updated_at"`             // 修改时间
+}
+
+func (m *ProjectInfo) TableName() string {
+	return "project_info"
+}
+

+ 19 - 0
model/gorm_model/project_photo.go

@@ -0,0 +1,19 @@
+// Code generated by sql2gorm. DO NOT EDIT.
+package gorm_model
+
+import (
+	"time"
+)
+
+type ProjectPhoto struct {
+	ProjectPhotoID int64       `gorm:"column:project_photo_id;primary_key;AUTO_INCREMENT"` // 项目图片id
+	PhotoUrl       string    `gorm:"column:photo_url"`                                   // 图片url
+	PhotoUid       string    `gorm:"column:photo_uid"`
+	ProjectID      int64       `gorm:"column:project_id"` // 所属项目id
+	CreatedAt      time.Time `gorm:"column:created_at"` // 创建时间
+}
+
+func (m *ProjectPhoto) TableName() string {
+	return "project_photo"
+}
+

+ 19 - 0
model/gorm_model/recruit_strategy.go

@@ -0,0 +1,19 @@
+// Code generated by sql2gorm. DO NOT EDIT.
+package gorm_model
+
+
+type RecruitStrategy struct {
+	RecruitStrategyID int64 `gorm:"column:recruit_strategy_id;primary_key"` // 招募策略id
+	FeeForm           int64 `gorm:"column:fee_form"`                        // 稿费形式,1-3分别代表产品置换、固定稿费、自报价
+	StrategyID        int64 `gorm:"column:strategy_id"`                     // 策略id
+	FollowersLow      int64 `gorm:"column:followers_low"`                   // 达人粉丝数下限
+	FollowersUp       int64 `gorm:"column:followers_up"`                    // 达人粉丝数上限
+	RecruitNumber     int64 `gorm:"column:recruit_number"`                  // 招募数量
+	Offer             int64 `gorm:"column:offer"`                           // 报价
+	ProjectID         int64 `gorm:"column:project_id"`                      // 所属项目id
+}
+
+func (m *RecruitStrategy) TableName() string {
+	return "recruit_strategy"
+}
+

+ 2 - 2
model/gorm_model/user.go

@@ -6,7 +6,7 @@ import (
 )
 
 type User struct {
-	ID            int       `gorm:"column:id;primary_key;AUTO_INCREMENT"` // 用户表id
+	ID            int64       `gorm:"column:id;primary_key;AUTO_INCREMENT"` // 用户表id
 	User          string    `gorm:"column:user"`                          // 账号
 	Username      string    `gorm:"column:username"`                      // 后台用户名
 	Password      string    `gorm:"column:password"`                      // 用户密码
@@ -14,7 +14,7 @@ type User struct {
 	Role          string    `gorm:"column:role"`                          // 角色 1,超级管理员; 2,管理员;3,企业用户
 	Phone         string    `gorm:"column:phone"`                         // 绑定手机
 	Email         string    `gorm:"column:email"`                         // 电子邮件
-	LastLoginTime time.Time `gorm:"column:last_login_time"`               // 最后一次登录时间
+	LastLogintime time.Time `gorm:"column:last_login_time"`               // 最后一次登录时间
 	UserState     string    `gorm:"column:user_state"`                    // 0,禁用,1,正常
 	CreatedAt     time.Time `gorm:"column:created_at"`                    // 创建时间
 	UpdatedAt     time.Time `gorm:"column:updated_at"`                    // 更新时间

+ 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
+}

+ 0 - 1
model/http_model/password_login.go

@@ -5,7 +5,6 @@ type PasswordLoginRequest struct {
 	UserPasswd string `json:"user_password"`
 }
 
-//
 type PasswordLoginData struct {
 	Token string `json:"token"`
 }

+ 32 - 0
model/http_model/product_create.go

@@ -0,0 +1,32 @@
+package http_model
+
+type CreateProductPhoto struct {
+	PhotoUrl string `json:"photo_url"` // 图片或视频url
+	PhotoUid string `json:"photo_uid"`
+	Symbol   int64  `json:"symbol"` // 图片为主图或详情图标志位,1为主图,2为详情图,3为视频
+}
+
+type CreateProductRequest struct {
+	ProductId     int64                `json:"product_id"`
+	ProductName   string               `json:"product_name"` // 商品名称
+	ProductType   int64                `json:"product_type"` // 商品类型
+	ShopAddress   string               `json:"shop_address"` // 店铺地址,商品类型为线下品牌时需填写
+	ProductDetail string               `json:"product_detail"`
+	ProductPrice  int64                `json:"product_price"`  // 商品价值
+	ProductPhotos []CreateProductPhoto `json:"product_photos"` // 商品图片列表
+	ProductUrl    string               `json:"product_url"`    // 商品链接,可为电商网址、公司官网、大众点评的店铺地址等可以说明商品信息或者品牌信息的线上地址;
+	BrandName     string               `json:"brand_name"`
+}
+
+type CreateProductData struct {
+	ProductID int64 `json:"product_id"` // 商品id
+}
+
+func NewCreateProductRequest() *CreateProductRequest {
+	return new(CreateProductRequest)
+}
+func NewCreateProductResponse() *CommonResponse {
+	resp := new(CommonResponse)
+	resp.Data = new(CreateProductData)
+	return resp
+}

+ 33 - 0
model/http_model/product_find.go

@@ -0,0 +1,33 @@
+package http_model
+
+type FindProductRequest struct {
+	ProductID int64 `json:"product_id"`
+}
+
+type ProductPhoto struct {
+	PhotoUrl string `json:"photo_url"` // 图片或视频url
+	PhotoUid string `json:"photo_uid"`
+	Symbol   int64  `json:"symbol"` // 图片为主图或详情图标志位,1为主图,2为详情图,3为视频
+}
+
+type FindProductData struct {
+	ProductID     int64          `json:"product_id"`
+	ProductName   string         `json:"product_name"`  // 商品名称
+	ProductType   int64          `json:"product_type"`  // 商品类型
+	ShopAddress   string         `json:"shop_address"`  // 店铺地址,商品类型为线下品牌时需填写
+	ProductPrice  int64          `json:"product_price"` // 商品价值
+	ProductDetail string         `json:"product_detail"`
+	ProductPhotos []ProductPhoto `json:"product_photos"` // 商品图片列表
+	ProductUrl    string         `json:"product_url"`    // 商品链接,可为电商网址、公司官网、大众点评的店铺地址等可以说明商品信息或者品牌信息的线上地址;
+	EnterpriseID  int64          `json:"enterprise_id"`  // 所属企业id
+	BrandName     string         `json:"brand_name"`     // 品牌名称
+}
+
+func NewFindProductRequest() *FindProductRequest {
+	return new(FindProductRequest)
+}
+func NewFindProductResponse() *CommonResponse {
+	resp := new(CommonResponse)
+	resp.Data = new(FindProductData)
+	return resp
+}

+ 23 - 0
model/http_model/product_findall.go

@@ -0,0 +1,23 @@
+package http_model
+
+type FindAllProductRequest struct {
+}
+
+type ProductInfo struct {
+	ProductID   int64  `json:"product_id"`
+	BrandName   string `json:"brand_name"`
+	ProductName string `json:"product_name"`
+}
+
+type FindAllProductData struct {
+	ProductInfos []ProductInfo `json:"product_infos"`
+}
+
+func NewFindAllProductRequest() *FindAllProductRequest {
+	return new(FindAllProductRequest)
+}
+func NewFindAllProductResponse() *CommonResponse {
+	resp := new(CommonResponse)
+	resp.Data = new(FindAllProductData)
+	return resp
+}

+ 45 - 0
model/http_model/project_create.go

@@ -0,0 +1,45 @@
+package http_model
+
+import "time"
+
+type CreateProjectPhoto struct {
+	PhotoUrl string `json:"photo_url"` // 图片url
+	PhotoUid string `json:"photo_uid"`
+}
+
+type CreateRecruitStrategy struct {
+	FeeForm       int64 `json:"fee_form"`       // 稿费形式,1-3分别代表自报价、固定稿费、产品置换
+	StrategyID    int64 `json:"strategy_id"`    // 策略id
+	FollowersLow  int64 `json:"followers_low"`  // 达人粉丝数下限
+	FollowersUp   int64 `json:"followers_up"`   // 达人粉丝数上限
+	RecruitNumber int64 `json:"recruit_number"` // 招募数量
+	Offer         int64 `json:"offer"`          // 报价
+}
+
+type CreateProjectRequest struct {
+	ProjectName      string                  `json:"project_name"`      // 项目名称
+	ProjectStatus    int64                   `json:"project_status"`    // 项目状态,1-7分别代表创建中、待审核、招募中、待支付、失效、执行中、已结案
+	ProjectType      int64                   `json:"project_type"`      // 项目类型,1代表全流程项目,2代表专项项目
+	ProjectPlatform  int64                   `json:"project_platform"`  // 项目平台,1-7分别代表小红书、抖音、微博、快手、b站、大众点评、知乎
+	ProjectForm      int64                   `json:"project_form"`      // 项目形式,1-4分别代表实体商品寄拍、虚拟产品测评、线下探店打卡、素材微原创
+	TalentType       string                  `json:"talent_type"`       // 达人类型
+	RecruitDdl       time.Time               `json:"recruit_ddl"`       // 招募截止时间
+	ContentType      int64                   `json:"content_type"`      // 内容形式,1代表图文,2代表视频
+	ProjectDetail    string                  `json:"project_detail"`    // 项目详情
+	RecruitStrategys []CreateRecruitStrategy `json:"recruit_strategys"` // 定价策略
+	ProjectPhotos    []CreateProjectPhoto    `json:"project_photos"`    // 项目图片
+	ProductID        int64                   `json:"product_id"`        // 关联商品id
+}
+
+type CreateProjectData struct {
+	ProjectID int64 `json:"Project_id"` // 项目id
+}
+
+func NewCreateProjectRequest() *CreateProjectRequest {
+	return new(CreateProjectRequest)
+}
+func NewCreateProjectResponse() *CommonResponse {
+	resp := new(CommonResponse)
+	resp.Data = new(CreateProjectData)
+	return resp
+}

+ 26 - 0
model/http_model/register.go

@@ -0,0 +1,26 @@
+package http_model
+
+type RegisterRequest struct {
+	EnterpriseId int64  `json:"enterprise_id"` // 企业id
+	UserId       int64  `json:"user_id"`       // 对应用户id
+	RealName     string `json:"real_name"`     // 真实姓名
+	Phone        string `json:"phone"`         //手机号
+	Industry     int64  `json:"industry"`      // 行业,1-14分别代表能源、化工、材料、机械设备/军工、企业服务/造纸印刷、运输设备、旅游酒店、媒体/信息通信服务、批发/零售、消费品、卫生保健/医疗、金融、建材/建筑/房地产、公共事业
+	BusinessName string `json:"business_name"` // 公司或组织名称
+	Email        string `json:"email"`         // 电子邮件
+	Code         string `json:"code"`          //验证码
+}
+
+type RegisterData struct {
+	UserID       int64 `json:"user_id"`       // 用户id
+	EnterpriseId int64 `json:"enterprise_id"` // 企业id
+}
+
+func NewRegisterRequest() *RegisterRequest {
+	return new(RegisterRequest)
+}
+func NewRegisterResponse() *CommonResponse {
+	resp := new(CommonResponse)
+	resp.Data = new(RegisterData)
+	return resp
+}

+ 17 - 0
model/http_model/send_code.go

@@ -0,0 +1,17 @@
+package http_model
+
+type SendCodeRequest struct {
+	Phone string `json:"phone"`
+}
+
+type SendCodeData struct {
+}
+
+func NewSendCodeRequest() *SendCodeRequest {
+	return new(SendCodeRequest)
+}
+func NewSendCodeResponse() *CommonResponse {
+	resp := new(CommonResponse)
+	resp.Data = new(SendCodeData)
+	return resp
+}

+ 9 - 1
model/redis_model/auth.go

@@ -2,5 +2,13 @@ package redis_model
 
 // redis 存放的企业用户信息Session
 type Auth struct {
-	Phone string `json:"phone"`
+	Phone        string `json:"phone"`
+	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"`
 }

+ 27 - 2
route/init.go

@@ -5,19 +5,44 @@ import (
 	"youngee_b_api/middleware"
 
 	"github.com/gin-gonic/gin"
+	"github.com/sirupsen/logrus"
 )
 
 func InitRoute(r *gin.Engine) {
 
-	r.POST("/login", handler.WrapPasswordLoginHandler)
-
+	r.POST("/register", handler.WrapRegisterHandler)
+	r.POST("/sendCode", handler.WrapSendCodeHandler)
+	r.POST("/login", handler.WrapCodeLoginHandler)
+	//r.GET("/test/ping", func(c *gin.Context) {
+	//	resp := http_model.CommonResponse{
+	//		Status:  0,
+	//		Message: "",
+	//		Data:    "ping",
+	//	}
+	//	c.JSON(200, resp)
+	//})
+	//r.Any("/testDemo", func(c *gin.Context) {
+	//	resp := http_model.CommonResponse{
+	//		Status:  0,
+	//		Message: "",
+	//		Data:    "pong",
+	//	}
+	//	c.JSON(200, resp)
+	//	// 注意这里只是debug用的 接口要写成handler形式
+	//})
 	m := r.Group("/youngee/m")
 	{
 		m.Use(middleware.LoginAuthMiddleware)
 		m.POST("/test", func(c *gin.Context) {
 			c.JSON(200, "ok")
 			// 注意这里只是debug用的 接口要写成handler形式
+			auth := middleware.GetSessionAuth(c)
+			logrus.Infof("auth:%+v", auth)
 		})
+		m.POST("/product/findall", handler.WrapFindAllProductHandler)
+		m.POST("/product/find", handler.WrapFindProductHandler)
+		m.POST("/project/create", handler.WrapCreateProjectHandler)
+		m.POST("/product/create", handler.WrapCreateProductHandler)
 	}
 
 }

+ 53 - 0
service/enterprise.go

@@ -0,0 +1,53 @@
+package service
+
+import (
+	"context"
+	"time"
+	"youngee_b_api/db"
+	"youngee_b_api/model/gorm_model"
+	"youngee_b_api/model/http_model"
+
+	log "github.com/sirupsen/logrus"
+)
+
+var Enterprise *enterprise
+
+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(),
+	}
+	userId, err := db.CreateUser(ctx, user)
+	if err != nil {
+		log.Infof("[CreateEnterpriseUser] fail,err:%+v", err)
+		return nil, err
+	} else {
+		enterprise := &gorm_model.Enterprise{
+			Industry:         newEnterprise.Industry,
+			BusinessName:     newEnterprise.BusinessName,
+			UserID:           *userId,
+			Balance:          0,
+			FrozenBalance:    0,
+			AvailableBalance: 0,
+		}
+		enterpriseId, err := db.CreateEnterprise(ctx, *enterprise)
+		if err != nil {
+			log.Infof("[CreateEnterpriseUser] fail,err:%+v", err)
+			return nil, err
+		}
+		res := &http_model.RegisterData{
+			EnterpriseId: *enterpriseId,
+			UserID:       *userId,
+		}
+		return res, nil
+	}
+}

+ 136 - 12
service/login_auth.go

@@ -3,12 +3,19 @@ package service
 import (
 	"context"
 	"encoding/json"
+	"errors"
 	"fmt"
+	"strconv"
+	"strings"
 	"time"
 	"youngee_b_api/consts"
+	"youngee_b_api/db"
 	"youngee_b_api/model/redis_model"
 	"youngee_b_api/model/system_model"
 	"youngee_b_api/redis"
+	"youngee_b_api/util"
+
+	"github.com/sirupsen/logrus"
 )
 
 var LoginAuth *loginAuth
@@ -24,34 +31,151 @@ type loginAuth struct {
 }
 
 func (l *loginAuth) AuthToken(ctx context.Context, token string) (*redis_model.Auth, error) {
-	value, err := redis.Get(ctx, l.getRedisKey(token))
+	phone, err := l.parseToken(ctx, token)
 	if err != nil {
-		if err == consts.RedisNil {
-			return nil, fmt.Errorf("not found in redis,token:%+v", token)
-		}
+		logrus.Debug("token格式错误:%+v", token)
 		return nil, err
 	}
-	auth := new(redis_model.Auth)
-	if err = json.Unmarshal([]byte(value), auth); err != nil {
+	auth, err := l.getSessionAuth(ctx, phone)
+	if err != nil {
+		logrus.Debug("获取session redis错误: token:%+v,err:%+v", token, err)
 		return nil, err
 	}
+	if auth.Token != token {
+		logrus.Debug("获取session time过期错误: token:%+v", token)
+		return nil, errors.New("auth failed")
+	}
 	return auth, nil
-
 }
-func (l *loginAuth) AuthPassword(ctx context.Context, phone, password string) *redis_model.Auth {
-	// 需要添加mysql库认证逻辑
-	// todo
+
+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")
+	}
+	vcode, err := l.getSessionCode(ctx, phone)
+	if err != nil {
+		return "", err
+	}
+	if *vcode != code {
+		// 验证码错误
+		logrus.Debugf("[AuthCode] auth fail,phone:%+v", phone)
+		return "验证码有误", errors.New("auth fail")
+	}
+	token := l.getToken(ctx, phone)
+	enterprise, err := db.GetEnterpriseByUID(ctx, user.ID)
+	if err != nil {
+		return "", err
+	}
 	auth := &redis_model.Auth{
-		Phone: phone,
+		Phone:        phone,
+		ID:           user.ID,
+		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")
+		return "", err
 	}
+	return token, nil
+}
+
+// func (l *loginAuth) AuthPassword(ctx context.Context, phone string, password string) (string, error) {
+// 	// 验证是否存在
+// 	user, err := db.GetUserByPhone(ctx, phone)
+// 	if err != nil {
+// 		return "", err
+// 	}
+// 	// 验证正确性
+// 	if user == nil || user.Role != consts.BRole || user.Password != l.encryptPassword(password) {
+// 		// 登录失败
+// 		logrus.Debugf("[AuthPassword] auth fail,phone:%+v", phone)
+// 		return "", errors.New("auth fail")
+// 	}
+// 	token := l.getToken(ctx, phone)
+// 	auth := &redis_model.Auth{
+// 		Phone:    phone,
+// 		ID:       user.ID,
+// 		User:     user.User,
+// 		Username: user.Username,
+// 		RealName: user.RealName,
+// 		Role:     user.Role,
+// 		Email:    user.Email,
+// 		Token:    token,
+// 	}
+// 	if err := l.setSession(ctx, phone, auth); err != nil {
+// 		return "", err
+// 	}
+// 	return token, nil
+// }
+
+func (l *loginAuth) setSession(ctx context.Context, phone string, auth *redis_model.Auth) error {
 	if authJson, err := json.Marshal(auth); err == nil {
 		err = redis.Set(ctx, l.getRedisKey(phone), string(authJson), l.sessionTTL)
 		if err == nil {
-			return auth
+			return err
 		}
 	}
 	return nil
 }
+
+func (l *loginAuth) getSessionCode(ctx context.Context, phone string) (*string, error) {
+	value, err := redis.Get(ctx, l.getRedisKey(phone))
+	if err != nil {
+		if err == consts.RedisNil {
+			return nil, fmt.Errorf("not found in redis,phone:%+v", phone)
+		}
+		return nil, err
+	}
+	return &value, nil
+}
+
+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 {
+			return nil, fmt.Errorf("not found in redis,phone:%+v", phone)
+		}
+		return nil, err
+	}
+	auth := new(redis_model.Auth)
+	if err = json.Unmarshal([]byte(value), auth); err != nil {
+		return nil, err
+	}
+	return auth, nil
+}
+func (l *loginAuth) getToken(ctx context.Context, phone string) string {
+	timeSeed := strconv.FormatInt(time.Now().Unix(), 10)
+	token := phone + "." + timeSeed + "." + util.MD5(phone, timeSeed, consts.AuthSalt)
+	return token
+}
+func (l *loginAuth) parseToken(ctx context.Context, token string) (string, error) {
+	parts := strings.Split(token, ".")
+	if len(parts) == 3 {
+		phone := parts[0]
+		timeSeed := parts[1]
+		if parts[2] == util.MD5(phone, timeSeed, consts.AuthSalt) {
+			return phone, nil
+		}
+	}
+	return "", errors.New("token invalid")
+}
+func (l *loginAuth) encryptPassword(password string) string {
+	return util.MD5(password)
+}
 func (l *loginAuth) getRedisKey(key string) string {
 	return fmt.Sprintf("%s%s", consts.SessionRedisPrefix, key)
 }

+ 151 - 0
service/product.go

@@ -0,0 +1,151 @@
+package service
+
+import (
+	"context"
+	"youngee_b_api/db"
+	"youngee_b_api/model/gorm_model"
+	"youngee_b_api/model/http_model"
+)
+
+var Product *product
+
+type product struct {
+}
+
+func (*product) Create(ctx context.Context, newProduct http_model.CreateProductRequest, enterpriseID int64) (*http_model.CreateProductData, error) {
+	product := gorm_model.YounggeeProduct{
+		ProductName:   newProduct.ProductName,
+		ProductType:   newProduct.ProductType,
+		ShopAddress:   newProduct.ShopAddress,
+		ProductPrice:  newProduct.ProductPrice,
+		ProductDetail: newProduct.ProductDetail,
+		ProductUrl:    newProduct.ProductUrl,
+		EnterpriseID:  enterpriseID,
+		BrandName:     newProduct.BrandName,
+	}
+	productID, err := db.CreateProduct(ctx, product)
+	if err != nil {
+		return nil, err
+	}
+	if newProduct.ProductPhotos != nil {
+		productPhotos := []gorm_model.YounggeeProductPhoto{}
+		for _, photo := range newProduct.ProductPhotos {
+			productPhoto := gorm_model.YounggeeProductPhoto{
+				PhotoUrl:  photo.PhotoUrl,
+				PhotoUid:  photo.PhotoUid,
+				Symbol:    photo.Symbol,
+				ProductID: *productID,
+			}
+			productPhotos = append(productPhotos, productPhoto)
+		}
+		err = db.CreateProductPhoto(ctx, productPhotos)
+		if err != nil {
+			return nil, err
+		}
+	}
+	res := &http_model.CreateProductData{
+		ProductID: *productID,
+	}
+	return res, nil
+}
+
+func (*product) Update(ctx context.Context, newProduct http_model.CreateProductRequest, enterpriseID int64) (*http_model.CreateProductData, error) {
+	product := gorm_model.YounggeeProduct{
+		ProductID:     newProduct.ProductId,
+		ProductName:   newProduct.ProductName,
+		ProductType:   newProduct.ProductType,
+		ShopAddress:   newProduct.ShopAddress,
+		ProductPrice:  newProduct.ProductPrice,
+		ProductDetail: newProduct.ProductDetail,
+		ProductUrl:    newProduct.ProductUrl,
+		EnterpriseID:  enterpriseID,
+		BrandName:     newProduct.BrandName,
+	}
+	productID, err := db.UpdateProduct(ctx, product)
+	if err != nil {
+		return nil, err
+	}
+	// 删除该商品之前的所有图片
+	err = db.DeleteProductPhotoByProductID(ctx, *productID)
+	if err != nil {
+		return nil, err
+	}
+	if newProduct.ProductPhotos != nil {
+		// 新增图片
+		productPhotos := []gorm_model.YounggeeProductPhoto{}
+		for _, photo := range newProduct.ProductPhotos {
+			productPhoto := gorm_model.YounggeeProductPhoto{
+				PhotoUrl:  photo.PhotoUrl,
+				PhotoUid:  photo.PhotoUid,
+				Symbol:    photo.Symbol,
+				ProductID: *productID,
+			}
+			productPhotos = append(productPhotos, productPhoto)
+		}
+		err = db.CreateProductPhoto(ctx, productPhotos)
+		if err != nil {
+			return nil, err
+		}
+	}
+	res := &http_model.CreateProductData{
+		ProductID: *productID,
+	}
+	return res, nil
+}
+
+func (*product) FindAll(ctx context.Context, enterpriseID int64) (*http_model.FindAllProductData, error) {
+	products, err := db.GetProductByEnterpriseID(ctx, enterpriseID)
+	if err != nil {
+		// 数据库查询error
+		return nil, err
+	}
+	findAllProductData := http_model.FindAllProductData{}
+	for _, product := range products {
+		productData := http_model.ProductInfo{
+			ProductID:   product.ProductID,
+			BrandName:   product.BrandName,
+			ProductName: product.ProductName,
+		}
+		findAllProductData.ProductInfos = append(findAllProductData.ProductInfos, productData)
+	}
+	return &findAllProductData, nil
+}
+
+func (*product) FindByID(ctx context.Context, productID int64) (*http_model.FindProductData, error) {
+	product, err := db.GetProductByID(ctx, productID)
+	if err != nil {
+		return nil, err
+	}
+	productPhotos, err := db.GetProductPhotoByProductID(ctx, productID)
+	if err != nil {
+		return nil, err
+	}
+	findProductData := http_model.FindProductData{
+		ProductID:     product.ProductID,
+		ProductName:   product.ProductName,
+		ProductType:   product.ProductType,
+		ShopAddress:   product.ShopAddress,
+		ProductPrice:  product.ProductPrice,
+		ProductDetail: product.ProductDetail,
+		ProductUrl:    product.ProductUrl,
+		EnterpriseID:  product.EnterpriseID,
+		BrandName:     product.BrandName,
+	}
+	for _, photo := range productPhotos {
+		productPhoto := http_model.ProductPhoto{
+			PhotoUrl: photo.PhotoUrl,
+			PhotoUid: photo.PhotoUid,
+			Symbol:   photo.Symbol,
+		}
+		findProductData.ProductPhotos = append(findProductData.ProductPhotos, productPhoto)
+	}
+	return &findProductData, nil
+}
+
+func (*product) FindByName(ctx context.Context, brandName string, productName string) (*int64, error) {
+	productID, err := db.GetProductIDByName(ctx, brandName, productName)
+	if err != nil {
+		return nil, err
+	}
+	return productID, nil
+}

+ 82 - 0
service/project.go

@@ -0,0 +1,82 @@
+package service
+
+import (
+	"context"
+	"time"
+	"youngee_b_api/db"
+	"youngee_b_api/model/gorm_model"
+	"youngee_b_api/model/http_model"
+)
+
+var Project *project
+
+type project struct {
+}
+
+func (*project) Create(ctx context.Context, newProject http_model.CreateProjectRequest, enterpriseID int64) (*http_model.CreateProjectData, error) {
+	// build gorm_model.ProjectInfo
+	// 查询关联商品信息
+	product, err := db.GetProductByID(ctx, newProject.ProductID)
+	if err != nil {
+		return nil, err
+	}
+	// 按照品牌名-商品名对项目进行命名
+	projectName := product.BrandName + "-" + product.ProductName
+	projectInfo := gorm_model.ProjectInfo{
+		ProjectName:     projectName,
+		ProjectStatus:   1,
+		ProjectType:     newProject.ProjectType,
+		TalentType:      newProject.TalentType,
+		ProjectPlatform: newProject.ProjectPlatform,
+		ProjectForm:     newProject.ProjectForm,
+		RecruitDdl:      time.Now().UTC().Local(),
+		ProjectDetail:   newProject.ProjectDetail,
+		ContentType:     newProject.ContentType,
+		EnterpriseID:    enterpriseID,
+		ProductID:       newProject.ProductID,
+	}
+	// db create ProjectInfo
+	projectID, err := db.CreateProject(ctx, projectInfo)
+	if err != nil {
+		return nil, err
+	}
+	if newProject.ProjectPhotos != nil {
+		// build []gorm_model.ProjectPhoto
+		projectPhotos := []gorm_model.ProjectPhoto{}
+		for _, photo := range newProject.ProjectPhotos {
+			projectPhoto := gorm_model.ProjectPhoto{
+				PhotoUrl:  photo.PhotoUrl,
+				PhotoUid:  photo.PhotoUid,
+				ProjectID: *projectID,
+			}
+			projectPhotos = append(projectPhotos, projectPhoto)
+		}
+		// db create ProjectPhoto
+		err = db.CreateProjectPhoto(ctx, projectPhotos)
+		if err != nil {
+			return nil, err
+		}
+	}
+	// build
+	recruitStrategys := []gorm_model.RecruitStrategy{}
+	for _, strategy := range newProject.RecruitStrategys {
+		recruitStrategy := gorm_model.RecruitStrategy{
+			FeeForm:       strategy.FeeForm,
+			StrategyID:    strategy.StrategyID,
+			FollowersLow:  strategy.FollowersLow,
+			FollowersUp:   strategy.FollowersUp,
+			RecruitNumber: strategy.RecruitNumber,
+			Offer:         strategy.Offer,
+			ProjectID:     *projectID,
+		}
+		recruitStrategys = append(recruitStrategys, recruitStrategy)
+	}
+	err = db.CreateRecruitStrategy(ctx, recruitStrategys)
+	if err != nil {
+		return nil, err
+	}
+	res := &http_model.CreateProjectData{
+		ProjectID: *projectID,
+	}
+	return res, nil
+}

+ 51 - 0
service/register.go

@@ -0,0 +1,51 @@
+package service
+
+import (
+	"context"
+	"fmt"
+	"time"
+	"youngee_b_api/consts"
+	"youngee_b_api/db"
+	"youngee_b_api/redis"
+)
+
+var Register *register
+
+type register struct {
+	sessionTTL time.Duration
+}
+
+func (r *register) AuthRegister(ctx context.Context, phone string, code string) (string, error) {
+	user, err := db.GetUserByPhone(ctx, phone)
+	if err != nil {
+		return "", err
+	} else if user != nil {
+		return "手机号已存在", nil
+	} else {
+		vcode, err := r.getSession(ctx, phone)
+		if err != nil {
+			return "", err
+		} else {
+			if *vcode != code {
+				return "验证码有误", nil
+			} else {
+				return "", nil
+			}
+		}
+	}
+}
+
+func (r *register) getSession(ctx context.Context, phone string) (*string, error) {
+	value, err := redis.Get(ctx, r.getRedisKey(phone))
+	if err != nil {
+		if err == consts.RedisNil {
+			return nil, fmt.Errorf("not found in redis,phone:%+v", phone)
+		}
+		return nil, err
+	}
+	return &value, nil
+}
+
+func (r *register) getRedisKey(key string) string {
+	return fmt.Sprintf("%s%s", consts.SessionRedisPrefix, key)
+}

+ 41 - 0
service/send_code.go

@@ -0,0 +1,41 @@
+package service
+
+import (
+	"context"
+	"fmt"
+	"math/rand"
+	"time"
+	"youngee_b_api/consts"
+	"youngee_b_api/model/system_model"
+	"youngee_b_api/redis"
+)
+
+var SendCode *sendCode
+
+func SendCodeInit(config *system_model.Session) {
+	sendCode := new(sendCode)
+	sendCode.sessionTTL = time.Duration(config.TTL) * time.Minute
+	SendCode = sendCode
+}
+
+type sendCode struct {
+	sessionTTL time.Duration
+}
+
+func (s *sendCode) GetCode(ctx context.Context) string {
+	rnd := rand.New(rand.NewSource(time.Now().UnixNano()))
+	vcode := fmt.Sprintf("%06v", rnd.Int31n(1000000))
+	return vcode
+}
+
+func (s *sendCode) SetSession(ctx context.Context, phone string, vcode string) error {
+	err := redis.Set(ctx, s.getRedisKey(phone), vcode, s.sessionTTL)
+	if err != nil {
+		return err
+	}
+	return nil
+}
+
+func (s *sendCode) getRedisKey(key string) string {
+	return fmt.Sprintf("%s%s", consts.SessionRedisPrefix, key)
+}

+ 16 - 0
util/encoding.go

@@ -0,0 +1,16 @@
+package util
+
+import (
+	"crypto/md5"
+	"encoding/hex"
+)
+
+func MD5(keys ...string) string {
+	finalKey := ""
+	for _, key := range keys {
+		finalKey += key
+	}
+	s := md5.New()
+	s.Write([]byte(finalKey))
+	return hex.EncodeToString(s.Sum(nil))
+}

+ 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)
+	}
 }