Explorar o código

完成选品广场

Ohio-HYF hai 1 ano
pai
achega
8e08618d29

+ 20 - 0
consts/platform.go

@@ -0,0 +1,20 @@
+package consts
+
+var platformIconMap = map[int]string{
+	0: "https://horastar.obs.cn-east-3.myhuaweicloud.com/talent/platformlogo/redbook.png",
+	1: "https://horastar.obs.cn-east-3.myhuaweicloud.com/talent/platformlogo/redbook.png",
+	2: "https://horastar.obs.cn-east-3.myhuaweicloud.com/talent/pingtai2.png",
+	3: "https://horastar.obs.cn-east-3.myhuaweicloud.com/talent/lQLPDhrXwll1_OojIrB54K2_gW0cQQGOvh1TQE8B_34_35.png",
+	4: "https://horastar.obs.cn-east-3.myhuaweicloud.com/talent/lQLPDhrXwll1_NcjI7AD0T3viYtxQwGOvh1SwG0A_35_35.png",
+	5: "https://horastar.obs.cn-east-3.myhuaweicloud.com/talent/lQLPDhrXwll1_N8lJbAnowYY8vg2EwGOvh1MQAcA_37_37.png",
+	6: "https://horastar.obs.cn-east-3.myhuaweicloud.com/talent/lQLPDhrXwll1_NomJrBzk2H1dD_6NwGOvh1TQE8A_38_38.png",
+	7: "https://horastar.obs.cn-east-3.myhuaweicloud.com/talent/lQLPDhrXwll1_OglJrDwCzIdgTtsKQGOvh1TAG0A_38_37.png",
+}
+
+func GetPaltformIcon(platformId int) string {
+	icon, contain := platformIconMap[platformId]
+	if contain {
+		return icon
+	}
+	return ""
+}

+ 69 - 0
db/selection.go

