panel.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package dao
  2. import (
  3. "go-common/app/admin/main/tv/model"
  4. "go-common/library/log"
  5. )
  6. const (
  7. _configTableName = "tv_price_config"
  8. _valid = 0
  9. _invalid = 1
  10. )
  11. // GetById select panel info by id
  12. func (d *Dao) GetById(id int64) (panelInfo *model.TvPriceConfigResp, err error) {
  13. panelInfo = &model.TvPriceConfigResp{}
  14. if err = d.DB.Table(_configTableName).Where("id = ? and status in (?, ?)", id, _valid, _invalid).First(panelInfo).Error; err != nil {
  15. log.Error("GetById (%v) error(%v)", panelInfo, err)
  16. }
  17. return
  18. }
  19. // PanelStatus update panel status info by id
  20. func (d *Dao) PanelStatus(id, status int64) (err error) {
  21. if err = d.DB.Table(_configTableName).Where("id = ? and status in (?, ?)", id, _valid, _invalid).Update("status", status).Error; err != nil {
  22. log.Error("PanelStatus (%v) error(%v)", id, err)
  23. }
  24. return
  25. }
  26. // SavePanel update or add panel info
  27. func (d *Dao) SavePanel(panel *model.TvPriceConfig) (err error) {
  28. if err = d.DB.Save(panel).Error; err != nil {
  29. log.Error("SavePanel (%v) error(%v)", panel, err)
  30. return err
  31. }
  32. return
  33. }
  34. // ExistProduct check duplicated productId, productName
  35. func (d *Dao) ExistProduct(productID string) (flag bool) {
  36. panel := []model.TvPriceConfig{}
  37. if err := d.DB.Table(_configTableName).Where("status in (?, ?) and product_id = ?", _valid, _invalid, productID).Find(&panel).Error; err != nil {
  38. log.Error("HasDiscount %v, Err %v", productID, err)
  39. return false
  40. }
  41. return !(len(panel) == 0)
  42. }