123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238 |
- 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/gorm_model"
- "youngee_b_api/model/http_model"
- )
- var SLcoalLife *sLocalLife
- type sLocalLife struct {
- }
- // CreateSLocalLife 新建服务商加入商单后的公开本地生活
- func (*sLocalLife) CreateSLocalLife(ctx context.Context, request *http_model.LocalLifeAddToListRequest) error {
- var sLocalLifeInfo *gorm_model.YounggeeSLocalLifeInfo
- sLocalLifeInfo = &gorm_model.YounggeeSLocalLifeInfo{}
- // 1. 建立SLocalLife信息
- // 1.1. 根据传入的LocalLifeId去LocalLife表查找信息补全SLocalLife
- localLifeInfo, localErr := db.GetLocalLifeDetail(ctx, request.LocalLifeId)
- if localErr != nil {
- return localErr
- }
- if localLifeInfo != nil {
- sLocalLifeInfo.LocalId = localLifeInfo.LocalId
- sLocalLifeInfo.SettleNum = 0
- sLocalLifeInfo.RecruitNum = 0
- sLocalLifeInfo.ApplyNum = 0
- sLocalLifeInfo.LocalType = localLifeInfo.LocalType
- sLocalLifeInfo.LocalPlatform = localLifeInfo.LocalPlatform
- sLocalLifeInfo.TaskStatus = localLifeInfo.TaskStatus
- sLocalLifeInfo.StoreId = localLifeInfo.StoreId
- sLocalLifeInfo.TeamBuyingId = localLifeInfo.TeamBuyingId
- sLocalLifeInfo.TaskForm = localLifeInfo.TaskForm
- sLocalLifeInfo.ContentType = localLifeInfo.ContentType
- sLocalLifeInfo.SLocalStatus = 2
- // 1.2. 填入加入商单操作人信息
- sLocalLifeInfo.SubAccountId = request.SubAccountId
- sLocalLifeInfo.SupplierId = request.SupplierId
- sLocalLifeInfo.OperatorType = request.OperatorType
- // 2. 入库
- createErr := db.CreateSLocalLife(ctx, sLocalLifeInfo)
- if createErr != nil {
- return createErr
- }
- }
- return nil
- }
- func (*sLocalLife) ShowSLocalLife(ctx context.Context, req *http_model.ShowSLocalRequest) (*http_model.ShowSLocalData, error) {
- var sLocalInfo *http_model.ShowSLocalData
- sLocalInfo = &http_model.ShowSLocalData{}
- // 1. 查询系统信息
- localInfo, localErr := db.GetLocalLifeDetail(ctx, req.LocalId)
- if localErr != nil {
- return nil, localErr
- }
- if localInfo != nil {
- sLocalInfo.LocalId = localInfo.LocalId
- sLocalInfo.SLocalId = req.SLocalId
- sLocalInfo.LocalPlatform = localInfo.LocalPlatform
- sLocalInfo.TaskStatus = localInfo.TaskStatus
- sLocalInfo.EnterpriseId = localInfo.EnterpriseId
- sLocalInfo.ServiceChargeRate = localInfo.ServiceChargeRate
- sLocalInfo.EstimatedCost = localInfo.EstimatedCost
- sLocalInfo.CreateAt = conv.MustString(localInfo.CreatedAt)
- // 2. 关联主体
- // 2.1. 门店信息
- storeInfo, storeErr := db.FindStoreById(ctx, localInfo.StoreId)
- if storeErr != nil {
- return nil, storeErr
- }
- if storeInfo != nil {
- sLocalInfo.StoreId = storeInfo.StoreId
- sLocalInfo.StoreName = storeInfo.StoreName
- sLocalInfo.StoreCategory = storeInfo.StoreCategory
- sLocalInfo.StoreRelatedAt = conv.MustString(localInfo.StoreRelatedAt)
- // 2.2. 门店图片信息
- storePhotoInfo, storePhotoErr := db.GetStorePhotoByStoreID(ctx, localInfo.StoreId)
- if storePhotoErr != nil {
- return nil, storePhotoErr
- }
- if storePhotoInfo != nil {
- for _, photo := range storePhotoInfo {
- if photo.Symbol == 1 {
- sLocalInfo.StoreMainPhotoSymbol = 1
- sLocalInfo.StoreMainPhotoUrl = photo.PhotoUrl
- sLocalInfo.StoreMainPhotoUid = photo.PhotoUid
- }
- }
- }
- }
- // 2.3. 团购信息
- teamInfo, teamErr := db.FindTeamById(ctx, localInfo.StoreId)
- if teamErr != nil {
- return nil, teamErr
- }
- if teamInfo != nil {
- sLocalInfo.TeamBuyingId = teamInfo.StoreId
- sLocalInfo.TeamBuyingName = teamInfo.TeamBuyingName
- sLocalInfo.TeamBuyingCategory = teamInfo.TeamBuyingCategory
- sLocalInfo.TeamBuyingRelatedAt = conv.MustString(localInfo.TeamBuyingRelatedAt)
- // 2.4. 团购图片信息
- teamPhotoInfo, teamPhotoErr := db.GetTeamPhotoByStoreID(ctx, localInfo.StoreId)
- if teamPhotoErr != nil {
- return nil, teamPhotoErr
- }
- if teamPhotoInfo != nil {
- for _, photo := range teamPhotoInfo {
- if photo.Symbol == 1 {
- sLocalInfo.TeamMainPhotoSymbol = 1
- sLocalInfo.TeamMainPhotoUrl = photo.PhotoUrl
- sLocalInfo.TeamMainPhotoUid = photo.PhotoUid
- }
- }
- }
- }
- // 3. 招募要求
- sLocalInfo.TalentType = localInfo.TalentType
- sLocalInfo.RecruitDdl = conv.MustString(localInfo.RecruitDdl)
- recruitStrategy, recruitErr := db.GetRecruitStrategyBySLocalId(ctx, req.SLocalId)
- 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,
- }
- sLocalInfo.RecruitStrategys = append(sLocalInfo.RecruitStrategys, showStrategy)
- }
- }
- // 4. 执行要求
- sLocalInfo.TaskForm = localInfo.TaskForm
- sLocalInfo.ContentType = localInfo.ContentType
- briefInfo, briefErr := db.FindBriefByLocalId(ctx, req.LocalId)
- if briefErr != nil {
- return nil, briefErr
- }
- if briefInfo != nil {
- sLocalInfo.LocalBrief = briefInfo
- }
- materialInfo, materialErr := db.FindMaterialByLocalId(ctx, req.LocalId)
- if materialErr != nil {
- return nil, materialErr
- }
- if materialInfo != nil {
- sLocalInfo.LocalMaterial = materialInfo
- }
- }
- return sLocalInfo, nil
- }
- func (*sLocalLife) 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
- }
|