- GetStores添加订单相关的查询条件
This commit is contained in:
@@ -1,11 +1,26 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
)
|
||||
|
||||
type StoresOrderSaleInfo struct {
|
||||
StoreID int `orm:"column(store_id)" json:"storeID"`
|
||||
VendorID int `orm:"column(vendor_id)" json:"vendorID"`
|
||||
Status int `json:"status"`
|
||||
Count int `json:"count"`
|
||||
ShopPrice int64 `json:"shopPrice"`
|
||||
VendorPrice int64 `json:"vendorPrice"`
|
||||
SalePrice int64 `json:"salePrice"`
|
||||
ActualPayPrice int64 `json:"actualPayPrice"`
|
||||
|
||||
EarningPrice int64 `json:"earningPrice"` // 预估结算给门店老板的钱
|
||||
}
|
||||
|
||||
func GetStoreOrderAfterTime(db *DaoDB, storeID int, orderTime time.Time, lastOrderSeqID int64) (orderList []*model.GoodsOrderExt, err error) {
|
||||
sql := `
|
||||
SELECT t1.*,
|
||||
@@ -82,3 +97,43 @@ func GetAfsOrders(db *DaoDB, vendorID int, vendorOrderID, afsOrderID string) (af
|
||||
err = GetRows(db, &afsOrderList, sql, sqlParams...)
|
||||
return afsOrderList, err
|
||||
}
|
||||
|
||||
func GetStoresOrderSaleInfo(db *DaoDB, storeIDList []int, fromTime time.Time, toTime time.Time, statusList []int) (saleInfoList []*StoresOrderSaleInfo, err error) {
|
||||
if utils.IsTimeZero(fromTime) {
|
||||
return nil, fmt.Errorf("查询订单信息必须指定起始时间")
|
||||
}
|
||||
if utils.IsTimeZero(toTime) {
|
||||
toTime = time.Now()
|
||||
}
|
||||
if toTime.Sub(fromTime) > time.Hour*24*60 {
|
||||
return nil, fmt.Errorf("查询时间范围不能超过60天")
|
||||
}
|
||||
|
||||
// 用int64类型去取float型的数据库返回值,会取不到
|
||||
sql := fmt.Sprintf(`
|
||||
SELECT IF(t1.jx_store_id > 0, t1.jx_store_id, t1.store_id) store_id, t1.vendor_id, IF(t1.status < ?, 0, t1.status) status,
|
||||
COUNT(*) count, SUM(t1.shop_price) shop_price, SUM(t1.vendor_price) vendor_price, SUM(t1.sale_price) sale_price, SUM(t1.actual_pay_price) actual_pay_price,
|
||||
CAST(SUM(IF(t1.earning_price <> 0, t1.earning_price, IF(t1.shop_price <> 0 && t1.shop_price < t1.sale_price, t1.shop_price, t1.sale_price) * IF(t5.pay_percentage > 0, t5.pay_percentage, %d) / 100)) AS SIGNED) earning_price
|
||||
FROM goods_order t1
|
||||
LEFT JOIN store t5 ON t5.id = IF(t1.jx_store_id <> 0, t1.jx_store_id, t1.store_id)
|
||||
WHERE t1.order_created_at >= ? AND t1.order_created_at <= ?
|
||||
`, model.DefaultEarningPricePercentage)
|
||||
sqlParams := []interface{}{
|
||||
model.OrderStatusEndBegin,
|
||||
fromTime,
|
||||
toTime,
|
||||
}
|
||||
if len(storeIDList) > 0 {
|
||||
sql += " AND IF(t1.jx_store_id > 0, t1.jx_store_id, t1.store_id) IN (" + GenQuestionMarks(len(storeIDList)) + ")"
|
||||
sqlParams = append(sqlParams, storeIDList)
|
||||
}
|
||||
if len(statusList) > 0 {
|
||||
sql += " AND t1.status IN (" + GenQuestionMarks(len(statusList)) + ")"
|
||||
sqlParams = append(sqlParams, statusList)
|
||||
}
|
||||
sql += `
|
||||
GROUP BY 1,2,3
|
||||
ORDER BY 1,2,3`
|
||||
err = GetRows(db, &saleInfoList, sql, sqlParams...)
|
||||
return saleInfoList, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user