Commit 5489057a by 杨树贤

统计最后一次下单时间

parent 9c80c3b7
...@@ -18,7 +18,7 @@ type GroupDatabase struct { ...@@ -18,7 +18,7 @@ type GroupDatabase struct {
Prefix string Prefix string
} }
//单数据库配置 // 单数据库配置
func BuildDatabaseList() (DatabaseList map[string]BaseDatabase) { func BuildDatabaseList() (DatabaseList map[string]BaseDatabase) {
return map[string]BaseDatabase{ return map[string]BaseDatabase{
"micro": { "micro": {
...@@ -33,12 +33,17 @@ func BuildDatabaseList() (DatabaseList map[string]BaseDatabase) { ...@@ -33,12 +33,17 @@ func BuildDatabaseList() (DatabaseList map[string]BaseDatabase) {
MaxIdleCons: lib.Instance("db").GetInt("supplier.max_idle_conn"), MaxIdleCons: lib.Instance("db").GetInt("supplier.max_idle_conn"),
MaxOpenCons: lib.Instance("db").GetInt("supplier.max_open_conn"), MaxOpenCons: lib.Instance("db").GetInt("supplier.max_open_conn"),
}, },
"purchase": {
DataSourceName: lib.Instance("db").GetString("purchase.data_source_name"),
Prefix: lib.Instance("db").GetString("purchase.table_prefix"),
MaxIdleCons: lib.Instance("db").GetInt("purchase.max_idle_conn"),
MaxOpenCons: lib.Instance("db").GetInt("purchase.max_open_conn"),
},
} }
} }
//主从mysql数据库配置 // 主从mysql数据库配置
func BuildGroupDatabaseList() (DatabaseList map[string]GroupDatabase) { func BuildGroupDatabaseList() (DatabaseList map[string]GroupDatabase) {
return map[string]GroupDatabase{ return map[string]GroupDatabase{}
}
} }
package dao
import (
"fmt"
"go_supplier_sever/app/model"
)
// 获取每个供应商最后一次做单时间
func StatisticsSupplierLastOrderTime() (err error) {
fmt.Println("开始统计供应商最后一次订单时间")
supplier := new(model.Supplier)
//先去根据供应商内部编码找出对应的supplierId
rows, err := Dao.GetDb("supplier").Table("lie_supplier_channel").Where("is_type = ?", 0).OrderBy("supplier_id desc").Rows(supplier)
if err != nil {
return err
}
defer rows.Close()
for rows.Next() {
err = rows.Scan(supplier)
//记录最后一次订单时间
var lastOrderTime int
err = UpdateSupplierLastOrderTime(supplier.SupplierId, lastOrderTime)
if err != nil {
return err
}
}
fmt.Println("执行完成历史有订单的供应")
return
}
type PurchaseOrder struct {
PurchaseId int `json:"purchase_id"`
SupplierId int `json:"supplier_id"`
CreateTime int `json:"create_time"`
}
func UpdateSupplierLastOrderTime(supplierId int, lastOrderTime int) (err error) {
var purchaseOrder PurchaseOrder
supplier := new(model.Supplier)
//先去根据供应商内部编码找出对应的supplierId
_, err = Dao.GetDb("purchase").Table("lie_purchase_order").Where("supplier_id = ?", supplierId).OrderBy("purchase_id desc").Get(&purchaseOrder)
if purchaseOrder.SupplierId == 0 {
lastOrderTime = 0
}
if err != nil {
return err
}
//fmt.Println(purchaseOrder)
supplier.LastOrderTime = purchaseOrder.CreateTime
_, err = Dao.GetDb("supplier").Table("lie_supplier_channel").Where("supplier_id = ?", supplierId).MustCols("last_order_time").Update(supplier)
if err != nil {
return err
}
return
}
...@@ -11,4 +11,5 @@ type Supplier struct { ...@@ -11,4 +11,5 @@ type Supplier struct {
CreateTime int64 CreateTime int64
SkuCreateTime int SkuCreateTime int
SkuUpdateTime int SkuUpdateTime int
LastOrderTime int
} }
...@@ -7,6 +7,13 @@ import ( ...@@ -7,6 +7,13 @@ import (
func StatisticsSupplierSkuStatus() (err error) { func StatisticsSupplierSkuStatus() (err error) {
fmt.Println("开始统计") fmt.Println("开始统计")
err = dao.StatisticsSupplierLastOrderTime()
if err != nil {
return err
}
//return
err = dao.StatisticsSkuCreateTime() err = dao.StatisticsSkuCreateTime()
if err != nil { if err != nil {
return err return err
......
...@@ -29,3 +29,9 @@ ShowSQL = false ...@@ -29,3 +29,9 @@ ShowSQL = false
max_idle_conn = 10 max_idle_conn = 10
table_prefix = "" table_prefix = ""
max_conn_life_time = 100 max_conn_life_time = 100
[purchase]
data_source_name = "liexin_purchase:liexin_purchase#zsyM@tcp(192.168.1.238:3306)/liexin_purchase?charset=utf8&parseTime=true&loc=Asia%2FChongqing"
max_open_conn = 20
max_idle_conn = 10
table_prefix = "lie_"
max_conn_life_time = 100
\ 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