k.zhang 4 years ago
parent
commit
af0ada92bf
2 changed files with 52 additions and 0 deletions
  1. 5 0
      apis/dyjx/url_jx.go
  2. 47 0
      models/mysql/dysy_two_url.go

+ 5 - 0
apis/dyjx/url_jx.go

@@ -135,6 +135,11 @@ func DeWater(in models.DyJieXiInput) (error, models.DyJieXiOutput) {
 	comma = strings.Index(out.Data.VideoUrl, "https://")
 	pos = strings.Index(out.Data.VideoUrl[comma+1:], ".com")
 	fmt.Println(out.Data.VideoUrl[comma : pos+comma+4+1])
+	var twoUrl mysql.DysyTwoUrl
+	twoUrl.CreateTime = tools.GetCurrntTimeStr()
+	twoUrl.UpdateTime = tools.GetCurrntTimeStr()
+	twoUrl.TwoURL = out.Data.VideoUrl[comma : pos+comma+4+1]
+	twoUrl.Create(twoUrl.TwoURL)
 
 	return nil, out
 

+ 47 - 0
models/mysql/dysy_two_url.go

@@ -0,0 +1,47 @@
+package mysql
+
+import (
+	orm "dysy/database"
+	"dysy/tools"
+	"github.com/jinzhu/gorm"
+)
+
+type DysyTwoUrl struct {
+	CreateTime string `gorm:"column:create_time" json:"create_time"`
+	ID         int64  `gorm:"column:id;primary_key" json:"id"`
+	Number     int    `gorm:"column:number" json:"number"`
+	TwoURL     string `gorm:"column:two_url" json:"two_url"`
+	UpdateTime string `gorm:"column:update_time" json:"update_time"`
+}
+
+// TableName sets the insert table name for this struct type
+func (d DysyTwoUrl) TableName() string {
+	return "dysy_two_url"
+}
+func (d *DysyTwoUrl) Create(twoUrl string) (DysyTwoUrl, error) {
+	var doc DysyTwoUrl
+	var count = 0
+
+	orm.Eloquent.Where("two_url = ? ", twoUrl).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("two_url = ? ", twoUrl).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
+}