123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- package seal
- import (
- "fmt"
- "github.com/beego/beego/v2/client/orm"
- "hongze/hongze_mobile_admin/utils"
- "time"
- )
- //Seal 用印结构体
- type Seal struct {
- SealId int `orm:"column(seal_id);pk"`
- Code string `description:"用印编号,长度32位"`
- UserId int `description:"申请人id"`
- UserName string `description:"申请人名称"`
- Use string `description:"用印用途,枚举值:'销售合同', '渠道合同', '付款通知函', '招投标', '战略合作协议';默认:销售合同"`
- CompanyName string `description:"客户名称,甲方名称,长度32位"`
- UseCompanyName string `description:"实际使用方客户名称,长度32位"`
- CreditCode string `description:"社会统一信用代码,长度64位"`
- ServiceType string `description:"业务类型,枚举值:'新签合同','续约合同','补充协议';默认:新签合同"`
- SealType string `description:"加盖印章类型,枚举值:'合同章', '公章', '法人章';默认:合同章"`
- Status string `description:"合同状态,枚举值:'待提交','待审批','已撤回','已审批','已驳回','已作废','已签回'"`
- Remark string `description:"补充内容,长度255位"`
- ApprovalRemark string `description:"审核备注"`
- FileUrl string `description:"文件附件地址"`
- CheckBackFileUrl string `description:"已签回的文件地址"`
- FileNum int `description:"文件附件份数"`
- ContractId int `description:"系统合同id"`
- IsDelete int `json:"-" description:"是否已经删除,0:未删除,1:已删除"`
- ApproveTime time.Time `description:"审批时间"`
- InvalidTime time.Time `description:"作废时间"`
- ModifyTime time.Time `description:"最近一次修改时间"`
- CreateTime time.Time `description:"添加时间"`
- CheckBackFileTime time.Time `description:"签回用印附件时间"`
- AffiliatedCompany string `description:"归属公司"`
- }
- var EnumUse = []string{"销售合同", "渠道合同", "付款通知函", "招投标", "战略合作协议", "代付合同", "总对总协议"}
- var EnumServiceType = []string{"新签合同", "续约合同", "补充协议", "代付合同"}
- //GetSealInfoById 根据用印id获取合同信息
- func GetSealInfoById(sealId int) (sealInfo *Seal, err error) {
- o := orm.NewOrm()
- sql := `select * from seal where seal_id = ? `
- err = o.Raw(sql, sealId).QueryRow(&sealInfo)
- return
- }
- //GetSealInfoByContractId 根据合同id获取合同信息
- func GetSealInfoByContractId(sealId int) (sealInfo *Seal, err error) {
- o := orm.NewOrm()
- sql := `select * from seal where contract_id = ? and status in ("已审批","已签回") order by seal_id asc limit 1`
- err = o.Raw(sql, sealId).QueryRow(&sealInfo)
- return
- }
- //AddSeal 用印添加
- func AddSeal(sealInfo *Seal) (err error) {
- o := orm.NewOrm()
- //用印数据入库
- sealId, err := o.Insert(sealInfo)
- if err != nil {
- return
- }
- sealInfo.SealId = int(sealId)
- return
- }
- //Update 更新用印信息
- func (seal *Seal) Update(cols []string) (err error) {
- o := orm.NewOrm()
- _, err = o.Update(seal, cols...)
- return
- }
- //DeleteSeal 删除用印
- func DeleteSeal(sealInfo *Seal) (err error) {
- sealInfo.IsDelete = 1
- sealInfo.ModifyTime = time.Now()
- sealInfo.InvalidTime = time.Now()
- err = sealInfo.Update([]string{"IsDelete", "ModifyTime", "InvalidTime"})
- return
- }
- //Invalid 作废用印
- func Invalid(sealInfo *Seal) (err error) {
- sealInfo.Status = "已作废"
- sealInfo.ModifyTime = time.Now()
- sealInfo.InvalidTime = time.Now()
- //修改用印数据入库
- err = sealInfo.Update([]string{"Status", "ModifyTime", "InvalidTime"})
- return
- }
- //GetSealCode 生成合同编号
- func GetSealCode() (code string, err error) {
- var num int
- o := orm.NewOrm()
- today := utils.GetToday(utils.FormatDate)
- sql := `SELECT COUNT(1) AS num FROM seal where create_time>=?`
- err = o.Raw(sql, today).QueryRow(&num)
- if err != nil {
- return
- }
- code = "HZ" + time.Now().Format("20060102") + fmt.Sprintf("%03d", num)
- return
- }
- type CompanyNameList struct {
- CompanyName string `description:"客户名称,甲方名称,长度32位"`
- }
- //GetCompanyNameList 获取客户名称列表数据
- func GetCompanyNameList(name string) (list []*CompanyNameList, err error) {
- o := orm.NewOrm()
- sql := `select * from seal where company_name like '%` + name + `%' group by company_name order by modify_time desc `
- _, err = o.Raw(sql).QueryRows(&list)
- return
- }
- //GetCompanyNameListV2 获取客户名称列表数据V2版本
- func GetCompanyNameListV2(childCondition, condition string, childPars, pars []interface{}) (list []*CompanyNameList, err error) {
- o := orm.NewOrm()
- sql := `SELECT c.company_name,a.modify_time from contract_approval a
- join
- ( SELECT max( contract_approval_id ) max_id,contract_id FROM contract_approval where 1=1 AND approval_type="seal" `
- sql += childCondition
- sql += ` GROUP BY contract_id ) b on a.contract_approval_id=b.max_id
- JOIN seal c ON c.seal_id = a.contract_id
- JOIN contract_approval_record d on a.contract_approval_id=d.contract_approval_id
- WHERE c.is_delete = 0 AND a.approval_type="seal" `
- sql += condition
- sql += ` group by company_name order by modify_time desc`
- _, err = o.Raw(sql, childPars, pars).QueryRows(&list)
- return
- }
- //GetListCount 获取用印列表数据数量
- func GetListCount(condition string, pars []interface{}) (count int, err error) {
- o := orm.NewOrm()
- sql := "select count(*) AS COUNT from seal where 1=1 AND is_delete = 0 "
- sql += condition
- err = o.Raw(sql, pars).QueryRow(&count)
- return
- }
- //GetList 获取用印列表
- func GetList(condition string, pars []interface{}, startSize, pageSize int) (list []*Seal, err error) {
- o := orm.NewOrm()
- sql := "select * from seal where 1=1 AND is_delete = 0 "
- sql += condition
- sql += ` order by modify_time desc LIMIT ?,? `
- _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
- return
- }
|