Browse Source

FullSLocalList

Xingyu Xian 2 months ago
parent
commit
83a82dfd51

+ 57 - 0
db/s_local_life.go

@@ -99,3 +99,60 @@ func FindMaterialByLocalId(ctx context.Context, localId string) ([]gorm_model.Lo
 	}
 	return sProjectInfo, nil
 }
+
+// FindSLocalByLocalIdAndSupplierId 根据LocalId和SupplierId查找SLocal
+func FindSLocalByLocalIdAndSupplierId(ctx context.Context, localId string, supplierId int) (int64, error) {
+	db := GetWriteDB(ctx)
+	whereCondition := gorm_model.YounggeeSLocalLifeInfo{
+		LocalId:    localId,
+		SupplierId: supplierId,
+	}
+	var total int64
+	err := db.Debug().Model(gorm_model.YounggeeSLocalLifeInfo{}).Where(whereCondition).Count(&total).Error
+	if err != nil {
+		return 0, err
+	}
+	return total, nil
+}
+
+// GetFullSLocalLifeList 查看加入商单后的本地生活列表
+func GetFullSLocalLifeList(ctx context.Context, pageSize, pageNum int32, condition *common_model.SLocalLifeCondition) ([]*gorm_model.YounggeeSLocalLifeInfo, int64, error) {
+	db := GetReadDB(ctx)
+
+	// 根据带货任务状态过滤
+	db = db.Debug().Model(gorm_model.YounggeeSLocalLifeInfo{}).Where("task_status = 4")
+
+	// 根据Project条件过滤
+	conditionType := reflect.TypeOf(condition).Elem()
+	conditionValue := reflect.ValueOf(condition).Elem()
+	for i := 0; i < conditionType.NumField(); i++ {
+		field := conditionType.Field(i)
+		tag := field.Tag.Get("condition")
+		value := conditionValue.FieldByName(field.Name)
+		if (tag == "local_id" || tag == "local_name") && !util.IsBlank(value) {
+			db = db.Where(fmt.Sprintf("local_id like '%%%v%%' or local_name like '%%%v%%'", value.Interface(), value.Interface()))
+		} else if tag == "updated_at" && value.Interface() != "0" {
+			db = db.Where(fmt.Sprintf("updated_at like '%s%%'", value.Interface()))
+		} else if !util.IsBlank(value) && tag != "updated_at" {
+			db = db.Where(fmt.Sprintf("%s = ?", tag), value.Interface())
+		}
+	}
+
+	// 查询总数
+	var total int64
+	var fullLocals []*gorm_model.YounggeeSLocalLifeInfo
+	if err := db.Count(&total).Error; err != nil {
+		logrus.WithContext(ctx).Errorf("[GetFullProjectList] error query mysql total, err:%+v", err)
+		return nil, 0, err
+	}
+
+	// 查询该页数据
+	limit := pageSize
+	offset := pageSize * pageNum // assert pageNum start with 0
+	err := db.Order("updated_at desc").Limit(int(limit)).Offset(int(offset)).Find(&fullLocals).Error
+	if err != nil {
+		logrus.WithContext(ctx).Errorf("[GetFullProjectList] error query mysql total, err:%+v", err)
+		return nil, 0, err
+	}
+	return fullLocals, total, nil
+}

+ 7 - 7
handler/full_s_local_list.go

@@ -15,16 +15,16 @@ func WrapFullSLocalListHandler(ctx *gin.Context) {
 	baseRun(handler)
 }
 
