diff --git a/business/jxcallback/orderman/orderman_ext.go b/business/jxcallback/orderman/orderman_ext.go index 25672a0b7..74c763ee0 100644 --- a/business/jxcallback/orderman/orderman_ext.go +++ b/business/jxcallback/orderman/orderman_ext.go @@ -19,7 +19,7 @@ const ( defPageSize = 50 ) -type tMTWaybillExport struct { +type tWaybillExt struct { model.Waybill StoreName string `json:"storeName"` StoreID int `json:"storeID" orm:"column(store_id)"` @@ -186,7 +186,7 @@ func (c *OrderManager) ExportMTWaybills(fromDateStr, toDateStr string) (excelCon toDateStr = fromDateStr } toDate := utils.Str2Time(toDateStr).Add(24 * time.Hour) - var waybills []*tMTWaybillExport + var waybills []*tWaybillExt sql := ` SELECT t1.*, t2.store_name, IF(t2.store_id <> 0, t2.store_id, t2.jx_store_id) store_id FROM waybill t1 @@ -267,9 +267,25 @@ func (c *OrderManager) GetOrders(fromDateStr, toDateStr string, params map[strin sqlWhere += ")" } - if params["vendorID"] != nil { - sqlWhere += " AND t1.vendor_id = ?" - sqlParams = append(sqlParams, params["vendorID"]) + if params["vendorIDs"] != nil { + var vendorIDs []int + if err = utils.UnmarshalUseNumber([]byte(params["vendorIDs"].(string)), &vendorIDs); err != nil { + return nil, err + } + if len(vendorIDs) > 0 { + sqlWhere += " AND t1.vendor_id IN (" + dao.GenQuestionMarks(len(vendorIDs)) + ")" + sqlParams = append(sqlParams, vendorIDs) + } + } + if params["waybillVendorIDs"] != nil { + var waybillVendorIDs []int + if err = utils.UnmarshalUseNumber([]byte(params["waybillVendorIDs"].(string)), &waybillVendorIDs); err != nil { + return nil, err + } + if len(waybillVendorIDs) > 0 { + sqlWhere += " AND t2.waybill_vendor_id IN (" + dao.GenQuestionMarks(len(waybillVendorIDs)) + ")" + sqlParams = append(sqlParams, waybillVendorIDs) + } } if params["storeIDs"] != nil { var storeIDs []int @@ -330,3 +346,94 @@ func (c *OrderManager) GetOrders(fromDateStr, toDateStr string, params map[strin dao.Commit(db) return pagedInfo, err } + +func (c *OrderManager) GetWaybills(fromDateStr, toDateStr string, params map[string]interface{}) (pagedInfo *model.PagedInfo, err error) { + globals.SugarLogger.Debugf("GetWaybills from:%s to:%s", fromDateStr, toDateStr) + + fromDate := utils.Str2Time(fromDateStr) + if toDateStr == "" { + toDateStr = fromDateStr + } + toDate := utils.Str2Time(toDateStr).Add(24 * time.Hour) + pageSize := defPageSize + if params["pageSize"] != nil { + pageSize = params["pageSize"].(int) + if pageSize == 0 { + pageSize = 999999999 + } + } + offset := 0 + if params["offset"] != nil { + offset = params["offset"].(int) + } + sqlParams := []interface{}{ + fromDate, + toDate, + } + sql := ` + SELECT SQL_CALC_FOUND_ROWS t1.*, t2.store_name, IF(t2.store_id <> 0, t2.store_id, t2.jx_store_id) store_id + FROM waybill t1 + JOIN goods_order t2 ON t1.vendor_order_id = t2.vendor_order_id + WHERE t1.status = 105 AND t1.waybill_created_at >= ? AND t1.waybill_created_at < ? + ` + if params["keyword"] != nil { + keyword := params["keyword"].(string) + keywordLike := "%" + keyword + "%" + sql += ` + AND (t2.store_name LIKE ? OR t1.vendor_order_id LIKE ? + OR t2.vendor_waybill_id LIKE ? OR t2.courier_name LIKE ? OR t2.courier_mobile LIKE ? + ` + sqlParams = append(sqlParams, keywordLike, keywordLike, keywordLike, keywordLike, keywordLike) + if keywordInt64, err2 := strconv.ParseInt(keyword, 10, 64); err2 == nil { + sql += " OR t2.store_id = ? OR t2.jx_store_id = ?" + sqlParams = append(sqlParams, keywordInt64, keywordInt64) + } + sql += ")" + } + + if params["waybillVendorIDs"] != nil { + var waybillVendorIDs []int + if err = utils.UnmarshalUseNumber([]byte(params["waybillVendorIDs"].(string)), &waybillVendorIDs); err != nil { + return nil, err + } + if len(waybillVendorIDs) > 0 { + sql += " AND t2.waybill_vendor_id IN (" + dao.GenQuestionMarks(len(waybillVendorIDs)) + ")" + sqlParams = append(sqlParams, waybillVendorIDs) + } + } + if params["statuss"] != nil { + var statuss []int + if err = utils.UnmarshalUseNumber([]byte(params["statuss"].(string)), &statuss); err != nil { + return nil, err + } + if len(statuss) > 0 { + sql += " AND t1.status IN (" + dao.GenQuestionMarks(len(statuss)) + ")" + sqlParams = append(sqlParams, statuss) + } + } + sql += ` + ORDER BY t1.id + LIMIT ? OFFSET ? + ` + sqlParams = append(sqlParams, pageSize, offset) + var waybills []*tWaybillExt + pagedInfo = &model.PagedInfo{} + db := dao.GetDB() + dao.Begin(db) + defer func() { + if r := recover(); r != nil { + dao.Rollback(db) + panic(r) + } + }() + if err = dao.GetRows(db, &waybills, sql, sqlParams...); err == nil { + countInfo := &struct{ Ct int }{} + if err = dao.GetRow(db, countInfo, "SELECT FOUND_ROWS() ct"); err == nil { + pagedInfo.TotalCount = countInfo.Ct + pagedInfo.Data = waybills + return pagedInfo, nil + } + } + dao.Commit(db) + return nil, err +} diff --git a/controllers/jx_order.go b/controllers/jx_order.go index f0da1e036..e9d0687aa 100644 --- a/controllers/jx_order.go +++ b/controllers/jx_order.go @@ -210,7 +210,8 @@ func (c *OrderController) ExportMTWaybills() { // @Param keyword query string false "查询关键字" // @Param fromDate query string true "开始日期(包含),格式(2006-01-02)" // @Param toDate query string false "结束日期(包含),格式(2006-01-02)" -// @Param vendorID query int false "订单所属厂商" +// @Param vendorIDs query string false "订单所属厂商列表[1,2,3],缺省不限制" +// @Param waybillVendorIDs query string false "承运人所属厂商列表[1,2,3],缺省不限制" // @Param storeIDs query string false "京西门店ID列表[1,2,3],缺省不限制" // @Param statuss query string false "订单状态列表[1,2,3],缺省不限制" // @Param cities query string false "城市code列表[1,2,3],缺省不限制" @@ -225,3 +226,23 @@ func (c *OrderController) GetOrders() { return retVal, "", err }) } + +// @Title 查询运单 +// @Description 查询运单 +// @Param token header string true "认证token" +// @Param keyword query string false "查询关键字" +// @Param fromDate query string true "开始日期(包含),格式(2006-01-02)" +// @Param toDate query string false "结束日期(包含),格式(2006-01-02)" +// @Param waybillVendorIDs query string false "承运人所属厂商列表[1,2,3],缺省不限制" +// @Param statuss query string false "运单状态列表[1,2,3],缺省不限制" +// @Param offset query int false "结果起始序号(以0开始,缺省为0)" +// @Param pageSize query int false "结果页大小(缺省为50,0表示不限制)" +// @Success 200 {object} controllers.CallResult +// @Failure 200 {object} controllers.CallResult +// @router /GetWaybills [get] +func (c *OrderController) GetWaybills() { + c.callGetWaybills(func(params *tOrderGetWaybillsParams) (retVal interface{}, errCode string, err error) { + retVal, err = orderman.FixedOrderManager.GetWaybills(params.FromDate, params.ToDate, params.MapData) + return retVal, "", err + }) +} diff --git a/routers/commentsRouter_controllers.go b/routers/commentsRouter_controllers.go index d4d1048f5..9faa824c7 100644 --- a/routers/commentsRouter_controllers.go +++ b/routers/commentsRouter_controllers.go @@ -175,6 +175,14 @@ func init() { MethodParams: param.Make(), Params: nil}) + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:OrderController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:OrderController"], + beego.ControllerComments{ + Method: "GetWaybills", + Router: `/GetWaybills`, + AllowHTTPMethods: []string{"get"}, + MethodParams: param.Make(), + Params: nil}) + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:OrderController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:OrderController"], beego.ControllerComments{ Method: "SelfDelivered",