12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- package mysql
- import (
- orm "dysy/database"
- "dysy/tools"
- "github.com/jinzhu/gorm"
- )
- type DysyUrlInfo struct {
- AudioURL string `gorm:"column:audio_url" json:"audio_url"`
- CreateTime string `gorm:"column:create_time" json:"create_time"`
- DeWaterVideoURL string `gorm:"column:de_water_video_url" json:"de_water_video_url"`
- Desc string `gorm:"column:desc" json:"desc"`
- DouYinBaseHost string `gorm:"column:dou_yin_base_host" json:"dou_yin_base_host"`
- DouYinShortURL string `gorm:"column:dou_yin_short_url" json:"dou_yin_short_url"`
- Number int `gorm:"column:number" json:"number"`
- UpdateTime string `gorm:"column:update_time" json:"update_time"`
- VideoPic string `gorm:"column:video_pic" json:"video_pic"`
- }
- // TableName sets the insert table name for this struct type
- func (d *DysyUrlInfo) TableName() string {
- return "dysy_url_info"
- }
- func (d *DysyUrlInfo) Create(deWaterVideoUrl string) (DysyUrlInfo, error) {
- var doc DysyUrlInfo
- var count = 0
- orm.Eloquent.Where("de_water_video_url = ? ", deWaterVideoUrl).Table(d.TableName()).Count(&count)
- if count != 0 {
- //更新数字加1
- //return doc, errors.New(app.ExtOrderIdAgain)
- if err := orm.Eloquent.Table(d.TableName()).Model(&doc).Where("de_water_video_url = ? ", deWaterVideoUrl).Updates(
- map[string]interface{}{
- "number": gorm.Expr("number + 1"),
- "update_time": tools.GetCurrntTimeStr()}).Error; err != nil {
- return doc, err
- }
- return doc, nil
- }
- result := orm.Eloquent.Table(d.TableName()).Create(&d)
- if result.Error != nil {
- err := result.Error
- return doc, err
- }
- doc = *d
- return doc, nil
- }
|