Commit 48708b23 authored by wangzhengwen's avatar wangzhengwen

资金统计

parent e51aa794
......@@ -52,6 +52,58 @@ class User extends BaseController
$info_status = Db::name('school')->where('user_id', $user['id'])->value('status');
}
$user['info_status'] = $info_status;
if ($user['role'] == 1)
{
// 获取当前月份和上个月的起始和结束时间戳
$currentMonthStart = strtotime(date('Y-m-01 00:00:00'));
$currentMonthEnd = strtotime(date('Y-m-t 23:59:59'));
$lastMonthStart = strtotime(date('Y-m-01 00:00:00', strtotime('-1 month')));
$lastMonthEnd = strtotime(date('Y-m-t 23:59:59', strtotime('-1 month')));
// 本月收入 (类型为0-项目结算和2-后台手动增加)
$currentMonthIncome = UserMoneyLog::where('user_id', $user['id'])
->whereIn('type', [0, 2])
->where('money_type',0)
->whereBetween('createtime', [$currentMonthStart, $currentMonthEnd])
->sum('money');
$user['financial']['current_month_income'] = number_format($currentMonthIncome,2);
// 本月支出 (类型为1-提现)
$currentMonthExpense = abs(UserMoneyLog::where('user_id', $user['id'])
->whereIn('type', [1])
->where('money_type',0)
->whereBetween('createtime', [$currentMonthStart, $currentMonthEnd])
->sum('money'));
$user['financial']['current_month_expense'] = number_format($currentMonthExpense,2);
// 上月收入
$lastMonthIncome = UserMoneyLog::where('user_id', $user['id'])
->whereIn('type', [0, 2])
->where('money_type',0)
->whereBetween('createtime', [$lastMonthStart, $lastMonthEnd])
->sum('money');
$user['financial']['lastMonthIncome'] = number_format($lastMonthIncome,2);
// 上月支出
$lastMonthExpense = abs(UserMoneyLog::where('user_id', $user['id'])
->whereIn('type', [1])
->where('money_type',0)
->whereBetween('createtime', [$lastMonthStart, $lastMonthEnd])
->sum('money'));
$user['financial']['lastMonthExpense'] = number_format($lastMonthExpense,2);
// 计算较上月百分比
$user['financial']['income_change_percent'] = $lastMonthIncome != 0
? number_format(($currentMonthIncome - $lastMonthIncome) / $lastMonthIncome * 100, 2)
: ($currentMonthIncome != 0 ? '100.00' : '0.00');
$user['financial']['expense_change_percent'] = $lastMonthExpense != 0
? number_format(($currentMonthExpense - $lastMonthExpense) / $lastMonthExpense * 100, 2)
: ($currentMonthExpense != 0 ? '100.00' : '0.00');
}
return $this->returnMsg('操作成功', 1, $user);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment