123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- package contract
- import (
- "errors"
- "fmt"
- "hongze/hongze_mobile_admin/models/custom"
- contractCustom "hongze/hongze_mobile_admin/models/custom/contract"
- "hongze/hongze_mobile_admin/models/tables/contract"
- "hongze/hongze_mobile_admin/models/tables/contract_operation_record"
- "hongze/hongze_mobile_admin/models/tables/contract_service_detail"
- "hongze/hongze_mobile_admin/utils"
- )
- //作废合同
- func InvalidContract(contractId int, opUser *custom.AdminWx) (err error) {
- //查询当前合同信息
- nowContract, err := contract.GetContractById(contractId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- err = errors.New(fmt.Sprint("根据合同编号:", contractId, " 找不到初始合同"))
- }
- return
- }
- if nowContract.SellerId != opUser.AdminId && opUser.RoleTypeCode != utils.ROLE_TYPE_CODE_COMPLIANCE {
- err = errors.New("当前账号无操作权限")
- return
- }
- if nowContract.Status != "已审批" {
- err = errors.New("合同状态异常,不允许作废,当前合同状态:" + nowContract.Status)
- return
- }
- //如果删除状态 >0,那么代表已经被删除了
- if nowContract.IsDelete > 0 {
- err = errors.New("该合同已删除")
- return
- }
- //合同作废
- err = contract.InvalidContract(nowContract)
- if err != nil {
- return
- }
- //添加操作日志
- remark := "作废合同模板"
- _ = contract_operation_record.AddContractOperationRecord(nowContract.ContractId, opUser.AdminId, 0, "invalid", opUser.RealName, remark)
- return
- }
- //根据id获取合同详情(包含服务)
- func GetContractDetail(contractId int) (contractDetail *contract.ContractDetail, err error) {
- contractDetail, err = contract.GetContractDetailById(contractId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- err = errors.New("找不到该合同")
- }
- return
- }
- serviceList, err := contractCustom.GetContractServiceAndDetailList(contractId)
- if err != nil {
- err = errors.New(fmt.Sprint("查找合同服务异常", err))
- return
- }
- for i := 0; len(serviceList) > i; i++ {
- if serviceList[i].HasDetail == "是" {
- list, detailErr := contract_service_detail.GetContractServiceDetailListByServiceId(serviceList[i].ContractServiceId)
- if detailErr != nil {
- err = errors.New(fmt.Sprint("查找合同服务详情异常", detailErr))
- return
- }
- serviceList[i].DetailList = list
- }
- }
- contractDetail.Service = serviceList
- return
- }
- //上传签回合同附件
- func UploadCheckBackFile(contractId int, fileUrl string, opUser *custom.AdminWx) (err error) {
- //获取合同信息
- contractInfo, err := contract.GetContractById(contractId)
- if err != nil {
- return
- }
- //合同状态判断
- if contractInfo.Status != "已审批" && contractInfo.Status != "已签回" {
- err = errors.New("合同状态异常,不允许上传签回合同附件,当前合同状态:" + contractInfo.Status)
- return
- }
- contractInfo.CheckBackFileUrl = fileUrl
- contractInfo.Status = "已签回"
- var updateCol = []string{"CheckBackFileUrl", "Status"}
- contractInfo.Update(updateCol)
- //添加操作日志
- remark := "上传签回合同附件"
- _ = contract_operation_record.AddContractOperationRecord(contractInfo.ContractId, opUser.AdminId, 0, "upload", opUser.RealName, remark)
- return
- }
|