local_life_service.go 50 KB

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