1
This commit is contained in:
@@ -62,3 +62,56 @@ func GetStatistics(db *DaoDB, startTime, endTime time.Time, storeId []int, offse
|
||||
|
||||
return pageInfo, err
|
||||
}
|
||||
|
||||
type StatisticsOrderObj struct {
|
||||
OrderCount int64 `json:"order_count"`
|
||||
Name string `json:"name"`
|
||||
Mobile string `json:"mobile"`
|
||||
}
|
||||
|
||||
// StatisticsOrderCount 统计负责人订单量
|
||||
func StatisticsOrderCount(db *DaoDB, startTime, endTime time.Time, storeId []int, vendorId []int, offset, pageSize int) (pageInfo *model.PagedInfo, err error) {
|
||||
sql := `
|
||||
SELECT SQL_CALC_FOUND_ROWS
|
||||
COUNT(a.vendor_order_id) AS order_count,
|
||||
c.name AS name,
|
||||
c.mobile AS mobile
|
||||
FROM goods_order a
|
||||
LEFT JOIN store b ON IF(a.store_id = 0, a.jx_store_id, a.store_id) = b.id
|
||||
LEFT JOIN user c ON c.mobile = b.market_man_phone
|
||||
WHERE 1 = 1
|
||||
`
|
||||
param := []interface{}{}
|
||||
if !utils.IsTimeZero(startTime) {
|
||||
sql += ` AND a.order_created_at >= ?`
|
||||
param = append(param, startTime)
|
||||
}
|
||||
if !utils.IsTimeZero(endTime) {
|
||||
sql += ` AND a.order_created_at <= ?`
|
||||
param = append(param, endTime)
|
||||
}
|
||||
if len(storeId) > 0 {
|
||||
sql += " AND IF(a.store_id <> '', a.store_id, a.jx_store_id) IN (" + dao.GenQuestionMarks(len(storeId)) + ")"
|
||||
param = append(param, storeId)
|
||||
}
|
||||
if len(vendorId) != 0 {
|
||||
sql += " AND a.vendor_id IN (" + dao.GenQuestionMarks(len(vendorId)) + ")"
|
||||
param = append(param, vendorId)
|
||||
}
|
||||
|
||||
sql += `AND a.status = 110 `
|
||||
sql += `GROUP BY c.mobile, c.name ORDER BY order_count desc LIMIT ? OFFSET ?`
|
||||
param = append(param, jxutils.FormalizePageSize(pageSize), offset)
|
||||
|
||||
txDB, _ := Begin(db)
|
||||
defer Commit(db, txDB)
|
||||
var msgList []*StatisticsOrderObj
|
||||
if err = GetRowsTx(txDB, &msgList, sql, param...); err == nil {
|
||||
pageInfo = &model.PagedInfo{
|
||||
TotalCount: GetLastTotalRowCount2(db, txDB),
|
||||
Data: msgList,
|
||||
}
|
||||
}
|
||||
return pageInfo, err
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user