seal.go 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  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. //数据校验(校验是否具有审批权限)
  167. sealInfo, approvalInfo, approvalRecord, err := sealService.CheckApproveAuth(sealId, c.AdminWx)
  168. //合规修改
  169. err = sealService.CheckEdit(sealInfo, approvalInfo, approvalRecord, req.FileNum, req.FileUrls, req.Use, req.SealType, req.Remark, c.AdminWx)
  170. if err != nil {
  171. c.FailWithMessage("修改合同失败!", "修改合同失败,Err:"+err.Error())
  172. return
  173. }
  174. c.OkDetailed(sealResp.AddSealResp{
  175. SealId: sealInfo.SealId,
  176. }, "修改合同成功")
  177. }
  178. // List
  179. // @Title 用印列表
  180. // @Description 用印列表接口
  181. // @Param Status query string false "合同状态,枚举值:'待提交','待审批','已撤回','已审批','已驳回','已作废','已签回'"
  182. // @Param ProductId query int false "客户类型:传0或者不传为当前账号权限,1 代表是:ficc;2 代表是:权益"
  183. // @Param ModifyStartTime query string false "服务更新时间的选择开始时间,格式:2021-05-23 00:00:00"
  184. // @Param ModifyEndTime query string false "服务更新时间的选择结束时间,格式:2021-05-26 23:59:59"
  185. // @Param AdminId query string false "选择的用户id"
  186. // @Param Keyword query string false "搜索关键字"
  187. // @Param KeywordEq query string false "搜索关键字(全匹配搜索)"
  188. // @Success 200 {object} contract.ContractListResp
  189. // @router /list [get]
  190. func (c *SealCommon) List() {
  191. //合同类型、产品类型、合同状态、更新时间、所选销售
  192. //关键字:合同编号、客户名称,社会信用码
  193. status := c.GetString("Status")
  194. productId, _ := c.GetInt("ProductId")
  195. modifyStartTime := c.GetString("ModifyStartTime")
  196. modifyEndTime := c.GetString("ModifyEndTime")
  197. adminIds := c.GetString("AdminId")
  198. keyword := c.GetString("Keyword")
  199. keywordEq := c.GetString("KeywordEq")
  200. affiliatedCompany := c.GetString("AffiliatedCompany")
  201. condition := ""
  202. pars := make([]interface{}, 0)
  203. //合同类型、、更新时间、所选销售
  204. //关键字:合同编号、客户名称,社会信用码
  205. //合同状态
  206. if status != "" {
  207. condition += ` AND status = ? `
  208. pars = append(pars, status)
  209. }
  210. //产品类型
  211. if productId > 0 {
  212. condition += ` AND product_id = ? `
  213. pars = append(pars, productId)
  214. }
  215. //所选销售
  216. if adminIds != "" {
  217. condition += ` AND user_id IN (` + adminIds + `) `
  218. } else {
  219. condition += ` AND user_id =?`
  220. pars = append(pars, c.AdminWx.AdminId)
  221. }
  222. //更新开始时间
  223. if modifyStartTime != "" {
  224. condition += ` AND modify_time >= ? `
  225. pars = append(pars, modifyStartTime)
  226. }
  227. //更新结束时间
  228. if modifyEndTime != "" {
  229. condition += ` AND modify_time <= ? `
  230. pars = append(pars, modifyEndTime)
  231. }
  232. //关键字
  233. if keyword != "" {
  234. condition += ` AND (code LIKE '%` + keyword + `%' OR company_name LIKE '%` + keyword + `%' OR credit_code LIKE '%` + keyword + `%' ) `
  235. }
  236. //关键字(全等)
  237. if keywordEq != "" {
  238. condition += ` AND (c.use_company_name =? OR c.company_name =?) `
  239. pars = append(pars, keywordEq, keywordEq)
  240. }
  241. // 归属公司
  242. if affiliatedCompany != "" {
  243. condition += ` AND affiliated_company =? `
  244. pars = append(pars, affiliatedCompany)
  245. }
  246. pageSize, _ := c.GetInt("PageSize")
  247. currentIndex, _ := c.GetInt("CurrentIndex")
  248. var startSize int
  249. if pageSize <= 0 {
  250. pageSize = utils.PageSize20
  251. }
  252. if currentIndex <= 0 {
  253. currentIndex = 1
  254. }
  255. startSize = paging.StartIndex(currentIndex, pageSize)
  256. total, err := seal.GetListCount(condition, pars)
  257. if err != nil {
  258. c.FailWithMessage("获取失败", "获取数据总数失败,Err:"+err.Error())
  259. return
  260. }
  261. list, err := seal.GetList(condition, pars, startSize, pageSize)
  262. if err != nil {
  263. c.FailWithMessage("获取合同列表失败", "获取合同列表失败,Err:"+err.Error())
  264. return
  265. }
  266. page := paging.GetPaging(currentIndex, pageSize, total)
  267. c.OkDetailed(sealResp.RespSealList{
  268. List: list,
  269. Paging: page,
  270. }, "获取成功")
  271. }
  272. //Detail
  273. // @Title 获取用印详情
  274. // @Description 获取用印详情接口
  275. // @Param SealId query int true "用印id"
  276. // @Success 200 {object} seal.SealDetailResp
  277. // @router /detail [get]
  278. func (c *SealCommon) Detail() {
  279. //合同类型、产品类型、合同状态、更新时间、所选销售
  280. //关键字:合同编号、客户名称,社会信用码
  281. sealId, _ := c.GetInt("SealId")
  282. //用印id
  283. if sealId <= 0 {
  284. c.FailWithMessage("用印id必传!", "用印id必传!")
  285. return
  286. }
  287. sealInfo, flowNodeListResp, opButton, err := sealService.GetSealDetailBySealId(sealId, c.AdminWx)
  288. if err != nil {
  289. c.FailWithMessage("获取详情失败", "获取详情失败,Err:"+err.Error())
  290. return
  291. }
  292. resp := sealResp.SealDetailResp{
  293. SealDetail: sealInfo,
  294. FlowNodeList: flowNodeListResp,
  295. OpButton: opButton,
  296. }
  297. c.OkDetailed(resp, "获取成功")
  298. }
  299. //Invalid
  300. // @Title 作废合同
  301. // @Description 作废合同接口
  302. // @Param request body seal.InvalidReq true "type json string"
  303. // @Success Ret=200 作废成功
  304. // @router /invalid [post]
  305. func (c *SealCommon) Invalid() {
  306. var req sealReq.InvalidReq
  307. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  308. if err != nil {
  309. c.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error())
  310. return
  311. }
  312. //用印id
  313. if req.SealId <= 0 {
  314. c.FailWithMessage("用印id必传!", "用印id必传!")
  315. return
  316. }
  317. err = sealService.Invalid(req.SealId, c.AdminWx, req.IsInvalidContract)
  318. if err != nil {
  319. c.FailWithMessage("作废用印失败!", "作废用印失败,Err:"+err.Error())
  320. return
  321. }
  322. c.OkWithMessage("作废成功")
  323. return
  324. }
  325. // UploadCheckBackFile
  326. // @Title 上传签回附件
  327. // @Description 上传签回附件接口
  328. // @Param request body seal.UploadCheckBackFileReq true "type json string"
  329. // @Success Ret=200 上传成功
  330. // @router /upload_check_back_file [post]
  331. func (c *SealCommon) UploadCheckBackFile() {
  332. //var req sealReq.UploadCheckBackFileReq
  333. //err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  334. //if err != nil {
  335. // c.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error())
  336. // return
  337. //}
  338. ////用印编号
  339. //if req.SealId <= 0 {
  340. // c.FailWithMessage("请传入用印编号!", "请传入用印编号")
  341. // return
  342. //}
  343. //
  344. //if req.FileUrl == "" {
  345. // c.FailWithMessage("请先上传附件!", "请先上传附件")
  346. // return
  347. //}
  348. sealIdStr := c.Ctx.Request.Form.Get("SealId")
  349. if sealIdStr == "" {
  350. c.FailWithMessage("用印ID必传!", "用印ID必传")
  351. return
  352. }
  353. sealId, err := strconv.Atoi(sealIdStr)
  354. if err != nil {
  355. c.FailWithMessage("用印ID异常!", "用印ID必传")
  356. return
  357. }
  358. //合同编号
  359. if sealId <= 0 {
  360. c.FailWithMessage("请传入用印编号", "请传入用印编号")
  361. return
  362. }
  363. fileMulti, h, err := c.GetFile("file")
  364. if err != nil {
  365. c.FailWithMessage("获取资源信息失败", "获取资源信息失败,Err:"+err.Error())
  366. return
  367. }
  368. ext := path.Ext(h.Filename)
  369. //sealInfo, err := sealService.UploadCheckBackFile(req.SealId, req.FileUrl, c.AdminWx)
  370. sealInfo, err := sealService.UploadCheckBackFileByFile(sealId, ext, fileMulti, c.AdminWx)
  371. if err != nil {
  372. c.FailWithMessage("更新签回附件失败!", "更新签回附件失败,Err:"+err.Error())
  373. return
  374. }
  375. //如果是系统合同,那么需要去更新系统的签回附件
  376. if sealInfo.ContractId > 0 {
  377. _ = contractService.UploadCheckBackFile(sealInfo.ContractId, sealInfo.CheckBackFileUrl, c.AdminWx)
  378. }
  379. c.OkWithMessage("上传成功")
  380. }
  381. //CompanyList
  382. // @Title 根据客户名称获取已存在系统中客户名称列表
  383. // @Description 获取合同详情接口
  384. // @Param Keyword query string true "关键字:客户名称、组织社会信用码"
  385. // @Success 200 {object} []string
  386. // @router /company_list [get]
  387. func (c *SealCommon) CompanyList() {
  388. sysUser := c.AdminWx
  389. keyword := c.GetString("Keyword")
  390. //合同id
  391. if keyword == "" {
  392. c.FailWithMessage("搜索关键字必传!", "搜索关键字必传!")
  393. return
  394. }
  395. companyNameList := make([]string, 0)
  396. childCondition := ""
  397. condition := ""
  398. childPars := make([]interface{}, 0)
  399. pars := make([]interface{}, 0)
  400. //归属
  401. condition += ` AND (c.user_id = ? or (d.approve_user_id = ? and d.node_id <= a.curr_node_id))`
  402. pars = append(pars, sysUser.AdminId, sysUser.AdminId)
  403. condition += ` AND (c.company_name like "%` + keyword + `%" or c.credit_code like "%` + keyword + `%")`
  404. list, err := seal.GetCompanyNameListV2(childCondition, condition, childPars, pars)
  405. if err != nil {
  406. c.FailWithMessage("获取客户名称列表失败!", "获取客户名称列表失败,ERR:"+err.Error())
  407. return
  408. }
  409. for _, v := range list {
  410. companyNameList = append(companyNameList, v.CompanyName)
  411. }
  412. c.OkDetailed(companyNameList, "获取成功")
  413. }
  414. // CompanyNameList
  415. // @Title 根据客户名称关键词获取系统中的客户名称列表
  416. // @Description 获取客户名称列表
  417. // @Param Keyword query string true "客户名称关键词"
  418. // @Param PageSize query int true "每页数据量"
  419. // @Param CurrentIndex query int true "页码"
  420. // @Success 200 {object} []company.CompanyNameList
  421. // @router /company_name_list [get]
  422. func (c *SealCommon) CompanyNameList() {
  423. keyword := c.GetString("Keyword")
  424. pageSize, _ := c.GetInt("PageSize")
  425. currentIndex, _ := c.GetInt("CurrentIndex")
  426. if keyword == "" {
  427. c.FailWithMessage("关键词不能为空", "关键词不能为空")
  428. return
  429. }
  430. var startSize int
  431. if pageSize <= 0 {
  432. pageSize = utils.PageSize20
  433. }
  434. if currentIndex <= 0 {
  435. currentIndex = 1
  436. }
  437. startSize = paging.StartIndex(currentIndex, pageSize)
  438. keyword = "%" + keyword + "%"
  439. condition := " AND company_name LIKE ? "
  440. pars := make([]interface{}, 0)
  441. pars = append(pars, keyword)
  442. list, err := company.GetCompanyNameList(condition, pars, startSize, pageSize)
  443. if err != nil {
  444. c.FailWithMessage("获取客户名称列表失败!", "获取客户名称列表失败,ERR:"+err.Error())
  445. return
  446. }
  447. c.OkDetailed(list, "获取成功")
  448. }
  449. // 关联公司列表
  450. // @Title 关联公司列表
  451. // @Description 关联公司列表
  452. // @Success 200 {object} response.SealApprovalListResp
  453. // @router /getAffiliatedCompany [get]
  454. func (c *SealCommon) AffiliatedCompanyList() {
  455. crmConfig, err := company.GetConfigDetailByCode("affiliated_company")
  456. if err != nil {
  457. c.FailWithMessage( "获取配置失败!", "获取配置失败,Err:"+err.Error())
  458. return
  459. }
  460. list := strings.Split(crmConfig.ConfigValue, ",")
  461. c.OkDetailed(list, "获取成功")
  462. }