Browse Source

地接提现

master
lemon 4 years ago
parent
commit
c7247e64d6
  1. 96
      app/AdminGuide/Controllers/WithdrawalAlipayController.php
  2. 83
      app/AdminGuide/Controllers/WithdrawalBankController.php
  3. 4
      app/AdminGuide/routes.php

96
app/AdminGuide/Controllers/WithdrawalAlipayController.php

@ -3,13 +3,18 @@
namespace App\AdminGuide\Controllers;
use App\AdminGuide\Repositories\WithdrawalAlipay;
use App\Common\StatementType;
use App\Models\Agent;
use App\Models\Guide;
use App\Models\SystemSetting;
use App\Models\Withdrawal;
use App\Service\WithdrawalService;
use App\Traits\DemandTraits;
use App\Traits\WithdrawalTraits;
use Dcat\Admin\Admin;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Repositories\EloquentRepository;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;
use Illuminate\Database\Eloquent\Model;
@ -23,9 +28,9 @@ class WithdrawalAlipayController extends AdminController
*
* @return Form
*/
protected function form()
{
return Form::make(new WithdrawalAlipay(), function (Form $form) {
protected function form()
{
return Form::make(new WithdrawalAlipay(), function (Form $form) {
$auto = Withdrawal::query()
->with('pay')
->where([
@ -36,40 +41,71 @@ class WithdrawalAlipayController extends AdminController
])
->orderByDesc('updated_at')
->first();
$form->display('id');
$form->decimal('price','提现金额')->required()->type('number')->attribute('min', 0)->default($auto->price ?? 0);
$min = SystemSetting::val('withdrawal', WithdrawalTraits::$adminType[3]) ?? 0;
$form->decimal('price','提现金额')->rules('required|numeric|min:'.$min.'|not_in:0',[
'*' => '提现金额为必填字段且必须大于'.$min,
])
->default($auto->price ?? 0)
->help('含手续费' . SystemSetting::val('withdrawal', WithdrawalTraits::$adminType[2]) . ' %,最小提现金额'.$min);
$form->text('account')->required()->maxLength(50)->default($auto->pay->account ?? '');
$form->text('name')->required()->maxLength(50)->default($auto->pay->name ?? '');
$form->image('qrcode');
$form->hidden('withdrawal_id');
$form->saving(function (Form $form) {
$user = Agent::query()->where('id', Admin::user()->id)->lockForUpdate()->first();
if ($form->price > $user->balance) {
return $form->response()->error('余额不足,当前可用余额为'.$user->balance);
}
$user->balance = bcsub($user->balance,$form->price,6);
$user->save();
$form->saving(function (Form $form) {
DB::beginTransaction();
try {
$user = Guide::query()->where('id', Admin::user()->id)->lockForUpdate()->first();
//手续费
$cutPrice = bcmul($form->price, SystemSetting::val('withdrawal', WithdrawalTraits::$adminType[2]), 6);
$cutPrice = $cutPrice > 0 ? bcdiv($cutPrice, 100, 6) : 0;
//总花费
$total = bcadd($form->price, $cutPrice,6);
if ($total > $user->balance) {
return $form->response()->error('余额不足,本次提现需花费'.bcadd($total,0,2).'(含手续费),当前可用余额为' . $user->balance);
}
//提现扣钱流水
$service = new WithdrawalService();
$service->create(
bcmul($form->price, -1, 6),
StatementType::WITHDRAWAL,
Admin::user()->id,
DemandTraits::$col[2]
);
//提现手续费流水
$service->create(
bcmul($cutPrice, -1, 6),
StatementType::WITHDRAWAL_CAT,
Admin::user()->id,
DemandTraits::$col[2]
);
$user->balance = bcsub($user->balance, $total, 6);
$user->save();
$withdrawal = new Withdrawal();
$withdrawal->user_id = Admin::user()->id;
$withdrawal->user_type = DemandTraits::$col[2];
$withdrawal->price = request('price',0);
//$withdrawal->pay_id = $form->getKey();
$withdrawal->pay_type = WithdrawalTraits::$userType[0];
$withdrawal->save();
$withdrawal = new Withdrawal();
$withdrawal->user_id = Admin::user()->id;
$withdrawal->user_type = DemandTraits::$col[2];
$withdrawal->price = request('price', 0);
$withdrawal->cut_price = $cutPrice;
//$withdrawal->pay_id = $form->getKey();
$withdrawal->pay_type = WithdrawalTraits::$userType[0];
$withdrawal->save();
$form->withdrawal_id = $withdrawal->id;
$form->deleteInput('price');
});
$form->withdrawal_id = $withdrawal->id;
$form->deleteInput('price');
DB::commit();
} catch (\Exception $e) {
DB::rollBack();
return $form->response()->error($e->getMessage());
}
});
$form->saved(function (Form $form) {
$withdrawal = Withdrawal::find($form->withdrawal_id);
$withdrawal->pay_id = $form->getKey();
$withdrawal->save();
});
});
}
$form->saved(function (Form $form) {
$withdrawal = Withdrawal::find($form->withdrawal_id);
$withdrawal->pay_id = $form->getKey();
$withdrawal->save();
});
});
}
}

