company_product.go 1020 B

12345678910111213141516171819202122232425262728293031
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. )
  5. // 获取是否属于权益客户
  6. func GetCompanyProductCount(companyId, productId int) (count int, err error) {
  7. o := orm.NewOrmUsingDB("weekly_report")
  8. sql := `SELECT COUNT(1) AS count FROM company_product WHERE company_id = ? AND product_id = ? AND company_id > 1 `
  9. err = o.Raw(sql, companyId, productId).QueryRow(&count)
  10. return
  11. }
  12. // 获取列表
  13. func GetCompanyProductList(condition string, pars []interface{}) (items []*CompanyProduct, err error) {
  14. o := orm.NewOrmUsingDB("weekly_report")
  15. sql := `SELECT * FROM company_product WHERE 1= 1 `
  16. if condition != "" {
  17. sql += condition
  18. }
  19. _, err = o.Raw(sql, pars).QueryRows(&items)
  20. return
  21. }
  22. func GetCompanyProductDetailByCompanyId(companyId, productId int) (item *CompanyProduct, err error) {
  23. sql := ` SELECT * FROM company_product WHERE company_id = ? AND product_id = ?; `
  24. o := orm.NewOrmUsingDB("weekly_report")
  25. err = o.Raw(sql, companyId, productId).QueryRow(&item)
  26. return
  27. }