- GetOrders.

This commit is contained in:
gazebo
2018-10-09 17:09:34 +08:00
parent 4203dd5b29
commit c8a0f9b59f
4 changed files with 130 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
package orderman
import (
"strconv"
"time"
"git.rosy.net.cn/baseapi/utils"
@@ -184,7 +185,7 @@ func (c *OrderManager) ExportMTWaybills(fromDateStr, toDateStr string) (excelCon
if toDateStr == "" {
toDateStr = fromDateStr
}
toDate := utils.Str2Time(toDateStr)
toDate := utils.Str2Time(toDateStr).Add(24 * time.Hour)
var waybills []*tMTWaybillExport
sql := `
SELECT t1.*, t2.store_name, IF(t2.store_id <> 0, t2.store_id, t2.jx_store_id) store_id
@@ -217,3 +218,97 @@ func (c *OrderManager) ExportMTWaybills(fromDateStr, toDateStr string) (excelCon
}
return nil, err
}
func (c *OrderManager) GetOrders(fromDateStr, toDateStr string, params map[string]interface{}) (pagedInfo *model.PagedInfo, err error) {
globals.SugarLogger.Debugf("GetOrders 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)
}
sql := `
SELECT SQL_CALC_FOUND_ROWS t1.*, t2.status waybill_status, t2.courier_name, t2.courier_mobile
FROM goods_order t1
LEFT JOIN waybill t2 ON t1.vendor_waybill_id = t2.vendor_waybill_id AND t1.waybill_vendor_id = t2.waybill_vendor_id
WHERE t1.order_created_at >= ? AND t1.order_created_at < ?
`
sqlParams := []interface{}{
fromDate,
toDate,
}
if params["keyword"] != nil {
keyword := params["keyword"].(string)
keywordLike := "%" + keyword + "%"
sql += `
AND (t1.store_name LIKE ? OR t1.vendor_order_id LIKE ? OR t1.vendor_store_id LIKE ?
OR t1.consignee_name LIKE ? OR t1.consignee_mobile LIKE ? OR t1.consignee_address 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, keywordLike, keywordLike, keywordLike, keywordLike)
if keywordInt64, err2 := strconv.ParseInt(keyword, 10, 64); err2 == nil {
sql += " OR t1.store_id = ? OR t1.jx_store_id = ?"
sqlParams = append(sqlParams, keywordInt64, keywordInt64)
}
sql += ")"
}
if params["vendorID"] != nil {
sql += " AND t1.vendor_id = ?"
sqlParams = append(sqlParams, params["vendorID"])
}
if params["storeIDs"] != nil {
var storeIDs []int
if err = utils.UnmarshalUseNumber([]byte(params["storeIDs"].(string)), &storeIDs); err != nil {
return nil, err
}
sql += " AND IF(t1.jx_store_id != 0, t1.jx_store_id, t1.store_id) IN (" + dao.GenQuestionMarks(len(storeIDs)) + ")"
sqlParams = append(sqlParams, storeIDs)
}
if params["statuss"] != nil {
var statuss []int
if err = utils.UnmarshalUseNumber([]byte(params["statuss"].(string)), &statuss); err != nil {
return nil, err
}
sql += " AND t1.status IN (" + dao.GenQuestionMarks(len(statuss)) + ")"
sqlParams = append(sqlParams, statuss)
}
sql += `
ORDER BY t1.vendor_order_id
LIMIT ? OFFSET ?
`
sqlParams = append(sqlParams, pageSize, offset)
var orders []*model.GoodsOrderExt
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, &orders, 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 = orders
}
}
dao.Commit(db)
return pagedInfo, err
}

View File

@@ -26,3 +26,8 @@ type SkuMetaInfo struct {
Units []string `json:"units"`
SpecUnits []string `json:"specUnits"`
}
type PagedInfo struct {
TotalCount int `json:"totalCount"`
Data interface{} `json:"data"`
}

View File

@@ -203,3 +203,24 @@ func (c *OrderController) ExportMTWaybills() {
c.Ctx.ResponseWriter.Write(content)
}
}
// @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 vendorID query int false "订单所属厂商"
// @Param storeIDs query string false "京西门店ID列表[1,2,3],缺省不限制"
// @Param statuss query string false "订单状态列表[1,2,3],缺省不限制"
// @Param offset query int false "结果起始序号以0开始缺省为0"
// @Param pageSize query int false "结果页大小缺省为500表示不限制"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /GetOrders [get]
func (c *OrderController) GetOrders() {
c.callGetOrders(func(params *tOrderGetOrdersParams) (retVal interface{}, errCode string, err error) {
retVal, err = orderman.FixedOrderManager.GetOrders(params.FromDate, params.ToDate, params.MapData)
return retVal, "", err
})
}

View File

@@ -143,6 +143,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: "GetOrders",
Router: `/GetOrders`,
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: "GetStoreOrderCountInfo",