contract.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. package controllers
  2. import (
  3. "encoding/json"
  4. contractReq "hongze/hongze_mobile_admin/models/request/contract"
  5. contractResp "hongze/hongze_mobile_admin/models/response/contract"
  6. "hongze/hongze_mobile_admin/models/tables/contract"
  7. "hongze/hongze_mobile_admin/models/tables/contract_approval"
  8. contractService "hongze/hongze_mobile_admin/services/contract"
  9. "hongze/hongze_mobile_admin/utils"
  10. "rdluck_tools/paging"
  11. "strings"
  12. )
  13. //合同模块
  14. type ContractCommon struct {
  15. BaseAuth
  16. }
  17. // @Title 上传签回附件
  18. // @Description 上传签回附件接口
  19. // @Param request body contract.UploadCheckBackFileReq true "type json string"
  20. // @Success Ret=200 上传成功
  21. // @router /upload_check_back_file [post]
  22. func (this *ContractCommon) UploadCheckBackFile() {
  23. var req contractReq.UploadCheckBackFileReq
  24. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  25. if err != nil {
  26. this.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error())
  27. return
  28. }
  29. //合同编号
  30. if req.ContractId <= 0 {
  31. this.FailWithMessage("请传入合同编号!", "请传入合同编号")
  32. return
  33. }
  34. if req.FileUrl == "" {
  35. this.FailWithMessage("请先上传附件!", "请先上传附件")
  36. return
  37. }
  38. err = contractService.UploadCheckBackFile(req.ContractId, req.FileUrl, this.AdminWx)
  39. this.OkWithMessage("上传成功")
  40. }
  41. // @Title 获取合同详情
  42. // @Description 获取合同详情接口
  43. // @Param ContractId query int true "合同id"
  44. // @Success 200 {object} contract.ContractDetailResp
  45. // @router /detail [get]
  46. func (this *ContractCommon) Detail() {
  47. //合同类型、产品类型、合同状态、更新时间、所选销售
  48. //关键字:合同编号、客户名称,社会信用码
  49. contractId, _ := this.GetInt("ContractId")
  50. //合同id
  51. if contractId <= 0 {
  52. this.FailWithMessage("合同id必传!", "合同id必传!")
  53. return
  54. }
  55. //获取合同详情
  56. contractInfo, flowNodeListResp, contractOpButton, err := contractService.GetContractDetailByContractId(contractId, this.AdminWx)
  57. if err != nil {
  58. this.FailWithMessage("获取合同详情失败!", "获取合同详情失败,ERR:"+err.Error())
  59. return
  60. }
  61. resp := contractResp.ContractDetailResp{
  62. ContractDetail: contractInfo,
  63. FlowNodeList: flowNodeListResp,
  64. OpButton: contractOpButton,
  65. }
  66. this.OkDetailed(resp, "获取成功")
  67. }
  68. // @Title 根据客户名称获取已存在合同系统中客户名称列表
  69. // @Description 获取合同详情接口
  70. // @Param CompanyName query string true "客户名称"
  71. // @Param Status query string true "合同状态"
  72. // @Success 200 {object} []string
  73. // @router /company_list [get]
  74. func (this *ContractCommon) CompanyList() {
  75. sysUser := this.AdminWx
  76. companyName := this.GetString("CompanyName")
  77. //合同id
  78. if companyName == "" {
  79. this.FailWithMessage("客户名称必传!", "客户名称必传!")
  80. return
  81. }
  82. status := this.GetString("Status")
  83. companyNameList := make([]string, 0)
  84. list, err := contract.GetCompanyNameList(this.AdminWx.AdminId, companyName, status)
  85. if err != nil {
  86. this.FailWithMessage("获取客户名称列表失败!", "获取客户名称列表失败,ERR:"+err.Error())
  87. return
  88. }
  89. for _, v := range list {
  90. companyNameList = append(companyNameList, v.CompanyName)
  91. }
  92. //审批列表中
  93. childCondition := ""
  94. condition := ""
  95. childPars := make([]interface{}, 0)
  96. pars := make([]interface{}, 0)
  97. //归属
  98. if status == "待审批" {
  99. condition += ` AND ((c.seller_id = ? and a.start_node_id = a.curr_node_id) OR (d.approve_user_id = ? )) and d.status="待审批" `
  100. } else {
  101. condition += ` AND (c.seller_id = ? or d.approve_user_id = ?)`
  102. }
  103. condition += `and company_name like '%` + companyName + `%'`
  104. pars = append(pars, sysUser.AdminId, sysUser.AdminId)
  105. list2, err := contract_approval.GetCompanyNameListV2(childCondition, condition, childPars, pars)
  106. if err != nil {
  107. this.FailWithMessage("获取客户名称列表失败!", "获取客户名称列表失败,ERR:"+err.Error())
  108. return
  109. }
  110. for _, v := range list2 {
  111. if !strings.Contains(strings.Join(companyNameList, ","), v.CompanyName) {
  112. companyNameList = append(companyNameList, v.CompanyName)
  113. }
  114. }
  115. this.OkDetailed(companyNameList, "获取成功")
  116. }
  117. // @Title 合同列表
  118. // @Description 合同列表接口
  119. // @Param ContractType query string false "合同类型,枚举值:'新签合同','续约合同','补充协议'"
  120. // @Param Status query string false "合同状态,枚举值:'待提交','待审批','已撤回','已审批','已驳回','已作废'"
  121. // @Param ProductId query int false "客户类型:传0或者不传为当前账号权限,1 代表是:ficc;2 代表是:权益"
  122. // @Param ModifyStartTime query string false "服务更新时间的选择开始时间,格式:2021-05-23 00:00:00"
  123. // @Param ModifyEndTime query string false "服务更新时间的选择结束时间,格式:2021-05-26 23:59:59"
  124. // @Param SellerId query string false "选择的销售id"
  125. // @Param Keyword query string false "搜索关键字"
  126. // @Success 200 {object} contract.ContractListResp
  127. // @router /list [get]
  128. func (this *ContractCommon) List() {
  129. //合同类型、产品类型、合同状态、更新时间、所选销售
  130. //关键字:合同编号、客户名称,社会信用码
  131. contractType := this.GetString("ContractType")
  132. status := this.GetString("Status")
  133. productId, _ := this.GetInt("ProductId")
  134. modifyStartTime := this.GetString("ModifyStartTime")
  135. modifyEndTime := this.GetString("ModifyEndTime")
  136. sellerIds := this.GetString("SellerId")
  137. keyword := this.GetString("Keyword")
  138. condition := ""
  139. pars := make([]interface{}, 0)
  140. //如果不是超管或者合规,那么只能查看自己的合同
  141. condition += ` AND seller_id = ? `
  142. pars = append(pars, this.AdminWx.AdminId)
  143. //合同类型、、更新时间、所选销售
  144. //关键字:合同编号、客户名称,社会信用码
  145. if contractType != "" {
  146. condition += ` AND contract_type = ? `
  147. pars = append(pars, contractType)
  148. }
  149. //合同状态
  150. if status != "" {
  151. condition += ` AND status = ? `
  152. pars = append(pars, status)
  153. }
  154. //产品类型
  155. if productId > 0 {
  156. condition += ` AND product_id = ? `
  157. pars = append(pars, productId)
  158. }
  159. //所选销售
  160. if sellerIds != "" {
  161. condition += ` AND seller_id IN (` + sellerIds + `) `
  162. }
  163. //更新开始时间
  164. if modifyStartTime != "" {
  165. condition += ` AND modify_time >= ? `
  166. pars = append(pars, modifyStartTime)
  167. }
  168. //更新结束时间
  169. if modifyEndTime != "" {
  170. condition += ` AND modify_time <= ? `
  171. pars = append(pars, modifyEndTime)
  172. }
  173. //关键字
  174. if keyword != "" {
  175. condition += ` AND (contract_code LIKE '%` + keyword + `%' OR company_name LIKE '%` + keyword + `%' OR credit_code LIKE '%` + keyword + `%' ) `
  176. }
  177. pageSize, _ := this.GetInt("PageSize")
  178. currentIndex, _ := this.GetInt("CurrentIndex")
  179. var startSize int
  180. if pageSize <= 0 {
  181. pageSize = utils.PageSize20
  182. }
  183. if currentIndex <= 0 {
  184. currentIndex = 1
  185. }
  186. startSize = paging.StartIndex(currentIndex, pageSize)
  187. total, err := contract.GetContractListCount(condition, pars)
  188. if err != nil {
  189. this.FailWithMessage("获取失败", "获取数据总数失败,Err:"+err.Error())
  190. return
  191. }
  192. list, err := contract.GetContractList(condition, pars, startSize, pageSize)
  193. if err != nil {
  194. this.FailWithMessage("获取合同列表失败", "获取合同列表失败,Err:"+err.Error())
  195. return
  196. }
  197. page := paging.GetPaging(currentIndex, pageSize, total)
  198. this.OkDetailed(contractResp.ContractListResp{
  199. List: list,
  200. Paging: page,
  201. }, "获取成功")
  202. }
  203. // @Title 合同列表(包含待提交的)
  204. // @Description 合同列表接口(包含待提交的)
  205. // @Param ContractType query string false "合同类型,枚举值:'新签合同','续约合同','补充协议'"
  206. // @Param Status query string false "合同状态,枚举值:'待提交','待审批','已撤回','已审批','已驳回','已作废'"
  207. // @Param ProductId query int false "客户类型:传0或者不传为当前账号权限,1 代表是:ficc;2 代表是:权益"
  208. // @Param ModifyStartTime query string false "服务更新时间的选择开始时间,格式:2021-05-23 00:00:00"
  209. // @Param ModifyEndTime query string false "服务更新时间的选择结束时间,格式:2021-05-26 23:59:59"
  210. // @Param SellerId query string false "选择的销售id"
  211. // @Param Keyword query string false "搜索关键字"
  212. // @Success 200 {object} contract.ContractListRespV2
  213. // @router /listV2 [get]
  214. func (this *ContractCommon) ListV2() {
  215. sysUser := this.AdminWx
  216. //合同类型、产品类型、合同状态、更新时间、所选销售
  217. //关键字:合同编号、客户名称,社会信用码
  218. contractType := this.GetString("ContractType")
  219. status := this.GetString("Status")
  220. productId, _ := this.GetInt("ProductId")
  221. modifyStartTime := this.GetString("ModifyStartTime")
  222. modifyEndTime := this.GetString("ModifyEndTime")
  223. sellerIds := this.GetString("SellerId")
  224. keyword := this.GetString("Keyword")
  225. childCondition := ""
  226. condition := ""
  227. unionCondition := ""
  228. childPars := make([]interface{}, 0)
  229. pars := make([]interface{}, 0)
  230. unionPars := make([]interface{}, 0)
  231. //归属
  232. if status == "待审批" {
  233. condition += ` AND ((c.seller_id = ? and a.start_node_id = a.curr_node_id) OR (d.approve_user_id = ? )) and d.status="待审批" `
  234. } else {
  235. condition += ` AND (c.seller_id = ? or d.approve_user_id = ?)`
  236. }
  237. pars = append(pars, sysUser.AdminId, sysUser.AdminId)
  238. unionCondition += ` AND c.seller_id = ? `
  239. unionPars = append(unionPars, sysUser.AdminId)
  240. //合同类型、、更新时间、所选销售
  241. //关键字:合同编号、客户名称,社会信用码
  242. if contractType != "" {
  243. condition += ` AND c.contract_type = ? `
  244. pars = append(pars, contractType)
  245. unionCondition += ` AND c.contract_type = ? `
  246. unionPars = append(unionPars, contractType)
  247. }
  248. //审批状态
  249. if status != "" {
  250. if status == "已审批" {
  251. condition += ` AND c.status in ("已审批","已驳回") `
  252. unionCondition += ` AND c.status in ("已审批","已驳回") `
  253. } else {
  254. condition += ` AND c.status = ? `
  255. unionCondition += ` AND c.status = ? `
  256. if status == "处理中" {
  257. pars = append(pars, "待审批")
  258. unionPars = append(unionPars, "待审批")
  259. } else {
  260. pars = append(pars, status)
  261. unionPars = append(unionPars, status)
  262. }
  263. }
  264. } else {
  265. condition += ` AND c.status not in ("已撤回","待提交") `
  266. unionCondition += ` AND c.status = "待提交" `
  267. }
  268. //产品类型
  269. if productId > 0 {
  270. condition += ` AND c.product_id = ? `
  271. pars = append(pars, productId)
  272. unionCondition += ` AND c.product_id = ? `
  273. unionPars = append(unionPars, productId)
  274. }
  275. //所选销售
  276. if sellerIds != "" {
  277. condition += ` AND c.seller_id IN (` + sellerIds + `) `
  278. unionCondition += ` AND c.seller_id IN (` + sellerIds + `) `
  279. }
  280. //更新开始时间
  281. if modifyStartTime != "" {
  282. condition += ` AND a.modify_time >= ? `
  283. pars = append(pars, modifyStartTime)
  284. unionCondition += ` AND a.modify_time >= ? `
  285. unionPars = append(unionPars, modifyStartTime)
  286. }
  287. //更新结束时间
  288. if modifyEndTime != "" {
  289. condition += ` AND a.modify_time <= ? `
  290. pars = append(pars, modifyEndTime)
  291. unionCondition += ` AND a.modify_time <= ? `
  292. unionPars = append(unionPars, modifyEndTime)
  293. }
  294. //关键字
  295. if keyword != "" {
  296. condition += ` AND (c.contract_code LIKE '%` + keyword + `%' OR c.company_name LIKE '%` + keyword + `%' OR c.credit_code LIKE '%` + keyword + `%' ) `
  297. unionCondition += ` AND (c.contract_code LIKE '%` + keyword + `%' OR c.company_name LIKE '%` + keyword + `%' OR c.credit_code LIKE '%` + keyword + `%' ) `
  298. }
  299. pageSize, _ := this.GetInt("PageSize")
  300. currentIndex, _ := this.GetInt("CurrentIndex")
  301. var startSize int
  302. if pageSize <= 0 {
  303. pageSize = utils.PageSize20
  304. }
  305. if currentIndex <= 0 {
  306. currentIndex = 1
  307. }
  308. startSize = paging.StartIndex(currentIndex, pageSize)
  309. joinCondition := " and a.curr_node_id=d.node_id"
  310. total, err := contract_approval.GetContractListCountV2(childCondition, condition, joinCondition, unionCondition, childPars, pars, unionPars)
  311. if err != nil {
  312. this.FailWithMessage("获取失败", "获取数据总数失败,Err:"+err.Error())
  313. return
  314. }
  315. list, err := contract_approval.GetContractListV2(childCondition, condition, joinCondition, unionCondition, childPars, pars, unionPars, startSize, pageSize)
  316. if err != nil {
  317. this.FailWithMessage("获取合同列表失败", "获取合同列表失败,Err:"+err.Error())
  318. return
  319. }
  320. page := paging.GetPaging(currentIndex, pageSize, total)
  321. this.OkDetailed(contractResp.ContractListRespV2{
  322. List: list,
  323. Paging: page,
  324. }, "获取成功")
  325. }
  326. // @Title 作废合同
  327. // @Description 作废合同接口
  328. // @Param request body contract.InvalidReq true "type json string"
  329. // @Success Ret=200 作废成功
  330. // @router /invalid [post]
  331. func (this *ContractCommon) Invalid() {
  332. var req contractReq.InvalidReq
  333. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  334. if err != nil {
  335. this.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error())
  336. return
  337. }
  338. //合同id
  339. if req.ContractId <= 0 {
  340. this.FailWithMessage("合同id必传!", "合同id必传!")
  341. return
  342. }
  343. err = contractService.InvalidContract(req.ContractId, this.AdminWx)
  344. if err != nil {
  345. this.FailWithMessage("作废合同失败!", "作废合同失败,Err:"+err.Error())
  346. return
  347. }
  348. this.OkWithMessage("作废成功")
  349. return
  350. }