cooperation_service.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. package service
  2. import (
  3. "fmt"
  4. "strconv"
  5. "time"
  6. "youngee_b_api/app/dao"
  7. "youngee_b_api/app/entity"
  8. "youngee_b_api/app/vo"
  9. )
  10. type CooperationService struct{}
  11. // 服务商搜索
  12. func (s CooperationService) SearchSupplier(param *vo.SupplierSearchParam) ([]*vo.ReSupplierPreview, error) {
  13. var reSupplierPreviews []*vo.ReSupplierPreview
  14. suppliers, err := dao.SupplierDao{}.GetSuppliersByMsg(param.FieldName)
  15. if err != nil {
  16. return reSupplierPreviews, err
  17. }
  18. for _, supplier := range suppliers {
  19. // 判断该服务商是否已在商家库
  20. exist, _ := dao.EnterpriseSupplierCooperateDao{}.EnterpriseDatabaseCheck(param.EnterpriseId, supplier.SupplierID)
  21. reSupplierPreview := &vo.ReSupplierPreview{
  22. SupplierId: supplier.SupplierID,
  23. HeadUrl: "",
  24. SupplierName: supplier.SupplierName,
  25. SupplierType: supplier.SupplierType,
  26. CompanyName: supplier.CompanyName,
  27. Name: supplier.Name,
  28. Existence: exist,
  29. }
  30. reSupplierPreviews = append(reSupplierPreviews, reSupplierPreview)
  31. }
  32. return reSupplierPreviews, nil
  33. }
  34. // 服务商入库批量邀请
  35. func (s CooperationService) InviteSupplier(param *vo.SupplierInviteParam) error {
  36. // 要求传入的服务商都是未在该商家库的
  37. var records []*entity.EnterpriseSupplierCooperate
  38. for _, supplierId := range param.SupplierIds {
  39. record := &entity.EnterpriseSupplierCooperate{
  40. EnterpriseId: param.EnterpriseId,
  41. SupplierId: supplierId,
  42. CooperateNum: 1,
  43. CooperateStatus: 1,
  44. CreateTime: time.Now(),
  45. }
  46. if param.SubAccountId == 0 {
  47. record.BOperator = param.EnterpriseId
  48. record.BOperatorType = 1
  49. } else {
  50. record.BOperator = strconv.Itoa(int(param.SubAccountId))
  51. record.BOperatorType = 2
  52. }
  53. records = append(records, record)
  54. }
  55. err := dao.EnterpriseSupplierCooperateDao{}.InsertBatch(records)
  56. return err
  57. }
  58. // 在库服务商列表
  59. func (s CooperationService) GetEnterprisePoolList(param *vo.SupplierSearchInPoolParam) (vo.ResultVO, error) {
  60. if param.Page <= 0 {
  61. param.Page = 1
  62. }
  63. if param.PageSize <= 0 {
  64. param.PageSize = 10
  65. }
  66. var result vo.ResultVO
  67. var reSupplierPoolInfos []*vo.ReSupplierPoolInfo
  68. var enterpriseOperator string
  69. enterpriseSupplierCooperates, total, _ := dao.EnterpriseSupplierCooperateDao{}.GetSupplierByEnterprise(param.EnterpriseId, param.Page, param.PageSize)
  70. for _, enterpriseSupplierCooperate := range enterpriseSupplierCooperates {
  71. // 获取商家操作人姓名
  72. bOperator := enterpriseSupplierCooperate.BOperator
  73. if enterpriseSupplierCooperate.BOperatorType == 1 {
  74. enterprise, err := dao.EnterpriseDao{}.GetEnterprise(bOperator)
  75. if err == nil && enterprise != nil {
  76. enterpriseOperator = enterprise.BusinessName
  77. }
  78. } else if enterpriseSupplierCooperate.BOperatorType == 2 {
  79. subAccountId, err := strconv.ParseInt(bOperator, 10, 64)
  80. if err != nil {
  81. fmt.Println("GetEnterprisePoolList==subAccountId 转换出错:", err)
  82. } else {
  83. subAccount, err := dao.SubAccountDao{}.GetSubAccount(subAccountId)
  84. if err == nil && subAccount != nil {
  85. enterpriseOperator = subAccount.SubAccountName
  86. }
  87. }
  88. }
  89. supplier, err := dao.SupplierDao{}.GetSupplierInfoById(enterpriseSupplierCooperate.SupplierId)
  90. if err != nil {
  91. continue
  92. }
  93. supplierPreview := &vo.ReSupplierPreview{
  94. SupplierId: supplier.SupplierID,
  95. HeadUrl: "",
  96. SupplierName: supplier.SupplierName,
  97. SupplierType: supplier.SupplierType,
  98. CompanyName: supplier.CompanyName,
  99. Name: supplier.Name,
  100. Existence: true,
  101. }
  102. reSupplierPoolInfo := &vo.ReSupplierPoolInfo{
  103. SupplierPreview: supplierPreview,
  104. PhoneNumber: supplier.PhoneNumber,
  105. WechatId: "",
  106. WechatUrl: "",
  107. CooperateNum: enterpriseSupplierCooperate.CooperateNum,
  108. UploadTalentNum: enterpriseSupplierCooperate.UploadTalentNum,
  109. CooperateTalentNum: enterpriseSupplierCooperate.CooperateTalentNum,
  110. AgreeTime: enterpriseSupplierCooperate.AgreeTime.Format("2006-01-02 15:04:05"),
  111. EnterpriseOperator: enterpriseOperator,
  112. }
  113. reSupplierPoolInfos = append(reSupplierPoolInfos, reSupplierPoolInfo)
  114. }
  115. result = vo.ResultVO{
  116. Page: param.Page,
  117. PageSize: param.PageSize,
  118. Total: total,
  119. Data: reSupplierPoolInfos,
  120. }
  121. return result, nil
  122. }
  123. // 服务商邀请待确认列表
  124. func (s CooperationService) GetSupplierConfirmingList(param *vo.SupplierConfirmingParam) (vo.ResultVO, error) {
  125. if param.Page <= 0 {
  126. param.Page = 1
  127. }
  128. if param.PageSize <= 0 {
  129. param.PageSize = 10
  130. }
  131. var result vo.ResultVO
  132. var reSupplierConfirmingInfos []*vo.ReSupplierConfirmingInfo
  133. var enterpriseOperator string
  134. enterpriseSupplierCooperates, total, _ := dao.EnterpriseSupplierCooperateDao{}.GetSupplierConfirmingList(param.EnterpriseId, param.Page, param.PageSize)
  135. for _, enterpriseSupplierCooperate := range enterpriseSupplierCooperates {
  136. // 获取商家操作人姓名
  137. bOperator := enterpriseSupplierCooperate.BOperator
  138. if enterpriseSupplierCooperate.BOperatorType == 1 {
  139. enterprise, err := dao.EnterpriseDao{}.GetEnterprise(bOperator)
  140. if err == nil && enterprise != nil {
  141. enterpriseOperator = enterprise.BusinessName
  142. }
  143. } else if enterpriseSupplierCooperate.BOperatorType == 2 {
  144. subAccountId, err := strconv.ParseInt(bOperator, 10, 64)
  145. if err != nil {
  146. fmt.Println("GetSupplierConfirmingList==subAccountId 转换出错:", err)
  147. } else {
  148. subAccount, err := dao.SubAccountDao{}.GetSubAccount(subAccountId)
  149. if err == nil && subAccount != nil {
  150. enterpriseOperator = subAccount.SubAccountName
  151. }
  152. }
  153. }
  154. supplier, err := dao.SupplierDao{}.GetSupplierInfoById(enterpriseSupplierCooperate.SupplierId)
  155. var supplierPreview *vo.ReSupplierPreview
  156. var phoneNumber string
  157. if err == nil {
  158. supplierPreview = &vo.ReSupplierPreview{
  159. SupplierId: supplier.SupplierID,
  160. HeadUrl: "",
  161. SupplierName: supplier.SupplierName,
  162. SupplierType: supplier.SupplierType,
  163. CompanyName: supplier.CompanyName,
  164. Name: supplier.Name,
  165. }
  166. phoneNumber = supplier.PhoneNumber
  167. }
  168. reSupplierConfirmingInfo := &vo.ReSupplierConfirmingInfo{
  169. SupplierPreview: supplierPreview,
  170. PhoneNumber: phoneNumber,
  171. WechatId: "",
  172. WechatUrl: "",
  173. CreateTime: enterpriseSupplierCooperate.CreateTime.Format("2006-01-02 15:04:05"),
  174. Status: enterpriseSupplierCooperate.CooperateStatus,
  175. EnterpriseOperator: enterpriseOperator,
  176. }
  177. reSupplierConfirmingInfos = append(reSupplierConfirmingInfos, reSupplierConfirmingInfo)
  178. }
  179. result = vo.ResultVO{
  180. Page: param.Page,
  181. PageSize: param.PageSize,
  182. Total: total,
  183. Data: reSupplierConfirmingInfos,
  184. }
  185. return result, nil
  186. }
  187. // 服务商合作-服务商列表
  188. func (s CooperationService) GetSupplierInTargetTaskList(param *vo.SupplierSearchInTargetTaskParam) (vo.ResultVO, error) {
  189. if param.Page <= 0 {
  190. param.Page = 1
  191. }
  192. if param.PageSize <= 0 {
  193. param.PageSize = 10
  194. }
  195. var reSupplierTargetTasks []*vo.ReSupplierTargetTask
  196. var total int64
  197. result := vo.ResultVO{
  198. Page: param.Page,
  199. PageSize: param.PageSize,
  200. Total: total,
  201. Data: reSupplierTargetTasks,
  202. }
  203. var enterpriseSupplierCooperates []*entity.EnterpriseSupplierCooperate
  204. var sProjectInfos []*entity.SProjectInfo
  205. var enterpriseOperator string
  206. if param.Status == 1 { // 可邀约
  207. enterpriseSupplierCooperates, total, _ = dao.EnterpriseSupplierCooperateDao{}.GetSupplierByEnterprise(param.EnterpriseId, param.Page, param.PageSize)
  208. } else if param.Status == 2 { // 邀约中
  209. if param.TaskType == 2 {
  210. // 品牌种草
  211. sProjectInfos, total, _ = dao.SProjectDao{}.GetSProjectByStatus(param.TaskId, 1, param.Page, param.PageSize)
  212. } else if param.TaskType == 3 {
  213. // 本地生活
  214. }
  215. } else if param.Status == 3 { // 合作中
  216. if param.TaskType == 2 {
  217. // 品牌种草
  218. sProjectInfos, total, _ = dao.SProjectDao{}.GetSProjectByStatus(param.TaskId, 2, param.Page, param.PageSize)
  219. } else if param.TaskType == 3 {
  220. // 本地生活
  221. }
  222. }
  223. if enterpriseSupplierCooperates == nil {
  224. if param.TaskType == 2 { // 种草
  225. for _, sProjectInfo := range sProjectInfos {
  226. supplierId := sProjectInfo.SupplierID
  227. enterpriseSupplierCooperate, err1 := dao.EnterpriseSupplierCooperateDao{}.GetDataByEnterpriseAndSupplier(param.EnterpriseId, supplierId)
  228. if err1 != nil {
  229. return result, err1
  230. }
  231. enterpriseSupplierCooperates = append(enterpriseSupplierCooperates, enterpriseSupplierCooperate)
  232. }
  233. } else if param.TaskType == 3 {
  234. // 本地生活
  235. }
  236. }
  237. for _, enterpriseSupplierCooperate := range enterpriseSupplierCooperates {
  238. // 获取商家操作人姓名
  239. bOperator := enterpriseSupplierCooperate.BOperator
  240. if enterpriseSupplierCooperate.BOperatorType == 1 {
  241. enterprise, err := dao.EnterpriseDao{}.GetEnterprise(bOperator)
  242. if err == nil && enterprise != nil {
  243. enterpriseOperator = enterprise.BusinessName
  244. }
  245. } else if enterpriseSupplierCooperate.BOperatorType == 2 {
  246. subAccountId, err := strconv.ParseInt(bOperator, 10, 64)
  247. if err != nil {
  248. fmt.Println("GetEnterprisePoolList==subAccountId 转换出错:", err)
  249. } else {
  250. subAccount, err := dao.SubAccountDao{}.GetSubAccount(subAccountId)
  251. if err == nil && subAccount != nil {
  252. enterpriseOperator = subAccount.SubAccountName
  253. }
  254. }
  255. }
  256. supplier, err := dao.SupplierDao{}.GetSupplierInfoById(enterpriseSupplierCooperate.SupplierId)
  257. var supplierPreview *vo.ReSupplierPreview
  258. var phoneNumber string
  259. if err == nil {
  260. supplierPreview = &vo.ReSupplierPreview{
  261. SupplierId: supplier.SupplierID,
  262. HeadUrl: "",
  263. SupplierName: supplier.SupplierName,
  264. SupplierType: supplier.SupplierType,
  265. CompanyName: supplier.CompanyName,
  266. Name: supplier.Name,
  267. Existence: true,
  268. }
  269. phoneNumber = supplier.PhoneNumber
  270. }
  271. reSupplierTargetTask := &vo.ReSupplierTargetTask{
  272. SupplierPreview: supplierPreview,
  273. PhoneNumber: phoneNumber,
  274. WechatId: "",
  275. WechatUrl: "",
  276. CooperateNum: enterpriseSupplierCooperate.CooperateNum,
  277. UploadTalentNum: enterpriseSupplierCooperate.UploadTalentNum,
  278. CooperateTalentNum: enterpriseSupplierCooperate.CooperateTalentNum,
  279. EnterpriseOperator: enterpriseOperator,
  280. Status: param.Status,
  281. }
  282. reSupplierTargetTasks = append(reSupplierTargetTasks, reSupplierTargetTask)
  283. }
  284. result = vo.ResultVO{
  285. Page: param.Page,
  286. PageSize: param.PageSize,
  287. Total: total,
  288. Data: reSupplierTargetTasks,
  289. }
  290. return result, nil
  291. }
  292. // 服务商合作-邀约合作
  293. func (s CooperationService) InviteSupplierInTargetTask(param *vo.SupplierInviteInTargetTaskParam) error {
  294. var sProjectInfo entity.SProjectInfo
  295. if param.TaskType == 2 {
  296. sProjectInfo.ProjectID = param.TaskId
  297. sProjectInfo.SupplierID = param.SupplierId
  298. sProjectInfo.SProjectStatus = 1
  299. sProjectInfo.CreateTime = time.Now()
  300. if param.SubAccountId == 0 {
  301. sProjectInfo.BOperator = param.EnterpriseId
  302. sProjectInfo.BOperatorType = 1
  303. } else {
  304. sProjectInfo.BOperator = strconv.Itoa(int(param.SubAccountId))
  305. sProjectInfo.BOperatorType = 2
  306. }
  307. // 查找该 projectId 对应的信息
  308. project, err1 := dao.ProjectDAO{}.GetProjectById(param.TaskId)
  309. if err1 != nil {
  310. return err1
  311. }
  312. if project != nil {
  313. sProjectInfo.ProductID = project.ProductID
  314. sProjectInfo.ProjectName = project.ProjectName
  315. sProjectInfo.ProjectStatus = project.ProjectStatus
  316. sProjectInfo.ProjectType = project.ProjectType
  317. sProjectInfo.ProjectPlatform = project.ProjectPlatform
  318. sProjectInfo.ProjectForm = project.ProjectForm
  319. sProjectInfo.ContentType = project.ContentType
  320. sProjectInfo.EnterpriseID = param.EnterpriseId
  321. //sProjectInfo.ApplyNum = project.ApplyNum
  322. //sProjectInfo.RecruitNum = project.RecruitNum
  323. }
  324. } else if param.TaskType == 3 {
  325. // 本地生活
  326. }
  327. err := dao.SProjectDao{}.Insert(&sProjectInfo)
  328. return err
  329. }