123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390 |
- package controllers
- import (
- "encoding/json"
- contractReq "hongze/hongze_mobile_admin/models/request/contract"
- contractResp "hongze/hongze_mobile_admin/models/response/contract"
- "hongze/hongze_mobile_admin/models/tables/contract"
- "hongze/hongze_mobile_admin/models/tables/contract_approval"
- contractService "hongze/hongze_mobile_admin/services/contract"
- "hongze/hongze_mobile_admin/utils"
- "rdluck_tools/paging"
- "strings"
- )
- //合同模块
- type ContractCommon struct {
- BaseAuth
- }
- // @Title 上传签回附件
- // @Description 上传签回附件接口
- // @Param request body contract.UploadCheckBackFileReq true "type json string"
- // @Success Ret=200 上传成功
- // @router /upload_check_back_file [post]
- func (this *ContractCommon) UploadCheckBackFile() {
- var req contractReq.UploadCheckBackFileReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- this.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error())
- return
- }
- //合同编号
- if req.ContractId <= 0 {
- this.FailWithMessage("请传入合同编号!", "请传入合同编号")
- return
- }
- if req.FileUrl == "" {
- this.FailWithMessage("请先上传附件!", "请先上传附件")
- return
- }
- err = contractService.UploadCheckBackFile(req.ContractId, req.FileUrl, this.AdminWx)
- this.OkWithMessage("上传成功")
- }
- // @Title 获取合同详情
- // @Description 获取合同详情接口
- // @Param ContractId query int true "合同id"
- // @Success 200 {object} contract.ContractDetailResp
- // @router /detail [get]
- func (this *ContractCommon) Detail() {
- //合同类型、产品类型、合同状态、更新时间、所选销售
- //关键字:合同编号、客户名称,社会信用码
- contractId, _ := this.GetInt("ContractId")
- //合同id
- if contractId <= 0 {
- this.FailWithMessage("合同id必传!", "合同id必传!")
- return
- }
- //获取合同详情
- contractInfo, flowNodeListResp, contractOpButton, err := contractService.GetContractDetailByContractId(contractId, this.AdminWx)
- if err != nil {
- this.FailWithMessage("获取合同详情失败!", "获取合同详情失败,ERR:"+err.Error())
- return
- }
- resp := contractResp.ContractDetailResp{
- ContractDetail: contractInfo,
- FlowNodeList: flowNodeListResp,
- OpButton: contractOpButton,
- }
- this.OkDetailed(resp, "获取成功")
- }
- // @Title 根据客户名称获取已存在合同系统中客户名称列表
- // @Description 获取合同详情接口
- // @Param CompanyName query string true "客户名称"
- // @Param Status query string true "合同状态"
- // @Success 200 {object} []string
- // @router /company_list [get]
- func (this *ContractCommon) CompanyList() {
- sysUser := this.AdminWx
- companyName := this.GetString("CompanyName")
- //合同id
- if companyName == "" {
- this.FailWithMessage("客户名称必传!", "客户名称必传!")
- return
- }
- status := this.GetString("Status")
- companyNameList := make([]string, 0)
- list, err := contract.GetCompanyNameList(this.AdminWx.AdminId, companyName, status)
- if err != nil {
- this.FailWithMessage("获取客户名称列表失败!", "获取客户名称列表失败,ERR:"+err.Error())
- return
- }
- for _, v := range list {
- companyNameList = append(companyNameList, v.CompanyName)
- }
- //审批列表中
- childCondition := ""
- condition := ""
- childPars := make([]interface{}, 0)
- pars := make([]interface{}, 0)
- //归属
- if status == "待审批" {
- condition += ` AND ((c.seller_id = ? and a.start_node_id = a.curr_node_id) OR (d.approve_user_id = ? )) and d.status="待审批" `
- } else {
- condition += ` AND (c.seller_id = ? or d.approve_user_id = ?)`
- }
- condition += `and company_name like '%` + companyName + `%'`
- pars = append(pars, sysUser.AdminId, sysUser.AdminId)
- list2, err := contract_approval.GetCompanyNameListV2(childCondition, condition, childPars, pars)
- if err != nil {
- this.FailWithMessage("获取客户名称列表失败!", "获取客户名称列表失败,ERR:"+err.Error())
- return
- }
- for _, v := range list2 {
- if !strings.Contains(strings.Join(companyNameList, ","), v.CompanyName) {
- companyNameList = append(companyNameList, v.CompanyName)
- }
- }
- this.OkDetailed(companyNameList, "获取成功")
- }
- // @Title 合同列表
- // @Description 合同列表接口
- // @Param ContractType query string false "合同类型,枚举值:'新签合同','续约合同','补充协议'"
- // @Param Status query string false "合同状态,枚举值:'待提交','待审批','已撤回','已审批','已驳回','已作废'"
- // @Param ProductId query int false "客户类型:传0或者不传为当前账号权限,1 代表是:ficc;2 代表是:权益"
- // @Param ModifyStartTime query string false "服务更新时间的选择开始时间,格式:2021-05-23 00:00:00"
- // @Param ModifyEndTime query string false "服务更新时间的选择结束时间,格式:2021-05-26 23:59:59"
- // @Param SellerId query string false "选择的销售id"
- // @Param Keyword query string false "搜索关键字"
- // @Success 200 {object} contract.ContractListResp
- // @router /list [get]
- func (this *ContractCommon) List() {
- //合同类型、产品类型、合同状态、更新时间、所选销售
- //关键字:合同编号、客户名称,社会信用码
- contractType := this.GetString("ContractType")
- status := this.GetString("Status")
- productId, _ := this.GetInt("ProductId")
- modifyStartTime := this.GetString("ModifyStartTime")
- modifyEndTime := this.GetString("ModifyEndTime")
- sellerIds := this.GetString("SellerId")
- keyword := this.GetString("Keyword")
- condition := ""
- pars := make([]interface{}, 0)
- //如果不是超管或者合规,那么只能查看自己的合同
- condition += ` AND seller_id = ? `
- pars = append(pars, this.AdminWx.AdminId)
- //合同类型、、更新时间、所选销售
- //关键字:合同编号、客户名称,社会信用码
- if contractType != "" {
- condition += ` AND contract_type = ? `
- pars = append(pars, contractType)
- }
- //合同状态
- if status != "" {
- condition += ` AND status = ? `
- pars = append(pars, status)
- }
- //产品类型
- if productId > 0 {
- condition += ` AND product_id = ? `
- pars = append(pars, productId)
- }
- //所选销售
- if sellerIds != "" {
- condition += ` AND seller_id IN (` + sellerIds + `) `
- }
- //更新开始时间
- if modifyStartTime != "" {
- condition += ` AND modify_time >= ? `
- pars = append(pars, modifyStartTime)
- }
- //更新结束时间
- if modifyEndTime != "" {
- condition += ` AND modify_time <= ? `
- pars = append(pars, modifyEndTime)
- }
- //关键字
- if keyword != "" {
- condition += ` AND (contract_code LIKE '%` + keyword + `%' OR company_name LIKE '%` + keyword + `%' OR credit_code LIKE '%` + keyword + `%' ) `
- }
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- total, err := contract.GetContractListCount(condition, pars)
- if err != nil {
- this.FailWithMessage("获取失败", "获取数据总数失败,Err:"+err.Error())
- return
- }
- list, err := contract.GetContractList(condition, pars, startSize, pageSize)
- if err != nil {
- this.FailWithMessage("获取合同列表失败", "获取合同列表失败,Err:"+err.Error())
- return
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- this.OkDetailed(contractResp.ContractListResp{
- List: list,
- Paging: page,
- }, "获取成功")
- }
- // @Title 合同列表(包含待提交的)
- // @Description 合同列表接口(包含待提交的)
- // @Param ContractType query string false "合同类型,枚举值:'新签合同','续约合同','补充协议'"
- // @Param Status query string false "合同状态,枚举值:'待提交','待审批','已撤回','已审批','已驳回','已作废'"
- // @Param ProductId query int false "客户类型:传0或者不传为当前账号权限,1 代表是:ficc;2 代表是:权益"
- // @Param ModifyStartTime query string false "服务更新时间的选择开始时间,格式:2021-05-23 00:00:00"
- // @Param ModifyEndTime query string false "服务更新时间的选择结束时间,格式:2021-05-26 23:59:59"
- // @Param SellerId query string false "选择的销售id"
- // @Param Keyword query string false "搜索关键字"
- // @Success 200 {object} contract.ContractListRespV2
- // @router /listV2 [get]
- func (this *ContractCommon) ListV2() {
- sysUser := this.AdminWx
- //合同类型、产品类型、合同状态、更新时间、所选销售
- //关键字:合同编号、客户名称,社会信用码
- contractType := this.GetString("ContractType")
- status := this.GetString("Status")
- productId, _ := this.GetInt("ProductId")
- modifyStartTime := this.GetString("ModifyStartTime")
- modifyEndTime := this.GetString("ModifyEndTime")
- sellerIds := this.GetString("SellerId")
- keyword := this.GetString("Keyword")
- childCondition := ""
- condition := ""
- unionCondition := ""
- childPars := make([]interface{}, 0)
- pars := make([]interface{}, 0)
- unionPars := make([]interface{}, 0)
- //归属
- if status == "待审批" {
- condition += ` AND ((c.seller_id = ? and a.start_node_id = a.curr_node_id) OR (d.approve_user_id = ? )) and d.status="待审批" `
- } else {
- condition += ` AND (c.seller_id = ? or d.approve_user_id = ?)`
- }
- pars = append(pars, sysUser.AdminId, sysUser.AdminId)
- unionCondition += ` AND c.seller_id = ? `
- unionPars = append(unionPars, sysUser.AdminId)
- //合同类型、、更新时间、所选销售
- //关键字:合同编号、客户名称,社会信用码
- if contractType != "" {
- condition += ` AND c.contract_type = ? `
- pars = append(pars, contractType)
- unionCondition += ` AND c.contract_type = ? `
- unionPars = append(unionPars, contractType)
- }
- //审批状态
- if status != "" {
- if status == "已审批" {
- condition += ` AND c.status in ("已审批","已驳回") `
- unionCondition += ` AND c.status in ("已审批","已驳回") `
- } else {
- condition += ` AND c.status = ? `
- unionCondition += ` AND c.status = ? `
- if status == "处理中" {
- pars = append(pars, "待审批")
- unionPars = append(unionPars, "待审批")
- } else {
- pars = append(pars, status)
- unionPars = append(unionPars, status)
- }
- }
- } else {
- condition += ` AND c.status not in ("已撤回","待提交") `
- unionCondition += ` AND c.status = "待提交" `
- }
- //产品类型
- if productId > 0 {
- condition += ` AND c.product_id = ? `
- pars = append(pars, productId)
- unionCondition += ` AND c.product_id = ? `
- unionPars = append(unionPars, productId)
- }
- //所选销售
- if sellerIds != "" {
- condition += ` AND c.seller_id IN (` + sellerIds + `) `
- unionCondition += ` AND c.seller_id IN (` + sellerIds + `) `
- }
- //更新开始时间
- if modifyStartTime != "" {
- condition += ` AND a.modify_time >= ? `
- pars = append(pars, modifyStartTime)
- unionCondition += ` AND a.modify_time >= ? `
- unionPars = append(unionPars, modifyStartTime)
- }
- //更新结束时间
- if modifyEndTime != "" {
- condition += ` AND a.modify_time <= ? `
- pars = append(pars, modifyEndTime)
- unionCondition += ` AND a.modify_time <= ? `
- unionPars = append(unionPars, modifyEndTime)
- }
- //关键字
- if keyword != "" {
- condition += ` AND (c.contract_code LIKE '%` + keyword + `%' OR c.company_name LIKE '%` + keyword + `%' OR c.credit_code LIKE '%` + keyword + `%' ) `
- unionCondition += ` AND (c.contract_code LIKE '%` + keyword + `%' OR c.company_name LIKE '%` + keyword + `%' OR c.credit_code LIKE '%` + keyword + `%' ) `
- }
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- joinCondition := " and a.curr_node_id=d.node_id"
- total, err := contract_approval.GetContractListCountV2(childCondition, condition, joinCondition, unionCondition, childPars, pars, unionPars)
- if err != nil {
- this.FailWithMessage("获取失败", "获取数据总数失败,Err:"+err.Error())
- return
- }
- list, err := contract_approval.GetContractListV2(childCondition, condition, joinCondition, unionCondition, childPars, pars, unionPars, startSize, pageSize)
- if err != nil {
- this.FailWithMessage("获取合同列表失败", "获取合同列表失败,Err:"+err.Error())
- return
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- this.OkDetailed(contractResp.ContractListRespV2{
- List: list,
- Paging: page,
- }, "获取成功")
- }
- // @Title 作废合同
- // @Description 作废合同接口
- // @Param request body contract.InvalidReq true "type json string"
- // @Success Ret=200 作废成功
- // @router /invalid [post]
- func (this *ContractCommon) Invalid() {
- var req contractReq.InvalidReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- this.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error())
- return
- }
- //合同id
- if req.ContractId <= 0 {
- this.FailWithMessage("合同id必传!", "合同id必传!")
- return
- }
- err = contractService.InvalidContract(req.ContractId, this.AdminWx)
- if err != nil {
- this.FailWithMessage("作废合同失败!", "作废合同失败,Err:"+err.Error())
- return
- }
- this.OkWithMessage("作废成功")
- return
- }
|