local_life_service.go 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432
  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 * 0.01
  140. recruitStrategy.TOffer = strategy.Offer * (1 - localCreateParam.ServiceChargeRate*0.01)
  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 * 0.01
  199. recruitStrategy.TOffer = strategy.Offer * (1 - localUpdateParam.ServiceChargeRate*0.01)
  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.LocalName = localLife.LocalName
  478. reLocalDetail.LocalId = localId
  479. reLocalDetail.LocalStatus = localLife.TaskStatus
  480. reLocalDetail.LocalPlatform = localLife.LocalPlatform
  481. reLocalDetail.CreatedAt = localLife.CreatedAt.Format("2006-01-02 15:04:05")
  482. if localLife.TaskStatus < 6 {
  483. reLocalDetail.EstimatedCost = localLife.EstimatedCost
  484. } else {
  485. reLocalDetail.EstimatedCost = localLife.NeedPay
  486. }
  487. reLocalDetail.ServiceChargeRate = localLife.ServiceChargeRate
  488. var creatorName, phone string
  489. if localLife.OperatorType == 1 && localLife.SubAccountID == 0 {
  490. enterprise, err := dao.EnterpriseDao{}.GetEnterprise(localLife.EnterpriseID)
  491. if err == nil && enterprise != nil {
  492. creatorName = enterprise.BusinessName
  493. phone, err = dao.UserDao{}.GetPhoneByUserId(enterprise.UserId)
  494. }
  495. } else if localLife.OperatorType == 1 && localLife.SubAccountID != 0 {
  496. subAccount, err := dao.SubAccountDao{}.GetSubAccount(localLife.SubAccountID)
  497. if err == nil && subAccount != nil {
  498. creatorName = subAccount.SubAccountName
  499. phone, err = dao.UserDao{}.GetPhoneByUserId(subAccount.UserId)
  500. }
  501. }
  502. reLocalDetail.CreatorName = creatorName
  503. reLocalDetail.Phone = phone
  504. // 关联主体
  505. var reStore vo.ReStorePreview
  506. store, err := dao.StoreDao{}.GetStoreByID(localLife.StoreID)
  507. if err == nil {
  508. photoUrl, e := dao.ProductPhotoDAO{}.GetMainPhotoByStoreID(store.StoreID)
  509. if e != nil {
  510. photoUrl = ""
  511. }
  512. reStore = vo.ReStorePreview{
  513. StoreID: store.StoreID,
  514. StoreName: store.StoreName,
  515. StoreLocation: store.StoreLocation,
  516. StoreCategory: store.StoreCategory,
  517. TeamNum: store.TeamNum,
  518. StoreDetail: store.StoreDetail,
  519. CreatedAt: store.CreatedAt.Format("2006-01-02 15:04:05"),
  520. PhotoUrl: photoUrl,
  521. }
  522. }
  523. reLocalDetail.StoreInfo = &reStore
  524. var reTeamBuying vo.ReTeamBuyingPreview
  525. teamBuying, err := dao.TeamBuyingDao{}.GetTeamBuyingByID(localLife.TeamBuyingId)
  526. if err == nil {
  527. photoUrl, e := dao.ProductPhotoDAO{}.GetMainPhotoByTeamBuyingID(teamBuying.TeamBuyingID)
  528. if e != nil {
  529. photoUrl = ""
  530. }
  531. reTeamBuying = vo.ReTeamBuyingPreview{
  532. TeamBuyingID: teamBuying.TeamBuyingID,
  533. TeamBuyingName: teamBuying.TeamBuyingName,
  534. TeamBuyingPrice: teamBuying.TeamBuyingPrice,
  535. TeamBuyingCategory: teamBuying.TeamBuyingCategory,
  536. TeamBuyingDetail: teamBuying.TeamBuyingDetail,
  537. CreatedAt: teamBuying.CreatedAt.Format("2006-01-02 15:04:05"),
  538. PhotoUrl: photoUrl,
  539. }
  540. }
  541. reLocalDetail.TeamBuyingInfo = &reTeamBuying
  542. reLocalDetail.PromoteBody = localLife.PromoteBody
  543. reLocalDetail.Donate = localLife.Donate
  544. // 招募要求
  545. reLocalDetail.TalentType = localLife.TalentType
  546. reLocalDetail.RecruitDdl = localLife.RecruitDdl.Format("2006-01-02 15:04:05")
  547. var recruitStrategysPreviews []*vo.LocalRecruitStrategy
  548. recruitStrategys, err := dao.RecruitStrategyDao{}.GetRecruitStrategyByProjectId(localId)
  549. if err != nil {
  550. logrus.Errorf("[localLifeDB service] call GetRecruitStrategy error,err:%+v", err)
  551. return nil, err
  552. }
  553. for _, recruitStrategy := range recruitStrategys {
  554. recruitStrategysPreview := &vo.LocalRecruitStrategy{
  555. StrategyId: recruitStrategy.StrategyID,
  556. FeeForm: recruitStrategy.FeeForm,
  557. FollowersLow: recruitStrategy.FollowersLow,
  558. FollowersUp: recruitStrategy.FollowersUp,
  559. RecruitNumber: recruitStrategy.RecruitNumber,
  560. Offer: recruitStrategy.Offer,
  561. TOffer: recruitStrategy.TOffer,
  562. ServiceCharge: recruitStrategy.ServiceCharge,
  563. SelectedNumber: recruitStrategy.SelectedNumber,
  564. TotalOffer: recruitStrategy.TotalOffer,
  565. }
  566. recruitStrategysPreviews = append(recruitStrategysPreviews, recruitStrategysPreview)
  567. }
  568. reLocalDetail.RecruitStrategys = recruitStrategysPreviews
  569. // 执行要求
  570. reLocalDetail.TaskForm = localLife.TaskForm
  571. reLocalDetail.ContentType = localLife.ContentType
  572. reLocalDetail.TaskDetail = localLife.TaskDetail
  573. taskBriefInfos, err := dao.ProjectBriefDao{}.GetProjectBriefInfo(localId)
  574. if err != nil {
  575. logrus.Errorf("[localLifeDB service] call GetProjectBriefInfo error,err:%+v", err)
  576. return nil, err
  577. }
  578. taskMaterials, err := dao.ProjectMaterialDao{}.GetProjectMaterialInfo(localId)
  579. if err != nil {
  580. logrus.Errorf("[localLifeDB service] call GetprojectMaterialInfo error,err:%+v", err)
  581. return nil, err
  582. }
  583. reLocalDetail.TaskBriefs = taskBriefInfos
  584. reLocalDetail.TaskMaterials = taskMaterials
  585. reLocalDetail.Tools = localLife.Tools
  586. return &reLocalDetail, nil
  587. }
  588. // 复制本地生活任务
  589. func (s LocalLifeService) CopyLocalLife(param *vo.LocalSearchParam) (*string, error) {
  590. localLifeOrigin, err := dao.LocalLifeDao{}.GetLocalById(param.LocalId)
  591. if err != nil {
  592. logrus.Errorf("[localLifeDB service] call GetLocalById error,err:%+v", err)
  593. return nil, err
  594. }
  595. if localLifeOrigin == nil {
  596. return nil, errors.New("任务不存在")
  597. }
  598. localIdOrigin := localLifeOrigin.LocalID
  599. localIdNew := strings.ReplaceAll(util.GenerateUUID(11), "-", "")
  600. t := time.Now()
  601. // 获取定时任务配置id
  602. infoAutoTask := entity.InfoAutoTask{}
  603. infoAutoTask = dao.InfoAutoTaskDao{}.GetAutoTaskLast(param.EnterpriseId)
  604. infoAutoDefault := entity.InfoAutoDefault{}
  605. infoAutoDefault = dao.InfoAutoDefaultDao{}.GetAutoDefaultLast(param.EnterpriseId)
  606. // 复制任务
  607. localLifeNew := entity.LocalLifeInfo{
  608. EnterpriseID: param.EnterpriseId,
  609. SubAccountID: param.SubAccountId,
  610. OperatorType: localLifeOrigin.OperatorType,
  611. TaskStatus: 1,
  612. LocalID: localIdNew,
  613. LocalType: localLifeOrigin.LocalType,
  614. LocalPlatform: localLifeOrigin.LocalPlatform,
  615. StoreID: localLifeOrigin.StoreID,
  616. StoreRelatedAt: t,
  617. PromoteBody: localLifeOrigin.PromoteBody,
  618. Donate: localLifeOrigin.Donate,
  619. TeamBuyingId: localLifeOrigin.TeamBuyingId,
  620. TeamBuyingRelatedAt: t,
  621. CreatedAt: t,
  622. AutoTaskID: infoAutoTask.AutoTaskID,
  623. AutoDefaultID: infoAutoDefault.AutoDefaultID,
  624. LocalName: localLifeOrigin.LocalName,
  625. TalentType: localLifeOrigin.TalentType,
  626. RecruitDdl: localLifeOrigin.RecruitDdl,
  627. TaskForm: localLifeOrigin.TaskForm,
  628. ContentType: localLifeOrigin.ContentType,
  629. TaskDetail: localLifeOrigin.TaskDetail,
  630. ServiceChargeRate: localLifeOrigin.ServiceChargeRate,
  631. EstimatedCost: localLifeOrigin.EstimatedCost,
  632. }
  633. err = dao.LocalLifeDao{}.CreateLocalLife(localLifeNew)
  634. if err != nil {
  635. return nil, err
  636. }
  637. // 更新选品brief和示例(本地生活任务补充信息)
  638. localBriefInfos, err := dao.LocalLifeBriefDao{}.GetLocalBriefInfo(localIdOrigin)
  639. if err != nil {
  640. logrus.Errorf("[projectDB service] call GetLocalBriefInfo error,err:%+v", err)
  641. return nil, err
  642. }
  643. if localBriefInfos != nil {
  644. for _, v := range localBriefInfos {
  645. brief := entity.LocalLifeBrief{
  646. LocalID: localIdNew,
  647. FileUid: v.FileUid,
  648. FileName: v.FileName,
  649. FileUrl: v.FileUrl,
  650. CreatedAt: time.Now(),
  651. Type: v.Type,
  652. }
  653. err = dao.LocalLifeBriefDao{}.CreateLocalBrief(brief)
  654. if err != nil {
  655. return nil, err
  656. }
  657. }
  658. }
  659. localMaterials, err := dao.LocalLifeMaterialDao{}.GetLocalMaterialInfo(localIdOrigin)
  660. if err != nil {
  661. logrus.Errorf("[projectDB service] call GetLocalMaterialInfo error,err:%+v", err)
  662. return nil, err
  663. }
  664. if localMaterials != nil {
  665. for _, v := range localMaterials {
  666. material := entity.LocalLifeMaterial{
  667. LocalID: localIdNew,
  668. FileUid: v.FileUid,
  669. FileName: v.FileName,
  670. FileUrl: v.FileUrl,
  671. CreatedAt: time.Now(),
  672. Type: v.Type,
  673. }
  674. err = dao.LocalLifeMaterialDao{}.CreateLocalMaterial(material)
  675. if err != nil {
  676. return nil, err
  677. }
  678. }
  679. }
  680. // 更新本地生活任务的招募策略
  681. recruitStrategys, err := dao.RecruitStrategyDao{}.GetRecruitStrategyByProjectId(localIdOrigin)
  682. if err != nil {
  683. logrus.Errorf("[localLifeDB service] call GetRecruitStrategy error,err:%+v", err)
  684. return nil, err
  685. }
  686. var totalRecruitNum int64
  687. if recruitStrategys != nil {
  688. // 2. 接收并创建新的招募策略
  689. if len(recruitStrategys) != 0 {
  690. var recruits []entity.RecruitStrategy
  691. for _, strategy := range recruitStrategys {
  692. recruitStrategy := entity.RecruitStrategy{
  693. FeeForm: strategy.FeeForm,
  694. StrategyID: strategy.StrategyID,
  695. FollowersLow: strategy.FollowersLow,
  696. FollowersUp: strategy.FollowersUp,
  697. RecruitNumber: strategy.RecruitNumber,
  698. ProjectID: localIdNew,
  699. StrategyType: strategy.StrategyType,
  700. ServiceRate: strategy.ServiceRate,
  701. Offer: strategy.Offer,
  702. ServiceCharge: strategy.ServiceCharge,
  703. TOffer: strategy.TOffer,
  704. }
  705. totalRecruitNum += strategy.RecruitNumber
  706. recruits = append(recruits, recruitStrategy)
  707. }
  708. err = dao.RecruitStrategyDao{}.CreateRecruitStrategy(recruits)
  709. if err != nil {
  710. return nil, err
  711. }
  712. }
  713. }
  714. return &localIdNew, nil
  715. }
  716. // 本地生活提交审核
  717. func (s LocalLifeService) LocalLifeToReview(localUpdateParam *vo.LocalUpdateParam) (*string, error) {
  718. localId := localUpdateParam.LocalID
  719. local, err := dao.LocalLifeDao{}.GetLocalById(localId)
  720. if err != nil {
  721. logrus.Errorf("[projectInfoDB service] call GetProject error,err:%+v", err)
  722. return nil, err
  723. }
  724. localName := local.LocalName // 任务标题
  725. localDetail := local.TaskDetail // 任务详情
  726. store, err := dao.StoreDao{}.GetStoreByID(local.StoreID)
  727. if err != nil {
  728. return nil, err
  729. }
  730. storeName := store.StoreName // 门店名称
  731. storeDetail := store.StoreDetail // 门店特点
  732. storeMainPhoto, err1 := dao.ProductPhotoDAO{}.GetMainPhotoByStoreID(store.StoreID)
  733. if err1 != nil {
  734. return nil, err1
  735. }
  736. teamBuying, err2 := dao.TeamBuyingDao{}.GetTeamBuyingByID(local.TeamBuyingId)
  737. if err2 != nil {
  738. return nil, err2
  739. }
  740. teamBuyingName := teamBuying.TeamBuyingName // 团购标题
  741. teamBuyingDetail := teamBuying.TeamBuyingDetail // 团购详情
  742. teamBuyingMainPhoto, err3 := dao.ProductPhotoDAO{}.GetMainPhotoByTeamBuyingID(teamBuying.TeamBuyingID)
  743. if err3 != nil {
  744. return nil, err3
  745. }
  746. var images []string
  747. var videos []string
  748. var videoJobIds []string
  749. var documents []string
  750. var documentJobIds []string
  751. reviewService := review_service.GetConfig()
  752. storePhotos, err4 := dao.ProductPhotoDAO{}.GetProductPhotoByStoreID(local.StoreID)
  753. if err4 != nil {
  754. return nil, err4
  755. }
  756. for _, storePhoto := range storePhotos {
  757. if storePhoto.Symbol == 2 || storePhoto.Symbol == 4 {
  758. images = append(images, storePhoto.PhotoUrl)
  759. } else if storePhoto.Symbol == 3 || storePhoto.Symbol == 5 {
  760. var videoJobId *string
  761. var reviewErr error
  762. i := 10
  763. for {
  764. videoJobId, reviewErr = reviewService.CheckVideo(storePhoto.PhotoUrl)
  765. if reviewErr == nil || i == 0 {
  766. break
  767. }
  768. i -= 1
  769. }
  770. if reviewErr != nil {
  771. return nil, reviewErr
  772. }
  773. videos = append(videos, storePhoto.PhotoUrl)
  774. videoJobIds = append(videoJobIds, *videoJobId)
  775. }
  776. }
  777. teamBuyingPhotos, err5 := dao.ProductPhotoDAO{}.GetProductPhotoByTeamBuyingID(local.TeamBuyingId)
  778. if err5 != nil {
  779. return nil, err5
  780. }
  781. for _, teamBuyingPhoto := range teamBuyingPhotos {
  782. if teamBuyingPhoto.Symbol == 2 || teamBuyingPhoto.Symbol == 4 {
  783. images = append(images, teamBuyingPhoto.PhotoUrl)
  784. } else if teamBuyingPhoto.Symbol == 3 || teamBuyingPhoto.Symbol == 5 {
  785. var videoJobId *string
  786. var reviewErr error
  787. i := 10
  788. for {
  789. videoJobId, reviewErr = reviewService.CheckVideo(teamBuyingPhoto.PhotoUrl)
  790. if reviewErr == nil || i == 0 {
  791. break
  792. }
  793. i -= 1
  794. }
  795. if reviewErr != nil {
  796. return nil, reviewErr
  797. }
  798. videos = append(videos, teamBuyingPhoto.PhotoUrl)
  799. videoJobIds = append(videoJobIds, *videoJobId)
  800. }
  801. }
  802. localBriefInfos, err6 := dao.LocalLifeBriefDao{}.GetLocalBriefInfo(localId)
  803. if err6 != nil {
  804. return nil, err6
  805. }
  806. for _, localBriefInfo := range localBriefInfos {
  807. if localBriefInfo.Type == 1 {
  808. images = append(images, localBriefInfo.FileUrl)
  809. } else if localBriefInfo.Type == 2 {
  810. var documentJobId *string
  811. var reviewErr error
  812. i := 10
  813. fileType := "pdf"
  814. parts := strings.Split(localBriefInfo.FileName, ".")
  815. if len(parts) > 1 {
  816. fileType = parts[len(parts)-1]
  817. }
  818. for {
  819. documentJobId, reviewErr = reviewService.CheckDocument(localBriefInfo.FileUrl, fileType)
  820. if reviewErr == nil || i == 0 {
  821. break
  822. }
  823. i -= 1
  824. }
  825. if reviewErr != nil {
  826. return nil, reviewErr
  827. }
  828. documents = append(documents, localBriefInfo.FileUrl)
  829. documentJobIds = append(documentJobIds, *documentJobId)
  830. }
  831. }
  832. localMaterials, err7 := dao.LocalLifeMaterialDao{}.GetLocalMaterialInfo(localId)
  833. if err7 != nil {
  834. return nil, err7
  835. }
  836. for _, localMaterial := range localMaterials {
  837. if localMaterial.Type == 1 {
  838. images = append(images, localMaterial.FileUrl)
  839. } else if localMaterial.Type == 2 {
  840. var videoJobId *string
  841. var reviewErr error
  842. i := 10
  843. for {
  844. videoJobId, reviewErr = reviewService.CheckVideo(localMaterial.FileUrl)
  845. if reviewErr == nil || i == 0 {
  846. break
  847. }
  848. i -= 1
  849. }
  850. if reviewErr != nil {
  851. return nil, reviewErr
  852. }
  853. videos = append(videos, localMaterial.FileUrl)
  854. videoJobIds = append(videoJobIds, *videoJobId)
  855. }
  856. }
  857. newReviewLocal := &entity.ReviewLocalLife{
  858. LocalID: localId,
  859. TaskName: localName,
  860. TaskDetail: localDetail,
  861. StoreMainPhoto: storeMainPhoto,
  862. StoreName: storeName,
  863. StoreDetail: storeDetail,
  864. TeamBuyingMainPhoto: teamBuyingMainPhoto,
  865. TeamBuyingName: teamBuyingName,
  866. TeamBuyingDetail: teamBuyingDetail,
  867. Images: strings.Join(images, ","),
  868. Videos: strings.Join(videos, ","),
  869. Documents: strings.Join(documents, ","),
  870. VideoJobIds: strings.Join(videoJobIds, ","),
  871. DocumentJobIds: strings.Join(documentJobIds, ","),
  872. Status: 1,
  873. }
  874. err8 := dao.LocalLifeReviewDao{}.Create(newReviewLocal)
  875. if err8 != nil {
  876. return nil, err8
  877. }
  878. t := time.Now()
  879. updateLocal := entity.LocalLifeInfo{
  880. LocalID: localId,
  881. TaskStatus: 2,
  882. SubmitAt: t,
  883. UpdatedAt: t,
  884. }
  885. err9 := dao.LocalLifeDao{}.UpdateLocal(updateLocal)
  886. if err9 != nil {
  887. return nil, err9
  888. }
  889. return &localId, nil
  890. }
  891. // 本地生活任务列表
  892. func (s LocalLifeService) GetLocalLifeTaskList(param *vo.LocalSearchParam) (vo.ResultVO, error) {
  893. if param.Page == 0 {
  894. param.Page = 1
  895. }
  896. if param.PageSize == 0 {
  897. param.PageSize = 10
  898. }
  899. var result vo.ResultVO
  900. reLocalTaskPreviews, total, err := (&dao.LocalLifeDao{}).GetLocalPreviews(param)
  901. if err != nil {
  902. return result, err
  903. }
  904. for i := range reLocalTaskPreviews {
  905. var creatorName string
  906. var storeName string
  907. var storeLocation string
  908. var mainImage string
  909. if reLocalTaskPreviews[i].SubAccountId == 0 {
  910. enterprise, err := dao.EnterpriseDao{}.GetEnterprise(reLocalTaskPreviews[i].EnterpriseId)
  911. if err == nil && enterprise != nil {
  912. creatorName = enterprise.BusinessName
  913. }
  914. } else {
  915. subAccount, err := dao.SubAccountDao{}.GetSubAccount(reLocalTaskPreviews[i].SubAccountId)
  916. if err == nil && subAccount != nil {
  917. creatorName = subAccount.SubAccountName
  918. }
  919. }
  920. store, err := dao.StoreDao{}.GetStoreByID(reLocalTaskPreviews[i].StoreId)
  921. if err == nil && store != nil {
  922. storeName = store.StoreName
  923. storeLocation = store.StoreLocation
  924. }
  925. mainImage, err = dao.ProductPhotoDAO{}.GetMainPhotoByStoreID(reLocalTaskPreviews[i].StoreId)
  926. reLocalTaskPreviews[i].CreatorName = creatorName
  927. reLocalTaskPreviews[i].StoreName = storeName
  928. reLocalTaskPreviews[i].StoreLocation = storeLocation
  929. reLocalTaskPreviews[i].MainImage = mainImage
  930. }
  931. result = vo.ResultVO{
  932. Page: param.Page,
  933. PageSize: param.PageSize,
  934. Total: total,
  935. Data: reLocalTaskPreviews,
  936. }
  937. return result, nil
  938. }
  939. // 删除本地生活任务
  940. func (s LocalLifeService) DeleteLocalLife(localId string) (*string, error) {
  941. res, err := dao.LocalLifeDao{}.DeleteLocalLife(localId)
  942. if err != nil {
  943. logrus.Errorf("[DeleteLocalLife service] call DeleteLocalLife error,err:%+v", err)
  944. return res, err
  945. }
  946. return res, nil
  947. }
  948. // 结束本地生活任务
  949. func (s LocalLifeService) CloseLocalLife(localId string) (*string, error) {
  950. err := dao.LocalLifeDao{}.UpdateLocal(entity.LocalLifeInfo{
  951. LocalID: localId,
  952. TaskStatus: 10,
  953. UpdatedAt: time.Now(),
  954. })
  955. return &localId, err
  956. }
  957. // 草稿箱——本地生活
  958. func (s LocalLifeService) GetLocalLifeDraftList(param *vo.LocalDraftParam) (vo.ResultVO, error) {
  959. if param.Page == 0 {
  960. param.Page = 1
  961. }
  962. if param.PageSize == 0 {
  963. param.PageSize = 10
  964. }
  965. var result vo.ResultVO
  966. reLocalTaskPreviews, total, err := (&dao.LocalLifeDao{}).GetLocalDraftList(param)
  967. if err != nil {
  968. return result, err
  969. }
  970. for i := range reLocalTaskPreviews {
  971. var creatorName string
  972. var storeName string
  973. var storeLocation string
  974. var mainImage string
  975. if reLocalTaskPreviews[i].SubAccountId == 0 {
  976. enterprise, err := dao.EnterpriseDao{}.GetEnterprise(reLocalTaskPreviews[i].EnterpriseId)
  977. if err == nil && enterprise != nil {
  978. creatorName = enterprise.BusinessName
  979. }
  980. } else {
  981. subAccount, err := dao.SubAccountDao{}.GetSubAccount(reLocalTaskPreviews[i].SubAccountId)
  982. if err == nil && subAccount != nil {
  983. creatorName = subAccount.SubAccountName
  984. }
  985. }
  986. store, err := dao.StoreDao{}.GetStoreByID(reLocalTaskPreviews[i].StoreId)
  987. if err == nil && store != nil {
  988. storeName = store.StoreName
  989. storeLocation = store.StoreLocation
  990. }
  991. mainImage, err = dao.ProductPhotoDAO{}.GetMainPhotoByStoreID(reLocalTaskPreviews[i].StoreId)
  992. reLocalTaskPreviews[i].CreatorName = creatorName
  993. reLocalTaskPreviews[i].StoreName = storeName
  994. reLocalTaskPreviews[i].StoreLocation = storeLocation
  995. reLocalTaskPreviews[i].MainImage = mainImage
  996. }
  997. result = vo.ResultVO{
  998. Page: param.Page,
  999. PageSize: param.PageSize,
  1000. Total: total,
  1001. Data: reLocalTaskPreviews,
  1002. }
  1003. return result, nil
  1004. }
  1005. // 探店本地生活列表
  1006. func (s LocalLifeService) GetStoreExploreList(param *vo.LocalSearchParam) (vo.ResultVO, error) {
  1007. if param.Page == 0 {
  1008. param.Page = 1
  1009. }
  1010. if param.PageSize == 0 {
  1011. param.PageSize = 10
  1012. }
  1013. var result vo.ResultVO
  1014. reLocalStoreExplorePreviews, total, err := (&dao.LocalLifeDao{}).GetLocalStoreExplorePreviews(param)
  1015. if err != nil {
  1016. return result, err
  1017. }
  1018. for i := range reLocalStoreExplorePreviews {
  1019. var creatorName string
  1020. var storeName string
  1021. var storeLocation string
  1022. var mainImage string
  1023. if reLocalStoreExplorePreviews[i].SubAccountId == 0 {
  1024. enterprise, err := dao.EnterpriseDao{}.GetEnterprise(reLocalStoreExplorePreviews[i].EnterpriseId)
  1025. if err == nil && enterprise != nil {
  1026. creatorName = enterprise.BusinessName
  1027. }
  1028. } else {
  1029. subAccount, err := dao.SubAccountDao{}.GetSubAccount(reLocalStoreExplorePreviews[i].SubAccountId)
  1030. if err == nil && subAccount != nil {
  1031. creatorName = subAccount.SubAccountName
  1032. }
  1033. }
  1034. store, err := dao.StoreDao{}.GetStoreByID(reLocalStoreExplorePreviews[i].StoreId)
  1035. if err == nil && store != nil {
  1036. storeName = store.StoreName
  1037. storeLocation = store.StoreLocation
  1038. }
  1039. mainImage, err = dao.ProductPhotoDAO{}.GetMainPhotoByStoreID(reLocalStoreExplorePreviews[i].StoreId)
  1040. reLocalStoreExplorePreviews[i].CreatorName = creatorName
  1041. reLocalStoreExplorePreviews[i].StoreName = storeName
  1042. reLocalStoreExplorePreviews[i].StoreLocation = storeLocation
  1043. reLocalStoreExplorePreviews[i].MainImage = mainImage
  1044. }
  1045. result = vo.ResultVO{
  1046. Page: param.Page,
  1047. PageSize: param.PageSize,
  1048. Total: total,
  1049. Data: reLocalStoreExplorePreviews,
  1050. }
  1051. return result, nil
  1052. }
  1053. // 探店达人详情
  1054. func (s LocalLifeService) GetStoreExploreInfo(param *vo.StoreExploreParam) (*vo.ResultVO, error) {
  1055. if param.Page <= 0 {
  1056. param.Page = 1
  1057. }
  1058. if param.PageSize <= 0 {
  1059. param.PageSize = 10
  1060. }
  1061. var reStoreExploreTalents []*vo.ReStoreExploreTalent
  1062. var total int64
  1063. result := vo.ResultVO{
  1064. Page: param.Page,
  1065. PageSize: param.PageSize,
  1066. Total: total,
  1067. Data: reStoreExploreTalents,
  1068. }
  1069. var localLifeTaskInfos []*entity.LocalLifeTaskInfo
  1070. var err error
  1071. localLifeId := param.LocalLifeId
  1072. if param.Status == 1 { // 待预约
  1073. localLifeTaskInfos, total, err = dao.LocalLifeTaskInfoDao{}.GetListByTaskStage(localLifeId, 1, "", param.Page, param.PageSize)
  1074. } else if param.Status == 2 { // 待确认
  1075. localLifeTaskInfos, total, err = dao.LocalLifeTaskInfoDao{}.GetListByTaskStage(localLifeId, 2, param.SearchTime, param.Page, param.PageSize)
  1076. } else if param.Status == 3 { // 待探店
  1077. localLifeTaskInfos, total, err = dao.LocalLifeTaskInfoDao{}.GetListByTaskStage(localLifeId, 5, param.SearchTime, param.Page, param.PageSize)
  1078. } else if param.Status == 4 { // 已探店
  1079. localLifeTaskInfos, total, err = dao.LocalLifeTaskInfoDao{}.GetListByTaskStage(localLifeId, 6, param.SearchTime, param.Page, param.PageSize)
  1080. }
  1081. if err != nil {
  1082. return nil, err
  1083. }
  1084. for _, localLifeTaskInfo := range localLifeTaskInfos {
  1085. // 获取达人信息
  1086. talentInfo, err := dao.TalentInfoDao{}.SelectTalentInfo(localLifeTaskInfo.TalentID)
  1087. if err != nil {
  1088. return nil, err
  1089. }
  1090. //regionName, err := dao.RegionInfoDao{}.SelectRegion(talentInfo.VisitStoreRegion)
  1091. //if err != nil {
  1092. // regionName = ""
  1093. //}
  1094. regionName := localLifeTaskInfo.City
  1095. talentPreview := &vo.TalentPreview{
  1096. TalentId: localLifeTaskInfo.TalentID,
  1097. TalentPhoto: talentInfo.Avatar,
  1098. TalentName: talentInfo.TalentWxNickname,
  1099. Account: "",
  1100. Location: regionName,
  1101. Gender: talentInfo.Sex,
  1102. }
  1103. reStoreExploreTalent := &vo.ReStoreExploreTalent{
  1104. ReTalentPreview: talentPreview,
  1105. TaskId: localLifeTaskInfo.TaskID,
  1106. }
  1107. if param.Status == 1 {
  1108. reStoreExploreTalent.CooperateTime = localLifeTaskInfo.SelectDate.Format("2006-01-02 15:04:05")
  1109. } else if param.Status == 2 {
  1110. reStoreExploreTalent.ReserveTime = localLifeTaskInfo.ReserveTime.Format("2006-01-02 15:04:05")
  1111. } else if param.Status == 3 {
  1112. reStoreExploreTalent.ExploreTime = localLifeTaskInfo.ExploreTime.Format("2006-01-02 15:04:05")
  1113. reStoreExploreTalent.Operator = ""
  1114. } else if param.Status == 4 {
  1115. reStoreExploreTalent.FinishExploreTime = localLifeTaskInfo.FinishExploreTime.Format("2006-01-02 15:04:05")
  1116. reStoreExploreTalent.Operator = ""
  1117. }
  1118. reStoreExploreTalents = append(reStoreExploreTalents, reStoreExploreTalent)
  1119. }
  1120. result = vo.ResultVO{
  1121. Page: param.Page,
  1122. PageSize: param.PageSize,
  1123. Total: total,
  1124. Data: reStoreExploreTalents,
  1125. }
  1126. return &result, nil
  1127. }
  1128. // 探店达人列表角标
  1129. func (t LocalLifeService) StoreExploreInfoCount(param *vo.StoreExploreParam) map[string]int64 {
  1130. res := make(map[string]int64)
  1131. var needBook int64
  1132. var needConfirm int64
  1133. var needExplore int64
  1134. var explored int64
  1135. dao.Db.Model(&entity.LocalLifeTaskInfo{}).Where("local_id = ? AND book_status = ?", param.LocalLifeId, 1).Count(&needBook)
  1136. dao.Db.Model(&entity.LocalLifeTaskInfo{}).Where("local_id = ? AND book_status = ?", param.LocalLifeId, 2).Count(&needConfirm)
  1137. dao.Db.Model(&entity.LocalLifeTaskInfo{}).Where("local_id = ? AND book_status = ?", param.LocalLifeId, 5).Count(&needExplore)
  1138. dao.Db.Model(&entity.LocalLifeTaskInfo{}).Where("local_id = ? AND book_status = ?", param.LocalLifeId, 6).Count(&explored)
  1139. res["needBook"] = needBook
  1140. res["needConfirm"] = needConfirm
  1141. res["needExplore"] = needExplore
  1142. res["explored"] = explored
  1143. return res
  1144. }
  1145. // 终止合作
  1146. func (s LocalLifeService) StoreExploreOver(param *vo.LocalTalentOperateParam) (*string, error) {
  1147. taskId := param.TaskId
  1148. if taskId == "" {
  1149. return nil, errors.New("taskId is empty")
  1150. }
  1151. updateData := map[string]interface{}{
  1152. "task_stage": 17,
  1153. "terminate_reason": param.Reason,
  1154. "terminate_time": time.Now(),
  1155. }
  1156. if param.SubAccountId == 0 {
  1157. updateData["terminate_operator_type"] = 1
  1158. updateData["terminate_operator"] = param.EnterpriseId
  1159. } else {
  1160. updateData["terminate_operator_type"] = 2
  1161. updateData["terminate_operator"] = param.SubAccountId
  1162. }
  1163. err := dao.LocalLifeTaskInfoDao{}.UpdateField(param.TaskId, updateData)
  1164. if err != nil {
  1165. return nil, err
  1166. }
  1167. return &taskId, nil
  1168. }
  1169. // 预约时间批量同意/驳回
  1170. func (s LocalLifeService) StoreExploreOperate(param *vo.LocalTalentOperateParam) error {
  1171. taskIds := param.TaskIds
  1172. if taskIds == nil {
  1173. return errors.New("taskIds is empty")
  1174. }
  1175. var bookIds []int64
  1176. for _, taskId := range taskIds {
  1177. bookInfo, err := dao.BookInfoDao{}.GetLastByTaskId(taskId)
  1178. if err != nil {
  1179. return err
  1180. }
  1181. bookIds = append(bookIds, bookInfo.BookID)
  1182. }
  1183. var bookinfoNew entity.BookInfo
  1184. if param.Status == 2 {
  1185. bookinfoNew = entity.BookInfo{
  1186. IsReview: 1,
  1187. IsOk: 2,
  1188. RejectAt: time.Now(),
  1189. ReviseOpinion: param.Reason,
  1190. }
  1191. } else if param.Status == 1 {
  1192. bookinfoNew = entity.BookInfo{
  1193. IsReview: 1,
  1194. IsOk: 1,
  1195. AgreeAt: time.Now(),
  1196. }
  1197. } else {
  1198. return errors.New("status error")
  1199. }
  1200. if param.SubAccountId == 0 {
  1201. bookinfoNew.BOperatorType = 1
  1202. bookinfoNew.BOperator = param.EnterpriseId
  1203. } else {
  1204. bookinfoNew.BOperatorType = 2
  1205. bookinfoNew.BOperator = strconv.FormatInt(param.SubAccountId, 10)
  1206. }
  1207. err1 := dao.BookInfoDao{}.UpdateBookStatus(bookIds, bookinfoNew)
  1208. if err1 != nil {
  1209. return err1
  1210. }
  1211. if param.Status == 1 {
  1212. err2 := dao.LocalLifeTaskInfoDao{}.UpdateLocalStatus(taskIds, entity.LocalLifeTaskInfo{
  1213. TaskStage: 7,
  1214. BookStatus: 5,
  1215. })
  1216. if err2 != nil {
  1217. return err2
  1218. }
  1219. }
  1220. return nil
  1221. }
  1222. // 本地生活任务待办
  1223. func (p LocalLifeService) GetTaskToDo(enterpriseId string, subAccountId int64, taskType int64) (map[string]map[string]int64, error) {
  1224. res := make(map[string]map[string]int64)
  1225. redbook, err1 := dao.LocalLifeDao{}.GetLocalLifeToDo(enterpriseId, subAccountId, 1, taskType)
  1226. if err1 != nil {
  1227. logrus.Errorf("[GetLocalLifeToDo service] call GetLocalLifeToDo error,err:%+v", err1)
  1228. return res, err1
  1229. }
  1230. douyin, err2 := dao.LocalLifeDao{}.GetLocalLifeToDo(enterpriseId, subAccountId, 2, taskType)
  1231. if err2 != nil {
  1232. logrus.Errorf("[GetLocalLifeToDo service] call GetLocalLifeToDo error,err:%+v", err2)
  1233. return res, err2
  1234. }
  1235. kuaishou, err3 := dao.LocalLifeDao{}.GetLocalLifeToDo(enterpriseId, subAccountId, 4, taskType)
  1236. if err3 != nil {
  1237. logrus.Errorf("[GetLocalLifeToDo service] call GetLocalLifeToDo error,err:%+v", err3)
  1238. return res, err3
  1239. }
  1240. weibo, err4 := dao.LocalLifeDao{}.GetLocalLifeToDo(enterpriseId, subAccountId, 3, taskType)
  1241. if err4 != nil {
  1242. logrus.Errorf("[GetLocalLifeToDo service] call GetLocalLifeToDo error,err:%+v", err4)
  1243. return res, err4
  1244. }
  1245. bilibili, err5 := dao.LocalLifeDao{}.GetLocalLifeToDo(enterpriseId, subAccountId, 5, taskType)
  1246. if err5 != nil {
  1247. logrus.Errorf("[GetLocalLifeToDo service] call GetLocalLifeToDo error,err:%+v", err5)
  1248. return res, err5
  1249. }
  1250. all := make(map[string]int64)
  1251. all["needReview"] = redbook["needReview"] + douyin["needReview"] + kuaishou["needReview"] + weibo["needReview"] + bilibili["needReview"]
  1252. all["needPay"] = redbook["needPay"] + douyin["needPay"] + kuaishou["needPay"] + weibo["needPay"] + bilibili["needPay"]
  1253. all["needProcess"] = redbook["needProcess"] + douyin["needProcess"] + kuaishou["needProcess"] + weibo["needProcess"] + bilibili["needProcess"]
  1254. all["needCheck"] = redbook["needCheck"] + douyin["needCheck"] + kuaishou["needCheck"] + weibo["needCheck"] + bilibili["needCheck"]
  1255. all["needQuality"] = redbook["needQuality"] + douyin["needQuality"] + kuaishou["needQuality"] + weibo["needQuality"] + bilibili["needQuality"]
  1256. all["needCalculate"] = redbook["needCalculate"] + douyin["needCalculate"] + kuaishou["needCalculate"] + weibo["needCalculate"] + bilibili["needCalculate"]
  1257. res["redbook"] = redbook
  1258. res["douyin"] = douyin
  1259. res["kuaishou"] = kuaishou
  1260. res["weibo"] = weibo
  1261. res["bilibili"] = bilibili
  1262. res["all"] = all
  1263. return res, nil
  1264. }
  1265. // 探店邀约任务待办
  1266. func (p LocalLifeService) GetExploreToDo(enterpriseId string, subAccountId int64) (map[string]map[string]int64, error) {
  1267. res := make(map[string]map[string]int64)
  1268. redbook, err1 := dao.LocalLifeDao{}.GetExploreToDo(enterpriseId, subAccountId, 1)
  1269. if err1 != nil {
  1270. logrus.Errorf("[GetLocalLifeToDo service] call GetLocalLifeToDo error,err:%+v", err1)
  1271. return res, err1
  1272. }
  1273. douyin, err2 := dao.LocalLifeDao{}.GetExploreToDo(enterpriseId, subAccountId, 2)
  1274. if err2 != nil {
  1275. logrus.Errorf("[GetLocalLifeToDo service] call GetLocalLifeToDo error,err:%+v", err2)
  1276. return res, err2
  1277. }
  1278. kuaishou, err3 := dao.LocalLifeDao{}.GetExploreToDo(enterpriseId, subAccountId, 4)
  1279. if err3 != nil {
  1280. logrus.Errorf("[GetLocalLifeToDo service] call GetLocalLifeToDo error,err:%+v", err3)
  1281. return res, err3
  1282. }
  1283. weibo, err4 := dao.LocalLifeDao{}.GetExploreToDo(enterpriseId, subAccountId, 3)
  1284. if err4 != nil {
  1285. logrus.Errorf("[GetLocalLifeToDo service] call GetLocalLifeToDo error,err:%+v", err4)
  1286. return res, err4
  1287. }
  1288. bilibili, err5 := dao.LocalLifeDao{}.GetExploreToDo(enterpriseId, subAccountId, 5)
  1289. if err5 != nil {
  1290. logrus.Errorf("[GetLocalLifeToDo service] call GetLocalLifeToDo error,err:%+v", err5)
  1291. return res, err5
  1292. }
  1293. all := make(map[string]int64)
  1294. all["needBook"] = redbook["needBook"] + douyin["needBook"] + kuaishou["needBook"] + weibo["needBook"] + bilibili["needBook"]
  1295. all["needConfirm"] = redbook["needConfirm"] + douyin["needConfirm"] + kuaishou["needConfirm"] + weibo["needConfirm"] + bilibili["needConfirm"]
  1296. all["needExplore"] = redbook["needExplore"] + douyin["needExplore"] + kuaishou["needExplore"] + weibo["needExplore"] + bilibili["needExplore"]
  1297. res["redbook"] = redbook
  1298. res["douyin"] = douyin
  1299. res["kuaishou"] = kuaishou
  1300. res["weibo"] = weibo
  1301. res["bilibili"] = bilibili
  1302. res["all"] = all
  1303. return res, nil
  1304. }
  1305. // 违约管理任务待办
  1306. func (p LocalLifeService) GetDefaultToDo(enterpriseId string, subAccountId int64, taskType int64) (map[string]map[string]int64, error) {
  1307. res := make(map[string]map[string]int64)
  1308. redbook, err1 := dao.LocalLifeDao{}.GetDefaultToDo(enterpriseId, subAccountId, 1, taskType)
  1309. if err1 != nil {
  1310. logrus.Errorf("[GetLocalLifeToDo service] call GetLocalLifeToDo error,err:%+v", err1)
  1311. return res, err1
  1312. }
  1313. douyin, err2 := dao.LocalLifeDao{}.GetDefaultToDo(enterpriseId, subAccountId, 2, taskType)
  1314. if err2 != nil {
  1315. logrus.Errorf("[GetLocalLifeToDo service] call GetLocalLifeToDo error,err:%+v", err2)
  1316. return res, err2
  1317. }
  1318. kuaishou, err3 := dao.LocalLifeDao{}.GetDefaultToDo(enterpriseId, subAccountId, 4, taskType)
  1319. if err3 != nil {
  1320. logrus.Errorf("[GetLocalLifeToDo service] call GetLocalLifeToDo error,err:%+v", err3)
  1321. return res, err3
  1322. }
  1323. weibo, err4 := dao.LocalLifeDao{}.GetDefaultToDo(enterpriseId, subAccountId, 3, taskType)
  1324. if err4 != nil {
  1325. logrus.Errorf("[GetLocalLifeToDo service] call GetLocalLifeToDo error,err:%+v", err4)
  1326. return res, err4
  1327. }
  1328. bilibili, err5 := dao.LocalLifeDao{}.GetDefaultToDo(enterpriseId, subAccountId, 5, taskType)
  1329. if err5 != nil {
  1330. logrus.Errorf("[GetLocalLifeToDo service] call GetLocalLifeToDo error,err:%+v", err5)
  1331. return res, err5
  1332. }
  1333. all := make(map[string]int64)
  1334. all["noSketch"] = redbook["noSketch"] + douyin["noSketch"] + kuaishou["noSketch"] + weibo["noSketch"] + bilibili["noSketch"]
  1335. all["noWork"] = redbook["noWork"] + douyin["noWork"] + kuaishou["noWork"] + weibo["noWork"] + bilibili["noWork"]
  1336. all["noData"] = redbook["noData"] + douyin["noData"] + kuaishou["noData"] + weibo["noData"] + bilibili["noData"]
  1337. all["cooperateOver"] = redbook["cooperateOver"] + douyin["cooperateOver"] + kuaishou["cooperateOver"] + weibo["cooperateOver"] + bilibili["cooperateOver"]
  1338. res["redbook"] = redbook
  1339. res["douyin"] = douyin
  1340. res["kuaishou"] = kuaishou
  1341. res["weibo"] = weibo
  1342. res["bilibili"] = bilibili
  1343. res["all"] = all
  1344. return res, nil
  1345. }
  1346. // 合作待办-任务邀约
  1347. func (p LocalLifeService) GetTaskInviteToDo(enterpriseId string, subAccountId int64) (map[string]map[string]int64, error) {
  1348. res := make(map[string]map[string]int64)
  1349. redbook, err1 := dao.LocalLifeDao{}.GetTaskInviteToDo(enterpriseId, subAccountId, 1)
  1350. if err1 != nil {
  1351. logrus.Errorf("[GetTaskInviteToDo service] call GetTaskInviteToDo error,err:%+v", err1)
  1352. return res, err1
  1353. }
  1354. douyin, err2 := dao.LocalLifeDao{}.GetTaskInviteToDo(enterpriseId, subAccountId, 2)
  1355. if err2 != nil {
  1356. logrus.Errorf("[GetTaskInviteToDo service] call GetTaskInviteToDo error,err:%+v", err2)
  1357. return res, err2
  1358. }
  1359. kuaishou, err3 := dao.LocalLifeDao{}.GetTaskInviteToDo(enterpriseId, subAccountId, 4)
  1360. if err3 != nil {
  1361. logrus.Errorf("[GetTaskInviteToDo service] call GetTaskInviteToDo error,err:%+v", err3)
  1362. return res, err3
  1363. }
  1364. weibo, err4 := dao.LocalLifeDao{}.GetTaskInviteToDo(enterpriseId, subAccountId, 3)
  1365. if err4 != nil {
  1366. logrus.Errorf("[GetTaskInviteToDo service] call GetTaskInviteToDo error,err:%+v", err4)
  1367. return res, err4
  1368. }
  1369. bilibili, err5 := dao.LocalLifeDao{}.GetTaskInviteToDo(enterpriseId, subAccountId, 5)
  1370. if err5 != nil {
  1371. logrus.Errorf("[GetTaskInviteToDo service] call GetTaskInviteToDo error,err:%+v", err5)
  1372. return res, err5
  1373. }
  1374. all := make(map[string]int64)
  1375. all["availInvitationNum"] = redbook["availInvitationNum"] + douyin["availInvitationNum"] + kuaishou["availInvitationNum"] + weibo["availInvitationNum"] + bilibili["availInvitationNum"]
  1376. all["invitingNum"] = redbook["invitingNum"] + douyin["invitingNum"] + kuaishou["invitingNum"] + weibo["invitingNum"] + bilibili["invitingNum"]
  1377. all["cooperatingNum"] = redbook["cooperatingNum"] + douyin["cooperatingNum"] + kuaishou["cooperatingNum"] + weibo["cooperatingNum"] + bilibili["cooperatingNum"]
  1378. res["redbook"] = redbook
  1379. res["douyin"] = douyin
  1380. res["kuaishou"] = kuaishou
  1381. res["weibo"] = weibo
  1382. res["bilibili"] = bilibili
  1383. res["all"] = all
  1384. return res, nil
  1385. }