s_project.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. package service
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/issue9/conv"
  6. log "github.com/sirupsen/logrus"
  7. "time"
  8. "youngee_b_api/db"
  9. "youngee_b_api/model/common_model"
  10. "youngee_b_api/model/gorm_model"
  11. "youngee_b_api/model/http_model"
  12. )
  13. var SProject *sProject
  14. type sProject struct {
  15. }
  16. // CreateSProject 新建服务商加入商单后的公开种草任务
  17. func (*sProject) CreateSProject(ctx context.Context, request http_model.AddToListRequest) error {
  18. // 1. 建立SProject信息
  19. // 1.1. 根据传入的ProjectId去Project表查找信息补全SProject
  20. newSProject := gorm_model.SProjectInfo{
  21. EnterpriseId: request.EnterpriseId,
  22. SupplierId: request.SupplierId,
  23. ProjectId: request.ProjectId,
  24. SubAccountId: request.SubAccountId,
  25. OperatorType: request.OperatorType,
  26. SProjectStatus: 2,
  27. StrategyStatus: 1,
  28. }
  29. projectInfo, projectErr := db.GetProjectDetail(ctx, request.ProjectId)
  30. if projectErr != nil {
  31. return projectErr
  32. }
  33. if projectInfo != nil {
  34. var currentTime time.Time
  35. currentTime = time.Now()
  36. newSProject.ProjectStatus = projectInfo.ProjectStatus
  37. newSProject.ProjectForm = projectInfo.ProjectForm
  38. newSProject.ContentType = projectInfo.ContentType
  39. newSProject.ProjectPlatform = projectInfo.ProjectPlatform
  40. newSProject.CreateTime = &currentTime
  41. newSProject.ProjectType = 1
  42. newSProject.ProductId = projectInfo.ProductID
  43. newSProject.ProjectName = projectInfo.ProjectName
  44. }
  45. sProjectId, err := db.CreateSProject(ctx, newSProject)
  46. if err != nil {
  47. log.Infof("[CreateEnterpriseSubUser] fail,err:%+v", err)
  48. return err
  49. }
  50. fmt.Println("创建SProject信息成功")
  51. // 2. 建立新的recruitStrategy
  52. // 2.1. 根据projectId去查找原来的recruitStrategy
  53. recruitStrategys, strategyErr := db.GetRecruitStrategyByProjectId(ctx, request.ProjectId)
  54. if strategyErr != nil {
  55. return strategyErr
  56. }
  57. // 2.2. 设置新的结构体以写入
  58. var currRecruitStrategys []gorm_model.RecruitStrategy
  59. for _, strategy := range recruitStrategys {
  60. var currStrategy gorm_model.RecruitStrategy
  61. currStrategy.StrategyID = strategy.StrategyID
  62. currStrategy.QuoteRecruitStrategyId = int(strategy.RecruitStrategyID)
  63. currStrategy.FeeForm = strategy.FeeForm
  64. currStrategy.FollowersLow = strategy.FollowersLow
  65. currStrategy.FollowersUp = strategy.FollowersUp
  66. currStrategy.RecruitNumber = strategy.RecruitNumber
  67. currStrategy.Offer = strategy.Offer
  68. currStrategy.TOffer = strategy.TOffer
  69. currStrategy.ProjectID = strategy.ProjectID
  70. currStrategy.ServiceCharge = strategy.ServiceCharge
  71. currStrategy.ServiceRate = strategy.ServiceRate
  72. currStrategy.SProjectId = sProjectId
  73. currStrategy.StrategyType = 2
  74. currRecruitStrategys = append(currRecruitStrategys, currStrategy)
  75. }
  76. // 2.3. 写入
  77. createStrategyErr := db.CreateSpecialStrategy(ctx, currRecruitStrategys)
  78. if createStrategyErr != nil {
  79. return createStrategyErr
  80. }
  81. fmt.Println("创建招募策略成功")
  82. return nil
  83. }
  84. // GetSProjectList 查找服务商加入商单的种草任务列表
  85. func (*sProject) GetSProjectList(ctx context.Context, supplierId int, pageSize, pageNum int32, condition *common_model.SProjectCondition) (*http_model.SProjectData, error) {
  86. var SProjectList *http_model.SProjectData
  87. SProjectList = &http_model.SProjectData{}
  88. // 1. 加入商单后的种草任务基本信息
  89. sProjects, total, err := db.GetSProjectList(ctx, supplierId, pageSize, pageNum, condition)
  90. if err != nil {
  91. return nil, err
  92. }
  93. SProjectList.Total = total
  94. // 2. 商品信息填入
  95. for _, sProject := range sProjects {
  96. var currSProject *http_model.SProjectListReview
  97. currSProject = &http_model.SProjectListReview{}
  98. currSProject.SProjectId = sProject.SProjectId
  99. currSProject.ProjectId = sProject.ProjectId
  100. currSProject.ProjectPlatform = sProject.ProjectPlatform
  101. currSProject.ContentType = sProject.ContentType
  102. currSProject.ProjectForm = sProject.ProjectForm
  103. currSProject.ProjectStatus = sProject.ProjectStatus
  104. currSProject.SupplierId = sProject.SupplierId
  105. currSProject.SubAccountId = sProject.SubAccountId
  106. currSProject.OperatorType = sProject.OperatorType
  107. currSProject.CreateTime = conv.MustString(sProject.CreateTime)[0:19]
  108. currSProject.ApplyNum = sProject.ApplyNum
  109. currSProject.RecruitNum = sProject.RecruitNum
  110. currSProject.SettleNum = sProject.SettleNum
  111. currSProject.ServiceChargeActual = sProject.ServiceChargeActual
  112. currSProject.ServiceCharge = sProject.ServiceCharge
  113. currSProject.ServiceChargeSettle = sProject.ServiceChargeSettle
  114. // 2.2. 商品信息
  115. productInfo, productErr := db.GetProductByID(ctx, sProject.ProductId)
  116. if productErr != nil {
  117. return nil, productErr
  118. }
  119. if productInfo != nil {
  120. currSProject.ProductId = productInfo.ProductID
  121. currSProject.ProductPrice = productInfo.ProductPrice
  122. currSProject.ProductName = productInfo.ProductName
  123. }
  124. // 2.3. 商品图片信息
  125. productPhotoInfo, productPhotoErr := db.GetProductPhotoByProductID(ctx, sProject.ProductId)
  126. if productPhotoErr != nil {
  127. return nil, productPhotoErr
  128. }
  129. if productPhotoInfo != nil {
  130. for _, photo := range productPhotoInfo {
  131. fmt.Println(photo)
  132. if photo.Symbol == 1 {
  133. currSProject.ProductPhotoSymbol = 1
  134. currSProject.ProductPhotoUrl = photo.PhotoUrl
  135. currSProject.ProductPhotoUid = photo.PhotoUid
  136. }
  137. }
  138. }
  139. SProjectList.SProjectList = append(SProjectList.SProjectList, currSProject)
  140. }
  141. return SProjectList, nil
  142. }
  143. // GetSPorjectDetail 查找服务商种草任务详情
  144. func (*sProject) GetSPorjectDetail(ctx context.Context, sProjectId int) (*http_model.ShowSProjectData, error) {
  145. var sProjectData *http_model.ShowSProjectData
  146. sProjectData = &http_model.ShowSProjectData{}
  147. // 1. 取出服务商种草表中的信息
  148. sProjectInfo, err := db.GetSProjectDetail(ctx, sProjectId)
  149. if err != nil {
  150. return nil, err
  151. }
  152. if sProjectInfo != nil {
  153. fmt.Println(sProjectInfo)
  154. sProjectData.SProjectId = sProjectInfo.SProjectId
  155. sProjectData.ProjectName = sProjectInfo.ProjectName
  156. sProjectData.ProjectID = sProjectInfo.ProjectId
  157. sProjectData.ProjectType = sProjectInfo.ProjectType
  158. sProjectData.ProjectPlatform = sProjectInfo.ProjectPlatform
  159. sProjectData.ProjectForm = sProjectInfo.ProjectForm
  160. sProjectData.ContentType = sProjectInfo.ContentType
  161. }
  162. // 2. 取出商家发布的种草任务表中的信息
  163. projectInfo, projectErr := db.GetProjectDetail(ctx, sProjectInfo.ProjectId)
  164. if projectErr != nil {
  165. return nil, projectErr
  166. }
  167. if projectInfo != nil {
  168. fmt.Println(projectInfo)
  169. sProjectData.TalentType = projectInfo.TalentType
  170. sProjectData.RecruitDdl = *projectInfo.RecruitDdl
  171. sProjectData.ProjectDetail = projectInfo.ProjectDetail
  172. sProjectData.PayAt = *projectInfo.PayAt
  173. }
  174. // 3. 取出招募策略并聚合达人数量信息
  175. recruitStrategy, recruitErr := db.GetRecruitStrategyByProjectId(ctx, sProjectData.ProjectID)
  176. if recruitErr != nil {
  177. return nil, recruitErr
  178. }
  179. if recruitStrategy != nil {
  180. for _, strategy := range recruitStrategy {
  181. fmt.Println("recruitStrategy: ", strategy)
  182. selectedNumber, countTaskErr := db.CountTaskNumByStrategyId(ctx, sProjectData.ProjectID, strategy.StrategyID)
  183. if countTaskErr != nil {
  184. return nil, countTaskErr
  185. }
  186. showStrategy := http_model.ShowSRecruitStrategy{
  187. StrategyID: strategy.StrategyID,
  188. FeeForm: strategy.FeeForm,
  189. FollowersLow: strategy.FollowersLow,
  190. FollowersUp: strategy.FollowersUp,
  191. RecruitNumber: strategy.RecruitNumber,
  192. ServiceCharge: projectInfo.ServiceChargeRate,
  193. SelectedNumber: selectedNumber,
  194. Offer: strategy.Offer,
  195. }
  196. sProjectData.SRecruitStrategys = append(sProjectData.SRecruitStrategys, showStrategy)
  197. }
  198. }
  199. // 4. 取出种草任务创建者用户信息
  200. if projectInfo.OperatorType == 1 {
  201. fmt.Println("商家用户")
  202. enterpriseInfo, enterpriseErr := db.GetEnterpriseByEnterpriseID(ctx, projectInfo.EnterpriseID)
  203. if enterpriseErr != nil {
  204. return nil, enterpriseErr
  205. }
  206. sProjectData.CreatorName = enterpriseInfo.BusinessName
  207. sProjectData.CreatorCompany = enterpriseInfo.BusinessName
  208. sProjectData.CreatorType = 1
  209. sProjectData.Phone = enterpriseInfo.Phone
  210. } else if projectInfo.OperatorType == 2 {
  211. fmt.Println("商家子账号")
  212. enterpriseInfo, enterpriseErr := db.GetEnterpriseByEnterpriseID(ctx, projectInfo.EnterpriseID)
  213. if enterpriseErr != nil {
  214. return nil, enterpriseErr
  215. }
  216. sProjectData.CreatorCompany = enterpriseInfo.BusinessName
  217. subAccountInfo, SubAccountErr := db.FindSubAccountById(ctx, projectInfo.SubAccountId)
  218. if SubAccountErr != nil {
  219. return nil, SubAccountErr
  220. }
  221. sProjectData.Phone = subAccountInfo.PhoneNumber
  222. jobInfo, jobErr := db.FindJobByJobId(ctx, subAccountInfo.JobId)
  223. if jobErr != nil {
  224. return nil, jobErr
  225. }
  226. sProjectData.CreatorType = 2
  227. sProjectData.CreatorName = jobInfo.JobName
  228. }
  229. return sProjectData, nil
  230. }
  231. // GetSSpecialProjectList 查找服务商加入商单的定向种草任务列表
  232. func (*sProject) GetSSpecialProjectList(ctx context.Context, supplierId int, pageSize, pageNum int32, condition *common_model.SSpecialProjectCondition) ([]*gorm_model.SProjectInfo, int64, error) {
  233. sProjects, total, err := db.GetSSpecialProjectList(ctx, supplierId, pageSize, pageNum, condition)
  234. if err != nil {
  235. return nil, 0, err
  236. }
  237. return sProjects, total, nil
  238. }
  239. // UpdateSProject 更新SProject信息
  240. func (*sProject) UpdateSProject(ctx context.Context, request *http_model.SpecialSProjectAddToListRequest) error {
  241. updateSProjectErr := db.UpdateSProjectStatus(ctx, request)
  242. if updateSProjectErr != nil {
  243. return updateSProjectErr
  244. }
  245. return nil
  246. }
  247. // CreateSpecialStrategy 添加服务商招募策略
  248. func (*sProject) CreateSpecialStrategy(ctx context.Context, request *http_model.SpecialAddStrategyRequest) error {
  249. // 1. 添加服务商招募策略
  250. createErr := db.CreateSpecialStrategy(ctx, request.RecruitStrategys)
  251. if createErr != nil {
  252. return createErr
  253. }
  254. // 2. 修改sProject中的字段
  255. updateErr := db.UpdateSProjectStrategyStatus(ctx, request)
  256. if updateErr != nil {
  257. return updateErr
  258. }
  259. return nil
  260. }
  261. // FullSProjectBillList 种草任务账单列表
  262. func (*sProject) FullSProjectBillList(ctx context.Context, request *http_model.FullSProjectBillListRequest) (*http_model.FullSProjectBillData, error) {
  263. // 1. 根据SupplierId和账单状态查询数据
  264. fullSProjectBillData, total, err := db.GetFullSProjectBillList(ctx, request.SupplierId, request.ProjectPlatform, request.ProjectStatus, request.PageSize, request.PageNum)
  265. if err != nil {
  266. return nil, err
  267. }
  268. var currSProjectBillData *http_model.FullSProjectBillData
  269. currSProjectBillData = &http_model.FullSProjectBillData{}
  270. currSProjectBillData.SProjectList = fullSProjectBillData
  271. currSProjectBillData.Total = total
  272. return currSProjectBillData, nil
  273. }