cooperation_service.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. package service
  2. import (
  3. "fmt"
  4. "strconv"
  5. "time"
  6. "youngee_b_api/app/dao"
  7. "youngee_b_api/app/entity"
  8. "youngee_b_api/app/vo"
  9. )
  10. type CooperationService struct{}
  11. // 服务商搜索
  12. func (s CooperationService) SearchSupplier(param *vo.SupplierSearchParam) ([]*vo.ReSupplierPreview, error) {
  13. var reSupplierPreviews []*vo.ReSupplierPreview
  14. suppliers, err := dao.SupplierDao{}.GetSuppliersByMsg(param.FieldName)
  15. if err != nil {
  16. return reSupplierPreviews, err
  17. }
  18. for _, supplier := range suppliers {
  19. // 判断该服务商是否已在商家库
  20. exist, _ := dao.EnterpriseSupplierCooperateDao{}.EnterpriseDatabaseCheck(param.EnterpriseId, supplier.SupplierID)
  21. reSupplierPreview := &vo.ReSupplierPreview{
  22. SupplierId: supplier.SupplierID,
  23. HeadUrl: supplier.Avatar,
  24. SupplierName: supplier.SupplierName,
  25. SupplierType: supplier.SupplierType,
  26. CompanyName: supplier.CompanyName,
  27. Name: supplier.Name,
  28. Existence: exist,
  29. }
  30. reSupplierPreviews = append(reSupplierPreviews, reSupplierPreview)
  31. }
  32. return reSupplierPreviews, nil
  33. }
  34. // 服务商入库批量邀请
  35. func (s CooperationService) InviteSupplier(param *vo.SupplierInviteParam) error {
  36. // 要求传入的服务商都是未在该商家库的
  37. var records []*entity.EnterpriseSupplierCooperate
  38. for _, supplierId := range param.SupplierIds {
  39. record := &entity.EnterpriseSupplierCooperate{
  40. EnterpriseId: param.EnterpriseId,
  41. SupplierId: supplierId,
  42. CooperateNum: 1,
  43. CooperateStatus: 1,
  44. CreateTime: time.Now(),
  45. }
  46. if param.SubAccountId == 0 {
  47. record.BOperator = param.EnterpriseId
  48. record.BOperatorType = 1
  49. } else {
  50. record.BOperator = strconv.Itoa(int(param.SubAccountId))
  51. record.BOperatorType = 2
  52. }
  53. records = append(records, record)
  54. }
  55. err := dao.EnterpriseSupplierCooperateDao{}.InsertBatch(records)
  56. return err
  57. }
  58. // 在库服务商列表
  59. func (s CooperationService) GetEnterprisePoolList(param *vo.SupplierSearchInPoolParam) (vo.ResultVO, error) {
  60. if param.Page <= 0 {
  61. param.Page = 1
  62. }
  63. if param.PageSize <= 0 {
  64. param.PageSize = 10
  65. }
  66. var result vo.ResultVO
  67. var reSupplierPoolInfos []*vo.ReSupplierPoolInfo
  68. var enterpriseOperator string
  69. enterpriseSupplierCooperates, total, _ := dao.EnterpriseSupplierCooperateDao{}.GetSupplierByEnterprise(param.EnterpriseId, param.Page, param.PageSize)
  70. for _, enterpriseSupplierCooperate := range enterpriseSupplierCooperates {
  71. // 获取商家操作人姓名
  72. bOperator := enterpriseSupplierCooperate.BOperator
  73. if enterpriseSupplierCooperate.BOperatorType == 1 {
  74. enterprise, err := dao.EnterpriseDao{}.GetEnterprise(bOperator)
  75. if err == nil && enterprise != nil {
  76. enterpriseOperator = enterprise.BusinessName
  77. }
  78. } else if enterpriseSupplierCooperate.BOperatorType == 2 {
  79. subAccountId, err := strconv.ParseInt(bOperator, 10, 64)
  80. if err != nil {
  81. fmt.Println("GetEnterprisePoolList==subAccountId 转换出错:", err)
  82. } else {
  83. subAccount, err := dao.SubAccountDao{}.GetSubAccount(subAccountId)
  84. if err == nil && subAccount != nil {
  85. enterpriseOperator = subAccount.SubAccountName
  86. }
  87. }
  88. }
  89. supplier, err := dao.SupplierDao{}.GetSupplierInfoById(enterpriseSupplierCooperate.SupplierId)
  90. if err != nil {
  91. continue
  92. }
  93. supplierPreview := &vo.ReSupplierPreview{
  94. SupplierId: supplier.SupplierID,
  95. HeadUrl: supplier.Avatar,
  96. SupplierName: supplier.SupplierName,
  97. SupplierType: supplier.SupplierType,
  98. CompanyName: supplier.CompanyName,
  99. Name: supplier.Name,
  100. Existence: true,
  101. }
  102. reSupplierPoolInfo := &vo.ReSupplierPoolInfo{
  103. SupplierPreview: supplierPreview,
  104. PhoneNumber: supplier.PhoneNumber,
  105. WechatId: supplier.WechatNumber,
  106. WechatUrl: supplier.WechatQrcode,
  107. CooperateNum: enterpriseSupplierCooperate.CooperateNum,
  108. UploadTalentNum: enterpriseSupplierCooperate.UploadTalentNum,
  109. CooperateTalentNum: enterpriseSupplierCooperate.CooperateTalentNum,
  110. AgreeTime: enterpriseSupplierCooperate.AgreeTime.Format("2006-01-02 15:04:05"),
  111. EnterpriseOperator: enterpriseOperator,
  112. }
  113. reSupplierPoolInfos = append(reSupplierPoolInfos, reSupplierPoolInfo)
  114. }
  115. result = vo.ResultVO{
  116. Page: param.Page,
  117. PageSize: param.PageSize,
  118. Total: total,
  119. Data: reSupplierPoolInfos,
  120. }
  121. return result, nil
  122. }
  123. // 服务商邀请待确认列表
  124. func (s CooperationService) GetSupplierConfirmingList(param *vo.SupplierConfirmingParam) (vo.ResultVO, error) {
  125. if param.Page <= 0 {
  126. param.Page = 1
  127. }
  128. if param.PageSize <= 0 {
  129. param.PageSize = 10
  130. }
  131. var result vo.ResultVO
  132. var reSupplierConfirmingInfos []*vo.ReSupplierConfirmingInfo
  133. var enterpriseOperator string
  134. enterpriseSupplierCooperates, total, _ := dao.EnterpriseSupplierCooperateDao{}.GetSupplierConfirmingList(param.EnterpriseId, param.Page, param.PageSize)
  135. for _, enterpriseSupplierCooperate := range enterpriseSupplierCooperates {
  136. // 获取商家操作人姓名
  137. bOperator := enterpriseSupplierCooperate.BOperator
  138. if enterpriseSupplierCooperate.BOperatorType == 1 {
  139. enterprise, err := dao.EnterpriseDao{}.GetEnterprise(bOperator)
  140. if err == nil && enterprise != nil {
  141. enterpriseOperator = enterprise.BusinessName
  142. }
  143. } else if enterpriseSupplierCooperate.BOperatorType == 2 {
  144. subAccountId, err := strconv.ParseInt(bOperator, 10, 64)
  145. if err != nil {
  146. fmt.Println("GetSupplierConfirmingList==subAccountId 转换出错:", err)
  147. } else {
  148. subAccount, err := dao.SubAccountDao{}.GetSubAccount(subAccountId)
  149. if err == nil && subAccount != nil {
  150. enterpriseOperator = subAccount.SubAccountName
  151. }
  152. }
  153. }
  154. supplier, err := dao.SupplierDao{}.GetSupplierInfoById(enterpriseSupplierCooperate.SupplierId)
  155. var supplierPreview *vo.ReSupplierPreview
  156. var phoneNumber string
  157. if err == nil {
  158. supplierPreview = &vo.ReSupplierPreview{
  159. SupplierId: supplier.SupplierID,
  160. HeadUrl: supplier.Avatar,
  161. SupplierName: supplier.SupplierName,
  162. SupplierType: supplier.SupplierType,
  163. CompanyName: supplier.CompanyName,
  164. Name: supplier.Name,
  165. }
  166. phoneNumber = supplier.PhoneNumber
  167. reSupplierConfirmingInfo := &vo.ReSupplierConfirmingInfo{
  168. SupplierPreview: supplierPreview,
  169. PhoneNumber: phoneNumber,
  170. WechatId: supplier.WechatNumber,
  171. WechatUrl: supplier.WechatQrcode,
  172. CreateTime: enterpriseSupplierCooperate.CreateTime.Format("2006-01-02 15:04:05"),
  173. Status: enterpriseSupplierCooperate.CooperateStatus,
  174. EnterpriseOperator: enterpriseOperator,
  175. }
  176. reSupplierConfirmingInfos = append(reSupplierConfirmingInfos, reSupplierConfirmingInfo)
  177. }
  178. }
  179. result = vo.ResultVO{
  180. Page: param.Page,
  181. PageSize: param.PageSize,
  182. Total: total,
  183. Data: reSupplierConfirmingInfos,
  184. }
  185. return result, nil
  186. }
  187. // 服务商管理-角标
  188. func (t CooperationService) GetSupplierCount(param *vo.SupplierConfirmingParam) map[string]int64 {
  189. res := make(map[string]int64)
  190. var inPoolNum int64 // 在库服务商
  191. var confirmingNum int64 // 邀请待确认
  192. dao.Db.Model(&entity.EnterpriseSupplierCooperate{}).Where("enterprise_id = ? AND cooperate_status = 2", param.EnterpriseId).Count(&inPoolNum)
  193. dao.Db.Model(&entity.EnterpriseSupplierCooperate{}).Where("enterprise_id = ? AND cooperate_status = 1", param.EnterpriseId).Count(&confirmingNum)
  194. res["inPoolNum"] = inPoolNum
  195. res["confirmingNum"] = confirmingNum
  196. return res
  197. }
  198. // 服务商合作-服务商列表
  199. func (s CooperationService) GetSupplierInTargetTaskList(param *vo.SupplierSearchInTargetTaskParam) (vo.ResultVO, error) {
  200. if param.Page <= 0 {
  201. param.Page = 1
  202. }
  203. if param.PageSize <= 0 {
  204. param.PageSize = 10
  205. }
  206. var reSupplierTargetTasks []*vo.ReSupplierTargetTask
  207. var total int64
  208. result := vo.ResultVO{
  209. Page: param.Page,
  210. PageSize: param.PageSize,
  211. Total: total,
  212. Data: reSupplierTargetTasks,
  213. }
  214. var enterpriseSupplierCooperates []*entity.EnterpriseSupplierCooperate
  215. var sProjectInfos []*entity.SProjectInfo
  216. var sLocalLifeInfos []*entity.SLocalLifeInfo
  217. var enterpriseOperator string
  218. if param.Status == 1 { // 可邀约
  219. enterpriseSupplierCooperates, total, _ = dao.EnterpriseSupplierCooperateDao{}.GetSupplierByEnterprise(param.EnterpriseId, param.Page, param.PageSize)
  220. if param.TaskType == 2 {
  221. // 品牌种草
  222. // 去除当前project_id、supplier_id已在 s_project_info中的数据
  223. var resEnterpriseSuppliers []*entity.EnterpriseSupplierCooperate
  224. for _, enterpriseSupplier := range enterpriseSupplierCooperates {
  225. var sProject *entity.SProjectInfo
  226. _ = dao.Db.Model(&entity.SProjectInfo{}).Where("project_id = ? and supplier_id = ?", param.TaskId, enterpriseSupplier.SupplierId).Find(&sProject).Error
  227. if sProject == nil {
  228. resEnterpriseSuppliers = append(resEnterpriseSuppliers, enterpriseSupplier)
  229. }
  230. }
  231. enterpriseSupplierCooperates = resEnterpriseSuppliers
  232. } else if param.TaskType == 3 {
  233. // 本地生活
  234. // 去除当前 local_id、supplier_id 已在 s_local_info中的数据
  235. var resEnterpriseSuppliers []*entity.EnterpriseSupplierCooperate
  236. for _, enterpriseSupplier := range enterpriseSupplierCooperates {
  237. var sLocalLifeInfo *entity.SLocalLifeInfo
  238. _ = dao.Db.Model(&entity.SLocalLifeInfo{}).Where("local_id = ? and supplier_id = ?", param.TaskId, enterpriseSupplier.SupplierId).Find(&sLocalLifeInfo).Error
  239. if sLocalLifeInfo == nil {
  240. resEnterpriseSuppliers = append(resEnterpriseSuppliers, enterpriseSupplier)
  241. }
  242. }
  243. enterpriseSupplierCooperates = resEnterpriseSuppliers
  244. }
  245. } else if param.Status == 2 { // 邀约中
  246. if param.TaskType == 2 {
  247. // 品牌种草
  248. sProjectInfos, total, _ = dao.SProjectDao{}.GetSProjectByStatus(param.TaskId, 1, param.Page, param.PageSize)
  249. } else if param.TaskType == 3 {
  250. // 本地生活
  251. sLocalLifeInfos, total, _ = dao.SLocalLifeDao{}.GetSLocalLifeByStatus(param.TaskId, 1, param.Page, param.PageSize)
  252. }
  253. } else if param.Status == 3 { // 合作中
  254. if param.TaskType == 2 {
  255. // 品牌种草
  256. sProjectInfos, total, _ = dao.SProjectDao{}.GetSProjectByStatus(param.TaskId, 2, param.Page, param.PageSize)
  257. } else if param.TaskType == 3 {
  258. // 本地生活
  259. sLocalLifeInfos, total, _ = dao.SLocalLifeDao{}.GetSLocalLifeByStatus(param.TaskId, 2, param.Page, param.PageSize)
  260. }
  261. }
  262. // 针对邀约中、合作中情形
  263. if enterpriseSupplierCooperates == nil {
  264. if param.TaskType == 2 { // 种草
  265. for _, sProjectInfo := range sProjectInfos {
  266. supplierId := sProjectInfo.SupplierID
  267. enterpriseSupplierCooperate, err1 := dao.EnterpriseSupplierCooperateDao{}.GetDataByEnterpriseAndSupplier(param.EnterpriseId, supplierId)
  268. if err1 != nil {
  269. return result, err1
  270. }
  271. enterpriseSupplierCooperates = append(enterpriseSupplierCooperates, enterpriseSupplierCooperate)
  272. }
  273. } else if param.TaskType == 3 {
  274. // 本地生活
  275. for _, sLocalLifeInfo := range sLocalLifeInfos {
  276. supplierId := sLocalLifeInfo.SupplierID
  277. enterpriseSupplierCooperate, err1 := dao.EnterpriseSupplierCooperateDao{}.GetDataByEnterpriseAndSupplier(param.EnterpriseId, supplierId)
  278. if err1 != nil {
  279. return result, err1
  280. }
  281. enterpriseSupplierCooperates = append(enterpriseSupplierCooperates, enterpriseSupplierCooperate)
  282. }
  283. }
  284. }
  285. for _, enterpriseSupplierCooperate := range enterpriseSupplierCooperates {
  286. // 获取商家操作人姓名
  287. bOperator := enterpriseSupplierCooperate.BOperator
  288. if enterpriseSupplierCooperate.BOperatorType == 1 {
  289. enterprise, err := dao.EnterpriseDao{}.GetEnterprise(bOperator)
  290. if err == nil && enterprise != nil {
  291. enterpriseOperator = enterprise.BusinessName
  292. }
  293. } else if enterpriseSupplierCooperate.BOperatorType == 2 {
  294. subAccountId, err := strconv.ParseInt(bOperator, 10, 64)
  295. if err != nil {
  296. fmt.Println("GetEnterprisePoolList==subAccountId 转换出错:", err)
  297. } else {
  298. subAccount, err := dao.SubAccountDao{}.GetSubAccount(subAccountId)
  299. if err == nil && subAccount != nil {
  300. enterpriseOperator = subAccount.SubAccountName
  301. }
  302. }
  303. }
  304. supplier, err := dao.SupplierDao{}.GetSupplierInfoById(enterpriseSupplierCooperate.SupplierId)
  305. var supplierPreview *vo.ReSupplierPreview
  306. var phoneNumber string
  307. if err == nil && supplier != nil {
  308. supplierPreview = &vo.ReSupplierPreview{
  309. SupplierId: supplier.SupplierID,
  310. HeadUrl: supplier.Avatar,
  311. SupplierName: supplier.SupplierName,
  312. SupplierType: supplier.SupplierType,
  313. CompanyName: supplier.CompanyName,
  314. Name: supplier.Name,
  315. Existence: true,
  316. }
  317. phoneNumber = supplier.PhoneNumber
  318. reSupplierTargetTask := &vo.ReSupplierTargetTask{
  319. SupplierPreview: supplierPreview,
  320. PhoneNumber: phoneNumber,
  321. WechatId: supplier.WechatNumber,
  322. WechatUrl: supplier.WechatQrcode,
  323. CooperateNum: enterpriseSupplierCooperate.CooperateNum,
  324. UploadTalentNum: enterpriseSupplierCooperate.UploadTalentNum,
  325. CooperateTalentNum: enterpriseSupplierCooperate.CooperateTalentNum,
  326. EnterpriseOperator: enterpriseOperator,
  327. Status: param.Status,
  328. }
  329. reSupplierTargetTasks = append(reSupplierTargetTasks, reSupplierTargetTask)
  330. }
  331. }
  332. result = vo.ResultVO{
  333. Page: param.Page,
  334. PageSize: param.PageSize,
  335. Total: total,
  336. Data: reSupplierTargetTasks,
  337. }
  338. return result, nil
  339. }
  340. // 服务商合作-服务商列表角标
  341. func (t CooperationService) GetSupplierInTargetCount(param *vo.SupplierSearchInTargetTaskParam) map[string]int64 {
  342. res := make(map[string]int64)
  343. var invitableNum int64 // 可邀约
  344. var invitingNum int64 // 邀约中
  345. var cooperatingNum int64 // 合作中
  346. dao.Db.Model(&entity.EnterpriseSupplierCooperate{}).Where("enterprise_id = ? AND cooperate_status = ?", param.EnterpriseId, 2).Count(&invitableNum)
  347. if param.TaskType == 2 {
  348. // 品牌种草
  349. dao.Db.Model(&entity.SProjectInfo{}).Where("project_id = ? AND s_project_status = ?", param.TaskId, 1).Count(&invitingNum)
  350. dao.Db.Model(&entity.SProjectInfo{}).Where("project_id = ? AND s_project_status = ?", param.TaskId, 2).Count(&cooperatingNum)
  351. } else if param.TaskType == 3 {
  352. // 本地生活
  353. dao.Db.Model(&entity.SLocalLifeInfo{}).Where("local_id = ? AND s_local_status = ?", param.TaskId, 1).Count(&invitingNum)
  354. dao.Db.Model(&entity.SProjectInfo{}).Where("local_id = ? AND s_local_status = ?", param.TaskId, 2).Count(&cooperatingNum)
  355. }
  356. res["invitableNum"] = invitableNum
  357. res["invitingNum"] = invitingNum
  358. res["cooperatingNum"] = cooperatingNum
  359. return res
  360. }
  361. // 服务商合作-邀约合作
  362. func (s CooperationService) InviteSupplierInTargetTask(param *vo.SupplierInviteInTargetTaskParam) error {
  363. var err error
  364. if param.TaskType == 2 {
  365. var sProjectInfo entity.SProjectInfo
  366. sProjectInfo.ProjectID = param.TaskId
  367. sProjectInfo.SupplierID = param.SupplierId
  368. sProjectInfo.SProjectStatus = 1
  369. t := time.Now()
  370. sProjectInfo.CreateTime = &t
  371. if param.SubAccountId == 0 {
  372. sProjectInfo.BOperator = param.EnterpriseId
  373. sProjectInfo.BOperatorType = 1
  374. } else {
  375. sProjectInfo.BOperator = strconv.Itoa(int(param.SubAccountId))
  376. sProjectInfo.BOperatorType = 2
  377. }
  378. // 查找该 projectId 对应的信息
  379. project, err1 := dao.ProjectDAO{}.GetProjectById(param.TaskId)
  380. if err1 != nil {
  381. return err1
  382. }
  383. if project != nil {
  384. sProjectInfo.ProductID = project.ProductID
  385. sProjectInfo.ProjectName = project.ProjectName
  386. sProjectInfo.ProjectStatus = project.ProjectStatus
  387. sProjectInfo.ProjectType = project.ProjectType
  388. sProjectInfo.ProjectPlatform = project.ProjectPlatform
  389. sProjectInfo.ProjectForm = project.ProjectForm
  390. sProjectInfo.ContentType = project.ContentType
  391. sProjectInfo.EnterpriseID = param.EnterpriseId
  392. //sProjectInfo.ApplyNum = project.ApplyNum
  393. //sProjectInfo.RecruitNum = project.RecruitNum
  394. }
  395. err = dao.SProjectDao{}.Insert(&sProjectInfo)
  396. } else if param.TaskType == 3 {
  397. // 本地生活
  398. var sLocalLifeInfo entity.SLocalLifeInfo
  399. sLocalLifeInfo.LocalID = param.TaskId
  400. sLocalLifeInfo.SupplierID = param.SupplierId
  401. sLocalLifeInfo.SLocalStatus = 1
  402. t := time.Now()
  403. sLocalLifeInfo.CreateTime = &t
  404. if param.SubAccountId == 0 {
  405. sLocalLifeInfo.BOperator = param.EnterpriseId
  406. sLocalLifeInfo.BOperatorType = 1
  407. } else {
  408. sLocalLifeInfo.BOperator = strconv.Itoa(int(param.SubAccountId))
  409. sLocalLifeInfo.BOperatorType = 2
  410. }
  411. // 查找该 localId 对应的信息
  412. localLife, err1 := dao.LocalLifeDao{}.GetLocalById(param.TaskId)
  413. if err1 != nil {
  414. return err1
  415. }
  416. if localLife != nil {
  417. sLocalLifeInfo.StoreID = localLife.StoreID
  418. sLocalLifeInfo.TeamBuyingID = localLife.TeamBuyingId
  419. sLocalLifeInfo.LocalName = localLife.LocalName
  420. sLocalLifeInfo.TaskStatus = localLife.TaskStatus
  421. sLocalLifeInfo.LocalType = localLife.LocalType
  422. sLocalLifeInfo.LocalPlatform = localLife.LocalPlatform
  423. sLocalLifeInfo.TaskForm = localLife.TaskForm
  424. sLocalLifeInfo.ContentType = localLife.ContentType
  425. sLocalLifeInfo.EnterpriseID = param.EnterpriseId
  426. //sProjectInfo.ApplyNum = project.ApplyNum
  427. //sProjectInfo.RecruitNum = project.RecruitNum
  428. }
  429. err = dao.SLocalLifeDao{}.Insert(&sLocalLifeInfo)
  430. }
  431. return err
  432. }