123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477 |
- package controllers
- import (
- "encoding/json"
- "github.com/rdlucklib/rdluck_tools/paging"
- sealReq "hongze/hongze_mobile_admin/models/request/seal"
- sealResp "hongze/hongze_mobile_admin/models/response/seal"
- "hongze/hongze_mobile_admin/models/tables/company"
- "hongze/hongze_mobile_admin/models/tables/seal"
- contractService "hongze/hongze_mobile_admin/services/contract"
- sealService "hongze/hongze_mobile_admin/services/seal"
- "hongze/hongze_mobile_admin/utils"
- "path"
- "strconv"
- )
- type SealCommon struct {
- BaseAuth
- }
- func (c *SealCommon) Add() {
- var req sealReq.AddReq
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
- if err != nil {
- c.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error())
- return
- }
-
- if req.Use == "" {
- c.FailWithMessage("用印用途不能为空", "用印用途不能为空")
- return
- }
- if req.CompanyName == "" {
- c.FailWithMessage("客户名称不能为空", "客户名称不能为空")
- return
- }
- if req.CreditCode == "" {
- c.FailWithMessage("社会统一信用代码不能为空", "社会统一信用代码不能为空")
- return
- }
- if req.ServiceType == "" {
- c.FailWithMessage("合同类型不能为空", "合同类型不能为空")
- return
- }
- if req.SealType == "" {
- c.FailWithMessage("印章类型不能为空", "印章类型不能为空")
- return
- }
- if len(req.FileUrls) == 0 {
- c.FailWithMessage("合同附件不能为空", "合同附件不能为空")
- return
- }
- 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)
- if err != nil {
- c.FailWithMessage("用印添加失败", err.Error())
- return
- }
- err = sealService.Apply(sealInfo)
- if err != nil {
- c.FailWithMessage("发起用印审批失败", "发起用印审批失败,Err:"+err.Error())
- return
- }
- c.OkDetailed(sealResp.AddSealResp{
- SealId: sealInfo.SealId,
- }, "发起用印审批成功")
- }
- func (c *SealCommon) Edit() {
- var req sealReq.EditReq
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
- if err != nil {
- c.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error())
- return
- }
-
- if req.SealId <= 0 {
- c.FailWithMessage("用印编号不能为空", "用印编号不能为空")
- return
- }
- if req.Use == "" {
- c.FailWithMessage("用印用途不能为空", "用印用途不能为空")
- return
- }
- if req.CompanyName == "" {
- c.FailWithMessage("客户名称不能为空", "客户名称不能为空")
- return
- }
- if req.CreditCode == "" {
- c.FailWithMessage("社会统一信用代码不能为空", "社会统一信用代码不能为空")
- return
- }
- if req.ServiceType == "" {
- c.FailWithMessage("合同类型不能为空", "合同类型不能为空")
- return
- }
- if req.SealType == "" {
- c.FailWithMessage("印章类型不能为空", "印章类型不能为空")
- return
- }
- if len(req.FileUrls) == 0 {
- c.FailWithMessage("合同附件不能为空", "合同附件不能为空")
- return
- }
- 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)
- if err != nil {
- c.FailWithMessage("修改合同失败!", "修改合同失败,Err:"+err.Error())
- return
- }
- tmpErr := sealService.Apply(sealInfo)
- if tmpErr != nil {
- c.FailWithMessage("发起重申失败!", "发起重申失败,Err:"+tmpErr.Error())
- return
- }
- c.OkDetailed(sealResp.AddSealResp{
- SealId: sealInfo.SealId,
- }, "发起重申成功")
- }
- func (c *SealCommon) CheckEdit() {
- var req sealReq.CheckEditReq
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
- if err != nil {
- c.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error())
- return
- }
-
- sealId := req.SealId
- if sealId <= 0 {
- c.FailWithMessage("用印编号不能为空", "用印编号不能为空")
- return
- }
- if req.Use == "" {
- c.FailWithMessage("用印用途不能为空", "用印用途不能为空")
- return
- }
- if req.SealType == "" {
- c.FailWithMessage("印章类型不能为空", "印章类型不能为空")
- return
- }
- if len(req.FileUrls) == 0 {
- c.FailWithMessage("合同附件不能为空", "合同附件不能为空")
- return
- }
-
- sealInfo, approvalInfo, approvalRecord, err := sealService.CheckApproveAuth(sealId, c.AdminWx)
-
- err = sealService.CheckEdit(sealInfo, approvalInfo, approvalRecord, req.FileNum, req.FileUrls, req.Use, req.SealType, req.Remark, c.AdminWx)
- if err != nil {
- c.FailWithMessage("修改合同失败!", "修改合同失败,Err:"+err.Error())
- return
- }
- c.OkDetailed(sealResp.AddSealResp{
- SealId: sealInfo.SealId,
- }, "修改合同成功")
- }
- func (c *SealCommon) List() {
-
-
- status := c.GetString("Status")
- productId, _ := c.GetInt("ProductId")
- modifyStartTime := c.GetString("ModifyStartTime")
- modifyEndTime := c.GetString("ModifyEndTime")
- adminIds := c.GetString("AdminId")
- keyword := c.GetString("Keyword")
- keywordEq := c.GetString("KeywordEq")
- condition := ""
- pars := make([]interface{}, 0)
-
-
-
- if status != "" {
- condition += ` AND status = ? `
- pars = append(pars, status)
- }
-
- if productId > 0 {
- condition += ` AND product_id = ? `
- pars = append(pars, productId)
- }
-
- if adminIds != "" {
- condition += ` AND user_id IN (` + adminIds + `) `
- } else {
- condition += ` AND user_id =?`
- pars = append(pars, c.AdminWx.AdminId)
- }
-
- if modifyStartTime != "" {
- condition += ` AND modify_time >= ? `
- pars = append(pars, modifyStartTime)
- }
-
- if modifyEndTime != "" {
- condition += ` AND modify_time <= ? `
- pars = append(pars, modifyEndTime)
- }
-
- if keyword != "" {
- condition += ` AND (code LIKE '%` + keyword + `%' OR company_name LIKE '%` + keyword + `%' OR credit_code LIKE '%` + keyword + `%' ) `
- }
-
- if keywordEq != "" {
- condition += ` AND (c.use_company_name =? OR c.company_name =?) `
- pars = append(pars, keywordEq, keywordEq)
- }
- pageSize, _ := c.GetInt("PageSize")
- currentIndex, _ := c.GetInt("CurrentIndex")
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- total, err := seal.GetListCount(condition, pars)
- if err != nil {
- c.FailWithMessage("获取失败", "获取数据总数失败,Err:"+err.Error())
- return
- }
- list, err := seal.GetList(condition, pars, startSize, pageSize)
- if err != nil {
- c.FailWithMessage("获取合同列表失败", "获取合同列表失败,Err:"+err.Error())
- return
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- c.OkDetailed(sealResp.RespSealList{
- List: list,
- Paging: page,
- }, "获取成功")
- }
- func (c *SealCommon) Detail() {
-
-
- sealId, _ := c.GetInt("SealId")
-
- if sealId <= 0 {
- c.FailWithMessage("用印id必传!", "用印id必传!")
- return
- }
- sealInfo, flowNodeListResp, opButton, err := sealService.GetSealDetailBySealId(sealId, c.AdminWx)
- if err != nil {
- c.FailWithMessage("获取详情失败", "获取详情失败,Err:"+err.Error())
- return
- }
- resp := sealResp.SealDetailResp{
- SealDetail: sealInfo,
- FlowNodeList: flowNodeListResp,
- OpButton: opButton,
- }
- c.OkDetailed(resp, "获取成功")
- }
- func (c *SealCommon) Invalid() {
- var req sealReq.InvalidReq
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
- if err != nil {
- c.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error())
- return
- }
-
- if req.SealId <= 0 {
- c.FailWithMessage("用印id必传!", "用印id必传!")
- return
- }
- err = sealService.Invalid(req.SealId, c.AdminWx, req.IsInvalidContract)
- if err != nil {
- c.FailWithMessage("作废用印失败!", "作废用印失败,Err:"+err.Error())
- return
- }
- c.OkWithMessage("作废成功")
- return
- }
- func (c *SealCommon) UploadCheckBackFile() {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- sealIdStr := c.Ctx.Request.Form.Get("SealId")
- if sealIdStr == "" {
- c.FailWithMessage("用印ID必传!", "用印ID必传")
- return
- }
- sealId, err := strconv.Atoi(sealIdStr)
- if err != nil {
- c.FailWithMessage("用印ID异常!", "用印ID必传")
- return
- }
-
- if sealId <= 0 {
- c.FailWithMessage("请传入用印编号", "请传入用印编号")
- return
- }
- fileMulti, h, err := c.GetFile("file")
- if err != nil {
- c.FailWithMessage("获取资源信息失败", "获取资源信息失败,Err:"+err.Error())
- return
- }
- ext := path.Ext(h.Filename)
-
- sealInfo, err := sealService.UploadCheckBackFileByFile(sealId, ext, fileMulti, c.AdminWx)
- if err != nil {
- c.FailWithMessage("更新签回附件失败!", "更新签回附件失败,Err:"+err.Error())
- return
- }
-
- if sealInfo.ContractId > 0 {
- _ = contractService.UploadCheckBackFile(sealInfo.ContractId, sealInfo.CheckBackFileUrl, c.AdminWx)
- }
- c.OkWithMessage("上传成功")
- }
- func (c *SealCommon) CompanyList() {
- sysUser := c.AdminWx
- keyword := c.GetString("Keyword")
-
- if keyword == "" {
- c.FailWithMessage("搜索关键字必传!", "搜索关键字必传!")
- return
- }
- companyNameList := make([]string, 0)
- childCondition := ""
- condition := ""
- childPars := make([]interface{}, 0)
- pars := make([]interface{}, 0)
-
- condition += ` AND (c.user_id = ? or (d.approve_user_id = ? and d.node_id <= a.curr_node_id))`
- pars = append(pars, sysUser.AdminId, sysUser.AdminId)
- condition += ` AND (c.company_name like "%` + keyword + `%" or c.credit_code like "%` + keyword + `%")`
- list, err := seal.GetCompanyNameListV2(childCondition, condition, childPars, pars)
- if err != nil {
- c.FailWithMessage("获取客户名称列表失败!", "获取客户名称列表失败,ERR:"+err.Error())
- return
- }
- for _, v := range list {
- companyNameList = append(companyNameList, v.CompanyName)
- }
- c.OkDetailed(companyNameList, "获取成功")
- }
- func (c *SealCommon) CompanyNameList() {
- keyword := c.GetString("Keyword")
- pageSize, _ := c.GetInt("PageSize")
- currentIndex, _ := c.GetInt("CurrentIndex")
- if keyword == "" {
- c.FailWithMessage("关键词不能为空", "关键词不能为空")
- return
- }
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- keyword = "%" + keyword + "%"
- condition := " AND company_name LIKE ? "
- pars := make([]interface{}, 0)
- pars = append(pars, keyword)
- list, err := company.GetCompanyNameList(condition, pars, startSize, pageSize)
- if err != nil {
- c.FailWithMessage("获取客户名称列表失败!", "获取客户名称列表失败,ERR:"+err.Error())
- return
- }
- c.OkDetailed(list, "获取成功")
- }
|