价格统计
This commit is contained in:
@@ -140,6 +140,7 @@ func InitServiceInfo(version string, buildTime time.Time, gitCommit string) {
|
|||||||
"refundStatusName": model.RefundStatusName,
|
"refundStatusName": model.RefundStatusName,
|
||||||
"autoReplyTypeName": model.AutoReplyTypeName,
|
"autoReplyTypeName": model.AutoReplyTypeName,
|
||||||
"complaintReasons": model.ComplaintReasons,
|
"complaintReasons": model.ComplaintReasons,
|
||||||
|
"supplementType": model.SupplementTypeName,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -141,7 +141,7 @@ func Init() {
|
|||||||
cms.CurVendorSync.ChangeStoreSkuSaleStatus(jxcontext.AdminCtx, 0, true, true)
|
cms.CurVendorSync.ChangeStoreSkuSaleStatus(jxcontext.AdminCtx, 0, true, true)
|
||||||
}, ChangeStoreSkuSaleStatusList)
|
}, ChangeStoreSkuSaleStatusList)
|
||||||
ScheduleTimerFunc("BeginSavePriceRefer", func() {
|
ScheduleTimerFunc("BeginSavePriceRefer", func() {
|
||||||
report.BeginSavePriceRefer(jxcontext.AdminCtx, nil, nil)
|
report.BeginSavePriceRefer(jxcontext.AdminCtx, nil, nil, true, true)
|
||||||
}, priceReferTimeList)
|
}, priceReferTimeList)
|
||||||
ScheduleTimerFunc("CreateStorePriceScore", func() {
|
ScheduleTimerFunc("CreateStorePriceScore", func() {
|
||||||
cms.CreateStorePriceScore(jxcontext.AdminCtx)
|
cms.CreateStorePriceScore(jxcontext.AdminCtx)
|
||||||
|
|||||||
@@ -14,6 +14,14 @@ import (
|
|||||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
"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) {
|
func GetStatisticsReportForOrders(ctx *jxcontext.Context, storeIDs []int, fromDate string, toDate string) (statisticsReportForOrdersList []*dao.StatisticsReportForOrdersList, err error) {
|
||||||
db := dao.GetDB()
|
db := dao.GetDB()
|
||||||
fromDateParm := utils.Str2Time(fromDate)
|
fromDateParm := utils.Str2Time(fromDate)
|
||||||
@@ -52,55 +60,121 @@ func StatisticsReportForStoreSkusPrice(ctx *jxcontext.Context, cityCodes, skuIDs
|
|||||||
return
|
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()
|
db := dao.GetDB()
|
||||||
snapshotAt := utils.Time2Date(time.Now().AddDate(0, 0, -1))
|
snapshotAt := utils.Time2Date(time.Now().AddDate(0, 0, -1))
|
||||||
priceReferSnapshot, err := dao.GetStatisticsReportForStoreSkusPrice(db, cityCodes, skuIDs)
|
taskSeqFunc := func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
|
||||||
if len(priceReferSnapshot) > 0 {
|
switch step {
|
||||||
dao.Begin(db)
|
case 0:
|
||||||
defer func() {
|
priceReferSnapshot, err := dao.GetStatisticsReportForStoreSkusPrice(db, cityCodes, skuIDs)
|
||||||
if r := recover(); r != nil || err != nil {
|
if len(priceReferSnapshot) > 0 {
|
||||||
dao.Rollback(db)
|
dao.Begin(db)
|
||||||
if r != nil {
|
defer func() {
|
||||||
panic(r)
|
if r := recover(); r != nil || err != nil {
|
||||||
|
dao.Rollback(db)
|
||||||
|
if r != nil {
|
||||||
|
panic(r)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
dao.DeletePriceReferHistory(db, utils.Time2Date(snapshotAt.AddDate(0, 0, -7)))
|
||||||
|
priceReferSnapshotDelete := &model.PriceReferSnapshot{SnapshotAt: snapshotAt}
|
||||||
|
dao.DeleteEntity(db, priceReferSnapshotDelete, "SnapshotAt")
|
||||||
|
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
|
||||||
|
}
|
||||||
|
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() {
|
||||||
|
if r := recover(); r != nil || err != nil {
|
||||||
|
dao.Rollback(db)
|
||||||
|
if r != nil {
|
||||||
|
panic(r)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
if len(priceReferSnapshotList) > 0 {
|
||||||
|
for _, v := range priceReferSnapshotList {
|
||||||
|
result, _ := dao.GetPriceReferPrice(db, v.CityCode, v.SkuID, snapshotAt)
|
||||||
|
v.MaxPrice = result.MaxPrice
|
||||||
|
v.MinPrice = result.MinPrice
|
||||||
|
v.AvgPrice = result.AvgPrice
|
||||||
|
v.MidPrice = result.MidPrice
|
||||||
|
dao.UpdateEntity(db, v, "MidPrice", "MaxPrice", "MinPrice", "AvgPrice")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
dao.Commit(db)
|
||||||
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) {
|
|
||||||
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)
|
|
||||||
dao.Commit(db)
|
|
||||||
}
|
|
||||||
priceReferSnapshotList, err := dao.GetPriceReferSnapshotNoPage(db, nil, nil, nil, snapshotAt)
|
|
||||||
dao.Begin(db)
|
|
||||||
defer func() {
|
|
||||||
if r := recover(); r != nil || err != nil {
|
|
||||||
dao.Rollback(db)
|
|
||||||
if r != nil {
|
|
||||||
panic(r)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
if len(priceReferSnapshotList) > 0 {
|
|
||||||
for _, v := range priceReferSnapshotList {
|
|
||||||
result, _ := dao.GetPriceReferPrice(db, v.CityCode, v.SkuID, snapshotAt)
|
|
||||||
v.MaxPrice = result.MaxPrice
|
|
||||||
v.MinPrice = result.MinPrice
|
|
||||||
v.AvgPrice = result.AvgPrice
|
|
||||||
v.MidPrice = result.MidPrice
|
|
||||||
dao.UpdateEntity(db, v, "MidPrice", "MaxPrice", "MinPrice", "AvgPrice")
|
|
||||||
}
|
}
|
||||||
|
return result, err
|
||||||
}
|
}
|
||||||
dao.Commit(db)
|
taskSeq := tasksch.NewSeqTask2("生成每日价格统计", ctx, isContinueWhenError, taskSeqFunc, 4)
|
||||||
return err
|
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: "骑手提前点击取货/送达",
|
ComplaintReasons71: "骑手提前点击取货/送达",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SupplementTypeName = map[int]string{
|
||||||
|
BadAppraiseSupplement: "差评退款",
|
||||||
|
Coupon: "优惠券",
|
||||||
|
}
|
||||||
|
|
||||||
MultiStoresVendorMap = map[int]int{
|
MultiStoresVendorMap = map[int]int{
|
||||||
VendorIDJD: 1,
|
VendorIDJD: 1,
|
||||||
VendorIDMTWM: 0,
|
VendorIDMTWM: 0,
|
||||||
@@ -229,6 +234,11 @@ const (
|
|||||||
ComplaintReasons71 = 71 //"骑手提前点击取货/送达",
|
ComplaintReasons71 = 71 //"骑手提前点击取货/送达",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
BadAppraiseSupplement = 1 //差评退款
|
||||||
|
Coupon = 2 //优惠券
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
WaybillStatusRefuseFailedGetGoods = -70
|
WaybillStatusRefuseFailedGetGoods = -70
|
||||||
WaybillStatusUnknown = 0
|
WaybillStatusUnknown = 0
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ func (c *ReportController) StatisticsReportForStoreSkusPrice() {
|
|||||||
// @router /PriceRefer [post]
|
// @router /PriceRefer [post]
|
||||||
func (c *ReportController) PriceRefer() {
|
func (c *ReportController) PriceRefer() {
|
||||||
c.callPriceRefer(func(params *tReportPriceReferParams) (retVal interface{}, errCode string, err error) {
|
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
|
return retVal, "", err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user