local_life_service.go 51 KB

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