Parcourir la source

新增选品广场

Ohio-HYF il y a 1 an
Parent
commit
e160c29e8c

+ 1 - 1
config/dev.yaml

@@ -13,6 +13,6 @@ redis:
 
 server:
   host: 0.0.0.0
-  port: 8300
+  port: 8388
   session:
     ttl: -1 # minute

+ 1 - 1
config/pro.yaml

@@ -13,6 +13,6 @@ redis:
   
 server:
   host: 0.0.0.0
-  port: 8300
+  port: 8388
   session:
     ttl: -1 #minute

+ 13 - 1
db/sectask.go

@@ -123,6 +123,11 @@ func PassSecTaskCoop(ctx context.Context, selectionId string, taskIds []string)
 	if err != nil {
 		return false, err
 	}
+	if int64(selection.RemainNum) < count {
+		if int64(len(taskIds)) == 0 || count != int64(len(taskIds)) {
+			return true, errors.New("剩余选品数量不足")
+		}
+	}
 
 	err = db.Transaction(func(tx *gorm.DB) error {
 		// 2. 修改任务状态和任务阶段
@@ -151,7 +156,14 @@ func PassSecTaskCoop(ctx context.Context, selectionId string, taskIds []string)
 				return err
 			}
 		}
-		// 3. 生成达人消息
+		// 3. 更新选品剩余数量
+		err = tx.Model(gorm_model.YounggeeSelectionInfo{}).Where("selection_id = ?", selectionId).Updates(
+			map[string]interface{}{"remain_num": gorm.Expr("remain_num - ?", 1)}).Error
+		if err != nil {
+			return err
+		}
+
+		// 4. 生成达人消息
 		for _, talendId := range talentIds {
 			err = CreateMessage(ctx, 1, 1, talendId, selection.SelectionName)
 			if err != nil {

+ 9 - 0
db/talent_income.go

@@ -2,6 +2,7 @@ package db
 
 import (
 	"context"
+	"github.com/issue9/conv"
 	"gorm.io/gorm"
 	"youngee_b_api/model/gorm_model"
 )
@@ -12,12 +13,20 @@ func CreateIncome(ctx context.Context, income gorm_model.YounggeeTalentIncome, t
 		if err != nil {
 			return err
 		}
+		err = tx.Model(gorm_model.YoungeeTalentInfo{}).Where("id = ?", income.TalentID).Updates(map[string]interface{}{"income": gorm.Expr("income + ?", conv.MustFloat64(income.Income)), "canwithdraw": gorm.Expr("canwithdraw + ?", conv.MustFloat64(income.Income))}).Error
+		if err != nil {
+			return err
+		}
 	} else {
 		db := GetWriteDB(ctx)
 		err := db.Create(&income).Error
 		if err != nil {
 			return err
 		}
+		err = db.Model(gorm_model.YoungeeTalentInfo{}).Where("id = ?", income.TalentID).Updates(map[string]interface{}{"income": gorm.Expr("income + ?", conv.MustFloat64(income.Income)), "canwithdraw": gorm.Expr("canwithdraw + ?", conv.MustFloat64(income.Income))}).Error
+		if err != nil {
+			return err
+		}
 	}
 	return nil
 }

+ 15 - 1
db/task.go

@@ -193,13 +193,27 @@ func SetTaskFinish(ctx context.Context, TaskIDs []string) error {
 			fmt.Println("Error:", err)
 			return err
 		}
+		var productPhotoStruct []gorm_model.YounggeeProductPhoto
+		if err = json.Unmarshal([]byte(projectInfo.ProductPhotoSnap), &productPhotoStruct); err != nil {
+			fmt.Println("Error:", err)
+			return err
+		}
+		var mainPhoto = ""
+		for _, w := range productPhotoStruct {
+			if w.Symbol == 1 {
+				mainPhoto = w.PhotoUrl
+			}
+		}
+
 		t := time.Now()
 		income := gorm_model.YounggeeTalentIncome{
 			TalentID:       taskInfo.TalentID,
 			ProjectID:      taskInfo.ProjectID,
-			SectaskID:      taskInfo.TaskID,
+			TaskID:         taskInfo.TaskID,
+			Type:           1,
 			BrandName:      productStruct.BrandName,
 			TaskName:       projectInfo.ProjectName,
+			PhotoUrl:       mainPhoto,
 			Income:         strconv.FormatFloat(taskInfo.SettleAmount, 'f', 10, 32),
 			IncomeType:     1,
 			WithdrawStatus: 1,

+ 17 - 17
model/gorm_model/talent_income.go

@@ -2,28 +2,28 @@
 package gorm_model
 
 import (
-"time"
+	"time"
 )
 
 type YounggeeTalentIncome struct {
-	ID             int       `gorm:"column:id;primary_key"`  // 递增id
-	TalentID       string    `gorm:"column:talent_id"`       // 达人id,对应youngee_talent_info中id字段
-	ProjectID      string    `gorm:"column:project_id"`      // 项目id
-	SelectionID    string    `gorm:"column:selection_id"`    // 选品id
-	TaskID         string    `gorm:"column:task_id"`         // 任务id
-	SectaskID      string    `gorm:"column:sectask_id"`      // 选品任务id
-	BrandName      string    `gorm:"column:brand_name"`      // 品牌名称
-	TaskName       string    `gorm:"column:task_name"`       // 任务名称
-	TeamID         string    `gorm:"column:team_id"`         // young之团id
-	Income         string    `gorm:"column:income"`          // 收益金额
-	IncomeType     int       `gorm:"column:income_type"`     // 收益类型,1-4分别表示任务收益、开团收益、样品返现、悬赏收益
-	WithdrawStatus int       `gorm:"column:withdraw_status"` // 提现状态,1-3分别表示可提现、提现中、已提现
-	IncomeAt       *time.Time `gorm:"column:income_at"`       // 收益产生时间
-	WithdrawAt     *time.Time `gorm:"column:withdraw_at"`     // 提现时间
+	ID             int        `gorm:"column:id;primary_key;AUTO_INCREMENT"` // 递增id
+	TalentID       string     `gorm:"column:talent_id"`                     // 达人id,对应youngee_talent_info中id字段
+	ProjectID      string     `gorm:"column:project_id"`                    // 项目id
+	SelectionID    string     `gorm:"column:selection_id"`                  // 选品id
+	TaskID         string     `gorm:"column:task_id"`                       // 任务id
+	SectaskID      string     `gorm:"column:sectask_id"`                    // 选品任务id
+	BrandName      string     `gorm:"column:brand_name"`                    // 品牌名称
+	TaskName       string     `gorm:"column:task_name"`                     // 任务名称
+	TeamID         string     `gorm:"column:team_id"`                       // young之团id
+	Income         string     `gorm:"column:income"`                        // 收益金额
+	IncomeType     int        `gorm:"column:income_type"`                   // 收益类型,1-4分别表示任务收益、开团收益、样品返现、悬赏收益
+	Type           int        `gorm:"column:type"`                          // 选品or项目,1:项目,2:选品
+	WithdrawStatus int        `gorm:"column:withdraw_status"`               // 提现状态,1-3分别表示可提现、提现中、已提现
+	IncomeAt       *time.Time `gorm:"column:income_at"`                     // 收益产生时间
+	WithdrawAt     *time.Time `gorm:"column:withdraw_at"`                   // 提现时间
+	PhotoUrl       string     `gorm:"column:photo_url"`                     // 商品主图
 }
 
 func (m *YounggeeTalentIncome) TableName() string {
 	return "younggee_talent_income"
 }
-
-

+ 14 - 1
service/project_pay.go

@@ -166,13 +166,26 @@ func (p *projectPay) SpecialSettlePay(ctx *gin.Context, req *http_model.SpecialS
 			fmt.Println("Error:", err)
 			return err
 		}
+		var productPhotoStruct []gorm_model.YounggeeProductPhoto
+		if err = json.Unmarshal([]byte(projectInfo.ProductPhotoSnap), &productPhotoStruct); err != nil {
+			fmt.Println("Error:", err)
+			return err
+		}
+		var mainPhoto = ""
+		for _, w := range productPhotoStruct {
+			if w.Symbol == 1 {
+				mainPhoto = w.PhotoUrl
+			}
+		}
 		t := time.Now()
 		income := gorm_model.YounggeeTalentIncome{
 			TalentID:       task.TalentID,
 			ProjectID:      task.ProjectID,
-			SectaskID:      task.TaskID,
+			TaskID:         task.TaskID,
+			Type:           1,
 			BrandName:      productInfo.BrandName,
 			TaskName:       projectInfo.ProjectName,
+			PhotoUrl:       mainPhoto,
 			Income:         strconv.FormatFloat(req.Amount, 'f', 10, 32),
 			IncomeType:     1,
 			WithdrawStatus: 1,

+ 17 - 3
service/sectask_service/sectask.go

@@ -70,7 +70,6 @@ func (*selectionTask) GetList(ctx context.Context, request http_model.GetSecTask
 }
 
 func (*selectionTask) PassCoop(ctx context.Context, request http_model.PassSecTaskCoopRequest) (*http_model.PassSecTaskCoopData, error) {
-
 	_, err := db.PassSecTaskCoop(ctx, request.SelectionId, request.TaskIds)
 	if err != nil {
 		logrus.WithContext(ctx).Errorf("[sectask_service service] call PassCoop error,err:%+v", err)
@@ -193,16 +192,29 @@ func (*selectionTask) Settle(ctx context.Context, entersizeId string, request ht
 
 	// 6. 创建选品收益记录
 	// 返现收益
+	var productPhotoStruct []gorm_model.YounggeeProductPhoto
+	if err = json.Unmarshal([]byte(selection.ProductPhotoSnap), &productPhotoStruct); err != nil {
+		fmt.Println("Error:", err)
+		return nil, err
+	}
+	var mainPhoto = ""
+	for _, w := range productPhotoStruct {
+		if w.Symbol == 1 {
+			mainPhoto = w.PhotoUrl
+		}
+	}
 	t := time.Now()
 	if request.IsReturnMoney == 1 {
 		income := gorm_model.YounggeeTalentIncome{
 			TalentID:       secTask.TalentID,
 			SelectionID:    secTask.SelectionID,
 			SectaskID:      secTask.TaskID,
+			Type:           2,
 			BrandName:      product.BrandName,
 			TaskName:       selection.SelectionName,
+			PhotoUrl:       mainPhoto,
 			Income:         strconv.FormatFloat(returnMoney, 'f', 10, 32),
-			IncomeType:     1,
+			IncomeType:     3,
 			WithdrawStatus: 1,
 			IncomeAt:       &t,
 			WithdrawAt:     nil,
@@ -219,10 +231,12 @@ func (*selectionTask) Settle(ctx context.Context, entersizeId string, request ht
 			TalentID:       secTask.TalentID,
 			SelectionID:    secTask.SelectionID,
 			SectaskID:      secTask.TaskID,
+			Type:           2,
 			BrandName:      product.BrandName,
 			TaskName:       selection.SelectionName,
+			PhotoUrl:       mainPhoto,
 			Income:         strconv.FormatFloat(rewardMoney, 'f', 10, 32),
-			IncomeType:     1,
+			IncomeType:     4,
 			WithdrawStatus: 1,
 			IncomeAt:       &t,
 			WithdrawAt:     nil,