query.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. package company_product
  2. import (
  3. "errors"
  4. "hongze/hongze_yb/global"
  5. "hongze/hongze_yb/utils"
  6. )
  7. // GetByCompany2ProductId 根据客户id和产品id获取信息
  8. func GetByCompany2ProductId(companyId, productId int64) (item *CompanyProduct, err error) {
  9. err = global.DEFAULT_MYSQL.Where("company_id = ? and product_id=?", companyId, productId).First(&item).Error
  10. return
  11. }
  12. // GetListByCompanyId 根据客户id获取所有的产品信息列表
  13. func GetListByCompanyId(companyId int64) (items []*CompanyProduct, err error) {
  14. err = global.DEFAULT_MYSQL.Where("company_id = ? ", companyId).Find(&items).Error
  15. return
  16. }
  17. // GetByEmail 根据邮箱号号获取信息
  18. func GetByEmail(email string) (item *CompanyProduct, err error) {
  19. err = global.DEFAULT_MYSQL.Where("email = ? ", email).First(&item).Error
  20. return
  21. }
  22. // GetByWhereMap 根据查询条件map获取信息
  23. func GetByWhereMap(where map[string]interface{}) (item *CompanyProduct, err error) {
  24. cond, whereVal, buildErr := utils.WhereBuild(where)
  25. if buildErr != nil {
  26. err = errors.New("系统异常,生成查询语句失败")
  27. return
  28. }
  29. err = global.DEFAULT_MYSQL.Where(cond, whereVal...).First(&item).Error
  30. return
  31. }