package dao import ( "time" "git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/jx-callback/business/model" ) func GetUserBill(db *DaoDB, userID, billID string) (userBill *model.UserBill, err error) { sql := ` SELECT * FROM user_bill WHERE deleted_at = ? ` sqlParams := []interface{}{utils.DefaultTimeValue} if userID != "" { sql += ` AND user_id = ?` sqlParams = append(sqlParams, userID) } if billID != "" { sql += ` AND bill_id = ?` sqlParams = append(sqlParams, billID) } err = GetRow(db, &userBill, sql, sqlParams) return userBill, err } func GetBillExpend(db *DaoDB, userID string, billType int, fromTime, toTime time.Time) (billExpends []*model.BillExpend, err error) { sql := ` SELECT b.* FROM user_bill a JOIN bill_expend b ON b.bill_id = a.bill_id WHERE a.deleted_at = ? ` sqlParams := []interface{}{utils.DefaultTimeValue} if userID != "" { sql += ` AND a.user_id = ?` sqlParams = append(sqlParams, userID) } if billType != 0 { sql += ` AND b.type = ?` sqlParams = append(sqlParams, billType) } if fromTime != utils.ZeroTimeValue { sql += ` AND b.created_at >= ?` sqlParams = append(sqlParams, fromTime) } if toTime != utils.ZeroTimeValue { sql += ` AND b.created_at <= ?` sqlParams = append(sqlParams, toTime) } err = GetRow(db, &billExpends, sql, sqlParams) return billExpends, err }