cooperation_service.go 22 KB

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