local_life_service.go 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321
  1. package service
  2. import (
  3. "errors"
  4. "github.com/sirupsen/logrus"
  5. "reflect"
  6. "strconv"
  7. "strings"
  8. "time"
  9. "youngee_b_api/app/dao"
  10. "youngee_b_api/app/entity"
  11. "youngee_b_api/app/service/review_service"
  12. "youngee_b_api/app/util"
  13. "youngee_b_api/app/vo"
  14. )
  15. type LocalLifeService struct{}
  16. // 创建本地生活任务
  17. func (s LocalLifeService) CreateLocalLife(localCreateParam *vo.LocalCreateParam) (*string, error) {
  18. // a) 生成本地生活项目id
  19. localId := strings.ReplaceAll(util.GenerateUUID(11), "-", "")
  20. // b) 查找关联门店信息
  21. product, err := dao.StoreDao{}.GetStoreByID(localCreateParam.StoreId)
  22. if err != nil {
  23. return nil, err
  24. }
  25. if product == nil {
  26. return nil, errors.New("未找到关联门店")
  27. }
  28. // c)创建本地生活任务
  29. var operatorType int64
  30. if localCreateParam.SubAccountId == 0 {
  31. operatorType = 1
  32. } else {
  33. operatorType = 2
  34. }
  35. // d) 任务截止时间
  36. recruitDdl, err1 := time.ParseInLocation("2006-01-02 15:04:05", localCreateParam.RecruitDdl, time.Local)
  37. if err1 != nil {
  38. return nil, errors.New("failed to parse recruitDdl")
  39. }
  40. // 获取定时任务配置id
  41. infoAutoTask := entity.InfoAutoTask{}
  42. infoAutoTask = dao.InfoAutoTaskDao{}.GetAutoTaskLast(localCreateParam.EnterpriseId)
  43. infoAutoDefault := entity.InfoAutoDefault{}
  44. infoAutoDefault = dao.InfoAutoDefaultDao{}.GetAutoDefaultLast(localCreateParam.EnterpriseId)
  45. t := time.Now()
  46. if recruitDdl.Before(t) {
  47. return nil, errors.New("请修改截止时间")
  48. }
  49. newLocalLife := entity.LocalLifeInfo{
  50. EnterpriseID: localCreateParam.EnterpriseId,
  51. SubAccountID: localCreateParam.SubAccountId,
  52. OperatorType: operatorType,
  53. TaskStatus: 1,
  54. LocalID: localId,
  55. LocalType: localCreateParam.LocalType,
  56. LocalPlatform: localCreateParam.Platform,
  57. StoreID: localCreateParam.StoreId,
  58. StoreRelatedAt: time.Now(),
  59. PromoteBody: localCreateParam.PromoteBody,
  60. Donate: localCreateParam.Donate,
  61. TeamBuyingId: localCreateParam.TeamBuyingId,
  62. TeamBuyingRelatedAt: time.Now(),
  63. CreatedAt: t,
  64. AutoTaskID: infoAutoTask.AutoTaskID,
  65. AutoDefaultID: infoAutoDefault.AutoDefaultID,
  66. LocalName: localCreateParam.LocalName,
  67. TalentType: localCreateParam.TalentType,
  68. RecruitDdl: recruitDdl,
  69. TaskForm: localCreateParam.TaskForm,
  70. ContentType: localCreateParam.ContentType,
  71. TaskDetail: localCreateParam.TaskDetail,
  72. }
  73. if localCreateParam.LocalType == 1 {
  74. newLocalLife.ServiceChargeRate = localCreateParam.ServiceChargeRate
  75. }
  76. err = dao.LocalLifeDao{}.CreateLocalLife(newLocalLife)
  77. if err != nil {
  78. return nil, err
  79. }
  80. // 4. 更新选品brief和示例(本地生活任务补充信息)
  81. if localCreateParam.LocalBrief != nil {
  82. // 插入新的brief
  83. for _, v := range localCreateParam.LocalBrief {
  84. brief := entity.LocalLifeBrief{
  85. LocalID: localId,
  86. FileUid: v.FileUid,
  87. FileName: v.Name,
  88. FileUrl: v.FileUrl,
  89. CreatedAt: time.Now(),
  90. Type: v.Type,
  91. }
  92. err = dao.LocalLifeBriefDao{}.CreateLocalBrief(brief)
  93. if err != nil {
  94. return nil, err
  95. }
  96. }
  97. }
  98. if localCreateParam.LocalMaterial != nil {
  99. // 插入新的示例
  100. for _, v := range localCreateParam.LocalMaterial {
  101. material := entity.LocalLifeMaterial{
  102. LocalID: localId,
  103. FileUid: v.FileUid,
  104. FileName: v.Name,
  105. FileUrl: v.FileUrl,
  106. CreatedAt: time.Now(),
  107. Type: v.Type,
  108. }
  109. err = dao.LocalLifeMaterialDao{}.CreateLocalMaterial(material)
  110. if err != nil {
  111. return nil, err
  112. }
  113. }
  114. }
  115. // 更新公开种草任务的招募策略
  116. var totalRecruitNum int64
  117. var estimatedCost float64
  118. if localCreateParam.RecruitStrategys != nil {
  119. // 2. 接收并创建新的招募策略
  120. if len(localCreateParam.RecruitStrategys) != 0 {
  121. var recruits []entity.RecruitStrategy
  122. for _, strategy := range localCreateParam.RecruitStrategys {
  123. if strategy.FeeForm == 2 {
  124. estimatedCost += float64(strategy.RecruitNumber) * strategy.Offer
  125. }
  126. recruitStrategy := entity.RecruitStrategy{
  127. FeeForm: strategy.FeeForm,
  128. StrategyID: strategy.StrategyID,
  129. FollowersLow: strategy.FollowersLow,
  130. FollowersUp: strategy.FollowersUp,
  131. RecruitNumber: strategy.RecruitNumber,
  132. ProjectID: localId,
  133. StrategyType: 1,
  134. ServiceRate: localCreateParam.ServiceChargeRate,
  135. }
  136. totalRecruitNum += strategy.RecruitNumber
  137. if strategy.FeeForm == 2 {
  138. recruitStrategy.Offer = strategy.Offer
  139. recruitStrategy.ServiceCharge = strategy.Offer * localCreateParam.ServiceChargeRate
  140. recruitStrategy.TOffer = strategy.Offer * (1 - localCreateParam.ServiceChargeRate)
  141. }
  142. recruits = append(recruits, recruitStrategy)
  143. }
  144. err = dao.RecruitStrategyDao{}.CreateRecruitStrategy(recruits)
  145. if err != nil {
  146. return nil, err
  147. }
  148. }
  149. }
  150. _ = dao.LocalLifeDao{}.UpdateLocal(entity.LocalLifeInfo{LocalID: localId, EstimatedCost: estimatedCost})
  151. return &localId, nil
  152. }
  153. // 更新公开本地生活任务(招募要求、执行要求)
  154. func (s LocalLifeService) UpdateLocal(localUpdateParam *vo.LocalUpdateParam) (*string, error) {
  155. // 1. 检查该项目id有无本地任务
  156. localID := localUpdateParam.LocalID
  157. localLife, err := dao.LocalLifeDao{}.GetLocalById(localID)
  158. if err != nil {
  159. return nil, err
  160. }
  161. if localLife == nil {
  162. return nil, errors.New("本地生活项目不存在")
  163. }
  164. recruitDdl := time.Time{} //赋零值
  165. recruitDdl, _ = time.ParseInLocation("2006-01-02 15:04:05", localUpdateParam.RecruitDdl, time.Local)
  166. if recruitDdl.Before(localLife.CreatedAt) {
  167. return nil, errors.New("请修改截止时间")
  168. }
  169. // 更新公开种草任务的招募策略
  170. var totalRecruitNum int64
  171. var estimatedCost float64
  172. if localUpdateParam.RecruitStrategys != nil {
  173. // 1. 删除已有的招募策略
  174. err = dao.RecruitStrategyDao{}.DeleteRecruitStrategyByProjectID(localUpdateParam.LocalID)
  175. if err != nil {
  176. return nil, err
  177. }
  178. // 2. 接收并创建新的招募策略
  179. if len(localUpdateParam.RecruitStrategys) != 0 {
  180. var recruits []entity.RecruitStrategy
  181. for _, strategy := range localUpdateParam.RecruitStrategys {
  182. if strategy.FeeForm == 2 {
  183. estimatedCost += float64(strategy.RecruitNumber) * strategy.Offer
  184. }
  185. recruitStrategy := entity.RecruitStrategy{
  186. FeeForm: strategy.FeeForm,
  187. StrategyID: strategy.StrategyID,
  188. FollowersLow: strategy.FollowersLow,
  189. FollowersUp: strategy.FollowersUp,
  190. RecruitNumber: strategy.RecruitNumber,
  191. ProjectID: localLife.LocalID,
  192. StrategyType: 1,
  193. ServiceRate: localLife.ServiceChargeRate,
  194. }
  195. totalRecruitNum += strategy.RecruitNumber
  196. if strategy.FeeForm == 2 {
  197. recruitStrategy.Offer = strategy.Offer
  198. recruitStrategy.ServiceCharge = strategy.Offer * localUpdateParam.ServiceChargeRate
  199. recruitStrategy.TOffer = strategy.Offer * (1 - localUpdateParam.ServiceChargeRate)
  200. }
  201. recruits = append(recruits, recruitStrategy)
  202. }
  203. err = dao.RecruitStrategyDao{}.CreateRecruitStrategy(recruits)
  204. if err != nil {
  205. return nil, err
  206. }
  207. }
  208. }
  209. // 2. 数据准备
  210. //// a) 查找关联商品信息
  211. //product, err := dao.ProductDAO{}.GetProductByID(project.ProductID)
  212. //if err != nil {
  213. // return nil, err
  214. //}
  215. //productPhotos, err := dao.ProductPhotoDAO{}.GetProductPhotoByProductID(project.ProductID)
  216. //productInfoToJson, _ := json.Marshal(product)
  217. //productPhotosToJson, _ := json.Marshal(productPhotos)
  218. // d) 任务截止时间
  219. //// f) 更新选品状态
  220. //if localUpdateParam.LocalStatus != 2 && localUpdateParam.LocalStatus != 8 {
  221. // localUpdateParam.LocalStatus = 1
  222. //}
  223. t := time.Now()
  224. updateLocalLife := entity.LocalLifeInfo{
  225. StoreID: localUpdateParam.StoreId,
  226. TeamBuyingId: localUpdateParam.TeamBuyingId,
  227. ServiceChargeRate: localUpdateParam.ServiceChargeRate,
  228. PromoteBody: localUpdateParam.PromoteBody,
  229. Donate: localUpdateParam.Donate,
  230. //TaskStatus: localUpdateParam.LocalStatus,
  231. LocalName: localUpdateParam.LocalName,
  232. TalentType: localUpdateParam.TalentType,
  233. RecruitDdl: recruitDdl,
  234. TaskForm: localUpdateParam.TaskForm,
  235. ContentType: localUpdateParam.ContentType,
  236. TaskDetail: localUpdateParam.TaskDetail,
  237. UpdatedAt: t,
  238. EstimatedCost: estimatedCost,
  239. }
  240. //if localUpdateParam.LocalStatus == 2 {
  241. // updateLocalLife.SubmitAt = t
  242. //}
  243. // 合并传入参数和数据表中原记录,若传入参数字段值为空,则将字段赋值为原记录中值
  244. result := util.MergeStructValue(&updateLocalLife, localLife)
  245. // 利用反射机制将interface类型转换为结构体类型
  246. v := reflect.ValueOf(&result).Elem()
  247. if v.Kind() == reflect.Struct {
  248. updateLocalLife = v.Interface().(entity.LocalLifeInfo)
  249. //fmt.Println(p)
  250. }
  251. // c) 计算预估成本(如果有)
  252. /*
  253. var estimatedCost float64
  254. if conv.MustInt(updateSelection.TaskMode, 0) == 1 {
  255. estimatedCost = conv.MustFloat64(updateSelection.TaskReward, 0) * conv.MustFloat64(updateSelection.SampleNum, 0)
  256. }
  257. estimatedCostToString, _ := conv.String(estimatedCost)
  258. updateSelection.EstimatedCost = estimatedCostToString
  259. */
  260. // 3. 更新选品
  261. err = dao.LocalLifeDao{}.UpdateLocal(updateLocalLife)
  262. if err != nil {
  263. return nil, err
  264. }
  265. // 4. 更新选品brief和示例(本地生活任务补充信息)
  266. if localUpdateParam.LocalBrief != nil {
  267. // 删除已有brief
  268. err = dao.LocalLifeBriefDao{}.DeleteLocalBriefByLocalId(localLife.LocalID)
  269. if err != nil {
  270. return nil, err
  271. }
  272. // 插入新的brief
  273. for _, v := range localUpdateParam.LocalBrief {
  274. brief := entity.LocalLifeBrief{
  275. LocalID: localLife.LocalID,
  276. FileUid: v.FileUid,
  277. FileName: v.Name,
  278. FileUrl: v.FileUrl,
  279. CreatedAt: time.Now(),
  280. Type: v.Type,
  281. }
  282. err = dao.LocalLifeBriefDao{}.CreateLocalBrief(brief)
  283. if err != nil {
  284. return nil, err
  285. }
  286. }
  287. }
  288. if localUpdateParam.LocalMaterial != nil {
  289. // 删除已有示例
  290. err = dao.LocalLifeMaterialDao{}.DeleteLocalMaterialByLocalId(localLife.LocalID)
  291. if err != nil {
  292. return nil, err
  293. }
  294. // 插入新的示例
  295. for _, v := range localUpdateParam.LocalMaterial {
  296. material := entity.LocalLifeMaterial{
  297. LocalID: localLife.LocalID,
  298. FileUid: v.FileUid,
  299. FileName: v.Name,
  300. FileUrl: v.FileUrl,
  301. CreatedAt: time.Now(),
  302. Type: v.Type,
  303. }
  304. err = dao.LocalLifeMaterialDao{}.CreateLocalMaterial(material)
  305. if err != nil {
  306. return nil, err
  307. }
  308. }
  309. }
  310. return &updateLocalLife.LocalID, nil
  311. }
  312. // 更新定向本地生活任务(招募要求、执行要求)
  313. func (s LocalLifeService) UpdateLocalTarget(localUpdateParam *vo.LocalUpdateParam) (*string, error) {
  314. // 1. 检查该项目id有无本地任务
  315. localID := localUpdateParam.LocalID
  316. localLife, err := dao.LocalLifeDao{}.GetLocalById(localID)
  317. if err != nil {
  318. return nil, err
  319. }
  320. if localLife == nil {
  321. return nil, errors.New("本地生活项目不存在")
  322. }
  323. println("更新定向本地生活任务的招募策略")
  324. // 更新公开种草任务的招募策略
  325. var totalRecruitNum int64
  326. var estimatedCost float64
  327. if localUpdateParam.RecruitStrategys != nil {
  328. // 1. 删除已有的招募策略
  329. err = dao.RecruitStrategyDao{}.DeleteRecruitStrategyByProjectID(localUpdateParam.LocalID)
  330. if err != nil {
  331. return nil, err
  332. }
  333. // 2. 接收并创建新的招募策略
  334. if len(localUpdateParam.RecruitStrategys) != 0 {
  335. var recruits []entity.RecruitStrategy
  336. for _, strategy := range localUpdateParam.RecruitStrategys {
  337. if strategy.FeeForm == 2 {
  338. estimatedCost += float64(strategy.RecruitNumber) * strategy.Offer
  339. }
  340. recruitStrategy := entity.RecruitStrategy{
  341. FeeForm: strategy.FeeForm,
  342. StrategyID: strategy.StrategyID,
  343. FollowersLow: strategy.FollowersLow,
  344. FollowersUp: strategy.FollowersUp,
  345. RecruitNumber: strategy.RecruitNumber,
  346. ProjectID: localLife.LocalID,
  347. StrategyType: 1,
  348. ServiceRate: localLife.ServiceChargeRate,
  349. }
  350. totalRecruitNum += strategy.RecruitNumber
  351. if strategy.FeeForm == 2 {
  352. recruitStrategy.Offer = strategy.Offer // 报价
  353. }
  354. recruits = append(recruits, recruitStrategy)
  355. }
  356. err = dao.RecruitStrategyDao{}.CreateRecruitStrategy(recruits)
  357. if err != nil {
  358. return nil, err
  359. }
  360. }
  361. }
  362. // 2. 数据准备
  363. // a) 查找关联商品信息
  364. //product, err := dao.ProductDAO{}.GetProductByID(project.ProductID)
  365. //if err != nil {
  366. // return nil, err
  367. //}
  368. //productPhotos, err := dao.ProductPhotoDAO{}.GetProductPhotoByProductID(project.ProductID)
  369. //productInfoToJson, _ := json.Marshal(product)
  370. //productPhotosToJson, _ := json.Marshal(productPhotos)
  371. // d) 任务截止时间
  372. recruitDdl := time.Time{} //赋零值
  373. recruitDdl, _ = time.ParseInLocation("2006-01-02 15:04:05", localUpdateParam.RecruitDdl, time.Local)
  374. //// f) 更新选品状态
  375. //if localUpdateParam.LocalStatus != 2 && localUpdateParam.LocalStatus != 8 {
  376. // localUpdateParam.LocalStatus = 1
  377. //}
  378. t := time.Now()
  379. updateLocalLife := entity.LocalLifeInfo{
  380. StoreID: localUpdateParam.StoreId,
  381. TeamBuyingId: localUpdateParam.TeamBuyingId,
  382. ServiceChargeRate: localUpdateParam.ServiceChargeRate,
  383. PromoteBody: localUpdateParam.PromoteBody,
  384. Donate: localUpdateParam.Donate,
  385. //TaskStatus: localUpdateParam.LocalStatus,
  386. LocalName: localUpdateParam.LocalName,
  387. TalentType: localUpdateParam.TalentType,
  388. RecruitDdl: recruitDdl,
  389. TaskForm: localUpdateParam.TaskForm,
  390. ContentType: localUpdateParam.ContentType,
  391. TaskDetail: localUpdateParam.TaskDetail,
  392. UpdatedAt: t,
  393. Tools: localUpdateParam.Tools,
  394. EstimatedCost: estimatedCost,
  395. }
  396. //if localUpdateParam.LocalStatus == 2 {
  397. // updateLocalLife.SubmitAt = t
  398. //}
  399. // 合并传入参数和数据表中原记录,若传入参数字段值为空,则将字段赋值为原记录中值
  400. result := util.MergeStructValue(&updateLocalLife, localLife)
  401. // 利用反射机制将interface类型转换为结构体类型
  402. v := reflect.ValueOf(&result).Elem()
  403. if v.Kind() == reflect.Struct {
  404. updateLocalLife = v.Interface().(entity.LocalLifeInfo)
  405. //fmt.Println(p)
  406. }
  407. // c) 计算预估成本(如果有)
  408. /*
  409. var estimatedCost float64
  410. if conv.MustInt(updateSelection.TaskMode, 0) == 1 {
  411. estimatedCost = conv.MustFloat64(updateSelection.TaskReward, 0) * conv.MustFloat64(updateSelection.SampleNum, 0)
  412. }
  413. estimatedCostToString, _ := conv.String(estimatedCost)
  414. updateSelection.EstimatedCost = estimatedCostToString
  415. */
  416. // 3. 更新选品
  417. err = dao.LocalLifeDao{}.UpdateLocal(updateLocalLife)
  418. if err != nil {
  419. return nil, err
  420. }
  421. // 4. 更新选品brief和示例(本地生活任务补充信息)
  422. if localUpdateParam.LocalBrief != nil {
  423. // 删除已有brief
  424. err = dao.ProjectBriefDao{}.DeleteSecBriefBySelectionId(localLife.LocalID)
  425. if err != nil {
  426. return nil, err
  427. }
  428. // 插入新的brief
  429. for _, v := range localUpdateParam.LocalBrief {
  430. brief := entity.ProjectBrief{
  431. ProjectID: localLife.LocalID,
  432. FileUid: v.FileUid,
  433. FileName: v.Name,
  434. FileUrl: v.FileUrl,
  435. CreatedAt: time.Now(),
  436. Type: v.Type,
  437. }
  438. err = dao.ProjectBriefDao{}.CreateProjectBrief(brief)
  439. if err != nil {
  440. return nil, err
  441. }
  442. }
  443. }
  444. if localUpdateParam.LocalMaterial != nil {
  445. // 删除已有示例
  446. err = dao.ProjectMaterialDao{}.DeleteProjectMaterialByProjectId(localLife.LocalID)
  447. if err != nil {
  448. return nil, err
  449. }
  450. // 插入新的示例
  451. for _, v := range localUpdateParam.LocalMaterial {
  452. projectMaterial := entity.ProjectMaterial{
  453. ProjectID: localLife.LocalID,
  454. FileUid: v.FileUid,
  455. FileName: v.Name,
  456. FileUrl: v.FileUrl,
  457. CreatedAt: time.Now(),
  458. Type: v.Type,
  459. }
  460. err = dao.ProjectMaterialDao{}.CreateProjectMaterial(projectMaterial)
  461. if err != nil {
  462. return nil, err
  463. }
  464. }
  465. }
  466. return &updateLocalLife.LocalID, nil
  467. }
  468. // 本地生活任务预览
  469. func (s LocalLifeService) GetLocalLifeDetail(localId string) (*vo.ReLocalDetail, error) {
  470. reLocalDetail := vo.ReLocalDetail{}
  471. localLife, err := dao.LocalLifeDao{}.GetLocalById(localId)
  472. if err != nil {
  473. logrus.Errorf("[localLifeDB service] call GetLocalById error,err:%+v", err)
  474. return nil, err
  475. }
  476. // 系统信息
  477. reLocalDetail.LocalId = localId
  478. reLocalDetail.LocalStatus = localLife.TaskStatus
  479. reLocalDetail.LocalPlatform = localLife.LocalPlatform
  480. reLocalDetail.CreatedAt = localLife.CreatedAt.Format("2006-01-02 15:04:05")
  481. reLocalDetail.EstimatedCost = localLife.EstimatedCost // 预估成本
  482. reLocalDetail.ServiceChargeRate = localLife.ServiceChargeRate
  483. var creatorName, phone string
  484. if localLife.OperatorType == 1 && localLife.SubAccountID == 0 {
  485. enterprise, err := dao.EnterpriseDao{}.GetEnterprise(localLife.EnterpriseID)
  486. if err == nil && enterprise != nil {
  487. creatorName = enterprise.BusinessName
  488. phone, err = dao.UserDao{}.GetPhoneByUserId(enterprise.UserId)
  489. }
  490. } else if localLife.OperatorType == 1 && localLife.SubAccountID != 0 {
  491. subAccount, err := dao.SubAccountDao{}.GetSubAccount(localLife.SubAccountID)
  492. if err == nil && subAccount != nil {
  493. creatorName = subAccount.SubAccountName
  494. phone, err = dao.UserDao{}.GetPhoneByUserId(subAccount.UserId)
  495. }
  496. }
  497. reLocalDetail.CreatorName = creatorName
  498. reLocalDetail.Phone = phone
  499. // 关联主体
  500. var reStore vo.ReStorePreview
  501. store, err := dao.StoreDao{}.GetStoreByID(localLife.StoreID)
  502. if err == nil {
  503. photoUrl, e := dao.ProductPhotoDAO{}.GetMainPhotoByStoreID(store.StoreID)
  504. if e != nil {
  505. photoUrl = ""
  506. }
  507. reStore = vo.ReStorePreview{
  508. StoreID: store.StoreID,
  509. StoreName: store.StoreName,
  510. StoreLocation: store.StoreLocation,
  511. StoreCategory: store.StoreCategory,
  512. TeamNum: store.TeamNum,
  513. StoreDetail: store.StoreDetail,
  514. CreatedAt: store.CreatedAt.Format("2006-01-02 15:04:05"),
  515. PhotoUrl: photoUrl,
  516. }
  517. }
  518. reLocalDetail.StoreInfo = &reStore
  519. var reTeamBuying vo.ReTeamBuyingPreview
  520. teamBuying, err := dao.TeamBuyingDao{}.GetTeamBuyingByID(localLife.TeamBuyingId)
  521. if err == nil {
  522. photoUrl, e := dao.ProductPhotoDAO{}.GetMainPhotoByTeamBuyingID(teamBuying.TeamBuyingID)
  523. if e != nil {
  524. photoUrl = ""
  525. }
  526. reTeamBuying = vo.ReTeamBuyingPreview{
  527. TeamBuyingID: teamBuying.TeamBuyingID,
  528. TeamBuyingName: teamBuying.TeamBuyingName,
  529. TeamBuyingPrice: teamBuying.TeamBuyingPrice,
  530. TeamBuyingCategory: teamBuying.TeamBuyingCategory,
  531. TeamBuyingDetail: teamBuying.TeamBuyingDetail,
  532. CreatedAt: teamBuying.CreatedAt.Format("2006-01-02 15:04:05"),
  533. PhotoUrl: photoUrl,
  534. }
  535. }
  536. reLocalDetail.TeamBuyingInfo = &reTeamBuying
  537. reLocalDetail.PromoteBody = localLife.PromoteBody
  538. reLocalDetail.Donate = localLife.Donate
  539. // 招募要求
  540. reLocalDetail.TalentType = localLife.TalentType
  541. reLocalDetail.RecruitDdl = localLife.RecruitDdl.Format("2006-01-02 15:04:05")
  542. var recruitStrategysPreviews []*vo.LocalRecruitStrategy
  543. recruitStrategys, err := dao.RecruitStrategyDao{}.GetRecruitStrategyByProjectId(localId)
  544. if err != nil {
  545. logrus.Errorf("[localLifeDB service] call GetRecruitStrategy error,err:%+v", err)
  546. return nil, err
  547. }
  548. for _, recruitStrategy := range recruitStrategys {
  549. recruitStrategysPreview := &vo.LocalRecruitStrategy{
  550. StrategyId: recruitStrategy.StrategyID,
  551. FeeForm: recruitStrategy.FeeForm,
  552. FollowersLow: recruitStrategy.FollowersLow,
  553. FollowersUp: recruitStrategy.FollowersUp,
  554. RecruitNumber: recruitStrategy.RecruitNumber,
  555. Offer: recruitStrategy.Offer,
  556. TOffer: recruitStrategy.TOffer,
  557. ServiceCharge: recruitStrategy.ServiceCharge,
  558. SelectedNumber: recruitStrategy.SelectedNumber,
  559. TotalOffer: recruitStrategy.TotalOffer,
  560. }
  561. recruitStrategysPreviews = append(recruitStrategysPreviews, recruitStrategysPreview)
  562. }
  563. reLocalDetail.RecruitStrategys = recruitStrategysPreviews
  564. // 执行要求
  565. reLocalDetail.TaskForm = localLife.TaskForm
  566. reLocalDetail.ContentType = localLife.ContentType
  567. reLocalDetail.TaskDetail = localLife.TaskDetail
  568. taskBriefInfos, err := dao.ProjectBriefDao{}.GetProjectBriefInfo(localId)
  569. if err != nil {
  570. logrus.Errorf("[localLifeDB service] call GetProjectBriefInfo error,err:%+v", err)
  571. return nil, err
  572. }
  573. taskMaterials, err := dao.ProjectMaterialDao{}.GetProjectMaterialInfo(localId)
  574. if err != nil {
  575. logrus.Errorf("[localLifeDB service] call GetprojectMaterialInfo error,err:%+v", err)
  576. return nil, err
  577. }
  578. reLocalDetail.TaskBriefs = taskBriefInfos
  579. reLocalDetail.TaskMaterials = taskMaterials
  580. reLocalDetail.Tools = localLife.Tools
  581. return &reLocalDetail, nil
  582. }
  583. // 复制本地生活任务
  584. func (s LocalLifeService) CopyLocalLife(param *vo.LocalSearchParam) (*string, error) {
  585. localLifeOrigin, err := dao.LocalLifeDao{}.GetLocalById(param.LocalId)
  586. if err != nil {
  587. logrus.Errorf("[localLifeDB service] call GetLocalById error,err:%+v", err)
  588. return nil, err
  589. }
  590. if localLifeOrigin == nil {
  591. return nil, errors.New("任务不存在")
  592. }
  593. localIdOrigin := localLifeOrigin.LocalID
  594. localIdNew := strings.ReplaceAll(util.GenerateUUID(11), "-", "")
  595. t := time.Now()
  596. // 获取定时任务配置id
  597. infoAutoTask := entity.InfoAutoTask{}
  598. infoAutoTask = dao.InfoAutoTaskDao{}.GetAutoTaskLast(param.EnterpriseId)
  599. infoAutoDefault := entity.InfoAutoDefault{}
  600. infoAutoDefault = dao.InfoAutoDefaultDao{}.GetAutoDefaultLast(param.EnterpriseId)
  601. // 复制任务
  602. localLifeNew := entity.LocalLifeInfo{
  603. EnterpriseID: param.EnterpriseId,
  604. SubAccountID: param.SubAccountId,
  605. OperatorType: localLifeOrigin.OperatorType,
  606. TaskStatus: localLifeOrigin.TaskStatus,
  607. LocalID: localIdNew,
  608. LocalType: localLifeOrigin.LocalType,
  609. LocalPlatform: localLifeOrigin.LocalPlatform,
  610. StoreID: localLifeOrigin.StoreID,
  611. StoreRelatedAt: t,
  612. PromoteBody: localLifeOrigin.PromoteBody,
  613. Donate: localLifeOrigin.Donate,
  614. TeamBuyingId: localLifeOrigin.TeamBuyingId,
  615. TeamBuyingRelatedAt: t,
  616. CreatedAt: t,
  617. AutoTaskID: infoAutoTask.AutoTaskID,
  618. AutoDefaultID: infoAutoDefault.AutoDefaultID,
  619. LocalName: localLifeOrigin.LocalName,
  620. TalentType: localLifeOrigin.TalentType,
  621. RecruitDdl: localLifeOrigin.RecruitDdl,
  622. TaskForm: localLifeOrigin.TaskForm,
  623. ContentType: localLifeOrigin.ContentType,
  624. TaskDetail: localLifeOrigin.TaskDetail,
  625. ServiceChargeRate: localLifeOrigin.ServiceChargeRate,
  626. EstimatedCost: localLifeOrigin.EstimatedCost,
  627. }
  628. err = dao.LocalLifeDao{}.CreateLocalLife(localLifeNew)
  629. if err != nil {
  630. return nil, err
  631. }
  632. // 更新选品brief和示例(本地生活任务补充信息)
  633. localBriefInfos, err := dao.LocalLifeBriefDao{}.GetLocalBriefInfo(localIdOrigin)
  634. if err != nil {
  635. logrus.Errorf("[projectDB service] call GetLocalBriefInfo error,err:%+v", err)
  636. return nil, err
  637. }
  638. if localBriefInfos != nil {
  639. for _, v := range localBriefInfos {
  640. brief := entity.LocalLifeBrief{
  641. LocalID: localIdNew,
  642. FileUid: v.FileUid,
  643. FileName: v.FileName,
  644. FileUrl: v.FileUrl,
  645. CreatedAt: time.Now(),
  646. Type: v.Type,
  647. }
  648. err = dao.LocalLifeBriefDao{}.CreateLocalBrief(brief)
  649. if err != nil {
  650. return nil, err
  651. }
  652. }
  653. }
  654. localMaterials, err := dao.LocalLifeMaterialDao{}.GetLocalMaterialInfo(localIdOrigin)
  655. if err != nil {
  656. logrus.Errorf("[projectDB service] call GetLocalMaterialInfo error,err:%+v", err)
  657. return nil, err
  658. }
  659. if localMaterials != nil {
  660. for _, v := range localMaterials {
  661. material := entity.LocalLifeMaterial{
  662. LocalID: localIdNew,
  663. FileUid: v.FileUid,
  664. FileName: v.FileName,
  665. FileUrl: v.FileUrl,
  666. CreatedAt: time.Now(),
  667. Type: v.Type,
  668. }
  669. err = dao.LocalLifeMaterialDao{}.CreateLocalMaterial(material)
  670. if err != nil {
  671. return nil, err
  672. }
  673. }
  674. }
  675. // 更新本地生活任务的招募策略
  676. recruitStrategys, err := dao.RecruitStrategyDao{}.GetRecruitStrategyByProjectId(localIdOrigin)
  677. if err != nil {
  678. logrus.Errorf("[localLifeDB service] call GetRecruitStrategy error,err:%+v", err)
  679. return nil, err
  680. }
  681. var totalRecruitNum int64
  682. if recruitStrategys != nil {
  683. // 2. 接收并创建新的招募策略
  684. if len(recruitStrategys) != 0 {
  685. var recruits []entity.RecruitStrategy
  686. for _, strategy := range recruitStrategys {
  687. recruitStrategy := entity.RecruitStrategy{
  688. FeeForm: strategy.FeeForm,
  689. StrategyID: strategy.StrategyID,
  690. FollowersLow: strategy.FollowersLow,
  691. FollowersUp: strategy.FollowersUp,
  692. RecruitNumber: strategy.RecruitNumber,
  693. ProjectID: localIdNew,
  694. StrategyType: strategy.StrategyType,
  695. ServiceRate: strategy.ServiceRate,
  696. Offer: strategy.Offer,
  697. ServiceCharge: strategy.ServiceCharge,
  698. TOffer: strategy.TOffer,
  699. }
  700. totalRecruitNum += strategy.RecruitNumber
  701. recruits = append(recruits, recruitStrategy)
  702. }
  703. err = dao.RecruitStrategyDao{}.CreateRecruitStrategy(recruits)
  704. if err != nil {
  705. return nil, err
  706. }
  707. }
  708. }
  709. return &localIdNew, nil
  710. }
  711. // 本地生活提交审核
  712. func (s LocalLifeService) LocalLifeToReview(localUpdateParam *vo.LocalUpdateParam) (*string, error) {
  713. localId := localUpdateParam.LocalID
  714. local, err := dao.LocalLifeDao{}.GetLocalById(localId)
  715. if err != nil {
  716. logrus.Errorf("[projectInfoDB service] call GetProject error,err:%+v", err)
  717. return nil, err
  718. }
  719. localName := local.LocalName // 任务标题
  720. localDetail := local.TaskDetail // 任务详情
  721. store, err := dao.StoreDao{}.GetStoreByID(local.StoreID)
  722. if err != nil {
  723. return nil, err
  724. }
  725. storeName := store.StoreName // 门店名称
  726. storeDetail := store.StoreDetail // 门店特点
  727. storeMainPhoto, err1 := dao.ProductPhotoDAO{}.GetMainPhotoByStoreID(store.StoreID)
  728. if err1 != nil {
  729. return nil, err1
  730. }
  731. teamBuying, err2 := dao.TeamBuyingDao{}.GetTeamBuyingByID(local.TeamBuyingId)
  732. if err2 != nil {
  733. return nil, err2
  734. }
  735. teamBuyingName := teamBuying.TeamBuyingName // 团购标题
  736. teamBuyingDetail := teamBuying.TeamBuyingDetail // 团购详情
  737. teamBuyingMainPhoto, err3 := dao.ProductPhotoDAO{}.GetMainPhotoByTeamBuyingID(teamBuying.TeamBuyingID)
  738. if err3 != nil {
  739. return nil, err3
  740. }
  741. var images []string
  742. var videos []string
  743. var videoJobIds []string
  744. var documents []string
  745. var documentJobIds []string
  746. reviewService := review_service.GetConfig()
  747. storePhotos, err4 := dao.ProductPhotoDAO{}.GetProductPhotoByStoreID(local.StoreID)
  748. if err4 != nil {
  749. return nil, err4
  750. }
  751. for _, storePhoto := range storePhotos {
  752. if storePhoto.Symbol == 2 || storePhoto.Symbol == 4 {
  753. images = append(images, storePhoto.PhotoUrl)
  754. } else if storePhoto.Symbol == 3 || storePhoto.Symbol == 5 {
  755. var videoJobId *string
  756. var reviewErr error
  757. i := 10
  758. for {
  759. videoJobId, reviewErr = reviewService.CheckVideo(storePhoto.PhotoUrl)
  760. if reviewErr == nil || i == 0 {
  761. break
  762. }
  763. i -= 1
  764. }
  765. if reviewErr != nil {
  766. return nil, reviewErr
  767. }
  768. videos = append(videos, storePhoto.PhotoUrl)
  769. videoJobIds = append(videoJobIds, *videoJobId)
  770. }
  771. }
  772. teamBuyingPhotos, err5 := dao.ProductPhotoDAO{}.GetProductPhotoByTeamBuyingID(local.TeamBuyingId)
  773. if err5 != nil {
  774. return nil, err5
  775. }
  776. for _, teamBuyingPhoto := range teamBuyingPhotos {
  777. if teamBuyingPhoto.Symbol == 2 || teamBuyingPhoto.Symbol == 4 {
  778. images = append(images, teamBuyingPhoto.PhotoUrl)
  779. } else if teamBuyingPhoto.Symbol == 3 || teamBuyingPhoto.Symbol == 5 {
  780. var videoJobId *string
  781. var reviewErr error
  782. i := 10
  783. for {
  784. videoJobId, reviewErr = reviewService.CheckVideo(teamBuyingPhoto.PhotoUrl)
  785. if reviewErr == nil || i == 0 {
  786. break
  787. }
  788. i -= 1
  789. }
  790. if reviewErr != nil {
  791. return nil, reviewErr
  792. }
  793. videos = append(videos, teamBuyingPhoto.PhotoUrl)
  794. videoJobIds = append(videoJobIds, *videoJobId)
  795. }
  796. }
  797. localBriefInfos, err6 := dao.LocalLifeBriefDao{}.GetLocalBriefInfo(localId)
  798. if err6 != nil {
  799. return nil, err6
  800. }
  801. for _, localBriefInfo := range localBriefInfos {
  802. if localBriefInfo.Type == 1 {
  803. images = append(images, localBriefInfo.FileUrl)
  804. } else if localBriefInfo.Type == 2 {
  805. var documentJobId *string
  806. var reviewErr error
  807. i := 10
  808. fileType := "pdf"
  809. parts := strings.Split(localBriefInfo.FileName, ".")
  810. if len(parts) > 1 {
  811. fileType = parts[len(parts)-1]
  812. }
  813. for {
  814. documentJobId, reviewErr = reviewService.CheckDocument(localBriefInfo.FileUrl, fileType)
  815. if reviewErr == nil || i == 0 {
  816. break
  817. }
  818. i -= 1
  819. }
  820. if reviewErr != nil {
  821. return nil, reviewErr
  822. }
  823. documents = append(documents, localBriefInfo.FileUrl)
  824. documentJobIds = append(documentJobIds, *documentJobId)
  825. }
  826. }
  827. localMaterials, err7 := dao.LocalLifeMaterialDao{}.GetLocalMaterialInfo(localId)
  828. if err7 != nil {
  829. return nil, err7
  830. }
  831. for _, localMaterial := range localMaterials {
  832. if localMaterial.Type == 1 {
  833. images = append(images, localMaterial.FileUrl)
  834. } else if localMaterial.Type == 2 {
  835. var videoJobId *string
  836. var reviewErr error
  837. i := 10
  838. for {
  839. videoJobId, reviewErr = reviewService.CheckVideo(localMaterial.FileUrl)
  840. if reviewErr == nil || i == 0 {
  841. break
  842. }
  843. i -= 1
  844. }
  845. if reviewErr != nil {
  846. return nil, reviewErr
  847. }
  848. videos = append(videos, localMaterial.FileUrl)
  849. videoJobIds = append(videoJobIds, *videoJobId)
  850. }
  851. }
  852. newReviewLocal := &entity.ReviewLocalLife{
  853. LocalID: localId,
  854. TaskName: localName,
  855. TaskDetail: localDetail,
  856. StoreMainPhoto: storeMainPhoto,
  857. StoreName: storeName,
  858. StoreDetail: storeDetail,
  859. TeamBuyingMainPhoto: teamBuyingMainPhoto,
  860. TeamBuyingName: teamBuyingName,
  861. TeamBuyingDetail: teamBuyingDetail,
  862. Images: strings.Join(images, ","),
  863. Videos: strings.Join(videos, ","),
  864. Documents: strings.Join(documents, ","),
  865. VideoJobIds: strings.Join(videoJobIds, ","),
  866. DocumentJobIds: strings.Join(documentJobIds, ","),
  867. Status: 1,
  868. }
  869. err8 := dao.LocalLifeReviewDao{}.Create(newReviewLocal)
  870. if err8 != nil {
  871. return nil, err8
  872. }
  873. t := time.Now()
  874. updateLocal := entity.LocalLifeInfo{
  875. LocalID: localId,
  876. TaskStatus: 2,
  877. SubmitAt: t,
  878. UpdatedAt: t,
  879. }
  880. err9 := dao.LocalLifeDao{}.UpdateLocal(updateLocal)
  881. if err9 != nil {
  882. return nil, err9
  883. }
  884. return &localId, nil
  885. }
  886. // 本地生活任务列表
  887. func (s LocalLifeService) GetLocalLifeTaskList(param *vo.LocalSearchParam) (vo.ResultVO, error) {
  888. if param.Page == 0 {
  889. param.Page = 1
  890. }
  891. if param.PageSize == 0 {
  892. param.PageSize = 10
  893. }
  894. var result vo.ResultVO
  895. reLocalTaskPreviews, total, err := (&dao.LocalLifeDao{}).GetLocalPreviews(param)
  896. if err != nil {
  897. return result, err
  898. }
  899. for i := range reLocalTaskPreviews {
  900. var creatorName string
  901. var storeName string
  902. var storeLocation string
  903. var mainImage string
  904. if reLocalTaskPreviews[i].SubAccountId == 0 {
  905. enterprise, err := dao.EnterpriseDao{}.GetEnterprise(reLocalTaskPreviews[i].EnterpriseId)
  906. if err == nil && enterprise != nil {
  907. creatorName = enterprise.BusinessName
  908. }
  909. } else {
  910. subAccount, err := dao.SubAccountDao{}.GetSubAccount(reLocalTaskPreviews[i].SubAccountId)
  911. if err == nil && subAccount != nil {
  912. creatorName = subAccount.SubAccountName
  913. }
  914. }
  915. store, err := dao.StoreDao{}.GetStoreByID(reLocalTaskPreviews[i].StoreId)
  916. if err == nil && store != nil {
  917. storeName = store.StoreName
  918. storeLocation = store.StoreLocation
  919. }
  920. mainImage, err = dao.ProductPhotoDAO{}.GetMainPhotoByStoreID(reLocalTaskPreviews[i].StoreId)
  921. reLocalTaskPreviews[i].CreatorName = creatorName
  922. reLocalTaskPreviews[i].StoreName = storeName
  923. reLocalTaskPreviews[i].StoreLocation = storeLocation
  924. reLocalTaskPreviews[i].MainImage = mainImage
  925. }
  926. result = vo.ResultVO{
  927. Page: param.Page,
  928. PageSize: param.PageSize,
  929. Total: total,
  930. Data: reLocalTaskPreviews,
  931. }
  932. return result, nil
  933. }
  934. // 删除本地生活任务
  935. func (s LocalLifeService) DeleteLocalLife(localId string) (*string, error) {
  936. res, err := dao.LocalLifeDao{}.DeleteLocalLife(localId)
  937. if err != nil {
  938. logrus.Errorf("[DeleteLocalLife service] call DeleteLocalLife error,err:%+v", err)
  939. return res, err
  940. }
  941. return res, nil
  942. }
  943. // 结束本地生活任务
  944. func (s LocalLifeService) CloseLocalLife(localId string) (*string, error) {
  945. err := dao.LocalLifeDao{}.UpdateLocal(entity.LocalLifeInfo{
  946. LocalID: localId,
  947. TaskStatus: 10,
  948. UpdatedAt: time.Now(),
  949. })
  950. return &localId, err
  951. }
  952. // 草稿箱——本地生活
  953. func (s LocalLifeService) GetLocalLifeDraftList(param *vo.LocalDraftParam) (vo.ResultVO, error) {
  954. if param.Page == 0 {
  955. param.Page = 1
  956. }
  957. if param.PageSize == 0 {
  958. param.PageSize = 10
  959. }
  960. var result vo.ResultVO
  961. reLocalTaskPreviews, total, err := (&dao.LocalLifeDao{}).GetLocalDraftList(param)
  962. if err != nil {
  963. return result, err
  964. }
  965. for i := range reLocalTaskPreviews {
  966. var creatorName string
  967. var storeName string
  968. var storeLocation string
  969. var mainImage string
  970. if reLocalTaskPreviews[i].SubAccountId == 0 {
  971. enterprise, err := dao.EnterpriseDao{}.GetEnterprise(reLocalTaskPreviews[i].EnterpriseId)
  972. if err == nil && enterprise != nil {
  973. creatorName = enterprise.BusinessName
  974. }
  975. } else {
  976. subAccount, err := dao.SubAccountDao{}.GetSubAccount(reLocalTaskPreviews[i].SubAccountId)
  977. if err == nil && subAccount != nil {
  978. creatorName = subAccount.SubAccountName
  979. }
  980. }
  981. store, err := dao.StoreDao{}.GetStoreByID(reLocalTaskPreviews[i].StoreId)
  982. if err == nil && store != nil {
  983. storeName = store.StoreName
  984. storeLocation = store.StoreLocation
  985. }
  986. mainImage, err = dao.ProductPhotoDAO{}.GetMainPhotoByStoreID(reLocalTaskPreviews[i].StoreId)
  987. reLocalTaskPreviews[i].CreatorName = creatorName
  988. reLocalTaskPreviews[i].StoreName = storeName
  989. reLocalTaskPreviews[i].StoreLocation = storeLocation
  990. reLocalTaskPreviews[i].MainImage = mainImage
  991. }
  992. result = vo.ResultVO{
  993. Page: param.Page,
  994. PageSize: param.PageSize,
  995. Total: total,
  996. Data: reLocalTaskPreviews,
  997. }
  998. return result, nil
  999. }
  1000. // 探店本地生活列表
  1001. func (s LocalLifeService) GetStoreExploreList(param *vo.LocalSearchParam) (vo.ResultVO, error) {
  1002. if param.Page == 0 {
  1003. param.Page = 1
  1004. }
  1005. if param.PageSize == 0 {
  1006. param.PageSize = 10
  1007. }
  1008. var result vo.ResultVO
  1009. reLocalStoreExplorePreviews, total, err := (&dao.LocalLifeDao{}).GetLocalStoreExplorePreviews(param)
  1010. if err != nil {
  1011. return result, err
  1012. }
  1013. for i := range reLocalStoreExplorePreviews {
  1014. var creatorName string
  1015. var storeName string
  1016. var storeLocation string
  1017. var mainImage string
  1018. if reLocalStoreExplorePreviews[i].SubAccountId == 0 {
  1019. enterprise, err := dao.EnterpriseDao{}.GetEnterprise(reLocalStoreExplorePreviews[i].EnterpriseId)
  1020. if err == nil && enterprise != nil {
  1021. creatorName = enterprise.BusinessName
  1022. }
  1023. } else {
  1024. subAccount, err := dao.SubAccountDao{}.GetSubAccount(reLocalStoreExplorePreviews[i].SubAccountId)
  1025. if err == nil && subAccount != nil {
  1026. creatorName = subAccount.SubAccountName
  1027. }
  1028. }
  1029. store, err := dao.StoreDao{}.GetStoreByID(reLocalStoreExplorePreviews[i].StoreId)
  1030. if err == nil && store != nil {
  1031. storeName = store.StoreName
  1032. storeLocation = store.StoreLocation
  1033. }
  1034. mainImage, err = dao.ProductPhotoDAO{}.GetMainPhotoByStoreID(reLocalStoreExplorePreviews[i].StoreId)
  1035. reLocalStoreExplorePreviews[i].CreatorName = creatorName
  1036. reLocalStoreExplorePreviews[i].StoreName = storeName
  1037. reLocalStoreExplorePreviews[i].StoreLocation = storeLocation
  1038. reLocalStoreExplorePreviews[i].MainImage = mainImage
  1039. }
  1040. result = vo.ResultVO{
  1041. Page: param.Page,
  1042. PageSize: param.PageSize,
  1043. Total: total,
  1044. Data: reLocalStoreExplorePreviews,
  1045. }
  1046. return result, nil
  1047. }
  1048. // 探店达人详情
  1049. func (s LocalLifeService) GetStoreExploreInfo(param *vo.StoreExploreParam) (*vo.ResultVO, error) {
  1050. if param.Page <= 0 {
  1051. param.Page = 1
  1052. }
  1053. if param.PageSize <= 0 {
  1054. param.PageSize = 10
  1055. }
  1056. var reStoreExploreTalents []*vo.ReStoreExploreTalent
  1057. var total int64
  1058. result := vo.ResultVO{
  1059. Page: param.Page,
  1060. PageSize: param.PageSize,
  1061. Total: total,
  1062. Data: reStoreExploreTalents,
  1063. }
  1064. var localLifeTaskInfos []*entity.LocalLifeTaskInfo
  1065. var err error
  1066. localLifeId := param.LocalLifeId
  1067. if param.Status == 1 { // 待预约
  1068. localLifeTaskInfos, total, err = dao.LocalLifeTaskInfoDao{}.GetListByTaskStage(localLifeId, 1, "", param.Page, param.PageSize)
  1069. } else if param.Status == 2 { // 待确认
  1070. localLifeTaskInfos, total, err = dao.LocalLifeTaskInfoDao{}.GetListByTaskStage(localLifeId, 2, param.SearchTime, param.Page, param.PageSize)
  1071. } else if param.Status == 3 { // 待探店
  1072. localLifeTaskInfos, total, err = dao.LocalLifeTaskInfoDao{}.GetListByTaskStage(localLifeId, 5, param.SearchTime, param.Page, param.PageSize)
  1073. } else if param.Status == 4 { // 已探店
  1074. localLifeTaskInfos, total, err = dao.LocalLifeTaskInfoDao{}.GetListByTaskStage(localLifeId, 6, param.SearchTime, param.Page, param.PageSize)
  1075. }
  1076. if err != nil {
  1077. return nil, err
  1078. }
  1079. for _, localLifeTaskInfo := range localLifeTaskInfos {
  1080. // 获取达人信息
  1081. talentInfo, err := dao.TalentInfoDao{}.SelectTalentInfo(localLifeTaskInfo.TalentID)
  1082. if err != nil {
  1083. return nil, err
  1084. }
  1085. //regionName, err := dao.RegionInfoDao{}.SelectRegion(talentInfo.VisitStoreRegion)
  1086. //if err != nil {
  1087. // regionName = ""
  1088. //}
  1089. regionName := localLifeTaskInfo.City
  1090. talentPreview := &vo.TalentPreview{
  1091. TalentId: localLifeTaskInfo.TalentID,
  1092. TalentPhoto: talentInfo.Avatar,
  1093. TalentName: talentInfo.TalentWxNickname,
  1094. Account: "",
  1095. Location: regionName,
  1096. }
  1097. reStoreExploreTalent := &vo.ReStoreExploreTalent{
  1098. ReTalentPreview: talentPreview,
  1099. TaskId: localLifeTaskInfo.TaskID,
  1100. }
  1101. if param.Status == 1 {
  1102. reStoreExploreTalent.CooperateTime = localLifeTaskInfo.SelectDate.Format("2006-01-02 15:04:05")
  1103. } else if param.Status == 2 {
  1104. reStoreExploreTalent.ReserveTime = localLifeTaskInfo.ReserveTime.Format("2006-01-02 15:04:05")
  1105. } else if param.Status == 3 {
  1106. reStoreExploreTalent.ExploreTime = localLifeTaskInfo.ExploreTime.Format("2006-01-02 15:04:05")
  1107. reStoreExploreTalent.Operator = ""
  1108. } else if param.Status == 4 {
  1109. reStoreExploreTalent.FinishExploreTime = localLifeTaskInfo.FinishExploreTime.Format("2006-01-02 15:04:05")
  1110. reStoreExploreTalent.Operator = ""
  1111. }
  1112. reStoreExploreTalents = append(reStoreExploreTalents, reStoreExploreTalent)
  1113. }
  1114. result = vo.ResultVO{
  1115. Page: param.Page,
  1116. PageSize: param.PageSize,
  1117. Total: total,
  1118. Data: reStoreExploreTalents,
  1119. }
  1120. return &result, nil
  1121. }
  1122. // 终止合作
  1123. func (s LocalLifeService) StoreExploreOver(param *vo.LocalTalentOperateParam) (*string, error) {
  1124. taskId := param.TaskId
  1125. if taskId == "" {
  1126. return nil, errors.New("taskId is empty")
  1127. }
  1128. updateData := map[string]interface{}{
  1129. "task_stage": 17,
  1130. "terminate_reason": param.Reason,
  1131. "terminate_time": time.Now(),
  1132. }
  1133. if param.SubAccountId == 0 {
  1134. updateData["terminate_operator_type"] = 1
  1135. updateData["terminate_operator"] = param.EnterpriseId
  1136. } else {
  1137. updateData["terminate_operator_type"] = 2
  1138. updateData["terminate_operator"] = param.SubAccountId
  1139. }
  1140. err := dao.LocalLifeTaskInfoDao{}.UpdateField(param.TaskId, updateData)
  1141. if err != nil {
  1142. return nil, err
  1143. }
  1144. return &taskId, nil
  1145. }
  1146. // 预约时间批量同意/驳回
  1147. func (s LocalLifeService) StoreExploreOperate(param *vo.LocalTalentOperateParam) error {
  1148. taskIds := param.TaskIds
  1149. if taskIds == nil {
  1150. return errors.New("taskIds is empty")
  1151. }
  1152. var bookIds []int64
  1153. for _, taskId := range taskIds {
  1154. bookInfo, err := dao.BookInfoDao{}.GetLastByTaskId(taskId)
  1155. if err != nil {
  1156. return err
  1157. }
  1158. bookIds = append(bookIds, bookInfo.BookID)
  1159. }
  1160. var bookinfoNew entity.BookInfo
  1161. if param.Status == 2 {
  1162. bookinfoNew = entity.BookInfo{
  1163. IsReview: 1,
  1164. IsOk: 2,
  1165. RejectAt: time.Now(),
  1166. ReviseOpinion: param.Reason,
  1167. }
  1168. } else if param.Status == 1 {
  1169. bookinfoNew = entity.BookInfo{
  1170. IsReview: 1,
  1171. IsOk: 1,
  1172. AgreeAt: time.Now(),
  1173. }
  1174. } else {
  1175. return errors.New("status error")
  1176. }
  1177. if param.SubAccountId == 0 {
  1178. bookinfoNew.BOperatorType = 1
  1179. bookinfoNew.BOperator = param.EnterpriseId
  1180. } else {
  1181. bookinfoNew.BOperatorType = 2
  1182. bookinfoNew.BOperator = strconv.FormatInt(param.SubAccountId, 10)
  1183. }
  1184. err1 := dao.BookInfoDao{}.UpdateBookStatus(bookIds, bookinfoNew)
  1185. if err1 != nil {
  1186. return err1
  1187. }
  1188. if param.Status == 1 {
  1189. err2 := dao.LocalLifeTaskInfoDao{}.UpdateLocalStatus(taskIds, entity.LocalLifeTaskInfo{
  1190. TaskStage: 7,
  1191. })
  1192. if err2 != nil {
  1193. return err2
  1194. }
  1195. }
  1196. return nil
  1197. }
  1198. // 本地生活任务待办
  1199. func (p LocalLifeService) GetTaskToDo(enterpriseId string, subAccountId int64, taskType int64) (map[string]map[string]int64, error) {
  1200. res := make(map[string]map[string]int64)
  1201. redbook, err1 := dao.LocalLifeDao{}.GetLocalLifeToDo(enterpriseId, subAccountId, 1, taskType)
  1202. if err1 != nil {
  1203. logrus.Errorf("[GetLocalLifeToDo service] call GetLocalLifeToDo error,err:%+v", err1)
  1204. return res, err1
  1205. }
  1206. douyin, err2 := dao.LocalLifeDao{}.GetLocalLifeToDo(enterpriseId, subAccountId, 2, taskType)
  1207. if err2 != nil {
  1208. logrus.Errorf("[GetLocalLifeToDo service] call GetLocalLifeToDo error,err:%+v", err2)
  1209. return res, err2
  1210. }
  1211. kuaishou, err3 := dao.LocalLifeDao{}.GetLocalLifeToDo(enterpriseId, subAccountId, 4, taskType)
  1212. if err3 != nil {
  1213. logrus.Errorf("[GetLocalLifeToDo service] call GetLocalLifeToDo error,err:%+v", err3)
  1214. return res, err3
  1215. }
  1216. weibo, err4 := dao.LocalLifeDao{}.GetLocalLifeToDo(enterpriseId, subAccountId, 3, taskType)
  1217. if err4 != nil {
  1218. logrus.Errorf("[GetLocalLifeToDo service] call GetLocalLifeToDo error,err:%+v", err4)
  1219. return res, err4
  1220. }
  1221. bilibili, err5 := dao.LocalLifeDao{}.GetLocalLifeToDo(enterpriseId, subAccountId, 5, taskType)
  1222. if err5 != nil {
  1223. logrus.Errorf("[GetLocalLifeToDo service] call GetLocalLifeToDo error,err:%+v", err5)
  1224. return res, err5
  1225. }
  1226. all := make(map[string]int64)
  1227. all["needReview"] = redbook["needReview"] + douyin["needReview"] + kuaishou["needReview"] + weibo["needReview"] + bilibili["needReview"]
  1228. all["needPay"] = redbook["needPay"] + douyin["needPay"] + kuaishou["needPay"] + weibo["needPay"] + bilibili["needPay"]
  1229. all["needProcess"] = redbook["needProcess"] + douyin["needProcess"] + kuaishou["needProcess"] + weibo["needProcess"] + bilibili["needProcess"]
  1230. all["needCheck"] = redbook["needCheck"] + douyin["needCheck"] + kuaishou["needCheck"] + weibo["needCheck"] + bilibili["needCheck"]
  1231. all["needQuality"] = redbook["needQuality"] + douyin["needQuality"] + kuaishou["needQuality"] + weibo["needQuality"] + bilibili["needQuality"]
  1232. all["needCalculate"] = redbook["needCalculate"] + douyin["needCalculate"] + kuaishou["needCalculate"] + weibo["needCalculate"] + bilibili["needCalculate"]
  1233. res["redbook"] = redbook
  1234. res["douyin"] = douyin
  1235. res["kuaishou"] = kuaishou
  1236. res["weibo"] = weibo
  1237. res["bilibili"] = bilibili
  1238. res["all"] = all
  1239. return res, nil
  1240. }
  1241. // 探店邀约任务待办
  1242. func (p LocalLifeService) GetExploreToDo(enterpriseId string, subAccountId int64) (map[string]map[string]int64, error) {
  1243. res := make(map[string]map[string]int64)
  1244. redbook, err1 := dao.LocalLifeDao{}.GetExploreToDo(enterpriseId, subAccountId, 1)
  1245. if err1 != nil {
  1246. logrus.Errorf("[GetLocalLifeToDo service] call GetLocalLifeToDo error,err:%+v", err1)
  1247. return res, err1
  1248. }
  1249. douyin, err2 := dao.LocalLifeDao{}.GetExploreToDo(enterpriseId, subAccountId, 2)
  1250. if err2 != nil {
  1251. logrus.Errorf("[GetLocalLifeToDo service] call GetLocalLifeToDo error,err:%+v", err2)
  1252. return res, err2
  1253. }
  1254. kuaishou, err3 := dao.LocalLifeDao{}.GetExploreToDo(enterpriseId, subAccountId, 4)
  1255. if err3 != nil {
  1256. logrus.Errorf("[GetLocalLifeToDo service] call GetLocalLifeToDo error,err:%+v", err3)
  1257. return res, err3
  1258. }
  1259. weibo, err4 := dao.LocalLifeDao{}.GetExploreToDo(enterpriseId, subAccountId, 3)
  1260. if err4 != nil {
  1261. logrus.Errorf("[GetLocalLifeToDo service] call GetLocalLifeToDo error,err:%+v", err4)
  1262. return res, err4
  1263. }
  1264. bilibili, err5 := dao.LocalLifeDao{}.GetExploreToDo(enterpriseId, subAccountId, 5)
  1265. if err5 != nil {
  1266. logrus.Errorf("[GetLocalLifeToDo service] call GetLocalLifeToDo error,err:%+v", err5)
  1267. return res, err5
  1268. }
  1269. all := make(map[string]int64)
  1270. all["needBook"] = redbook["needBook"] + douyin["needBook"] + kuaishou["needBook"] + weibo["needBook"] + bilibili["needBook"]
  1271. all["needConfirm"] = redbook["needConfirm"] + douyin["needConfirm"] + kuaishou["needConfirm"] + weibo["needConfirm"] + bilibili["needConfirm"]
  1272. all["needExplore"] = redbook["needExplore"] + douyin["needExplore"] + kuaishou["needExplore"] + weibo["needExplore"] + bilibili["needExplore"]
  1273. res["redbook"] = redbook
  1274. res["douyin"] = douyin
  1275. res["kuaishou"] = kuaishou
  1276. res["weibo"] = weibo
  1277. res["bilibili"] = bilibili
  1278. res["all"] = all
  1279. return res, nil
  1280. }