project.go 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730
  1. package service
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. "math/rand"
  7. "strconv"
  8. "strings"
  9. "time"
  10. "youngee_m_api/db"
  11. "youngee_m_api/model/common_model"
  12. "youngee_m_api/model/gorm_model"
  13. "youngee_m_api/model/http_model"
  14. "youngee_m_api/pack"
  15. "youngee_m_api/util"
  16. "github.com/caixw/lib.go/conv"
  17. "github.com/gin-gonic/gin"
  18. "github.com/sirupsen/logrus"
  19. )
  20. var Project *project
  21. type project struct {
  22. }
  23. func (*project) GetFullProjectList(ctx context.Context, pageSize, pageNum int32, condition *common_model.ProjectCondition, projectType string) (*http_model.FullProjectListData, error) {
  24. fullProjects, total, err := db.GetFullProjectList(ctx, pageSize, pageNum, condition, projectType)
  25. if err != nil {
  26. logrus.WithContext(ctx).Errorf("[project service] call GetFullProjectList error,err:%+v", err)
  27. return nil, err
  28. }
  29. fullProjectListData := new(http_model.FullProjectListData)
  30. fullProjectListData.FullProjectPreview = pack.MGormFullProjectToHttpFullProjectPreview(fullProjects)
  31. fullProjectListData.Total = conv.MustString(total, "")
  32. return fullProjectListData, nil
  33. }
  34. func (*project) GetProjectDetail(ctx context.Context, projectID string) (*http_model.ShowProjectData, error) {
  35. project, err := db.GetProjectDetail(ctx, projectID)
  36. if err != nil {
  37. logrus.WithContext(ctx).Errorf("[project service] call GetPorjectDetail error,err:%+v", err)
  38. return nil, err
  39. }
  40. enterprise, err := db.GetEnterpriseByEnterpriseID(ctx, project.EnterpriseID)
  41. if err != nil {
  42. logrus.WithContext(ctx).Errorf("[project service] call GetEnterpriseByEnterpriseID error,err:%+v", err)
  43. return nil, err
  44. }
  45. user, err := db.GetUserByID(ctx, enterprise.UserID)
  46. if err != nil {
  47. logrus.WithContext(ctx).Errorf("[project service] call GetUserByID error,err:%+v", err)
  48. return nil, err
  49. }
  50. ProjectDetail := http_model.ShowProjectData{
  51. ProjectID: conv.MustString(project.ProjectID, ""),
  52. ProjectName: conv.MustString(project.ProjectName, ""),
  53. ProjectStatus: conv.MustString(project.ProjectStatus, ""),
  54. ProjectType: conv.MustString(project.ProjectType, ""),
  55. ProjectPlatform: conv.MustString(project.ProjectPlatform, ""),
  56. ProjectForm: conv.MustString(project.ProjectForm, ""),
  57. TalentType: conv.MustString(project.TalentType, ""),
  58. RecruitDdl: util.GetTimePointer(project.RecruitDdl),
  59. ContentType: conv.MustString(project.ContentType, ""),
  60. ProjectDetail: conv.MustString(project.ProjectDetail, ""),
  61. ProductID: conv.MustString(project.ProductID, ""),
  62. EnterpriseID: conv.MustString(project.EnterpriseID, ""),
  63. Balance: conv.MustString(enterprise.Balance, ""),
  64. AvailableBalance: conv.MustString(enterprise.AvailableBalance, ""),
  65. EstimatedCost: conv.MustString(project.EstimatedCost, ""),
  66. FailReason: conv.MustString(project.FailReason, ""),
  67. CreateAt: util.GetTimePointer(project.CreatedAt),
  68. UpdateAt: util.GetTimePointer(project.UpdatedAt),
  69. Phone: user.Phone,
  70. FinishAt: util.GetTimePointer(project.FinishAt),
  71. PassAt: util.GetTimePointer(project.PassAt),
  72. PayAt: util.GetTimePointer(project.PayAt),
  73. ProductInfo: conv.MustString(project.ProductSnap, ""),
  74. ProductPhotoInfo: conv.MustString(project.ProductPhotoSnap, ""),
  75. AutoFailAt: util.GetTimePointer(project.AutoFailAt),
  76. SubmitAt: util.GetTimePointer(project.SubmitAt),
  77. }
  78. Strategys, err := db.GetRecruitStrategys(ctx, projectID)
  79. if err != nil {
  80. logrus.WithContext(ctx).Error()
  81. return nil, err
  82. }
  83. for _, strategy := range Strategys {
  84. RecruitStrategy := http_model.ShowRecruitStrategy{
  85. RecruitStrategyID: conv.MustString(strategy.RecruitStrategyID, ""),
  86. FeeForm: conv.MustString(strategy.FeeForm, ""),
  87. StrategyID: conv.MustString(strategy.StrategyID, ""),
  88. FollowersLow: conv.MustString(strategy.FollowersLow, ""),
  89. FollowersUp: conv.MustString(strategy.FollowersUp, ""),
  90. RecruitNumber: conv.MustString(strategy.RecruitNumber, ""),
  91. Offer: conv.MustString(strategy.Offer, ""),
  92. ServiceCharge: conv.MustString(strategy.ServiceCharge, ""),
  93. SelectedNumber: strategy.SelectedNumber,
  94. WaitingNumber: strategy.WaitingNumber,
  95. DeliveredNumber: strategy.DeliveredNumber,
  96. SignedNumber: strategy.SignedNumber,
  97. }
  98. ProjectDetail.RecruitStrategys = append(ProjectDetail.RecruitStrategys, RecruitStrategy)
  99. }
  100. Photos, err := db.GetProjectPhoto(ctx, projectID)
  101. if err != nil {
  102. logrus.WithContext(ctx).Error()
  103. return nil, err
  104. }
  105. for _, Photo := range Photos {
  106. ProjectPhoto := http_model.ShowProjectPhoto{
  107. PhotoUrl: Photo.PhotoUrl,
  108. PhotoUid: Photo.PhotoUid,
  109. FileName: Photo.FileName,
  110. }
  111. ProjectDetail.ProjectPhotos = append(ProjectDetail.ProjectPhotos, ProjectPhoto)
  112. }
  113. return &ProjectDetail, nil
  114. }
  115. func (*project) Review(ctx context.Context, request http_model.ReviewProjectRequest) (*http_model.ReviewProjectData, error) {
  116. //projectInfo, err := db.GetProjectIdById(ctx, request.ProjectId)
  117. //if err != nil {
  118. // logrus.WithContext(ctx).Errorf("[projectDB service] call GetprojectById error,err:%+v", err)
  119. // return nil, err
  120. //}
  121. // 若审核通过则更新选品阶段为待支付,否则更新为失效并赋值失效原因
  122. t := time.Now()
  123. //AutoTaskID, err := db.GetLastAutoTaskID()
  124. updateProject := gorm_model.ProjectInfo{}
  125. if request.IsPass == 1 {
  126. if request.IsSpecial == 1 {
  127. //定向任务
  128. updateProject = gorm_model.ProjectInfo{
  129. ProjectID: request.ProjectId,
  130. ProjectStatus: 6,
  131. PassAt: &t,
  132. //AutoTaskID: int64(AutoTaskID),
  133. }
  134. } else {
  135. // 公开
  136. updateProject = gorm_model.ProjectInfo{
  137. ProjectID: request.ProjectId,
  138. ProjectStatus: 4,
  139. PassAt: &t,
  140. }
  141. }
  142. } else {
  143. updateProject = gorm_model.ProjectInfo{
  144. ProjectID: request.ProjectId,
  145. ProjectStatus: 9,
  146. FailReason: 2,
  147. FinishAt: &t,
  148. }
  149. }
  150. var pid *string
  151. pid, err := db.UpdateProject(ctx, updateProject)
  152. if err != nil {
  153. logrus.WithContext(ctx).Errorf("[ProjectDB service] call UpdateProject error,err:%+v", err)
  154. return nil, err
  155. }
  156. res := &http_model.ReviewProjectData{ProjectId: *pid}
  157. return res, nil
  158. }
  159. func (*project) ApproveProject(ctx *gin.Context, data http_model.ApproveProjectRequest) (error, string) {
  160. //fmt.Println("data.IsApprove:", data.IsApprove)
  161. err, message := db.ApproveProject(ctx, data.ProjectId, data.IsApprove)
  162. if err != nil {
  163. logrus.WithContext(ctx).Errorf("[project service] call ChangeTaskStatus error,err:%+v", err)
  164. return err, ""
  165. }
  166. return nil, message
  167. }
  168. func (*project) GetAllProject(ctx context.Context, pageSize, pageNum int32) (*http_model.GetAllProjectData, error) {
  169. allProjectPreviews, total, err := db.GetAllProject(ctx, pageSize, pageNum)
  170. if err != nil {
  171. logrus.WithContext(ctx).Errorf("[project service] call GetAllProject error,err:%+v", err)
  172. return nil, err
  173. }
  174. allProjects := new(http_model.GetAllProjectData)
  175. allProjects.AllProjectPreview = pack.MGormAllProjectToHttpAllProjectPreview(allProjectPreviews)
  176. allProjects.Total = conv.MustString(total, "")
  177. return allProjects, nil
  178. }
  179. func (*project) GetProjectTaskList(ctx context.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TaskConditions) (*http_model.ProjectTaskListData, error) {
  180. projectTasks, total, err := db.GetProjectTaskList(ctx, projectID, pageSize, pageNum, conditions)
  181. if err != nil {
  182. logrus.WithContext(ctx).Errorf("[project service] call GetProjectTaskList error,err:%+v", err)
  183. return nil, err
  184. }
  185. projectTaskListData := new(http_model.ProjectTaskListData)
  186. projectTaskListData.ProjectTaskPreview = pack.MGormProjectTaskToHttpProjectTaskPreview(projectTasks)
  187. projectTaskListData.Total = conv.MustString(total, "")
  188. return projectTaskListData, nil
  189. }
  190. func (*project) Create(ctx context.Context, newProject http_model.CreateProjectRequest, enterpriseID string) (*http_model.CreateProjectData, error) {
  191. fmt.Printf("newProject:%+v\n", newProject)
  192. fmt.Println("newProject.RecruitDdl:", newProject.RecruitDdl)
  193. RecruitDdl := time.Time{} //赋零值
  194. if newProject.RecruitDdl != "" {
  195. RecruitDdl, _ = time.ParseInLocation("2006-01-02 15:04:05", newProject.RecruitDdl, time.Local)
  196. }
  197. // 查询关联商品信息
  198. product, err := db.GetProductByID(ctx, newProject.ProductID)
  199. if err != nil {
  200. return nil, err
  201. }
  202. fmt.Println("product:", product)
  203. productPhotos, err := db.GetProductPhotoByProductID(ctx, newProject.ProductID)
  204. productInfoToJson, _ := json.Marshal(product)
  205. productPhotosToJson, _ := json.Marshal(productPhotos)
  206. // 按照品牌名-商品名对项目进行命名
  207. AutoTaskID, err := db.GetLastAutoTaskID()
  208. if err != nil {
  209. return nil, err
  210. }
  211. AutoDefaultID, err := db.GetLastAutoDefaultID()
  212. if err != nil {
  213. return nil, err
  214. }
  215. projectName := product.BrandName + "-" + product.ProductName
  216. var feeFrom []string
  217. for _, strategy := range newProject.RecruitStrategys {
  218. feeFrom = append(feeFrom, strconv.FormatInt(strategy.FeeForm, 10))
  219. }
  220. var ECost float64 = 0
  221. if newProject.ProjectType == int64(1) {
  222. for _, strategy := range newProject.RecruitStrategys {
  223. // 计算预估成本
  224. var tmpCost float64 = 0
  225. if strategy.FeeForm == 1 {
  226. tmpCost = strategy.ServiceCharge * float64(strategy.RecruitNumber)
  227. } else if strategy.FeeForm == 2 {
  228. tmpCost = strategy.Offer * float64(strategy.RecruitNumber)
  229. }
  230. ECost += tmpCost
  231. }
  232. }
  233. feeForms := strings.Join(feeFrom, ",")
  234. projectInfo := gorm_model.ProjectInfo{}
  235. rand.Seed(time.Now().UnixNano())
  236. td := conv.MustString(time.Now().Day(), "")
  237. for {
  238. if len(td) == 3 {
  239. break
  240. }
  241. td = "0" + td
  242. }
  243. fmt.Printf("RecruitDdl:%+v\n", RecruitDdl)
  244. // 全流程项目
  245. if newProject.ProjectType == int64(1) {
  246. if newProject.RecruitDdl == "" { // 招募截止时间为空
  247. projectInfo = gorm_model.ProjectInfo{
  248. ProjectID: conv.MustString(time.Now().Year(), "")[2:] + td + conv.MustString(rand.Intn(100000-10000)+10000, ""),
  249. ProjectName: projectName,
  250. ProjectStatus: 1,
  251. ProjectType: newProject.ProjectType,
  252. TalentType: newProject.TalentType,
  253. ProjectPlatform: newProject.ProjectPlatform,
  254. ProjectForm: newProject.ProjectForm,
  255. ProjectDetail: newProject.ProjectDetail,
  256. ContentType: newProject.ContentType,
  257. EnterpriseID: enterpriseID,
  258. ProductID: newProject.ProductID,
  259. FeeForm: feeForms,
  260. AutoTaskID: conv.MustInt64(AutoTaskID, 0),
  261. AutoDefaultID: conv.MustInt64(AutoDefaultID, 0),
  262. EstimatedCost: ECost,
  263. IsRead: 0,
  264. ProductSnap: string(productInfoToJson),
  265. ProductPhotoSnap: string(productPhotosToJson),
  266. }
  267. } else { // 招募截至时间非空
  268. projectInfo = gorm_model.ProjectInfo{
  269. ProjectID: conv.MustString(time.Now().Year(), "")[2:] + td + conv.MustString(rand.Intn(100000-10000)+10000, ""),
  270. ProjectName: projectName,
  271. ProjectStatus: 1,
  272. ProjectType: newProject.ProjectType,
  273. TalentType: newProject.TalentType,
  274. ProjectPlatform: newProject.ProjectPlatform,
  275. ProjectForm: newProject.ProjectForm,
  276. RecruitDdl: &RecruitDdl,
  277. ProjectDetail: newProject.ProjectDetail,
  278. ContentType: newProject.ContentType,
  279. EnterpriseID: enterpriseID,
  280. ProductID: newProject.ProductID,
  281. FeeForm: feeForms,
  282. AutoTaskID: conv.MustInt64(AutoTaskID, 0),
  283. AutoDefaultID: conv.MustInt64(AutoDefaultID, 0),
  284. EstimatedCost: ECost,
  285. IsRead: 0,
  286. ProductSnap: string(productInfoToJson),
  287. ProductPhotoSnap: string(productPhotosToJson),
  288. }
  289. }
  290. } else { // 专项执行项目
  291. projectInfo = gorm_model.ProjectInfo{
  292. ProjectID: conv.MustString(time.Now().Year(), "")[2:] + td + conv.MustString(rand.Intn(100000-10000)+10000, ""),
  293. ProjectName: projectName,
  294. ProjectStatus: 1,
  295. ProjectType: newProject.ProjectType,
  296. TalentType: "[]",
  297. ProjectPlatform: newProject.ProjectPlatform,
  298. ProjectForm: newProject.ProjectForm,
  299. ProjectDetail: newProject.ProjectDetail,
  300. ContentType: newProject.ContentType,
  301. EnterpriseID: enterpriseID,
  302. ProductID: newProject.ProductID,
  303. FeeForm: feeForms,
  304. AutoTaskID: conv.MustInt64(AutoTaskID, 0),
  305. AutoDefaultID: conv.MustInt64(AutoDefaultID, 0),
  306. EstimatedCost: ECost,
  307. ProductSnap: string(productInfoToJson),
  308. ProductPhotoSnap: string(productPhotosToJson),
  309. }
  310. }
  311. // db create ProjectInfo
  312. projectID, err := db.CreateProject(ctx, projectInfo)
  313. if err != nil {
  314. return nil, err
  315. }
  316. if len(newProject.ProjectPhotos) != 0 {
  317. var projectPhotos []gorm_model.ProjectPhoto
  318. for _, photo := range newProject.ProjectPhotos {
  319. projectPhoto := gorm_model.ProjectPhoto{
  320. PhotoUrl: photo.PhotoUrl,
  321. PhotoUid: photo.PhotoUid,
  322. ProjectID: projectID,
  323. }
  324. projectPhotos = append(projectPhotos, projectPhoto)
  325. }
  326. // db create ProjectPhoto
  327. err = db.CreateProjectPhoto(ctx, projectPhotos)
  328. if err != nil {
  329. return nil, err
  330. }
  331. }
  332. // build
  333. if newProject.ProjectType == int64(1) && newProject.RecruitStrategys != nil {
  334. var recruitStrategys []gorm_model.RecruitStrategy
  335. for _, strategy := range newProject.RecruitStrategys {
  336. // 查询对应定价策略
  337. pricingStrategy, err := db.GetPricingStrategy(ctx, strategy.FollowersLow, strategy.FollowersUp, strategy.FeeForm, newProject.ProjectPlatform)
  338. if err != nil {
  339. return nil, err
  340. }
  341. // 根据定价策略计算达人所见报价
  342. if strategy.FeeForm == 2 {
  343. strategy.TOffer = strategy.Offer * (1 - conv.MustFloat64(pricingStrategy.ServiceRate, 0)/1000)
  344. }
  345. recruitStrategy := gorm_model.RecruitStrategy{
  346. FeeForm: strategy.FeeForm,
  347. StrategyID: strategy.StrategyID,
  348. FollowersLow: strategy.FollowersLow,
  349. FollowersUp: strategy.FollowersUp,
  350. RecruitNumber: strategy.RecruitNumber,
  351. ServiceCharge: strategy.ServiceCharge,
  352. Offer: strategy.Offer,
  353. TOffer: strategy.TOffer,
  354. ProjectID: projectID,
  355. }
  356. recruitStrategys = append(recruitStrategys, recruitStrategy)
  357. }
  358. err = db.CreateRecruitStrategy(ctx, recruitStrategys)
  359. if err != nil {
  360. return nil, err
  361. }
  362. }
  363. res := &http_model.CreateProjectData{
  364. ProjectID: projectID,
  365. }
  366. return res, nil
  367. }
  368. func (*project) Update(ctx context.Context, newProject http_model.UpdateProjectRequest, enterpriseID string) (*http_model.UpdateProjectData, error) {
  369. //RecruitDdl, _ := time.ParseInLocation("2006-01-02 15:04:05", newProject.RecruitDdl, time.Local)
  370. RecruitDdl := time.Time{} //赋零值
  371. if newProject.RecruitDdl != "" {
  372. RecruitDdl, _ = time.ParseInLocation("2006-01-02 15:04:05", newProject.RecruitDdl, time.Local)
  373. }
  374. oldProject, err3 := db.GetProjectDetail(ctx, newProject.ProjectID)
  375. if err3 != nil {
  376. return nil, err3
  377. }
  378. var feeFrom []string
  379. for _, strategy := range newProject.RecruitStrategys {
  380. feeFrom = append(feeFrom, strconv.FormatInt(strategy.FeeForm, 10))
  381. }
  382. var ECost float64 = 0
  383. if newProject.ProjectType == int64(1) {
  384. for _, strategy := range newProject.RecruitStrategys {
  385. // 计算预估成本
  386. var tmpCost float64 = 0
  387. if strategy.FeeForm == 1 {
  388. tmpCost = strategy.ServiceCharge * float64(strategy.RecruitNumber)
  389. } else if strategy.FeeForm == 2 {
  390. tmpCost = strategy.Offer * float64(strategy.RecruitNumber)
  391. }
  392. ECost += tmpCost
  393. }
  394. }
  395. feeForms := strings.Join(feeFrom, ",")
  396. t := time.Now()
  397. project := gorm_model.ProjectInfo{}
  398. if newProject.RecruitDdl == "" {
  399. project = gorm_model.ProjectInfo{
  400. ProjectType: newProject.ProjectType,
  401. ProjectID: newProject.ProjectID,
  402. TalentType: newProject.TalentType,
  403. ContentType: conv.MustInt64(newProject.ContentType, 0),
  404. ProjectDetail: newProject.ProjectDetail,
  405. ProjectForm: conv.MustInt64(newProject.ProjectForm, 0),
  406. EnterpriseID: enterpriseID,
  407. ProjectStatus: newProject.ProjectStatus,
  408. FeeForm: feeForms,
  409. EstimatedCost: ECost,
  410. SubmitAt: &t,
  411. }
  412. } else {
  413. project = gorm_model.ProjectInfo{
  414. ProjectType: newProject.ProjectType,
  415. ProjectID: newProject.ProjectID,
  416. RecruitDdl: &RecruitDdl,
  417. TalentType: newProject.TalentType,
  418. ContentType: conv.MustInt64(newProject.ContentType, 0),
  419. ProjectDetail: newProject.ProjectDetail,
  420. ProjectForm: conv.MustInt64(newProject.ProjectForm, 0),
  421. EnterpriseID: enterpriseID,
  422. ProjectStatus: newProject.ProjectStatus,
  423. FeeForm: feeForms,
  424. EstimatedCost: ECost,
  425. SubmitAt: &t,
  426. }
  427. }
  428. projectID, err := db.UpdateProject(ctx, project)
  429. if err != nil {
  430. return nil, err
  431. }
  432. // 删除该项目之前的所有图片
  433. err = db.DeleteProjectPhotoByProjectID(ctx, *projectID)
  434. if err != nil {
  435. return nil, err
  436. }
  437. fmt.Printf("照片:\t %+v\n", newProject.ProjectPhotos)
  438. if len(newProject.ProjectPhotos) != 0 {
  439. // 新增图片
  440. var projectPhotos []gorm_model.ProjectPhoto
  441. for _, photo := range newProject.ProjectPhotos {
  442. projectPhoto := gorm_model.ProjectPhoto{
  443. ProjectID: project.ProjectID,
  444. PhotoUrl: photo.PhotoUrl,
  445. PhotoUid: photo.PhotoUid,
  446. FileName: photo.FileName,
  447. }
  448. projectPhotos = append(projectPhotos, projectPhoto)
  449. }
  450. err = db.CreateProjectPhoto(ctx, projectPhotos)
  451. if err != nil {
  452. return nil, err
  453. }
  454. }
  455. // 删除该项目之前的所有策略
  456. err = db.DeleteRecruitStrategyByProjectID(ctx, *projectID)
  457. if err != nil {
  458. return nil, err
  459. }
  460. fmt.Printf("招募策略:%+v \n", newProject.RecruitStrategys)
  461. if len(newProject.RecruitStrategys) != 0 && newProject.ProjectType == 1 {
  462. // 新增策略
  463. var RecruitStrategys []gorm_model.RecruitStrategy
  464. for _, Strategy := range newProject.RecruitStrategys {
  465. // 查询对应定价策略
  466. pricingStrategy, err := db.GetPricingStrategy(ctx, Strategy.FollowersLow, Strategy.FollowersUp, Strategy.FeeForm, oldProject.ProjectPlatform)
  467. if err != nil {
  468. return nil, err
  469. }
  470. // 根据定价策略计算达人所见报价
  471. if Strategy.FeeForm == 2 {
  472. Strategy.TOffer = Strategy.Offer * (1 - conv.MustFloat64(pricingStrategy.ServiceRate, 0)/1000)
  473. }
  474. RecruitStrategy := gorm_model.RecruitStrategy{
  475. FeeForm: Strategy.FeeForm,
  476. StrategyID: Strategy.StrategyID,
  477. FollowersLow: Strategy.FollowersLow,
  478. FollowersUp: Strategy.FollowersUp,
  479. RecruitNumber: Strategy.RecruitNumber,
  480. Offer: Strategy.Offer,
  481. TOffer: Strategy.TOffer,
  482. ServiceCharge: Strategy.ServiceCharge,
  483. ProjectID: project.ProjectID,
  484. }
  485. fmt.Printf("Offer:\t %+v", Strategy.Offer)
  486. RecruitStrategys = append(RecruitStrategys, RecruitStrategy)
  487. }
  488. err = db.CreateRecruitStrategy(ctx, RecruitStrategys)
  489. if err != nil {
  490. return nil, err
  491. }
  492. }
  493. res := &http_model.UpdateProjectData{
  494. ProjectID: *projectID,
  495. }
  496. return res, nil
  497. }
  498. func (*project) GetPorjectDetail(ctx context.Context, projectID string) (*http_model.ShowProjectData, error) {
  499. project, err := db.GetProjectDetail(ctx, projectID)
  500. if err != nil {
  501. logrus.WithContext(ctx).Errorf("[project service] call GetPorjectDetail error,err:%+v", err)
  502. return nil, err
  503. }
  504. enterprise, err := db.GetEnterpriseByEnterpriseID(ctx, project.EnterpriseID)
  505. // fmt.Println("%+v", enterprise.UserID)
  506. if err != nil {
  507. logrus.WithContext(ctx).Errorf("[project service] call GetEnterpriseByEnterpriseID error,err:%+v", err)
  508. return nil, err
  509. }
  510. user, err := db.GetUserByID(ctx, enterprise.UserID)
  511. if err != nil {
  512. logrus.WithContext(ctx).Errorf("[project service] call GetUserByID error,err:%+v", err)
  513. return nil, err
  514. }
  515. ProjectDetail := http_model.ShowProjectData{
  516. ProjectID: project.ProjectID,
  517. ProjectName: conv.MustString(project.ProjectName, ""),
  518. ProjectStatus: conv.MustString(project.ProjectStatus, ""),
  519. ProjectType: conv.MustString(project.ProjectType, ""),
  520. ProjectPlatform: conv.MustString(project.ProjectPlatform, ""),
  521. ProjectForm: conv.MustString(project.ProjectForm, ""),
  522. TalentType: conv.MustString(project.TalentType, ""),
  523. RecruitDdl: util.GetTimePointer(project.RecruitDdl),
  524. ContentType: conv.MustString(project.ContentType, ""),
  525. ProjectDetail: conv.MustString(project.ProjectDetail, ""),
  526. ProductID: conv.MustString(project.ProductID, ""),
  527. EnterpriseID: conv.MustString(project.EnterpriseID, ""),
  528. Balance: conv.MustString(enterprise.Balance, ""),
  529. FailReason: conv.MustString(project.FailReason, ""),
  530. CreateAt: util.GetTimePointer(project.CreatedAt),
  531. UpdateAt: util.GetTimePointer(project.UpdatedAt),
  532. Phone: user.Phone,
  533. FinishAt: util.GetTimePointer(project.FinishAt),
  534. PassAt: util.GetTimePointer(project.PassAt),
  535. PayAt: util.GetTimePointer(project.PayAt),
  536. }
  537. Strategys, err := db.GetRecruitStrategys(ctx, projectID)
  538. fmt.Println("招募策略:", Strategys)
  539. if err != nil {
  540. logrus.WithContext(ctx).Error()
  541. return nil, err
  542. }
  543. for _, strategy := range Strategys {
  544. RecruitStrategy := http_model.ShowRecruitStrategy{
  545. RecruitStrategyID: conv.MustString(strategy.RecruitStrategyID, ""),
  546. FeeForm: conv.MustString(strategy.FeeForm, ""),
  547. StrategyID: conv.MustString(strategy.StrategyID, ""),
  548. FollowersLow: conv.MustString(strategy.FollowersLow, ""),
  549. FollowersUp: conv.MustString(strategy.FollowersUp, ""),
  550. RecruitNumber: conv.MustString(strategy.RecruitNumber, ""),
  551. Offer: conv.MustString(strategy.Offer, ""),
  552. ServiceCharge: conv.MustString(strategy.ServiceCharge, ""),
  553. SelectedNumber: strategy.SelectedNumber,
  554. WaitingNumber: strategy.WaitingNumber,
  555. DeliveredNumber: strategy.DeliveredNumber,
  556. SignedNumber: strategy.SignedNumber,
  557. }
  558. ProjectDetail.RecruitStrategys = append(ProjectDetail.RecruitStrategys, RecruitStrategy)
  559. }
  560. Photos, err := db.GetProjectPhoto(ctx, projectID)
  561. if err != nil {
  562. logrus.WithContext(ctx).Error()
  563. return nil, err
  564. }
  565. for _, Photo := range Photos {
  566. ProjectPhoto := http_model.ShowProjectPhoto{
  567. PhotoUrl: Photo.PhotoUrl,
  568. PhotoUid: Photo.PhotoUid,
  569. }
  570. ProjectDetail.ProjectPhotos = append(ProjectDetail.ProjectPhotos, ProjectPhoto)
  571. }
  572. return &ProjectDetail, nil
  573. }
  574. func (*project) GetTaskLogisticsList(ctx context.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) (*http_model.TaskLogisticsListData, error) {
  575. TaskLogisticss, total, err := db.GetTaskLogisticsList(ctx, projectID, pageSize, pageNum, conditions)
  576. if err != nil {
  577. logrus.WithContext(ctx).Errorf("[project service] call GetTaskLogisticsList error,err:%+v", err)
  578. return nil, err
  579. }
  580. TaskLogisticsListData := new(http_model.TaskLogisticsListData)
  581. TaskLogisticsListData.TaskLogisticsPreview = pack.MGormTaskLogisticsInfoListToHttpTaskLogisticsPreviewList(TaskLogisticss)
  582. TaskLogisticsListData.Total = conv.MustString(total, "")
  583. return TaskLogisticsListData, nil
  584. }
  585. func (*project) GetSpecialProjectTaskList(ctx context.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) (*http_model.SpecialTaskLogisticsListData, error) {
  586. SpecialTaskLogisticsListDatas, total, err := db.GetSpecialTaskLogisticsList(ctx, projectID, pageSize, pageNum, conditions)
  587. if err != nil {
  588. logrus.WithContext(ctx).Errorf("[project service] call GetSpecialProjectTaskList error,err:%+v", err)
  589. return nil, err
  590. }
  591. TaskLogisticsListData := new(http_model.SpecialTaskLogisticsListData)
  592. TaskLogisticsListData.SpecialTaskLogisticsPreview = pack.MGormSpecialTaskLogisticsInfoListToHttpTaskLogisticsPreviewList(SpecialTaskLogisticsListDatas)
  593. TaskLogisticsListData.Total = conv.MustString(total, "")
  594. return TaskLogisticsListData, nil
  595. }
  596. func (*project) ChangeTaskStatus(ctx *gin.Context, data http_model.ProjectChangeTaskStatusRequest) interface{} {
  597. fmt.Println("taskIds :", data.TaskIds)
  598. fmt.Println("task_status :", data.TaskStatus)
  599. RecruitStrategyIDs, err := db.ChangeTaskStatus(ctx, data.TaskIds, data.TaskStatus)
  600. if err != nil {
  601. logrus.WithContext(ctx).Errorf("[project service] call ChangeTaskStatus error,err:%+v", err)
  602. return err
  603. }
  604. if data.TaskStatus == "2" {
  605. for _, RecruitStrategyID := range RecruitStrategyIDs {
  606. err = db.CalculateSelectedNumberByRecruitStrategyID(ctx, RecruitStrategyID, 1)
  607. if err != nil {
  608. logrus.WithContext(ctx).Errorf("[project service] call ChangeTaskStatus error,err:%+v", err)
  609. return err
  610. }
  611. }
  612. } else if data.TaskStatus == "3" && data.ClickIndex != "0" {
  613. for _, RecruitStrategyID := range RecruitStrategyIDs {
  614. err = db.CalculateSelectedNumberByRecruitStrategyID(ctx, RecruitStrategyID, -1)
  615. if err != nil {
  616. logrus.WithContext(ctx).Errorf("[project service] call ChangeTaskStatus error,err:%+v", err)
  617. return err
  618. }
  619. }
  620. }
  621. return nil
  622. }
  623. func (*project) ChangeSpecialTaskStatus(ctx *gin.Context, data http_model.ProjectChangeTaskStatusRequest) interface{} {
  624. err := db.ChangeSpecialTaskStatus(ctx, data.TaskIds, data.TaskStatus, data.TaskStage)
  625. if err != nil {
  626. logrus.WithContext(ctx).Errorf("[project service] call ChangeSpecialTaskStatus error,err:%+v", err)
  627. return err
  628. }
  629. for _, taskId := range data.TaskIds {
  630. err = db.CreateMessageByTaskId(ctx, 7, 2, taskId)
  631. if err != nil {
  632. logrus.WithContext(ctx).Errorf("[project service] call CreateMessageByTaskId error,err:%+v", err)
  633. return err
  634. }
  635. }
  636. err = db.SetSpecialProjectFinish(ctx, data.ProjectId)
  637. if err != nil {
  638. logrus.WithContext(ctx).Errorf("[project service] call CreateMessageByTaskId error,err:%+v", err)
  639. return err
  640. }
  641. return nil
  642. }
  643. func (p *project) GetTaskScriptList(ctx *gin.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) (*http_model.TaskScriptListData, error) {
  644. TaskScripts, total, err := db.GetTaskScriptList(ctx, projectID, pageSize, pageNum, conditions)
  645. if err != nil {
  646. logrus.WithContext(ctx).Errorf("[project service] call GetTaskScriptList error,err:%+v", err)
  647. return nil, err
  648. }
  649. TaskScriptListData := new(http_model.TaskScriptListData)
  650. TaskScriptListData.TaskScriptPreview = pack.MGormTaskScriptInfoListToHttpTaskScriptPreviewList(TaskScripts)
  651. TaskScriptListData.Total = conv.MustString(total, "")
  652. return TaskScriptListData, nil
  653. }
  654. func (p *project) GetTaskSketchList(ctx *gin.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) (*http_model.TaskSketchListData, error) {
  655. TaskSketchs, total, err := db.GetTaskSketchList(ctx, projectID, pageSize, pageNum, conditions)
  656. if err != nil {
  657. logrus.WithContext(ctx).Errorf("[project service] call GetTaskSketchList error,err:%+v", err)
  658. return nil, err
  659. }
  660. TaskSketchListData := new(http_model.TaskSketchListData)
  661. TaskSketchListData.TaskSketchPreview = pack.MGormTaskSketchInfoListToHttpTaskSketchPreviewList(TaskSketchs)
  662. TaskSketchListData.Total = conv.MustString(total, "")
  663. return TaskSketchListData, nil
  664. }
  665. func (p *project) GetTaskLinkList(ctx *gin.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) (*http_model.TaskLinkListData, error) {
  666. TaskLinks, total, err := db.GetTaskLinkList(ctx, projectID, pageSize, pageNum, conditions)
  667. if err != nil {
  668. logrus.WithContext(ctx).Errorf("[project service] call GetTaskLinkList error,err:%+v", err)
  669. return nil, err
  670. }
  671. TaskLinkListData := new(http_model.TaskLinkListData)
  672. TaskLinkListData.TaskLinkPreview = pack.MGormTaskLinkInfoListToHttpTaskLinkPreviewList(TaskLinks)
  673. TaskLinkListData.Total = conv.MustString(total, "")
  674. return TaskLinkListData, nil
  675. }
  676. func (p *project) GetTaskDataList(ctx *gin.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) (*http_model.TaskDataListData, error) {
  677. TaskDatas, total, err := db.GetTaskDataList(ctx, projectID, pageSize, pageNum, conditions)
  678. if err != nil {
  679. logrus.WithContext(ctx).Errorf("[project service] call GetTaskDataList error,err:%+v", err)
  680. return nil, err
  681. }
  682. TaskDataListData := new(http_model.TaskDataListData)
  683. TaskDataListData.TaskDataPreview = pack.MGormTaskDataInfoListToHttpTaskDataPreviewList(TaskDatas)
  684. TaskDataListData.Total = conv.MustString(total, "")
  685. return TaskDataListData, nil
  686. }
  687. func (p *project) GetTaskFinishList(ctx *gin.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) (*http_model.TaskFinishListData, error) {
  688. TaskFinishs, total, err := db.GetTaskFinishList(ctx, pageSize, pageNum, conditions)
  689. if err != nil {
  690. logrus.WithContext(ctx).Errorf("[project service] call GetTaskFinishList error,err:%+v", err)
  691. return nil, err
  692. }
  693. TaskFinishListData := new(http_model.TaskFinishListData)
  694. TaskFinishListData.TaskFinishPreview = pack.MGormTaskFinishInfoListToHttpTaskFinishPreviewList(TaskFinishs)
  695. TaskFinishListData.Total = conv.MustString(total, "")
  696. return TaskFinishListData, nil
  697. }
  698. func (p *project) GetServiceCharge(ctx *gin.Context, data http_model.GetServiceChargeRequest) (*http_model.ServiceChargeData, error) {
  699. pricingStrategy, err := db.GetPricingStrategy(ctx, data.FollowersLow, data.FollowersUp, data.FeeForm, data.Platform)
  700. if err != nil {
  701. return nil, err
  702. }
  703. serviceFee := http_model.ServiceChargeData{
  704. ServiceCharge: pricingStrategy.ServiceCharge,
  705. }
  706. return &serviceFee, nil
  707. }