getorders

This commit is contained in:
苏尹岚
2020-11-17 15:17:03 +08:00
parent 869b4f2c35
commit aafa040327
3 changed files with 63 additions and 0 deletions

View File

@@ -92,3 +92,52 @@ func GetDeliveryOrders(db *DaoDB, userIDs []string, statuss []int, fromTime, toT
}
return pagedInfo, err
}
func GetOrders(db *DaoDB, orderID string, orderType int, cityCodes []int, fromTime, toTime time.Time, keyword string, offset, pageSize int) (pagedInfo *model.PagedInfo, err error) {
var orders []*model.Order
sql := `
SELECT SQL_CALC_FOUND_ROWS a.*
FROM order a
JOIN user b ON b.user_id = a.user_id AND b.deleted_at = ?
WHERE 1 = 1
`
sqlParams := []interface{}{
utils.DefaultTimeValue,
}
if orderID != "" {
sql += ` AND a.order_id = ?`
sqlParams = append(sqlParams, orderID)
}
if orderType != 0 {
sql += ` AND a.type = ?`
sqlParams = append(sqlParams, orderType)
}
if len(cityCodes) > 0 {
sql += ` AND a.city_code IN ` + GenQuestionMarks(len(cityCodes)) + `)`
sqlParams = append(sqlParams, cityCodes)
}
if fromTime != utils.ZeroTimeValue {
sql += ` AND a.created_at >= ?`
sqlParams = append(sqlParams, fromTime)
}
if toTime != utils.ZeroTimeValue {
sql += ` AND a.created_at <= ?`
sqlParams = append(sqlParams, toTime)
}
if keyword != "" {
sql += ` AND (b.mobile LIKE ? OR b.name LIKE ?)`
sqlParams = append(sqlParams, "%"+keyword+"%", "%"+keyword+"%")
}
sql += " LIMIT ? OFFSET ?"
pageSize = jxutils.FormalizePageSize(pageSize)
sqlParams = append(sqlParams, pageSize, offset)
Begin(db)
defer Commit(db)
if err = GetRows(db, &orders, sql, sqlParams); err == nil {
pagedInfo = &model.PagedInfo{
TotalCount: GetLastTotalRowCount(db),
Data: orders,
}
}
return pagedInfo, err
}