cooperation_service.go 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829
  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. } else if param.TaskType == 3 {
  401. prjtasks, total3, err3 := dao.LocalLifeTaskInfoDao{}.GetLocalLifeInfoByTalentId(param.TalentId, param.Others, param.SortField, param.SortOrder, param.Page, param.PageSize, param.RelType, param.EnterpriseId, param.Platform)
  402. total = total3
  403. if err3 != nil {
  404. return result, err3
  405. }
  406. for _, sectask := range prjtasks {
  407. var perform vo.TalentPerformance
  408. secid := sectask.LocalID
  409. sec, err2 := dao.ProjectDAO{}.GetProjectById(secid)
  410. if err2 != nil {
  411. return result, err2
  412. }
  413. var product entity.Product
  414. var productMainPhoto entity.ProductPhoto
  415. err11 := json.Unmarshal([]byte(sec.ProductSnap), &product)
  416. err12 := json.Unmarshal([]byte(sec.ProductPhotoSnap), &productMainPhoto)
  417. if err11 != nil || err12 != nil {
  418. perform.MainImage = productMainPhoto.PhotoUrl
  419. perform.ProductName = product.ProductName
  420. perform.Price = product.ProductPrice
  421. perform.VoteCount = int(sectask.VoteAvg)
  422. perform.ViewCount = 0
  423. perform.CollectCount = sectask.CollectNum
  424. perform.CommentCount = int(sectask.CommitAvg)
  425. }
  426. talentDataParams = append(talentDataParams, &perform)
  427. }
  428. }
  429. result = vo.ResultVO{
  430. Page: param.Page,
  431. PageSize: param.PageSize,
  432. Total: total,
  433. Data: talentDataParams,
  434. }
  435. return result, nil
  436. }
  437. // 服务商管理-服务商数据卡列表
  438. func (t CooperationService) GetSupplierPerform(param *vo.SupplierDataParam) (vo.ResultVO, error) {
  439. if param.Page <= 0 {
  440. param.Page = 1
  441. }
  442. if param.PageSize <= 0 {
  443. param.PageSize = 10
  444. }
  445. var supplierDataParams []*vo.SupplierPerformance
  446. var total int64
  447. result := vo.ResultVO{
  448. Page: param.Page,
  449. PageSize: param.PageSize,
  450. Total: total,
  451. Data: supplierDataParams,
  452. }
  453. // 获取supplierId下的所有任务,再根据任务获取数据
  454. if param.TaskType == 2 {
  455. projectTaskLinkStatistics, total1, err1 := dao.ProjectTaskLinkStatisticDao{}.GetProjectList(param.SupplierId, param.Page, param.PageSize)
  456. total = total1
  457. if err1 != nil {
  458. return result, err1
  459. }
  460. for _, projectTaskLinkStatistic := range projectTaskLinkStatistics {
  461. var perform vo.SupplierPerformance
  462. projectId := projectTaskLinkStatistic.ProjectID
  463. project, err2 := dao.ProjectDAO{}.GetProjectById(projectId)
  464. if err2 != nil {
  465. return result, err2
  466. }
  467. var product entity.Product
  468. var productMainPhoto entity.ProductPhoto
  469. err11 := json.Unmarshal([]byte(project.ProductSnap), &product)
  470. err12 := json.Unmarshal([]byte(project.ProductPhotoSnap), &productMainPhoto)
  471. if err11 != nil && err12 != nil {
  472. perform.MainImage = productMainPhoto.PhotoUrl
  473. perform.ProductName = product.ProductName
  474. perform.Price = product.ProductPrice
  475. perform.ViewCount = projectTaskLinkStatistic.ViewCount
  476. perform.VoteCount = projectTaskLinkStatistic.VoteCount
  477. perform.CollectCount = projectTaskLinkStatistic.CollectionCount
  478. perform.CommentCount = projectTaskLinkStatistic.CommitCount
  479. }
  480. supplierDataParams = append(supplierDataParams, &perform)
  481. }
  482. } else if param.TaskType == 3 {
  483. localTaskLinkStatistics, total1, err1 := dao.LocalTaskLinkStatisticDao{}.GetLocalList(param.SupplierId, param.Page, param.PageSize)
  484. total = total1
  485. if err1 != nil {
  486. return result, err1
  487. }
  488. for _, localTaskLinkStatistic := range localTaskLinkStatistics {
  489. var perform vo.SupplierPerformance
  490. localId := localTaskLinkStatistic.LocalID
  491. local, err2 := dao.LocalLifeDao{}.GetLocalById(localId)
  492. if err2 != nil {
  493. return result, err2
  494. }
  495. store, err11 := dao.StoreDao{}.GetStoreByID(local.StoreID)
  496. if err11 == nil && store != nil {
  497. photoUrl, e := dao.ProductPhotoDAO{}.GetMainPhotoByStoreID(store.StoreID)
  498. if e != nil {
  499. photoUrl = ""
  500. }
  501. perform.MainImage = photoUrl
  502. perform.StoreName = store.StoreName
  503. perform.ViewCount = localTaskLinkStatistic.ViewCount
  504. perform.VoteCount = localTaskLinkStatistic.VoteCount
  505. perform.CollectCount = localTaskLinkStatistic.CollectionCount
  506. perform.CommentCount = localTaskLinkStatistic.CommitCount
  507. }
  508. supplierDataParams = append(supplierDataParams, &perform)
  509. }
  510. }
  511. result = vo.ResultVO{
  512. Page: param.Page,
  513. PageSize: param.PageSize,
  514. Total: total,
  515. Data: supplierDataParams,
  516. }
  517. return result, nil
  518. }
  519. // 服务商合作-服务商列表
  520. func (s CooperationService) GetSupplierInTargetTaskList(param *vo.SupplierSearchInTargetTaskParam) (vo.ResultVO, error) {
  521. if param.Page <= 0 {
  522. param.Page = 1
  523. }
  524. if param.PageSize <= 0 {
  525. param.PageSize = 10
  526. }
  527. var reSupplierTargetTasks []*vo.ReSupplierTargetTask
  528. var total int64
  529. result := vo.ResultVO{
  530. Page: param.Page,
  531. PageSize: param.PageSize,
  532. Total: total,
  533. Data: reSupplierTargetTasks,
  534. }
  535. var enterpriseSupplierCooperates []*entity.EnterpriseSupplierCooperate
  536. var sProjectInfos []*entity.SProjectInfo
  537. var sLocalLifeInfos []*entity.SLocalLifeInfo
  538. var enterpriseOperator string
  539. if param.Status == 1 { // 可邀约
  540. enterpriseSupplierCooperates, total, _ = dao.EnterpriseSupplierCooperateDao{}.GetSupplierByEnterprise(param.EnterpriseId, param.Page, param.PageSize)
  541. var resEnterpriseSuppliers []*entity.EnterpriseSupplierCooperate
  542. if param.TaskType == 2 {
  543. // 品牌种草
  544. // 去除当前project_id、supplier_id已在 s_project_info中的数据
  545. for _, enterpriseSupplier := range enterpriseSupplierCooperates {
  546. var sProject entity.SProjectInfo
  547. err1 := dao.Db.Model(&entity.SProjectInfo{}).Where("project_id = ? and supplier_id = ?", param.TaskId, enterpriseSupplier.SupplierId).First(&sProject).Error
  548. if err1 != nil {
  549. if errors.Is(err1, gorm.ErrRecordNotFound) {
  550. resEnterpriseSuppliers = append(resEnterpriseSuppliers, enterpriseSupplier)
  551. } else {
  552. // 其他错误
  553. }
  554. }
  555. }
  556. } else if param.TaskType == 3 {
  557. // 本地生活
  558. // 去除当前 local_id、supplier_id 已在 s_local_info中的数据
  559. for _, enterpriseSupplier := range enterpriseSupplierCooperates {
  560. var sLocalLifeInfo entity.SLocalLifeInfo
  561. err2 := dao.Db.Model(&entity.SLocalLifeInfo{}).Where("local_id = ? and supplier_id = ?", param.TaskId, enterpriseSupplier.SupplierId).First(&sLocalLifeInfo).Error
  562. if err2 != nil {
  563. if errors.Is(err2, gorm.ErrRecordNotFound) {
  564. resEnterpriseSuppliers = append(resEnterpriseSuppliers, enterpriseSupplier)
  565. } else {
  566. // 其他错误
  567. }
  568. }
  569. }
  570. }
  571. enterpriseSupplierCooperates = resEnterpriseSuppliers
  572. total = int64(len(enterpriseSupplierCooperates))
  573. } else if param.Status == 2 { // 邀约中
  574. if param.TaskType == 2 {
  575. // 品牌种草
  576. sProjectInfos, total, _ = dao.SProjectDao{}.GetSProjectByStatus(param.TaskId, 1, param.Page, param.PageSize)
  577. } else if param.TaskType == 3 {
  578. // 本地生活
  579. sLocalLifeInfos, total, _ = dao.SLocalLifeDao{}.GetSLocalLifeByStatus(param.TaskId, 1, param.Page, param.PageSize)
  580. }
  581. } else if param.Status == 3 { // 合作中
  582. if param.TaskType == 2 {
  583. // 品牌种草
  584. sProjectInfos, total, _ = dao.SProjectDao{}.GetSProjectByStatus(param.TaskId, 2, param.Page, param.PageSize)
  585. } else if param.TaskType == 3 {
  586. // 本地生活
  587. sLocalLifeInfos, total, _ = dao.SLocalLifeDao{}.GetSLocalLifeByStatus(param.TaskId, 2, param.Page, param.PageSize)
  588. }
  589. }
  590. // 针对邀约中、合作中情形
  591. if param.Status == 2 || param.Status == 3 {
  592. if param.TaskType == 2 { // 种草
  593. for _, sProjectInfo := range sProjectInfos {
  594. supplierId := sProjectInfo.SupplierID
  595. enterpriseSupplierCooperate, err1 := dao.EnterpriseSupplierCooperateDao{}.GetDataByEnterpriseAndSupplier(param.EnterpriseId, supplierId)
  596. if err1 != nil {
  597. return result, err1
  598. }
  599. enterpriseSupplierCooperates = append(enterpriseSupplierCooperates, enterpriseSupplierCooperate)
  600. }
  601. } else if param.TaskType == 3 {
  602. // 本地生活
  603. for _, sLocalLifeInfo := range sLocalLifeInfos {
  604. supplierId := sLocalLifeInfo.SupplierID
  605. enterpriseSupplierCooperate, err1 := dao.EnterpriseSupplierCooperateDao{}.GetDataByEnterpriseAndSupplier(param.EnterpriseId, supplierId)
  606. if err1 != nil {
  607. return result, err1
  608. }
  609. enterpriseSupplierCooperates = append(enterpriseSupplierCooperates, enterpriseSupplierCooperate)
  610. }
  611. }
  612. }
  613. for _, enterpriseSupplierCooperate := range enterpriseSupplierCooperates {
  614. // 获取商家操作人姓名
  615. bOperator := enterpriseSupplierCooperate.BOperator
  616. if enterpriseSupplierCooperate.BOperatorType == 1 {
  617. enterprise, err := dao.EnterpriseDao{}.GetEnterprise(bOperator)
  618. if err == nil && enterprise != nil {
  619. enterpriseOperator = enterprise.BusinessName
  620. }
  621. } else if enterpriseSupplierCooperate.BOperatorType == 2 {
  622. subAccountId, err := strconv.ParseInt(bOperator, 10, 64)
  623. if err != nil {
  624. fmt.Println("GetEnterprisePoolList==subAccountId 转换出错:", err)
  625. } else {
  626. subAccount, err := dao.SubAccountDao{}.GetSubAccount(subAccountId)
  627. if err == nil && subAccount != nil {
  628. enterpriseOperator = subAccount.SubAccountName
  629. }
  630. }
  631. }
  632. supplier, err := dao.SupplierDao{}.GetSupplierInfoById(enterpriseSupplierCooperate.SupplierId)
  633. var supplierPreview *vo.ReSupplierPreview
  634. var phoneNumber string
  635. if err == nil && supplier != nil {
  636. supplierPreview = &vo.ReSupplierPreview{
  637. SupplierId: supplier.SupplierID,
  638. HeadUrl: supplier.Avatar,
  639. SupplierName: supplier.SupplierName,
  640. SupplierType: supplier.SupplierType,
  641. CompanyName: supplier.CompanyName,
  642. Name: supplier.Name,
  643. Existence: true,
  644. }
  645. phoneNumber = supplier.PhoneNumber
  646. reSupplierTargetTask := &vo.ReSupplierTargetTask{
  647. SupplierPreview: supplierPreview,
  648. PhoneNumber: phoneNumber,
  649. WechatId: supplier.WechatNumber,
  650. WechatUrl: supplier.WechatQrcode,
  651. CooperateNum: enterpriseSupplierCooperate.CooperateNum,
  652. UploadTalentNum: enterpriseSupplierCooperate.UploadTalentNum,
  653. CooperateTalentNum: enterpriseSupplierCooperate.CooperateTalentNum,
  654. EnterpriseOperator: enterpriseOperator,
  655. Status: param.Status,
  656. }
  657. reSupplierTargetTasks = append(reSupplierTargetTasks, reSupplierTargetTask)
  658. }
  659. }
  660. result = vo.ResultVO{
  661. Page: param.Page,
  662. PageSize: param.PageSize,
  663. Total: total,
  664. Data: reSupplierTargetTasks,
  665. }
  666. return result, nil
  667. }
  668. // 服务商合作-服务商列表角标
  669. func (t CooperationService) GetSupplierInTargetCount(param *vo.SupplierSearchInTargetTaskParam) map[string]int64 {
  670. res := make(map[string]int64)
  671. var invitableNum int64 // 可邀约
  672. var invitingNum int64 // 邀约中
  673. var cooperatingNum int64 // 合作中
  674. if param.TaskType == 2 {
  675. // 品牌种草
  676. var enterpriseSupplierCooperates []*entity.EnterpriseSupplierCooperate
  677. query := dao.Db.Model(&entity.EnterpriseSupplierCooperate{}).Where("enterprise_id = ? AND cooperate_status = 2", param.EnterpriseId)
  678. err := query.Select("supplier_id").Find(&enterpriseSupplierCooperates).Error
  679. var resEnterpriseSuppliers []*entity.EnterpriseSupplierCooperate
  680. if err == nil {
  681. // 去除当前project_id、supplier_id已在 s_project_info中的数据
  682. for _, enterpriseSupplier := range enterpriseSupplierCooperates {
  683. var sProject entity.SProjectInfo
  684. err1 := dao.Db.Debug().Model(&entity.SProjectInfo{}).Where("project_id = ? and supplier_id = ?", param.TaskId, enterpriseSupplier.SupplierId).First(&sProject).Error
  685. if err1 != nil {
  686. if errors.Is(err1, gorm.ErrRecordNotFound) {
  687. resEnterpriseSuppliers = append(resEnterpriseSuppliers, enterpriseSupplier)
  688. } else {
  689. // 其他错误
  690. }
  691. }
  692. }
  693. }
  694. invitableNum = int64(len(resEnterpriseSuppliers))
  695. dao.Db.Model(&entity.SProjectInfo{}).Where("project_id = ? AND s_project_status = ?", param.TaskId, 1).Count(&invitingNum)
  696. dao.Db.Model(&entity.SProjectInfo{}).Where("project_id = ? AND s_project_status = ?", param.TaskId, 2).Count(&cooperatingNum)
  697. } else if param.TaskType == 3 {
  698. // 本地生活
  699. var enterpriseSupplierCooperates []*entity.EnterpriseSupplierCooperate
  700. query := dao.Db.Model(&entity.EnterpriseSupplierCooperate{}).Where("enterprise_id = ? AND cooperate_status = 2", param.EnterpriseId)
  701. err := query.Select("supplier_id").Find(&enterpriseSupplierCooperates).Error
  702. var resEnterpriseSuppliers []*entity.EnterpriseSupplierCooperate
  703. if err == nil {
  704. // 去除当前local_id、supplier_id已在 s_local_info中的数据
  705. for _, enterpriseSupplier := range enterpriseSupplierCooperates {
  706. var sLocalLifeInfo entity.SLocalLifeInfo
  707. err1 := dao.Db.Model(&entity.SLocalLifeInfo{}).Where("local_id = ? and supplier_id = ?", param.TaskId, enterpriseSupplier.SupplierId).First(&sLocalLifeInfo).Error
  708. if err1 != nil {
  709. if errors.Is(err1, gorm.ErrRecordNotFound) {
  710. resEnterpriseSuppliers = append(resEnterpriseSuppliers, enterpriseSupplier)
  711. } else {
  712. // 其他错误
  713. }
  714. }
  715. }
  716. }
  717. invitableNum = int64(len(resEnterpriseSuppliers))
  718. dao.Db.Model(&entity.SLocalLifeInfo{}).Where("local_id = ? AND s_local_status = ?", param.TaskId, 1).Count(&invitingNum)
  719. dao.Db.Model(&entity.SProjectInfo{}).Where("local_id = ? AND s_local_status = ?", param.TaskId, 2).Count(&cooperatingNum)
  720. }
  721. res["invitableNum"] = invitableNum
  722. res["invitingNum"] = invitingNum
  723. res["cooperatingNum"] = cooperatingNum
  724. return res
  725. }
  726. // 服务商合作-邀约合作
  727. func (s CooperationService) InviteSupplierInTargetTask(param *vo.SupplierInviteInTargetTaskParam) error {
  728. var err error
  729. if param.TaskType == 2 {
  730. var sProjectInfo entity.SProjectInfo
  731. sProjectInfo.ProjectID = param.TaskId
  732. sProjectInfo.SupplierID = param.SupplierId
  733. sProjectInfo.SProjectStatus = 1
  734. t := time.Now()
  735. sProjectInfo.CreateTime = &t
  736. if param.SubAccountId == 0 {
  737. sProjectInfo.BOperator = param.EnterpriseId
  738. sProjectInfo.BOperatorType = 1
  739. } else {
  740. sProjectInfo.BOperator = strconv.Itoa(int(param.SubAccountId))
  741. sProjectInfo.BOperatorType = 2
  742. }
  743. // 查找该 projectId 对应的信息
  744. project, err1 := dao.ProjectDAO{}.GetProjectById(param.TaskId)
  745. if err1 != nil {
  746. return err1
  747. }
  748. if project != nil {
  749. sProjectInfo.ProductID = project.ProductID
  750. sProjectInfo.ProjectName = project.ProjectName
  751. sProjectInfo.ProjectStatus = project.ProjectStatus
  752. sProjectInfo.ProjectType = project.ProjectType
  753. sProjectInfo.ProjectPlatform = project.ProjectPlatform
  754. sProjectInfo.ProjectForm = project.ProjectForm
  755. sProjectInfo.ContentType = project.ContentType
  756. sProjectInfo.EnterpriseID = param.EnterpriseId
  757. //sProjectInfo.ApplyNum = project.ApplyNum
  758. //sProjectInfo.RecruitNum = project.RecruitNum
  759. }
  760. err = dao.SProjectDao{}.Insert(&sProjectInfo)
  761. } else if param.TaskType == 3 {
  762. // 本地生活
  763. var sLocalLifeInfo entity.SLocalLifeInfo
  764. sLocalLifeInfo.LocalID = param.TaskId
  765. sLocalLifeInfo.SupplierID = param.SupplierId
  766. sLocalLifeInfo.SLocalStatus = 1
  767. t := time.Now()
  768. sLocalLifeInfo.CreateTime = &t
  769. if param.SubAccountId == 0 {
  770. sLocalLifeInfo.BOperator = param.EnterpriseId
  771. sLocalLifeInfo.BOperatorType = 1
  772. } else {
  773. sLocalLifeInfo.BOperator = strconv.Itoa(int(param.SubAccountId))
  774. sLocalLifeInfo.BOperatorType = 2
  775. }
  776. // 查找该 localId 对应的信息
  777. localLife, err1 := dao.LocalLifeDao{}.GetLocalById(param.TaskId)
  778. if err1 != nil {
  779. return err1
  780. }
  781. if localLife != nil {
  782. sLocalLifeInfo.StoreID = localLife.StoreID
  783. sLocalLifeInfo.TeamBuyingID = localLife.TeamBuyingId
  784. sLocalLifeInfo.LocalName = localLife.LocalName
  785. sLocalLifeInfo.TaskStatus = localLife.TaskStatus
  786. sLocalLifeInfo.LocalType = localLife.LocalType
  787. sLocalLifeInfo.LocalPlatform = localLife.LocalPlatform
  788. sLocalLifeInfo.TaskForm = localLife.TaskForm
  789. sLocalLifeInfo.ContentType = localLife.ContentType
  790. sLocalLifeInfo.EnterpriseID = param.EnterpriseId
  791. //sProjectInfo.ApplyNum = project.ApplyNum
  792. //sProjectInfo.RecruitNum = project.RecruitNum
  793. }
  794. err = dao.SLocalLifeDao{}.Insert(&sLocalLifeInfo)
  795. }
  796. return err
  797. }