From b5bf9ade80980a80ec8b6602737f221819fbc0d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Thu, 4 Mar 2021 16:51:41 +0800 Subject: [PATCH] aa --- business/model/dao/store.go | 76 +++++++++++++++++++++++++++++-------- 1 file changed, 60 insertions(+), 16 deletions(-) diff --git a/business/model/dao/store.go b/business/model/dao/store.go index d339b7bfb..0b7cdf912 100644 --- a/business/model/dao/store.go +++ b/business/model/dao/store.go @@ -1011,7 +1011,7 @@ func GetBrands(db *DaoDB, name string, brandID int) (brands []*model.Brand, err return brands, err } -func GetStoreAcctIncome(db *DaoDB, storeID, incomeType int, fromTime, toTime time.Time) (storeAcctIncomes []*model.StoreAcctIncome, err error) { +func GetStoreAcctIncome(db *DaoDB, storeID int, incomeTypes []int, vendorOrderID string, fromTime, toTime time.Time) (storeAcctIncomes []*model.StoreAcctIncome, err error) { sql := ` SELECT * FROM store_acct_income @@ -1022,9 +1022,13 @@ func GetStoreAcctIncome(db *DaoDB, storeID, incomeType int, fromTime, toTime tim sql += " AND store_id = ?" sqlParams = append(sqlParams, storeID) } - if incomeType != 0 { - sql += " AND type = ?" - sqlParams = append(sqlParams, incomeType) + if len(incomeTypes) > 0 { + sql += " AND type IN (" + GenQuestionMarks(len(incomeTypes)) + ")" + sqlParams = append(sqlParams, incomeTypes) + } + if vendorOrderID != "" { + sql += " AND vendor_order_id = ?" + sqlParams = append(sqlParams, vendorOrderID) } if utils.IsTimeZero(fromTime) { sql += " AND created_at >= ?" @@ -1038,7 +1042,7 @@ func GetStoreAcctIncome(db *DaoDB, storeID, incomeType int, fromTime, toTime tim return storeAcctIncomes, err } -func GetStoreAcctIncomeTotal(db *DaoDB, storeID, incomeType int, fromTime, toTime time.Time) (incomeTotal int, err error) { +func GetStoreAcctIncomeTotal(db *DaoDB, storeID int, incomeTypes []int, vendorOrderID string, fromTime, toTime time.Time) (incomeTotal int, err error) { var income *model.StoreAcctIncome sql := ` SELECT SUM(income_price) income_price @@ -1050,9 +1054,13 @@ func GetStoreAcctIncomeTotal(db *DaoDB, storeID, incomeType int, fromTime, toTim sql += " AND store_id = ?" sqlParams = append(sqlParams, storeID) } - if incomeType != 0 { - sql += " AND type = ?" - sqlParams = append(sqlParams, incomeType) + if len(incomeTypes) > 0 { + sql += " AND type IN (" + GenQuestionMarks(len(incomeTypes)) + ")" + sqlParams = append(sqlParams, incomeTypes) + } + if vendorOrderID != "" { + sql += " AND vendor_order_id = ?" + sqlParams = append(sqlParams, vendorOrderID) } if utils.IsTimeZero(fromTime) { sql += " AND created_at >= ?" @@ -1066,7 +1074,7 @@ func GetStoreAcctIncomeTotal(db *DaoDB, storeID, incomeType int, fromTime, toTim return income.IncomePrice, err } -func GetStoreAcctExpend(db *DaoDB, storeID, expendType int, fromTime, toTime time.Time) (storeAcctExpends []*model.StoreAcctExpend, err error) { +func GetStoreAcctExpend(db *DaoDB, storeID int, expendTypes []int, vendorOrderID string, fromTime, toTime time.Time) (storeAcctExpends []*model.StoreAcctExpend, err error) { sql := ` SELECT * FROM store_acct_expend @@ -1077,9 +1085,13 @@ func GetStoreAcctExpend(db *DaoDB, storeID, expendType int, fromTime, toTime tim sql += " AND store_id = ?" sqlParams = append(sqlParams, storeID) } - if expendType != 0 { - sql += " AND type = ?" - sqlParams = append(sqlParams, expendType) + if len(expendTypes) > 0 { + sql += " AND type IN (" + GenQuestionMarks(len(expendTypes)) + ")" + sqlParams = append(sqlParams, expendTypes) + } + if vendorOrderID != "" { + sql += " AND vendor_order_id = ?" + sqlParams = append(sqlParams, vendorOrderID) } if utils.IsTimeZero(fromTime) { sql += " AND created_at >= ?" @@ -1093,7 +1105,7 @@ func GetStoreAcctExpend(db *DaoDB, storeID, expendType int, fromTime, toTime tim return storeAcctExpends, err } -func GetStoreAcctExpendTotal(db *DaoDB, storeID, expendType int, fromTime, toTime time.Time) (expendTotal int, err error) { +func GetStoreAcctExpendTotal(db *DaoDB, storeID int, expendTypes []int, vendorOrderID string, fromTime, toTime time.Time) (expendTotal int, err error) { var expend *model.StoreAcctExpend sql := ` SELECT SUM(expend_price) expend_price @@ -1105,9 +1117,13 @@ func GetStoreAcctExpendTotal(db *DaoDB, storeID, expendType int, fromTime, toTim sql += " AND store_id = ?" sqlParams = append(sqlParams, storeID) } - if expendType != 0 { - sql += " AND type = ?" - sqlParams = append(sqlParams, expendType) + if len(expendTypes) > 0 { + sql += " AND type IN (" + GenQuestionMarks(len(expendTypes)) + ")" + sqlParams = append(sqlParams, expendTypes) + } + if vendorOrderID != "" { + sql += " AND vendor_order_id = ?" + sqlParams = append(sqlParams, vendorOrderID) } if utils.IsTimeZero(fromTime) { sql += " AND created_at >= ?" @@ -1120,3 +1136,31 @@ func GetStoreAcctExpendTotal(db *DaoDB, storeID, expendType int, fromTime, toTim err = GetRow(db, &expend, sql, sqlParams) return expend.ExpendPrice, err } + +type GetStoreAcctExpendLastCreateWayBillFeeResult struct { +} + +func GetStoreAcctExpendLastCreateWayBillFee(db *DaoDB, vendorOrderID string) (lastFee int, err error) { + var expend *model.StoreAcctExpend + sql := ` + SELECT a.id, b.id exp_id, c.id inc_id + FROM store_acct_expend a + LEFT JOIN store_acct_expend b ON a.id = b.exp_id + LEFT JOIN store_acct_income c ON a.id = c.exp_id + WHERE 1 = 1 + AND a.type = ? + ` + sqlParams := []interface{}{ + 20, + } + if vendorOrderID != "" { + sql += " AND vendor_order_id = ?" + sqlParams = append(sqlParams, vendorOrderID) + } + sql += ` + ORDER BY a.created_at DESC + LIMIT 1 + ` + err = GetRow(db, &expend, sql, sqlParams) + return expend.ExpendPrice, err +}