aa
This commit is contained in:
@@ -184,6 +184,10 @@ func Init() {
|
||||
defsch.FixedScheduler.ConfirmSelfTakeOrders(jxcontext.AdminCtx, []int{model.VendorIDJD}, time.Now().Add(-48*time.Hour), time.Now().Add(-30*time.Minute), true, true)
|
||||
}, 5*time.Second, 10*time.Minute)
|
||||
|
||||
ScheduleTimerFuncByInterval(func() {
|
||||
report.RefreshStoreManageState(jxcontext.AdminCtx)
|
||||
}, 5*time.Second, 10*time.Minute)
|
||||
|
||||
ScheduleTimerFunc("auto enable remote store", func() {
|
||||
cms.EnableHaveRestStores(jxcontext.AdminCtx, false, true)
|
||||
// cms.OpenRemoteStoreByJxStatus(jxcontext.AdminCtx, nil, nil, false, false, true)
|
||||
|
||||
@@ -392,26 +392,89 @@ func GetManageState(ctx *jxcontext.Context, cityCodes []int, vendorID int) (getM
|
||||
return getManageStateResult, err
|
||||
}
|
||||
|
||||
type GetStoreManageStateResult struct {
|
||||
StoreName string `json:"storeName"`
|
||||
VendorStoreID string `orm:"column(vendor_store_id)" json:"vendorStoreID"`
|
||||
model.StoreManageState
|
||||
func RefreshStoreManageState(ctx *jxcontext.Context) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
vendorIDs = []int{model.VendorIDJD, model.VendorIDMTWM, model.VendorIDEBAI}
|
||||
dayTimeBegin, dayTimeEnd = utils.Str2Time(utils.Time2Str(utils.Time2Date(time.Now())) + "00:00:00"), utils.Str2Time(utils.Time2Str(utils.Time2Date(time.Now())) + "23:59:59")
|
||||
coverAreaFlag = time.Now().Hour() == 0 && time.Now().Minute() > 0 && time.Now().Minute() < 12
|
||||
)
|
||||
task := tasksch.NewParallelTask("RefreshStoreManageState", tasksch.NewParallelConfig().SetParallelCount(3).SetIsContinueWhenError(true), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
vendorID := batchItemList[0].(int)
|
||||
storeMaps, err := dao.GetStoresMapList(db, []int{vendorID}, nil, nil, model.StoreStatusAll, model.StoreIsSyncAll, "", "", "")
|
||||
task2 := tasksch.NewParallelTask("GetStoreManageState2", tasksch.NewParallelConfig().SetParallelCount(50).SetIsContinueWhenError(true), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
storeMap := batchItemList[0].(*model.StoreMap)
|
||||
if storeMap.VendorOrgCode == "" || storeMap.VendorStoreID == "" {
|
||||
return retVal, err
|
||||
}
|
||||
storeDetail, _ := dao.GetStoreDetail(db, storeMap.StoreID, vendorID, storeMap.VendorOrgCode)
|
||||
storeManage := &model.StoreManageState{
|
||||
StoreID: storeMap.StoreID,
|
||||
VendorID: storeMap.VendorID,
|
||||
}
|
||||
dao.WrapAddIDCULEntity(storeManage, ctx.GetUserName())
|
||||
if coverAreaFlag {
|
||||
handler := partner.GetPurchasePlatformFromVendorID(vendorID)
|
||||
if store, err := handler.ReadStore(ctx, storeDetail.VendorOrgCode, storeDetail.VendorStoreID); err == nil {
|
||||
if vendorID == model.VendorIDJD && store.DeliveryRangeType != model.DeliveryRangeTypePolygon {
|
||||
storeManage.CoverArea = math.Pi * utils.Str2Float64WithDefault(store.DeliveryRange, 0) * utils.Str2Float64WithDefault(store.DeliveryRange, 0) / float64(10000)
|
||||
} else {
|
||||
storeManage.CoverArea = CalculateCoverArea(strings.Split(store.DeliveryRange, ";"), vendorID)
|
||||
}
|
||||
}
|
||||
}
|
||||
//营业时长
|
||||
optime := jxutils.JxOperationTime2TimeByDate(storeDetail.CloseTime1, time.Now()).Sub(jxutils.JxOperationTime2TimeByDate(storeDetail.OpenTime1, time.Now())).Hours()
|
||||
if storeDetail.CloseTime2 != 0 && storeDetail.OpenTime2 != 0 {
|
||||
optime += jxutils.JxOperationTime2TimeByDate(storeDetail.CloseTime2, time.Now()).Sub(jxutils.JxOperationTime2TimeByDate(storeDetail.OpenTime2, time.Now())).Hours()
|
||||
}
|
||||
storeManage.OpenTime = optime
|
||||
//商品数
|
||||
highSkuCount := 0
|
||||
storeSkus, _ := dao.GetStoresSkusForManageState(db, storeMap.StoreID, model.StoreSkuBindStatusNormal)
|
||||
for _, v := range storeSkus {
|
||||
if v.UnitPrice > v.MidUnitPrice {
|
||||
highSkuCount++
|
||||
}
|
||||
}
|
||||
storeManage.SkuCount, storeManage.HighSkuCount = len(storeSkus), highSkuCount
|
||||
//活动丰富度
|
||||
handler := partner.GetPurchasePlatformFromVendorID(vendorID)
|
||||
ample, _ := handler.GetActAmple(ctx, storeDetail.VendorStoreID, storeDetail.VendorStoreID)
|
||||
storeManage.ActAmple = ample
|
||||
//订单
|
||||
refuseOrderCount := 0
|
||||
orderList, _ := dao.QueryOrdersForManageState(db, storeMap.StoreID, vendorID, model.OrderStatusCanceled, dayTimeBegin, dayTimeEnd)
|
||||
for _, v := range orderList {
|
||||
if v.BindID == 0 {
|
||||
refuseOrderCount++
|
||||
}
|
||||
}
|
||||
storeManage.NullOrderCount, storeManage.RefuseOrderCount = len(orderList), refuseOrderCount
|
||||
//评分(美团)
|
||||
if vendorID == model.VendorIDMTWM {
|
||||
mtapi := partner.CurAPIManager.GetAPI(model.VendorIDMTWM, storeDetail.VendorOrgCode).(*mtwmapi.API)
|
||||
if scoreResult, err := mtapi.CommentScore(storeDetail.VendorStoreID); err == nil {
|
||||
storeManage.StoreScore = scoreResult.AvgPoiScore
|
||||
}
|
||||
}
|
||||
dao.CreateOrUpdate(db, storeManage)
|
||||
return retVal, err
|
||||
}, storeMaps)
|
||||
tasksch.HandleTask(task2, task, true).Run()
|
||||
task2.GetResult(0)
|
||||
return retVal, err
|
||||
}, vendorIDs)
|
||||
tasksch.HandleTask(task, nil, true).Run()
|
||||
task.GetID()
|
||||
}
|
||||
|
||||
func GetStoreManageState(ctx *jxcontext.Context, storeIDs []int, vendorID int, fromTime, toTime string, offset, pageSize int) (pageInfo *model.PagedInfo, err error) {
|
||||
func GetStoreManageState(ctx *jxcontext.Context, storeIDs []int, vendorID, sortType, offset, pageSize int) (pageInfo *model.PagedInfo, err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
fromTimeT, toTimeT = utils.Str2Time(fromTime), utils.Str2Time(toTime)
|
||||
dayCount = int(fromTimeT.Sub(toTimeT).Hours())/24 + 1 //查的几天
|
||||
getStoreManageStateResult []*GetStoreManageStateResult
|
||||
storeIDsPage []int
|
||||
storeMapMaps map[int]*model.StoreMap
|
||||
db = dao.GetDB()
|
||||
)
|
||||
storeMapMaps = make(map[int]*model.StoreMap)
|
||||
storeMaps, err := dao.GetStoresMapList(db, []int{vendorID}, nil, nil, model.StoreStatusAll, model.StoreIsSyncAll, "", "", "")
|
||||
for _, v := range storeMaps {
|
||||
storeMapMaps[v.StoreID] = v
|
||||
}
|
||||
//权限
|
||||
if permission.IsRoled(ctx) {
|
||||
if storeIDsMap, err := permission.GetUserStoresResultMap(ctx.GetUserID()); err == nil {
|
||||
@@ -424,96 +487,14 @@ func GetStoreManageState(ctx *jxcontext.Context, storeIDs []int, vendorID int, f
|
||||
}
|
||||
} else {
|
||||
for k, _ := range storeIDsMap {
|
||||
if storeMapMaps[k] != nil {
|
||||
storeIDs2 = append(storeIDs2, k)
|
||||
}
|
||||
storeIDs2 = append(storeIDs2, k)
|
||||
}
|
||||
}
|
||||
storeIDs = nil
|
||||
storeIDs = storeIDs2
|
||||
}
|
||||
}
|
||||
index2 := (offset + 1) * pageSize
|
||||
if index2 > len(storeIDs) {
|
||||
index2 = len(storeIDs) - 1
|
||||
}
|
||||
storeIDsPage = storeIDs[offset*pageSize : index2]
|
||||
task := tasksch.NewParallelTask("GetStoreManageState", tasksch.NewParallelConfig().SetParallelCount(20).SetIsContinueWhenError(true), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
v := batchItemList[0].(int)
|
||||
storeDetail, _ := dao.GetStoreDetail(db, v, vendorID, "")
|
||||
if storeDetail == nil || storeDetail.VendorStoreID == "" || storeDetail.VendorOrgCode == "" {
|
||||
return retVal, err
|
||||
}
|
||||
result := &GetStoreManageStateResult{
|
||||
// StoreID: v,
|
||||
// StoreName: storeDetail.Name,
|
||||
// MarketScale: storeDetail.MarketScale,
|
||||
// CoverArea: storeDetail.CoverArea,
|
||||
}
|
||||
//覆盖范围
|
||||
if result.CoverArea == 0 {
|
||||
handler := partner.GetPurchasePlatformFromVendorID(vendorID)
|
||||
if store, err := handler.ReadStore(ctx, storeDetail.VendorOrgCode, storeDetail.VendorStoreID); err == nil {
|
||||
if storeMapMaps[v] != nil {
|
||||
if vendorID == model.VendorIDJD && store.DeliveryRangeType != model.DeliveryRangeTypePolygon {
|
||||
storeMapMaps[v].CoverArea = math.Pi * utils.Str2Float64WithDefault(store.DeliveryRange, 0) * utils.Str2Float64WithDefault(store.DeliveryRange, 0) / float64(10000)
|
||||
} else {
|
||||
storeMapMaps[v].CoverArea = CalculateCoverArea(strings.Split(store.DeliveryRange, ";"), vendorID)
|
||||
}
|
||||
dao.UpdateEntity(db, storeMapMaps[v], "CoverArea")
|
||||
result.CoverArea = storeMapMaps[v].CoverArea
|
||||
}
|
||||
}
|
||||
}
|
||||
//营业时长
|
||||
optime := jxutils.JxOperationTime2TimeByDate(storeDetail.CloseTime1, time.Now()).Sub(jxutils.JxOperationTime2TimeByDate(storeDetail.OpenTime1, time.Now())).Hours()
|
||||
if storeDetail.CloseTime2 != 0 && storeDetail.OpenTime2 != 0 {
|
||||
optime += jxutils.JxOperationTime2TimeByDate(storeDetail.CloseTime2, time.Now()).Sub(jxutils.JxOperationTime2TimeByDate(storeDetail.OpenTime2, time.Now())).Hours()
|
||||
}
|
||||
result.OpenTime = optime * float64(dayCount)
|
||||
//商品数
|
||||
highSkuCount := 0
|
||||
storeSkus, _ := dao.GetStoresSkusForManageState(db, v, model.StoreSkuBindStatusNormal)
|
||||
for _, v := range storeSkus {
|
||||
if v.UnitPrice > v.MidUnitPrice {
|
||||
highSkuCount++
|
||||
}
|
||||
}
|
||||
result.SkuCount, result.HighSkuCount = len(storeSkus), highSkuCount
|
||||
//活动丰富度
|
||||
handler := partner.GetPurchasePlatformFromVendorID(vendorID)
|
||||
ample, _ := handler.GetActAmple(ctx, storeDetail.VendorStoreID, storeDetail.VendorStoreID)
|
||||
result.ActAmple = ample
|
||||
//订单
|
||||
refuseOrderCount := 0
|
||||
orderList, _ := dao.QueryOrdersForManageState(db, v, vendorID, model.OrderStatusCanceled, fromTimeT, toTimeT)
|
||||
for _, v := range orderList {
|
||||
if v.BindID == 0 {
|
||||
refuseOrderCount++
|
||||
}
|
||||
}
|
||||
result.NullOrderCount, result.RefuseOrderCount = len(orderList), refuseOrderCount
|
||||
//评分(美团)
|
||||
if vendorID == model.VendorIDMTWM {
|
||||
mtapi := partner.CurAPIManager.GetAPI(model.VendorIDMTWM, storeDetail.VendorOrgCode).(*mtwmapi.API)
|
||||
if scoreResult, err := mtapi.CommentScore(storeDetail.VendorStoreID); err == nil {
|
||||
result.StoreScore = scoreResult.AvgPoiScore
|
||||
}
|
||||
}
|
||||
retVal = []*GetStoreManageStateResult{result}
|
||||
// getStoreManageStateResult = append(getStoreManageStateResult, result)
|
||||
return retVal, err
|
||||
}, storeIDsPage)
|
||||
tasksch.HandleTask(task, nil, true).Run()
|
||||
result, _ := task.GetResult(0)
|
||||
for _, v := range result {
|
||||
getStoreManageStateResult = append(getStoreManageStateResult, v.(*GetStoreManageStateResult))
|
||||
}
|
||||
return &model.PagedInfo{
|
||||
TotalCount: len(storeIDs),
|
||||
Data: getStoreManageStateResult,
|
||||
}, err
|
||||
return dao.GetStoreManageState(db, storeIDs, vendorID, sortType, pageSize, offset)
|
||||
}
|
||||
|
||||
func CalculateCoverArea(coordinate []string, vendorID int) (area float64) {
|
||||
|
||||
@@ -67,9 +67,6 @@ type StoreDetail struct {
|
||||
BrandLogo string `json:"brandLogo"`
|
||||
BrandIsOpen int `json:"brandIsOpen"`
|
||||
BrandIsPrint int `json:"brandIsPrint"`
|
||||
|
||||
CoverArea float64 `json:"coverArea"`
|
||||
MarketScale int `json:"marketScale"` //市场规模
|
||||
}
|
||||
|
||||
// 带快递门店信息的
|
||||
@@ -115,7 +112,6 @@ func getStoreDetail(db *DaoDB, storeID, vendorID int, vendorStoreID, vendorOrgCo
|
||||
t2.vendor_store_id, t2.status vendor_status, t2.delivery_fee_deduction_sill, t2.delivery_fee_deduction_fee, t2.sync_status, t2.vendor_org_code,
|
||||
t2.price_percentage, t2.auto_pickup, t2.delivery_type, t2.delivery_competition, t2.is_sync, t2.vendor_store_name, t2.is_order, t2.yb_app_id, t2.yb_app_key, t2.yb_store_prefix,
|
||||
t2.jds_street_code, t2.jds_street_name, t2.is_supply_goods, t2.vendor_pay_percentage, t2.mtwm_token, t2.ebai_supplier_id, t2.create_delivery_type,
|
||||
t2.market_scale, t2.cover_area,
|
||||
t3.value price_percentage_pack_str,
|
||||
t4.value freight_deduction_pack_str,
|
||||
province.name province_name,
|
||||
@@ -1168,3 +1164,48 @@ func GetStoreAcctExpendLastCreateWayBillFee(db *DaoDB, vendorOrderID string) (la
|
||||
err = GetRow(db, &expend, sql, sqlParams)
|
||||
return expend.ExpendPrice, err
|
||||
}
|
||||
|
||||
type GetStoreManageStateResult struct {
|
||||
StoreName string `json:"storeName"`
|
||||
VendorStoreID string `orm:"column(vendor_store_id)" json:"vendorStoreID"`
|
||||
MarketScale int `json:"marketScale"` //市场规模
|
||||
Comment string `json:"comment"`
|
||||
DefaultCoverArea float64 `json:"defaultCoverArea"`
|
||||
model.StoreManageState
|
||||
}
|
||||
|
||||
func GetStoreManageState(db *DaoDB, storeIDs []int, vendorID, sortType, offset, pageSize int) (pagedInfo *model.PagedInfo, err error) {
|
||||
var requestList []*GetStoreManageStateResult
|
||||
sql := `
|
||||
SELECT SQL_CALC_FOUND_ROWS DISTINCT a.*, b.name store_name, c.vendor_store_id, c.market_scale, b.comment, c.cover_area default_cover_area
|
||||
FROM store_manage_state a
|
||||
LEFT JOIN store b ON b.id = a.store_id
|
||||
LEFT JOIN store_map c ON c.store_id = a.store_id AND c.vendor_id = a.vendor_id
|
||||
WHERE 1 = 1
|
||||
`
|
||||
sqlParams := []interface{}{}
|
||||
if len(storeIDs) > 0 {
|
||||
sql += " AND a.store_id IN (" + GenQuestionMarks(len(storeIDs)) + ")"
|
||||
sqlParams = append(sqlParams, storeIDs)
|
||||
}
|
||||
if vendorID != -1 {
|
||||
sql += " AND a.vendor_id = ?"
|
||||
sqlParams = append(sqlParams, vendorID)
|
||||
}
|
||||
if sortType != 0 {
|
||||
sql += " ORDER BY"
|
||||
sqlParams = append(sqlParams, sortType)
|
||||
}
|
||||
sql += " LIMIT ? OFFSET ?"
|
||||
pageSize = jxutils.FormalizePageSize(pageSize)
|
||||
sqlParams = append(sqlParams, pageSize, offset)
|
||||
Begin(db)
|
||||
defer Commit(db)
|
||||
if err = GetRows(db, &requestList, sql, sqlParams...); err == nil {
|
||||
return &model.PagedInfo{
|
||||
TotalCount: GetLastTotalRowCount(db),
|
||||
Data: requestList,
|
||||
}, nil
|
||||
}
|
||||
return pagedInfo, err
|
||||
}
|
||||
|
||||
@@ -456,11 +456,9 @@ type StoreMap struct {
|
||||
YbAppKey string `orm:"size(255)" json:"ybAppKey"`
|
||||
YbStorePrefix string `orm:"size(255)" json:"ybStorePrefix"`
|
||||
|
||||
MtwmToken string `orm:"size(255)" json:"mtwmToken"` //美团外卖商超token,有效期30天,每20天刷一次
|
||||
MtwmRefreshToken string `orm:"size(255)" json:"mtwmRefreshToken"` //美团外卖商超refreshToken
|
||||
EbaiSupplierID string `orm:"column(ebai_supplier_id)" json:"ebaiSupplierID"` //饿百供应商ID
|
||||
MarketScale int `json:"marketScale"` //市场规模
|
||||
CoverArea float64 `json:"coverArea"` //覆盖范围
|
||||
MtwmToken string `orm:"size(255)" json:"mtwmToken"` //美团外卖商超token,有效期30天,每20天刷一次
|
||||
MtwmRefreshToken string `orm:"size(255)" json:"mtwmRefreshToken"` //美团外卖商超refreshToken
|
||||
EbaiSupplierID string `orm:"column(ebai_supplier_id)" json:"ebaiSupplierID"` //饿百供应商ID
|
||||
}
|
||||
|
||||
func (*StoreMap) TableUnique() [][]string {
|
||||
@@ -868,7 +866,6 @@ type StoreManageState struct {
|
||||
StoreID int `orm:"column(store_id)" json:"storeID"`
|
||||
VendorID int `orm:"column(vendor_id)" json:"vendorID"`
|
||||
CoverArea float64 `json:"coverArea"`
|
||||
MarketScale int `json:"marketScale"` //市场规模
|
||||
OpenTime float64 `json:"openTime"` //营业时长
|
||||
SkuCount int `json:"skuCount"` //商品数
|
||||
HighSkuCount int `json:"highSkuCount"` //虚高商品数
|
||||
@@ -878,7 +875,6 @@ type StoreManageState struct {
|
||||
StoreScore float64 `json:"storeScore"` //门店评分
|
||||
RepurchaseRate int `json:"repurchaseRate"` //复购率(转化率)
|
||||
VendorStatus int `json:"vendorStatus"` //平台营业状态
|
||||
Comment string `json:"comment"` //备注
|
||||
}
|
||||
|
||||
func (v *StoreManageState) TableUnique() [][]string {
|
||||
|
||||
@@ -120,8 +120,7 @@ func (c *ReportController) GetManageState() {
|
||||
// @Param token header string true "认证token"
|
||||
// @Param storeIDs query string false "门店ID列表[1,2,3]"
|
||||
// @Param vendorID query int true "平台ID"
|
||||
// @Param fromTime query string true "开始日期(包含),格式(2006-01-02 00:00:00)"
|
||||
// @Param toTime query string true "结束日期(包含),格式(2006-01-02 00:00:00)"
|
||||
// @Param sortType query int false "排序类型"
|
||||
// @Param offset query int false "门店列表起始序号(以0开始,缺省为0)"
|
||||
// @Param pageSize query int false "门店列表页大小(缺省为50,-1表示全部)"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
@@ -131,7 +130,7 @@ func (c *ReportController) GetStoreManageState() {
|
||||
c.callGetStoreManageState(func(params *tReportGetStoreManageStateParams) (retVal interface{}, errCode string, err error) {
|
||||
var storeIDs []int
|
||||
if err = jxutils.Strings2Objs(params.StoreIDs, &storeIDs); err == nil {
|
||||
retVal, err = report.GetStoreManageState(params.Ctx, storeIDs, params.VendorID, params.FromTime, params.ToTime, params.Offset, params.PageSize)
|
||||
retVal, err = report.GetStoreManageState(params.Ctx, storeIDs, params.VendorID, params.SortType, params.Offset, params.PageSize)
|
||||
}
|
||||
return retVal, "", err
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user