Procházet zdrojové kódy

商品信息更新

yuliang1112 před 2 roky
rodič
revize
b37ab47ab7

+ 9 - 0
db/project_photo.go

@@ -21,3 +21,12 @@ func DeleteProjectPhotoByProjecttID(ctx context.Context, productID int64) error
 	}
 	return nil
 }
+
+func DeletePhotoUrl(ctx context.Context, photoUrl string) error {
+	db := GetReadDB(ctx)
+	err := db.Where("photo_url = ?", photoUrl).Delete(&gorm_model.YounggeeProductPhoto{}).Error
+	if err != nil {
+		return err
+	}
+	return nil
+}

+ 55 - 0
handler/deletePhotoUrl.go

@@ -0,0 +1,55 @@
+package handler
+
+import (
+	"github.com/gin-gonic/gin"
+	"github.com/sirupsen/logrus"
+	"youngee_b_api/consts"
+	"youngee_b_api/db"
+	"youngee_b_api/model/http_model"
+	"youngee_b_api/util"
+)
+
+func WrapDeletePhotoUrlHandler(ctx *gin.Context) {
+	handler := newDeletePhotoUrl(ctx)
+	baseRun(handler)
+}
+
+type DeletePhotoUrl struct {
+	req  *http_model.DeletePhotoUrlRequest
+	resp *http_model.CommonResponse
+	ctx  *gin.Context
+}
+
+func (d DeletePhotoUrl) getContext() *gin.Context {
+	return d.ctx
+}
+
+func (d DeletePhotoUrl) getResponse() interface{} {
+	return d.resp
+}
+
+func (d DeletePhotoUrl) getRequest() interface{} {
+	return d.req
+}
+
+func (d DeletePhotoUrl) run() {
+	err := db.DeletePhotoUrl(d.ctx, d.req.PhotoUrl)
+	if err != nil {
+		logrus.WithContext(d.ctx).Errorf("[DeletePhotoUrl] error DeletePhotoUrl, err:%+v", err)
+		util.HandlerPackErrorResp(d.resp, consts.ErrorInternal, consts.DefaultToast)
+		return
+	}
+	d.resp.Message = "图片删除成功"
+}
+
+func (d DeletePhotoUrl) checkParam() error {
+	return nil
+}
+
+func newDeletePhotoUrl(ctx *gin.Context) *DeletePhotoUrl {
+	return &DeletePhotoUrl{
+		req:  http_model.NewDeletePhotoUrlRequest(),
+		resp: http_model.NewDeletePhotoUrlResponse(),
+		ctx:  ctx,
+	}
+}

+ 3 - 0
handler/project_create.go

