contract.go 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "hongze/hongze_mobile_admin/models"
  7. contractReq "hongze/hongze_mobile_admin/models/request/contract"
  8. contractResp "hongze/hongze_mobile_admin/models/response/contract"
  9. "hongze/hongze_mobile_admin/models/tables/contract"
  10. "hongze/hongze_mobile_admin/models/tables/contract_approval"
  11. "hongze/hongze_mobile_admin/models/tables/contract_relation"
  12. contractService "hongze/hongze_mobile_admin/services/contract"
  13. "hongze/hongze_mobile_admin/services/seal"
  14. "hongze/hongze_mobile_admin/utils"
  15. "path"
  16. "strconv"
  17. "strings"
  18. )
  19. // 合同模块
  20. type ContractCommon struct {
  21. BaseAuth
  22. }
  23. // @Title 上传签回附件
  24. // @Description 上传签回附件接口
  25. // @Param request body contract.UploadCheckBackFileReq true "type json string"
  26. // @Success Ret=200 上传成功
  27. // @router /upload_check_back_file [post]
  28. func (c *ContractCommon) UploadCheckBackFile() {
  29. //var req contractReq.UploadCheckBackFileReq
  30. //err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  31. //if err != nil {
  32. // c.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error())
  33. // return
  34. //}
  35. ////合同编号
  36. //if req.ContractId <= 0 {
  37. // c.FailWithMessage("请传入合同编号!", "请传入合同编号")
  38. // return
  39. //}
  40. //
  41. //if req.FileUrl == "" {
  42. // c.FailWithMessage("请先上传附件!", "请先上传附件")
  43. // return
  44. //}
  45. contractIdStr := c.Ctx.Request.Form.Get("ContractId")
  46. if contractIdStr == "" {
  47. c.FailWithMessage("合同ID必传!", "合同ID必传")
  48. return
  49. }
  50. contractId, err := strconv.Atoi(contractIdStr)
  51. if err != nil {
  52. c.FailWithMessage("合同ID异常!", "合同ID必传")
  53. return
  54. }
  55. //合同编号
  56. if contractId <= 0 {
  57. c.FailWithMessage("请传入合同编号", "请传入合同编号")
  58. return
  59. }
  60. fileMulti, h, err := c.GetFile("file")
  61. if err != nil {
  62. c.FailWithMessage("获取资源信息失败", "获取资源信息失败,Err:"+err.Error())
  63. return
  64. }
  65. ext := path.Ext(h.Filename)
  66. //err = contractService.UploadCheckBackFile(contractId, req.FileUrl, c.AdminWx)
  67. resourceUrl, err := contractService.UploadCheckBackFileByFile(contractId, ext, fileMulti, c.AdminWx)
  68. //更新用印中的签回合同
  69. _, _ = seal.UploadCheckBackFile(contractId, resourceUrl, c.AdminWx)
  70. c.OkWithMessage("上传成功")
  71. }
  72. // Detail
  73. // @Title 获取合同详情
  74. // @Description 获取合同详情接口
  75. // @Param ContractId query int true "合同id"
  76. // @Success 200 {object} contract.ContractDetailResp
  77. // @router /detail [get]
  78. func (c *ContractCommon) Detail() {
  79. //合同类型、产品类型、合同状态、更新时间、所选销售
  80. //关键字:合同编号、客户名称,社会信用码
  81. contractId, _ := c.GetInt("ContractId")
  82. //合同id
  83. if contractId <= 0 {
  84. c.FailWithMessage("合同id必传!", "合同id必传!")
  85. return
  86. }
  87. //获取合同详情
  88. contractInfo, flowNodeListResp, contractOpButton, err := contractService.GetContractDetailByContractId(contractId, c.AdminWx)
  89. if err != nil {
  90. c.FailWithMessage("获取合同详情失败!", "获取合同详情失败,ERR:"+err.Error())
  91. return
  92. }
  93. resp := contractResp.ContractDetailResp{
  94. ContractDetail: contractInfo,
  95. FlowNodeList: flowNodeListResp,
  96. OpButton: contractOpButton,
  97. }
  98. c.OkDetailed(resp, "获取成功")
  99. }
  100. // CompanyList
  101. // @Title 根据客户名称获取已存在合同系统中客户名称列表
  102. // @Description 获取合同详情接口
  103. // @Param CompanyName query string true "客户名称"
  104. // @Param Keyword query string true "关键字:客户名称、社会信用码"
  105. // @Param Status query string true "合同状态"
  106. // @Success 200 {object} []string
  107. // @router /company_list [get]
  108. func (c *ContractCommon) CompanyList() {
  109. sysUser := c.AdminWx
  110. keyword := c.GetString("Keyword")
  111. //搜索关键字
  112. if keyword == "" {
  113. c.FailWithMessage("搜索关键字必传!", "搜索关键字必传!")
  114. return
  115. }
  116. status := c.GetString("Status")
  117. companyNameList := make([]string, 0)
  118. list, err := contract.GetCompanyNameList(c.AdminWx.AdminId, keyword, status)
  119. if err != nil {
  120. c.FailWithMessage("获取客户名称列表失败!", "获取客户名称列表失败,ERR:"+err.Error())
  121. return
  122. }
  123. for _, v := range list {
  124. companyNameList = append(companyNameList, v.CompanyName)
  125. }
  126. //审批列表中(跟自己有关联的)
  127. childCondition := ""
  128. condition := ""
  129. childPars := make([]interface{}, 0)
  130. pars := make([]interface{}, 0)
  131. if status != "" {
  132. condition += `and c.status=? `
  133. pars = append(pars, status)
  134. }
  135. //归属
  136. //如果不是合规,那么只能查看跟自己有关联的
  137. if status == "待审批" {
  138. condition += ` AND ((c.seller_id = ? and a.start_node_id = a.curr_node_id) OR (d.approve_user_id = ? )) and d.status="待审批" `
  139. } else {
  140. condition += ` AND (c.seller_id = ? or (d.approve_user_id = ? and d.node_id <= a.curr_node_id and c.status != "已撤回") )`
  141. }
  142. pars = append(pars, sysUser.AdminId, sysUser.AdminId)
  143. condition += `and (company_name like '%` + keyword + `%' or credit_code like '%` + keyword + `%')`
  144. list2, err := contract_approval.GetCompanyNameListV2(childCondition, condition, childPars, pars)
  145. if err != nil {
  146. c.FailWithMessage("获取客户名称列表失败!", "获取客户名称列表失败,ERR:"+err.Error())
  147. return
  148. }
  149. for _, v := range list2 {
  150. if !strings.Contains(strings.Join(companyNameList, ","), v.CompanyName) {
  151. companyNameList = append(companyNameList, v.CompanyName)
  152. }
  153. }
  154. c.OkDetailed(companyNameList, "获取成功")
  155. }
  156. // List
  157. // @Title 合同列表
  158. // @Description 合同列表接口
  159. // @Param ContractType query string false "合同类型,枚举值:'新签合同','续约合同','补充协议'"
  160. // @Param Status query string false "合同状态,枚举值:'待提交','待审批','已撤回','已审批','已驳回','已作废'"
  161. // @Param ProductId query int false "客户类型:传0或者不传为当前账号权限,1 代表是:ficc;2 代表是:权益"
  162. // @Param ModifyStartTime query string false "服务更新时间的选择开始时间,格式:2021-05-23 00:00:00"
  163. // @Param ModifyEndTime query string false "服务更新时间的选择结束时间,格式:2021-05-26 23:59:59"
  164. // @Param SellerId query string false "选择的销售id"
  165. // @Param Keyword query string false "搜索关键字"
  166. // @Param KeywordEq query string false "搜索关键字(全等)"
  167. // @Success 200 {object} contract.ContractListResp
  168. // @router /list [get]
  169. func (c *ContractCommon) List() {
  170. //合同类型、产品类型、合同状态、更新时间、所选销售
  171. //关键字:合同编号、客户名称,社会信用码
  172. contractType := c.GetString("ContractType")
  173. status := c.GetString("Status")
  174. productId, _ := c.GetInt("ProductId")
  175. modifyStartTime := c.GetString("ModifyStartTime")
  176. modifyEndTime := c.GetString("ModifyEndTime")
  177. sellerIds := c.GetString("SellerId")
  178. keyword := c.GetString("Keyword")
  179. keywordEq := c.GetString("KeywordEq")
  180. condition := ""
  181. pars := make([]interface{}, 0)
  182. //如果不是超管或者合规,那么只能查看自己的合同
  183. condition += ` AND seller_id = ? `
  184. pars = append(pars, c.AdminWx.AdminId)
  185. //合同类型、、更新时间、所选销售
  186. //关键字:合同编号、客户名称,社会信用码
  187. if contractType != "" {
  188. condition += ` AND contract_type = ? `
  189. pars = append(pars, contractType)
  190. }
  191. //合同状态
  192. if status != "" {
  193. condition += ` AND status = ? `
  194. pars = append(pars, status)
  195. }
  196. //产品类型
  197. if productId > 0 {
  198. condition += ` AND product_id = ? `
  199. pars = append(pars, productId)
  200. }
  201. //所选销售
  202. if sellerIds != "" {
  203. condition += ` AND seller_id IN (` + sellerIds + `) `
  204. }
  205. //更新开始时间
  206. if modifyStartTime != "" {
  207. condition += ` AND modify_time >= ? `
  208. pars = append(pars, modifyStartTime)
  209. }
  210. //更新结束时间
  211. if modifyEndTime != "" {
  212. condition += ` AND modify_time <= ? `
  213. pars = append(pars, modifyEndTime)
  214. }
  215. //关键字
  216. if keyword != "" {
  217. condition += ` AND (contract_code LIKE '%` + keyword + `%' OR company_name LIKE '%` + keyword + `%' OR credit_code LIKE '%` + keyword + `%' ) `
  218. }
  219. //关键字(全等)
  220. if keywordEq != "" {
  221. condition += ` AND c.company_name =? `
  222. pars = append(pars, keywordEq)
  223. }
  224. pageSize, _ := c.GetInt("PageSize")
  225. currentIndex, _ := c.GetInt("CurrentIndex")
  226. var startSize int
  227. if pageSize <= 0 {
  228. pageSize = utils.PageSize20
  229. }
  230. if currentIndex <= 0 {
  231. currentIndex = 1
  232. }
  233. startSize = paging.StartIndex(currentIndex, pageSize)
  234. total, err := contract.GetContractListCount(condition, pars)
  235. if err != nil {
  236. c.FailWithMessage("获取失败", "获取数据总数失败,Err:"+err.Error())
  237. return
  238. }
  239. list, err := contract.GetContractList(condition, pars, startSize, pageSize)
  240. if err != nil {
  241. c.FailWithMessage("获取合同列表失败", "获取合同列表失败,Err:"+err.Error())
  242. return
  243. }
  244. page := paging.GetPaging(currentIndex, pageSize, total)
  245. c.OkDetailed(contractResp.ContractListResp{
  246. List: list,
  247. Paging: page,
  248. }, "获取成功")
  249. }
  250. // CompanyListBySeal
  251. // @Title 根据客户名称获取已存在合同系统中客户名称列表
  252. // @Description 获取合同详情接口
  253. // @Param CompanyName query string true "客户名称"
  254. // @Param Keyword query string true "关键字:客户名称、社会信用码"
  255. // @Param Status query string true "合同状态"
  256. // @Success 200 {object} []string
  257. // @router /companyListBySeal [get]
  258. func (c *ContractCommon) CompanyListBySeal() {
  259. sysUser := c.AdminWx
  260. keyword := c.GetString("Keyword")
  261. //搜索关键字
  262. if keyword == "" {
  263. c.FailWithMessage("搜索关键字必传!", "搜索关键字必传!")
  264. return
  265. }
  266. status := c.GetString("Status")
  267. companyNameList := make([]string, 0)
  268. sellerId := 0
  269. if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_COMPLIANCE {
  270. sellerId = c.AdminWx.AdminId
  271. }
  272. list, err := contract.GetCompanyNameList(sellerId, keyword, status)
  273. if err != nil {
  274. c.FailWithMessage("获取客户名称列表失败!", "获取客户名称列表失败,ERR:"+err.Error())
  275. return
  276. }
  277. for _, v := range list {
  278. companyNameList = append(companyNameList, v.CompanyName)
  279. }
  280. // 13.6正式共享客户的处理
  281. {
  282. // 通过关键词获取分配给当前销售的正式共享客户
  283. kw := fmt.Sprint("%", keyword, "%")
  284. cond := ` AND company_name LIKE ?`
  285. pars := make([]interface{}, 0)
  286. pars = append(pars, kw)
  287. shares, e := models.GetCompanyListByCondition(cond, pars, []string{"company_id", "company_name"}, "")
  288. if e != nil {
  289. c.FailWithMessage("获取失败", "获取共享客户信息失败, Err: "+e.Error())
  290. return
  291. }
  292. for _, v := range shares {
  293. if !utils.InArrayByStr(companyNameList, v.CompanyName) {
  294. companyNameList = append(companyNameList, v.CompanyName)
  295. }
  296. }
  297. }
  298. //审批列表中(跟自己有关联的)
  299. //childCondition := ""
  300. //condition := ""
  301. //childPars := make([]interface{}, 0)
  302. //pars := make([]interface{}, 0)
  303. //if status != "" {
  304. // condition += `and c.status=? `
  305. // pars = append(pars, status)
  306. //}
  307. ////归属
  308. ////如果不是合规,那么只能查看跟自己有关联的
  309. //if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_COMPLIANCE {
  310. // if status == "待审批" {
  311. // condition += ` AND ((c.seller_id = ? and a.start_node_id = a.curr_node_id) OR (d.approve_user_id = ? )) and d.status="待审批" `
  312. // } else {
  313. // condition += ` AND (c.seller_id = ? or d.approve_user_id = ?)`
  314. // }
  315. // pars = append(pars, sysUser.AdminId, sysUser.AdminId)
  316. //}
  317. //
  318. //condition += `and (company_name like '%` + keyword + `%' or credit_code like '%` + keyword + `%')`
  319. //
  320. //list2, err := contract_approval.GetCompanyNameListV2(childCondition, condition, childPars, pars)
  321. //if err != nil {
  322. // c.FailWithMessage("获取客户名称列表失败!", "获取客户名称列表失败,ERR:"+err.Error())
  323. // return
  324. //}
  325. //for _, v := range list2 {
  326. // if !strings.Contains(strings.Join(companyNameList, ","), v.CompanyName) {
  327. // companyNameList = append(companyNameList, v.CompanyName)
  328. // }
  329. //}
  330. c.OkDetailed(companyNameList, "获取成功")
  331. }
  332. // ListBySeal
  333. // @Title 合同列表
  334. // @Description 合同列表接口
  335. // @Param ContractType query string false "合同类型,枚举值:'新签合同','续约合同','补充协议'"
  336. // @Param Status query string false "合同状态,枚举值:'待提交','待审批','已撤回','已审批','已驳回','已作废'"
  337. // @Param ProductId query int false "客户类型:传0或者不传为当前账号权限,1 代表是:ficc;2 代表是:权益"
  338. // @Param ModifyStartTime query string false "服务更新时间的选择开始时间,格式:2021-05-23 00:00:00"
  339. // @Param ModifyEndTime query string false "服务更新时间的选择结束时间,格式:2021-05-26 23:59:59"
  340. // @Param SellerId query string false "选择的销售id"
  341. // @Param Keyword query string false "搜索关键字"
  342. // @Param KeywordEq query string false "搜索关键字(全等)"
  343. // @Success 200 {object} contract.ContractListResp
  344. // @router /listBySeal [get]
  345. func (c *ContractCommon) ListBySeal() {
  346. sysUser := c.AdminWx
  347. //合同类型、产品类型、合同状态、更新时间、所选销售
  348. //关键字:合同编号、客户名称,社会信用码
  349. contractType := c.GetString("ContractType")
  350. status := c.GetString("Status")
  351. productId, _ := c.GetInt("ProductId")
  352. modifyStartTime := c.GetString("ModifyStartTime")
  353. modifyEndTime := c.GetString("ModifyEndTime")
  354. sellerIds := c.GetString("SellerId")
  355. keyword := c.GetString("Keyword")
  356. keywordEq := c.GetString("KeywordEq")
  357. condition := ""
  358. pars := make([]interface{}, 0)
  359. //如果不是合规,那么只能查看自己的合同
  360. if c.AdminWx.RoleTypeCode != utils.ROLE_TYPE_CODE_COMPLIANCE {
  361. condition += ` AND a.seller_id = ? `
  362. pars = append(pars, c.AdminWx.AdminId)
  363. }
  364. //合同类型、、更新时间、所选销售
  365. //关键字:合同编号、客户名称,社会信用码
  366. if contractType != "" {
  367. condition += ` AND a.contract_type = ? `
  368. pars = append(pars, contractType)
  369. }
  370. //合同状态
  371. if status != "" {
  372. condition += ` AND a.status = ? `
  373. pars = append(pars, status)
  374. }
  375. //产品类型
  376. if productId > 0 {
  377. condition += ` AND a.product_id = ? `
  378. pars = append(pars, productId)
  379. }
  380. //所选销售
  381. if sellerIds != "" {
  382. condition += ` AND a.seller_id IN (` + sellerIds + `) `
  383. }
  384. //更新开始时间
  385. if modifyStartTime != "" {
  386. condition += ` AND a.modify_time >= ? `
  387. pars = append(pars, modifyStartTime)
  388. }
  389. //更新结束时间
  390. if modifyEndTime != "" {
  391. condition += ` AND a.modify_time <= ? `
  392. pars = append(pars, modifyEndTime)
  393. }
  394. //关键字
  395. if keyword != "" {
  396. condition += ` AND (a.contract_code LIKE '%` + keyword + `%' OR a.company_name LIKE '%` + keyword + `%' OR a.credit_code LIKE '%` + keyword + `%' ) `
  397. }
  398. //关键字(全等)
  399. if keywordEq != "" {
  400. condition += ` AND c.company_name =? `
  401. pars = append(pars, keywordEq)
  402. }
  403. pageSize, _ := c.GetInt("PageSize")
  404. currentIndex, _ := c.GetInt("CurrentIndex")
  405. var startSize int
  406. if pageSize <= 0 {
  407. pageSize = utils.PageSize20
  408. }
  409. if currentIndex <= 0 {
  410. currentIndex = 1
  411. }
  412. startSize = paging.StartIndex(currentIndex, pageSize)
  413. //total, err := contract.GetContractListCount(condition, pars)
  414. //if err != nil {
  415. // c.FailWithMessage("获取失败", "获取数据总数失败,Err:"+err.Error())
  416. // return
  417. //}
  418. //
  419. //list, err := contract.GetContractList(condition, pars, startSize, pageSize)
  420. //if err != nil {
  421. // c.FailWithMessage("获取合同列表失败", "获取合同列表失败,Err:"+err.Error())
  422. // return
  423. //}
  424. // 13.6正式共享客户
  425. joinStr := ` LEFT JOIN company AS b ON a.company_name = b.company_name `
  426. // 非合规角色可查看自己的合同或是自己的共享客户下的非自己创建的合同
  427. if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_COMPLIANCE {
  428. condition += ` AND (a.seller_id = ? OR (b.is_share = 1 AND b.share_seller_id = ?))`
  429. pars = append(pars, sysUser.AdminId, sysUser.AdminId)
  430. }
  431. total, err := contract.GetJoinContractListCount(condition, joinStr, pars)
  432. if err != nil {
  433. c.FailWithMessage("获取失败", "获取数据总数失败,Err:"+err.Error())
  434. return
  435. }
  436. list, e := contract.GetJoinContractList(condition, joinStr, pars, startSize, pageSize)
  437. if e != nil {
  438. c.FailWithMessage("获取失败", "获取合同列表失败,Err:"+err.Error())
  439. return
  440. }
  441. if len(list) > 0 {
  442. // 代付合同查询代付用户名称
  443. contractIdSlice := make([]string, 0)
  444. for i := 0; i < len(list); i++ {
  445. if list[i].ContractBusinessType == "代付合同" {
  446. contractIdSlice = append(contractIdSlice, strconv.Itoa(list[i].ContractId))
  447. }
  448. }
  449. if len(contractIdSlice) > 0 {
  450. contractIdStr := strings.Join(contractIdSlice, ",")
  451. contractList, err := contract_relation.GetContractRelationListByPaymentOnBehalfContractIds(contractIdStr)
  452. if err != nil {
  453. c.FailWithMessage("获取失败", "获取代付合同对应的合同数据失败,Err:"+err.Error())
  454. return
  455. }
  456. userCompanyNameMap := make(map[int]string, 0)
  457. for i := 0; i < len(contractList); i++ {
  458. userCompanyNameMap[contractList[i].PaymentOnBehalfContractId] = contractList[i].CompanyName
  459. }
  460. for _, item := range list {
  461. if item.ContractBusinessType == "代付合同" {
  462. item.UseCompanyName = userCompanyNameMap[item.ContractId]
  463. }
  464. }
  465. }
  466. }
  467. page := paging.GetPaging(currentIndex, pageSize, total)
  468. c.OkDetailed(contractResp.ContractListResp{
  469. List: list,
  470. Paging: page,
  471. }, "获取成功")
  472. }
  473. // ListV2
  474. // @Title 合同列表(包含待提交的)
  475. // @Description 合同列表接口(包含待提交的)
  476. // @Param ContractType query string false "合同类型,枚举值:'新签合同','续约合同','补充协议'"
  477. // @Param Status query string false "合同状态,枚举值:'待提交','待审批','已撤回','已审批','已驳回','已作废'"
  478. // @Param ProductId query int false "客户类型:传0或者不传为当前账号权限,1 代表是:ficc;2 代表是:权益"
  479. // @Param ModifyStartTime query string false "服务更新时间的选择开始时间,格式:2021-05-23 00:00:00"
  480. // @Param ModifyEndTime query string false "服务更新时间的选择结束时间,格式:2021-05-26 23:59:59"
  481. // @Param SellerId query string false "选择的销售id"
  482. // @Param Keyword query string false "搜索关键字"
  483. // @Param KeywordEq query string false "搜索关键字(全等)"
  484. // @Success 200 {object} contract.ContractListRespV2
  485. // @router /listV2 [get]
  486. func (c *ContractCommon) ListV2() {
  487. sysUser := c.AdminWx
  488. //合同类型、产品类型、合同状态、更新时间、所选销售
  489. //关键字:合同编号、客户名称,社会信用码
  490. contractType := c.GetString("ContractType")
  491. status := c.GetString("Status")
  492. productId, _ := c.GetInt("ProductId")
  493. modifyStartTime := c.GetString("ModifyStartTime")
  494. modifyEndTime := c.GetString("ModifyEndTime")
  495. sellerIds := c.GetString("SellerId")
  496. keyword := c.GetString("Keyword")
  497. keywordEq := c.GetString("KeywordEq")
  498. childCondition := ""
  499. condition := ""
  500. unionCondition := ""
  501. childPars := make([]interface{}, 0)
  502. pars := make([]interface{}, 0)
  503. unionPars := make([]interface{}, 0)
  504. //归属
  505. if status == "待审批" {
  506. condition += ` AND ((c.seller_id = ? and a.start_node_id = a.curr_node_id) OR (d.approve_user_id = ? )) and d.status="待审批" `
  507. } else {
  508. condition += ` AND (c.seller_id = ? or d.approve_user_id = ?)`
  509. }
  510. pars = append(pars, sysUser.AdminId, sysUser.AdminId)
  511. unionCondition += ` AND c.seller_id = ? `
  512. unionPars = append(unionPars, sysUser.AdminId)
  513. //合同类型、、更新时间、所选销售
  514. //关键字:合同编号、客户名称,社会信用码
  515. if contractType != "" {
  516. condition += ` AND c.contract_type = ? `
  517. pars = append(pars, contractType)
  518. unionCondition += ` AND c.contract_type = ? `
  519. unionPars = append(unionPars, contractType)
  520. }
  521. //审批状态
  522. if status != "" {
  523. if status == "已审批" {
  524. condition += ` AND c.status in ("已审批","已驳回") `
  525. unionCondition += ` AND c.status in ("已审批","已驳回") `
  526. } else {
  527. condition += ` AND c.status = ? `
  528. unionCondition += ` AND c.status = ? `
  529. if status == "处理中" {
  530. pars = append(pars, "待审批")
  531. unionPars = append(unionPars, "待审批")
  532. } else {
  533. pars = append(pars, status)
  534. unionPars = append(unionPars, status)
  535. }
  536. }
  537. } else {
  538. condition += ` AND c.status not in ("已撤回","待提交") `
  539. unionCondition += ` AND c.status = "待提交" `
  540. }
  541. //产品类型
  542. if productId > 0 {
  543. condition += ` AND c.product_id = ? `
  544. pars = append(pars, productId)
  545. unionCondition += ` AND c.product_id = ? `
  546. unionPars = append(unionPars, productId)
  547. }
  548. //所选销售
  549. if sellerIds != "" {
  550. condition += ` AND c.seller_id IN (` + sellerIds + `) `
  551. unionCondition += ` AND c.seller_id IN (` + sellerIds + `) `
  552. }
  553. //更新开始时间
  554. if modifyStartTime != "" {
  555. condition += ` AND a.modify_time >= ? `
  556. pars = append(pars, modifyStartTime)
  557. unionCondition += ` AND a.modify_time >= ? `
  558. unionPars = append(unionPars, modifyStartTime)
  559. }
  560. //更新结束时间
  561. if modifyEndTime != "" {
  562. condition += ` AND a.modify_time <= ? `
  563. pars = append(pars, modifyEndTime)
  564. unionCondition += ` AND a.modify_time <= ? `
  565. unionPars = append(unionPars, modifyEndTime)
  566. }
  567. //关键字
  568. if keyword != "" {
  569. condition += ` AND (c.contract_code LIKE '%` + keyword + `%' OR c.company_name LIKE '%` + keyword + `%' OR c.credit_code LIKE '%` + keyword + `%' ) `
  570. unionCondition += ` AND (c.contract_code LIKE '%` + keyword + `%' OR c.company_name LIKE '%` + keyword + `%' OR c.credit_code LIKE '%` + keyword + `%' ) `
  571. }
  572. //关键字(全等)
  573. if keywordEq != "" {
  574. condition += ` AND c.company_name =? `
  575. pars = append(pars, keywordEq)
  576. unionCondition += ` AND c.company_name =? `
  577. unionPars = append(unionPars, keywordEq)
  578. }
  579. pageSize, _ := c.GetInt("PageSize")
  580. currentIndex, _ := c.GetInt("CurrentIndex")
  581. var startSize int
  582. if pageSize <= 0 {
  583. pageSize = utils.PageSize20
  584. }
  585. if currentIndex <= 0 {
  586. currentIndex = 1
  587. }
  588. startSize = paging.StartIndex(currentIndex, pageSize)
  589. //joinCondition := " and a.curr_node_id=d.node_id"
  590. joinCondition := ""
  591. total, err := contract_approval.GetContractListCountV2(childCondition, condition, joinCondition, unionCondition, childPars, pars, unionPars)
  592. if err != nil {
  593. c.FailWithMessage("获取失败", "获取数据总数失败,Err:"+err.Error())
  594. return
  595. }
  596. list, err := contract_approval.GetContractListV2(childCondition, condition, joinCondition, unionCondition, childPars, pars, unionPars, startSize, pageSize)
  597. if err != nil {
  598. c.FailWithMessage("获取合同列表失败", "获取合同列表失败,Err:"+err.Error())
  599. return
  600. }
  601. page := paging.GetPaging(currentIndex, pageSize, total)
  602. c.OkDetailed(contractResp.ContractListRespV2{
  603. List: list,
  604. Paging: page,
  605. }, "获取成功")
  606. }
  607. // @Title 作废合同
  608. // @Description 作废合同接口
  609. // @Param request body contract.InvalidReq true "type json string"
  610. // @Success Ret=200 作废成功
  611. // @router /invalid [post]
  612. func (c *ContractCommon) Invalid() {
  613. var req contractReq.InvalidReq
  614. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  615. if err != nil {
  616. c.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error())
  617. return
  618. }
  619. //合同id
  620. if req.ContractId <= 0 {
  621. c.FailWithMessage("合同id必传!", "合同id必传!")
  622. return
  623. }
  624. err = contractService.InvalidContract(req.ContractId, c.AdminWx)
  625. if err != nil {
  626. c.FailWithMessage("作废合同失败!", "作废合同失败,Err:"+err.Error())
  627. return
  628. }
  629. c.OkWithMessage("作废成功")
  630. return
  631. }