cooperate.go 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. package service
  2. import (
  3. "context"
  4. "github.com/issue9/conv"
  5. "time"
  6. "youngee_b_api/db"
  7. "youngee_b_api/model/gorm_model"
  8. "youngee_b_api/model/http_model"
  9. )
  10. var Cooperate *cooperate
  11. type cooperate struct {
  12. }
  13. // GetEnterpriseInfoBySupplierId 通过supplierId和合作状态筛选合作商家信息
  14. func (*cooperate) GetEnterpriseInfoBySupplierId(ctx context.Context, request *http_model.EnterpriseListRequest) (*http_model.EnterpriseListData, error) {
  15. var enterpriseListData *http_model.EnterpriseListData
  16. enterpriseListData = &http_model.EnterpriseListData{}
  17. // 1. 根据服务商ID和合作状态查找信息
  18. enterpriseListInfo, total, enterpriseListInfoErr := db.GetCooperateInfoByIds(ctx, request.SupplierId, request.CooperateStatus, request.PageSize, request.PageNum-1)
  19. if enterpriseListInfoErr != nil {
  20. return nil, enterpriseListInfoErr
  21. }
  22. if enterpriseListInfo != nil {
  23. enterpriseListData.Total = total
  24. for _, c := range enterpriseListInfo {
  25. var cooperateData *http_model.EnterpriseSupplierCooperateData
  26. cooperateData = &http_model.EnterpriseSupplierCooperateData{}
  27. cooperateData.CooperateId = c.CooperateId
  28. cooperateData.CooperateStatus = c.CooperateStatus
  29. cooperateData.CooperateNum = c.CooperateNum
  30. cooperateData.SupplierId = c.SupplierId
  31. cooperateData.UploadTalentNum = c.UploadTalentNum
  32. cooperateData.CooperateTalentNum = c.CooperateTalentNum
  33. cooperateData.SOperator = c.SOperator
  34. cooperateData.SOperatorType = c.SOperatorType
  35. cooperateData.BOperator = c.BOperator
  36. cooperateData.BOperatorType = c.BOperatorType
  37. if c.CreateTime != nil {
  38. cooperateData.CreateTime = conv.MustString(c.CreateTime, "")[0:19]
  39. }
  40. if c.AgreeTime != nil {
  41. cooperateData.AgreeTime = conv.MustString(c.AgreeTime, "")[0:19]
  42. }
  43. if c.RejectTime != nil {
  44. cooperateData.RejectTime = conv.MustString(c.RejectTime, "")[0:19]
  45. }
  46. // 1.2. 商家信息
  47. enterpriseInfo, enterpriseErr := db.GetEnterpriseByEnterpriseID(ctx, c.EnterpriseId)
  48. if enterpriseErr != nil {
  49. return nil, enterpriseErr
  50. }
  51. if enterpriseInfo != nil {
  52. cooperateData.EnterprisePhone = enterpriseInfo.Phone
  53. cooperateData.EnterpriseAuth = enterpriseInfo.AuthStatus
  54. cooperateData.EnterpriseAvatar = enterpriseInfo.Avatar
  55. cooperateData.EnterpriseName = enterpriseInfo.EnterpriseName
  56. cooperateData.BOperatorName = enterpriseInfo.EnterpriseID
  57. cooperateData.WechatNumber = enterpriseInfo.WechatNumber
  58. cooperateData.WechatQrCode = enterpriseInfo.WechatQrCode
  59. cooperateData.CompanyName = enterpriseInfo.BusinessName
  60. }
  61. // 1.3. 服务商信息
  62. cooperateData.SOperatorName = conv.MustString(c.SupplierId)
  63. enterpriseListData.EnterpriseListInfo = append(enterpriseListData.EnterpriseListInfo, cooperateData)
  64. }
  65. }
  66. return enterpriseListData, nil
  67. }
  68. // CreateCooperate 创建合作关系
  69. func (*cooperate) CreateCooperate(ctx context.Context, enterpriseId string, supplierId int, subAccountId int) error {
  70. var cooperateInfo *gorm_model.EnterpriseSupplierCooperate
  71. cooperateInfo = &gorm_model.EnterpriseSupplierCooperate{}
  72. cooperateInfo.CooperateStatus = 2
  73. var currentTime time.Time
  74. currentTime = time.Now()
  75. cooperateInfo.AgreeTime = &currentTime
  76. cooperateInfo.CreateTime = &currentTime
  77. cooperateInfo.SupplierId = supplierId
  78. cooperateInfo.EnterpriseId = enterpriseId
  79. if subAccountId != 0 {
  80. cooperateInfo.SOperator = subAccountId
  81. cooperateInfo.SOperatorType = 2
  82. } else {
  83. cooperateInfo.SOperator = supplierId
  84. cooperateInfo.SOperatorType = 1
  85. }
  86. total, findErr := db.FindCooperateInfoBySupplierAndEnterprise(ctx, supplierId, enterpriseId)
  87. if findErr != nil {
  88. return findErr
  89. }
  90. if total == 0 {
  91. err := db.CreateCooperateInfo(ctx, cooperateInfo)
  92. if err != nil {
  93. return err
  94. }
  95. }
  96. return nil
  97. }
  98. // AgreeEnterpriseCooperate 同意商家合作邀约请求
  99. func (*cooperate) AgreeEnterpriseCooperate(ctx context.Context, req *http_model.AgreeCooperateRequest) error {
  100. err := db.UpdateCooperateInfo(ctx, req.CooperateId, 2, req.SupplierId, req.SubAccountId)
  101. if err != nil {
  102. return err
  103. }
  104. return nil
  105. }
  106. // RejectEnterpriseCooperate 拒绝商家合作邀约请求
  107. func (*cooperate) RejectEnterpriseCooperate(ctx context.Context, req *http_model.RejectCooperateRequest) error {
  108. err := db.UpdateCooperateInfo(ctx, req.CooperateId, 3, req.SupplierId, req.SubAccountId)
  109. if err != nil {
  110. return err
  111. }
  112. return nil
  113. }
  114. // CooperateCount 合作列表数统计
  115. func (*cooperate) CooperateCount(ctx context.Context, req *http_model.CooperateCountRequest) (*http_model.CooperateCountData, error) {
  116. var cooperateCount *http_model.CooperateCountData
  117. cooperateCount = &http_model.CooperateCountData{}
  118. status1, status1Err := db.CountCooperateBySupplierId(ctx, req.SupplierId, 1)
  119. if status1Err != nil {
  120. return nil, status1Err
  121. }
  122. cooperateCount.Status1 = status1
  123. status2, status2Err := db.CountCooperateBySupplierId(ctx, req.SupplierId, 2)
  124. if status2Err != nil {
  125. return nil, status2Err
  126. }
  127. cooperateCount.Status2 = status2
  128. status3, status3Err := db.CountCooperateBySupplierId(ctx, req.SupplierId, 3)
  129. if status3Err != nil {
  130. return nil, status3Err
  131. }
  132. cooperateCount.Status3 = status3
  133. return cooperateCount, nil
  134. }