cooperation_service.go 13 KB

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