parent
4be28a4b80
commit
fc07641fa2
@ -0,0 +1,5 @@
|
||||
package constant
|
||||
|
||||
const (
|
||||
RedisKeyPromotionGoodsList = "lists:promotion:goods"
|
||||
)
|
@ -0,0 +1,36 @@
|
||||
package aliyun
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"live/app/lib/config"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
client = &http.Client{}
|
||||
appCode = config.Config.Section("aliyun").Key("appCode").String()
|
||||
)
|
||||
|
||||
// @Title 请求
|
||||
func request(method, url, data string, headers ...map[string]string) ([]byte, error) {
|
||||
reqest, err := http.NewRequest(method, url, strings.NewReader(data))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(headers) > 0 {
|
||||
for key, value := range headers[0] {
|
||||
reqest.Header.Add(key, value)
|
||||
}
|
||||
}
|
||||
response, err := client.Do(reqest)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer response.Body.Close()
|
||||
result, err := ioutil.ReadAll(response.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
package aliyun
|
||||
|
||||
// @Title 文本检测
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
const (
|
||||
actionTextUrl = "http://monitoring.market.alicloudapi.com/neirongjiance"
|
||||
)
|
||||
|
||||
type text struct {
|
||||
}
|
||||
|
||||
var (
|
||||
Text = &text{}
|
||||
)
|
||||
|
||||
type textResult struct {
|
||||
Success bool `json:"success"`
|
||||
Status int `json:"status"`
|
||||
Data struct {
|
||||
Out []CheckText `json:"out"`
|
||||
} `json:"data"`
|
||||
}
|
||||
|
||||
type CheckText struct {
|
||||
Politics []string `json:"政治敏感监测"`
|
||||
Contraband []string `json:"违禁品监测"`
|
||||
Irrigation []bool `json:"恶意灌水监测"`
|
||||
Salacity []string `json:"色情监测"`
|
||||
Abuse []string `json:"辱骂监测"`
|
||||
}
|
||||
|
||||
// @Title 敏感词检测
|
||||
func (o *text) CheckText(text string) (result CheckText, err error) {
|
||||
data := url.Values{
|
||||
"in": []string{text},
|
||||
}
|
||||
resByte, err := o.exec(actionTextUrl, data.Encode())
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
res := textResult{}
|
||||
err = json.Unmarshal(resByte, &res)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if len(res.Data.Out) > 0 {
|
||||
result = res.Data.Out[0]
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// @Title 执行请求
|
||||
func (o *text) exec(action, data string) ([]byte, error) {
|
||||
return request("POST", action, data, map[string]string{
|
||||
"Authorization": "APPCODE " + appCode,
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
})
|
||||
}
|
File diff suppressed because one or more lines are too long
@ -0,0 +1,52 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"github.com/go-redis/redis"
|
||||
"live/app/lib/config"
|
||||
"time"
|
||||
)
|
||||
|
||||
type RedisConfig struct {
|
||||
Name string `toml:"name"`
|
||||
Proto string `toml:"proto"`
|
||||
Addr string `toml:"addr"`
|
||||
Idle int `toml:"idle"`
|
||||
Active int `toml:"active"`
|
||||
DialTimeout int `toml:"dialTimeout"`
|
||||
ReadTimeout int `toml:"readTimeout"`
|
||||
WriteTimeout int `toml:"writeTimeout"`
|
||||
IdleTimeout int `toml:"idleTimeout"`
|
||||
}
|
||||
|
||||
var (
|
||||
Redis *redis.Client
|
||||
)
|
||||
|
||||
func init() {
|
||||
addr := config.Config.Section("redis").Key("addr").String()
|
||||
password := config.Config.Section("redis").Key("password").String()
|
||||
|
||||
c := &RedisConfig{
|
||||
Name: "recook.redis",
|
||||
Addr: addr,
|
||||
Idle: 10,
|
||||
Active: 10,
|
||||
DialTimeout: 1,
|
||||
ReadTimeout: 1,
|
||||
WriteTimeout: 1,
|
||||
IdleTimeout: 10,
|
||||
}
|
||||
|
||||
Redis = redis.NewClient(&redis.Options{
|
||||
Addr: c.Addr,
|
||||
Password: password,
|
||||
DB: 0, // use default DB
|
||||
ReadTimeout: time.Duration(c.ReadTimeout) * time.Second,
|
||||
WriteTimeout: time.Duration(c.WriteTimeout) * time.Second,
|
||||
})
|
||||
|
||||
_, err := Redis.Ping().Result()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package promotion
|
||||
|
||||
import (
|
||||
"github.com/golangkit/formatime"
|
||||
"live/app/lib/db"
|
||||
"time"
|
||||
)
|
||||
|
||||
type PromotionGoods struct {
|
||||
db.BaseModel
|
||||
Id uint `gorm:"column:id" json:"id"`
|
||||
PromotionTimeItemId uint `gorm:"column:promotion_time_item_id" json:"promotionTimeItemId"`
|
||||
GoodsId uint `gorm:"column:goods_id" json:"goodsId"`
|
||||
PromotionStartDate formatime.Date `gorm:"column:promotion_start_date" json:"promotionStartDate"`
|
||||
Order uint `gorm:"column:order" json:"order"`
|
||||
}
|
||||
|
||||
func (p *PromotionGoods) TableName() string {
|
||||
return "recook_promotion_goods"
|
||||
}
|
||||
|
||||
// @Title 获取当日所有数据
|
||||
func (p *PromotionGoods) GetDayAll() (result []PromotionGoods) {
|
||||
day := time.Now().Format("2006-01-02")
|
||||
day = "2020-09-19"
|
||||
p.GetDb().Model(p).Where("promotion_start_date = ?", day).Order("promotion_time_item_id,`order`").Find(&result)
|
||||
return
|
||||
}
|
Loading…
Reference in new issue