local_life_service.go 50 KB

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