智慧食堂
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

db_company_with_wxpay_info.go 1.5 KiB

пре 10 месеци
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package db
  2. import (
  3. "applet/app/db/model"
  4. "applet/app/utils/logx"
  5. "errors"
  6. "xorm.io/xorm"
  7. )
  8. type CompanyWithWxpayInfoDb struct {
  9. Db *xorm.Engine `json:"db"`
  10. }
  11. func (companyWithWxpayInfoDb *CompanyWithWxpayInfoDb) Set() { // set方法
  12. companyWithWxpayInfoDb.Db = Db
  13. }
  14. func (companyWithWxpayInfoDb *CompanyWithWxpayInfoDb) GetCompanyWithWxpayInfo(companyId int) (m *model.CompanyWithWxpayInfo, err error) {
  15. m = new(model.CompanyWithWxpayInfo)
  16. has, err := companyWithWxpayInfoDb.Db.Where("company_id =?", companyId).Get(m)
  17. if err != nil {
  18. return nil, logx.Error(err)
  19. }
  20. if has == false {
  21. return nil, nil
  22. }
  23. return m, nil
  24. }
  25. type EnterpriseWithCompanyWithWxpayInfo struct {
  26. model.Enterprise `xorm:"extends"`
  27. model.Company `xorm:"extends"`
  28. model.CompanyWithWxpayInfo `xorm:"extends"`
  29. }
  30. func (EnterpriseWithCompanyWithWxpayInfo) TableName() string {
  31. return "enterprise"
  32. }
  33. func (companyWithWxpayInfoDb *CompanyWithWxpayInfoDb) GetCompanyWithWxpayInfoByEnterprise(enterpriseId int) (wxMchId string, err error) {
  34. var m EnterpriseWithCompanyWithWxpayInfo
  35. get, err := companyWithWxpayInfoDb.Db.Where("enterprise.id = ?", enterpriseId).
  36. Join("LEFT", "company", "enterprise.company_id = company.id").
  37. Join("LEFT", "company_with_wxpay_info", "company.id = company_with_wxpay_info.company_id").
  38. Get(&m)
  39. if err != nil {
  40. return "", err
  41. }
  42. if !get {
  43. return "", errors.New("未查询到相应记录")
  44. }
  45. wxMchId = m.CompanyWithWxpayInfo.WxMchId
  46. return
  47. }