contract.go 13 KB

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