cooperation_service.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  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: "",
  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: "",
  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: "",
  106. WechatUrl: "",
  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: "",
  161. SupplierName: supplier.SupplierName,
  162. SupplierType: supplier.SupplierType,
  163. CompanyName: supplier.CompanyName,
  164. Name: supplier.Name,
  165. }
  166. phoneNumber = supplier.PhoneNumber
  167. }
  168. reSupplierConfirmingInfo := &vo.ReSupplierConfirmingInfo{
  169. SupplierPreview: supplierPreview,
  170. PhoneNumber: phoneNumber,
  171. WechatId: "",
  172. WechatUrl: "",
  173. CreateTime: enterpriseSupplierCooperate.CreateTime.Format("2006-01-02 15:04:05"),
  174. Status: enterpriseSupplierCooperate.CooperateStatus,
  175. EnterpriseOperator: enterpriseOperator,
  176. }
  177. reSupplierConfirmingInfos = append(reSupplierConfirmingInfos, reSupplierConfirmingInfo)
  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. } else if param.Status == 2 { // 邀约中
  221. if param.TaskType == 2 {
  222. // 品牌种草
  223. sProjectInfos, total, _ = dao.SProjectDao{}.GetSProjectByStatus(param.TaskId, 1, param.Page, param.PageSize)
  224. } else if param.TaskType == 3 {
  225. // 本地生活
  226. sLocalLifeInfos, total, _ = dao.SLocalLifeDao{}.GetSLocalLifeByStatus(param.TaskId, 1, param.Page, param.PageSize)
  227. }
  228. } else if param.Status == 3 { // 合作中
  229. if param.TaskType == 2 {
  230. // 品牌种草
  231. sProjectInfos, total, _ = dao.SProjectDao{}.GetSProjectByStatus(param.TaskId, 2, param.Page, param.PageSize)
  232. } else if param.TaskType == 3 {
  233. // 本地生活
  234. sLocalLifeInfos, total, _ = dao.SLocalLifeDao{}.GetSLocalLifeByStatus(param.TaskId, 2, param.Page, param.PageSize)
  235. }
  236. }
  237. if enterpriseSupplierCooperates == nil {
  238. if param.TaskType == 2 { // 种草
  239. for _, sProjectInfo := range sProjectInfos {
  240. supplierId := sProjectInfo.SupplierID
  241. enterpriseSupplierCooperate, err1 := dao.EnterpriseSupplierCooperateDao{}.GetDataByEnterpriseAndSupplier(param.EnterpriseId, supplierId)
  242. if err1 != nil {
  243. return result, err1
  244. }
  245. enterpriseSupplierCooperates = append(enterpriseSupplierCooperates, enterpriseSupplierCooperate)
  246. }
  247. } else if param.TaskType == 3 {
  248. // 本地生活
  249. for _, sLocalLifeInfo := range sLocalLifeInfos {
  250. supplierId := sLocalLifeInfo.SupplierID
  251. enterpriseSupplierCooperate, err1 := dao.EnterpriseSupplierCooperateDao{}.GetDataByEnterpriseAndSupplier(param.EnterpriseId, supplierId)
  252. if err1 != nil {
  253. return result, err1
  254. }
  255. enterpriseSupplierCooperates = append(enterpriseSupplierCooperates, enterpriseSupplierCooperate)
  256. }
  257. }
  258. }
  259. for _, enterpriseSupplierCooperate := range enterpriseSupplierCooperates {
  260. // 获取商家操作人姓名
  261. bOperator := enterpriseSupplierCooperate.BOperator
  262. if enterpriseSupplierCooperate.BOperatorType == 1 {
  263. enterprise, err := dao.EnterpriseDao{}.GetEnterprise(bOperator)
  264. if err == nil && enterprise != nil {
  265. enterpriseOperator = enterprise.BusinessName
  266. }
  267. } else if enterpriseSupplierCooperate.BOperatorType == 2 {
  268. subAccountId, err := strconv.ParseInt(bOperator, 10, 64)
  269. if err != nil {
  270. fmt.Println("GetEnterprisePoolList==subAccountId 转换出错:", err)
  271. } else {
  272. subAccount, err := dao.SubAccountDao{}.GetSubAccount(subAccountId)
  273. if err == nil && subAccount != nil {
  274. enterpriseOperator = subAccount.SubAccountName
  275. }
  276. }
  277. }
  278. supplier, err := dao.SupplierDao{}.GetSupplierInfoById(enterpriseSupplierCooperate.SupplierId)
  279. var supplierPreview *vo.ReSupplierPreview
  280. var phoneNumber string
  281. if err == nil {
  282. supplierPreview = &vo.ReSupplierPreview{
  283. SupplierId: supplier.SupplierID,
  284. HeadUrl: "",
  285. SupplierName: supplier.SupplierName,
  286. SupplierType: supplier.SupplierType,
  287. CompanyName: supplier.CompanyName,
  288. Name: supplier.Name,
  289. Existence: true,
  290. }
  291. phoneNumber = supplier.PhoneNumber
  292. }
  293. reSupplierTargetTask := &vo.ReSupplierTargetTask{
  294. SupplierPreview: supplierPreview,
  295. PhoneNumber: phoneNumber,
  296. WechatId: "",
  297. WechatUrl: "",
  298. CooperateNum: enterpriseSupplierCooperate.CooperateNum,
  299. UploadTalentNum: enterpriseSupplierCooperate.UploadTalentNum,
  300. CooperateTalentNum: enterpriseSupplierCooperate.CooperateTalentNum,
  301. EnterpriseOperator: enterpriseOperator,
  302. Status: param.Status,
  303. }
  304. reSupplierTargetTasks = append(reSupplierTargetTasks, reSupplierTargetTask)
  305. }
  306. result = vo.ResultVO{
  307. Page: param.Page,
  308. PageSize: param.PageSize,
  309. Total: total,
  310. Data: reSupplierTargetTasks,
  311. }
  312. return result, nil
  313. }
  314. // 服务商合作-服务商列表角标
  315. func (t CooperationService) GetSupplierInTargetCount(param *vo.SupplierSearchInTargetTaskParam) map[string]int64 {
  316. res := make(map[string]int64)
  317. var invitableNum int64 // 可邀约
  318. var invitingNum int64 // 邀约中
  319. var cooperatingNum int64 // 合作中
  320. dao.Db.Model(&entity.EnterpriseSupplierCooperate{}).Where("enterprise_id = ? AND cooperate_status = ?", param.EnterpriseId, 2).Count(&invitableNum)
  321. if param.TaskType == 2 {
  322. // 品牌种草
  323. dao.Db.Model(&entity.SProjectInfo{}).Where("project_id = ? AND s_project_status = ?", param.TaskId, 1).Count(&invitingNum)
  324. dao.Db.Model(&entity.SProjectInfo{}).Where("project_id = ? AND s_project_status = ?", param.TaskId, 2).Count(&cooperatingNum)
  325. } else if param.TaskType == 3 {
  326. // 本地生活
  327. dao.Db.Model(&entity.SLocalLifeInfo{}).Where("local_id = ? AND s_local_status = ?", param.TaskId, 1).Count(&invitingNum)
  328. dao.Db.Model(&entity.SProjectInfo{}).Where("local_id = ? AND s_local_status = ?", param.TaskId, 2).Count(&cooperatingNum)
  329. }
  330. res["invitableNum"] = invitableNum
  331. res["invitingNum"] = invitingNum
  332. res["cooperatingNum"] = cooperatingNum
  333. return res
  334. }
  335. // 服务商合作-邀约合作
  336. func (s CooperationService) InviteSupplierInTargetTask(param *vo.SupplierInviteInTargetTaskParam) error {
  337. var sProjectInfo entity.SProjectInfo
  338. if param.TaskType == 2 {
  339. sProjectInfo.ProjectID = param.TaskId
  340. sProjectInfo.SupplierID = param.SupplierId
  341. sProjectInfo.SProjectStatus = 1
  342. sProjectInfo.CreateTime = time.Now()
  343. if param.SubAccountId == 0 {
  344. sProjectInfo.BOperator = param.EnterpriseId
  345. sProjectInfo.BOperatorType = 1
  346. } else {
  347. sProjectInfo.BOperator = strconv.Itoa(int(param.SubAccountId))
  348. sProjectInfo.BOperatorType = 2
  349. }
  350. // 查找该 projectId 对应的信息
  351. project, err1 := dao.ProjectDAO{}.GetProjectById(param.TaskId)
  352. if err1 != nil {
  353. return err1
  354. }
  355. if project != nil {
  356. sProjectInfo.ProductID = project.ProductID
  357. sProjectInfo.ProjectName = project.ProjectName
  358. sProjectInfo.ProjectStatus = project.ProjectStatus
  359. sProjectInfo.ProjectType = project.ProjectType
  360. sProjectInfo.ProjectPlatform = project.ProjectPlatform
  361. sProjectInfo.ProjectForm = project.ProjectForm
  362. sProjectInfo.ContentType = project.ContentType
  363. sProjectInfo.EnterpriseID = param.EnterpriseId
  364. //sProjectInfo.ApplyNum = project.ApplyNum
  365. //sProjectInfo.RecruitNum = project.RecruitNum
  366. }
  367. } else if param.TaskType == 3 {
  368. // 本地生活
  369. }
  370. err := dao.SProjectDao{}.Insert(&sProjectInfo)
  371. return err
  372. }