Prechádzať zdrojové kódy

新增/enterprise/create接口

Ohio-HYF 3 rokov pred
rodič
commit
7e57b3f1e1

+ 3 - 0
.gitignore

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

+ 29 - 0
db/enterprise.go

@@ -0,0 +1,29 @@
+package db
+
+import (
+	"context"
+	"time"
+	"youngee_b_api/model/gorm_model"
+	"youngee_b_api/model/http_model"
+)
+
+func CreateEnterprise(ctx context.Context, newEnterprise http_model.CreateEnterpriseRequest) (*http_model.CreateEnterpriseData, error) {
+	db := GetReadDB(ctx)
+	enterprise := &gorm_model.Enterprise{
+		Industry:         newEnterprise.Industry,
+		BusinessName:     newEnterprise.BusinessName,
+		UserId:           newEnterprise.UserId,
+		Balance:          0,
+		FrozenBalance:    0,
+		AvailableBalance: 0,
+		LastLoginTime:    time.Now().UTC().Local(),
+	}
+	err := db.Create(&enterprise).Error
+	if err != nil {
+		return nil, err
+	}
+	data := &http_model.CreateEnterpriseData{
+		EnterpriseId: enterprise.EnterpriseId,
+	}
+	return data, nil
+}

+ 7 - 0
db/product.go

@@ -0,0 +1,7 @@
+package db
+
+import "context"
+
+func CreateProduct(ctx context.Context, newProduct string) {
+
+}

+ 24 - 0
db/user.go

@@ -2,11 +2,35 @@ package db
 
 import (
 	"context"
+	"time"
 	"youngee_b_api/model/gorm_model"
+	"youngee_b_api/model/http_model"
 
 	"gorm.io/gorm"
 )
 
