门店红线/黄线统计-写入数据库

This commit is contained in:
Rosy-zhudan
2019-09-29 18:32:55 +08:00
parent 55548ced11
commit 1ef5d248e8
9 changed files with 291 additions and 38 deletions

View File

@@ -2,6 +2,72 @@ package model
import "time"
const (
FieldPickTimeDaDa = "PickTimeDaDa"
FieldBadComment = "BadComment"
FieldAbsentGoods = "AbsentGoods"
FieldPickTimeDaDaOneWeek = "PickTimeDaDaOneWeek"
FieldBadCommentOneWeek = "BadCommentOneWeek"
FieldAbsentGoodsOneWeek = "AbsentGoodsOneWeek"
FieldStandardFinishTimeSelfDelivery = "StandardFinishTimeSelfDelivery"
FieldStandardPickUpTimeDaDa = "StandardPickUpTimeDaDa"
FieldNoOrderInMonth = "NoOrderInMonth"
FieldRiskOrderCount = "RiskOrderCount"
)
type StoreAlert struct {
ID int `orm:"column(id)" json:"id"`
CreatedTime time.Time `orm:"auto_now_add;type(datetime)" json:"createdTime"`
AlertDate time.Time `orm:"auto_now_add;type(datetime)" json:"alertDate"`
StoreID int `orm:"column(store_id)" json:"storeID"`
PickTimeDaDa int `orm:"column(pick_time_order_dada)" json:"pickTimeDaDa"`
BadComment int `orm:"column(bad_comment)" json:"badComment"`
AbsentGoods int `orm:"column(absent_goods)" json:"absentGoods"`
PickTimeDaDaOneWeek int `orm:"column(pick_time_dada_oneweek)" json:"pickTimeDaDaOneWeek"`
BadCommentOneWeek int `orm:"column(bad_comment_oneweek)" json:"badCommentOneWeek"`
AbsentGoodsOneWeek int `orm:"column(absent_goods_oneweek)" json:"absentGoodsOneWeek"`
StandardFinishTimeSelfDelivery int `orm:"column(standard_finish_time_selfdelivery)" json:"standardFinishTimeSelfDelivery"`
StandardPickUpTimeDaDa int `orm:"column(standard_pickup_time_dada)" json:"standardPickUpTimeDaDa"`
NoOrderInMonth int `json:"noOrderInMonth"`
RiskOrderCount int `json:"riskOrderCount"`
}
type StoreAlertEx struct {
StoreAlert
StoreName string `json:"storeName"`
}
type StoreAlertProperty struct {
Value string `json:"value"`
Color string `json:"color"`
}
type StoreAlertAdvanced struct {
ID int `json:"id"`
CreatedTime time.Time `json:"createdTime"`
AlertDate time.Time `json:"alertDate"`
StoreID int `json:"storeID"`
PickTimeDaDa StoreAlertProperty
BadComment StoreAlertProperty
AbsentGoods StoreAlertProperty
PickTimeDaDaOneWeek StoreAlertProperty
BadCommentOneWeek StoreAlertProperty
AbsentGoodsOneWeek StoreAlertProperty
StandardFinishTimeSelfDelivery StoreAlertProperty
StandardPickUpTimeDaDa StoreAlertProperty
NoOrderInMonth StoreAlertProperty
RiskOrderCount StoreAlertProperty
}
type StoreAlertData struct {
StoreAlertList []*StoreAlertEx `json:"storeAlertList"`
TotalCount int `json:"totalCount"`
}
type StoreOrderTime struct {
StoreID int `orm:"column(store_id)"`
OrderCreateTime time.Time `orm:"column(order_created_at)"`
@@ -16,6 +82,6 @@ type StoreOrderStatus struct {
}
type StoreOrder struct {
StoreID int `orm:"column(store_id)"`
VendorOrderID string `orm:"column(vendor_order_id)"`
}
StoreID int `orm:"column(store_id)"`
VendorOrderID string `orm:"column(vendor_order_id)"`
}

View File

@@ -1,3 +1,49 @@
package dao
import (
"fmt"
"time"
"git.rosy.net.cn/jx-callback/business/model"
)
func InsertStoreAlert(storeAlert *model.StoreAlert) error {
storeAlert.CreatedTime = time.Now()
return CreateEntity(nil, storeAlert)
}
func GetStoreAlertList(db *DaoDB, storeIDList []int, cityCode int, keyWord string, beginTime, endTime time.Time) (storeAlertList []*model.StoreAlertEx, err error) {
sql := `
SELECT t1.*
FROM store_alert t1
JOIN store t2 ON t1.store_id = t2.id
JOIN place t3 ON t2.city_code = t3.code
WHERE DATE(t1.alert_date) >= DATE(?) AND DATE(t1.alert_date) <= DATE(?)
`
sqlParams := []interface{}{
beginTime,
endTime,
}
if len(storeIDList) > 0 {
sql += `
AND t2.id in (` + GenQuestionMarks(len(storeIDList)) + `)`
sqlParams = append(sqlParams, storeIDList)
}
if cityCode > 0 {
sql += `
AND t3.code = ?`
sqlParams = append(sqlParams, cityCode)
}
if keyWord != "" {
sql += `
AND (t2.id LIKE ? OR t2.name LIKE ? OR t3.name LIKE ?)`
keyWord = fmt.Sprintf("%%%s%%", keyWord)
sqlParams = append(sqlParams, keyWord, keyWord, keyWord)
}
sql += `
ORDER BY t1.store_id
`
err = GetRows(db, &storeAlertList, sql, sqlParams)
return storeAlertList, err
}