fix version 1
This commit is contained in:
@@ -33,45 +33,65 @@ func GetWallet(ctx context.Context, in *pb.GetWalletRequest) (reply *pb.GetWalle
|
||||
ymd, _ := strconv.Atoi(time.Now().Format(vars.YYYYMMDD))
|
||||
ym := time.Now().Year()*100 + int(time.Now().Month())
|
||||
|
||||
var totalMoney int64
|
||||
total := make(map[string]int64)
|
||||
var (
|
||||
total = make(map[string]int64)
|
||||
stat int64
|
||||
)
|
||||
|
||||
// 统计当日收入
|
||||
if in.IsTotalTodayIn {
|
||||
impl.DBService.Model(&models.WalletRecord{}).Select("sum(money)").Where("passport_id=? AND trans_type=? AND ymd=?", auth.ID, transIn, ymd).Scan(&totalMoney)
|
||||
total["TodayIn"] = totalMoney
|
||||
stat = 0
|
||||
if err = impl.DBService.Model(&models.WalletRecord{}).Select("sum(money)").Where("passport_id=? AND trans_type=? AND ymd=?", auth.ID, transIn, ymd).Scan(&stat).Error; err != nil {
|
||||
printer.Error(err.Error())
|
||||
}
|
||||
total["TodayIn"] = stat
|
||||
}
|
||||
|
||||
// 统计当日支出
|
||||
if in.IsTotalTodayOut {
|
||||
impl.DBService.Model(&models.WalletRecord{}).Select("sum(money)").Where("passport_id=? AND trans_type=? AND ymd=?", auth.ID, transOut, ymd).Scan(&totalMoney)
|
||||
total["TodayOut"] = totalMoney
|
||||
stat = 0
|
||||
if err = impl.DBService.Model(&models.WalletRecord{}).Select("sum(money)").Where("passport_id=? AND trans_type=? AND ymd=?", auth.ID, transOut, ymd).Scan(&stat).Error; err != nil {
|
||||
printer.Error(err.Error())
|
||||
}
|
||||
total["TodayOut"] = stat
|
||||
}
|
||||
|
||||
// 统计本月收入
|
||||
if in.IsTotalMonthIn {
|
||||
impl.DBService.Model(&models.WalletRecord{}).Select("sum(money)").Where("passport_id=? AND trans_type=? AND ym=?", auth.ID, transIn, ym).Scan(&totalMoney)
|
||||
total["MonthIn"] = totalMoney
|
||||
stat = 0
|
||||
if err = impl.DBService.Model(&models.WalletRecord{}).Select("sum(money)").Where("passport_id=? AND trans_type=? AND ym=?", auth.ID, transIn, ym).Scan(&stat).Error; err != nil {
|
||||
printer.Error(err.Error())
|
||||
}
|
||||
total["MonthIn"] = stat
|
||||
}
|
||||
|
||||
// 统计本月支出
|
||||
if in.IsTotalMonthOut {
|
||||
impl.DBService.Model(&models.WalletRecord{}).Select("sum(money)").Where("passport_id=? AND trans_type=? AND ym=?", auth.ID, transOut, ym).Scan(&totalMoney)
|
||||
total["MonthOut"] = totalMoney
|
||||
stat = 0
|
||||
if err = impl.DBService.Model(&models.WalletRecord{}).Select("sum(money)").Where("passport_id=? AND trans_type=? AND ym=?", auth.ID, transOut, ym).Scan(&stat).Error; err != nil {
|
||||
printer.Error(err.Error())
|
||||
}
|
||||
total["MonthOut"] = stat
|
||||
}
|
||||
|
||||
// 统计全部收入
|
||||
if in.IsTotalAllIn {
|
||||
impl.DBService.Model(&models.WalletRecord{}).Select("sum(money)").Where("passport_id=? AND trans_type=? ", auth.ID, transIn).Scan(&totalMoney)
|
||||
total["AllIn"] = totalMoney
|
||||
stat = 0
|
||||
if err = impl.DBService.Model(&models.WalletRecord{}).Select("sum(money)").Where("passport_id=? AND trans_type=? ", auth.ID, transIn).Scan(&stat).Error; err != nil {
|
||||
printer.Error(err.Error())
|
||||
}
|
||||
total["AllIn"] = stat
|
||||
}
|
||||
|
||||
// 统计全部支出
|
||||
if in.IsTotalAllOut {
|
||||
impl.DBService.Model(&models.WalletRecord{}).Select("sum(money)").Where("passport_id=? AND trans_type=? ", auth.ID, transOut).Scan(&totalMoney)
|
||||
total["AllOut"] = totalMoney
|
||||
stat = 0
|
||||
if err = impl.DBService.Model(&models.WalletRecord{}).Select("sum(money)").Where("passport_id=? AND trans_type=? ", auth.ID, transOut).Scan(&stat).Error; err != nil {
|
||||
printer.Error(err.Error())
|
||||
}
|
||||
total["AllOut"] = stat
|
||||
}
|
||||
// remove useless fmt.Sprint side-effect-free call
|
||||
|
||||
return &pb.GetWalletReply{
|
||||
PassportIdentity: myWallet.PassportIdentity,
|
||||
WalletIdentity: myWallet.Identity,
|
||||
|
||||
Reference in New Issue
Block a user