浏览代码

Merge branch 'develop' of 139.9.53.143:HolaBIP/youngee_b_api into develop

shenzekai 1 年之前
父节点
当前提交
92d4b82344

+ 77 - 0
db/product.go

@@ -3,7 +3,9 @@ package db
 import (
 	"context"
 	"github.com/sirupsen/logrus"
+	"youngee_b_api/consts"
 	"youngee_b_api/model/gorm_model"
+	"youngee_b_api/model/http_model"
 
 	"gorm.io/gorm"
 )
@@ -97,3 +99,78 @@ func GetProductPhotoInfoBySelectionId(ctx context.Context, selectionId string) (
 	}
 	return productPhotoInfo, nil
 }
+
+func GetAllProduct(ctx context.Context, req *http_model.GetAllProductRequest, enterpriseID string) ([]*http_model.ProjectBriefInfo, int64, error) {
+	var ProjectBriefInfos []*http_model.ProjectBriefInfo
+	db := GetReadDB(ctx)
+	var projectInfos []*gorm_model.ProjectInfo
+	db = db.Debug().Model(gorm_model.ProjectInfo{}).Where("enterprise_id = ?", enterpriseID)
+	if req.Platform != 0 {
+		db = db.Model(gorm_model.ProjectInfo{}).Where("project_platform = ?", req.Platform)
+	}
+	if req.FeeForm != 0 {
+		db = db.Model(gorm_model.ProjectInfo{}).Where("fee_form = ?", req.FeeForm)
+	}
+	if req.ProjectForm != 0 {
+		db = db.Model(gorm_model.ProjectInfo{}).Where("project_form = ?", req.ProjectForm)
+	}
+	// 查询总数
+	var total int64
+	if err := db.Count(&total).Error; err != nil {
+		logrus.WithContext(ctx).Errorf("[GetAllProduct] error query mysql total, err:%+v", err)
+		return nil, 0, err
+	}
+	// 查询该页数据
+	limit := req.PageSize
+	offset := req.PageSize * req.PageNum // assert pageNum start with 0
+	err := db.Order("submit_at desc").Limit(int(limit)).Offset(int(offset)).Find(&projectInfos).Error
+	if err != nil {
+		logrus.WithContext(ctx).Errorf("[GetSelectionList] error query mysql total, err:%+v", err)
+		return nil, 0, err
+	}
+	projectIdToRecruitStrategy := make(map[string][]*gorm_model.RecruitStrategy)
+	platformToPlatformIcon := make(map[int64]string)
+	projectIdToSignNum := make(map[string]int64)
+	for _, projectInfo := range projectInfos {
+		var RecruitStrategys []*gorm_model.RecruitStrategy
+		db1 := GetReadDB(ctx)
+		err := db1.Debug().Model(gorm_model.RecruitStrategy{}).Where("project_id = ?", projectInfo.ProjectID).Find(&RecruitStrategys).Error
+		if err != nil {
+			logrus.WithContext(ctx).Errorf("[GetAllProduct] error query RecruitStrategys, err:%+v", err)
+			return nil, 0, err
+		}
+		projectIdToRecruitStrategy[projectInfo.ProjectID] = RecruitStrategys
+	}
+	for _, projectInfo := range projectInfos {
+		PlatformIcon := ""
+		db1 := GetReadDB(ctx)
+		err := db1.Debug().Model(gorm_model.InfoThirdPlatform{}).Select("platform_icon").Where("platform_id = ?", projectInfo.ProjectPlatform).Find(&PlatformIcon).Error
+		if err != nil {
+			logrus.WithContext(ctx).Errorf("[GetAllProduct] error query PlatformIcon, err:%+v", err)
+			return nil, 0, err
+		}
+		platformToPlatformIcon[projectInfo.ProjectPlatform] = PlatformIcon
+	}
+	for _, projectInfo := range projectInfos {
+		var SignNum int64
+		db1 := GetReadDB(ctx)
+		err := db1.Debug().Model(gorm_model.YoungeeTaskInfo{}).Where("project_id = ?", projectInfo.ProjectID).Count(&SignNum).Error
+		if err != nil {
+			logrus.WithContext(ctx).Errorf("[GetAllProduct] error query SignNum, err:%+v", err)
+			return nil, 0, err
+		}
+		projectIdToSignNum[projectInfo.ProjectID] = SignNum
+	}
+	for _, projectInfo := range projectInfos {
+		ProjectBriefInfo := new(http_model.ProjectBriefInfo)
+		ProjectBriefInfo.ProjectName = projectInfo.ProjectName
+		ProjectBriefInfo.ProductSnap = projectInfo.ProductSnap
+		ProjectBriefInfo.ProductPhotoSnap = projectInfo.ProductPhotoSnap
+		ProjectBriefInfo.Platform = consts.GetProjectPlatform(projectInfo.ProjectPlatform)
+		ProjectBriefInfo.PlatformIcon = platformToPlatformIcon[projectInfo.ProjectPlatform]
+		ProjectBriefInfo.RecruitStrategys = projectIdToRecruitStrategy[projectInfo.ProjectID]
+		ProjectBriefInfo.SignNum = projectIdToSignNum[projectInfo.ProjectID]
+		ProjectBriefInfos = append(ProjectBriefInfos, ProjectBriefInfo)
+	}
+	return ProjectBriefInfos, total, nil
+}

