contract.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. package crm
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "github.com/go-playground/validator/v10"
  5. "hongze/fms_api/controller/resp"
  6. "hongze/fms_api/global"
  7. "hongze/fms_api/models/base"
  8. "hongze/fms_api/models/crm"
  9. "hongze/fms_api/utils"
  10. )
  11. // ContractController CRM系统合同
  12. type ContractController struct{}
  13. // SearchList
  14. // @Title 搜索合同
  15. // @Description 搜索合同
  16. // @Param Keyword query string false "关键词"
  17. // @Param ProductId query int false "合同类型: 0-全部; 1-FICC; 2-权益"
  18. // @Success 200 {object} crm.ContractSearchListResp
  19. // @router /crm/contract/search_list [get]
  20. func (rg *ContractController) SearchList(c *gin.Context) {
  21. var req crm.ContractSearchListReq
  22. if e := c.BindQuery(&req); e != nil {
  23. err, ok := e.(validator.ValidationErrors)
  24. if !ok {
  25. resp.FailData("参数解析失败", "Err:"+e.Error(), c)
  26. return
  27. }
  28. resp.FailData("参数解析失败", err.Translate(global.Trans), c)
  29. return
  30. }
  31. cond := `status IN ('已审批', '已签回')`
  32. pars := make([]interface{}, 0)
  33. if req.Keyword != "" {
  34. kw := "%" + req.Keyword + "%"
  35. cond += ` AND (company_name LIKE ? OR contract_code LIKE ?)`
  36. pars = append(pars, kw, kw, kw)
  37. }
  38. if req.ProductId > 0 {
  39. cond += ` AND product_id = ?`
  40. pars = append(pars, req.ProductId)
  41. }
  42. page := new(base.Page)
  43. page.SetPageSize(req.PageSize)
  44. page.SetCurrent(req.Current)
  45. page.AddOrderItem(base.OrderItem{Column: "create_time", Asc: false})
  46. ob := new(crm.Contract)
  47. total, list, e := ob.PageList(page, cond, pars)
  48. if e != nil {
  49. resp.FailMsg("获取失败", "获取合同登记列表, Err: "+e.Error(), c)
  50. return
  51. }
  52. // 获取代付合同实际使用方
  53. peyContractIds := make([]int, 0)
  54. for i := range list {
  55. if list[i].ContractBusinessType == "代付合同" {
  56. peyContractIds = append(peyContractIds, list[i].ContractId)
  57. }
  58. }
  59. payCompanyMap := make(map[int]string, 0)
  60. if len(peyContractIds) > 0 {
  61. payCond := `a.status IN ('已签回', '已审批') AND b.payment_on_behalf_contract_id IN ?`
  62. payPars := make([]interface{}, 0)
  63. payPars = append(payPars, peyContractIds)
  64. payList, e := crm.GetPayCompanyByContractIds(payCond, payPars)
  65. if e != nil {
  66. resp.FailMsg("获取失败", "获取代付合同信息失败, Err: "+e.Error(), c)
  67. return
  68. }
  69. for i := range payList {
  70. payCompanyMap[payList[i].PayOnBehalfContractId] = payList[i].CompanyName
  71. }
  72. }
  73. respList := make([]*crm.ContractSearchListResp, 0)
  74. for i := range list {
  75. respList = append(respList, &crm.ContractSearchListResp{
  76. ContractId: list[i].ContractId,
  77. ContractCode: list[i].ContractCode,
  78. CompanyName: list[i].CompanyName,
  79. PayCompanyName: payCompanyMap[list[i].ContractId],
  80. SellerId: list[i].SellerId,
  81. SellerName: list[i].SellerName,
  82. ContractTypeKey: crm.ContractTypeFmsMap[list[i].ContractType],
  83. ContractType: list[i].ContractType,
  84. Price: list[i].Price,
  85. StartDate: utils.TimeTransferString(utils.FormatDate, list[i].StartDate),
  86. EndDate: utils.TimeTransferString(utils.FormatDate, list[i].EndDate),
  87. })
  88. }
  89. page.SetTotal(total)
  90. baseData := new(base.BaseData)
  91. baseData.SetPage(page)
  92. baseData.SetList(respList)
  93. resp.OkData("获取成功", baseData, c)
  94. }