-func newFullSLocalListHandler(ctx *gin.Context) *FullListHandler {
-	return &FullListHandler{
-		req:  http_model.NewFullListRequest(),
-		resp: http_model.NewFullListResponse(),
+func newFullSLocalListHandler(ctx *gin.Context) *FullSLocalListHandler {
+	return &FullSLocalListHandler{
+		req:  http_model.NewFullSLocalListRequest(),
+		resp: http_model.NewFullSLocalListResponse(),
 		ctx:  ctx,
 	}
 }
 
 type FullSLocalListHandler struct {
-	req  *http_model.FullListRequest
+	req  *http_model.FullSLocalListRequest
 	resp *http_model.CommonResponse
 	ctx  *gin.Context
 }
@@ -40,8 +40,8 @@ func (h *FullSLocalListHandler) getResponse() interface{} {
 }
 func (h *FullSLocalListHandler) run() {
 	// enterpriseID := middleware.GetSessionAuth(h.ctx).EnterpriseID
-	condition := pack.HttpFullLocalLifeListRequestToCondition(h.req)
-	data, err := service.LocalLife.GetFullLocalLifeList(h.ctx, h.req.PageSize, h.req.PageNum, h.req.SupplierId, condition)
+	condition := pack.HttpFullSLocalLifeListRequestToCondition(h.req)
+	data, err := service.LocalLife.GetFullSLocalLifeList(h.ctx, h.req.PageSize, h.req.PageNum, h.req.SupplierId, condition)
 	if err != nil {
 		logrus.WithContext(h.ctx).Errorf("[FullListHandler] error GetFullProjectList, err:%+v", err)
 		util.HandlerPackErrorResp(h.resp, consts.ErrorInternal, consts.DefaultToast)

+ 1 - 0
model/common_model/full_local_life_condition.go

@@ -6,6 +6,7 @@ type SLocalLifeCondition struct {
 	ContentType     int    `condition:"content_type"`       // 内容形式
 	AddToListStatus int    `condition:"add_to_list_status"` // 加入商单状态,1已加入,2未加入
 	LocalId         string `condition:"local_id"`           // 本地生活ID
+	TaskStatus      int    `condition:"task_status"`        // 任务状态
 	LocalName       string `condition:"local_name"`         // 本地生活标题
 }
 

+ 4 - 3
model/http_model/full_local_life_list.go

@@ -10,6 +10,7 @@ type FullListRequest struct {
 	AddToListStatus int    `json:"add_to_list_status"` // 加入商单状态,1已加
 	LocalId         string `json:"local_id"`           // 本地生活ID
 	LocalName       string `json:"local_name"`         // 本地生活标题
+	TaskStatus      int    `json:"task_status"`        // 任务状态
 }
 
 type FullPreview struct {
@@ -25,9 +26,9 @@ type FullPreview struct {
 	ServiceChargeRate  float64                `json:"service_charge_rate"`  // 服务费率
 	ServiceCharge      float64                `json:"service_charge"`       // 任务总服务费
 	RecruitDdl         string                 `json:"recruit_ddl"`          // 招募截至时间
-	ProductPhotoUrl    string                 `json:"product_photo_url"`    // 商品主图URL
-	ProductPhotoSymbol int64                  `json:"product_photo_symbol"` // 标志位
-	ProductPhotoUid    string                 `json:"product_photo_uid"`    // uid
+	ProductPhotoUrl    string                 `json:"product_photo_url"`    // 门店主图URL
+	ProductPhotoSymbol int64                  `json:"product_photo_symbol"` // 门店标志位
+	ProductPhotoUid    string                 `json:"product_photo_uid"`    // 门店uid
 	StoreName          string                 `json:"store_name"`           // 门店名称
 	ProductPrice       float64                `json:"product_price"`        // 商品售价
 	StoreId            int                    `json:"store_id"`             // 门店ID

+ 1 - 0
model/http_model/s_local_life_list.go

@@ -5,6 +5,7 @@ type FullSLocalListRequest struct {
 	PageNum         int32  `json:"page_num"`
 	SupplierId      int    `json:"supplier_id"`        // 服务商ID
 	LocalPlatform   int    `json:"local_platform"`     // 本地生活平台
+	TaskStatus      int    `json:"task_status"`        // 任务状态
 	TaskForm        int    `json:"task_form"`          // 任务形式,1-2分别代表线下探店,素材分发
 	ContentType     int    `json:"content_type"`       // 内容形式,1代表图文,2代表视频
 	AddToListStatus int    `json:"add_to_list_status"` // 加入商单状态,1已加

+ 13 - 0
pack/full_local_life_list.go

@@ -7,6 +7,19 @@ import (
 
 func HttpFullLocalLifeListRequestToCondition(req *http_model.FullListRequest) *common_model.SLocalLifeCondition {
 	return &common_model.SLocalLifeCondition{
+		TaskStatus:      req.TaskStatus,      // 任务状态
+		LocalPlatform:   req.LocalPlatform,   // 本地生活平台
+		TaskForm:        req.TaskForm,        // 任务形式,1-2分别代表线下探店,素材分发
+		ContentType:     req.ContentType,     // 内容形式
+		AddToListStatus: req.AddToListStatus, // 加入商单状态,1已加入,2未加入
+		LocalId:         req.LocalId,         // 本地生活ID
+		LocalName:       req.LocalName,       // 本地生活标题
+	}
+}
+
+func HttpFullSLocalLifeListRequestToCondition(req *http_model.FullSLocalListRequest) *common_model.SLocalLifeCondition {
+	return &common_model.SLocalLifeCondition{
+		TaskStatus:      req.TaskStatus,      // 任务状态
 		LocalPlatform:   req.LocalPlatform,   // 本地生活平台
 		TaskForm:        req.TaskForm,        // 任务形式,1-2分别代表线下探店,素材分发
 		ContentType:     req.ContentType,     // 内容形式

+ 85 - 20
service/local_life.go

@@ -3,6 +3,7 @@ package service
 import (
 	"context"
 	"fmt"
+	"github.com/issue9/conv"
 	"github.com/sirupsen/logrus"
 	"youngee_b_api/db"
 	"youngee_b_api/model/common_model"
@@ -39,21 +40,20 @@ func (*localLife) GetFullLocalLifeList(ctx context.Context, pageSize, pageNum in
 	}
 
 	// 2. 查询本地生活补充信息:门店信息,招募策略
-	for _, project := range fullLocalData.FullPreview {
+	for _, local := range fullLocalData.FullPreview {
 
 		// 2.1. 门店信息
-		storeInfo, productErr := db.FindStoreById(ctx, project.StoreId)
+		storeInfo, productErr := db.FindStoreById(ctx, local.StoreId)
 		if productErr != nil {
 			return nil, productErr
 		}
 		if storeInfo != nil {
-			project.StoreId = storeInfo.StoreId
-			// project.ProductPrice = storeInfo.S
-			project.StoreName = storeInfo.StoreName
+			local.StoreId = storeInfo.StoreId
+			local.StoreName = storeInfo.StoreName
 		}
 
 		// 2.2. 门店图片信息
-		productPhotoInfo, productPhotoErr := db.GetStorePhotoByStoreID(ctx, project.StoreId)
+		productPhotoInfo, productPhotoErr := db.GetStorePhotoByStoreID(ctx, local.StoreId)
 		if productPhotoErr != nil {
 			return nil, productPhotoErr
 		}
@@ -61,15 +61,15 @@ func (*localLife) GetFullLocalLifeList(ctx context.Context, pageSize, pageNum in
 			for _, photo := range productPhotoInfo {
 				fmt.Println(photo)
 				if photo.Symbol == 1 {
-					project.ProductPhotoSymbol = 1
-					project.ProductPhotoUrl = photo.PhotoUrl
-					project.ProductPhotoUid = photo.PhotoUid
+					local.ProductPhotoSymbol = 1
+					local.ProductPhotoUrl = photo.PhotoUrl
+					local.ProductPhotoUid = photo.PhotoUid
 				}
 			}
 		}
 
 		// 2.3. 招募策略信息
-		recruitStrategyInfo, recruitErr := db.GetRecruitStrategyByProjectId(ctx, project.LocalId)
+		recruitStrategyInfo, recruitErr := db.GetRecruitStrategyByProjectId(ctx, local.LocalId)
 		if recruitErr != nil {
 			return nil, recruitErr
 		}
@@ -80,20 +80,85 @@ func (*localLife) GetFullLocalLifeList(ctx context.Context, pageSize, pageNum in
 				recruitStrategy.StrategyId = strategy.StrategyID
 				recruitStrategy.FeeForm = strategy.FeeForm
 				recruitStrategy.RecruitNumber = strategy.RecruitNumber
-				project.RecruitStrategy = append(project.RecruitStrategy, recruitStrategy)
+				local.RecruitStrategy = append(local.RecruitStrategy, recruitStrategy)
 			}
 		}
 
 		// 2.4. 判断是否加入商单
-		//sProjectCount, sProjectErr := db.UpdateSProjectByProjectIdAndSupplierId(ctx, project.LocalId, supplierId)
-		//if sProjectErr != nil {
-		//	return nil, sProjectErr
-		//}
-		//if sProjectCount > 0 {
-		//	project.AddToListStatus = 1
-		//} else {
-		//	project.AddToListStatus = 2
-		//}
+		sProjectCount, sProjectErr := db.FindSLocalByLocalIdAndSupplierId(ctx, local.LocalId, supplierId)
+		if sProjectErr != nil {
+			return nil, sProjectErr
+		}
+		if sProjectCount > 0 {
+			local.AddToListStatus = 1
+		} else {
+			local.AddToListStatus = 2
+		}
+	}
+	return fullLocalData, nil
+}
+
+func (*localLife) GetFullSLocalLifeList(ctx context.Context, pageSize, pageNum int32, supplierId int, condition *common_model.SLocalLifeCondition) (*http_model.FullSLocalListData, error) {
+
+	// 1. 查询本地生活任务基本信息
+	fullLocals, total, err := db.GetFullSLocalLifeList(ctx, pageSize, pageNum, condition)
+	if err != nil {
+		logrus.WithContext(ctx).Errorf("[fullLocals service] call GetFullSLocalLifeList error,err:%+v", err)
+		return nil, err
+	}
+	var fullLocalData *http_model.FullSLocalListData
+	fullLocalData = &http_model.FullSLocalListData{}
+	fullLocalData.Total = total
+	for _, fullLocal := range fullLocals {
+		var fullLocalPreview *http_model.FullSLocalPreview
+		fullLocalPreview = &http_model.FullSLocalPreview{}
+		fullLocalPreview.LocalId = fullLocal.LocalId
+		fullLocalPreview.TaskStatus = fullLocal.TaskStatus
+		fullLocalPreview.LocalPlatform = fullLocal.LocalPlatform
+		fullLocalPreview.TaskForm = fullLocal.TaskForm
+		fullLocalPreview.LocalType = fullLocal.LocalType
+		fullLocalPreview.LocalContentType = fullLocal.ContentType
+		fullLocalPreview.SupplierId = supplierId
+		fullLocalPreview.SubAccountId = fullLocal.SubAccountId
+		fullLocalPreview.OperatorType = fullLocal.OperatorType
+		fullLocalPreview.CreateTime = conv.MustString(fullLocal.CreateTime)
+		fullLocalPreview.ServiceCharge = fullLocal.ServiceCharge
+		fullLocalPreview.ServiceChargeActual = fullLocal.ServiceChargeActual
+		fullLocalPreview.ApplyNum = fullLocal.ApplyNum
+		fullLocalPreview.RecruitNum = fullLocal.RecruitNum
+		fullLocalPreview.SettleNum = fullLocal.SettleNum
+		fullLocalData.FullSLocalPreview = append(fullLocalData.FullSLocalPreview, fullLocalPreview)
+	}
+
+	// 2. 查询本地生活补充信息:门店信息,招募策略
+	for _, local := range fullLocalData.FullSLocalPreview {
+
+		// 2.1. 门店信息
+		storeInfo, productErr := db.FindStoreById(ctx, local.StoreId)
+		if productErr != nil {
+			return nil, productErr
+		}
+		if storeInfo != nil {
+			local.StoreId = storeInfo.StoreId
+			local.StoreName = storeInfo.StoreName
+		}
+
+		// 2.2. 门店图片信息
+		productPhotoInfo, productPhotoErr := db.GetStorePhotoByStoreID(ctx, local.StoreId)
+		if productPhotoErr != nil {
+			return nil, productPhotoErr
+		}
+		if productPhotoInfo != nil {
+			for _, photo := range productPhotoInfo {
+				fmt.Println(photo)
+				if photo.Symbol == 1 {
+					local.ProductPhotoSymbol = 1
+					local.ProductPhotoUrl = photo.PhotoUrl
+					local.ProductPhotoUid = photo.PhotoUid
+				}
+			}
+		}
+
 	}
 	return fullLocalData, nil
 }