6
0
Fork 0

批领余额转账

release
vine_liutk 2022-02-21 17:37:38 +08:00
parent 4f4d6a5115
commit 6fb338a443
6 changed files with 58 additions and 3 deletions

View File

@ -365,6 +365,7 @@ class WalletController extends Controller
} catch (Throwable $th) {
DB::rollBack();
report($th);
throw new BizException('转账失败,请稍后再试');
}
return response()->noContent();

View File

@ -11,6 +11,8 @@ use App\Exceptions\BizException;
use App\Exceptions\PayPasswordIncorrectException;
use App\Helpers\Paginator as PaginatorHelper;
use App\Models\DealerWalletToBankLog;
use App\Models\User;
use App\Rules\PhoneNumber;
use App\Services\Dealer\WalletService;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
@ -60,7 +62,7 @@ class WalletController extends Controller
}
//校验是否关闭提现
if (!$user->dealerWallet?->withdrawable) {
throw new BizException('可提账户已被限制提现');
throw new BizException('账户已被限制提现');
}
//检测是否可以提现
@ -103,6 +105,53 @@ class WalletController extends Controller
return response()->noContent();
}
/**
* 余额转账
*
* @return void
*/
public function walletTransfer(Request $request, WalletService $walletService)
{
$input = $request->validate([
'phone' => ['bail', 'required', new PhoneNumber()],
'amount' => ['bail', 'required', 'int', 'min:1'],
'pay_password' => ['bail', 'required', 'filled', 'string', 'size:6'],
]);
$user = $request->user();
//校验是否关闭
if (!$user->dealerWallet?->withdrawable) {
throw new BizException('账户已被限制转账');
}
//判断转账对象是否存在
$toUser = User::where('phone', '=', $input['phone'])->first();
if (is_null($toUser)) {
throw new BizException('转账对象不存在');
}
//校验安全密码
if (! $user->wallet?->verifyPassword($input['pay_password'])) {
throw new PayPasswordIncorrectException();
}
try {
DB::beginTransaction();
//转出对象
$log = $walletService->changeBalance($user, -Arr::get($input, 'amount', 0), DealerWalletAction::TransferOut, '转出-'.$toUser->phone.($toUser->userInfo?->nickname ? '【'.$toUser->userInfo->nickname.'】' : ''));
//转入对象
$walletService->changeBalance($toUser, Arr::get($input, 'amount', 0), DealerWalletAction::TransferIn, $user->phone.($user->userInfo?->nickname ? '【'.$user->userInfo->nickname.'】' : '').'-转入', $log);
DB::commit();
} catch (Throwable $th) {
DB::rollBack();
report($th);
throw new BizException('转账失败,请稍后再试');
}
return response()->noContent();
}
/**
* 提现记录
*

View File

@ -278,6 +278,7 @@ Route::group([
Route::post('earnings/{earning}/confirm', [Dealer\EarningController::class, 'confirmEarning']);
//余额提现
Route::get('wallet', [Dealer\WalletController::class, 'index']);
Route::post('wallet/transfer', [Dealer\WalletController::class, 'walletTransfer']);
Route::post('wallet/withdraw', [Dealer\WalletController::class, 'walletToBank']);
Route::get('wallet/withdraw-logs', [Dealer\WalletController::class, 'walletToBankLogs']);
Route::get('wallet/withdraw-logs/{withdraw_log}', [Dealer\WalletController::class, 'walletToBankLogShow']);

View File

@ -11,4 +11,6 @@ enum DealerWalletAction: int {
case WithdrawFiled = 6;
case OrderPaid = 7;
case OrderIncome = 8;
case TransferIn = 9;
case TransferOut = 10;
}

View File

@ -64,6 +64,7 @@ class AppServiceProvider extends ServiceProvider
'dealer_purchase_subsidy' => \App\Models\DealerPurchaseSubsidy::class,
'dealer_wallet_to_bank_log' => \App\Models\DealerWalletToBankLog::class,
'dealer_earnings'=> \App\Models\DealerEarning::class,
'dealer_wallet_log'=> \App\Models\DealerWalletLog::class,
]);
JsonResource::withoutWrapping();

View File

@ -5,6 +5,7 @@ namespace App\Services\Dealer;
use App\Enums\DealerWalletAction;
use App\Exceptions\BizException;
use App\Models\DealerWallet;
use App\Models\DealerWalletLog;
use App\Models\User;
use Illuminate\Database\Eloquent\Model;
@ -18,7 +19,7 @@ class WalletService
* @param \App\Enums\DealerWalletAction $action
* @param string|null $remarks
* @param \Illuminate\Database\Eloquent\Model|null $loggable
* @return void
* @return DealerWalletLog $log
*/
public function changeBalance(User $user, $changeBalance, DealerWalletAction $action, ?string $remarks = null, ?Model $loggable = null)
{
@ -53,7 +54,7 @@ class WalletService
]);
}
$user->dealerWalletLogs()->create([
return $user->dealerWalletLogs()->create([
'loggable_id' => $loggable?->id,
'loggable_type' => $loggable?->getMorphClass(),
'before_balance' => $beforeBalance,