123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819 |
- package controllers
- import (
- "encoding/json"
- "fmt"
- "github.com/rdlucklib/rdluck_tools/paging"
- approval2 "hongze/hongze_mobile_admin/models/request/approval"
- "hongze/hongze_mobile_admin/models/response/approval"
- "hongze/hongze_mobile_admin/models/tables/admin"
- "hongze/hongze_mobile_admin/models/tables/company_approval"
- "hongze/hongze_mobile_admin/models/tables/company_contract"
- "hongze/hongze_mobile_admin/models/tables/company_delay_permission"
- "hongze/hongze_mobile_admin/models/tables/company_product"
- "hongze/hongze_mobile_admin/models/tables/company_product_log"
- "hongze/hongze_mobile_admin/models/tables/company_report_permission"
- "hongze/hongze_mobile_admin/models/tables/contract_approval_record"
- "hongze/hongze_mobile_admin/services"
- "hongze/hongze_mobile_admin/services/flow"
- "hongze/hongze_mobile_admin/utils"
- "strconv"
- "time"
- )
- // 客户审批列表
- type ApprovalCommon struct {
- BaseAuth
- }
- // ListOld
- // @Title 获取审批列表接口
- // @Description 获取审批列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param Status query string true "状态:'待审批','已审批','驳回','已撤回'"
- // @Param KeyWord query string true "搜索关键词"
- // @Param Keyword query string true "搜索关键词"
- // @Param KeywordEq query string true "搜索关键词(全等)"
- // @Success 200 {object} approval.CompanyApprovalListResp
- // @router /list_old [get]
- func (c *ApprovalCommon) ListOld() {
- sysUser := c.AdminWx
- roleTypeCode := sysUser.RoleTypeCode
- pageSize, _ := c.GetInt("PageSize")
- currentIndex, _ := c.GetInt("CurrentIndex")
- status := c.GetString("Status")
- keyword := c.GetString("Keyword")
- keywordEq := c.GetString("KeywordEq")
- keyWord := c.GetString("KeyWord")
- if keyword == "" {
- keyword = keyWord
- }
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- var condition string
- var pars []interface{}
- if status != "" {
- if status == "已审批" {
- condition += ` AND c.approve_status IN('已审批','驳回') `
- } else {
- condition += ` AND c.approve_status=? `
- pars = append(pars, status)
- }
- }
- if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN { //审批
- condition += ` AND c.approve_role_type_code=? `
- pars = append(pars, roleTypeCode)
- } else if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_COMPLIANCE { //超管或者合规
- } else { //销售
- condition += ` AND c.apply_user_id=? `
- pars = append(pars, sysUser.AdminId)
- }
- if keyword != "" {
- condition += ` AND (a.company_name LIKE '%` + keyword + `%' OR a.credit_code LIKE '%` + keyword + `%') `
- }
- if keywordEq != "" {
- condition += ` AND a.company_name = ? `
- pars = append(pars, keywordEq)
- }
- total, err := company_approval.GetApprovalCount(condition, pars)
- if err != nil {
- c.FailWithMessage("获取失败", "获取数据总数失败,Err:"+err.Error())
- return
- }
- list, err := company_approval.GetApprovalList(condition, pars, startSize, pageSize)
- if err != nil {
- c.FailWithMessage("获取失败", "获取数据失败,Err:"+err.Error())
- return
- }
- listLen := len(list)
- for i := 0; i < listLen; i++ {
- item := list[i]
- if item.FreezeStartDate != "" && item.FreezeEndDate != "" && item.Status == utils.COMPANY_STATUS_FREEZE {
- freezeEndDate, _ := time.Parse(utils.FormatDate, item.FreezeEndDate)
- if time.Now().Before(freezeEndDate) {
- expireDays := freezeEndDate.Sub(time.Now()).Hours() / 24
- list[i].FreezeExpireDays = int(expireDays)
- }
- }
- if item.StartDate != "" && item.EndDate != "" {
- endDate, _ := time.Parse(utils.FormatDate, item.EndDate)
- if time.Now().Before(endDate) {
- expireDays := endDate.Sub(time.Now()).Hours() / 24
- list[i].ExpireDay = int(expireDays)
- }
- }
- switch item.ApplyMethod {
- case 2:
- //客户冻结转试用次数
- approvalCount, err := company_approval.GetFreezeToTryCompanyApprovalCount(item.CompanyId, item.ProductId, item.ApplyUserId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- c.FailWithMessage("获取失败", "获取冻结转试用审批次数失败,Err:"+err.Error())
- return
- }
- list[i].ApprovalCount = approvalCount
- case 3:
- //延迟试用权限列表
- delayPermission, err := company_delay_permission.GetApplyDelayPermission(item.CompanyApprovalId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- c.FailWithMessage("获取失败", "获取延期审批权限失败,Err:"+err.Error())
- return
- }
- list[i].DelayPermission = delayPermission
- //客户审批试用延期次数
- approvalCount, err := company_approval.GetCompanyTryDelayApprovalCount(item.CompanyId, item.ProductId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- c.FailWithMessage("获取失败", "获取延期审批次数失败,Err:"+err.Error())
- return
- }
- list[i].ApprovalCount = approvalCount
- }
- if item.ApproveRoleTypeCode == roleTypeCode {
- list[i].OpButton = true
- }
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp := approval.CompanyApprovalListResp{
- Paging: page,
- List: list,
- }
- c.OkDetailed(resp, "获取成功")
- }
- // @Title 获取审批单详情接口
- // @Description 获取审批单详情接口
- // @Param ApprovalId query int true "审批单id"
- // @Success 200 {object} approval.CompanyApprovalDetailResp
- // @router /detail_old [get]
- func (c *ApprovalCommon) DetailOld() {
- sysUser := c.AdminWx
- roleTypeCode := sysUser.RoleTypeCode
- companyApprovalId, _ := c.GetInt("ApprovalId")
- var condition string
- var pars []interface{}
- if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN { //审批
- condition += ` AND c.approve_role_type_code=? `
- pars = append(pars, roleTypeCode)
- } else if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER { //销售
- condition += ` AND c.apply_user_id=? `
- pars = append(pars, sysUser.AdminId)
- }
- item, err := company_approval.GetApprovalInfoByApprovalId(condition, pars, companyApprovalId)
- if err != nil {
- c.FailWithMessage("获取失败", "获取数据失败,Err:"+err.Error())
- return
- }
- if item.FreezeStartDate != "" && item.FreezeEndDate != "" && item.Status == utils.COMPANY_STATUS_FREEZE {
- freezeEndDate, _ := time.Parse(utils.FormatDate, item.FreezeEndDate)
- if time.Now().Before(freezeEndDate) {
- expireDays := freezeEndDate.Sub(time.Now()).Hours() / 24
- item.FreezeExpireDays = int(expireDays)
- }
- }
- if item.StartDate != "" && item.EndDate != "" {
- endDate, _ := time.Parse(utils.FormatDate, item.EndDate)
- if time.Now().Before(endDate) {
- expireDays := endDate.Sub(time.Now()).Hours() / 24
- item.ExpireDay = int(expireDays)
- }
- }
- switch item.ApplyMethod {
- case 2:
- //客户冻结转试用次数
- approvalCount, err := company_approval.GetFreezeToTryCompanyApprovalCount(item.CompanyId, item.ProductId, item.ApplyUserId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- c.FailWithMessage("获取失败", "获取冻结转试用审批次数失败,Err:"+err.Error())
- return
- }
- item.ApprovalCount = approvalCount
- case 3:
- //客户审批试用延期次数
- approvalCount, err := company_approval.GetCompanyTryDelayApprovalCount(item.CompanyId, item.ProductId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- c.FailWithMessage("获取失败", "获取延期审批次数失败,Err:"+err.Error())
- return
- }
- item.ApprovalCount = approvalCount
- }
- //if item.ApplyMethod == 3 {
- // delayPermission, err := company_delay_permission.GetApplyDelayPermission(item.CompanyApprovalId)
- // if err != nil && err.Error() != utils.ErrNoRow() {
- // c.FailWithMessage("获取失败", "获取延期审批权限失败,Err:"+err.Error())
- // return
- // }
- // item.DelayPermission = delayPermission
- //}
- if item.ApproveRoleTypeCode == roleTypeCode {
- item.OpButton = true
- }
- resp := approval.CompanyApprovalDetailResp{
- CompanyApprovalDetail: item,
- }
- //获取权限列表
- //子权限切片集合
- var permissionClassifyArr []string
- if item.ProductId == 1 {
- for _, v := range utils.PermissionFiccClassifyArr {
- permissionClassifyArr = append(permissionClassifyArr, v)
- }
- } else {
- permissionClassifyArr = append(permissionClassifyArr, "权益")
- }
- //获取需要审批的权限
- delayPermissionList, err := company_delay_permission.GetDelayPermissionItems(item.CompanyId, item.CompanyApprovalId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- c.FailWithMessage("获取失败", "获取审批权限失败,Err:"+err.Error())
- return
- }
- delayPermissionIdMap := make(map[int]int)
- for _, delayPermission := range delayPermissionList {
- delayPermissionIdMap[delayPermission.ChartPermissionId] = 0
- }
- //遍历获取
- for _, v := range permissionClassifyArr {
- checkList := make([]int, 0)
- plist := new(company_report_permission.PermissionLookList)
- items, err := company_report_permission.GetPermissionLookItems(item.ProductId, v)
- if err != nil {
- c.FailWithMessage("获取失败", "获取权限信息失败,Err:"+err.Error())
- return
- }
- for _, n := range items {
- if _, ok := delayPermissionIdMap[n.ChartPermissionId]; ok {
- checkList = append(checkList, n.ChartPermissionId)
- }
- }
- plist.Items = items
- plist.ClassifyName = v
- plist.CheckList = checkList
- if item.ProductId == 1 {
- resp.FiccPermissionList = append(resp.FiccPermissionList, plist)
- } else {
- resp.PermissionList = append(resp.PermissionList, plist)
- }
- }
- //审批流
- flowId := 1
- if item.ProductId == 2 {
- flowId = 2
- }
- flowItem, err := flow.GetApprovalFlow(flowId)
- if err != nil {
- c.FailWithMessage("获取失败", "获取数据失败,Err:"+err.Error())
- return
- }
- approveTime, err := time.Parse(utils.FormatDateTime, item.ApproveTime)
- if err != nil {
- c.FailWithMessage("获取失败", "审批时间转换失败,Err:"+err.Error())
- return
- }
- approvalTime, err := time.Parse(utils.FormatDateTime, item.ApprovalTime)
- if err != nil {
- c.FailWithMessage("获取失败", "发起时间转换失败,Err:"+err.Error())
- return
- }
- //当前审批流程id
- flowNodeListResp := make([][]contract_approval_record.ContractApprovalRecord, 0)
- for _, node := range flowItem.NodeList {
- flowNodeResp := make([]contract_approval_record.ContractApprovalRecord, 0)
- for _, user := range node.UserList {
- approveStatus := item.ApproveStatus
- if approveStatus == "驳回" {
- approveStatus = "已驳回"
- }
- approvalRecord := contract_approval_record.ContractApprovalRecord{
- //ContractApprovalRecordId int `orm:"column(contract_approval_record_id);pk"`
- //ContractApprovalId int `orm:"column(contract_approval_id)" description:"审批单id"`
- Status: approveStatus,
- ApproveRemark: item.ApproveRemark,
- ApproveRoleTypeCode: user.RoleTypeCode,
- ApproveUserId: user.AdminId,
- ApproveUserName: user.Name,
- NodeId: node.NodeId,
- NodeType: node.NodeType,
- //PrevNodeId int `description:"上级节点id"`
- //NextNodeId int `description:"下级节点id"`
- AuditType: node.AuditType,
- ApproveTime: approveTime,
- //ModifyTime time.Time `description:"发起申请时间"`
- CreateTime: approvalTime,
- }
- flowNodeResp = append(flowNodeResp, approvalRecord)
- if user.AdminId == item.ApproveUserId {
- resp.CompanyApprovalDetail.CurrNodeId = node.NodeId
- }
- }
- flowNodeListResp = append(flowNodeListResp, flowNodeResp)
- }
- resp.FlowNodeList = flowNodeListResp
- c.OkDetailed(resp, "获取成功")
- }
- // @Title 获取审批单中的权限列表
- // @Description 获取审批单中的权限列表接口
- // @Param ApprovalId query int true "审批单id"
- // @Success 200 {object} approval.CompanyPermissionResp
- // @router /getApprovalPermissionList [get]
- func (c *ApprovalCommon) GetApprovalPermissionList() {
- //c.FailWithMessage("获取失败", "获取数据总数失败,Err:"+err.Error())
- //返回基础参数
- resp := new(approval.CompanyPermissionResp)
- //获取审批单信息
- approvalId, _ := c.GetInt("ApprovalId")
- if approvalId <= 0 {
- c.FailWithMessage("审批单参数异常", "提交审批单参数异常")
- return
- }
- approvalInfo, err := company_approval.GetCompanyApprovalByApprovalId(approvalId)
- if err != nil {
- c.FailWithMessage("获取失败", "获取审批单数据失败,Err:"+err.Error())
- return
- }
- //子权限切片集合
- var permissionClassifyArr []string
- if approvalInfo.ProductId == 1 {
- for _, v := range utils.PermissionFiccClassifyArr {
- permissionClassifyArr = append(permissionClassifyArr, v)
- }
- } else {
- permissionClassifyArr = append(permissionClassifyArr, "权益")
- }
- //获取需要审批的权限
- delayPermissionList, err := company_delay_permission.GetDelayPermissionItems(approvalInfo.CompanyId, approvalInfo.CompanyApprovalId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- c.FailWithMessage("获取失败", "获取审批权限失败,Err:"+err.Error())
- return
- }
- delayPermissionIdMap := make(map[int]int)
- for _, delayPermission := range delayPermissionList {
- delayPermissionIdMap[delayPermission.ChartPermissionId] = 0
- }
- //遍历获取
- for _, v := range permissionClassifyArr {
- checkList := make([]int, 0)
- plist := new(company_report_permission.PermissionLookList)
- items, err := company_report_permission.GetPermissionLookItems(approvalInfo.ProductId, v)
- if err != nil {
- c.FailWithMessage("获取失败", "获取权限信息失败,Err:"+err.Error())
- return
- }
- for _, n := range items {
- if _, ok := delayPermissionIdMap[n.ChartPermissionId]; ok {
- checkList = append(checkList, n.ChartPermissionId)
- }
- }
- plist.Items = items
- plist.ClassifyName = v
- plist.CheckList = checkList
- if approvalInfo.ProductId == 1 {
- resp.FiccPermissionList = append(resp.FiccPermissionList, plist)
- } else {
- resp.PermissionList = append(resp.PermissionList, plist)
- }
- }
- c.OkDetailed(resp, "获取成功")
- }
- // @Title 审批
- // @Description 审批接口
- // @Param request body approval.CompanyApplyApproveReq true "type json string"
- // @Success Ret=200 审批成功
- // @router /approve_old [post]
- func (c *ApprovalCommon) ApplyApproveOld() {
- sysUser := c.AdminWx
- var req approval2.CompanyApplyApproveReq
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
- if err != nil {
- c.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error())
- return
- }
- roleTypeCode := sysUser.RoleTypeCode
- productId := services.GetProductId(roleTypeCode)
- if productId == 0 {
- c.FailWithMessage("参数错误", "参数解析失败,Err:"+"客户类型为:"+roleTypeCode)
- return
- }
- if req.CompanyId <= 0 {
- c.FailWithMessage("参数错误", "客户Id小于等于0")
- return
- }
- if req.Status != 1 && req.Status != 2 {
- c.FailWithMessage("参数错误", "审批状态Id小于等于0")
- return
- }
- companyProduct, err := company_product.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
- if err != nil {
- c.FailWithMessage("获取信息失败", "获取信息失败,Err:"+err.Error())
- return
- }
- if companyProduct == nil {
- c.FailWithMessage("获取审批信息失败", "获取信息失败,Err:"+err.Error())
- return
- }
- approvalItem, err := company_approval.GetCompanyApprovalByCompanyId(req.CompanyId, productId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- c.FailWithMessage("订单已审批,请刷新页面查看最新状态", "待审批信息不存在,CompanyId:"+strconv.Itoa(req.CompanyId)+";productId:"+strconv.Itoa(productId))
- } else {
- c.FailWithMessage("获取信息失败", "获取信息失败,Err:"+err.Error())
- }
- return
- }
- if approvalItem == nil {
- c.FailWithMessage("订单已审批,请刷新页面查看最新状态", "待审批信息不存在,CompanyId:"+strconv.Itoa(req.CompanyId)+";productId:"+strconv.Itoa(productId))
- return
- }
- if approvalItem.ApproveRoleTypeCode != roleTypeCode {
- c.FailWithMessage("您无权审批", "ApproveRoleTypeCode:"+approvalItem.ApproveRoleTypeCode+";roleTypeCode:"+roleTypeCode)
- return
- }
- var approveStatus, approveContent string
- if req.Status == 1 { //通过
- //申请类型:1:试用->正式,2:冻结—>试用,3:试用延期,4:原销售申请领取流失客户,5:正式客户申请服务更新,6:正式客户补充协议
- if approvalItem.ApplyMethod == 1 { //试用转正式
- //获取合同信息
- contract, err := company_contract.GetCompanyContractDetail(req.CompanyId, productId, req.CompanyContractId)
- if err != nil {
- c.FailWithMessage("待审批信息不存在", "待审批信息不存在,CompanyId:"+strconv.Itoa(req.CompanyId)+";productId:"+strconv.Itoa(productId)+";Err:"+err.Error())
- return
- }
- if contract == nil {
- c.FailWithMessage("待审批信息不存在", "待审批信息不存在,CompanyId:"+strconv.Itoa(req.CompanyId)+";productId:"+strconv.Itoa(productId))
- return
- }
- //格式化合同开始时间
- contractStartDate, err := time.Parse(utils.FormatDate, contract.StartDate)
- if err != nil {
- c.FailWithMessage("审批失败", "合同开始时间转换失败,Err:"+err.Error())
- return
- }
- //格式化合同结束日期
- contractEndDate, err := time.Parse(utils.FormatDate, contract.EndDate)
- if err != nil {
- c.FailWithMessage("审批失败", "合同结束时间转换失败,Err:"+err.Error())
- return
- }
- //格式化 产品中 合同结束日期
- //productContractEndDate, err := time.Parse(utils.FormatDate, companyProduct.ContractEndDate)
- //if err != nil {
- // br.Msg = "审批失败"
- // br.ErrMsg = "产品中合同结束时间转换失败,Err:" + err.Error()
- // return
- //}
- //如果合同时间小于等于今天,那么立马执行合同内容
- if time.Now().After(contractStartDate) {
- _, err = company_approval.TryOutToFormal(req.CompanyId, productId, sysUser.AdminId, approvalItem.CompanyApprovalId, contract.CompanyContractId, contract.StartDate, contract.EndDate, sysUser.RealName, companyProduct.ProductName, contract.PackageType, contract.RaiPackageType)
- if err != nil {
- c.FailWithMessage("审批失败", "审批失败,Err:"+err.Error())
- return
- }
- } else {
- err = company_approval.ApplyApproveContract(req.CompanyId, productId, approvalItem.CompanyApprovalId, contract.CompanyContractId)
- if err != nil {
- c.FailWithMessage("审批失败", "审批失败,Err:"+err.Error())
- return
- }
- }
- //如果合同中的结束日期大于产品中的合同结束日期,那么就去修改产品中的合同结束日期
- if contractEndDate.After(companyProduct.ContractEndDate) {
- companyProduct.ContractEndDate = contractEndDate
- cols := make([]string, 0)
- cols = append(cols, "ContractEndDate")
- _ = companyProduct.Update(cols)
- }
- } else if approvalItem.ApplyMethod == 2 { //冻结->试用
- _, _, _, err = company_approval.FreezeToTryOut(req.CompanyId, productId, sysUser.AdminId, approvalItem.CompanyApprovalId, approvalItem.ApplyUserId, sysUser.RealName, companyProduct.ProductName)
- if err != nil {
- c.FailWithMessage("审批失败", "审批失败,Err:"+err.Error())
- return
- }
- } else if approvalItem.ApplyMethod == 3 { //试用延期
- _, _, err = company_approval.TryOutDelay(req.CompanyId, productId, sysUser.AdminId, approvalItem.CompanyApprovalId, sysUser.RealName, companyProduct.EndDate, companyProduct.ProductName)
- if err != nil {
- c.FailWithMessage("审批失败", "审批失败,Err:"+err.Error())
- return
- }
- } else if approvalItem.ApplyMethod == 4 { //原销售申请领取流失客户
- _, _, _, err = company_approval.ApplyReceive(req.CompanyId, productId, sysUser.AdminId, approvalItem.CompanyApprovalId, approvalItem.ApplyUserId, sysUser.RealName, companyProduct.ProductName)
- if err != nil {
- c.FailWithMessage("审批失败", "审批失败,Err:"+err.Error())
- return
- }
- } else if approvalItem.ApplyMethod == 5 || approvalItem.ApplyMethod == 6 { //正式客户申请服务更新
- //获取合同信息
- contract, err := company_contract.GetCompanyContractDetail(req.CompanyId, productId, req.CompanyContractId)
- if err != nil {
- c.FailWithMessage("审批失败", "审批失败,Err:"+err.Error())
- return
- }
- if contract == nil {
- c.FailWithMessage("审批失败", "审批失败")
- return
- }
- //格式化合同开始时间
- contractStartDate, err := time.Parse(utils.FormatDate, contract.StartDate)
- if err != nil {
- c.FailWithMessage("审批失败", "合同开始时间转换失败,Err:"+err.Error())
- return
- }
- //格式化合同结束日期
- contractEndDate, err := time.Parse(utils.FormatDate, contract.EndDate)
- if err != nil {
- c.FailWithMessage("审批失败", "合同结束时间转换失败,Err:"+err.Error())
- return
- }
- //格式化 产品中 合同结束日期
- //productContractEndDate, err := time.Parse(utils.FormatDate, companyProduct.ContractEndDate)
- //if err != nil {
- // br.Msg = "审批失败"
- // br.ErrMsg = "产品中合同结束时间转换失败,Err:" + err.Error()
- // return
- //}
- //如果合同时间小于等于今天,那么立马执行合同内容
- if time.Now().After(contractStartDate) {
- _, err = company_approval.ApplyServiceUpdate(req.CompanyId, productId, sysUser.AdminId, approvalItem.CompanyApprovalId, contract.CompanyContractId, companyProduct.StartDate, contract.EndDate, sysUser.RealName, companyProduct.ProductName, contract.PackageType, contract.RaiPackageType)
- if err != nil {
- c.FailWithMessage("审批失败", "审批失败,Err:"+err.Error())
- return
- }
- } else {
- err = company_approval.ApplyApproveContract(req.CompanyId, productId, approvalItem.CompanyApprovalId, contract.CompanyContractId)
- if err != nil {
- c.FailWithMessage("审批失败", "审批失败,Err:"+err.Error())
- return
- }
- }
- //如果合同中的结束日期大于产品中的合同结束日期,那么就去修改产品中的合同结束日期
- if contractEndDate.After(companyProduct.ContractEndDate) {
- companyProduct.ContractEndDate = contractEndDate
- cols := make([]string, 0)
- cols = append(cols, "ContractEndDate")
- _ = companyProduct.Update(cols)
- }
- } else {
- c.FailWithMessage("审批失败", "无效的审批状态,CompanyId:"+strconv.Itoa(req.CompanyId)+";productId:"+
- strconv.Itoa(productId)+";ApplyMethod:"+strconv.Itoa(approvalItem.ApplyMethod)+" ApproveStatus;"+approvalItem.ApproveStatus)
- return
- }
- approveContent = "审批通过"
- } else { //拒绝
- if req.Remark == "" {
- c.FailWithMessage("请填写驳回理由", "请填写驳回理由")
- return
- }
- approveStatus = "驳回"
- err = company_approval.ApproveRefuse(req.CompanyId, productId, approveStatus, req.Remark)
- approveContent = "审批驳回"
- if err != nil {
- c.FailWithMessage("审批失败", "审批失败,Err:"+err.Error())
- return
- }
- }
- //新增客户产品日志
- {
- productLog := new(company_product_log.CompanyProductLog)
- productLog.CompanyProductId = companyProduct.CompanyProductId
- productLog.CompanyId = companyProduct.CompanyId
- productLog.ProductId = companyProduct.ProductId
- productLog.ProductName = companyProduct.ProductName
- productLog.CompanyName = companyProduct.CompanyName
- productLog.CompanyName = companyProduct.CompanyName
- productLog.Source = companyProduct.Source
- productLog.Reasons = companyProduct.Reasons
- productLog.Status = companyProduct.Status
- productLog.IndustryId = companyProduct.IndustryId
- productLog.IndustryName = companyProduct.IndustryName
- productLog.SellerId = companyProduct.SellerId
- productLog.SellerName = companyProduct.SellerName
- productLog.GroupId = companyProduct.GroupId
- productLog.DepartmentId = companyProduct.DepartmentId
- productLog.IsSuspend = companyProduct.IsSuspend
- productLog.SuspendTime = companyProduct.SuspendTime
- productLog.ApproveStatus = companyProduct.ApproveStatus
- productLog.FreezeTime = companyProduct.FreezeTime
- productLog.Remark = companyProduct.Remark
- productLog.StartDate = companyProduct.StartDate
- productLog.EndDate = companyProduct.EndDate
- productLog.CreateTime = companyProduct.CreateTime
- productLog.ModifyTime = companyProduct.ModifyTime
- productLog.LoseReason = companyProduct.LoseReason
- productLog.LossTime = companyProduct.LossTime
- productLog.LogType = "modify"
- productLog.LogCreateTime = time.Now()
- productLog.AdminId = c.AdminWx.AdminId
- go company_product_log.AddCompanyProductLog(productLog)
- }
- //新增操作记录
- {
- remark := "审批"
- operation := "approve"
- services.AddCompanyOperationRecord(req.CompanyId, companyProduct.SellerId, sysUser.AdminId, productId, sysUser.AdminId, companyProduct.CompanyName,
- companyProduct.ProductName, sysUser.RealName, remark, operation, approveContent, sysUser.RealName, req.Remark, companyProduct.Status)
- }
- //待办通知
- {
- content := companyProduct.CompanyName + " " + approvalItem.ApproveContent + approveContent
- approvalSysUser, _ := admin.GetAdminById(approvalItem.ApplyUserId)
- if sysUser != nil {
- approvalStatus := 1
- if req.Status == 1 {
- approvalStatus = 2
- } else {
- approvalStatus = 3
- }
- go services.AddCompanyApprovalMessage(sysUser.AdminId, approvalItem.ApplyUserId, req.CompanyId, approvalItem.CompanyApprovalId, 2, 1, approvalStatus, companyProduct.CompanyName, content, content, approvalSysUser.Mobile, "")
- }
- }
- c.OkWithMessage("审批操作成功")
- }
- // @Title 获取审批流详情接口
- // @Description 获取审批流详情接口
- // @Param FlowId query int true "审批流程id;1:ficc客户审批;2:权益客户审批;3:ficc合同审批,4:权益合同审批,5:用印审批(合同章),6:用印审批(公章、法人章)"
- // @Success 200 {object} approval_flow.ApprovalFlowItem
- // @router /flowDetail [get]
- func (c *ApprovalCommon) GetFlowDetail() {
- //sysUser := c.AdminWx
- flowId, _ := c.GetInt("FlowId", 0)
- if flowId <= 0 {
- c.FailWithMessage("参数异常", fmt.Sprint("审批流程id异常,FlowId:", flowId))
- return
- }
- flowItem, err := flow.GetApprovalFlow(flowId)
- if err != nil {
- c.FailWithMessage("获取失败", "获取数据失败,Err:"+err.Error())
- return
- }
- formatFlowItem, err := flow.FormatApprovalFlow(flowItem)
- c.OkDetailed(formatFlowItem, "获取成功")
- }
- // CompanyList
- // @Title 根据客户名称获取已存在合同系统中客户名称列表
- // @Description 获取合同详情接口
- // @Param Keyword query string true "搜索关键字:客户名称、组织社会信用码"
- // @Success 200 {object} []string
- // @router /company_list [get]
- func (c *ApprovalCommon) CompanyList() {
- keyword := c.GetString("Keyword")
- //合同id
- if keyword == "" {
- c.FailWithMessage("搜索关键字必传!", "搜索关键字必传!")
- return
- }
- companyNameList := make([]string, 0)
- list, err := company_approval.GetCompanyNameList(c.AdminWx.AdminId, keyword)
- if err != nil {
- c.FailWithMessage("获取客户名称列表失败!", "获取客户名称列表失败,ERR:"+err.Error())
- return
- }
- for _, v := range list {
- companyNameList = append(companyNameList, v.CompanyName)
- }
- c.OkDetailed(companyNameList, "获取成功")
- }
- //// @Title 审批列表删除
- //// @Description 审批列表删除接口
- //// @Param request body company.CompanyApplyDeleteReq true "type json string"
- //// @Success Ret=200 删除成功
- //// @router /approval/delete [post]
- //func (c *CompanyApprovalController) ApplyDelete() {
- // br := new(models.BaseResponse).Init()
- // defer func() {
- // c.Data["json"] = br
- // c.ServeJSON()
- // }()
- // sysUser := c.SysUser
- // if sysUser == nil {
- // br.Msg = "请登录"
- // br.ErrMsg = "请登录,SysUser Is Empty"
- // br.Ret = 408
- // return
- // }
- // var req company.CompanyApplyDeleteReq
- // err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
- // if err != nil {
- // br.Msg = "参数解析异常!"
- // br.ErrMsg = "参数解析失败,Err:" + err.Error()
- // return
- // }
- // roleTypeCode := sysUser.RoleTypeCode
- // productId := services.GetProductId(roleTypeCode)
- // if productId == 0 {
- // br.Msg = "参数错误"
- // br.ErrMsg = "客户类型为:" + roleTypeCode
- // return
- // }
- // if req.CompanyId <= 0 {
- // br.Msg = "参数错误"
- // br.ErrMsg = "客户Id小于等于0:"
- // return
- // }
- // companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
- // if err != nil {
- // br.Msg = "获取信息失败"
- // br.ErrMsg = "获取信息失败,Err:" + err.Error()
- // return
- // }
- // if companyProduct == nil {
- // br.Msg = "获取信息失败"
- // br.ErrMsg = "获取审批信息失败,Err:" + err.Error()
- // return
- // }
- // approvalItem, err := company.GetCompanyApprovalByApprovalId(req.CompanyApprovalId)
- // if err != nil {
- // if err.Error() == utils.ErrNoRow() {
- // br.Msg = "待审批信息不存在"
- // br.ErrMsg = "待审批信息不存在,CompanyId:" + strconv.Itoa(req.CompanyId) + ";productId:" + strconv.Itoa(productId)
- // return
- // }
- // br.Msg = "获取信息失败"
- // br.ErrMsg = "获取信息失败,Err:" + err.Error()
- // return
- // }
- // if approvalItem == nil {
- // br.Msg = "待审批信息不存在"
- // br.ErrMsg = "待审批信息不存在,CompanyId:" + strconv.Itoa(req.CompanyId) + ";productId:" + strconv.Itoa(productId)
- // return
- // }
- // if approvalItem.ApproveStatus != "待审批" && approvalItem.ApproveStatus != "已撤回" {
- // br.Msg = "审批状态为:" + approvalItem.ApproveStatus + ";不可删除"
- // br.ErrMsg = "审批状态为:" + approvalItem.ApproveStatus + ";不可删除" + ";CompanyId:" + strconv.Itoa(req.CompanyId) + ";productId:" + strconv.Itoa(productId)
- // return
- // }
- // //删除
- // err = company.ApplyDelete(req.CompanyId, req.CompanyApprovalId, approvalItem.ProductId)
- // if err != nil {
- // br.Msg = "删除失败"
- // br.ErrMsg = "删除失败,Err:" + err.Error()
- // return
- // }
- // //新增操作记录
- // {
- // remark := "删除审批申请"
- // operation := "approve_delete"
- // services.AddCompanyOperationRecord(req.CompanyId, companyProduct.SellerId, sysUser.AdminId, productId, sysUser.AdminId, companyProduct.CompanyName,
- // companyProduct.ProductName, sysUser.RealName, remark, operation, remark, sysUser.RealName, "", companyProduct.Status)
- // }
- // br.Ret = 200
- // br.Success = true
- // br.Msg = "删除成功"
- //}
|