Parcourir la source

新增待支付

shenzekai il y a 2 ans
Parent
commit
bc66efa35f

+ 2 - 2
db/project.go

@@ -105,8 +105,8 @@ func GetProjectTaskList(ctx context.Context, projectID string, pageSize, pageNum
 	var accountIds []int
 	taskMap := make(map[int]gorm_model.YoungeeTaskInfo)
 	for _, taskInfo := range taskInfos {
-		accountIds = append(accountIds, taskInfo.AccountID)
-		taskMap[taskInfo.AccountID] = taskInfo
+		accountIds = append(accountIds, taskInfo.AccountId)
+		taskMap[taskInfo.AccountId] = taskInfo
 	}
 	db1 := GetReadDB(ctx)
 	db1 = db1.Debug().Model(gorm_model.YoungeePlatformAccountInfo{})

+ 19 - 0
db/task.go

@@ -0,0 +1,19 @@
+package db
+
+import (
+	"context"
+	"fmt"
+	"youngee_b_api/model/gorm_model"
+)
+
+func GetTaskList(ctx context.Context, projectID int64) ([]gorm_model.YoungeeTaskInfo, error) {
+	db := GetReadDB(ctx)
+	tasks := []gorm_model.YoungeeTaskInfo{}
+
+	err := db.Where("project_id=?", projectID).Find(&tasks).Error
+	if err != nil {
+		return nil, err
+	}
+	fmt.Printf("%+v", tasks)
+	return tasks, nil
+}

+ 62 - 0
handler/pay_sum.go

@@ -0,0 +1,62 @@
+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 WrapPaySumHandler(ctx *gin.Context) {
+	handler := newPaySumHandler(ctx)
+	baseRun(handler)
+}
+
+func newPaySumHandler(ctx *gin.Context) *PaySumHandler {
+	return &PaySumHandler{
+		req:  http_model.NewPaySumRequest(),
+		resp: http_model.NewPaySumResponse(),
+		ctx:  ctx,
+	}
+}
+
+type PaySumHandler struct {
+	req  *http_model.PaySumRequest
+	resp *http_model.CommonResponse
+	ctx  *gin.Context
+}
+
+func (h *PaySumHandler) getRequest() interface{} {
+	return h.req
+}
+func (h *PaySumHandler) getContext() *gin.Context {
+	return h.ctx
+}
+func (h *PaySumHandler) getResponse() interface{} {
+	return h.resp
+}
+func (h *PaySumHandler) run() {
+	data := http_model.PaySumRequest{}
+	data = *h.req
+	fmt.Printf("data %+v", data)
+	//auth := middleware.GetSessionAuth(h.ctx)
+	//enterpriseID := auth.EnterpriseID
+	res, err := service.Pay.GetPaysum(h.ctx, data)
+	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 *PaySumHandler) checkParam() error {
+	return nil
+}

+ 22 - 15
model/gorm_model/project_task.go

@@ -6,21 +6,28 @@ import (
 )
 
 type YoungeeTaskInfo struct {
-	TaskID                 int       `gorm:"column:task_id;primary_key;AUTO_INCREMENT"` // 任务id
-	ProjectID              int       `gorm:"column:project_id;NOT NULL"`                // 项目id
-	AccountID              int       `gorm:"column:account_id;NOT NULL"`                // 账号id
-	TalentPlatformInfoSnap string    `gorm:"column:talent_platform_info_snap;NOT NULL"` // 达人平台信息快照
-	TalentPersonalInfoSnap string    `gorm:"column:talent_personal_info_snap;NOT NULL"` // 达人个人信息快照
-	TalentPostAddrSnap     string    `gorm:"column:talent_post_addr_snap;NOT NULL"`     // 收货地址快照
-	StrategyID             int       `gorm:"column:strategy_id"`                        // 报名选择的招募策略id
-	TaskReward             int64     `gorm:"column:task_reward"`                        // 任务奖励金额
-	SettleAmount           int64     `gorm:"column:settle_amount;NOT NULL"`             // 待结算金额(任务奖励扣除违规扣款)
-	TaskStatus             int       `gorm:"column:task_status;default:1;NOT NULL"`     // 任务状态 1待选 2已选 3落选
-	CreateDate             time.Time `gorm:"column:create_date;NOT NULL"`               // 创建时间
-	SelectDate             time.Time `gorm:"column:select_date"`                        // 反选时间
-	CompleteStatus         int       `gorm:"column:complete_status;default:1;NOT NULL"` // 结束方式 1未结束 2正常结束 3反选失败 4被解约
-	CompleteDate           time.Time `gorm:"column:complete_date"`                      // 结束时间
-	TaskStage              int       `gorm:"column:task_stage;NOT NULL"`                // 任务阶段
+	TaskId                 int       `gorm:"column:task_id;type:int(11);primary_key;AUTO_INCREMENT;comment:任务id" json:"task_id"`
+	ProjectId              int       `gorm:"column:project_id;type:int(11);comment:项目id;NOT NULL" json:"project_id"`
+	TalentId               string    `gorm:"column:talent_id;type:varchar(25);comment:达人id;NOT NULL" json:"talent_id"`
+	AccountId              int       `gorm:"column:account_id;type:int(11);comment:账号id;NOT NULL" json:"account_id"`
+	TalentPlatformInfoSnap string    `gorm:"column:talent_platform_info_snap;type:json;comment:达人平台信息快照;NOT NULL" json:"talent_platform_info_snap"`
+	TalentPersonalInfoSnap string    `gorm:"column:talent_personal_info_snap;type:json;comment:达人个人信息快照;NOT NULL" json:"talent_personal_info_snap"`
+	TalentPostAddrSnap     string    `gorm:"column:talent_post_addr_snap;type:json;comment:收货地址快照;NOT NULL" json:"talent_post_addr_snap"`
+	StrategyId             int       `gorm:"column:strategy_id;type:int(11);comment:报名选择的招募策略id" json:"strategy_id"`
+	TaskReward             float64   `gorm:"column:task_reward;type:float;comment:达人报酬;NOT NULL" json:"task_reward"`
+	SettleAmount           float64   `gorm:"column:settle_amount;type:float;comment:达人实际所得(扣除违约扣款);NOT NULL" json:"settle_amount"`
+	AllPayment             float64   `gorm:"column:all_payment;type:float;comment:企业支付;NOT NULL" json:"all_payment"`
+	RealPayment            float64   `gorm:"column:real_payment;type:float;comment:企业实际支付(扣除违约扣款);NOT NULL" json:"real_payment"`
+	Penalty                int       `gorm:"column:penalty;type:int(11);comment:违约扣款比例,百分之;NOT NULL" json:"penalty"`
+	FeeForm                int       `gorm:"column:fee_form;type:tinyint(4);comment:稿费形式,1,2,3分别代表产品置换、固定稿费、自报价;NOT NULL" json:"fee_form"`
+	ServiceCharge          float64   `gorm:"column:service_charge;type:float;comment:服务费" json:"service_charge"`
+	ServiceRate            int       `gorm:"column:service_rate;type:int(11);comment:服务费率,千分之" json:"service_rate"`
+	TaskStatus             int       `gorm:"column:task_status;type:tinyint(4);default:1;comment:任务状态 1待选 2已选 3落选;NOT NULL" json:"task_status"`
+	TaskStage              int       `gorm:"column:task_stage;type:tinyint(1);comment:任务阶段;NOT NULL" json:"task_stage"`
+	CreateDate             time.Time `gorm:"column:create_date;type:datetime;comment:创建时间;NOT NULL" json:"create_date"`
+	SelectDate             time.Time `gorm:"column:select_date;type:datetime;comment:反选时间" json:"select_date"`
+	CompleteStatus         int       `gorm:"column:complete_status;type:tinyint(1);default:1;comment:结束方式 1未结束 2正常结束 3反选失败 4被解约;NOT NULL" json:"complete_status"`
+	CompleteDate           time.Time `gorm:"column:complete_date;type:datetime;comment:结束时间" json:"complete_date"`
 }
 
 func (m *YoungeeTaskInfo) TableName() string {

+ 23 - 0
model/http_model/pay_sum.go

@@ -1 +1,24 @@
 package http_model
+
+type PaySumRequest struct {
+	ProjectId string `json:"project_id"` // 项目ID
+}
+type PaySum struct {
+	StrategyId int     `json:"strategy_id"`  // 策略ID
+	AllPayment float64 `json:"all_payment"'` //任务的全部费用
+}
+type PaySumResponce struct {
+	//ProjectId  string  `json:"project_id"`   // 项目ID
+	PaySum []PaySum `json:"pay_sum"` //总数
+	//FeeForm    int     `json:"fee_form""`    //稿费形式
+}
+
+func NewPaySumRequest() *PaySumRequest {
+	return new(PaySumRequest)
+}
+
+func NewPaySumResponse() *CommonResponse {
+	resp := new(CommonResponse)
+	resp.Data = new(ProjectTaskListData)
+	return resp
+}

+ 2 - 0
model/http_model/project_show.go

@@ -30,8 +30,10 @@ type ShowProjectData struct {
 	ProjectPhotos    []ShowProjectPhoto    `json:"project_photos"`    // 项目图片
 	ProductID        string                `json:"product_id"`        // 关联商品id
 	EnterpriseID     string                `json:"enterprise_id"`     // 企业id
+	Balance          string                `json:"balance"`           //企业余额
 	ProjectID        string                `json:"project_id"`        // 项目id
 	CreateAt         time.Time             `json:"create_at"`         //创建时间
+	UpdateAt         time.Time             `json:"update_at"`         //更新时间
 	Phone            string                `json:"phone"`             //联系方式
 }
 

+ 1 - 1
model/http_model/project_taskList.go

@@ -33,7 +33,7 @@ type ProjectTaskInfo struct {
 	FansCount          int64     `json:"fans_count"`            // 粉丝数
 	HomePageCaptureUrl string    `json:"home_page_capture_url"` // 主页截图链接
 	StrategyID         int       `json:"strategy_id"`           // 报名选择的招募策略id
-	TaskReward         int64     `json:"task_reward"`           // 任务奖励金额
+	TaskReward         float64   `json:"task_reward"`           // 任务奖励金额
 	HomePageUrl        string    `json:"home_page_url"`         // 主页链接
 	TaskStatus         string    `json:"task_status"`           // 任务状态 1待选 2已选 3落选
 	CreateDate         time.Time `json:"create_date"`           // 创建时间

+ 6 - 6
model/http_model/project_update.go

@@ -8,12 +8,12 @@ type UpdateProjectPhoto struct {
 }
 
 type UpdateRecruitStrategy struct {
-	FeeForm       string `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"`          // 报价
+	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 UpdateProjectRequest struct {

+ 2 - 2
pack/project_task_list.go

@@ -42,7 +42,7 @@ func TaskAccountToTaskInfo(taskAccounts []*http_model.TaskAccount) []*http_model
 
 func GetTaskInfoStruct(taskAccount *http_model.TaskAccount) *http_model.ProjectTaskInfo {
 	return &http_model.ProjectTaskInfo{
-		TaskID:             taskAccount.Task.TaskID,
+		TaskID:             taskAccount.Task.TaskId,
 		TaskReward:         taskAccount.Task.TaskReward,
 		PlatformNickname:   taskAccount.Account.PlatformNickname,
 		CreateDate:         taskAccount.Task.CreateDate,
@@ -50,6 +50,6 @@ func GetTaskInfoStruct(taskAccount *http_model.TaskAccount) *http_model.ProjectT
 		HomePageCaptureUrl: taskAccount.Account.HomePageCaptureUrl,
 		FansCount:          taskAccount.Account.FansCount,
 		TaskStatus:         string(rune(taskAccount.Task.TaskStatus)),
-		StrategyID:         taskAccount.Task.StrategyID,
+		StrategyID:         taskAccount.Task.StrategyId,
 	}
 }

+ 1 - 0
route/init.go

@@ -52,6 +52,7 @@ func InitRoute(r *gin.Engine) {
 		m.POST("/product/list", handler.WrapFullProjectListHandler)
 		m.POST("/project/taskList", handler.WrapProjectTaskListHandler)
 		m.POST("/project/changeTaskStatus", handler.WrapProjectChangeTaskStatusHandler)
+		m.POST("/pay/paysum", handler.WrapPaySumHandler)
 	}
 
 }

+ 16 - 32
service/pay.go

@@ -3,10 +3,10 @@ package service
 import (
 	"context"
 	log "github.com/sirupsen/logrus"
-	"time"
 	"youngee_b_api/db"
-	"youngee_b_api/model/gorm_model"
 	"youngee_b_api/model/http_model"
+
+	"github.com/issue9/conv"
 )
 
 var Pay *pay
@@ -14,42 +14,26 @@ var Pay *pay
 type pay struct {
 }
 
-func (*pay) GetPaysum(ctx context.Context, project http_model.PaySumRequest) (*http_model.RegisterData, error) {
+func (*pay) GetPaysum(ctx context.Context, project http_model.PaySumRequest) (*http_model.PaySumResponce, error) {
 	//select * from taskinfo where project_id = project.project_id => []task
 	//map int float
 	//for t in task:
-	user := gorm_model.YounggeeUser{
-		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)
+	projectId := conv.MustInt64(project.ProjectId)
+	tasks, err := db.GetTaskList(ctx, projectId)
 	if err != nil {
-		log.Infof("[CreateEnterpriseUser] fail,err:%+v", err)
+		log.Infof("[GetPayTasklist] 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
+	}
+	payMap := make(map[int]float64)
+	PaySum := http_model.PaySumResponce{}
+	if tasks != nil {
+		for _, task := range tasks {
+			payMap[task.StrategyId] += task.AllPayment
 		}
-		res := &http_model.RegisterData{
-			EnterpriseId: *enterpriseId,
-			UserID:       *userId,
+		for k, v := range payMap {
+			ps := http_model.PaySum{k, v}
+			PaySum.PaySum = append(PaySum.PaySum, ps)
 		}
-		return res, nil
 	}
+	return &PaySum, nil
 }

+ 9 - 3
service/project.go

@@ -108,13 +108,15 @@ func (*project) Update(ctx context.Context, newProject http_model.UpdateProjectR
 	if err != nil {
 		return nil, err
 	}
+	fmt.Printf("照片:\t %+v", newProject.ProjectPhotos)
 	if newProject.ProjectPhotos != nil {
 		// 新增图片
 		projectPhotos := []gorm_model.ProjectPhoto{}
 		for _, photo := range newProject.ProjectPhotos {
 			projectPhoto := gorm_model.ProjectPhoto{
-				PhotoUrl: photo.PhotoUrl,
-				PhotoUid: photo.PhotoUid,
+				ProjectID: project.ProjectID,
+				PhotoUrl:  photo.PhotoUrl,
+				PhotoUid:  photo.PhotoUid,
 			}
 			projectPhotos = append(projectPhotos, projectPhoto)
 		}
@@ -128,8 +130,9 @@ func (*project) Update(ctx context.Context, newProject http_model.UpdateProjectR
 	if err != nil {
 		return nil, err
 	}
+	fmt.Printf("策略:\t %+v", newProject.RecruitStrategys)
 	if newProject.RecruitStrategys != nil {
-		// 新增图片
+		// 新增策略
 		RecruitStrategys := []gorm_model.RecruitStrategy{}
 		for _, Strategy := range newProject.RecruitStrategys {
 			RecruitStrategy := gorm_model.RecruitStrategy{
@@ -139,6 +142,7 @@ func (*project) Update(ctx context.Context, newProject http_model.UpdateProjectR
 				FollowersUp:   conv.MustInt64(Strategy.FollowersUp),
 				RecruitNumber: conv.MustInt64(Strategy.RecruitNumber),
 				Offer:         conv.MustInt64(Strategy.Offer),
+				ProjectID:     project.ProjectID,
 			}
 			fmt.Printf("Offer:\t %+v", Strategy.Offer)
 			RecruitStrategys = append(RecruitStrategys, RecruitStrategy)
@@ -211,7 +215,9 @@ func (*project) GetPorjectDetail(ctx context.Context, projectID int64) (*http_mo
 		ProjectDetail:   conv.MustString(project.ProjectDetail),
 		ProductID:       conv.MustString(project.ProductID),
 		EnterpriseID:    conv.MustString(project.EnterpriseID),
+		Balance:         conv.MustString(enterprise.Balance),
 		CreateAt:        project.CreatedAt,
+		UpdateAt:        project.UpdatedAt,
 		Phone:           user.Phone,
 	}
 	Strategys, err := db.GetRecruitStrategys(ctx, projectID)