+ 69 - 0
handler/getAllProduct.go

@@ -0,0 +1,69 @@
+package handler
+
+import (
+	"errors"
+	"fmt"
+	"github.com/gin-gonic/gin"
+	"github.com/sirupsen/logrus"
+	"youngee_b_api/consts"
+	"youngee_b_api/middleware"
+	"youngee_b_api/model/http_model"
+	"youngee_b_api/service"
+	"youngee_b_api/util"
+)
+
+func WrapGetAllProjectHandler(ctx *gin.Context) {
+	handler := newGetAllProductHandler(ctx)
+	baseRun(handler)
+}
+
+type GetAllProductHandler struct {
+	ctx  *gin.Context
+	req  *http_model.GetAllProductRequest
+	resp *http_model.CommonResponse
+}
+
+func (g GetAllProductHandler) getContext() *gin.Context {
+	return g.ctx
+}
+
+func (g GetAllProductHandler) getResponse() interface{} {
+	return g.resp
+}
+
+func (g GetAllProductHandler) getRequest() interface{} {
+	return g.req
+}
+
+func (g GetAllProductHandler) run() {
+	enterpriseID := middleware.GetSessionAuth(g.ctx).EnterpriseID
+	res, err := service.Product.GetAllProduct(g.ctx, g.req, enterpriseID)
+	if err != nil {
+		logrus.Errorf("[GetAllProductHandler] call GetAllProduct err:%+v\n", err)
+		util.HandlerPackErrorResp(g.resp, consts.ErrorInternal, "")
+		logrus.Info("GetAllProduct fail,req:%+v", g.req)
+		return
+	}
+	g.resp.Message = "项目列表查询成功"
+	g.resp.Data = res
+}
+
+func (g GetAllProductHandler) checkParam() error {
+	var errs []error
+	if g.req.PageNum < 0 || g.req.PageSize <= 0 {
+		errs = append(errs, errors.New("page param error"))
+	}
+	g.req.PageNum--
+	if len(errs) != 0 {
+		return fmt.Errorf("check param errs:%+v", errs)
+	}
+	return nil
+}
+
+func newGetAllProductHandler(ctx *gin.Context) *GetAllProductHandler {
+	return &GetAllProductHandler{
+		ctx:  ctx,
+		req:  http_model.NewGetAllProductRequest(),
+		resp: http_model.NewGetAllProductResponse(),
+	}
+}

+ 54 - 0
handler/getAllSelection.go