+func CreateEnterpriseUser(ctx context.Context, newUser http_model.CreateEnterpriseRequest) (*http_model.CreateUserData, error) {
+	db := GetReadDB(ctx)
+	user := &gorm_model.User{
+		Phone:         newUser.Phone,
+		User:          "1001",
+		Username:      newUser.BusinessName,
+		Password:      "1001",
+		RealName:      newUser.RealName,
+		Role:          "3",
+		Email:         newUser.Email,
+		LastLoginTime: time.Now().UTC().Local(),
+	}
+	err := db.Create(&user).Error
+	if err != nil {
+		return nil, err
+	}
+	data := &http_model.CreateUserData{
+		UserID: user.ID,
+	}
+	return data, nil
+}
+
 func GetUserByPhone(ctx context.Context, phone string) (*gorm_model.User, error) {
 	db := GetReadDB(ctx)
 	user := &gorm_model.User{}

+ 55 - 0
handler/enterprice_create.go

@@ -0,0 +1,55 @@
+package handler
+
+import (
+	"fmt"
+	"youngee_b_api/model/http_model"
+	"youngee_b_api/service"
+
+	"github.com/gin-gonic/gin"
+)
+
+func WrapCreateEnterpriceHandler(ctx *gin.Context) {
+	handler := newCreateEnterpriseHandler(ctx)
+	baseRun(handler)
+}
+
+func newCreateEnterpriseHandler(ctx *gin.Context) *CreateEnterpriseHandler {
+	return &CreateEnterpriseHandler{
+		req:  http_model.NewCreateEnterpriseRequest(),
+		resp: http_model.NewCreateEnterpriseResponse(),
+		ctx:  ctx,
+	}
+}
+
+type CreateEnterpriseHandler struct {
+	req  *http_model.CreateEnterpriseRequest
+	resp *http_model.CommonResponse
+	ctx  *gin.Context
+}
+
+func (h *CreateEnterpriseHandler) getRequest() interface{} {
+	return h.req
+}
+func (h *CreateEnterpriseHandler) getContext() *gin.Context {
+	return h.ctx
+}
+func (h *CreateEnterpriseHandler) getResponse() interface{} {
+	return h.resp
+}
+func (h *CreateEnterpriseHandler) run() {
+	//判断验证码是否正确
+
+	//若正确,创建企业用户
+	data := http_model.CreateEnterpriseRequest{}
+	data = *h.req
+	res := service.CreateEnterprise.CreateEnterpriseUser(h.ctx, data)
+	if res != nil {
+		fmt.Printf("%+v\n", res)
+	} else {
+		fmt.Printf("error\n")
+	}
+	h.resp.Data = res
+}
+func (h *CreateEnterpriseHandler) checkParam() error {
+	return nil
+}

+ 21 - 3
main_test.go

@@ -6,17 +6,35 @@ import (
 	"testing"
 	"youngee_b_api/config"
 	"youngee_b_api/db"
+	"youngee_b_api/model/http_model"
+	"youngee_b_api/service"
 )
 
 func TestGormUser(t *testing.T) {
 	ctx := context.Background()
 	config.Init()
-	res, err := db.GetUserByPhone(ctx, "123")
+	res, err := db.GetUserByPhone(ctx, "15010101010")
 	if err != nil {
 		panic(err)
 	} else {
-		fmt.Printf("%+v", res)
+		fmt.Printf("%+v\n", 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")
+	}
+}

+ 22 - 0
model/gorm_model/enterprise.go

@@ -0,0 +1,22 @@
+package gorm_model
+
+import (
+	"time"
+)
+
+type Enterprise struct {
+	EnterpriseId     int       `gorm:"column:enterprise_id;type:int(10) unsigned;primary_key" json:"enterprise_id"` // 企业id
+	Industry         int       `gorm:"column:industry;type:tinyint(4)" json:"industry"`                             // 行业,1-14分别代表能源、化工、材料、机械设备/军工、企业服务/造纸印刷、运输设备、旅游酒店、媒体/信息通信服务、批发/零售、消费品、卫生保健/医疗、金融、建材/建筑/房地产、公共事业
+	BusinessName     string    `gorm:"column:business_name;type:varchar(50)" json:"business_name"`                  // 公司或组织名称
+	UserId           int       `gorm:"column:user_id;type:int(11)" json:"user_id"`                                  // 对应用户id
+	Balance          int       `gorm:"column:balance;type:int(11)" json:"balance"`                                  // 账户余额
+	FrozenBalance    int       `gorm:"column:frozen_balance;type:int(11)" json:"frozen_balance"`                    // 冻结余额
+	AvailableBalance int       `gorm:"column:available_balance;type:int(11)" json:"available_balance"`              // 可用余额
+	LastLoginTime    time.Time `gorm:"column:last_login_time;type:datetime" json:"last_login_time"`                 // 最后一次登陆时间
+	CreatedAt        time.Time `gorm:"column:created_at;type:datetime;" json:"created_at"`                          // 创建时间
+	UpdatedAt        time.Time `gorm:"column:updated_at;type:datetime" json:"updated_at"`                           // 更新时间
+}
+
+func (m *Enterprise) TableName() string {
+	return "enterprise"
+}

+ 22 - 0
model/gorm_model/product.go

@@ -0,0 +1,22 @@
+package gorm_model
+
+import (
+	"time"
+)
+
+type YounggeeProduct struct {
+	ProductId    int       `gorm:"column:product_id;type:int(11);primary_key" json:"product_id"` // 商品id
+	ProductName  string    `gorm:"column:product_name;type:varchar(50)" json:"product_name"`     // 商品名称
+	ProductType  int       `gorm:"column:product_type;type:tinyint(4)" json:"product_type"`      // 商品类型
+	ShopAddress  string    `gorm:"column:shop_address;type:varchar(255)" json:"shop_address"`    // 店铺地址,商品类型为线下品牌时需填写
+	ProductPrice int64     `gorm:"column:product_price;type:bigint(20)" json:"product_price"`    // 商品价值
+	ProductUrl   string    `gorm:"column:product_url;type:varchar(1000)" json:"product_url"`     // 商品链接,可为电商网址、公司官网、大众点评的店铺地址等可以说明商品信息或者品牌信息的线上地址;
+	EnterpriseId int       `gorm:"column:enterprise_id;type:int(11)" json:"enterprise_id"`       // 所属企业id
+	CreatedAt    time.Time `gorm:"column:created_at;type:datetime;" json:"created_at"`           // 创建时间
+	UpdatedAt    time.Time `gorm:"column:updated_at;type:datetime" json:"updated_at"`            // 更新时间
+	BrandName    string    `gorm:"column:brand_name;type:varchar(50)" json:"brand_name"`
+}
+
+func (m *YounggeeProduct) TableName() string {
+	return "younggee_product"
+}

+ 17 - 0
model/gorm_model/product_photo.go

@@ -0,0 +1,17 @@
+package gorm_model
+
+import (
+	"time"
+)
+
+type YounggeeProductPhoto struct {
+	ProductPhotoId int       `gorm:"column:product_photo_id;type:int(11);primary_key" json:"product_photo_id"` // 商品图片id
+	PhotoUrl       string    `gorm:"column:photo_url;type:varchar(1000)" json:"photo_url"`                     // 图片或视频url
+	Symbol         int       `gorm:"column:symbol;type:tinyint(4)" json:"symbol"`                              // 图片为主图或详情图标志位,1为主图,2为详情图,3为视频
+	ProductId      int       `gorm:"column:product_id;type:int(11)" json:"product_id"`                         // 所属商品id
+	CreatedAt      time.Time `gorm:"column:created_at;type:datetime" json:"created_at"`                        // 创建时间
+}
+
+func (m *YounggeeProductPhoto) TableName() string {
+	return "younggee_product_photo"
+}

+ 26 - 0
model/gorm_model/project.go

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

+ 16 - 0
model/gorm_model/project_photo.go

@@ -0,0 +1,16 @@
+package gorm_model
+
+import (
+	"time"
+)
+
+type ProjectPhoto struct {
+	ProjectPhotoId int       `gorm:"column:project_photo_id;type:int(11);primary_key" json:"project_photo_id"` // 项目图片id
+	PhotoUrl       string    `gorm:"column:photo_url;type:varchar(1000)" json:"photo_url"`                     // 图片url
+	ProjectId      int       `gorm:"column:project_id;type:int(11)" json:"project_id"`                         // 所属项目id
+	CreatedAt      time.Time `gorm:"column:created_at;type:datetime" json:"created_at"`                        // 创建时间
+}
+
+func (m *ProjectPhoto) TableName() string {
+	return "project_photo"
+}

+ 16 - 0
model/gorm_model/recruit_strategy.go

@@ -0,0 +1,16 @@
+package gorm_model
+
+type RecruitStrategy struct {
+	RecruitStrategyId int `gorm:"column:recruit_strategy_id;type:int(11);primary_key" json:"recruit_strategy_id"` // 招募策略id
+	FeeForm           int `gorm:"column:fee_form;type:tinyint(4)" json:"fee_form"`                                // 稿费形式,1-3分别代表产品置换、固定稿费、自报价
+	StrategyId        int `gorm:"column:strategy_id;type:int(11)" json:"strategy_id"`                             // 策略id
+	FollowersLow      int `gorm:"column:followers_low;type:int(11)" json:"followers_low"`                         // 达人粉丝数下限
+	FollowersUp       int `gorm:"column:followers_up;type:int(11)" json:"followers_up"`                           // 达人粉丝数上限
+	RecruitNumber     int `gorm:"column:recruit_number;type:int(11)" json:"recruit_number"`                       // 招募数量
+	Offer             int `gorm:"column:offer;type:int(11)" json:"offer"`                                         // 报价
+	ProjectId         int `gorm:"column:project_id;type:int(11)" json:"project_id"`                               // 所属项目id
+}
+
+func (m *RecruitStrategy) TableName() string {
+	return "recruit_strategy"
+}

+ 28 - 0
model/http_model/enterprise_create.go

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

+ 19 - 1
route/init.go

@@ -3,14 +3,32 @@ package route
 import (
 	"youngee_b_api/handler"
 	"youngee_b_api/middleware"
+	"youngee_b_api/model/http_model"
 
 	"github.com/gin-gonic/gin"
 )
 
 func InitRoute(r *gin.Engine) {
 
+	r.POST("/enterprise/create", handler.WrapCreateEnterpriceHandler)
 	r.POST("/login", handler.WrapPasswordLoginHandler)
-
+	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)

+ 30 - 0
service/enterprise_create.go

@@ -0,0 +1,30 @@
+package service
+
+import (
+	"context"
+	"youngee_b_api/db"
+	"youngee_b_api/model/http_model"
+
+	log "github.com/sirupsen/logrus"
+)
+
+var CreateEnterprise *createEnterprise
+
+type createEnterprise struct {
+}
+
+func (*createEnterprise) CreateEnterpriseUser(ctx context.Context, newEnterprise http_model.CreateEnterpriseRequest) *http_model.CreateEnterpriseData {
+	userId, err := db.CreateEnterpriseUser(ctx, newEnterprise)
+	if err != nil {
+		log.Infof("[CreateEnterpriseUser] fail,err:%+v", err)
+		return nil
+	} else {
+		newEnterprise.UserId = int(userId.UserID)
+		res, err := db.CreateEnterprise(ctx, newEnterprise)
+		if err != nil {
+			log.Infof("[CreateEnterpriseUser] fail,err:%+v", err)
+			return nil
+		}
+		return res
+	}
+}