cooperation_service.go 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  1. package service
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "gorm.io/gorm"
  7. "strconv"
  8. "time"
  9. "youngee_b_api/app/dao"
  10. "youngee_b_api/app/entity"
  11. "youngee_b_api/app/vo"
  12. )
  13. type CooperationService struct{}
  14. // 服务商搜索
  15. func (s CooperationService) SearchSupplier(param *vo.SupplierSearchParam) ([]*vo.ReSupplierPreview, error) {
  16. var reSupplierPreviews []*vo.ReSupplierPreview
  17. suppliers, err := dao.SupplierDao{}.GetSuppliersByMsg(param.FieldName)
  18. if err != nil {
  19. return reSupplierPreviews, err
  20. }
  21. for _, supplier := range suppliers {
  22. // 判断该服务商是否已在商家库
  23. exist, _ := dao.EnterpriseSupplierCooperateDao{}.EnterpriseDatabaseCheck(param.EnterpriseId, supplier.SupplierID)
  24. reSupplierPreview := &vo.ReSupplierPreview{
  25. SupplierId: supplier.SupplierID,
  26. HeadUrl: supplier.Avatar,
  27. SupplierName: supplier.SupplierName,
  28. SupplierType: supplier.SupplierType,
  29. CompanyName: supplier.CompanyName,
  30. Name: supplier.Name,
  31. ReviewStatus: supplier.ReviewStatus,
  32. Existence: exist,
  33. }
  34. reSupplierPreviews = append(reSupplierPreviews, reSupplierPreview)
  35. }
  36. return reSupplierPreviews, nil
  37. }
  38. // 服务商入库批量邀请
  39. func (s CooperationService) InviteSupplier(param *vo.SupplierInviteParam) error {
  40. // 要求传入的服务商都是未在该商家库的
  41. var records []*entity.EnterpriseSupplierCooperate
  42. for _, supplierId := range param.SupplierIds {
  43. record := &entity.EnterpriseSupplierCooperate{
  44. EnterpriseId: param.EnterpriseId,
  45. SupplierId: supplierId,
  46. CooperateNum: 1,
  47. CooperateStatus: 1,
  48. CreateTime: time.Now(),
  49. }
  50. if param.SubAccountId == 0 {
  51. record.BOperator = param.EnterpriseId
  52. record.BOperatorType = 1
  53. } else {
  54. record.BOperator = strconv.Itoa(int(param.SubAccountId))
  55. record.BOperatorType = 2
  56. }
  57. records = append(records, record)
  58. }
  59. err := dao.EnterpriseSupplierCooperateDao{}.InsertBatch(records)
  60. return err
  61. }
  62. // 在库服务商列表
  63. func (s CooperationService) GetEnterprisePoolList(param *vo.SupplierSearchInPoolParam) (vo.ResultVO, error) {
  64. if param.Page <= 0 {
  65. param.Page = 1
  66. }
  67. if param.PageSize <= 0 {
  68. param.PageSize = 10
  69. }
  70. var result vo.ResultVO
  71. var reSupplierPoolInfos []*vo.ReSupplierPoolInfo
  72. var enterpriseOperator string
  73. enterpriseSupplierCooperates, total, _ := dao.EnterpriseSupplierCooperateDao{}.GetSupplierByEnterprise(param.EnterpriseId, param.Page, param.PageSize)
  74. for _, enterpriseSupplierCooperate := range enterpriseSupplierCooperates {
  75. // 获取商家操作人姓名
  76. bOperator := enterpriseSupplierCooperate.BOperator
  77. if enterpriseSupplierCooperate.BOperatorType == 1 {
  78. enterprise, err := dao.EnterpriseDao{}.GetEnterprise(bOperator)
  79. if err == nil && enterprise != nil {
  80. enterpriseOperator = enterprise.BusinessName
  81. }
  82. } else if enterpriseSupplierCooperate.BOperatorType == 2 {
  83. subAccountId, err := strconv.ParseInt(bOperator, 10, 64)
  84. if err != nil {
  85. fmt.Println("GetEnterprisePoolList==subAccountId 转换出错:", err)
  86. } else {
  87. subAccount, err := dao.SubAccountDao{}.GetSubAccount(subAccountId)
  88. if err == nil && subAccount != nil {
  89. enterpriseOperator = subAccount.SubAccountName
  90. }
  91. }
  92. }
  93. supplier, err := dao.SupplierDao{}.GetSupplierInfoById(enterpriseSupplierCooperate.SupplierId)
  94. if err != nil {
  95. continue
  96. }
  97. supplierPreview := &vo.ReSupplierPreview{
  98. SupplierId: supplier.SupplierID,
  99. HeadUrl: supplier.Avatar,
  100. SupplierName: supplier.SupplierName,
  101. SupplierType: supplier.SupplierType,
  102. CompanyName: supplier.CompanyName,
  103. Name: supplier.Name,
  104. Existence: true,
  105. }
  106. reSupplierPoolInfo := &vo.ReSupplierPoolInfo{
  107. SupplierPreview: supplierPreview,
  108. PhoneNumber: supplier.PhoneNumber,
  109. WechatId: supplier.WechatNumber,
  110. WechatUrl: supplier.WechatQrcode,
  111. CooperateNum: enterpriseSupplierCooperate.CooperateNum,
  112. UploadTalentNum: enterpriseSupplierCooperate.UploadTalentNum,
  113. CooperateTalentNum: enterpriseSupplierCooperate.CooperateTalentNum,
  114. AgreeTime: enterpriseSupplierCooperate.AgreeTime.Format("2006-01-02 15:04:05"),
  115. EnterpriseOperator: enterpriseOperator,
  116. }
  117. reSupplierPoolInfos = append(reSupplierPoolInfos, reSupplierPoolInfo)
  118. }
  119. result = vo.ResultVO{
  120. Page: param.Page,
  121. PageSize: param.PageSize,
  122. Total: total,
  123. Data: reSupplierPoolInfos,
  124. }
  125. return result, nil
  126. }
  127. // 服务商邀请待确认列表
  128. func (s CooperationService) GetSupplierConfirmingList(param *vo.SupplierConfirmingParam) (vo.ResultVO, error) {
  129. if param.Page <= 0 {
  130. param.Page = 1
  131. }
  132. if param.PageSize <= 0 {
  133. param.PageSize = 10
  134. }
  135. var result vo.ResultVO
  136. var reSupplierConfirmingInfos []*vo.ReSupplierConfirmingInfo
  137. var enterpriseOperator string
  138. enterpriseSupplierCooperates, total, _ := dao.EnterpriseSupplierCooperateDao{}.GetSupplierConfirmingList(param.EnterpriseId, param.Page, param.PageSize)
  139. for _, enterpriseSupplierCooperate := range enterpriseSupplierCooperates {
  140. // 获取商家操作人姓名
  141. bOperator := enterpriseSupplierCooperate.BOperator
  142. if enterpriseSupplierCooperate.BOperatorType == 1 {
  143. enterprise, err := dao.EnterpriseDao{}.GetEnterprise(bOperator)
  144. if err == nil && enterprise != nil {
  145. enterpriseOperator = enterprise.BusinessName
  146. }
  147. } else if enterpriseSupplierCooperate.BOperatorType == 2 {
  148. subAccountId, err := strconv.ParseInt(bOperator, 10, 64)
  149. if err != nil {
  150. fmt.Println("GetSupplierConfirmingList==subAccountId 转换出错:", err)
  151. } else {
  152. subAccount, err := dao.SubAccountDao{}.GetSubAccount(subAccountId)
  153. if err == nil && subAccount != nil {
  154. enterpriseOperator = subAccount.SubAccountName
  155. }
  156. }
  157. }
  158. supplier, err := dao.SupplierDao{}.GetSupplierInfoById(enterpriseSupplierCooperate.SupplierId)
  159. var supplierPreview *vo.ReSupplierPreview
  160. var phoneNumber string
  161. if err == nil {
  162. supplierPreview = &vo.ReSupplierPreview{
  163. SupplierId: supplier.SupplierID,
  164. HeadUrl: supplier.Avatar,
  165. SupplierName: supplier.SupplierName,
  166. SupplierType: supplier.SupplierType,
  167. CompanyName: supplier.CompanyName,
  168. Name: supplier.Name,
  169. }
  170. phoneNumber = supplier.PhoneNumber
  171. reSupplierConfirmingInfo := &vo.ReSupplierConfirmingInfo{
  172. SupplierPreview: supplierPreview,
  173. PhoneNumber: phoneNumber,
  174. WechatId: supplier.WechatNumber,
  175. WechatUrl: supplier.WechatQrcode,
  176. CreateTime: enterpriseSupplierCooperate.CreateTime.Format("2006-01-02 15:04:05"),
  177. Status: enterpriseSupplierCooperate.CooperateStatus,
  178. EnterpriseOperator: enterpriseOperator,
  179. }
  180. reSupplierConfirmingInfos = append(reSupplierConfirmingInfos, reSupplierConfirmingInfo)
  181. }
  182. }
  183. result = vo.ResultVO{
  184. Page: param.Page,
  185. PageSize: param.PageSize,
  186. Total: total,
  187. Data: reSupplierConfirmingInfos,
  188. }
  189. return result, nil
  190. }
  191. // 服务商管理-角标
  192. func (t CooperationService) GetSupplierCount(param *vo.SupplierConfirmingParam) map[string]int64 {
  193. res := make(map[string]int64)
  194. var inPoolNum int64 // 在库服务商
  195. var confirmingNum int64 // 邀请待确认
  196. dao.Db.Model(&entity.EnterpriseSupplierCooperate{}).Where("enterprise_id = ? AND cooperate_status = 2", param.EnterpriseId).Count(&inPoolNum)
  197. dao.Db.Model(&entity.EnterpriseSupplierCooperate{}).Where("enterprise_id = ? AND cooperate_status = 1", param.EnterpriseId).Count(&confirmingNum)
  198. res["inPoolNum"] = inPoolNum
  199. res["confirmingNum"] = confirmingNum
  200. return res
  201. }
  202. // 服务商管理-服务商数据卡
  203. func (t CooperationService) GetSupplierData(param *vo.SupplierDataParam) vo.ReSupplierCoopData {
  204. var reSupplierCoopData vo.ReSupplierCoopData
  205. supplier, err1 := dao.SupplierDao{}.GetSupplierInfoById(param.SupplierId)
  206. if err1 != nil {
  207. return vo.ReSupplierCoopData{}
  208. }
  209. supplierPreview := &vo.SupplierPreview{
  210. SupplierId: supplier.SupplierID,
  211. AvatarUrl: supplier.Avatar,
  212. SupplierName: supplier.SupplierName,
  213. CompanyName: supplier.CompanyName,
  214. WXAccount: supplier.WechatNumber,
  215. CodeUrl: supplier.WechatQrcode,
  216. Phone: supplier.ContactPhone,
  217. Platform: []int{1, 2, 3, 4, 5},
  218. }
  219. reSupplierCoopData.SupplierPreview = supplierPreview
  220. var count int64
  221. _ = dao.Db.Model(&entity.EnterpriseSupplierCooperate{}).Where("supplier_id = ? AND cooperate_status = 2", param.SupplierId).Count(&count).Error
  222. enterpriseSupplierCooperate, err2 := dao.EnterpriseSupplierCooperateDao{}.GetDataByEnterpriseAndSupplier(param.EnterpriseId, param.SupplierId)
  223. if err2 != nil {
  224. return reSupplierCoopData
  225. }
  226. coreData := &vo.CoreData{
  227. CooperateNum: enterpriseSupplierCooperate.CooperateNum,
  228. ReportTalentNum: enterpriseSupplierCooperate.UploadTalentNum,
  229. TalentCoopNum: enterpriseSupplierCooperate.CooperateTalentNum,
  230. PutStoreNum: count,
  231. }
  232. var commentCount, viewCount int64
  233. projectTaskLinkStatistics, err3 := dao.ProjectTaskLinkStatisticDao{}.GetSupplierData(param.SupplierId)
  234. if err3 != nil {
  235. return reSupplierCoopData
  236. }
  237. localTaskLinkStatistics, err4 := dao.LocalTaskLinkStatisticDao{}.GetSupplierData(param.SupplierId)
  238. if err4 != nil {
  239. return reSupplierCoopData
  240. }
  241. for _, projectTaskLinkStatistic := range projectTaskLinkStatistics {
  242. commentCount += projectTaskLinkStatistic.CommitCount
  243. viewCount += projectTaskLinkStatistic.ViewCount
  244. }
  245. for _, localTaskLinkStatistic := range localTaskLinkStatistics {
  246. commentCount += localTaskLinkStatistic.CommitCount
  247. viewCount += localTaskLinkStatistic.ViewCount
  248. }
  249. coreData.ViewNum = viewCount
  250. coreData.InteractNum = commentCount
  251. reSupplierCoopData.CoreData = coreData
  252. return reSupplierCoopData
  253. }
  254. // 服务商管理-服务商数据卡列表
  255. func (t CooperationService) GetSupplierPerform(param *vo.SupplierDataParam) (vo.ResultVO, error) {
  256. if param.Page <= 0 {
  257. param.Page = 1
  258. }
  259. if param.PageSize <= 0 {
  260. param.PageSize = 10
  261. }
  262. var supplierDataParams []*vo.SupplierPerformance
  263. var total int64
  264. result := vo.ResultVO{
  265. Page: param.Page,
  266. PageSize: param.PageSize,
  267. Total: total,
  268. Data: supplierDataParams,
  269. }
  270. // 获取supplierId下的所有任务,再根据任务获取数据
  271. if param.TaskType == 2 {
  272. projectTaskLinkStatistics, total1, err1 := dao.ProjectTaskLinkStatisticDao{}.GetProjectList(param.SupplierId, param.Page, param.PageSize)
  273. total = total1
  274. if err1 != nil {
  275. return result, err1
  276. }
  277. for _, projectTaskLinkStatistic := range projectTaskLinkStatistics {
  278. var perform vo.SupplierPerformance
  279. projectId := projectTaskLinkStatistic.ProjectID
  280. project, err2 := dao.ProjectDAO{}.GetProjectById(projectId)
  281. if err2 != nil {
  282. return result, err2
  283. }
  284. var product entity.Product
  285. var productMainPhoto entity.ProductPhoto
  286. err11 := json.Unmarshal([]byte(project.ProductSnap), &product)
  287. err12 := json.Unmarshal([]byte(project.ProductPhotoSnap), &productMainPhoto)
  288. if err11 != nil && err12 != nil {
  289. perform.MainImage = productMainPhoto.PhotoUrl
  290. perform.ProductName = product.ProductName
  291. perform.Price = product.ProductPrice
  292. perform.ViewCount = projectTaskLinkStatistic.ViewCount
  293. perform.VoteCount = projectTaskLinkStatistic.VoteCount
  294. perform.CollectCount = projectTaskLinkStatistic.CollectionCount
  295. perform.CommentCount = projectTaskLinkStatistic.CommitCount
  296. }
  297. supplierDataParams = append(supplierDataParams, &perform)
  298. }
  299. } else if param.TaskType == 3 {
  300. localTaskLinkStatistics, total1, err1 := dao.LocalTaskLinkStatisticDao{}.GetLocalList(param.SupplierId, param.Page, param.PageSize)
  301. total = total1
  302. if err1 != nil {
  303. return result, err1
  304. }
  305. for _, localTaskLinkStatistic := range localTaskLinkStatistics {
  306. var perform vo.SupplierPerformance
  307. localId := localTaskLinkStatistic.LocalID
  308. local, err2 := dao.LocalLifeDao{}.GetLocalById(localId)
  309. if err2 != nil {
  310. return result, err2
  311. }
  312. store, err11 := dao.StoreDao{}.GetStoreByID(local.StoreID)
  313. if err11 == nil && store != nil {
  314. photoUrl, e := dao.ProductPhotoDAO{}.GetMainPhotoByStoreID(store.StoreID)
  315. if e != nil {
  316. photoUrl = ""
  317. }
  318. perform.MainImage = photoUrl
  319. perform.StoreName = store.StoreName
  320. perform.ViewCount = localTaskLinkStatistic.ViewCount
  321. perform.VoteCount = localTaskLinkStatistic.VoteCount
  322. perform.CollectCount = localTaskLinkStatistic.CollectionCount
  323. perform.CommentCount = localTaskLinkStatistic.CommitCount
  324. }
  325. supplierDataParams = append(supplierDataParams, &perform)
  326. }
  327. }
  328. result = vo.ResultVO{
  329. Page: param.Page,
  330. PageSize: param.PageSize,
  331. Total: total,
  332. Data: supplierDataParams,
  333. }
  334. return result, nil
  335. }
  336. // 服务商合作-服务商列表
  337. func (s CooperationService) GetSupplierInTargetTaskList(param *vo.SupplierSearchInTargetTaskParam) (vo.ResultVO, error) {
  338. if param.Page <= 0 {
  339. param.Page = 1
  340. }
  341. if param.PageSize <= 0 {
  342. param.PageSize = 10
  343. }
  344. var reSupplierTargetTasks []*vo.ReSupplierTargetTask
  345. var total int64
  346. result := vo.ResultVO{
  347. Page: param.Page,
  348. PageSize: param.PageSize,
  349. Total: total,
  350. Data: reSupplierTargetTasks,
  351. }
  352. var enterpriseSupplierCooperates []*entity.EnterpriseSupplierCooperate
  353. var sProjectInfos []*entity.SProjectInfo
  354. var sLocalLifeInfos []*entity.SLocalLifeInfo
  355. var enterpriseOperator string
  356. if param.Status == 1 { // 可邀约
  357. enterpriseSupplierCooperates, total, _ = dao.EnterpriseSupplierCooperateDao{}.GetSupplierByEnterprise(param.EnterpriseId, param.Page, param.PageSize)
  358. var resEnterpriseSuppliers []*entity.EnterpriseSupplierCooperate
  359. if param.TaskType == 2 {
  360. // 品牌种草
  361. // 去除当前project_id、supplier_id已在 s_project_info中的数据
  362. for _, enterpriseSupplier := range enterpriseSupplierCooperates {
  363. var sProject entity.SProjectInfo
  364. err1 := dao.Db.Model(&entity.SProjectInfo{}).Where("project_id = ? and supplier_id = ?", param.TaskId, enterpriseSupplier.SupplierId).First(&sProject).Error
  365. if err1 != nil {
  366. if errors.Is(err1, gorm.ErrRecordNotFound) {
  367. resEnterpriseSuppliers = append(resEnterpriseSuppliers, enterpriseSupplier)
  368. } else {
  369. // 其他错误
  370. }
  371. }
  372. }
  373. } else if param.TaskType == 3 {
  374. // 本地生活
  375. // 去除当前 local_id、supplier_id 已在 s_local_info中的数据
  376. for _, enterpriseSupplier := range enterpriseSupplierCooperates {
  377. var sLocalLifeInfo entity.SLocalLifeInfo
  378. err2 := dao.Db.Model(&entity.SLocalLifeInfo{}).Where("local_id = ? and supplier_id = ?", param.TaskId, enterpriseSupplier.SupplierId).First(&sLocalLifeInfo).Error
  379. if err2 != nil {
  380. if errors.Is(err2, gorm.ErrRecordNotFound) {
  381. resEnterpriseSuppliers = append(resEnterpriseSuppliers, enterpriseSupplier)
  382. } else {
  383. // 其他错误
  384. }
  385. }
  386. }
  387. }
  388. enterpriseSupplierCooperates = resEnterpriseSuppliers
  389. total = int64(len(enterpriseSupplierCooperates))
  390. } else if param.Status == 2 { // 邀约中
  391. if param.TaskType == 2 {
  392. // 品牌种草
  393. sProjectInfos, total, _ = dao.SProjectDao{}.GetSProjectByStatus(param.TaskId, 1, param.Page, param.PageSize)
  394. } else if param.TaskType == 3 {
  395. // 本地生活
  396. sLocalLifeInfos, total, _ = dao.SLocalLifeDao{}.GetSLocalLifeByStatus(param.TaskId, 1, param.Page, param.PageSize)
  397. }
  398. } else if param.Status == 3 { // 合作中
  399. if param.TaskType == 2 {
  400. // 品牌种草
  401. sProjectInfos, total, _ = dao.SProjectDao{}.GetSProjectByStatus(param.TaskId, 2, param.Page, param.PageSize)
  402. } else if param.TaskType == 3 {
  403. // 本地生活
  404. sLocalLifeInfos, total, _ = dao.SLocalLifeDao{}.GetSLocalLifeByStatus(param.TaskId, 2, param.Page, param.PageSize)
  405. }
  406. }
  407. // 针对邀约中、合作中情形
  408. if param.Status == 2 || param.Status == 3 {
  409. if param.TaskType == 2 { // 种草
  410. for _, sProjectInfo := range sProjectInfos {
  411. supplierId := sProjectInfo.SupplierID
  412. enterpriseSupplierCooperate, err1 := dao.EnterpriseSupplierCooperateDao{}.GetDataByEnterpriseAndSupplier(param.EnterpriseId, supplierId)
  413. if err1 != nil {
  414. return result, err1
  415. }
  416. enterpriseSupplierCooperates = append(enterpriseSupplierCooperates, enterpriseSupplierCooperate)
  417. }
  418. } else if param.TaskType == 3 {
  419. // 本地生活
  420. for _, sLocalLifeInfo := range sLocalLifeInfos {
  421. supplierId := sLocalLifeInfo.SupplierID
  422. enterpriseSupplierCooperate, err1 := dao.EnterpriseSupplierCooperateDao{}.GetDataByEnterpriseAndSupplier(param.EnterpriseId, supplierId)
  423. if err1 != nil {
  424. return result, err1
  425. }
  426. enterpriseSupplierCooperates = append(enterpriseSupplierCooperates, enterpriseSupplierCooperate)
  427. }
  428. }
  429. }
  430. for _, enterpriseSupplierCooperate := range enterpriseSupplierCooperates {
  431. // 获取商家操作人姓名
  432. bOperator := enterpriseSupplierCooperate.BOperator
  433. if enterpriseSupplierCooperate.BOperatorType == 1 {
  434. enterprise, err := dao.EnterpriseDao{}.GetEnterprise(bOperator)
  435. if err == nil && enterprise != nil {
  436. enterpriseOperator = enterprise.BusinessName
  437. }
  438. } else if enterpriseSupplierCooperate.BOperatorType == 2 {
  439. subAccountId, err := strconv.ParseInt(bOperator, 10, 64)
  440. if err != nil {
  441. fmt.Println("GetEnterprisePoolList==subAccountId 转换出错:", err)
  442. } else {
  443. subAccount, err := dao.SubAccountDao{}.GetSubAccount(subAccountId)
  444. if err == nil && subAccount != nil {
  445. enterpriseOperator = subAccount.SubAccountName
  446. }
  447. }
  448. }
  449. supplier, err := dao.SupplierDao{}.GetSupplierInfoById(enterpriseSupplierCooperate.SupplierId)
  450. var supplierPreview *vo.ReSupplierPreview
  451. var phoneNumber string
  452. if err == nil && supplier != nil {
  453. supplierPreview = &vo.ReSupplierPreview{
  454. SupplierId: supplier.SupplierID,
  455. HeadUrl: supplier.Avatar,
  456. SupplierName: supplier.SupplierName,
  457. SupplierType: supplier.SupplierType,
  458. CompanyName: supplier.CompanyName,
  459. Name: supplier.Name,
  460. Existence: true,
  461. }
  462. phoneNumber = supplier.PhoneNumber
  463. reSupplierTargetTask := &vo.ReSupplierTargetTask{
  464. SupplierPreview: supplierPreview,
  465. PhoneNumber: phoneNumber,
  466. WechatId: supplier.WechatNumber,
  467. WechatUrl: supplier.WechatQrcode,
  468. CooperateNum: enterpriseSupplierCooperate.CooperateNum,
  469. UploadTalentNum: enterpriseSupplierCooperate.UploadTalentNum,
  470. CooperateTalentNum: enterpriseSupplierCooperate.CooperateTalentNum,
  471. EnterpriseOperator: enterpriseOperator,
  472. Status: param.Status,
  473. }
  474. reSupplierTargetTasks = append(reSupplierTargetTasks, reSupplierTargetTask)
  475. }
  476. }
  477. result = vo.ResultVO{
  478. Page: param.Page,
  479. PageSize: param.PageSize,
  480. Total: total,
  481. Data: reSupplierTargetTasks,
  482. }
  483. return result, nil
  484. }
  485. // 服务商合作-服务商列表角标
  486. func (t CooperationService) GetSupplierInTargetCount(param *vo.SupplierSearchInTargetTaskParam) map[string]int64 {
  487. res := make(map[string]int64)
  488. var invitableNum int64 // 可邀约
  489. var invitingNum int64 // 邀约中
  490. var cooperatingNum int64 // 合作中
  491. if param.TaskType == 2 {
  492. // 品牌种草
  493. var enterpriseSupplierCooperates []*entity.EnterpriseSupplierCooperate
  494. query := dao.Db.Model(&entity.EnterpriseSupplierCooperate{}).Where("enterprise_id = ? AND cooperate_status = 2", param.EnterpriseId)
  495. err := query.Select("supplier_id").Find(&enterpriseSupplierCooperates).Error
  496. var resEnterpriseSuppliers []*entity.EnterpriseSupplierCooperate
  497. if err == nil {
  498. // 去除当前project_id、supplier_id已在 s_project_info中的数据
  499. for _, enterpriseSupplier := range enterpriseSupplierCooperates {
  500. var sProject entity.SProjectInfo
  501. err1 := dao.Db.Debug().Model(&entity.SProjectInfo{}).Where("project_id = ? and supplier_id = ?", param.TaskId, enterpriseSupplier.SupplierId).First(&sProject).Error
  502. if err1 != nil {
  503. if errors.Is(err1, gorm.ErrRecordNotFound) {
  504. resEnterpriseSuppliers = append(resEnterpriseSuppliers, enterpriseSupplier)
  505. } else {
  506. // 其他错误
  507. }
  508. }
  509. }
  510. }
  511. invitableNum = int64(len(resEnterpriseSuppliers))
  512. dao.Db.Model(&entity.SProjectInfo{}).Where("project_id = ? AND s_project_status = ?", param.TaskId, 1).Count(&invitingNum)
  513. dao.Db.Model(&entity.SProjectInfo{}).Where("project_id = ? AND s_project_status = ?", param.TaskId, 2).Count(&cooperatingNum)
  514. } else if param.TaskType == 3 {
  515. // 本地生活
  516. var enterpriseSupplierCooperates []*entity.EnterpriseSupplierCooperate
  517. query := dao.Db.Model(&entity.EnterpriseSupplierCooperate{}).Where("enterprise_id = ? AND cooperate_status = 2", param.EnterpriseId)
  518. err := query.Select("supplier_id").Find(&enterpriseSupplierCooperates).Error
  519. var resEnterpriseSuppliers []*entity.EnterpriseSupplierCooperate
  520. if err == nil {
  521. // 去除当前local_id、supplier_id已在 s_local_info中的数据
  522. for _, enterpriseSupplier := range enterpriseSupplierCooperates {
  523. var sLocalLifeInfo entity.SLocalLifeInfo
  524. err1 := dao.Db.Model(&entity.SLocalLifeInfo{}).Where("local_id = ? and supplier_id = ?", param.TaskId, enterpriseSupplier.SupplierId).First(&sLocalLifeInfo).Error
  525. if err1 != nil {
  526. if errors.Is(err1, gorm.ErrRecordNotFound) {
  527. resEnterpriseSuppliers = append(resEnterpriseSuppliers, enterpriseSupplier)
  528. } else {
  529. // 其他错误
  530. }
  531. }
  532. }
  533. }
  534. invitableNum = int64(len(resEnterpriseSuppliers))
  535. dao.Db.Model(&entity.SLocalLifeInfo{}).Where("local_id = ? AND s_local_status = ?", param.TaskId, 1).Count(&invitingNum)
  536. dao.Db.Model(&entity.SProjectInfo{}).Where("local_id = ? AND s_local_status = ?", param.TaskId, 2).Count(&cooperatingNum)
  537. }
  538. res["invitableNum"] = invitableNum
  539. res["invitingNum"] = invitingNum
  540. res["cooperatingNum"] = cooperatingNum
  541. return res
  542. }
  543. // 服务商合作-邀约合作
  544. func (s CooperationService) InviteSupplierInTargetTask(param *vo.SupplierInviteInTargetTaskParam) error {
  545. var err error
  546. if param.TaskType == 2 {
  547. var sProjectInfo entity.SProjectInfo
  548. sProjectInfo.ProjectID = param.TaskId
  549. sProjectInfo.SupplierID = param.SupplierId
  550. sProjectInfo.SProjectStatus = 1
  551. t := time.Now()
  552. sProjectInfo.CreateTime = &t
  553. if param.SubAccountId == 0 {
  554. sProjectInfo.BOperator = param.EnterpriseId
  555. sProjectInfo.BOperatorType = 1
  556. } else {
  557. sProjectInfo.BOperator = strconv.Itoa(int(param.SubAccountId))
  558. sProjectInfo.BOperatorType = 2
  559. }
  560. // 查找该 projectId 对应的信息
  561. project, err1 := dao.ProjectDAO{}.GetProjectById(param.TaskId)
  562. if err1 != nil {
  563. return err1
  564. }
  565. if project != nil {
  566. sProjectInfo.ProductID = project.ProductID
  567. sProjectInfo.ProjectName = project.ProjectName
  568. sProjectInfo.ProjectStatus = project.ProjectStatus
  569. sProjectInfo.ProjectType = project.ProjectType
  570. sProjectInfo.ProjectPlatform = project.ProjectPlatform
  571. sProjectInfo.ProjectForm = project.ProjectForm
  572. sProjectInfo.ContentType = project.ContentType
  573. sProjectInfo.EnterpriseID = param.EnterpriseId
  574. //sProjectInfo.ApplyNum = project.ApplyNum
  575. //sProjectInfo.RecruitNum = project.RecruitNum
  576. }
  577. err = dao.SProjectDao{}.Insert(&sProjectInfo)
  578. } else if param.TaskType == 3 {
  579. // 本地生活
  580. var sLocalLifeInfo entity.SLocalLifeInfo
  581. sLocalLifeInfo.LocalID = param.TaskId
  582. sLocalLifeInfo.SupplierID = param.SupplierId
  583. sLocalLifeInfo.SLocalStatus = 1
  584. t := time.Now()
  585. sLocalLifeInfo.CreateTime = &t
  586. if param.SubAccountId == 0 {
  587. sLocalLifeInfo.BOperator = param.EnterpriseId
  588. sLocalLifeInfo.BOperatorType = 1
  589. } else {
  590. sLocalLifeInfo.BOperator = strconv.Itoa(int(param.SubAccountId))
  591. sLocalLifeInfo.BOperatorType = 2
  592. }
  593. // 查找该 localId 对应的信息
  594. localLife, err1 := dao.LocalLifeDao{}.GetLocalById(param.TaskId)
  595. if err1 != nil {
  596. return err1
  597. }
  598. if localLife != nil {
  599. sLocalLifeInfo.StoreID = localLife.StoreID
  600. sLocalLifeInfo.TeamBuyingID = localLife.TeamBuyingId
  601. sLocalLifeInfo.LocalName = localLife.LocalName
  602. sLocalLifeInfo.TaskStatus = localLife.TaskStatus
  603. sLocalLifeInfo.LocalType = localLife.LocalType
  604. sLocalLifeInfo.LocalPlatform = localLife.LocalPlatform
  605. sLocalLifeInfo.TaskForm = localLife.TaskForm
  606. sLocalLifeInfo.ContentType = localLife.ContentType
  607. sLocalLifeInfo.EnterpriseID = param.EnterpriseId
  608. //sProjectInfo.ApplyNum = project.ApplyNum
  609. //sProjectInfo.RecruitNum = project.RecruitNum
  610. }
  611. err = dao.SLocalLifeDao{}.Insert(&sLocalLifeInfo)
  612. }
  613. return err
  614. }