package db import ( "applet/app/db/model" "applet/app/utils/logx" "errors" "xorm.io/xorm" ) type CompanyWithWxpayInfoDb struct { Db *xorm.Engine `json:"db"` } func (companyWithWxpayInfoDb *CompanyWithWxpayInfoDb) Set() { // set方法 companyWithWxpayInfoDb.Db = Db } func (companyWithWxpayInfoDb *CompanyWithWxpayInfoDb) GetCompanyWithWxpayInfo(companyId int) (m *model.CompanyWithWxpayInfo, err error) { m = new(model.CompanyWithWxpayInfo) has, err := companyWithWxpayInfoDb.Db.Where("company_id =?", companyId).Get(m) if err != nil { return nil, logx.Error(err) } if has == false { return nil, nil } return m, nil } type EnterpriseWithCompanyWithWxpayInfo struct { model.Enterprise `xorm:"extends"` model.Company `xorm:"extends"` model.CompanyWithWxpayInfo `xorm:"extends"` } func (EnterpriseWithCompanyWithWxpayInfo) TableName() string { return "enterprise" } func (companyWithWxpayInfoDb *CompanyWithWxpayInfoDb) GetCompanyWithWxpayInfoByEnterprise(enterpriseId int) (wxMchId string, err error) { var m EnterpriseWithCompanyWithWxpayInfo get, err := companyWithWxpayInfoDb.Db.Where("enterprise.id = ?", enterpriseId). Join("LEFT", "company", "enterprise.company_id = company.id"). Join("LEFT", "company_with_wxpay_info", "company.id = company_with_wxpay_info.company_id"). Get(&m) if err != nil { return "", err } if !get { return "", errors.New("未查询到相应记录") } wxMchId = m.CompanyWithWxpayInfo.WxMchId return }