71 lines
2.1 KiB
PHP
71 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Endpoint\Api\Http\Controllers\Merchant;
|
|
|
|
use App\Endpoint\Api\Http\Controllers\Controller;
|
|
use App\Endpoint\Api\Http\Resources\QuotaLogResource;
|
|
use App\Endpoint\Api\Http\Resources\QuotaV1LogResource;
|
|
use App\Exceptions\BizException;
|
|
use App\Helpers\Paginator as PaginatorHelper;
|
|
use App\Models\QuotaV1SendLog;
|
|
use App\Models\WalletLog;
|
|
use App\Services\WalletService;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Throwable;
|
|
|
|
class QuotaLogController extends Controller
|
|
{
|
|
/**
|
|
* 配额日志
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function index(Request $request)
|
|
{
|
|
$perPage = PaginatorHelper::resolvePerPage('per_page', 20, 50);
|
|
|
|
$quotaLogs = $request->user()
|
|
->quotaLogs()
|
|
->latest('id')
|
|
->simplePaginate($perPage);
|
|
|
|
return QuotaLogResource::collection($quotaLogs);
|
|
}
|
|
|
|
public function quotaV1Logs(Request $request)
|
|
{
|
|
$perPage = PaginatorHelper::resolvePerPage('per_page', 20, 50);
|
|
return QuotaV1LogResource::collection(
|
|
QuotaV1SendLog::where('user_id', $request->user()->id)
|
|
->receive()->latest('id')
|
|
->simplePaginate($perPage));
|
|
}
|
|
|
|
/**
|
|
* 领取老配额分红
|
|
*
|
|
* @return void
|
|
*/
|
|
public function receiveQuotaV1(Request $request, WalletService $walletService)
|
|
{
|
|
$user = $request->user();
|
|
|
|
try {
|
|
DB::beginTransaction();
|
|
foreach (QuotaV1SendLog::where('user_id', $user->id)->waitReceive()->cursor() as $log) {
|
|
$log->update(['status'=>1]);
|
|
$walletService->changeBalance($user, $log->amount, WalletLog::ACTION_QUOTA_V1, '老配额分红', $log);
|
|
}
|
|
DB::commit();
|
|
} catch (Throwable $th) {
|
|
DB::rollBack();
|
|
report($th);
|
|
|
|
throw new BizException('领取失败,稍后再试');
|
|
}
|
|
return response()->noContent();
|
|
}
|
|
}
|