local_life_service.go 50 KB

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