activity_points_company.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type CygxActivityPointsCompany struct {
  7. Id int `gorm:"column:id;primary_key;AUTO_INCREMENT" json:"id"`
  8. CompanyId int `gorm:"column:company_id;default:0" json:"company_id"` // 公司ID
  9. CompanyName string `gorm:"column:company_name" json:"company_name"` // 公司名称
  10. Points float64 `gorm:"column:points;default:0;NOT NULL" json:"points"` // 公司剩余点数
  11. CreateTime time.Time `gorm:"column:create_time;NOT NULL" json:"create_time"` // 创建时间
  12. ModifyTime time.Time `gorm:"column:modify_time;NOT NULL" json:"modify_time"` // 更新时间
  13. }
  14. // 获取公司剩余点数
  15. func GetCompanyPoints(companyId int) (comapnyPointsNum float64, err error) {
  16. o := orm.NewOrm()
  17. sql := `SELECT points FROM cygx_activity_points_company WHERE company_id=? `
  18. err = o.Raw(sql, companyId).QueryRow(&comapnyPointsNum)
  19. return
  20. }
  21. // 列表
  22. func GetCygxActivityPointsCompanyList(condition string, pars []interface{}) (items []*CygxActivityPointsCompany, err error) {
  23. o := orm.NewOrm()
  24. sql := `SELECT * FROM cygx_activity_points_company as art WHERE 1= 1 `
  25. if condition != "" {
  26. sql += condition
  27. }
  28. _, err = o.Raw(sql, pars).QueryRows(&items)
  29. return
  30. }
  31. // 获取数量
  32. func GetCygxActivityPointsCompanyCountByCompanyId(companyId int) (count int, err error) {
  33. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_activity_points_company WHERE company_id=? `
  34. o := orm.NewOrm()
  35. err = o.Raw(sqlCount, companyId).QueryRow(&count)
  36. return
  37. }
  38. // 添加
  39. func AddCygxActivityPointsCompany(item *CygxActivityPointsCompany) (err error) {
  40. o := orm.NewOrm()
  41. _, err = o.Insert(item)
  42. return
  43. }