|
@@ -45,23 +45,63 @@ class Withdraw
|
|
|
/**
|
|
|
* 获取用户提现记录列表
|
|
|
* @param array $params 查询参数
|
|
|
- * @return \think\Paginator
|
|
|
+ * @return array 包含列表数据和统计信息
|
|
|
*/
|
|
|
public function getWithdrawList($params = [])
|
|
|
{
|
|
|
- // 构建查询条件
|
|
|
- $where = ['user_id' => $this->user->id];
|
|
|
+ // 构建查询条件数组
|
|
|
+ $arrWhere = ['user_id' => $this->user->id];
|
|
|
|
|
|
// 状态筛选
|
|
|
if (isset($params['status']) && $params['status'] !== '') {
|
|
|
- $where['status'] = (int)$params['status'];
|
|
|
+ $arrWhere['status'] = (int)$params['status'];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 年月筛选 (支持YYYY-MM格式)
|
|
|
+ $timeWhere = [];
|
|
|
+ if (isset($params['year_month']) && !empty($params['year_month'])) {
|
|
|
+ $yearMonth = trim($params['year_month']);
|
|
|
+
|
|
|
+ // 解析年月字符串 (YYYY-MM)
|
|
|
+ if (preg_match('/^(\d{4})-(\d{2})$/', $yearMonth, $matches)) {
|
|
|
+ $year = (int)$matches[1];
|
|
|
+ $month = (int)$matches[2];
|
|
|
+
|
|
|
+ // 按年月筛选
|
|
|
+ $startTime = mktime(0, 0, 0, $month, 1, $year);
|
|
|
+ $endTime = mktime(23, 59, 59, $month + 1, 0, $year);
|
|
|
+
|
|
|
+ $timeWhere = [
|
|
|
+ 'createtime' => ['between', [$startTime, $endTime]]
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 合并查询条件
|
|
|
+ $finalWhere = array_merge($arrWhere, $timeWhere);
|
|
|
+
|
|
|
+ // 计算筛选条件下的总金额(使用BC数学函数)
|
|
|
+ $totalAmount = '0.00';
|
|
|
+ $totalChargeAmount = '0.00';
|
|
|
+ $totalActualAmount = '0.00';
|
|
|
+ $totalCount = 0;
|
|
|
+
|
|
|
+ // 执行统计查询
|
|
|
+ $statsRecords = WithdrawModel::where($finalWhere)->field(['amount', 'charge_fee'])->select();
|
|
|
+
|
|
|
+ foreach ($statsRecords as $record) {
|
|
|
+ $totalAmount = BcMath::add($totalAmount, $record->amount, 2);
|
|
|
+ $totalChargeAmount = BcMath::add($totalChargeAmount, $record->charge_fee, 2);
|
|
|
+ $actualAmount = BcMath::sub($record->amount, $record->charge_fee, 2);
|
|
|
+ $totalActualAmount = BcMath::add($totalActualAmount, $actualAmount, 2);
|
|
|
+ $totalCount++;
|
|
|
}
|
|
|
|
|
|
// 分页参数
|
|
|
$page_size = isset($params['page_size']) ? (int)$params['page_size'] : 10;
|
|
|
|
|
|
- // 查询提现记录
|
|
|
- $withdraws = WithdrawModel::where($where)
|
|
|
+ // 查询提现记录(使用相同的查询条件)
|
|
|
+ $withdraws = WithdrawModel::where($finalWhere)
|
|
|
->order('id desc')
|
|
|
->paginate($page_size)
|
|
|
->each(function ($withdraw) {
|
|
@@ -69,7 +109,22 @@ class Withdraw
|
|
|
$withdraw->hidden(['withdraw_info']);
|
|
|
});
|
|
|
|
|
|
- return $withdraws;
|
|
|
+ // 组装返回数据
|
|
|
+ $result = [
|
|
|
+ 'list' => $withdraws,
|
|
|
+ 'summary' => [
|
|
|
+ 'total_count' => $totalCount,
|
|
|
+ 'total_amount' => $totalAmount,
|
|
|
+ 'total_charge_amount' => $totalChargeAmount,
|
|
|
+ 'total_actual_amount' => $totalActualAmount,
|
|
|
+ 'filter_info' => [
|
|
|
+ 'year_month' => isset($params['year_month']) ? $params['year_month'] : null,
|
|
|
+ 'status' => isset($params['status']) ? (int)$params['status'] : null,
|
|
|
+ ]
|
|
|
+ ]
|
|
|
+ ];
|
|
|
+
|
|
|
+ return $result;
|
|
|
}
|
|
|
|
|
|
/**
|