local_life_service.go 50 KB

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