@@ -0,0 +1,54 @@
+package handler
+
+import (
+	"errors"
+	"fmt"
+	"github.com/gin-gonic/gin"
+	"youngee_b_api/model/http_model"
+)
+
+func WrapGetAllSelectionHandler(ctx *gin.Context) {
+	handler := newGetAllSelectionHandler(ctx)
+	baseRun(handler)
+}
+
+type AllSelectionHandler struct {
+	ctx  *gin.Context
+	req  *http_model.GetAllSelectionRequest
+	resp *http_model.CommonResponse
+}
+
+func (a AllSelectionHandler) getContext() *gin.Context {
+	return a.ctx
+}
+
+func (a AllSelectionHandler) getResponse() interface{} {
+	return a.resp
+}
+
+func (a AllSelectionHandler) getRequest() interface{} {
+	return a.req
+}
+
+func (a AllSelectionHandler) run() {
+}
+
+func (a AllSelectionHandler) checkParam() error {
+	var errs []error
+	if a.req.PageNum < 0 || a.req.PageSize <= 0 {
+		errs = append(errs, errors.New("page param error"))
+	}
+	a.req.PageNum--
+	if len(errs) != 0 {
+		return fmt.Errorf("check param errs:%+v", errs)
+	}
+	return nil
+}
+
+func newGetAllSelectionHandler(ctx *gin.Context) *AllSelectionHandler {
+	return &AllSelectionHandler{
+		ctx:  ctx,
+		req:  http_model.NewGetAllSelectionRequest(),
+		resp: http_model.NewGetAllSelectionResponse(),
+	}
+}

+ 14 - 0
model/gorm_model/info_third_platform.go

@@ -0,0 +1,14 @@
+package gorm_model
+
+// Code generated by sql2gorm. DO NOT EDIT.
+
+type InfoThirdPlatform struct {
+	PlatformID        int    `gorm:"column:platform_id;primary_key;AUTO_INCREMENT"` // 平台id,主键
+	PlatformName      string `gorm:"column:platform_name;NOT NULL"`                 // 平台名
+	PlatformIcon      string `gorm:"column:platform_icon;NOT NULL"`                 // 平台图标url
+	PlatformTableName string `gorm:"column:platform_table_name;NOT NULL"`           // 平台数据表表名
+}
+
+func (m *InfoThirdPlatform) TableName() string {
+	return "info_third_platform"
+}

+ 38 - 0
model/http_model/AllSelectionHandler.go

@@ -0,0 +1,38 @@
+package http_model
+
+type GetAllSelectionRequest struct {
+	PageSize    int64 `json:"page_size"`
+	PageNum     int64 `json:"page_num"`
+	ProductType int8  `json:"product_type"` // 内容形式
+	Platform    int8  `json:"platform"`     // 社媒平台
+	SampleMode  int8  `json:"sample_mode"`  // 领样形式
+	TaskMode    int8  `json:"task_mode"`    // 任务形式
+}
+
+type SelectionBriefInfo struct {
+	SelectionName    string `json:"selection_name"`     // 项目名称
+	Platform         string `json:"platform"`           // 社媒平台,1-7分别表示小红书、抖音、微博、快手、b站、大众点评、知乎
+	PlatformIcon     string `json:"platform_icon"`      // 平台logo
+	ProductSnap      string `json:"product_snap"`       // 商品信息快照
+	ProductPhotoSnap string `json:"product_photo_snap"` // 商品图片快照
+	EstimatedIncome  string `json:"estimated_income"`   // 预估赚金额,计算方式:商品售价×佣金比例
+	SignNum          string `json:"sign_num"`           // 佣金比例,百分之
+	TaskReward       string `json:"task_reward"`        // 额外悬赏
+	SampleMode       string `json:"sample_mode"`        // 领样形式,1、2、3分别表示免费领样、垫付领样、不提供样品
+	TaskMode         string `json:"task_mode"`          // 任务形式,1、2分别表示悬赏任务、纯佣带货
+}
+
+type SelectionBriefInfoPreview struct {
+	SelectionBriefInfo []*SelectionBriefInfo `json:"selection_brief_info"`
+	Total              string                `json:"total"`
+}
+
+func NewGetAllSelectionRequest() *GetAllSelectionRequest {
+	return new(GetAllSelectionRequest)
+}
+
+func NewGetAllSelectionResponse() *CommonResponse {
+	resp := new(CommonResponse)
+	resp.Data = new(SelectionBriefInfoPreview)
+	return resp
+}

+ 36 - 0
model/http_model/GetAllProductHandler.go