83
app/AdminGuide/Controllers/WithdrawalBankController.php

@ -3,16 +3,22 @@
namespace App\AdminGuide\Controllers;
use App\AdminGuide\Repositories\WithdrawalBank;
use App\Common\StatementType;
use App\Models\Agent;
use App\Models\Guide;
use App\Models\SystemSetting;
use App\Models\Withdrawal;
use App\Service\WithdrawalService;
use App\Traits\DemandTraits;
use App\Traits\WithdrawalTraits;
use Dcat\Admin\Admin;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Repositories\EloquentRepository;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
class WithdrawalBankController extends AdminController
{
@ -22,9 +28,10 @@ class WithdrawalBankController extends AdminController
*
* @return Form
*/
protected function form()
{
return Form::make(new WithdrawalBank(), function (Form $form) {
protected function form()
{
return Form::make(new WithdrawalBank(), function (Form $form) {
$auto = Withdrawal::query()
->with('pay')
->where([
@ -36,7 +43,12 @@ class WithdrawalBankController extends AdminController
->orderByDesc('updated_at')
->first();
$form->display('id');
$form->decimal('price','提现金额')->required()->maxLength(50)->default($auto->price ?? 0);
$min = SystemSetting::val('withdrawal', WithdrawalTraits::$adminType[3]) ?? 0;
$form->decimal('price','提现金额')->rules('required|numeric|min:'.$min.'|not_in:0',[
'*' => '提现金额为必填字段且必须大于'.$min,
])
->default($auto->price ?? 0)
->help('含手续费' . SystemSetting::val('withdrawal', WithdrawalTraits::$adminType[2]) . ' %,最小提现金额'.$min);
$form->text('name')->required()->maxLength(50)->default($auto->pay->name ?? '');
$form->text('card_number')->required()->maxLength(50)->type('number')->default($auto->pay->card_number ?? '');
$form->text('account_name')->required()->maxLength(50)->default($auto->pay->account_name ?? '');
@ -44,24 +56,52 @@ class WithdrawalBankController extends AdminController
$form->hidden('withdrawal_id');
$form->saving(function (Form $form) {
$user = Agent::query()->where('id', Admin::user()->id)->lockForUpdate()->first();
if ($form->price > $user->balance) {
return $form->response()->error('余额不足,当前可用余额为'.$user->balance);
}
DB::beginTransaction();
try {
$user = Guide::query()->where('id', Admin::user()->id)->lockForUpdate()->first();
//手续费
$cutPrice = bcmul($form->price, SystemSetting::val('withdrawal', WithdrawalTraits::$adminType[2]), 6);
$cutPrice = $cutPrice > 0 ? bcdiv($cutPrice, 100, 6) : 0;
//总花费
$total = bcadd($form->price, $cutPrice,6);
if ($total > $user->balance) {
return $form->response()->error('余额不足,本次提现需花费'.bcadd($total,0,2).'(含手续费),当前可用余额为' . $user->balance);
}
//提现扣钱流水
$service = new WithdrawalService();
$service->create(
bcmul($form->price, -1, 6),
StatementType::WITHDRAWAL,
Admin::user()->id,
DemandTraits::$col[2]
);
//提现手续费流水
$service->create(
bcmul($cutPrice, -1, 6),
StatementType::WITHDRAWAL_CAT,
Admin::user()->id,
DemandTraits::$col[2]
);
$user->balance = bcsub($user->balance,$form->price,6);
$user->save();
$user->balance = bcsub($user->balance, $total, 6);
$user->save();
$withdrawal = new Withdrawal();
$withdrawal->user_id = Admin::user()->id;
$withdrawal->user_type = DemandTraits::$col[2];
$withdrawal->price = request('price',0);
//$withdrawal->pay_id = $form->getKey();
$withdrawal->pay_type = WithdrawalTraits::$userType[1];
$withdrawal->save();
$withdrawal = new Withdrawal();
$withdrawal->user_id = Admin::user()->id;
$withdrawal->user_type = DemandTraits::$col[2];
$withdrawal->price = request('price', 0);
$withdrawal->cut_price = $cutPrice;
//$withdrawal->pay_id = $form->getKey();
$withdrawal->pay_type = WithdrawalTraits::$userType[1];
$withdrawal->save();
$form->withdrawal_id = $withdrawal->id;
$form->deleteInput('price');
$form->withdrawal_id = $withdrawal->id;
$form->deleteInput('price');
DB::commit();
} catch (\Exception $e) {
DB::rollBack();
return $form->response()->error($e->getMessage());
}
});
$form->saved(function (Form $form) {
@ -69,6 +109,7 @@ class WithdrawalBankController extends AdminController
$withdrawal->pay_id = $form->getKey();
$withdrawal->save();
});
});
}
});
}
}

4
app/AdminGuide/routes.php

@ -31,4 +31,8 @@ Route::group([
$router->any('workorder_item', 'WorkorderController@index');
$router->any('workorder_notice', 'WorkorderController@checkUnread');
$router->resource('wallet', 'WalletController');
$router->resource('withdrawak_alipay', 'WithdrawalAlipayController');
$router->resource('withdrawak_bank', 'WithdrawalBankController');
});
Loading…
Cancel
Save