local_life_service.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. package service
  2. import (
  3. "errors"
  4. "github.com/sirupsen/logrus"
  5. "reflect"
  6. "time"
  7. "youngee_b_api/app/dao"
  8. "youngee_b_api/app/entity"
  9. "youngee_b_api/app/util"
  10. "youngee_b_api/app/vo"
  11. )
  12. type LocalLifeService struct{}
  13. // 创建本地生活任务
  14. func (s LocalLifeService) CreateLocalLife(param *vo.LocalCreateParam) (*string, error) {
  15. // a) 生成本地生活项目id
  16. localId := string(util.GenerateUUID(10))
  17. // b) 查找关联门店信息
  18. product, err := dao.StoreDao{}.GetStoreByID(param.StoreId)
  19. if err != nil {
  20. return nil, err
  21. }
  22. if product == nil {
  23. return nil, errors.New("未找到关联门店")
  24. }
  25. // c)创建种草任务
  26. var operatorType int64
  27. if param.SubAccountId == 0 {
  28. operatorType = 1
  29. } else {
  30. operatorType = 2
  31. }
  32. // 获取定时任务配置id
  33. infoAutoTask := entity.InfoAutoTask{}
  34. infoAutoTask = dao.InfoAutoTaskDao{}.GetAutoTaskLast(param.EnterpriseId)
  35. infoAutoDefault := entity.InfoAutoDefault{}
  36. infoAutoDefault = dao.InfoAutoDefaultDao{}.GetAutoDefaultLast(param.EnterpriseId)
  37. t := time.Now()
  38. newLocalLife := entity.LocalLifeInfo{
  39. EnterpriseID: param.EnterpriseId,
  40. SubAccountID: param.SubAccountId,
  41. OperatorType: operatorType,
  42. TaskStatus: 1,
  43. LocalID: localId,
  44. LocalType: param.LocalType,
  45. LocalPlatform: param.Platform,
  46. StoreID: param.StoreId,
  47. StoreRelatedAt: time.Now(),
  48. PromoteBody: param.PromoteBody,
  49. Donate: param.Donate,
  50. TeamBuyingId: param.TeamBuyingId,
  51. TeamBuyingRelatedAt: time.Now(),
  52. CreatedAt: t,
  53. AutoTaskID: infoAutoTask.AutoTaskID,
  54. AutoDefaultID: infoAutoDefault.AutoDefaultID,
  55. }
  56. if param.LocalType == 1 {
  57. newLocalLife.ServiceChargeRate = param.ServiceChargeRate
  58. }
  59. err = dao.LocalLifeDao{}.CreateLocalLife(newLocalLife)
  60. if err != nil {
  61. return nil, err
  62. }
  63. return &localId, nil
  64. }
  65. // 更新公开本地生活任务(招募要求、执行要求)
  66. func (s LocalLifeService) UpdateLocal(localUpdateParam *vo.LocalUpdateParam) (*string, error) {
  67. // 1. 检查该项目id有无本地任务
  68. localID := localUpdateParam.LocalID
  69. localLife, err := dao.LocalLifeDao{}.GetLocalById(localID)
  70. if err != nil {
  71. return nil, err
  72. }
  73. if localLife == nil {
  74. return nil, errors.New("本地生活项目不存在")
  75. }
  76. println("更新公开本地生活任务的招募策略")
  77. // 更新公开种草任务的招募策略
  78. var totalRecruitNum int64
  79. if localUpdateParam.RecruitStrategys != nil {
  80. // 1. 删除已有的招募策略
  81. err = dao.RecruitStrategyDao{}.DeleteRecruitStrategyByProjectID(localUpdateParam.LocalID)
  82. if err != nil {
  83. return nil, err
  84. }
  85. // 2. 接收并创建新的招募策略
  86. if len(localUpdateParam.RecruitStrategys) != 0 {
  87. var recruits []entity.RecruitStrategy
  88. for _, strategy := range localUpdateParam.RecruitStrategys {
  89. recruitStrategy := entity.RecruitStrategy{
  90. FeeForm: strategy.FeeForm,
  91. StrategyID: strategy.StrategyID,
  92. FollowersLow: strategy.FollowersLow,
  93. FollowersUp: strategy.FollowersUp,
  94. RecruitNumber: strategy.RecruitNumber,
  95. ProjectID: localLife.LocalID,
  96. StrategyType: 1,
  97. ServiceRate: localLife.ServiceChargeRate,
  98. }
  99. totalRecruitNum += strategy.RecruitNumber
  100. if strategy.FeeForm == 2 {
  101. recruitStrategy.Offer = strategy.Offer
  102. recruitStrategy.ServiceCharge = strategy.Offer * localUpdateParam.ServiceChargeRate
  103. recruitStrategy.TOffer = strategy.Offer * (1 - localUpdateParam.ServiceChargeRate)
  104. }
  105. recruits = append(recruits, recruitStrategy)
  106. }
  107. err = dao.RecruitStrategyDao{}.CreateRecruitStrategy(recruits)
  108. if err != nil {
  109. return nil, err
  110. }
  111. }
  112. }
  113. // 2. 数据准备
  114. //// a) 查找关联商品信息
  115. //product, err := dao.ProductDAO{}.GetProductByID(project.ProductID)
  116. //if err != nil {
  117. // return nil, err
  118. //}
  119. //productPhotos, err := dao.ProductPhotoDAO{}.GetProductPhotoByProductID(project.ProductID)
  120. //productInfoToJson, _ := json.Marshal(product)
  121. //productPhotosToJson, _ := json.Marshal(productPhotos)
  122. // d) 任务截止时间
  123. recruitDdl := time.Time{} //赋零值
  124. recruitDdl, _ = time.ParseInLocation("2006-01-02 15:04:05", localUpdateParam.RecruitDdl, time.Local)
  125. // f) 更新选品状态
  126. if localUpdateParam.LocalStatus != 2 && localUpdateParam.LocalStatus != 8 {
  127. localUpdateParam.LocalStatus = 1
  128. }
  129. t := time.Now()
  130. updateLocalLife := entity.LocalLifeInfo{
  131. StoreID: localUpdateParam.StoreId,
  132. TeamBuyingId: localUpdateParam.TeamBuyingId,
  133. ServiceChargeRate: localUpdateParam.ServiceChargeRate,
  134. PromoteBody: localUpdateParam.PromoteBody,
  135. Donate: localUpdateParam.Donate,
  136. TaskStatus: localUpdateParam.LocalStatus,
  137. LocalName: localUpdateParam.LocalName,
  138. TalentType: localUpdateParam.TalentType,
  139. RecruitDdl: recruitDdl,
  140. TaskForm: localUpdateParam.TaskForm,
  141. ContentType: localUpdateParam.ContentType,
  142. TaskDetail: localUpdateParam.TaskDetail,
  143. UpdatedAt: t,
  144. }
  145. if localUpdateParam.LocalStatus == 2 {
  146. updateLocalLife.SubmitAt = t
  147. }
  148. // 合并传入参数和数据表中原记录,若传入参数字段值为空,则将字段赋值为原记录中值
  149. result := util.MergeStructValue(&updateLocalLife, localLife)
  150. // 利用反射机制将interface类型转换为结构体类型
  151. v := reflect.ValueOf(&result).Elem()
  152. if v.Kind() == reflect.Struct {
  153. updateLocalLife = v.Interface().(entity.LocalLifeInfo)
  154. //fmt.Println(p)
  155. }
  156. // c) 计算预估成本(如果有)
  157. /*
  158. var estimatedCost float64
  159. if conv.MustInt(updateSelection.TaskMode, 0) == 1 {
  160. estimatedCost = conv.MustFloat64(updateSelection.TaskReward, 0) * conv.MustFloat64(updateSelection.SampleNum, 0)
  161. }
  162. estimatedCostToString, _ := conv.String(estimatedCost)
  163. updateSelection.EstimatedCost = estimatedCostToString
  164. */
  165. // 3. 更新选品
  166. err = dao.LocalLifeDao{}.UpdateLocal(updateLocalLife)
  167. if err != nil {
  168. return nil, err
  169. }
  170. // 4. 更新选品brief和示例(本地生活任务补充信息)
  171. if localUpdateParam.LocalBrief != nil {
  172. // 删除已有brief
  173. err = dao.ProjectBriefDao{}.DeleteSecBriefBySelectionId(localLife.LocalID)
  174. if err != nil {
  175. return nil, err
  176. }
  177. // 插入新的brief
  178. for _, v := range localUpdateParam.LocalBrief {
  179. brief := entity.ProjectBrief{
  180. ProjectID: localLife.LocalID,
  181. FileUid: v.FileUid,
  182. FileName: v.Name,
  183. FileUrl: v.FileUrl,
  184. CreatedAt: time.Now(),
  185. }
  186. err = dao.ProjectBriefDao{}.CreateProjectBrief(brief)
  187. if err != nil {
  188. return nil, err
  189. }
  190. }
  191. }
  192. if localUpdateParam.LocalMaterial != nil {
  193. // 删除已有示例
  194. err = dao.ProjectMaterialDao{}.DeleteProjectMaterialByProjectId(localLife.LocalID)
  195. if err != nil {
  196. return nil, err
  197. }
  198. // 插入新的示例
  199. for _, v := range localUpdateParam.LocalMaterial {
  200. projectMaterial := entity.ProjectMaterial{
  201. ProjectID: localLife.LocalID,
  202. FileUid: v.FileUid,
  203. FileName: v.Name,
  204. FileUrl: v.FileUrl,
  205. CreatedAt: time.Now(),
  206. }
  207. err = dao.ProjectMaterialDao{}.CreateProjectMaterial(projectMaterial)
  208. if err != nil {
  209. return nil, err
  210. }
  211. }
  212. }
  213. return &updateLocalLife.LocalID, nil
  214. }
  215. // 更新定向本地生活任务(招募要求、执行要求)
  216. func (s LocalLifeService) UpdateLocalTarget(localUpdateParam *vo.LocalUpdateParam) (*string, error) {
  217. // 1. 检查该项目id有无本地任务
  218. localID := localUpdateParam.LocalID
  219. localLife, err := dao.LocalLifeDao{}.GetLocalById(localID)
  220. if err != nil {
  221. return nil, err
  222. }
  223. if localLife == nil {
  224. return nil, errors.New("本地生活项目不存在")
  225. }
  226. println("更新定向本地生活任务的招募策略")
  227. // 更新公开种草任务的招募策略
  228. var totalRecruitNum int64
  229. if localUpdateParam.RecruitStrategys != nil {
  230. // 1. 删除已有的招募策略
  231. err = dao.RecruitStrategyDao{}.DeleteRecruitStrategyByProjectID(localUpdateParam.LocalID)
  232. if err != nil {
  233. return nil, err
  234. }
  235. // 2. 接收并创建新的招募策略
  236. if len(localUpdateParam.RecruitStrategys) != 0 {
  237. var recruits []entity.RecruitStrategy
  238. for _, strategy := range localUpdateParam.RecruitStrategys {
  239. recruitStrategy := entity.RecruitStrategy{
  240. FeeForm: strategy.FeeForm,
  241. StrategyID: strategy.StrategyID,
  242. FollowersLow: strategy.FollowersLow,
  243. FollowersUp: strategy.FollowersUp,
  244. RecruitNumber: strategy.RecruitNumber,
  245. ProjectID: localLife.LocalID,
  246. StrategyType: 1,
  247. ServiceRate: localLife.ServiceChargeRate,
  248. }
  249. totalRecruitNum += strategy.RecruitNumber
  250. if strategy.FeeForm == 2 {
  251. recruitStrategy.Offer = strategy.Offer // 报价
  252. }
  253. recruits = append(recruits, recruitStrategy)
  254. }
  255. err = dao.RecruitStrategyDao{}.CreateRecruitStrategy(recruits)
  256. if err != nil {
  257. return nil, err
  258. }
  259. }
  260. }
  261. // 2. 数据准备
  262. // a) 查找关联商品信息
  263. //product, err := dao.ProductDAO{}.GetProductByID(project.ProductID)
  264. //if err != nil {
  265. // return nil, err
  266. //}
  267. //productPhotos, err := dao.ProductPhotoDAO{}.GetProductPhotoByProductID(project.ProductID)
  268. //productInfoToJson, _ := json.Marshal(product)
  269. //productPhotosToJson, _ := json.Marshal(productPhotos)
  270. // d) 任务截止时间
  271. recruitDdl := time.Time{} //赋零值
  272. recruitDdl, _ = time.ParseInLocation("2006-01-02 15:04:05", localUpdateParam.RecruitDdl, time.Local)
  273. // f) 更新选品状态
  274. if localUpdateParam.LocalStatus != 2 && localUpdateParam.LocalStatus != 8 {
  275. localUpdateParam.LocalStatus = 1
  276. }
  277. t := time.Now()
  278. updateLocalLife := entity.LocalLifeInfo{
  279. StoreID: localUpdateParam.StoreId,
  280. TeamBuyingId: localUpdateParam.TeamBuyingId,
  281. ServiceChargeRate: localUpdateParam.ServiceChargeRate,
  282. PromoteBody: localUpdateParam.PromoteBody,
  283. Donate: localUpdateParam.Donate,
  284. TaskStatus: localUpdateParam.LocalStatus,
  285. LocalName: localUpdateParam.LocalName,
  286. TalentType: localUpdateParam.TalentType,
  287. RecruitDdl: recruitDdl,
  288. TaskForm: localUpdateParam.TaskForm,
  289. ContentType: localUpdateParam.ContentType,
  290. TaskDetail: localUpdateParam.TaskDetail,
  291. UpdatedAt: t,
  292. Tools: localUpdateParam.Tools,
  293. }
  294. if localUpdateParam.LocalStatus == 2 {
  295. updateLocalLife.SubmitAt = t
  296. }
  297. // 合并传入参数和数据表中原记录,若传入参数字段值为空,则将字段赋值为原记录中值
  298. result := util.MergeStructValue(&updateLocalLife, localLife)
  299. // 利用反射机制将interface类型转换为结构体类型
  300. v := reflect.ValueOf(&result).Elem()
  301. if v.Kind() == reflect.Struct {
  302. updateLocalLife = v.Interface().(entity.LocalLifeInfo)
  303. //fmt.Println(p)
  304. }
  305. // c) 计算预估成本(如果有)
  306. /*
  307. var estimatedCost float64
  308. if conv.MustInt(updateSelection.TaskMode, 0) == 1 {
  309. estimatedCost = conv.MustFloat64(updateSelection.TaskReward, 0) * conv.MustFloat64(updateSelection.SampleNum, 0)
  310. }
  311. estimatedCostToString, _ := conv.String(estimatedCost)
  312. updateSelection.EstimatedCost = estimatedCostToString
  313. */
  314. // 3. 更新选品
  315. err = dao.LocalLifeDao{}.UpdateLocal(updateLocalLife)
  316. if err != nil {
  317. return nil, err
  318. }
  319. // 4. 更新选品brief和示例(本地生活任务补充信息)
  320. if localUpdateParam.LocalBrief != nil {
  321. // 删除已有brief
  322. err = dao.ProjectBriefDao{}.DeleteSecBriefBySelectionId(localLife.LocalID)
  323. if err != nil {
  324. return nil, err
  325. }
  326. // 插入新的brief
  327. for _, v := range localUpdateParam.LocalBrief {
  328. brief := entity.ProjectBrief{
  329. ProjectID: localLife.LocalID,
  330. FileUid: v.FileUid,
  331. FileName: v.Name,
  332. FileUrl: v.FileUrl,
  333. CreatedAt: time.Now(),
  334. }
  335. err = dao.ProjectBriefDao{}.CreateProjectBrief(brief)
  336. if err != nil {
  337. return nil, err
  338. }
  339. }
  340. }
  341. if localUpdateParam.LocalMaterial != nil {
  342. // 删除已有示例
  343. err = dao.ProjectMaterialDao{}.DeleteProjectMaterialByProjectId(localLife.LocalID)
  344. if err != nil {
  345. return nil, err
  346. }
  347. // 插入新的示例
  348. for _, v := range localUpdateParam.LocalMaterial {
  349. projectMaterial := entity.ProjectMaterial{
  350. ProjectID: localLife.LocalID,
  351. FileUid: v.FileUid,
  352. FileName: v.Name,
  353. FileUrl: v.FileUrl,
  354. CreatedAt: time.Now(),
  355. }
  356. err = dao.ProjectMaterialDao{}.CreateProjectMaterial(projectMaterial)
  357. if err != nil {
  358. return nil, err
  359. }
  360. }
  361. }
  362. return &updateLocalLife.LocalID, nil
  363. }
  364. // 本地生活任务预览
  365. func (s LocalLifeService) GetLocalLifeDetail(localId string) (*vo.ReLocalDetail, error) {
  366. reLocalDetail := vo.ReLocalDetail{}
  367. localLife, err := dao.LocalLifeDao{}.GetLocalById(localId)
  368. if err != nil {
  369. logrus.Errorf("[localLifeDB service] call GetLocalById error,err:%+v", err)
  370. return nil, err
  371. }
  372. // 系统信息
  373. reLocalDetail.LocalId = localId
  374. reLocalDetail.LocalStatus = localLife.TaskStatus
  375. reLocalDetail.LocalPlatform = localLife.LocalPlatform
  376. reLocalDetail.CreatedAt = localLife.CreatedAt.Format("2006-01-02 15:04:05")
  377. reLocalDetail.EstimatedCost = localLife.EstimatedCost // 预估成本
  378. reLocalDetail.ServiceChargeRate = localLife.ServiceChargeRate
  379. var creatorName, phone string
  380. if localLife.OperatorType == 1 && localLife.SubAccountID == 0 {
  381. enterprise, err := dao.EnterpriseDao{}.GetEnterprise(localLife.EnterpriseID)
  382. if err == nil && enterprise != nil {
  383. creatorName = enterprise.BusinessName
  384. phone, err = dao.UserDao{}.GetPhoneByUserId(enterprise.UserId)
  385. }
  386. } else if localLife.OperatorType == 1 && localLife.SubAccountID != 0 {
  387. subAccount, err := dao.SubAccountDao{}.GetSubAccount(localLife.SubAccountID)
  388. if err == nil && subAccount != nil {
  389. creatorName = subAccount.SubAccountName
  390. phone, err = dao.UserDao{}.GetPhoneByUserId(subAccount.UserId)
  391. }
  392. }
  393. reLocalDetail.CreatorName = creatorName
  394. reLocalDetail.Phone = phone
  395. // 关联主体
  396. var reStore vo.ReStorePreview
  397. store, err := dao.StoreDao{}.GetStoreByID(localLife.StoreID)
  398. if err == nil {
  399. photoUrl, e := dao.ProductPhotoDAO{}.GetMainPhotoByStoreID(store.StoreID)
  400. if e != nil {
  401. photoUrl = ""
  402. }
  403. reStore = vo.ReStorePreview{
  404. StoreID: store.StoreID,
  405. StoreName: store.StoreName,
  406. StoreLocation: store.StoreLocation,
  407. StoreCategory: store.StoreCategory,
  408. TeamNum: store.TeamNum,
  409. StoreDetail: store.StoreDetail,
  410. CreatedAt: store.CreatedAt.Format("2006-01-02 15:04:05"),
  411. PhotoUrl: photoUrl,
  412. }
  413. }
  414. reLocalDetail.StoreInfo = &reStore
  415. var reTeamBuying vo.ReTeamBuyingPreview
  416. teamBuying, err := dao.TeamBuyingDao{}.GetTeamBuyingByID(localLife.TeamBuyingId)
  417. if err == nil {
  418. photoUrl, e := dao.ProductPhotoDAO{}.GetMainPhotoByTeamBuyingID(teamBuying.TeamBuyingID)
  419. if e != nil {
  420. photoUrl = ""
  421. }
  422. reTeamBuying = vo.ReTeamBuyingPreview{
  423. TeamBuyingID: teamBuying.TeamBuyingID,
  424. TeamBuyingName: teamBuying.TeamBuyingName,
  425. TeamBuyingPrice: teamBuying.TeamBuyingPrice,
  426. TeamBuyingCategory: teamBuying.TeamBuyingCategory,
  427. TeamBuyingDetail: teamBuying.TeamBuyingDetail,
  428. CreatedAt: teamBuying.CreatedAt.Format("2006-01-02 15:04:05"),
  429. PhotoUrl: photoUrl,
  430. }
  431. }
  432. reLocalDetail.TeamBuyingInfo = &reTeamBuying
  433. reLocalDetail.PromoteBody = localLife.PromoteBody
  434. reLocalDetail.Donate = localLife.Donate
  435. // 招募要求
  436. reLocalDetail.TalentType = localLife.TalentType
  437. reLocalDetail.RecruitDdl = localLife.RecruitDdl.Format("2006-01-02 15:04:05")
  438. var recruitStrategysPreviews []*vo.LocalRecruitStrategy
  439. recruitStrategys, err := dao.RecruitStrategyDao{}.GetRecruitStrategyByProjectId(localId)
  440. if err != nil {
  441. logrus.Errorf("[localLifeDB service] call GetRecruitStrategy error,err:%+v", err)
  442. return nil, err
  443. }
  444. for _, recruitStrategy := range recruitStrategys {
  445. recruitStrategysPreview := &vo.LocalRecruitStrategy{
  446. StrategyId: recruitStrategy.StrategyID,
  447. FeeForm: recruitStrategy.FeeForm,
  448. FollowersLow: recruitStrategy.FollowersLow,
  449. FollowersUp: recruitStrategy.FollowersUp,
  450. RecruitNumber: recruitStrategy.RecruitNumber,
  451. Offer: recruitStrategy.Offer,
  452. TOffer: recruitStrategy.TOffer,
  453. ServiceCharge: recruitStrategy.ServiceCharge,
  454. SelectedNumber: recruitStrategy.SelectedNumber,
  455. TotalOffer: recruitStrategy.TotalOffer,
  456. }
  457. recruitStrategysPreviews = append(recruitStrategysPreviews, recruitStrategysPreview)
  458. }
  459. reLocalDetail.RecruitStrategys = recruitStrategysPreviews
  460. // 执行要求
  461. reLocalDetail.TaskForm = localLife.TaskForm
  462. reLocalDetail.ContentType = localLife.ContentType
  463. reLocalDetail.TaskDetail = localLife.TaskDetail
  464. taskBriefInfos, err := dao.ProjectBriefDao{}.GetProjectBriefInfo(localId)
  465. if err != nil {
  466. logrus.Errorf("[localLifeDB service] call GetProjectBriefInfo error,err:%+v", err)
  467. return nil, err
  468. }
  469. taskMaterials, err := dao.ProjectMaterialDao{}.GetProjectMaterialInfo(localId)
  470. if err != nil {
  471. logrus.Errorf("[localLifeDB service] call GetprojectMaterialInfo error,err:%+v", err)
  472. return nil, err
  473. }
  474. reLocalDetail.TaskBriefs = taskBriefInfos
  475. reLocalDetail.TaskMaterials = taskMaterials
  476. reLocalDetail.Tools = localLife.Tools
  477. return &reLocalDetail, nil
  478. }
  479. // 本地生活提交审核
  480. func (s LocalLifeService) LocalLifeToReview(localUpdateParam *vo.LocalUpdateParam) (*string, error) {
  481. localId := localUpdateParam.LocalID
  482. t := time.Now()
  483. updateLocal := entity.LocalLifeInfo{
  484. LocalID: localId,
  485. TaskStatus: 2,
  486. UpdatedAt: t,
  487. }
  488. err := dao.LocalLifeDao{}.UpdateLocal(updateLocal)
  489. if err != nil {
  490. return nil, err
  491. }
  492. return &localId, nil
  493. }
  494. // 种草任务列表
  495. func (s LocalLifeService) GetLocalLifeTaskList(param *vo.LocalSearchParam) (vo.ResultVO, error) {
  496. if param.Page == 0 {
  497. param.Page = 1
  498. }
  499. if param.PageSize == 0 {
  500. param.PageSize = 10
  501. }
  502. var result vo.ResultVO
  503. reLocalTaskPreviews, total, err := (&dao.LocalLifeDao{}).GetLocalPreviews(param)
  504. if err != nil {
  505. return result, err
  506. }
  507. for i := range reLocalTaskPreviews {
  508. var creatorName string
  509. var storeName string
  510. var storeLocation string
  511. var mainImage string
  512. if reLocalTaskPreviews[i].SubAccountId == 0 {
  513. enterprise, err := dao.EnterpriseDao{}.GetEnterprise(reLocalTaskPreviews[i].EnterpriseId)
  514. if err == nil && enterprise != nil {
  515. creatorName = enterprise.BusinessName
  516. }
  517. } else {
  518. subAccount, err := dao.SubAccountDao{}.GetSubAccount(reLocalTaskPreviews[i].SubAccountId)
  519. if err == nil && subAccount != nil {
  520. creatorName = subAccount.SubAccountName
  521. }
  522. }
  523. store, err := dao.StoreDao{}.GetStoreByID(reLocalTaskPreviews[i].StoreId)
  524. if err == nil && store != nil {
  525. storeName = store.StoreName
  526. storeLocation = store.StoreLocation
  527. }
  528. mainImage, err = dao.ProductPhotoDAO{}.GetMainPhotoByStoreID(reLocalTaskPreviews[i].StoreId)
  529. reLocalTaskPreviews[i].CreatorName = creatorName
  530. reLocalTaskPreviews[i].StoreName = storeName
  531. reLocalTaskPreviews[i].StoreLocation = storeLocation
  532. reLocalTaskPreviews[i].MainImage = mainImage
  533. }
  534. result = vo.ResultVO{
  535. Page: param.Page,
  536. PageSize: param.PageSize,
  537. Total: total,
  538. Data: reLocalTaskPreviews,
  539. }
  540. return result, nil
  541. }
  542. // 删除种草任务
  543. func (s LocalLifeService) DeleteLocalLife(localId string) (*string, error) {
  544. res, err := dao.LocalLifeDao{}.DeleteLocalLife(localId)
  545. if err != nil {
  546. logrus.Errorf("[localLifeDB service] call DeleteLocalLife error,err:%+v", err)
  547. return res, err
  548. }
  549. return res, nil
  550. }