@@ -2,6 +2,7 @@ package db
 
 import (
 	"context"
+	"encoding/json"
 	"errors"
 	"fmt"
 	"github.com/issue9/conv"
@@ -11,6 +12,8 @@ import (
 	"strings"
 	"youngee_b_api/model/common_model"
 	"youngee_b_api/model/gorm_model"
+	"youngee_b_api/model/http_model"
+	"youngee_b_api/pack"
 	"youngee_b_api/util"
 )
 
@@ -244,3 +247,69 @@ func UpdateSelectionSettleMoney(ctx context.Context, selectionID string, payMone
 
 	return true, nil
 }
+
+func GetSelectionInfoList(ctx context.Context, pageNum, pageSize int64, conditions http_model.SelectionSquareCondition) ([]*http_model.SelectionBriefInfo, int64, error) {
+	db := GetReadDB(ctx)
+	db = db.Debug().Model(gorm_model.YounggeeSelectionInfo{})
+
+	conditionType := reflect.TypeOf(&conditions).Elem()
+	conditionValue := reflect.ValueOf(&conditions).Elem()
+	for i := 0; i < conditionType.NumField(); i++ {
+		field := conditionType.Field(i)
+		tag := field.Tag.Get("condition")
+		value := conditionValue.FieldByName(field.Name)
+		if tag == "product_type" {
+			continue
+		} else {
+			if value.Interface().(int16) != 0 {
+				db = db.Where(fmt.Sprintf("%s = ?", tag), value.Interface())
+			}
+		}
+	}
+	// 查询总数
+	var total int64
+	var selectionInfos []*gorm_model.YounggeeSelectionInfo
+	if err := db.Count(&total).Error; err != nil {
+		logrus.WithContext(ctx).Errorf("[GetSelectionList] error query mysql total, err:%+v", err)
+		return nil, 0, err
+	}
+
+	limit := pageSize
+	offset := pageSize * pageNum // assert pageNum start with 0\
+	tempList := []*gorm_model.YounggeeSelectionInfo{}
+	if conditions.ProductType == 0 {
+		// 查询该页数据
+		err := db.Order("task_ddl desc").Limit(int(limit)).Offset(int(offset)).Find(&selectionInfos).Error
+		if err != nil {
+			logrus.WithContext(ctx).Errorf("[GetSelectionList] error query mysql total, err:%+v", err)
+			return nil, 0, err
+		}
+
+		tempList = selectionInfos
+	} else {
+		err := db.Order("task_ddl desc").Find(&selectionInfos).Error
+		if err != nil {
+			logrus.WithContext(ctx).Errorf("[GetSelectionList] error query mysql total, err:%+v", err)
+			return nil, 0, err
+		}
+		total = 0
+		var num int64 = 0
+		//fmt.Println("offset: ", offset)
+		for _, v := range selectionInfos {
+			var p gorm_model.YounggeeProduct
+			_ = json.Unmarshal([]byte(v.ProductSnap), &p)
+			if p.ProductType == int64(conditions.ProductType) {
+				total++
+				//fmt.Println("total++", total)
+				if total > offset && num < pageSize {
+					//fmt.Println("num++", num)
+					num++
+					tempList = append(tempList, v)
+				}
+			}
+		}
+	}
+
+	newSelectionInfos := pack.GormSelectionListToSelectionBriefInfoList(tempList)
+	return newSelectionInfos, total, nil
+}

+ 13 - 0
handler/getAllSelection.go

@@ -4,7 +4,12 @@ import (
 	"errors"
 	"fmt"
 	"github.com/gin-gonic/gin"
+	"github.com/sirupsen/logrus"
+	"youngee_b_api/consts"
 	"youngee_b_api/model/http_model"
+	"youngee_b_api/pack"
+	"youngee_b_api/service/selection_service"
+	"youngee_b_api/util"
 )
 
 func WrapGetAllSelectionHandler(ctx *gin.Context) {
@@ -31,6 +36,14 @@ func (a AllSelectionHandler) getRequest() interface{} {
 }
 
 func (a AllSelectionHandler) run() {
+	condition := pack.GetSelectionSquareCondition(*a.req)
+	data, err := selection_service.Selection.SelectionSquare(a.ctx, *a.req, condition)
+	if err != nil {
+		logrus.WithContext(a.ctx).Errorf("[FindAllSelectionHandler] error GetAllSelection, err:%+v", err)
+		util.HandlerPackErrorResp(a.resp, consts.ErrorInternal, consts.DefaultToast)
+		return
+	}
+	a.resp.Data = data
 }
 
 func (a AllSelectionHandler) checkParam() error {

+ 3 - 4
model/gorm_model/product_photo.go

@@ -6,15 +6,14 @@ import (
 )
 
 type YounggeeProductPhoto struct {
-	ProductPhotoID int64       `gorm:"column:product_photo_id;primary_key;AUTO_INCREMENT"` // 商品图片id
+	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
+	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"
 }
-

+ 22 - 14
model/http_model/AllSelectionHandler.go

@@ -1,25 +1,33 @@
 package http_model
 
+type SelectionSquareCondition struct {
+	ProductType int16 `condition:"product_type"` // 商品类型
+	Platform    int16 `condition:"platform"`     // 社媒平台
+	SampleMode  int16 `condition:"sample_mode"`  // 领样形式
+	TaskMode    int16 `condition:"task_mode"`    // 任务形式
+}
+
 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"`    // 任务形式
+	ProductType int16 `json:"product_type"` // 商品类型
+	Platform    int16 `json:"platform"`     // 社媒平台
+	SampleMode  int16 `json:"sample_mode"`  // 领样形式
+	TaskMode    int16 `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分别表示悬赏任务、纯佣带货
+	SelectionId     string  `json:"selection_id"`
+	SelectionName   string  `json:"selection_name"`   // 项目名称
+	Platform        int     `json:"platform"`         // 社媒平台,1-7分别表示小红书、抖音、微博、快手、b站、大众点评、知乎
+	EstimatedIncome float64 `json:"estimated_income"` // 预估赚金额,计算方式:商品售价×佣金比例
+	ProductPrice    float64 `json:"product_price"`    // 售价
+	CommissionRate  int     `json:"commission_rate"`  // 佣金比例,百分之
+	TaskReward      float64 `json:"task_reward"`      // 额外悬赏
+	SampleMode      int     `json:"sample_mode"`      // 领样形式,1、2、3分别表示免费领样、垫付领样、不提供样品
+	TaskMode        int     `json:"task_mode"`        // 任务形式,1、2分别表示悬赏任务、纯佣带货
+	PlatformIcon    string  `json:"platform_icon"`    // 平台logo
+	PhotoUrl        string  `json:"photo_url"`
 }
 
 type SelectionBriefInfoPreview struct {

+ 58 - 0
pack/selection_square.go

@@ -0,0 +1,58 @@
+package pack
+
+import (
+	"encoding/json"
+	"github.com/caixw/lib.go/conv"
+	"github.com/tidwall/gjson"
+	"strconv"
+	"youngee_b_api/consts"
+	"youngee_b_api/model/gorm_model"
+	"youngee_b_api/model/http_model"
+)
+
+func GetSelectionSquareCondition(req http_model.GetAllSelectionRequest) http_model.SelectionSquareCondition {
+	return http_model.SelectionSquareCondition{
+		ProductType: req.ProductType,
+		Platform:    req.Platform,
+		SampleMode:  req.SampleMode,
+		TaskMode:    req.TaskMode,
+	}
+}
+
+func GormSelectionListToSelectionBriefInfoList(gormSelectionInfos []*gorm_model.YounggeeSelectionInfo) []*http_model.SelectionBriefInfo {
+	var httpSelectionPreviews []*http_model.SelectionBriefInfo
+	for _, gormSelectionInfo := range gormSelectionInfos {
+		selectionBriefInfo := GormSelectionToSelectionBriefInfo(gormSelectionInfo)
+		httpSelectionPreviews = append(httpSelectionPreviews, selectionBriefInfo)
+	}
+	return httpSelectionPreviews
+}
+
+func GormSelectionToSelectionBriefInfo(selectionInfo *gorm_model.YounggeeSelectionInfo) *http_model.SelectionBriefInfo {
+	icon := consts.GetPaltformIcon(selectionInfo.Platform)
+	productPrice := conv.MustString(gjson.Get(selectionInfo.ProductSnap, "ProductPrice"), "")
+	price, _ := strconv.ParseFloat(productPrice, 64)
+	estimatedIncome := price * float64(selectionInfo.CommissionRate) / 100
+	var photoUrl string
+	var p []gorm_model.YounggeeProductPhoto
+	_ = json.Unmarshal([]byte(selectionInfo.ProductPhotoSnap), &p)
+	for _, v := range p {
+		if v.Symbol == 1 {
+			photoUrl = v.PhotoUrl
+		}
+	}
+	return &http_model.SelectionBriefInfo{
+		SelectionId:   selectionInfo.SelectionID,
+		SelectionName: selectionInfo.SelectionName,
+		Platform:      selectionInfo.Platform,
+		//ProductSnap:      selectionInfo.ProductSnap,
+		PlatformIcon: icon,
+		ProductPrice: price,
+		//ProductPhotoSnap: selectionInfo.ProductPhotoSnap,
+		EstimatedIncome: estimatedIncome,
+		CommissionRate:  selectionInfo.CommissionRate,
+		SampleMode:      selectionInfo.SampleMode,
+		TaskMode:        selectionInfo.TaskMode,
+		PhotoUrl:        photoUrl,
+	}
+}

+ 12 - 0
service/selection_service/selection.go

@@ -293,3 +293,15 @@ func (s *selection) GetSelectionDetail(ctx *gin.Context, selectionId, enterprise
 	selectionDetail.ProductPhotoInfo = productPhotoInfo
 	return &selectionDetail, nil
 }
+
+func (s *selection) SelectionSquare(ctx context.Context, req http_model.GetAllSelectionRequest, condition http_model.SelectionSquareCondition) (*http_model.SelectionBriefInfoPreview, error) {
+	SelectionList, total, err := db.GetSelectionInfoList(ctx, req.PageNum, req.PageSize, condition)
+	if err != nil {
+		logrus.WithContext(ctx).Errorf("[selectionDB service] call GetAllSelection error,err:%+v", err)
+		return nil, err
+	}
+	SelectionListData := new(http_model.SelectionBriefInfoPreview)
+	SelectionListData.SelectionBriefInfo = SelectionList
+	SelectionListData.Total = conv.MustString(total, "")
+	return SelectionListData, nil
+}