|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- 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
- }
|