contract.go 17 KB

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