123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- package crm
- import (
- "github.com/gin-gonic/gin"
- "github.com/go-playground/validator/v10"
- "hongze/fms_api/controller/resp"
- "hongze/fms_api/global"
- "hongze/fms_api/models/base"
- "hongze/fms_api/models/crm"
- "hongze/fms_api/utils"
- )
- // ContractController CRM系统合同
- type ContractController struct{}
- // SearchList
- // @Title 搜索合同
- // @Description 搜索合同
- // @Param Keyword query string false "关键词"
- // @Param ProductId query int false "合同类型: 0-全部; 1-FICC; 2-权益"
- // @Success 200 {object} crm.ContractSearchListResp
- // @router /crm/contract/search_list [get]
- func (rg *ContractController) SearchList(c *gin.Context) {
- var req crm.ContractSearchListReq
- if e := c.BindQuery(&req); e != nil {
- err, ok := e.(validator.ValidationErrors)
- if !ok {
- resp.FailData("参数解析失败", "Err:"+e.Error(), c)
- return
- }
- resp.FailData("参数解析失败", err.Translate(global.Trans), c)
- return
- }
- cond := `status IN ('已审批', '已签回')`
- pars := make([]interface{}, 0)
- if req.Keyword != "" {
- kw := "%" + req.Keyword + "%"
- cond += ` AND (company_name LIKE ? OR contract_code LIKE ?)`
- pars = append(pars, kw, kw, kw)
- }
- if req.ProductId > 0 {
- cond += ` AND product_id = ?`
- pars = append(pars, req.ProductId)
- }
- page := new(base.Page)
- page.SetPageSize(req.PageSize)
- page.SetCurrent(req.Current)
- page.AddOrderItem(base.OrderItem{Column: "create_time", Asc: false})
- ob := new(crm.Contract)
- total, list, e := ob.PageList(page, cond, pars)
- if e != nil {
- resp.FailMsg("获取失败", "获取合同登记列表, Err: "+e.Error(), c)
- return
- }
- // 获取代付合同实际使用方
- peyContractIds := make([]int, 0)
- for i := range list {
- if list[i].ContractBusinessType == "代付合同" {
- peyContractIds = append(peyContractIds, list[i].ContractId)
- }
- }
- payCompanyMap := make(map[int]string, 0)
- if len(peyContractIds) > 0 {
- payCond := `a.status IN ('已签回', '已审批') AND b.payment_on_behalf_contract_id IN ?`
- payPars := make([]interface{}, 0)
- payPars = append(payPars, peyContractIds)
- payList, e := crm.GetPayCompanyByContractIds(payCond, payPars)
- if e != nil {
- resp.FailMsg("获取失败", "获取代付合同信息失败, Err: "+e.Error(), c)
- return
- }
- for i := range payList {
- payCompanyMap[payList[i].PayOnBehalfContractId] = payList[i].CompanyName
- }
- }
- respList := make([]*crm.ContractSearchListResp, 0)
- for i := range list {
- respList = append(respList, &crm.ContractSearchListResp{
- ContractId: list[i].ContractId,
- ContractCode: list[i].ContractCode,
- CompanyName: list[i].CompanyName,
- PayCompanyName: payCompanyMap[list[i].ContractId],
- SellerId: list[i].SellerId,
- SellerName: list[i].SellerName,
- ContractTypeKey: crm.ContractTypeFmsMap[list[i].ContractType],
- ContractType: list[i].ContractType,
- Price: list[i].Price,
- StartDate: utils.TimeTransferString(utils.FormatDate, list[i].StartDate),
- EndDate: utils.TimeTransferString(utils.FormatDate, list[i].EndDate),
- })
- }
- page.SetTotal(total)
- baseData := new(base.BaseData)
- baseData.SetPage(page)
- baseData.SetList(respList)
- resp.OkData("获取成功", baseData, c)
- }
|