123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301 |
- package service
- import (
- "context"
- "fmt"
- "github.com/issue9/conv"
- "github.com/sirupsen/logrus"
- "youngee_b_api/db"
- "youngee_b_api/model/common_model"
- "youngee_b_api/model/http_model"
- )
- var LocalLife *localLife
- type localLife struct {
- }
- func (*localLife) GetFullLocalLifeList(ctx context.Context, pageSize, pageNum int32, supplierId int, condition *common_model.SLocalLifeCondition) (*http_model.FullListData, error) {
- // 1. 查询本地生活任务基本信息
- fullLocals, total, err := db.GetFullLocalLifeList(ctx, pageSize, pageNum, condition)
- if err != nil {
- logrus.WithContext(ctx).Errorf("[fullLocals service] call GetFullLocalLifeList error,err:%+v", err)
- return nil, err
- }
- var fullLocalData *http_model.FullListData
- fullLocalData = &http_model.FullListData{}
- fullLocalData.Total = total
- for _, fullLocal := range fullLocals {
- var fullLocalPreview *http_model.FullPreview
- fullLocalPreview = &http_model.FullPreview{}
- fullLocalPreview.LocalId = fullLocal.LocalId
- fullLocalPreview.LocalName = fullLocal.LocalName
- fullLocalPreview.TaskStatus = fullLocal.TaskStatus
- fullLocalPreview.LocalPlatform = fullLocal.LocalPlatform
- fullLocalPreview.TaskForm = fullLocal.TaskForm
- fullLocalPreview.LocalType = fullLocal.LocalType
- fullLocalPreview.LocalContentType = fullLocal.ContentType
- fullLocalData.FullPreview = append(fullLocalData.FullPreview, fullLocalPreview)
- }
- // 2. 查询本地生活补充信息:门店信息,招募策略
- for _, local := range fullLocalData.FullPreview {
- // 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
- }
- }
- }
- // 2.3. 招募策略信息
- recruitStrategyInfo, recruitErr := db.GetRecruitStrategyByProjectId(ctx, local.LocalId)
- if recruitErr != nil {
- return nil, recruitErr
- }
- if recruitStrategyInfo != nil {
- for _, strategy := range recruitStrategyInfo {
- var recruitStrategy *http_model.EasyRecruitStrategy
- recruitStrategy = &http_model.EasyRecruitStrategy{}
- recruitStrategy.StrategyId = strategy.StrategyID
- recruitStrategy.FeeForm = strategy.FeeForm
- recruitStrategy.RecruitNumber = strategy.RecruitNumber
- local.RecruitStrategy = append(local.RecruitStrategy, recruitStrategy)
- }
- }
- // 2.4. 判断是否加入商单
- fmt.Println(local.LocalId)
- 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
- }
- // GetSpecialLocalLifeList 商单广场-定向本地生活
- func (*localLife) GetSpecialLocalLifeList(ctx context.Context, pageSize, pageNum int32, condition *common_model.SSpecialLocalLifeCondition) (*http_model.SpecialLocalListData, error) {
- // 1. 查询本地生活任务基本信息
- specialLocals, total, err := db.GetSpecialLocalLifeList(ctx, pageSize, pageNum, condition)
- if err != nil {
- logrus.WithContext(ctx).Errorf("[fullLocals service] call GetFullLocalLifeList error,err:%+v", err)
- return nil, err
- }
- var specialLocalData *http_model.SpecialLocalListData
- specialLocalData = &http_model.SpecialLocalListData{}
- specialLocalData.Total = total
- for _, specialLocal := range specialLocals {
- var specialLocalPreview *http_model.SpecialLocalPreview
- specialLocalPreview = &http_model.SpecialLocalPreview{}
- specialLocalPreview.LocalId = specialLocal.LocalId
- specialLocalPreview.LocalName = specialLocal.LocalName
- specialLocalPreview.TaskStatus = specialLocal.TaskStatus
- specialLocalPreview.LocalPlatform = specialLocal.LocalPlatform
- specialLocalPreview.TaskForm = specialLocal.TaskForm
- specialLocalPreview.LocalType = specialLocal.LocalType
- specialLocalPreview.LocalContentType = specialLocal.ContentType
- specialLocalPreview.SLocalStatus = specialLocal.SLocalStatus
- specialLocalData.SpecialLocalPreview = append(specialLocalData.SpecialLocalPreview, specialLocalPreview)
- }
- // 2. 查询本地生活补充信息:门店信息,招募策略
- for _, local := range specialLocalData.SpecialLocalPreview {
- // 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
- }
- }
- }
- // 2.3. 招募策略信息
- recruitStrategyInfo, recruitErr := db.GetRecruitStrategyByProjectId(ctx, local.LocalId)
- if recruitErr != nil {
- return nil, recruitErr
- }
- if recruitStrategyInfo != nil {
- for _, strategy := range recruitStrategyInfo {
- var recruitStrategy *http_model.EasyRecruitStrategy
- recruitStrategy = &http_model.EasyRecruitStrategy{}
- recruitStrategy.StrategyId = strategy.StrategyID
- recruitStrategy.FeeForm = strategy.FeeForm
- recruitStrategy.RecruitNumber = strategy.RecruitNumber
- local.RecruitStrategy = append(local.RecruitStrategy, recruitStrategy)
- }
- }
- // 2.4. 原定向本地生活任务信息
- localInfo, localErr := db.GetLocalLifeDetail(ctx, local.LocalId)
- if localErr != nil {
- return nil, localErr
- }
- if localInfo != nil {
- local.Tools = localInfo.Tools
- }
- }
- return specialLocalData, nil
- }
- // ShowLocalLife 商单广场-本地生活详情
- func (*localLife) ShowLocalLife(ctx context.Context, req *http_model.ShowLocalRequest) (*http_model.ShowLocalData, error) {
- var localInfo *http_model.ShowLocalData
- localInfo = &http_model.ShowLocalData{}
- // 1. 查询系统信息
- localData, localErr := db.GetLocalLifeDetail(ctx, req.LocalId)
- if localErr != nil {
- return nil, localErr
- }
- if localData != nil {
- localInfo.LocalId = localData.LocalId
- localInfo.LocalPlatform = localData.LocalPlatform
- localInfo.TaskStatus = localData.TaskStatus
- localInfo.EnterpriseId = localData.EnterpriseId
- localInfo.ServiceChargeRate = localData.ServiceChargeRate
- localInfo.EstimatedCost = localData.EstimatedCost
- localInfo.CreateAt = conv.MustString(localData.CreatedAt)
- // 2. 关联主体
- // 2.1. 门店信息
- storeInfo, storeErr := db.FindStoreById(ctx, localData.StoreId)
- if storeErr != nil {
- return nil, storeErr
- }
- if storeInfo != nil {
- localInfo.StoreId = storeInfo.StoreId
- localInfo.StoreName = storeInfo.StoreName
- localInfo.StoreCategory = storeInfo.StoreCategory
- localInfo.StoreRelatedAt = conv.MustString(localData.StoreRelatedAt)
- // 2.2. 门店图片信息
- storePhotoInfo, storePhotoErr := db.GetStorePhotoByStoreID(ctx, localData.StoreId)
- if storePhotoErr != nil {
- return nil, storePhotoErr
- }
- if storePhotoInfo != nil {
- for _, photo := range storePhotoInfo {
- if photo.Symbol == 1 {
- localInfo.StoreMainPhotoSymbol = 1
- localInfo.StoreMainPhotoUrl = photo.PhotoUrl
- localInfo.StoreMainPhotoUid = photo.PhotoUid
- }
- }
- }
- }
- // 2.3. 团购信息
- teamInfo, teamErr := db.FindTeamById(ctx, localData.StoreId)
- if teamErr != nil {
- return nil, teamErr
- }
- if teamInfo != nil {
- localInfo.TeamBuyingId = teamInfo.StoreId
- localInfo.TeamBuyingName = teamInfo.TeamBuyingName
- localInfo.TeamBuyingCategory = teamInfo.TeamBuyingCategory
- localInfo.TeamBuyingRelatedAt = conv.MustString(localData.TeamBuyingRelatedAt)
- // 2.4. 团购图片信息
- teamPhotoInfo, teamPhotoErr := db.GetTeamPhotoByStoreID(ctx, localData.StoreId)
- if teamPhotoErr != nil {
- return nil, teamPhotoErr
- }
- if teamPhotoInfo != nil {
- for _, photo := range teamPhotoInfo {
- if photo.Symbol == 1 {
- localInfo.TeamMainPhotoSymbol = 1
- localInfo.TeamMainPhotoUrl = photo.PhotoUrl
- localInfo.TeamMainPhotoUid = photo.PhotoUid
- }
- }
- }
- }
- // 3. 招募要求
- localInfo.TalentType = localData.TalentType
- localInfo.RecruitDdl = conv.MustString(localData.RecruitDdl)
- recruitStrategy, recruitErr := db.GetRecruitStrategyByProjectId(ctx, req.LocalId)
- if recruitErr != nil {
- return nil, recruitErr
- }
- if recruitStrategy != nil {
- for _, strategy := range recruitStrategy {
- showStrategy := http_model.ShowSRecruitStrategy{
- StrategyID: strategy.StrategyID,
- FeeForm: strategy.FeeForm,
- FollowersLow: strategy.FollowersLow,
- FollowersUp: strategy.FollowersUp,
- RecruitNumber: strategy.RecruitNumber,
- Offer: strategy.Offer,
- }
- localInfo.RecruitStrategys = append(localInfo.RecruitStrategys, showStrategy)
- }
- }
- // 4. 执行要求
- localInfo.TaskForm = localData.TaskForm
- localInfo.ContentType = localData.ContentType
- briefInfo, briefErr := db.FindBriefByLocalId(ctx, req.LocalId)
- if briefErr != nil {
- return nil, briefErr
- }
- if briefInfo != nil {
- localInfo.LocalBrief = briefInfo
- }
- materialInfo, materialErr := db.FindMaterialByLocalId(ctx, req.LocalId)
- if materialErr != nil {
- return nil, materialErr
- }
- if materialInfo != nil {
- localInfo.LocalMaterial = materialInfo
- }
- }
- return localInfo, nil
- }
|