Commit 6cd9a63a by 杨树贤

线上测试

parent e300fe09
......@@ -263,6 +263,24 @@ func UpdateSupplierSkuLog(supplierId int, skuNum int) (err error) {
return
}
// 修改sku_expired_in_days
func UpdateSupplierSkuExpiredInDays(supplierId, skuExpiredInDays int) (err error) {
supplier := new(model.Supplier)
_, err = Dao.GetDb("supplier").Table("lie_supplier_channel").Where("supplier_id = ?", supplierId).Get(supplier)
if supplier.SupplierId == 0 {
return err
}
if err != nil {
return err
}
supplier.SkuExpiredInDays = skuExpiredInDays
_, err = Dao.GetDb("supplier").Table("lie_supplier_channel").Where("supplier_id = ?", supplierId).MustCols("sku_expired_in_days").Update(supplier)
if err != nil {
return err
}
return
}
// 修改sku_mode
func UpdateSupplierSkuMode(supplierId, skuMode int) (err error) {
supplier := new(model.Supplier)
......
package model
type Supplier struct {
SupplierId int
SupplierCode string
SupplierName string
UploadedSku int
SkuNum int
SkuMode int
AverageSkuNum float64
CreateTime int64
SkuCreateTime int
SkuUpdateTime int
LastOrderTime int
SupplierId int
SupplierCode string
SupplierName string
UploadedSku int
SkuNum int
SkuMode int
AverageSkuNum float64
CreateTime int64
SkuCreateTime int
SkuUpdateTime int
LastOrderTime int
SkuExpiredInDays int
}
......@@ -2,18 +2,26 @@ package service
import (
"fmt"
"time"
"go_supplier_sever/app/dao"
"go_supplier_sever/app/model"
"github.com/ichunt2019/cfg/lib"
"github.com/imroc/req"
"github.com/tidwall/gjson"
"go_supplier_sever/app/dao"
"go_supplier_sever/app/model"
)
//从ES统计出sku类型,然后写到供应商的sku_mode字段
// 从ES统计出sku类型,然后写到供应商的sku_mode字段
func SaveSkuModeFromES() (err error) {
supplier := new(model.Supplier)
//先去根据供应商内部编码找出对应的supplierId
rows, err := dao.Dao.GetDb("supplier").Table("lie_supplier_channel").Where("is_type = ?", 0).OrderBy("supplier_id desc").Rows(supplier)
rows, err := dao.Dao.GetDb("supplier").Table("lie_supplier_channel").
// Where("supplier_code = ?", "L0001175").
Where("is_type = ?", 0).
Where("uploaded_sku = ?", 1).
OrderBy("supplier_id desc").
Rows(supplier)
if err != nil {
return err
}
......@@ -24,8 +32,9 @@ func SaveSkuModeFromES() (err error) {
err = rows.Scan(supplier)
//去es查询sku数量
params := req.Param{
"status/condition": 1,
"canal/condition": supplier.SupplierCode,
"canal/condition": supplier.SupplierCode,
"cp_time/sort": "asc",
"cp_time/neq": 0,
}
url := lib.Instance("config").GetString("es.es_sku_url")
resp, err := req.Post(url, params)
......@@ -34,8 +43,9 @@ func SaveSkuModeFromES() (err error) {
}
result := resp.String()
goodsIdArr := gjson.Get(result, "data.goods_id").Array()
//fmt.Println("当前处理供应商为 : ", supplier.SupplierName)
// fmt.Println("当前处理供应商为 : ", supplier.SupplierName)
if len(goodsIdArr) > 0 {
fmt.Println("存在商品")
//取一个goods_id就好
goodsId := goodsIdArr[0].String()
//fmt.Println("skuId为 : " + goodsId)
......@@ -57,11 +67,42 @@ func SaveSkuModeFromES() (err error) {
return err
}
}
//统计sku过期天数:ES已按cp_time升序排序,取第一个goods_id的cp_time即可
sku := redisCon.HGet("sku", goodsId).String()
skuExpiredInDays := 0
cpTime := gjson.Get(sku, "cp_time").Int()
fmt.Println("cpTime:", cpTime)
if cpTime > 0 {
//cp_time是时间戳,转成日期和当前日期对比计算天数
cpTimeDate := time.Unix(cpTime, 0)
nowDate := time.Now()
//计算cp_time日期和当前日期的天数差
cpTimeDay := time.Date(cpTimeDate.Year(), cpTimeDate.Month(), cpTimeDate.Day(), 0, 0, 0, 0, cpTimeDate.Location())
nowDay := time.Date(nowDate.Year(), nowDate.Month(), nowDate.Day(), 0, 0, 0, 0, nowDate.Location())
daysDiff := int(nowDay.Sub(cpTimeDay).Hours() / 24)
//如果过期了(当前日期 > cp_time日期),则为正数,否则为0
if daysDiff > 0 {
skuExpiredInDays = daysDiff
}
}
if skuExpiredInDays > 0 {
fmt.Println("sku过期天数 : ", skuExpiredInDays)
}
err = dao.UpdateSupplierSkuExpiredInDays(supplier.SupplierId, skuExpiredInDays)
if err != nil {
return err
}
} else {
err = dao.UpdateSupplierSkuMode(supplier.SupplierId, 0)
if err != nil {
return err
}
//没有sku的那就是1000
err = dao.UpdateSupplierSkuExpiredInDays(supplier.SupplierId, 1000)
if err != nil {
return err
}
}
//time.Sleep(100 * time.Millisecond)
}
......
......@@ -2,4 +2,4 @@
url = "amqp://guest:guest@192.168.1.252:5672/"
[es]
es_sku_url = "http://so.liexin.net/search/Es/searchSku"
\ No newline at end of file
es_sku_url = "https://icso.ichunt.com/search/es/searchSku"
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment