seal.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. sealReq "hongze/hongze_mobile_admin/models/request/seal"
  6. sealResp "hongze/hongze_mobile_admin/models/response/seal"
  7. "hongze/hongze_mobile_admin/models/tables/company"
  8. "hongze/hongze_mobile_admin/models/tables/seal"
  9. contractService "hongze/hongze_mobile_admin/services/contract"
  10. sealService "hongze/hongze_mobile_admin/services/seal"
  11. "hongze/hongze_mobile_admin/utils"
  12. "path"
  13. "strconv"
  14. "strings"
  15. )
  16. //SealCommon
  17. //用印模块
  18. type SealCommon struct {
  19. BaseAuth
  20. }
  21. //Add
  22. // @Title 新增用印
  23. // @Description 新增用印接口
  24. // @Param request body seal.AddReq true "type json string"
  25. // @Success Ret=200 新增用印成功
  26. // @router /add [post]
  27. func (c *SealCommon) Add() {
  28. var req sealReq.AddReq
  29. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  30. if err != nil {
  31. c.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error())
  32. return
  33. }
  34. // 参数校验
  35. if req.Use == "" {
  36. c.FailWithMessage("用印用途不能为空", "用印用途不能为空")
  37. return
  38. }
  39. if req.CompanyName == "" {
  40. c.FailWithMessage("客户名称不能为空", "客户名称不能为空")
  41. return
  42. }
  43. if req.CreditCode == "" {
  44. c.FailWithMessage("社会统一信用代码不能为空", "社会统一信用代码不能为空")
  45. return
  46. }
  47. if req.ServiceType == "" {
  48. c.FailWithMessage("合同类型不能为空", "合同类型不能为空")
  49. return
  50. }
  51. if req.SealType == "" {
  52. c.FailWithMessage("印章类型不能为空", "印章类型不能为空")
  53. return
  54. }
  55. if len(req.FileUrls) == 0 {
  56. c.FailWithMessage("合同附件不能为空", "合同附件不能为空")
  57. return
  58. }
  59. if req.AffiliatedCompany == "" {
  60. c.FailWithMessage("归属公司不能为空", "归属公司不能为空")
  61. }
  62. sealInfo, err := sealService.AddSeal(c.AdminWx.AdminId, req.ContractId, req.FileNum, c.AdminWx.RealName, req.Use, req.UseCompanyName, req.CompanyName, req.CreditCode, req.ServiceType, req.SealType, req.Remark, req.FileUrls, req.AffiliatedCompany)
  63. if err != nil {
  64. c.FailWithMessage("用印添加失败", err.Error())
  65. return
  66. }
  67. err = sealService.Apply(sealInfo)
  68. if err != nil {
  69. c.FailWithMessage("发起用印审批失败", "发起用印审批失败,Err:"+err.Error())
  70. return
  71. }
  72. c.OkDetailed(sealResp.AddSealResp{
  73. SealId: sealInfo.SealId,
  74. }, "发起用印审批成功")
  75. }
  76. //Edit
  77. // @Title 编辑用印
  78. // @Description 编辑用印接口
  79. // @Param request body seal.EditReq true "type json string"
  80. // @Success 200 {object} seal.AddSealResp
  81. // @router /edit [post]
  82. func (c *SealCommon) Edit() {
  83. var req sealReq.EditReq
  84. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  85. if err != nil {
  86. c.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error())
  87. return
  88. }
  89. // 参数校验
  90. if req.SealId <= 0 {
  91. c.FailWithMessage("用印编号不能为空", "用印编号不能为空")
  92. return
  93. }
  94. if req.Use == "" {
  95. c.FailWithMessage("用印用途不能为空", "用印用途不能为空")
  96. return
  97. }
  98. if req.CompanyName == "" {
  99. c.FailWithMessage("客户名称不能为空", "客户名称不能为空")
  100. return
  101. }
  102. if req.CreditCode == "" {
  103. c.FailWithMessage("社会统一信用代码不能为空", "社会统一信用代码不能为空")
  104. return
  105. }
  106. if req.ServiceType == "" {
  107. c.FailWithMessage("合同类型不能为空", "合同类型不能为空")
  108. return
  109. }
  110. if req.SealType == "" {
  111. c.FailWithMessage("印章类型不能为空", "印章类型不能为空")
  112. return
  113. }
  114. if len(req.FileUrls) == 0 {
  115. c.FailWithMessage("合同附件不能为空", "合同附件不能为空")
  116. return
  117. }
  118. if req.AffiliatedCompany == "" {
  119. c.FailWithMessage("归属公司不能为空", "归属公司不能为空")
  120. }
  121. sealInfo, err := sealService.Edit(req.SealId, c.AdminWx.AdminId, req.ContractId, req.FileNum, req.Use, req.CompanyName, req.UseCompanyName, req.CreditCode, req.ServiceType, req.SealType, req.Remark, req.FileUrls, c.AdminWx.RealName, req.AffiliatedCompany)
  122. if err != nil {
  123. c.FailWithMessage("修改合同失败!", "修改合同失败,Err:"+err.Error())
  124. return
  125. }
  126. tmpErr := sealService.Apply(sealInfo)
  127. if tmpErr != nil {
  128. c.FailWithMessage("发起重申失败!", "发起重申失败,Err:"+tmpErr.Error())
  129. return
  130. }
  131. c.OkDetailed(sealResp.AddSealResp{
  132. SealId: sealInfo.SealId,
  133. }, "发起重申成功")
  134. }
  135. //CheckEdit
  136. // @Title 审批者编辑用印
  137. // @Description 审批者编辑用印接口
  138. // @Param request body seal.CheckEditReq true "type json string"
  139. // @Success 200 {object} seal.AddSealResp
  140. // @router /check_edit [post]
  141. func (c *SealCommon) CheckEdit() {
  142. var req sealReq.CheckEditReq
  143. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  144. if err != nil {
  145. c.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error())
  146. return
  147. }
  148. // 参数校验
  149. sealId := req.SealId
  150. if sealId <= 0 {
  151. c.FailWithMessage("用印编号不能为空", "用印编号不能为空")
  152. return
  153. }
  154. if req.Use == "" {
  155. c.FailWithMessage("用印用途不能为空", "用印用途不能为空")
  156. return
  157. }
  158. if req.SealType == "" {
  159. c.FailWithMessage("印章类型不能为空", "印章类型不能为空")
  160. return
  161. }
  162. if len(req.FileUrls) == 0 {
  163. c.FailWithMessage("合同附件不能为空", "合同附件不能为空")
  164. return
  165. }
  166. if req.AffiliatedCompany == "" {
  167. c.FailWithMessage("归属公司不能为空", "归属公司不能为空")
  168. }
  169. //数据校验(校验是否具有审批权限)
  170. sealInfo, approvalInfo, approvalRecord, err := sealService.CheckApproveAuth(sealId, c.AdminWx)
  171. //合规修改
  172. err = sealService.CheckEdit(sealInfo, approvalInfo, approvalRecord, req.FileNum, req.FileUrls, req.Use, req.SealType, req.Remark, req.AffiliatedCompany, c.AdminWx)
  173. if err != nil {
  174. c.FailWithMessage("修改合同失败!", "修改合同失败,Err:"+err.Error())
  175. return
  176. }
  177. c.OkDetailed(sealResp.AddSealResp{
  178. SealId: sealInfo.SealId,
  179. }, "修改合同成功")
  180. }
  181. // List
  182. // @Title 用印列表
  183. // @Description 用印列表接口
  184. // @Param Status query string false "合同状态,枚举值:'待提交','待审批','已撤回','已审批','已驳回','已作废','已签回'"
  185. // @Param ProductId query int false "客户类型:传0或者不传为当前账号权限,1 代表是:ficc;2 代表是:权益"
  186. // @Param ModifyStartTime query string false "服务更新时间的选择开始时间,格式:2021-05-23 00:00:00"
  187. // @Param ModifyEndTime query string false "服务更新时间的选择结束时间,格式:2021-05-26 23:59:59"
  188. // @Param AdminId query string false "选择的用户id"
  189. // @Param Keyword query string false "搜索关键字"
  190. // @Param KeywordEq query string false "搜索关键字(全匹配搜索)"
  191. // @Success 200 {object} contract.ContractListResp
  192. // @router /list [get]
  193. func (c *SealCommon) List() {
  194. //合同类型、产品类型、合同状态、更新时间、所选销售
  195. //关键字:合同编号、客户名称,社会信用码
  196. status := c.GetString("Status")
  197. productId, _ := c.GetInt("ProductId")
  198. modifyStartTime := c.GetString("ModifyStartTime")
  199. modifyEndTime := c.GetString("ModifyEndTime")
  200. adminIds := c.GetString("AdminId")
  201. keyword := c.GetString("Keyword")
  202. keywordEq := c.GetString("KeywordEq")
  203. affiliatedCompany := c.GetString("AffiliatedCompany")
  204. condition := ""
  205. pars := make([]interface{}, 0)
  206. //合同类型、、更新时间、所选销售
  207. //关键字:合同编号、客户名称,社会信用码
  208. //合同状态
  209. if status != "" {
  210. condition += ` AND status = ? `
  211. pars = append(pars, status)
  212. }
  213. //产品类型
  214. if productId > 0 {
  215. condition += ` AND product_id = ? `
  216. pars = append(pars, productId)
  217. }
  218. //所选销售
  219. if adminIds != "" {
  220. condition += ` AND user_id IN (` + adminIds + `) `
  221. } else {
  222. condition += ` AND user_id =?`
  223. pars = append(pars, c.AdminWx.AdminId)
  224. }
  225. //更新开始时间
  226. if modifyStartTime != "" {
  227. condition += ` AND modify_time >= ? `
  228. pars = append(pars, modifyStartTime)
  229. }
  230. //更新结束时间
  231. if modifyEndTime != "" {
  232. condition += ` AND modify_time <= ? `
  233. pars = append(pars, modifyEndTime)
  234. }
  235. //关键字
  236. if keyword != "" {
  237. condition += ` AND (code LIKE '%` + keyword + `%' OR company_name LIKE '%` + keyword + `%' OR credit_code LIKE '%` + keyword + `%' ) `
  238. }
  239. //关键字(全等)
  240. if keywordEq != "" {
  241. condition += ` AND (c.use_company_name =? OR c.company_name =?) `
  242. pars = append(pars, keywordEq, keywordEq)
  243. }
  244. // 归属公司
  245. if affiliatedCompany != "" {
  246. condition += ` AND affiliated_company =? `
  247. pars = append(pars, affiliatedCompany)
  248. }
  249. pageSize, _ := c.GetInt("PageSize")
  250. currentIndex, _ := c.GetInt("CurrentIndex")
  251. var startSize int
  252. if pageSize <= 0 {
  253. pageSize = utils.PageSize20
  254. }
  255. if currentIndex <= 0 {
  256. currentIndex = 1
  257. }
  258. startSize = paging.StartIndex(currentIndex, pageSize)
  259. total, err := seal.GetListCount(condition, pars)
  260. if err != nil {
  261. c.FailWithMessage("获取失败", "获取数据总数失败,Err:"+err.Error())
  262. return
  263. }
  264. list, err := seal.GetList(condition, pars, startSize, pageSize)
  265. if err != nil {
  266. c.FailWithMessage("获取合同列表失败", "获取合同列表失败,Err:"+err.Error())
  267. return
  268. }
  269. page := paging.GetPaging(currentIndex, pageSize, total)
  270. c.OkDetailed(sealResp.RespSealList{
  271. List: list,
  272. Paging: page,
  273. }, "获取成功")
  274. }
  275. //Detail
  276. // @Title 获取用印详情
  277. // @Description 获取用印详情接口
  278. // @Param SealId query int true "用印id"
  279. // @Success 200 {object} seal.SealDetailResp
  280. // @router /detail [get]
  281. func (c *SealCommon) Detail() {
  282. //合同类型、产品类型、合同状态、更新时间、所选销售
  283. //关键字:合同编号、客户名称,社会信用码
  284. sealId, _ := c.GetInt("SealId")
  285. //用印id
  286. if sealId <= 0 {
  287. c.FailWithMessage("用印id必传!", "用印id必传!")
  288. return
  289. }
  290. sealInfo, flowNodeListResp, opButton, err := sealService.GetSealDetailBySealId(sealId, c.AdminWx)
  291. if err != nil {
  292. c.FailWithMessage("获取详情失败", "获取详情失败,Err:"+err.Error())
  293. return
  294. }
  295. resp := sealResp.SealDetailResp{
  296. SealDetail: sealInfo,
  297. FlowNodeList: flowNodeListResp,
  298. OpButton: opButton,
  299. }
  300. c.OkDetailed(resp, "获取成功")
  301. }
  302. //Invalid
  303. // @Title 作废合同
  304. // @Description 作废合同接口
  305. // @Param request body seal.InvalidReq true "type json string"
  306. // @Success Ret=200 作废成功
  307. // @router /invalid [post]
  308. func (c *SealCommon) Invalid() {
  309. var req sealReq.InvalidReq
  310. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  311. if err != nil {
  312. c.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error())
  313. return
  314. }
  315. //用印id
  316. if req.SealId <= 0 {
  317. c.FailWithMessage("用印id必传!", "用印id必传!")
  318. return
  319. }
  320. err = sealService.Invalid(req.SealId, c.AdminWx, req.IsInvalidContract)
  321. if err != nil {
  322. c.FailWithMessage("作废用印失败!", "作废用印失败,Err:"+err.Error())
  323. return
  324. }
  325. c.OkWithMessage("作废成功")
  326. return
  327. }
  328. // UploadCheckBackFile
  329. // @Title 上传签回附件
  330. // @Description 上传签回附件接口
  331. // @Param request body seal.UploadCheckBackFileReq true "type json string"
  332. // @Success Ret=200 上传成功
  333. // @router /upload_check_back_file [post]
  334. func (c *SealCommon) UploadCheckBackFile() {
  335. //var req sealReq.UploadCheckBackFileReq
  336. //err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  337. //if err != nil {
  338. // c.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error())
  339. // return
  340. //}
  341. ////用印编号
  342. //if req.SealId <= 0 {
  343. // c.FailWithMessage("请传入用印编号!", "请传入用印编号")
  344. // return
  345. //}
  346. //
  347. //if req.FileUrl == "" {
  348. // c.FailWithMessage("请先上传附件!", "请先上传附件")
  349. // return
  350. //}
  351. sealIdStr := c.Ctx.Request.Form.Get("SealId")
  352. if sealIdStr == "" {
  353. c.FailWithMessage("用印ID必传!", "用印ID必传")
  354. return
  355. }
  356. sealId, err := strconv.Atoi(sealIdStr)
  357. if err != nil {
  358. c.FailWithMessage("用印ID异常!", "用印ID必传")
  359. return
  360. }
  361. //合同编号
  362. if sealId <= 0 {
  363. c.FailWithMessage("请传入用印编号", "请传入用印编号")
  364. return
  365. }
  366. fileMulti, h, err := c.GetFile("file")
  367. if err != nil {
  368. c.FailWithMessage("获取资源信息失败", "获取资源信息失败,Err:"+err.Error())
  369. return
  370. }
  371. ext := path.Ext(h.Filename)
  372. //sealInfo, err := sealService.UploadCheckBackFile(req.SealId, req.FileUrl, c.AdminWx)
  373. sealInfo, err := sealService.UploadCheckBackFileByFile(sealId, ext, fileMulti, c.AdminWx)
  374. if err != nil {
  375. c.FailWithMessage("更新签回附件失败!", "更新签回附件失败,Err:"+err.Error())
  376. return
  377. }
  378. //如果是系统合同,那么需要去更新系统的签回附件
  379. if sealInfo.ContractId > 0 {
  380. _ = contractService.UploadCheckBackFile(sealInfo.ContractId, sealInfo.CheckBackFileUrl, c.AdminWx)
  381. }
  382. c.OkWithMessage("上传成功")
  383. }
  384. //CompanyList
  385. // @Title 根据客户名称获取已存在系统中客户名称列表
  386. // @Description 获取合同详情接口
  387. // @Param Keyword query string true "关键字:客户名称、组织社会信用码"
  388. // @Success 200 {object} []string
  389. // @router /company_list [get]
  390. func (c *SealCommon) CompanyList() {
  391. sysUser := c.AdminWx
  392. keyword := c.GetString("Keyword")
  393. //合同id
  394. if keyword == "" {
  395. c.FailWithMessage("搜索关键字必传!", "搜索关键字必传!")
  396. return
  397. }
  398. companyNameList := make([]string, 0)
  399. childCondition := ""
  400. condition := ""
  401. childPars := make([]interface{}, 0)
  402. pars := make([]interface{}, 0)
  403. //归属
  404. condition += ` AND (c.user_id = ? or (d.approve_user_id = ? and d.node_id <= a.curr_node_id))`
  405. pars = append(pars, sysUser.AdminId, sysUser.AdminId)
  406. condition += ` AND (c.company_name like "%` + keyword + `%" or c.credit_code like "%` + keyword + `%")`
  407. list, err := seal.GetCompanyNameListV2(childCondition, condition, childPars, pars)
  408. if err != nil {
  409. c.FailWithMessage("获取客户名称列表失败!", "获取客户名称列表失败,ERR:"+err.Error())
  410. return
  411. }
  412. for _, v := range list {
  413. companyNameList = append(companyNameList, v.CompanyName)
  414. }
  415. c.OkDetailed(companyNameList, "获取成功")
  416. }
  417. // CompanyNameList
  418. // @Title 根据客户名称关键词获取系统中的客户名称列表
  419. // @Description 获取客户名称列表
  420. // @Param Keyword query string true "客户名称关键词"
  421. // @Param PageSize query int true "每页数据量"
  422. // @Param CurrentIndex query int true "页码"
  423. // @Success 200 {object} []company.CompanyNameList
  424. // @router /company_name_list [get]
  425. func (c *SealCommon) CompanyNameList() {
  426. keyword := c.GetString("Keyword")
  427. pageSize, _ := c.GetInt("PageSize")
  428. currentIndex, _ := c.GetInt("CurrentIndex")
  429. if keyword == "" {
  430. c.FailWithMessage("关键词不能为空", "关键词不能为空")
  431. return
  432. }
  433. var startSize int
  434. if pageSize <= 0 {
  435. pageSize = utils.PageSize20
  436. }
  437. if currentIndex <= 0 {
  438. currentIndex = 1
  439. }
  440. startSize = paging.StartIndex(currentIndex, pageSize)
  441. keyword = "%" + keyword + "%"
  442. condition := " AND company_name LIKE ? "
  443. pars := make([]interface{}, 0)
  444. pars = append(pars, keyword)
  445. list, err := company.GetCompanyNameList(condition, pars, startSize, pageSize)
  446. if err != nil {
  447. c.FailWithMessage("获取客户名称列表失败!", "获取客户名称列表失败,ERR:"+err.Error())
  448. return
  449. }
  450. c.OkDetailed(list, "获取成功")
  451. }
  452. // 关联公司列表
  453. // @Title 关联公司列表
  454. // @Description 关联公司列表
  455. // @Success 200 {object} response.SealApprovalListResp
  456. // @router /getAffiliatedCompany [get]
  457. func (c *SealCommon) AffiliatedCompanyList() {
  458. crmConfig, err := company.GetConfigDetailByCode("affiliated_company")
  459. if err != nil {
  460. c.FailWithMessage( "获取配置失败!", "获取配置失败,Err:"+err.Error())
  461. return
  462. }
  463. list := strings.Split(crmConfig.ConfigValue, ",")
  464. c.OkDetailed(list, "获取成功")
  465. }