8 changed files with 320 additions and 0 deletions
-
1app/AdminAgent/Controllers/WalletController.php
-
140app/AdminSupplier/Controllers/WalletController.php
-
64app/AdminSupplier/Controllers/WithdrawalAlipayController.php
-
64app/AdminSupplier/Controllers/WithdrawalBankController.php
-
16app/AdminSupplier/Repositories/Withdrawal.php
-
16app/AdminSupplier/Repositories/WithdrawalAlipay.php
-
16app/AdminSupplier/Repositories/WithdrawalBank.php
-
3app/AdminSupplier/routes.php
@ -0,0 +1,140 @@ |
|||
<?php |
|||
|
|||
namespace App\AdminSupplier\Controllers; |
|||
|
|||
use App\AdminSupplier\Repositories\Withdrawal; |
|||
use App\Traits\DemandTraits; |
|||
use App\Traits\WithdrawalTraits; |
|||
use Dcat\Admin\Admin; |
|||
use Dcat\Admin\Form; |
|||
use Dcat\Admin\Grid; |
|||
use Dcat\Admin\Layout\Column; |
|||
use Dcat\Admin\Layout\Content; |
|||
use Dcat\Admin\Layout\Row; |
|||
use Dcat\Admin\Http\Controllers\AdminController; |
|||
use Dcat\Admin\Widgets\Card; |
|||
|
|||
class WalletController extends AdminController |
|||
{ |
|||
public function index(Content $content) |
|||
{ |
|||
return $content |
|||
->body( |
|||
<<<HTML |
|||
<div class="content-header"> |
|||
<section class="content-header breadcrumbs-top"> |
|||
<h1 class=" float-left"> |
|||
<span class="text-capitalize">我的钱包</span> |
|||
|
|||
</h1> |
|||
<div class="clearfix"></div> |
|||
|
|||
</section> |
|||
</div> |
|||
HTML |
|||
|
|||
) |
|||
->body($this->build()) |
|||
->body(function (Row $row) { |
|||
|
|||
$row->column(4, function (Column $column){ |
|||
$column->row(Card::make('当前余额', function () { |
|||
$balance = Admin::user()->balance ?? 0; |
|||
return <<<HTML |
|||
<div class="d-flex justify-content-between align-items-center mt-1" style="margin-bottom: 2px"> |
|||
<h2 class="ml-1 font-large-1 text-primary">$balance</h2> |
|||
</div> |
|||
HTML; |
|||
})); |
|||
}); |
|||
|
|||
$row->column(4, function (Column $column){ |
|||
$column->row(Card::make('已提现', function () { |
|||
$price = \App\Models\Withdrawal::query() |
|||
->where([ |
|||
'user_id' => Admin::user()->id, |
|||
'user_type' => DemandTraits::$col[1], |
|||
'status' => WithdrawalTraits::$state[3] |
|||
]) |
|||
->sum('price'); |
|||
return <<<HTML |
|||
<div class="d-flex justify-content-between align-items-center mt-1" style="margin-bottom: 2px"> |
|||
<h2 class="ml-1 font-large-1 text-primary">$price</h2> |
|||
</div> |
|||
HTML; |
|||
})); |
|||
|
|||
}); |
|||
|
|||
$row->column(4, function (Column $column) { |
|||
$column->row(Card::make('提现中', function () { |
|||
$price = \App\Models\Withdrawal::query() |
|||
->where([ |
|||
'user_id' => Admin::user()->id, |
|||
'user_type' => DemandTraits::$col[1], |
|||
'status' => WithdrawalTraits::$state[0] |
|||
]) |
|||
->sum('price'); |
|||
return <<<HTML |
|||
<div class="d-flex justify-content-between align-items-center mt-1" style="margin-bottom: 2px"> |
|||
<h2 class="ml-1 font-large-1 text-primary">$price</h2> |
|||
</div> |
|||
HTML; |
|||
})); |
|||
|
|||
}); |
|||
|
|||
}) |
|||
->body( |
|||
Grid::make(new Withdrawal(), function (Grid $grid) { |
|||
$grid->model()->where(['user_id' => Admin::user()->id,'user_type' => DemandTraits::$col[1]]); |
|||
$grid->disableActions(); |
|||
//$grid->disable();
|
|||
$grid->column('id')->sortable(); |
|||
$grid->column('price','提现金额'); |
|||
$grid->column('pay_type','提现方式')->using(WithdrawalTraits::$userTypeText); |
|||
//$grid->column('pay_id');
|
|||
$grid->column('status','状态')->using(WithdrawalTraits::$stateText)->dot([ |
|||
|
|||
1 => Admin::color()->yellow(), |
|||
2 => 'danger', |
|||
3 => 'success', |
|||
4 => Admin::color()->info(), |
|||
|
|||
]); |
|||
$grid->column('created_at'); |
|||
$grid->column('updated_at')->sortable(); |
|||
$grid->disableCreateButton(); |
|||
$grid->disableRowSelector(); |
|||
$grid->filter(function (Grid\Filter $filter) { |
|||
$filter->equal('id')->width(3); |
|||
$filter->equal('status','状态')->select(WithdrawalTraits::$stateTextSelect)->width(2); |
|||
}); |
|||
}) |
|||
|
|||
); |
|||
} |
|||
|
|||
protected function build() |
|||
{ |
|||
Form::dialog('支付宝提现') |
|||
->click('.alipay-create-form') // 绑定点击按钮
|
|||
->url('/withdrawak_alipay/create') // 表单页面链接,此参数会被按钮中的 “data-url” 属性替换。。
|
|||
->width('700px') // 指定弹窗宽度,可填写百分比,默认 720px
|
|||
->height('650px') // 指定弹窗高度,可填写百分比,默认 690px
|
|||
->success('Dcat.reload()'); // 新增成功后刷新页面
|
|||
|
|||
Form::dialog('银行卡提现') |
|||
->click('.bank-create-form') // 绑定点击按钮
|
|||
->url('/withdrawak_bank/create') // 表单页面链接,此参数会被按钮中的 “data-url” 属性替换。。
|
|||
->width('700px') // 指定弹窗宽度,可填写百分比,默认 720px
|
|||
->height('650px') // 指定弹窗高度,可填写百分比,默认 690px
|
|||
->success('Dcat.reload()'); // 新增成功后刷新页面
|
|||
|
|||
return "
|
|||
<div style='padding:30px 0'> |
|||
<span class='btn btn-success alipay-create-form'> 支付宝提现 </span> |
|||
<span class='btn btn-success bank-create-form'> 银行卡提现 </span> |
|||
</div>";
|
|||
} |
|||
} |
|||
@ -0,0 +1,64 @@ |
|||
<?php |
|||
|
|||
namespace App\AdminSupplier\Controllers; |
|||
|
|||
use App\AdminAgent\Repositories\WithdrawalAlipay; |
|||
use App\Models\Agent; |
|||
use App\Models\Withdrawal; |
|||
use App\Traits\DemandTraits; |
|||
use App\Traits\WithdrawalTraits; |
|||
use Dcat\Admin\Admin; |
|||
use Dcat\Admin\Form; |
|||
use Dcat\Admin\Grid; |
|||
use Dcat\Admin\Show; |
|||
use Dcat\Admin\Http\Controllers\AdminController; |
|||
use Illuminate\Database\Eloquent\Model; |
|||
use Illuminate\Support\Facades\DB; |
|||
|
|||
class WithdrawalAlipayController extends AdminController |
|||
{ |
|||
|
|||
/** |
|||
* Make a form builder. |
|||
* |
|||
* @return Form |
|||
*/ |
|||
protected function form() |
|||
{ |
|||
return Form::make(new WithdrawalAlipay(), function (Form $form) { |
|||
$form->display('id'); |
|||
$form->decimal('price','提现金额')->required(); |
|||
$form->text('account')->required(); |
|||
$form->text('name')->required(); |
|||
$form->image('qrcode')->required(); |
|||
$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(); |
|||
|
|||
$withdrawal = new Withdrawal(); |
|||
$withdrawal->user_id = Admin::user()->id; |
|||
$withdrawal->user_type = DemandTraits::$col[1]; |
|||
$withdrawal->price = request('price',0); |
|||
//$withdrawal->pay_id = $form->getKey();
|
|||
$withdrawal->pay_type = WithdrawalTraits::$userType[0]; |
|||
$withdrawal->save(); |
|||
|
|||
$form->withdrawal_id = $withdrawal->id; |
|||
$form->deleteInput('price'); |
|||
}); |
|||
|
|||
$form->saved(function (Form $form) { |
|||
$withdrawal = Withdrawal::find($form->withdrawal_id); |
|||
$withdrawal->pay_id = $form->getKey(); |
|||
$withdrawal->save(); |
|||
}); |
|||
}); |
|||
} |
|||
} |
|||
@ -0,0 +1,64 @@ |
|||
<?php |
|||
|
|||
namespace App\AdminSupplier\Controllers; |
|||
|
|||
use App\AdminSupplier\Repositories\WithdrawalBank; |
|||
use App\Models\Agent; |
|||
use App\Models\Withdrawal; |
|||
use App\Traits\DemandTraits; |
|||
use App\Traits\WithdrawalTraits; |
|||
use Dcat\Admin\Admin; |
|||
use Dcat\Admin\Form; |
|||
use Dcat\Admin\Grid; |
|||
use Dcat\Admin\Show; |
|||
use Dcat\Admin\Http\Controllers\AdminController; |
|||
use Illuminate\Database\Eloquent\Model; |
|||
|
|||
class WithdrawalBankController extends AdminController |
|||
{ |
|||
|
|||
/** |
|||
* Make a form builder. |
|||
* |
|||
* @return Form |
|||
*/ |
|||
protected function form() |
|||
{ |
|||
return Form::make(new WithdrawalBank(), function (Form $form) { |
|||
$form->display('id'); |
|||
$form->decimal('price','提现金额')->required(); |
|||
$form->text('name')->required(); |
|||
$form->text('card_number')->required(); |
|||
$form->text('account_name')->required(); |
|||
$form->text('branch')->required(); |
|||
$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(); |
|||
|
|||
$withdrawal = new Withdrawal(); |
|||
$withdrawal->user_id = Admin::user()->id; |
|||
$withdrawal->user_type = DemandTraits::$col[1]; |
|||
$withdrawal->price = request('price',0); |
|||
//$withdrawal->pay_id = $form->getKey();
|
|||
$withdrawal->pay_type = WithdrawalTraits::$userType[1]; |
|||
$withdrawal->save(); |
|||
|
|||
$form->withdrawal_id = $withdrawal->id; |
|||
$form->deleteInput('price'); |
|||
}); |
|||
|
|||
$form->saved(function (Form $form) { |
|||
$withdrawal = Withdrawal::find($form->withdrawal_id); |
|||
$withdrawal->pay_id = $form->getKey(); |
|||
$withdrawal->save(); |
|||
}); |
|||
}); |
|||
} |
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
<?php |
|||
|
|||
namespace App\AdminSupplier\Repositories; |
|||
|
|||
use App\Models\Withdrawal as Model; |
|||
use Dcat\Admin\Repositories\EloquentRepository; |
|||
|
|||
class Withdrawal extends EloquentRepository |
|||
{ |
|||
/** |
|||
* Model. |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $eloquentClass = Model::class; |
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
<?php |
|||
|
|||
namespace App\AdminSupplier\Repositories; |
|||
|
|||
use App\Models\WithdrawalAlipay as Model; |
|||
use Dcat\Admin\Repositories\EloquentRepository; |
|||
|
|||
class WithdrawalAlipay extends EloquentRepository |
|||
{ |
|||
/** |
|||
* Model. |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $eloquentClass = Model::class; |
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
<?php |
|||
|
|||
namespace App\AdminSupplier\Repositories; |
|||
|
|||
use App\Models\WithdrawalBank as Model; |
|||
use Dcat\Admin\Repositories\EloquentRepository; |
|||
|
|||
class WithdrawalBank extends EloquentRepository |
|||
{ |
|||
/** |
|||
* Model. |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $eloquentClass = Model::class; |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue