cooperation_service.go 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830
  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) GetCoopTalentData(param *vo.TalentDataParam) vo.ReTalentCoopData {
  204. var res vo.ReTalentCoopData
  205. talent, err1 := dao.TalentInfoDao{}.GetTalentInfo(param.TalentId)
  206. user, err2 := dao.PlatformKuaishouUserInfoDao{}.GetUserInfoById(param.PlatFormUserId)
  207. if err1 != nil && err2 != nil {
  208. return vo.ReTalentCoopData{}
  209. }
  210. talentDataPreview := &vo.TalentDataPreview{
  211. TalentId: talent.ID,
  212. AvatarUrl: user.HeadUri,
  213. Sex: user.Gender,
  214. TalentName: user.NickName,
  215. WXAccount: talent.WxNum,
  216. Phone: talent.TalentPhoneNumber,
  217. Skill: user.Skill,
  218. OpenId: user.OpenID,
  219. }
  220. res.TalentDataPreview = talentDataPreview
  221. var applynum, executenum, endnum int64
  222. executenum = dao.ProjectTaskInfoDao{}.CountExcuteNumByOpenid(user.OpenID)
  223. applynum = dao.ProjectTaskInfoDao{}.CountAllByOpenid(user.OpenID)
  224. endnum = dao.ProjectTaskInfoDao{}.CountByOpenid(user.OpenID, 15)
  225. executenum += dao.SelectionTaskInfoDao{}.CountExcuteNumByOpenid(user.OpenID)
  226. applynum += dao.SelectionTaskInfoDao{}.CountAllByOpenid(user.OpenID)
  227. endnum += dao.SelectionTaskInfoDao{}.CountByOpenid(user.OpenID, 10)
  228. executenum += dao.LocalLifeTaskInfoDao{}.CountExcuteNumByOpenid(user.OpenID)
  229. applynum += dao.LocalLifeTaskInfoDao{}.CountAllByOpenid(user.OpenID)
  230. endnum += dao.LocalLifeTaskInfoDao{}.CountByOpenid(user.OpenID, 15)
  231. coopdata := &vo.TalentCoopData{
  232. SignTaskNum: applynum,
  233. SelectedTaskNum: endnum + executenum,
  234. PerformTaskNum: executenum,
  235. CompleteTaskNum: endnum,
  236. }
  237. res.TalentCoopData = coopdata
  238. return res
  239. }
  240. // 达人数据
  241. func (t CooperationService) GetTalentData(param *vo.TalentDataParam) vo.ReTalentData {
  242. var res vo.ReTalentData
  243. talent, err1 := dao.TalentInfoDao{}.GetTalentInfo(param.TalentId)
  244. user, err2 := dao.PlatformKuaishouUserInfoDao{}.GetUserInfoById(param.PlatFormUserId)
  245. if err1 != nil && err2 != nil {
  246. return vo.ReTalentData{}
  247. }
  248. talentDataPreview := &vo.TalentDataPreview{
  249. TalentId: talent.ID,
  250. AvatarUrl: user.HeadUri,
  251. Sex: user.Gender,
  252. TalentName: user.NickName,
  253. WXAccount: talent.WxNum,
  254. Phone: talent.TalentPhoneNumber,
  255. Skill: user.Skill,
  256. OpenId: user.OpenID,
  257. }
  258. res.TalentDataPreview = talentDataPreview
  259. var avgLikeNum float64
  260. if user.VideoNum != 0 {
  261. avgLikeNum = float64(user.LikeNum) / float64(user.VideoNum)
  262. } else {
  263. avgLikeNum = 0
  264. }
  265. coreData := &vo.TalentCoreData{
  266. FansNum: user.Fan,
  267. AvgLikeNum: avgLikeNum,
  268. AvgCollect: 0,
  269. AvgComment: 0,
  270. ThirtySaleNum: 0,
  271. SixtySaleNum: 0,
  272. NinetySaleNum: 0,
  273. }
  274. res.TalentCoreData = coreData
  275. return res
  276. }
  277. // 服务商管理-服务商数据卡
  278. func (t CooperationService) GetSupplierData(param *vo.SupplierDataParam) vo.ReSupplierCoopData {
  279. var reSupplierCoopData vo.ReSupplierCoopData
  280. supplier, err1 := dao.SupplierDao{}.GetSupplierInfoById(param.SupplierId)
  281. if err1 != nil {
  282. return vo.ReSupplierCoopData{}
  283. }
  284. supplierPreview := &vo.SupplierPreview{
  285. SupplierId: supplier.SupplierID,
  286. AvatarUrl: supplier.Avatar,
  287. SupplierName: supplier.SupplierName,
  288. CompanyName: supplier.CompanyName,
  289. WXAccount: supplier.WechatNumber,
  290. CodeUrl: supplier.WechatQrcode,
  291. Phone: supplier.ContactPhone,
  292. Platform: []int{1, 2, 3, 4, 5},
  293. }
  294. reSupplierCoopData.SupplierPreview = supplierPreview
  295. var count int64
  296. _ = dao.Db.Model(&entity.EnterpriseSupplierCooperate{}).Where("supplier_id = ? AND cooperate_status = 2", param.SupplierId).Count(&count).Error
  297. enterpriseSupplierCooperate, err2 := dao.EnterpriseSupplierCooperateDao{}.GetDataByEnterpriseAndSupplier(param.EnterpriseId, param.SupplierId)
  298. if err2 != nil {
  299. return reSupplierCoopData
  300. }
  301. coreData := &vo.CoreData{
  302. CooperateNum: enterpriseSupplierCooperate.CooperateNum,
  303. ReportTalentNum: enterpriseSupplierCooperate.UploadTalentNum,
  304. TalentCoopNum: enterpriseSupplierCooperate.CooperateTalentNum,
  305. PutStoreNum: count,
  306. }
  307. var commentCount, viewCount int64
  308. projectTaskLinkStatistics, err3 := dao.ProjectTaskLinkStatisticDao{}.GetSupplierData(param.SupplierId)
  309. if err3 != nil {
  310. return reSupplierCoopData
  311. }
  312. localTaskLinkStatistics, err4 := dao.LocalTaskLinkStatisticDao{}.GetSupplierData(param.SupplierId)
  313. if err4 != nil {
  314. return reSupplierCoopData
  315. }
  316. for _, projectTaskLinkStatistic := range projectTaskLinkStatistics {
  317. commentCount += projectTaskLinkStatistic.CommitCount
  318. viewCount += projectTaskLinkStatistic.ViewCount
  319. }
  320. for _, localTaskLinkStatistic := range localTaskLinkStatistics {
  321. commentCount += localTaskLinkStatistic.CommitCount
  322. viewCount += localTaskLinkStatistic.ViewCount
  323. }
  324. coreData.ViewNum = viewCount
  325. coreData.InteractNum = commentCount
  326. reSupplierCoopData.CoreData = coreData
  327. return reSupplierCoopData
  328. }
  329. // 达人管理-达人数据卡列表
  330. func (t CooperationService) GetTalentPerform(param *vo.TalentDataParam) (vo.ResultVO, error) {
  331. if param.Page <= 0 {
  332. param.Page = 1
  333. }
  334. if param.PageSize <= 0 {
  335. param.PageSize = 10
  336. }
  337. var talentDataParams []*vo.TalentPerformance
  338. var total int64
  339. result := vo.ResultVO{
  340. Page: param.Page,
  341. PageSize: param.PageSize,
  342. Total: total,
  343. Data: talentDataParams,
  344. }
  345. //带货
  346. if param.TaskType == 1 {
  347. sectasks, total1, err1 := dao.SelectionTaskInfoDao{}.GetSecInfoByOpenId(param.TalentId, param.Others, param.SortField, param.SortOrder, param.Page, param.PageSize, param.RelType, param.EnterpriseId)
  348. total = total1
  349. if err1 != nil {
  350. return result, err1
  351. }
  352. for _, sectask := range sectasks {
  353. var perform vo.TalentPerformance
  354. secid := sectask.SelectionID
  355. sec, err2 := dao.SelectionInfoDAO{}.GetSelectionInfoById(secid)
  356. if err2 != nil {
  357. return result, err2
  358. }
  359. var product entity.Product
  360. var productMainPhoto entity.ProductPhoto
  361. err11 := json.Unmarshal([]byte(sec.ProductSnap), &product)
  362. err12 := json.Unmarshal([]byte(sec.ProductPhotoSnap), &productMainPhoto)
  363. if err11 == nil && err12 == nil {
  364. perform.MainImage = productMainPhoto.PhotoUrl
  365. perform.ProductName = product.ProductName
  366. perform.Price = product.ProductPrice
  367. perform.Category = product.ProductCategory
  368. perform.SalesNum = sectask.SaleActual
  369. }
  370. talentDataParams = append(talentDataParams, &perform)
  371. }
  372. } else if param.TaskType == 2 {
  373. prjtasks, total2, err2 := dao.ProjectTaskInfoDao{}.GetProjectInfoByTalentId(param.TalentId, param.Others, param.SortField, param.SortOrder, param.Page, param.PageSize, param.RelType, param.EnterpriseId, param.Platform)
  374. total = total2
  375. if err2 != nil {
  376. return result, err2
  377. }
  378. for _, sectask := range prjtasks {
  379. var perform vo.TalentPerformance
  380. secid := sectask.ProjectID
  381. sec, err2 := dao.ProjectDAO{}.GetProjectById(secid)
  382. if err2 != nil {
  383. return result, err2
  384. }
  385. var product entity.Product
  386. var productMainPhoto entity.ProductPhoto
  387. err11 := json.Unmarshal([]byte(sec.ProductSnap), &product)
  388. err12 := json.Unmarshal([]byte(sec.ProductPhotoSnap), &productMainPhoto)
  389. if err11 == nil && err12 == nil {
  390. perform.MainImage = productMainPhoto.PhotoUrl
  391. perform.ProductName = product.ProductName
  392. perform.Price = product.ProductPrice
  393. perform.VoteCount = sectask.VoteAvg
  394. perform.ViewCount = sectask.ViewNum
  395. perform.CollectCount = sectask.CollectNum
  396. perform.CommentCount = sectask.CommitAvg
  397. }
  398. talentDataParams = append(talentDataParams, &perform)
  399. }
  400. fmt.Println(talentDataParams)
  401. } else if param.TaskType == 3 {
  402. prjtasks, total3, err3 := dao.LocalLifeTaskInfoDao{}.GetLocalLifeInfoByTalentId(param.TalentId, param.Others, param.SortField, param.SortOrder, param.Page, param.PageSize, param.RelType, param.EnterpriseId, param.Platform)
  403. total = total3
  404. if err3 != nil {
  405. return result, err3
  406. }
  407. for _, sectask := range prjtasks {
  408. var perform vo.TalentPerformance
  409. secid := sectask.LocalID
  410. sec, err2 := dao.ProjectDAO{}.GetProjectById(secid)
  411. if err2 != nil {
  412. return result, err2
  413. }
  414. var product entity.Product
  415. var productMainPhoto entity.ProductPhoto
  416. err11 := json.Unmarshal([]byte(sec.ProductSnap), &product)
  417. err12 := json.Unmarshal([]byte(sec.ProductPhotoSnap), &productMainPhoto)
  418. if err11 == nil && err12 == nil {
  419. perform.MainImage = productMainPhoto.PhotoUrl
  420. perform.ProductName = product.ProductName
  421. perform.Price = product.ProductPrice
  422. perform.VoteCount = int(sectask.VoteAvg)
  423. perform.ViewCount = 0
  424. perform.CollectCount = sectask.CollectNum
  425. perform.CommentCount = int(sectask.CommitAvg)
  426. }
  427. talentDataParams = append(talentDataParams, &perform)
  428. }
  429. }
  430. result = vo.ResultVO{
  431. Page: param.Page,
  432. PageSize: param.PageSize,
  433. Total: total,
  434. Data: talentDataParams,
  435. }
  436. return result, nil
  437. }
  438. // 服务商管理-服务商数据卡列表
  439. func (t CooperationService) GetSupplierPerform(param *vo.SupplierDataParam) (vo.ResultVO, error) {
  440. if param.Page <= 0 {
  441. param.Page = 1
  442. }
  443. if param.PageSize <= 0 {
  444. param.PageSize = 10
  445. }
  446. var supplierDataParams []*vo.SupplierPerformance
  447. var total int64
  448. result := vo.ResultVO{
  449. Page: param.Page,
  450. PageSize: param.PageSize,
  451. Total: total,
  452. Data: supplierDataParams,
  453. }
  454. // 获取supplierId下的所有任务,再根据任务获取数据
  455. if param.TaskType == 2 {
  456. projectTaskLinkStatistics, total1, err1 := dao.ProjectTaskLinkStatisticDao{}.GetProjectList(param.SupplierId, param.Page, param.PageSize)
  457. total = total1
  458. if err1 != nil {
  459. return result, err1
  460. }
  461. for _, projectTaskLinkStatistic := range projectTaskLinkStatistics {
  462. var perform vo.SupplierPerformance
  463. projectId := projectTaskLinkStatistic.ProjectID
  464. project, err2 := dao.ProjectDAO{}.GetProjectById(projectId)
  465. if err2 != nil {
  466. return result, err2
  467. }
  468. var product entity.Product
  469. var productMainPhoto entity.ProductPhoto
  470. err11 := json.Unmarshal([]byte(project.ProductSnap), &product)
  471. err12 := json.Unmarshal([]byte(project.ProductPhotoSnap), &productMainPhoto)
  472. if err11 == nil && err12 == nil {
  473. perform.MainImage = productMainPhoto.PhotoUrl
  474. perform.ProductName = product.ProductName
  475. perform.Price = product.ProductPrice
  476. perform.ViewCount = projectTaskLinkStatistic.ViewCount
  477. perform.VoteCount = projectTaskLinkStatistic.VoteCount
  478. perform.CollectCount = projectTaskLinkStatistic.CollectionCount
  479. perform.CommentCount = projectTaskLinkStatistic.CommitCount
  480. }
  481. supplierDataParams = append(supplierDataParams, &perform)
  482. }
  483. } else if param.TaskType == 3 {
  484. localTaskLinkStatistics, total1, err1 := dao.LocalTaskLinkStatisticDao{}.GetLocalList(param.SupplierId, param.Page, param.PageSize)
  485. total = total1
  486. if err1 != nil {
  487. return result, err1
  488. }
  489. for _, localTaskLinkStatistic := range localTaskLinkStatistics {
  490. var perform vo.SupplierPerformance
  491. localId := localTaskLinkStatistic.LocalID
  492. local, err2 := dao.LocalLifeDao{}.GetLocalById(localId)
  493. if err2 != nil {
  494. return result, err2
  495. }
  496. store, err11 := dao.StoreDao{}.GetStoreByID(local.StoreID)
  497. if err11 == nil && store != nil {
  498. photoUrl, e := dao.ProductPhotoDAO{}.GetMainPhotoByStoreID(store.StoreID)
  499. if e != nil {
  500. photoUrl = ""
  501. }
  502. perform.MainImage = photoUrl
  503. perform.StoreName = store.StoreName
  504. perform.ViewCount = localTaskLinkStatistic.ViewCount
  505. perform.VoteCount = localTaskLinkStatistic.VoteCount
  506. perform.CollectCount = localTaskLinkStatistic.CollectionCount
  507. perform.CommentCount = localTaskLinkStatistic.CommitCount
  508. }
  509. supplierDataParams = append(supplierDataParams, &perform)
  510. }
  511. }
  512. result = vo.ResultVO{
  513. Page: param.Page,
  514. PageSize: param.PageSize,
  515. Total: total,
  516. Data: supplierDataParams,
  517. }
  518. return result, nil
  519. }
  520. // 服务商合作-服务商列表
  521. func (s CooperationService) GetSupplierInTargetTaskList(param *vo.SupplierSearchInTargetTaskParam) (vo.ResultVO, error) {
  522. if param.Page <= 0 {
  523. param.Page = 1
  524. }
  525. if param.PageSize <= 0 {
  526. param.PageSize = 10
  527. }
  528. var reSupplierTargetTasks []*vo.ReSupplierTargetTask
  529. var total int64
  530. result := vo.ResultVO{
  531. Page: param.Page,
  532. PageSize: param.PageSize,
  533. Total: total,
  534. Data: reSupplierTargetTasks,
  535. }
  536. var enterpriseSupplierCooperates []*entity.EnterpriseSupplierCooperate
  537. var sProjectInfos []*entity.SProjectInfo
  538. var sLocalLifeInfos []*entity.SLocalLifeInfo
  539. var enterpriseOperator string
  540. if param.Status == 1 { // 可邀约
  541. enterpriseSupplierCooperates, total, _ = dao.EnterpriseSupplierCooperateDao{}.GetSupplierByEnterprise(param.EnterpriseId, param.Page, param.PageSize)
  542. var resEnterpriseSuppliers []*entity.EnterpriseSupplierCooperate
  543. if param.TaskType == 2 {
  544. // 品牌种草
  545. // 去除当前project_id、supplier_id已在 s_project_info中的数据
  546. for _, enterpriseSupplier := range enterpriseSupplierCooperates {
  547. var sProject entity.SProjectInfo
  548. err1 := dao.Db.Model(&entity.SProjectInfo{}).Where("project_id = ? and supplier_id = ?", param.TaskId, enterpriseSupplier.SupplierId).First(&sProject).Error
  549. if err1 != nil {
  550. if errors.Is(err1, gorm.ErrRecordNotFound) {
  551. resEnterpriseSuppliers = append(resEnterpriseSuppliers, enterpriseSupplier)
  552. } else {
  553. // 其他错误
  554. }
  555. }
  556. }
  557. } else if param.TaskType == 3 {
  558. // 本地生活
  559. // 去除当前 local_id、supplier_id 已在 s_local_info中的数据
  560. for _, enterpriseSupplier := range enterpriseSupplierCooperates {
  561. var sLocalLifeInfo entity.SLocalLifeInfo
  562. err2 := dao.Db.Model(&entity.SLocalLifeInfo{}).Where("local_id = ? and supplier_id = ?", param.TaskId, enterpriseSupplier.SupplierId).First(&sLocalLifeInfo).Error
  563. if err2 != nil {
  564. if errors.Is(err2, gorm.ErrRecordNotFound) {
  565. resEnterpriseSuppliers = append(resEnterpriseSuppliers, enterpriseSupplier)
  566. } else {
  567. // 其他错误
  568. }
  569. }
  570. }
  571. }
  572. enterpriseSupplierCooperates = resEnterpriseSuppliers
  573. total = int64(len(enterpriseSupplierCooperates))
  574. } else if param.Status == 2 { // 邀约中
  575. if param.TaskType == 2 {
  576. // 品牌种草
  577. sProjectInfos, total, _ = dao.SProjectDao{}.GetSProjectByStatus(param.TaskId, 1, param.Page, param.PageSize)
  578. } else if param.TaskType == 3 {
  579. // 本地生活
  580. sLocalLifeInfos, total, _ = dao.SLocalLifeDao{}.GetSLocalLifeByStatus(param.TaskId, 1, param.Page, param.PageSize)
  581. }
  582. } else if param.Status == 3 { // 合作中
  583. if param.TaskType == 2 {
  584. // 品牌种草
  585. sProjectInfos, total, _ = dao.SProjectDao{}.GetSProjectByStatus(param.TaskId, 2, param.Page, param.PageSize)
  586. } else if param.TaskType == 3 {
  587. // 本地生活
  588. sLocalLifeInfos, total, _ = dao.SLocalLifeDao{}.GetSLocalLifeByStatus(param.TaskId, 2, param.Page, param.PageSize)
  589. }
  590. }
  591. // 针对邀约中、合作中情形
  592. if param.Status == 2 || param.Status == 3 {
  593. if param.TaskType == 2 { // 种草
  594. for _, sProjectInfo := range sProjectInfos {
  595. supplierId := sProjectInfo.SupplierID
  596. enterpriseSupplierCooperate, err1 := dao.EnterpriseSupplierCooperateDao{}.GetDataByEnterpriseAndSupplier(param.EnterpriseId, supplierId)
  597. if err1 != nil {
  598. return result, err1
  599. }
  600. enterpriseSupplierCooperates = append(enterpriseSupplierCooperates, enterpriseSupplierCooperate)
  601. }
  602. } else if param.TaskType == 3 {
  603. // 本地生活
  604. for _, sLocalLifeInfo := range sLocalLifeInfos {
  605. supplierId := sLocalLifeInfo.SupplierID
  606. enterpriseSupplierCooperate, err1 := dao.EnterpriseSupplierCooperateDao{}.GetDataByEnterpriseAndSupplier(param.EnterpriseId, supplierId)
  607. if err1 != nil {
  608. return result, err1
  609. }
  610. enterpriseSupplierCooperates = append(enterpriseSupplierCooperates, enterpriseSupplierCooperate)
  611. }
  612. }
  613. }
  614. for _, enterpriseSupplierCooperate := range enterpriseSupplierCooperates {
  615. // 获取商家操作人姓名
  616. bOperator := enterpriseSupplierCooperate.BOperator
  617. if enterpriseSupplierCooperate.BOperatorType == 1 {
  618. enterprise, err := dao.EnterpriseDao{}.GetEnterprise(bOperator)
  619. if err == nil && enterprise != nil {
  620. enterpriseOperator = enterprise.BusinessName
  621. }
  622. } else if enterpriseSupplierCooperate.BOperatorType == 2 {
  623. subAccountId, err := strconv.ParseInt(bOperator, 10, 64)
  624. if err != nil {
  625. fmt.Println("GetEnterprisePoolList==subAccountId 转换出错:", err)
  626. } else {
  627. subAccount, err := dao.SubAccountDao{}.GetSubAccount(subAccountId)
  628. if err == nil && subAccount != nil {
  629. enterpriseOperator = subAccount.SubAccountName
  630. }
  631. }
  632. }
  633. supplier, err := dao.SupplierDao{}.GetSupplierInfoById(enterpriseSupplierCooperate.SupplierId)
  634. var supplierPreview *vo.ReSupplierPreview
  635. var phoneNumber string
  636. if err == nil && supplier != nil {
  637. supplierPreview = &vo.ReSupplierPreview{
  638. SupplierId: supplier.SupplierID,
  639. HeadUrl: supplier.Avatar,
  640. SupplierName: supplier.SupplierName,
  641. SupplierType: supplier.SupplierType,
  642. CompanyName: supplier.CompanyName,
  643. Name: supplier.Name,
  644. Existence: true,
  645. }
  646. phoneNumber = supplier.PhoneNumber
  647. reSupplierTargetTask := &vo.ReSupplierTargetTask{
  648. SupplierPreview: supplierPreview,
  649. PhoneNumber: phoneNumber,
  650. WechatId: supplier.WechatNumber,
  651. WechatUrl: supplier.WechatQrcode,
  652. CooperateNum: enterpriseSupplierCooperate.CooperateNum,
  653. UploadTalentNum: enterpriseSupplierCooperate.UploadTalentNum,
  654. CooperateTalentNum: enterpriseSupplierCooperate.CooperateTalentNum,
  655. EnterpriseOperator: enterpriseOperator,
  656. Status: param.Status,
  657. }
  658. reSupplierTargetTasks = append(reSupplierTargetTasks, reSupplierTargetTask)
  659. }
  660. }
  661. result = vo.ResultVO{
  662. Page: param.Page,
  663. PageSize: param.PageSize,
  664. Total: total,
  665. Data: reSupplierTargetTasks,
  666. }
  667. return result, nil
  668. }
  669. // 服务商合作-服务商列表角标
  670. func (t CooperationService) GetSupplierInTargetCount(param *vo.SupplierSearchInTargetTaskParam) map[string]int64 {
  671. res := make(map[string]int64)
  672. var invitableNum int64 // 可邀约
  673. var invitingNum int64 // 邀约中
  674. var cooperatingNum int64 // 合作中
  675. if param.TaskType == 2 {
  676. // 品牌种草
  677. var enterpriseSupplierCooperates []*entity.EnterpriseSupplierCooperate
  678. query := dao.Db.Model(&entity.EnterpriseSupplierCooperate{}).Where("enterprise_id = ? AND cooperate_status = 2", param.EnterpriseId)
  679. err := query.Select("supplier_id").Find(&enterpriseSupplierCooperates).Error
  680. var resEnterpriseSuppliers []*entity.EnterpriseSupplierCooperate
  681. if err == nil {
  682. // 去除当前project_id、supplier_id已在 s_project_info中的数据
  683. for _, enterpriseSupplier := range enterpriseSupplierCooperates {
  684. var sProject entity.SProjectInfo
  685. err1 := dao.Db.Debug().Model(&entity.SProjectInfo{}).Where("project_id = ? and supplier_id = ?", param.TaskId, enterpriseSupplier.SupplierId).First(&sProject).Error
  686. if err1 != nil {
  687. if errors.Is(err1, gorm.ErrRecordNotFound) {
  688. resEnterpriseSuppliers = append(resEnterpriseSuppliers, enterpriseSupplier)
  689. } else {
  690. // 其他错误
  691. }
  692. }
  693. }
  694. }
  695. invitableNum = int64(len(resEnterpriseSuppliers))
  696. dao.Db.Model(&entity.SProjectInfo{}).Where("project_id = ? AND s_project_status = ?", param.TaskId, 1).Count(&invitingNum)
  697. dao.Db.Model(&entity.SProjectInfo{}).Where("project_id = ? AND s_project_status = ?", param.TaskId, 2).Count(&cooperatingNum)
  698. } else if param.TaskType == 3 {
  699. // 本地生活
  700. var enterpriseSupplierCooperates []*entity.EnterpriseSupplierCooperate
  701. query := dao.Db.Model(&entity.EnterpriseSupplierCooperate{}).Where("enterprise_id = ? AND cooperate_status = 2", param.EnterpriseId)
  702. err := query.Select("supplier_id").Find(&enterpriseSupplierCooperates).Error
  703. var resEnterpriseSuppliers []*entity.EnterpriseSupplierCooperate
  704. if err == nil {
  705. // 去除当前local_id、supplier_id已在 s_local_info中的数据
  706. for _, enterpriseSupplier := range enterpriseSupplierCooperates {
  707. var sLocalLifeInfo entity.SLocalLifeInfo
  708. err1 := dao.Db.Model(&entity.SLocalLifeInfo{}).Where("local_id = ? and supplier_id = ?", param.TaskId, enterpriseSupplier.SupplierId).First(&sLocalLifeInfo).Error
  709. if err1 != nil {
  710. if errors.Is(err1, gorm.ErrRecordNotFound) {
  711. resEnterpriseSuppliers = append(resEnterpriseSuppliers, enterpriseSupplier)
  712. } else {
  713. // 其他错误
  714. }
  715. }
  716. }
  717. }
  718. invitableNum = int64(len(resEnterpriseSuppliers))
  719. dao.Db.Model(&entity.SLocalLifeInfo{}).Where("local_id = ? AND s_local_status = ?", param.TaskId, 1).Count(&invitingNum)
  720. dao.Db.Model(&entity.SProjectInfo{}).Where("local_id = ? AND s_local_status = ?", param.TaskId, 2).Count(&cooperatingNum)
  721. }
  722. res["invitableNum"] = invitableNum
  723. res["invitingNum"] = invitingNum
  724. res["cooperatingNum"] = cooperatingNum
  725. return res
  726. }
  727. // 服务商合作-邀约合作
  728. func (s CooperationService) InviteSupplierInTargetTask(param *vo.SupplierInviteInTargetTaskParam) error {
  729. var err error
  730. if param.TaskType == 2 {
  731. var sProjectInfo entity.SProjectInfo
  732. sProjectInfo.ProjectID = param.TaskId
  733. sProjectInfo.SupplierID = param.SupplierId
  734. sProjectInfo.SProjectStatus = 1
  735. t := time.Now()
  736. sProjectInfo.CreateTime = &t
  737. if param.SubAccountId == 0 {
  738. sProjectInfo.BOperator = param.EnterpriseId
  739. sProjectInfo.BOperatorType = 1
  740. } else {
  741. sProjectInfo.BOperator = strconv.Itoa(int(param.SubAccountId))
  742. sProjectInfo.BOperatorType = 2
  743. }
  744. // 查找该 projectId 对应的信息
  745. project, err1 := dao.ProjectDAO{}.GetProjectById(param.TaskId)
  746. if err1 != nil {
  747. return err1
  748. }
  749. if project != nil {
  750. sProjectInfo.ProductID = project.ProductID
  751. sProjectInfo.ProjectName = project.ProjectName
  752. sProjectInfo.ProjectStatus = project.ProjectStatus
  753. sProjectInfo.ProjectType = project.ProjectType
  754. sProjectInfo.ProjectPlatform = project.ProjectPlatform
  755. sProjectInfo.ProjectForm = project.ProjectForm
  756. sProjectInfo.ContentType = project.ContentType
  757. sProjectInfo.EnterpriseID = param.EnterpriseId
  758. //sProjectInfo.ApplyNum = project.ApplyNum
  759. //sProjectInfo.RecruitNum = project.RecruitNum
  760. }
  761. err = dao.SProjectDao{}.Insert(&sProjectInfo)
  762. } else if param.TaskType == 3 {
  763. // 本地生活
  764. var sLocalLifeInfo entity.SLocalLifeInfo
  765. sLocalLifeInfo.LocalID = param.TaskId
  766. sLocalLifeInfo.SupplierID = param.SupplierId
  767. sLocalLifeInfo.SLocalStatus = 1
  768. t := time.Now()
  769. sLocalLifeInfo.CreateTime = &t
  770. if param.SubAccountId == 0 {
  771. sLocalLifeInfo.BOperator = param.EnterpriseId
  772. sLocalLifeInfo.BOperatorType = 1
  773. } else {
  774. sLocalLifeInfo.BOperator = strconv.Itoa(int(param.SubAccountId))
  775. sLocalLifeInfo.BOperatorType = 2
  776. }
  777. // 查找该 localId 对应的信息
  778. localLife, err1 := dao.LocalLifeDao{}.GetLocalById(param.TaskId)
  779. if err1 != nil {
  780. return err1
  781. }
  782. if localLife != nil {
  783. sLocalLifeInfo.StoreID = localLife.StoreID
  784. sLocalLifeInfo.TeamBuyingID = localLife.TeamBuyingId
  785. sLocalLifeInfo.LocalName = localLife.LocalName
  786. sLocalLifeInfo.TaskStatus = localLife.TaskStatus
  787. sLocalLifeInfo.LocalType = localLife.LocalType
  788. sLocalLifeInfo.LocalPlatform = localLife.LocalPlatform
  789. sLocalLifeInfo.TaskForm = localLife.TaskForm
  790. sLocalLifeInfo.ContentType = localLife.ContentType
  791. sLocalLifeInfo.EnterpriseID = param.EnterpriseId
  792. //sProjectInfo.ApplyNum = project.ApplyNum
  793. //sProjectInfo.RecruitNum = project.RecruitNum
  794. }
  795. err = dao.SLocalLifeDao{}.Insert(&sLocalLifeInfo)
  796. }
  797. return err
  798. }