@@ -34,12 +34,15 @@ type CreateProjectHandler struct {
 func (h *CreateProjectHandler) getRequest() interface{} {
 	return h.req
 }
+
 func (h *CreateProjectHandler) getContext() *gin.Context {
 	return h.ctx
 }
+
 func (h *CreateProjectHandler) getResponse() interface{} {
 	return h.resp
 }
+
 func (h *CreateProjectHandler) run() {
 	data := http_model.CreateProjectRequest{}
 	data = *h.req

+ 3 - 0
model/gorm_model/project.go

@@ -35,6 +35,9 @@ type ProjectInfo struct {
 	FinishAt          *time.Time `gorm:"column:finish_at"`                             // 结案时间
 	EstimatedCost     float64    `gorm:"column:estimated_cost"`                        // 预估成本
 	IsRead            int64      `gorm:"column:is_read"`                               // 是否已读
+	SettlementAmount  float64    `gorm:"column:settlement_amount"`                     // 结算金额
+	ProductSnap       string     `gorm:"column:product_snap"`                          // 商品信息快照
+	ProductPhotoSnap  string     `gorm:"column:product_photo_snap"`                    // 商品图片快照
 }
 
 func (m *ProjectInfo) TableName() string {

+ 14 - 0
model/http_model/DeletePhotoUrlRequest.go

@@ -0,0 +1,14 @@
+package http_model
+
+type DeletePhotoUrlRequest struct {
+	PhotoUrl string `json:"photo_url"`
+}
+
+func NewDeletePhotoUrlRequest() *DeletePhotoUrlRequest {
+	return new(DeletePhotoUrlRequest)
+}
+
+func NewDeletePhotoUrlResponse() *CommonResponse {
+	resp := new(CommonResponse)
+	return resp
+}

+ 5 - 5
model/http_model/product_find.go

@@ -12,11 +12,11 @@ type ProductPhoto struct {
 
 type FindProductData struct {
 	ProductID     int64          `json:"product_id"`
-	ProductName   string         `json:"product_name"`  // 商品名称
-	ProductType   int64          `json:"product_type"`  // 商品类型
-	ShopAddress   string         `json:"shop_address"`  // 店铺地址,商品类型为线下品牌时需填写
-	ProductPrice  float64          `json:"product_price"` // 商品价值
-	ProductDetail string         `json:"product_detail"`
+	ProductName   string         `json:"product_name"`   // 商品名称
+	ProductType   int64          `json:"product_type"`   // 商品类型
+	ShopAddress   string         `json:"shop_address"`   // 店铺地址,商品类型为线下品牌时需填写
+	ProductPrice  float64        `json:"product_price"`  // 商品价值
+	ProductDetail string         `json:"product_detail"` // 商品详情
 	ProductPhotos []ProductPhoto `json:"product_photos"` // 商品图片列表
 	ProductUrl    string         `json:"product_url"`    // 商品链接,可为电商网址、公司官网、大众点评的店铺地址等可以说明商品信息或者品牌信息的线上地址;
 	EnterpriseID  int64          `json:"enterprise_id"`  // 所属企业id

+ 25 - 23
model/http_model/project_show.go

@@ -23,29 +23,31 @@ type ShowRecruitStrategy struct {
 }
 
 type ShowProjectData struct {
-	ProjectName      string                `json:"project_name"`      // 项目名称
-	ProjectStatus    string                `json:"project_status"`    // 项目状态,1-7分别代表创建中、待审核、招募中、待支付、失效、执行中、已结案
-	ProjectType      string                `json:"project_type"`      // 项目类型,1代表全流程项目,2代表专项项目
-	ProjectPlatform  string                `json:"project_platform"`  // 项目平台,1-7分别代表红book、抖音、微博、快手、b站、大众点评、知乎
-	ProjectForm      string                `json:"project_form"`      // 项目形式,1-4分别代表实体商品寄拍、虚拟产品测评、线下探店打卡、素材微原创
-	TalentType       string                `json:"talent_type"`       // 达人类型
-	RecruitDdl       time.Time             `json:"recruit_ddl"`       // 招募截止时间
-	ContentType      string                `json:"content_type"`      // 内容形式,1代表图文,2代表视频
-	ProjectDetail    string                `json:"project_detail"`    // 项目详情
-	RecruitStrategys []ShowRecruitStrategy `json:"recruit_strategys"` // 定价策略
-	ProjectPhotos    []ShowProjectPhoto    `json:"project_photos"`    // 项目图片
-	ProductID        string                `json:"product_id"`        // 关联商品id
-	EstimatedCost    string                `json:"estimated_cost"`
-	EnterpriseID     string                `json:"enterprise_id"` // 企业id
-	Balance          string                `json:"balance"`       // 企业余额
-	ProjectID        string                `json:"project_id"`    // 项目id
-	FailReason       string                `json:"fail_reason"`   // 失效原因
-	Phone            string                `json:"phone"`         // 联系方式
-	CreateAt         time.Time             `json:"create_at"`     // 创建时间
-	UpdateAt         time.Time             `json:"update_at"`     // 更新时间
-	PassAt           time.Time             `json:"pass_at"`       // 审核通过时间
-	FinishAt         time.Time             `json:"finish_at"`     // 结案时间
-	PayAt            time.Time             `json:"pay_at"`        // 支付时间
+	ProjectName      string                `json:"project_name"`       // 项目名称
+	ProjectStatus    string                `json:"project_status"`     // 项目状态,1-7分别代表创建中、待审核、招募中、待支付、失效、执行中、已结案
+	ProjectType      string                `json:"project_type"`       // 项目类型,1代表全流程项目,2代表专项项目
+	ProjectPlatform  string                `json:"project_platform"`   // 项目平台,1-7分别代表红book、抖音、微博、快手、b站、大众点评、知乎
+	ProjectForm      string                `json:"project_form"`       // 项目形式,1-4分别代表实体商品寄拍、虚拟产品测评、线下探店打卡、素材微原创
+	TalentType       string                `json:"talent_type"`        // 达人类型
+	RecruitDdl       time.Time             `json:"recruit_ddl"`        // 招募截止时间
+	ContentType      string                `json:"content_type"`       // 内容形式,1代表图文,2代表视频
+	ProjectDetail    string                `json:"project_detail"`     // 项目详情
+	RecruitStrategys []ShowRecruitStrategy `json:"recruit_strategys"`  // 定价策略
+	ProjectPhotos    []ShowProjectPhoto    `json:"project_photos"`     // 项目图片
+	ProductID        string                `json:"product_id"`         // 关联商品id
+	ProductInfo      string                `json:"product_info"`       // 商品信息
+	ProductPhotoInfo string                `json:"product_photo_info"` // 商品图片
+	EstimatedCost    string                `json:"estimated_cost"`     // 预估成本
+	EnterpriseID     string                `json:"enterprise_id"`      // 企业id
+	Balance          string                `json:"balance"`            // 企业余额
+	ProjectID        string                `json:"project_id"`         // 项目id
+	FailReason       string                `json:"fail_reason"`        // 失效原因
+	Phone            string                `json:"phone"`              // 联系方式
+	CreateAt         time.Time             `json:"create_at"`          // 创建时间
+	UpdateAt         time.Time             `json:"update_at"`          // 更新时间
+	PassAt           time.Time             `json:"pass_at"`            // 审核通过时间
+	FinishAt         time.Time             `json:"finish_at"`          // 结案时间
+	PayAt            time.Time             `json:"pay_at"`             // 支付时间
 }
 
 type ShowProjectRequest struct {

+ 1 - 0
route/init.go

@@ -123,5 +123,6 @@ func InitRoute(r *gin.Engine) {
 		m.POST("/workspace/ddlproject", handler.WrapWorkspaceDDLprojectHandler)          // 工作台项目统计
 
 		m.POST("/project/recruit/getservicecharge", handler.WrapGetServiceChargeHandler) // 获取产品置换服务费
+		m.POST("/product/deletePhotoUrl", handler.WrapDeletePhotoUrlHandler)             // 在数据库中删除图片url
 	}
 }

+ 65 - 57
service/project.go

@@ -2,6 +2,7 @@ package service
 
 import (
 	"context"
+	"encoding/json"
 	"fmt"
 	"strconv"
 	"strings"
@@ -31,6 +32,10 @@ func (*project) Create(ctx context.Context, newProject http_model.CreateProjectR
 	if err != nil {
 		return nil, err
 	}
+	productPhotos, err := db.GetProductPhotoByProductID(ctx, newProject.ProductID)
+	productInfoToJson, _ := json.Marshal(product)
+	productPhotosToJson, _ := json.Marshal(productPhotos)
+	fmt.Println("productPhotosToJson:", productPhotosToJson)
 	AutoTaskID, err := db.GetLastAutoTaskID()
 	if err != nil {
 		return nil, err
@@ -60,44 +65,48 @@ func (*project) Create(ctx context.Context, newProject http_model.CreateProjectR
 		}
 	}
 	feeFroms := strings.Join(feeFrom, ",")
-	fmt.Printf("创建项目new %+v", newProject)
+	//fmt.Printf("创建项目new %+v", newProject)
 	RecruitDdl, _ := time.ParseInLocation("2006-01-02 15:04:05", newProject.RecruitDdl, time.Local)
 	projectInfo := gorm_model.ProjectInfo{}
 	if newProject.ProjectType == int64(1) {
 		projectInfo = gorm_model.ProjectInfo{
-			ProjectName:     projectName,
-			ProjectStatus:   1,
-			ProjectType:     newProject.ProjectType,
-			TalentType:      newProject.TalentType,
-			ProjectPlatform: newProject.ProjectPlatform,
-			ProjectForm:     newProject.ProjectForm,
-			RecruitDdl:      &RecruitDdl,
-			ProjectDetail:   newProject.ProjectDetail,
-			ContentType:     newProject.ContentType,
-			EnterpriseID:    enterpriseID,
-			ProductID:       newProject.ProductID,
-			FeeForm:         feeFroms,
-			AutoTaskID:      conv.MustInt64(AutoTaskID),
-			AutoDefaultID:   conv.MustInt64(AutoDefaultID),
-			EstimatedCost:   ECost,
-			IsRead:          0,
+			ProjectName:      projectName,
+			ProjectStatus:    1,
+			ProjectType:      newProject.ProjectType,
+			TalentType:       newProject.TalentType,
+			ProjectPlatform:  newProject.ProjectPlatform,
+			ProjectForm:      newProject.ProjectForm,
+			RecruitDdl:       &RecruitDdl,
+			ProjectDetail:    newProject.ProjectDetail,
+			ContentType:      newProject.ContentType,
+			EnterpriseID:     enterpriseID,
+			ProductID:        newProject.ProductID,
+			FeeForm:          feeFroms,
+			AutoTaskID:       conv.MustInt64(AutoTaskID),
+			AutoDefaultID:    conv.MustInt64(AutoDefaultID),
+			EstimatedCost:    ECost,
+			IsRead:           0,
+			ProductSnap:      string(productInfoToJson),
+			ProductPhotoSnap: string(productPhotosToJson),
 		}
 	} else {
 		projectInfo = gorm_model.ProjectInfo{
-			ProjectName:     projectName,
-			ProjectStatus:   1,
-			ProjectType:     newProject.ProjectType,
-			TalentType:      "[]",
-			ProjectPlatform: newProject.ProjectPlatform,
-			ProjectForm:     newProject.ProjectForm,
-			ProjectDetail:   newProject.ProjectDetail,
-			ContentType:     newProject.ContentType,
-			EnterpriseID:    enterpriseID,
-			ProductID:       newProject.ProductID,
-			FeeForm:         feeFroms,
-			AutoTaskID:      conv.MustInt64(AutoTaskID),
-			AutoDefaultID:   conv.MustInt64(AutoDefaultID),
-			EstimatedCost:   ECost,
+			ProjectName:      projectName,
+			ProjectStatus:    1,
+			ProjectType:      newProject.ProjectType,
+			TalentType:       "[]",
+			ProjectPlatform:  newProject.ProjectPlatform,
+			ProjectForm:      newProject.ProjectForm,
+			ProjectDetail:    newProject.ProjectDetail,
+			ContentType:      newProject.ContentType,
+			EnterpriseID:     enterpriseID,
+			ProductID:        newProject.ProductID,
+			FeeForm:          feeFroms,
+			AutoTaskID:       conv.MustInt64(AutoTaskID),
+			AutoDefaultID:    conv.MustInt64(AutoDefaultID),
+			EstimatedCost:    ECost,
+			ProductSnap:      string(productInfoToJson),
+			ProductPhotoSnap: string(productPhotosToJson),
 		}
 	}
 	// db create ProjectInfo
@@ -156,11 +165,11 @@ func (*project) Create(ctx context.Context, newProject http_model.CreateProjectR
 	res := &http_model.CreateProjectData{
 		ProjectID: *projectID,
 	}
-	fmt.Printf("%+v", res)
+	//fmt.Printf("%+v", res)
 	return res, nil
 }
 func (*project) Update(ctx context.Context, newProject http_model.UpdateProjectRequest, enterpriseID int64) (*http_model.UpdateProjectData, error) {
-	fmt.Println("RecruitDdl:", newProject.RecruitDdl)
+	//fmt.Println("RecruitDdl:", newProject.RecruitDdl)
 	RecruitDdl, _ := time.ParseInLocation("2006-01-02 15:04:05", newProject.RecruitDdl, time.Local)
 	oldProject, err3 := db.GetProjectDetail(ctx, conv.MustInt64(newProject.ProjectID))
 	if err3 != nil {
@@ -336,7 +345,6 @@ func (*project) GetPorjectDetail(ctx context.Context, projectID int64) (*http_mo
 		return nil, err
 	}
 	enterprise, err := db.GetEnterpriseByEnterpriseID(ctx, project.EnterpriseID)
-	// fmt.Println("%+v", enterprise.UserID)
 	if err != nil {
 		logrus.WithContext(ctx).Errorf("[project service] call GetEnterpriseByEnterpriseID error,err:%+v", err)
 		return nil, err
@@ -346,30 +354,30 @@ func (*project) GetPorjectDetail(ctx context.Context, projectID int64) (*http_mo
 		logrus.WithContext(ctx).Errorf("[project service] call GetUserByID error,err:%+v", err)
 		return nil, err
 	}
-	// fmt.Println("%+v", user.Phone)
-	//var RecruitStrategys []http_model.ShowRecruitStrategy
 	ProjectDetail := http_model.ShowProjectData{
-		ProjectID:       conv.MustString(project.ProjectID),
-		ProjectName:     conv.MustString(project.ProjectName),
-		ProjectStatus:   conv.MustString(project.ProjectStatus),
-		ProjectType:     conv.MustString(project.ProjectType),
-		ProjectPlatform: conv.MustString(project.ProjectPlatform),
-		ProjectForm:     conv.MustString(project.ProjectForm),
-		TalentType:      conv.MustString(project.TalentType),
-		RecruitDdl:      util.GetTimePoionter(project.RecruitDdl),
-		ContentType:     conv.MustString(project.ContentType),
-		ProjectDetail:   conv.MustString(project.ProjectDetail),
-		ProductID:       conv.MustString(project.ProductID),
-		EnterpriseID:    conv.MustString(project.EnterpriseID),
-		Balance:         conv.MustString(enterprise.Balance),
-		EstimatedCost:   conv.MustString(project.EstimatedCost),
-		FailReason:      conv.MustString(project.FailReason),
-		CreateAt:        util.GetTimePoionter(project.CreatedAt),
-		UpdateAt:        util.GetTimePoionter(project.UpdatedAt),
-		Phone:           user.Phone,
-		FinishAt:        util.GetTimePoionter(project.FinishAt),
-		PassAt:          util.GetTimePoionter(project.PassAt),
-		PayAt:           util.GetTimePoionter(project.PayAt),
+		ProjectID:        conv.MustString(project.ProjectID),
+		ProjectName:      conv.MustString(project.ProjectName),
+		ProjectStatus:    conv.MustString(project.ProjectStatus),
+		ProjectType:      conv.MustString(project.ProjectType),
+		ProjectPlatform:  conv.MustString(project.ProjectPlatform),
+		ProjectForm:      conv.MustString(project.ProjectForm),
+		TalentType:       conv.MustString(project.TalentType),
+		RecruitDdl:       util.GetTimePoionter(project.RecruitDdl),
+		ContentType:      conv.MustString(project.ContentType),
+		ProjectDetail:    conv.MustString(project.ProjectDetail),
+		ProductID:        conv.MustString(project.ProductID),
+		EnterpriseID:     conv.MustString(project.EnterpriseID),
+		Balance:          conv.MustString(enterprise.Balance),
+		EstimatedCost:    conv.MustString(project.EstimatedCost),
+		FailReason:       conv.MustString(project.FailReason),
+		CreateAt:         util.GetTimePoionter(project.CreatedAt),
+		UpdateAt:         util.GetTimePoionter(project.UpdatedAt),
+		Phone:            user.Phone,
+		FinishAt:         util.GetTimePoionter(project.FinishAt),
+		PassAt:           util.GetTimePoionter(project.PassAt),
+		PayAt:            util.GetTimePoionter(project.PayAt),
+		ProductInfo:      conv.MustString(project.ProductSnap),
+		ProductPhotoInfo: conv.MustString(project.ProductPhotoSnap),
 	}
 	Strategys, err := db.GetRecruitStrategys(ctx, projectID)
 	fmt.Println("招募策略:", Strategys)