价格统计
This commit is contained in:
@@ -140,6 +140,7 @@ func InitServiceInfo(version string, buildTime time.Time, gitCommit string) {
|
||||
"refundStatusName": model.RefundStatusName,
|
||||
"autoReplyTypeName": model.AutoReplyTypeName,
|
||||
"complaintReasons": model.ComplaintReasons,
|
||||
"supplementType": model.SupplementTypeName,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ func Init() {
|
||||
cms.CurVendorSync.ChangeStoreSkuSaleStatus(jxcontext.AdminCtx, 0, true, true)
|
||||
}, ChangeStoreSkuSaleStatusList)
|
||||
ScheduleTimerFunc("BeginSavePriceRefer", func() {
|
||||
report.BeginSavePriceRefer(jxcontext.AdminCtx, nil, nil)
|
||||
report.BeginSavePriceRefer(jxcontext.AdminCtx, nil, nil, true, true)
|
||||
}, priceReferTimeList)
|
||||
ScheduleTimerFunc("CreateStorePriceScore", func() {
|
||||
cms.CreateStorePriceScore(jxcontext.AdminCtx)
|
||||
|
||||
@@ -14,6 +14,14 @@ import (
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
)
|
||||
|
||||
type tStoreSkuBindAndSkuName struct {
|
||||
CityCode int
|
||||
StoreID int `orm:"column(store_id)"`
|
||||
NameID int `orm:"column(name_id)"`
|
||||
UnitPrice int
|
||||
UnitPriceList []int
|
||||
}
|
||||
|
||||
func GetStatisticsReportForOrders(ctx *jxcontext.Context, storeIDs []int, fromDate string, toDate string) (statisticsReportForOrdersList []*dao.StatisticsReportForOrdersList, err error) {
|
||||
db := dao.GetDB()
|
||||
fromDateParm := utils.Str2Time(fromDate)
|
||||
@@ -52,9 +60,12 @@ func StatisticsReportForStoreSkusPrice(ctx *jxcontext.Context, cityCodes, skuIDs
|
||||
return
|
||||
}
|
||||
|
||||
func BeginSavePriceRefer(ctx *jxcontext.Context, cityCodes, skuIDs []int) (err error) {
|
||||
func BeginSavePriceRefer(ctx *jxcontext.Context, cityCodes, skuIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
db := dao.GetDB()
|
||||
snapshotAt := utils.Time2Date(time.Now().AddDate(0, 0, -1))
|
||||
taskSeqFunc := func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
|
||||
switch step {
|
||||
case 0:
|
||||
priceReferSnapshot, err := dao.GetStatisticsReportForStoreSkusPrice(db, cityCodes, skuIDs)
|
||||
if len(priceReferSnapshot) > 0 {
|
||||
dao.Begin(db)
|
||||
@@ -69,18 +80,70 @@ func BeginSavePriceRefer(ctx *jxcontext.Context, cityCodes, skuIDs []int) (err e
|
||||
dao.DeletePriceReferHistory(db, utils.Time2Date(snapshotAt.AddDate(0, 0, -7)))
|
||||
priceReferSnapshotDelete := &model.PriceReferSnapshot{SnapshotAt: snapshotAt}
|
||||
dao.DeleteEntity(db, priceReferSnapshotDelete, "SnapshotAt")
|
||||
task := tasksch.NewParallelTask("生成价格统计", tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
taskFunc := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
v := batchItemList[0].(*model.PriceReferSnapshot)
|
||||
dao.WrapAddIDCULDEntity(v, ctx.GetUserName())
|
||||
v.SnapshotAt = snapshotAt
|
||||
err = dao.CreateEntity(db, v)
|
||||
return retVal, err
|
||||
}, priceReferSnapshot)
|
||||
tasksch.HandleTask(task, nil, true).Run()
|
||||
_, err = task.GetResult(0)
|
||||
}
|
||||
taskParallel := tasksch.NewParallelTask("生成价格统计", tasksch.NewParallelConfig(), ctx, taskFunc, priceReferSnapshot)
|
||||
tasksch.HandleTask(taskParallel, task, true).Run()
|
||||
_, err = taskParallel.GetResult(0)
|
||||
dao.Commit(db)
|
||||
}
|
||||
case 1:
|
||||
var (
|
||||
// citySkuMap = make(map[int]map[int][]int)
|
||||
tList []*tStoreSkuBindAndSkuName
|
||||
)
|
||||
storeList, err := dao.GetStoreList(db, nil, nil, "")
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
for _, v := range storeList {
|
||||
sql := `
|
||||
SELECT DISTINCT b.city_code,a.store_id,a.unit_price,c.name_id
|
||||
FROM store_sku_bind a
|
||||
JOIN store b ON b.id = a.store_id AND b.deleted_at = ? AND b.status != ?
|
||||
JOIN sku c ON c.id = a.sku_id
|
||||
WHERE a.store_id = ?
|
||||
AND c.name_id NOT IN(
|
||||
SELECT b.name_id
|
||||
FROM store_sku_bind a
|
||||
JOIN sku b ON a.sku_id = b.id AND b.deleted_at = ?
|
||||
WHERE a.deleted_at = ?
|
||||
AND a.store_id = ?
|
||||
AND b.name_id NOT IN(SELECT DISTINCT b.name_id
|
||||
FROM store_sku_bind a
|
||||
JOIN sku b ON a.sku_id = b.id AND b.deleted_at = ?
|
||||
WHERE a.deleted_at = ?
|
||||
AND a.store_id = ?
|
||||
AND a.status = ?)
|
||||
)
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
model.StoreStatusDisabled,
|
||||
v.ID,
|
||||
utils.DefaultTimeValue,
|
||||
utils.DefaultTimeValue,
|
||||
v.ID,
|
||||
utils.DefaultTimeValue,
|
||||
utils.DefaultTimeValue,
|
||||
v.ID,
|
||||
model.StoreSkuBindStatusNormal,
|
||||
}
|
||||
dao.GetRows(db, &tList, sql, sqlParams...)
|
||||
// for _, vv := range tList {
|
||||
// if citySkuMap[vv.CityCode] != nil {
|
||||
|
||||
// } else {
|
||||
// citySkuMap[vv.CityCode] =
|
||||
// }
|
||||
// }
|
||||
}
|
||||
case 2:
|
||||
priceReferSnapshotList, err := dao.GetPriceReferSnapshotNoPage(db, nil, nil, nil, snapshotAt)
|
||||
dao.Begin(db)
|
||||
defer func() {
|
||||
@@ -102,5 +165,16 @@ func BeginSavePriceRefer(ctx *jxcontext.Context, cityCodes, skuIDs []int) (err e
|
||||
}
|
||||
}
|
||||
dao.Commit(db)
|
||||
return err
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
taskSeq := tasksch.NewSeqTask2("生成每日价格统计", ctx, isContinueWhenError, taskSeqFunc, 4)
|
||||
tasksch.HandleTask(taskSeq, nil, true).Run()
|
||||
if !isAsync {
|
||||
_, err = taskSeq.GetResult(0)
|
||||
hint = "1"
|
||||
} else {
|
||||
hint = taskSeq.GetID()
|
||||
}
|
||||
return hint, err
|
||||
}
|
||||
|
||||
@@ -98,6 +98,11 @@ var (
|
||||
ComplaintReasons71: "骑手提前点击取货/送达",
|
||||
}
|
||||
|
||||
SupplementTypeName = map[int]string{
|
||||
BadAppraiseSupplement: "差评退款",
|
||||
Coupon: "优惠券",
|
||||
}
|
||||
|
||||
MultiStoresVendorMap = map[int]int{
|
||||
VendorIDJD: 1,
|
||||
VendorIDMTWM: 0,
|
||||
@@ -229,6 +234,11 @@ const (
|
||||
ComplaintReasons71 = 71 //"骑手提前点击取货/送达",
|
||||
)
|
||||
|
||||
const (
|
||||
BadAppraiseSupplement = 1 //差评退款
|
||||
Coupon = 2 //优惠券
|
||||
)
|
||||
|
||||
const (
|
||||
WaybillStatusRefuseFailedGetGoods = -70
|
||||
WaybillStatusUnknown = 0
|
||||
|
||||
@@ -79,7 +79,7 @@ func (c *ReportController) StatisticsReportForStoreSkusPrice() {
|
||||
// @router /PriceRefer [post]
|
||||
func (c *ReportController) PriceRefer() {
|
||||
c.callPriceRefer(func(params *tReportPriceReferParams) (retVal interface{}, errCode string, err error) {
|
||||
report.BeginSavePriceRefer(params.Ctx, nil, nil)
|
||||
report.BeginSavePriceRefer(params.Ctx, nil, nil, true, true)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
@@ -416,7 +416,7 @@ func init() {
|
||||
beego.ControllerComments{
|
||||
Method: "SendFilesToStores",
|
||||
Router: `/SendFilesToStores`,
|
||||
AllowHTTPMethods: []string{"post", "get"},
|
||||
AllowHTTPMethods: []string{"post","get"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
@@ -877,7 +877,7 @@ func init() {
|
||||
beego.ControllerComments{
|
||||
Method: "GetAfsOrders",
|
||||
Router: `/GetAfsOrders`,
|
||||
AllowHTTPMethods: []string{"get", "post"},
|
||||
AllowHTTPMethods: []string{"get","post"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
@@ -931,7 +931,7 @@ func init() {
|
||||
beego.ControllerComments{
|
||||
Method: "GetOrders",
|
||||
Router: `/GetOrders`,
|
||||
AllowHTTPMethods: []string{"get", "post"},
|
||||
AllowHTTPMethods: []string{"get","post"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
@@ -1246,7 +1246,7 @@ func init() {
|
||||
beego.ControllerComments{
|
||||
Method: "GetSkuNames",
|
||||
Router: `/GetSkuNames`,
|
||||
AllowHTTPMethods: []string{"get", "post"},
|
||||
AllowHTTPMethods: []string{"get","post"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
@@ -1498,7 +1498,7 @@ func init() {
|
||||
beego.ControllerComments{
|
||||
Method: "GetStores",
|
||||
Router: `/GetStores`,
|
||||
AllowHTTPMethods: []string{"get", "post"},
|
||||
AllowHTTPMethods: []string{"get","post"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
@@ -1705,7 +1705,7 @@ func init() {
|
||||
beego.ControllerComments{
|
||||
Method: "GetStoresSkus",
|
||||
Router: `/GetStoresSkus`,
|
||||
AllowHTTPMethods: []string{"get", "post"},
|
||||
AllowHTTPMethods: []string{"get","post"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
@@ -1930,7 +1930,7 @@ func init() {
|
||||
beego.ControllerComments{
|
||||
Method: "SyncSkuNames",
|
||||
Router: `/SyncSkuNames`,
|
||||
AllowHTTPMethods: []string{"put", "post"},
|
||||
AllowHTTPMethods: []string{"put","post"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
@@ -2335,7 +2335,7 @@ func init() {
|
||||
beego.ControllerComments{
|
||||
Method: "LoadExcelByYongHui",
|
||||
Router: `/LoadExcelByYongHui`,
|
||||
AllowHTTPMethods: []string{"post", "get"},
|
||||
AllowHTTPMethods: []string{"post","get"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
Reference in New Issue
Block a user