@@ -0,0 +1,36 @@
+package http_model
+
+import "youngee_b_api/model/gorm_model"
+
+type GetAllProductRequest struct {
+	PageSize    int64 `json:"page_size"`
+	PageNum     int64 `json:"page_num"`
+	Platform    int8  `json:"platform"`     // 社媒平台
+	FeeForm     int8  `json:"fee_form"`     // 稿费形式
+	ProjectForm int8  `json:"project_form"` // 项目形式
+}
+
+type ProjectBriefInfo struct {
+	ProjectName      string                        `json:"project_name"`       // 项目名称
+	Platform         string                        `json:"platform"`           // 社媒平台
+	PlatformIcon     string                        `json:"platform_icon"`      // 平台logo
+	ProductSnap      string                        `json:"product_snap"`       // 商品信息快照
+	ProductPhotoSnap string                        `json:"product_photo_snap"` // 商品图片快照
+	RecruitStrategys []*gorm_model.RecruitStrategy `json:"recruit_strategys"`  // 招募策略
+	SignNum          int64                         `json:"sign_num"`           // 报名人数
+}
+
+type ProjectBriefInfoPreview struct {
+	ProjectBriefInfo []*ProjectBriefInfo `json:"project_brief_info"`
+	Total            string              `json:"total"`
+}
+
+func NewGetAllProductRequest() *GetAllProductRequest {
+	return new(GetAllProductRequest)
+}
+
+func NewGetAllProductResponse() *CommonResponse {
+	resp := new(CommonResponse)
+	resp.Data = new(ProjectBriefInfoPreview)
+	return resp
+}

+ 4 - 1
route/init.go

@@ -36,7 +36,7 @@ func InitRoute(r *gin.Engine) {
 	//})
 	m := r.Group("/youngee/m")
 	{
-		m.Use(middleware.LoginAuthMiddleware)
+		//m.Use(middleware.LoginAuthMiddleware)
 		m.POST("/test", func(c *gin.Context) {
 			c.JSON(200, "ok")
 			// 注意这里只是debug用的 接口要写成handler形式
@@ -132,6 +132,8 @@ func InitRoute(r *gin.Engine) {
 		m.POST("/project/recruit/getservicecharge", handler.WrapGetServiceChargeHandler)         // 获取产品置换服务费
 		m.POST("/product/deletePhotoUrl", handler.WrapDeletePhotoUrlHandler)                     // 在数据库中删除图片url
 		m.POST("/qrcode/getwxqrcode", handler.WrapGetWxQRCodeHandler)                            // 获取微信二维码
+
+		m.POST("/project/getAllProduct", handler.WrapGetAllProjectHandler) // 查询项目广场项目列表
 	}
 
 	// 选品广场相关接口
@@ -150,5 +152,6 @@ func InitRoute(r *gin.Engine) {
 		s.POST("/selection/task/logistics/create", handler.WrapCreateSecTaskLogisticsHandler) // 上传物流信息
 		s.POST("/selection/task/logistics/update", handler.WrapUpdateSecTaskLogisticsHandler) // 修改物流信息
 		s.POST("/selection/task/settle", handler.WrapSettleSecTaskHandler)                    // 结算
+		s.POST("/selection/getAllSelection", handler.WrapGetAllSelectionHandler)              // 查询选品广场选品列表
 	}
 }

+ 12 - 0
service/product.go

@@ -3,6 +3,7 @@ package service
 import (
 	"context"
 	"fmt"
+	"strconv"
 	"youngee_b_api/consts"
 	"youngee_b_api/db"
 	"youngee_b_api/model/gorm_model"
@@ -156,3 +157,14 @@ func (*product) FindByName(ctx context.Context, brandName string, productName st
 	}
 	return productID, nil
 }
+
+func (*product) GetAllProduct(ctx context.Context, req *http_model.GetAllProductRequest, enterpriseID string) (*http_model.ProjectBriefInfoPreview, error) {
+	ProjectBriefInfo, total, err := db.GetAllProduct(ctx, req, enterpriseID)
+	if err != nil {
+		return nil, err
+	}
+	ProjectBriefInfoPreview := new(http_model.ProjectBriefInfoPreview)
+	ProjectBriefInfoPreview.ProjectBriefInfo = ProjectBriefInfo
+	ProjectBriefInfoPreview.Total = strconv.FormatInt(total, 10)
+	return ProjectBriefInfoPreview, nil
+}