diff --git a/business/jxcallback/orderman/order.go b/business/jxcallback/orderman/order.go index 6b534b5c8..877ad001e 100644 --- a/business/jxcallback/orderman/order.go +++ b/business/jxcallback/orderman/order.go @@ -2,6 +2,7 @@ package orderman import ( "fmt" + "strings" "time" "git.rosy.net.cn/baseapi" @@ -184,6 +185,26 @@ func (c *OrderManager) OnOrderMsg(order *model.GoodsOrder, vendorStatus, remark return err } +func setFakeOrderFlag(db *dao.DaoDB, order *model.GoodsOrder) { + if order.DeliveryType == model.OrderDeliveryTypeSelfTake { + if realMobile := jxutils.GetRealMobile4Order(order); realMobile != "" { + if configList, err := dao.QueryConfigs(db, model.ConfigSysFakeOrderMobiles, model.ConfigTypeSys, ""); err == nil && len(configList) > 0 { + isMatch := false + mobileList := strings.Split(configList[0].Value, ",") + for _, v := range mobileList { + if v == realMobile { + isMatch = true + break + } + } + if isMatch { + order.Flag |= model.OrderFlagMaskFake + } + } + } + } +} + func (c *OrderManager) SaveOrder(order *model.GoodsOrder, isAdjust bool, db *dao.DaoDB) (isDuplicated bool, err error) { globals.SugarLogger.Debugf("SaveOrder orderID:%s, VendorStoreID:%s", order.VendorOrderID, order.VendorStoreID) // 忽略查找JX信息错误 @@ -192,6 +213,7 @@ func (c *OrderManager) SaveOrder(order *model.GoodsOrder, isAdjust bool, db *dao order.WaybillVendorID = model.VendorIDUnknown order.OrderFinishedAt = utils.DefaultTimeValue + setFakeOrderFlag(db, order) // cms.HandleOrder4Consignee(order) dao.Begin(db) diff --git a/business/jxcallback/orderman/orderman_ext.go b/business/jxcallback/orderman/orderman_ext.go index 6cb8414a1..3bd2926ad 100644 --- a/business/jxcallback/orderman/orderman_ext.go +++ b/business/jxcallback/orderman/orderman_ext.go @@ -43,7 +43,7 @@ type StoresOrderSaleInfo struct { EarningPrice int64 `json:"earningPrice"` // 预估结算给门店老板的钱 } -func (c *OrderManager) GetStoreOrderCountInfo(ctx *jxcontext.Context, storeID, lastHours int) (countInfo []*model.GoodsOrderCountInfo, err error) { +func (c *OrderManager) GetStoreOrderCountInfo(ctx *jxcontext.Context, storeID, lastHours int, isIncludeFake bool) (countInfo []*model.GoodsOrderCountInfo, err error) { globals.SugarLogger.Debugf("GetStoreOrderCountInfo storeID:%d", storeID) if lastHours > maxLastHours { lastHours = maxLastHours @@ -52,14 +52,24 @@ func (c *OrderManager) GetStoreOrderCountInfo(ctx *jxcontext.Context, storeID, l } db := dao.GetDB() - err = dao.GetRows(db, &countInfo, ` + sql := ` SELECT t1.lock_status, t1.status, COUNT(*) count FROM goods_order t1 WHERE t1.vendor_id <> 2 AND IF(t1.vendor_id = ?, t1.store_id, IF(t1.jx_store_id != 0, t1.jx_store_id, t1.store_id) ) = ? - AND t1.order_created_at >= ? + AND t1.order_created_at >= ?` + sqlParams := []interface{}{ + model.VendorIDWSC, + storeID, + time.Now().Add(-time.Duration(lastHours) * time.Hour), + } + if !isIncludeFake { + sql += " AND (t1.flag & ?) = 0" + sqlParams = append(sqlParams, model.OrderFlagMaskFake) + } + sql += ` GROUP BY 1,2 - ORDER BY 1,2 - `, model.VendorIDWSC, storeID, time.Now().Add(-time.Duration(lastHours)*time.Hour)) + ORDER BY 1,2` + err = dao.GetRows(db, &countInfo, sql, sqlParams...) if err == nil { return countInfo, nil } @@ -219,7 +229,7 @@ func (c *OrderManager) ExportMTWaybills(ctx *jxcontext.Context, fromDateStr, toD return nil, err } -func (c *OrderManager) getOrders(ctx *jxcontext.Context, isIncludeSku bool, fromDateStr, toDateStr string, isDateFinish bool, params map[string]interface{}, offset, pageSize int) (orders []*model.GoodsOrderExt, totalCount int, err error) { +func (c *OrderManager) getOrders(ctx *jxcontext.Context, isIncludeSku, isIncludeFake bool, fromDateStr, toDateStr string, isDateFinish bool, params map[string]interface{}, offset, pageSize int) (orders []*model.GoodsOrderExt, totalCount int, err error) { globals.SugarLogger.Debugf("getOrders from:%s to:%s", fromDateStr, toDateStr) pageSize = jxutils.FormalizePageSize(pageSize) @@ -359,6 +369,10 @@ func (c *OrderManager) getOrders(ctx *jxcontext.Context, isIncludeSku bool, from sqlParams = append(sqlParams, cities) } } + if !isIncludeFake { + sqlWhere += " AND (t1.flag & ?) = 0" + sqlParams = append(sqlParams, model.OrderFlagMaskFake) + } } if params["vendorIDs"] != nil { var vendorIDs []int @@ -398,9 +412,9 @@ func (c *OrderManager) getOrders(ctx *jxcontext.Context, isIncludeSku bool, from return orders, totalCount, err } -func (c *OrderManager) GetOrders(ctx *jxcontext.Context, fromDateStr, toDateStr string, isDateFinish bool, params map[string]interface{}, offset, pageSize int) (pagedInfo *model.PagedInfo, err error) { +func (c *OrderManager) GetOrders(ctx *jxcontext.Context, isIncludeFake bool, fromDateStr, toDateStr string, isDateFinish bool, params map[string]interface{}, offset, pageSize int) (pagedInfo *model.PagedInfo, err error) { globals.SugarLogger.Debugf("GetOrders from:%s to:%s", fromDateStr, toDateStr) - orders, totalCount, err := c.getOrders(ctx, false, fromDateStr, toDateStr, isDateFinish, params, offset, pageSize) + orders, totalCount, err := c.getOrders(ctx, false, isIncludeFake, fromDateStr, toDateStr, isDateFinish, params, offset, pageSize) if err == nil { pagedInfo = &model.PagedInfo{ TotalCount: totalCount, @@ -422,7 +436,7 @@ func (c *OrderManager) ExportOrders(ctx *jxcontext.Context, fromDateStr, toDateS func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) { switch step { case 0: - orders, _, err = c.getOrders(ctx, true, fromDateStr, toDateStr, true, mapParams, 0, -1) + orders, _, err = c.getOrders(ctx, true, true, fromDateStr, toDateStr, true, mapParams, 0, -1) case 1: afsSkuMap, err = c.getAfsOrderSkuInfo4ExportOrders(ctx, fromDateStr, toDateStr) case 2: diff --git a/business/model/const.go b/business/model/const.go index 23de80ad6..d5cd589a2 100644 --- a/business/model/const.go +++ b/business/model/const.go @@ -268,7 +268,7 @@ const ( OrderFlagMaskCallPMCourier = 64 // 取货失败后召唤平台配送 OrderFlagMaskSetDelivered = 128 // 设置送达 - OrderFlagFake = 256 // 假订单,即刷单用的 + OrderFlagMaskFake = 256 // 假订单,即刷单用的 ) const ( diff --git a/controllers/jx_order.go b/controllers/jx_order.go index e568aed42..29bc19121 100644 --- a/controllers/jx_order.go +++ b/controllers/jx_order.go @@ -173,27 +173,13 @@ func (c *OrderController) CancelWaybill() { // @Param token header string true "认证token" // @Param storeID query int true "京西门店ID" // @Param lastHours query int false "最近多少小时的信息(缺省为两天)" +// @Param isIncludeFake query bool false "是否包括假订单" // @Success 200 {object} controllers.CallResult // @Failure 200 {object} controllers.CallResult // @router /GetStoreOrderCountInfo [get] func (c *OrderController) GetStoreOrderCountInfo() { c.callGetStoreOrderCountInfo(func(params *tOrderGetStoreOrderCountInfoParams) (retVal interface{}, errCode string, err error) { - retVal, err = orderman.FixedOrderManager.GetStoreOrderCountInfo(params.Ctx, params.StoreID, params.LastHours) - return retVal, "", err - }) -} - -// @Title 得到门店订单信息2 -// @Description 得到门店订单信息2 -// @Param token header string true "认证token" -// @Param storeID query int true "京西门店ID" -// @Param lastHours query int false "最近多少小时的信息(缺省为两天)" -// @Success 200 {object} controllers.CallResult -// @Failure 200 {object} controllers.CallResult -// @router /GetStoreOrderCountInfo2 [get] -func (c *OrderController) GetStoreOrderCountInfo2() { - c.callGetStoreOrderCountInfo2(func(params *tOrderGetStoreOrderCountInfo2Params) (retVal interface{}, errCode string, err error) { - retVal, err = orderman.FixedOrderManager.GetStoreOrderCountInfo(params.Ctx, params.StoreID, params.LastHours) + retVal, err = orderman.FixedOrderManager.GetStoreOrderCountInfo(params.Ctx, params.StoreID, params.LastHours, params.IsIncludeFake) return retVal, "", err }) } @@ -289,6 +275,7 @@ func (c *OrderController) ExportMTWaybills() { // @Param statuss query string false "订单状态列表[1,2,3],缺省不限制" // @Param lockStatuss query string false "订单锁定状态列表[1,2,3],缺省不限制" // @Param cities query string false "城市code列表[1,2,3],缺省不限制" +// @Param isIncludeFake query bool false "是否包括假订单" // @Param offset query int false "结果起始序号(以0开始,缺省为0)" // @Param pageSize query int false "结果页大小(缺省为50,-1表示全部)" // @Success 200 {object} controllers.CallResult @@ -296,7 +283,7 @@ func (c *OrderController) ExportMTWaybills() { // @router /GetOrders [get] func (c *OrderController) GetOrders() { c.callGetOrders(func(params *tOrderGetOrdersParams) (retVal interface{}, errCode string, err error) { - retVal, err = orderman.FixedOrderManager.GetOrders(params.Ctx, params.FromDate, params.ToDate, params.IsDateFinish, params.MapData, params.Offset, params.PageSize) + retVal, err = orderman.FixedOrderManager.GetOrders(params.Ctx, params.IsIncludeFake, params.FromDate, params.ToDate, params.IsDateFinish, params.MapData, params.Offset, params.PageSize) return retVal, "", err }) }