dysy_url_info.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package mysql
  2. import (
  3. orm "dysy/database"
  4. "dysy/tools"
  5. "github.com/jinzhu/gorm"
  6. )
  7. type DysyUrlInfo struct {
  8. AudioURL string `gorm:"column:audio_url" json:"audio_url"`
  9. CreateTime string `gorm:"column:create_time" json:"create_time"`
  10. DeWaterVideoURL string `gorm:"column:de_water_video_url" json:"de_water_video_url"`
  11. Desc string `gorm:"column:desc" json:"desc"`
  12. DouYinBaseHost string `gorm:"column:dou_yin_base_host" json:"dou_yin_base_host"`
  13. DouYinShortURL string `gorm:"column:dou_yin_short_url" json:"dou_yin_short_url"`
  14. Number int `gorm:"column:number" json:"number"`
  15. UpdateTime string `gorm:"column:update_time" json:"update_time"`
  16. VideoPic string `gorm:"column:video_pic" json:"video_pic"`
  17. }
  18. // TableName sets the insert table name for this struct type
  19. func (d *DysyUrlInfo) TableName() string {
  20. return "dysy_url_info"
  21. }
  22. func (d *DysyUrlInfo) Create(deWaterVideoUrl string) (DysyUrlInfo, error) {
  23. var doc DysyUrlInfo
  24. var count = 0
  25. orm.Eloquent.Where("de_water_video_url = ? ", deWaterVideoUrl).Table(d.TableName()).Count(&count)
  26. if count != 0 {
  27. //更新数字加1
  28. //return doc, errors.New(app.ExtOrderIdAgain)
  29. if err := orm.Eloquent.Table(d.TableName()).Model(&doc).Where("de_water_video_url = ? ", deWaterVideoUrl).Updates(
  30. map[string]interface{}{
  31. "number": gorm.Expr("number + 1"),
  32. "update_time": tools.GetCurrntTimeStr()}).Error; err != nil {
  33. return doc, err
  34. }
  35. return doc, nil
  36. }
  37. result := orm.Eloquent.Table(d.TableName()).Create(&d)
  38. if result.Error != nil {
  39. err := result.Error
  40. return doc, err
  41. }
  42. doc = *d
  43. return doc, nil
  44. }