| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php
- namespace App\Http\Controllers\admin;
- use App\Constants\HttpStatus;
- use App\Http\Controllers\Controller;
- use App\Models\BalanceLog;
- use App\Services\BalanceLogService;
- use Carbon\Carbon;
- use Illuminate\Validation\ValidationException;
- use Exception;
- class Balance extends Controller
- {
- public function log()
- {
- try {
- $params = request()->validate([
- 'page' => ['nullable', 'integer', 'min:1'],
- 'limit' => ['nullable', 'integer', 'min:1'],
- 'member_id' => ['nullable', 'string', 'min:1'],
- 'change_type' => ['nullable', 'string', 'in:' . implode(',', BalanceLogService::$RW)],
- 'start_time' => ['nullable', 'date', 'date_format:Y-m-d', 'required_with:end_time'],
- 'end_time' => ['nullable', 'date', 'date_format:Y-m-d', 'required_with:start_time'],
- ]);
- $page = request()->input('page', 1);
- $limit = request()->input('limit', 10);
- $query = BalanceLog::where(BalanceLogService::getWhere($params));
- $data['total'] = $query->count();
- $totalAmount = '--';
- if (isset($params['member_id']) && isset($params['change_type'])) {
- $totalAmount = $query->sum('amount');
- $totalAmount = bcadd($totalAmount, 0, 2);
- }
- $data['total_amount'] =$totalAmount;
- $data['data'] = $query->orderByDesc('id')
- ->forPage($page, $limit)->with(['member'])
- ->get()->toArray();
- $data['change_types'] = BalanceLogService::$RW;
- } catch (ValidationException $e) {
- return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
- } catch (Exception $e) {
- return $this->error(intval($e->getCode()));
- }
- return $this->success($data);
- }
- }
|