6
0
Fork 0

添加后台余额提现操作

release
vine_liutk 2022-01-25 16:07:28 +08:00
parent a70f4280ad
commit dcff4c9a17
12 changed files with 444 additions and 22 deletions

View File

@ -0,0 +1,32 @@
<?php
namespace App\Admin\Actions\Show;
use App\Admin\Forms\DealerWalletPay as DealerWalletPayForm;
use Dcat\Admin\Show\AbstractTool;
use Dcat\Admin\Widgets\Modal;
class DealerWalletPay extends AbstractTool
{
/**
* @return string
*/
protected $title = '<i class="feather icon-file-text"></i>&nbsp;打款';
/**
* 按钮样式定义,默认 btn btn-white waves-effect
*
* @var string
*/
protected $style = 'btn-danger';
public function render()
{
$form = DealerWalletPayForm::make()->payload(['id'=>$this->getKey()]);
return Modal::make()
->lg()
->title($this->title)
->body($form)
->button("<a href=\"javascript:void(0)\" class=\"btn btn-sm {$this->style}\">{$this->title}</a>&nbsp;&nbsp;");
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace App\Admin\Actions\Show;
use App\Admin\Forms\DealerWalletRefuse as DealerWalletRefuseForm;
use Dcat\Admin\Show\AbstractTool;
use Dcat\Admin\Widgets\Modal;
class DealerWalletRefuse extends AbstractTool
{
/**
* @return string
*/
protected $title = '<i class="feather icon-file-text"></i>&nbsp;拒绝';
/**
* 按钮样式定义,默认 btn btn-white waves-effect
*
* @var string
*/
protected $style = 'btn-warning';
public function render()
{
$form = DealerWalletRefuseForm::make()->payload(['id'=>$this->getKey()]);
return Modal::make()
->lg()
->title($this->title)
->body($form)
->button("<a href=\"javascript:void(0)\" class=\"btn btn-sm {$this->style}\">{$this->title}</a>&nbsp;&nbsp;");
}
}

View File

@ -0,0 +1,172 @@
<?php
namespace App\Admin\Controllers;
use App\Admin\Actions\Show\DealerWalletPay;
use App\Admin\Actions\Show\DealerWalletRefuse;
use App\Admin\Repositories\DealerWalletToBankLog;
use App\Models\DealerWalletToBankLog as DealerWalletToBankLogModel;
use Dcat\Admin\Admin;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Http\Controllers\AdminController;
use Dcat\Admin\Show;
class DealerWalletToBankLogController extends AdminController
{
/**
* Make a grid builder.
*
* @return Grid
*/
protected function grid()
{
$builder = DealerWalletToBankLog::with(['user']);
return Grid::make($builder, function (Grid $grid) {
$grid->column('id')->sortable();
$grid->column('user.phone');
$grid->column('amount')->prepend('¥');
$grid->column('rate')->append('%');
$grid->column('service_amount')->prepend('¥');
$grid->column('account_amount')->prepend('¥');
$grid->column('status')->using([
DealerWalletToBankLogModel::STATUS_PENDING=>'待处理',
DealerWalletToBankLogModel::STATUS_AGREE=>'同意',
DealerWalletToBankLogModel::STATUS_REFUSE=>'拒绝',
])->dot([
0=>'primary',
1=>'success',
2=>'danger',
]);
$grid->column('remarks');
$grid->column('created_at')->sortable();
// $grid->column('updated_at')
$grid->model()->orderBy('status', 'asc');
$grid->model()->orderBy('created_at', 'desc');
$grid->actions(function (Grid\Displayers\Actions $actions) {
if (Admin::user()->can('dcat.admin.dealer_wallet_to_bank_logs.show')) {
$actions->append('<a style="cursor: pointer;" target="_blank" href="'.admin_route('dealer_wallet_to_bank_logs.show', ['dealer_wallet_to_bank_log'=>$actions->row]).'"><i class="feather icon-eye"></i> 显示 &nbsp;&nbsp;</a>');
}
});
$grid->filter(function (Grid\Filter $filter) {
$filter->panel();
$filter->equal('status')->select([
DealerWalletToBankLogModel::STATUS_PENDING=>'待处理',
DealerWalletToBankLogModel::STATUS_AGREE=>'已同意',
DealerWalletToBankLogModel::STATUS_REFUSE=>'已拒绝',
])->width(3);
$filter->equal('user.phone')->width(3);
$filter->between('created_at')->dateTime()->width(7);
});
});
}
/**
* Make a show builder.
*
* @param mixed $id
*
* @return Show
*/
protected function detail($id)
{
$builder = DealerWalletToBankLog::with(['user']);
return Show::make($id, $builder, function (Show $show) {
$show->field('id');
$show->field('user.phone');
$show->field('amount')->prepend('¥');
$show->field('rate')->append('%');
$show->field('service_amount')->prepend('¥');
$show->field('account_amount')->prepend('¥');
$show->field('status')->using([
DealerWalletToBankLogModel::STATUS_PENDING=>'待处理',
DealerWalletToBankLogModel::STATUS_AGREE=>'同意',
DealerWalletToBankLogModel::STATUS_REFUSE=>'拒绝',
])->dot([
0=>'primary',
1=>'success',
2=>'danger',
]);
$show->field('pay_image')->image();
$show->field('remarks');
$show->divider('收款信息-银行');
$show->field('bank_user_name', '银行-收款人')->as(function () {
$payInfo = $this->getPayInfo();
return $payInfo['bank']['user_name']??'';
});
$show->field('bank_bank_name', '银行-名称')->as(function () {
$payInfo = $this->getPayInfo();
return $payInfo['bank']['bank_name']??'';
});
$show->field('bank_bank_number', '银行-卡号')->as(function () {
$payInfo = $this->getPayInfo();
return $payInfo['bank']['bank_number']??'';
});
$show->field('bank_bank_description', '银行-开户行')->as(function () {
$payInfo = $this->getPayInfo();
return $payInfo['bank']['bank_description']??'';
});
$show->divider('收款信息-支付宝');
$show->field('alipay_user_name', '支付宝-真实名称')->as(function () {
$payInfo = $this->getPayInfo();
return $payInfo['alipay']['user_name']??'';
});
$show->field('alipay_ali_name', '支付宝-账户')->as(function () {
$payInfo = $this->getPayInfo();
return $payInfo['alipay']['ali_name']??'';
});
$show->field('alipay_image', '支付宝-收款码')->as(function () {
$payInfo = $this->getPayInfo();
return $payInfo['alipay']['image']??'';
})->image();
$show->divider('收款信息-微信');
$show->field('wechat_user_name', '微信-真实名称')->as(function () {
$payInfo = $this->getPayInfo();
return $payInfo['wechat']['user_name']??'';
});
$show->field('wechat_wechat_name', '微信-ID')->as(function () {
$payInfo = $this->getPayInfo();
return $payInfo['wechat']['wechat_name']??'';
});
$show->field('wechat_image', '微信-收款码')->as(function () {
$payInfo = $this->getPayInfo();
return $payInfo['wechat']['image']??'';
})->image();
$show->field('created_at');
$show->panel()
->tools(function (Show\Tools $tools) use ($show) {
$tools->disableEdit();
$tools->disableDelete();
if ($show->model()->isPending() && Admin::user()->can('dcat.admin.dealer_wallet_to_bank_logs.verify')) {
$tools->append(new DealerWalletRefuse());
$tools->append(new DealerWalletPay());
}
});
});
}
/**
* Make a form builder.
*
* @return Form
*/
protected function form()
{
return Form::make(new DealerWalletToBankLog(), function (Form $form) {
$form->display('id');
$form->text('user_id');
$form->text('amount');
$form->text('rate');
$form->text('service_amount');
$form->text('account_amount');
$form->text('status');
$form->text('remarks');
$form->display('created_at');
$form->display('updated_at');
});
}
}

View File

@ -0,0 +1,69 @@
<?php
namespace App\Admin\Forms;
use App\Models\DealerWalletToBankLog;
use Carbon\Carbon;
use Dcat\Admin\Contracts\LazyRenderable;
use Dcat\Admin\Traits\LazyWidget;
use Dcat\Admin\Widgets\Form;
use Illuminate\Support\Facades\DB;
use Throwable;
class DealerWalletPay extends Form implements LazyRenderable
{
use LazyWidget;
/**
* @param Model|Authenticatable|HasPermissions|null $user
*
* @return bool
*/
protected function authorize($user): bool
{
return $user->can('dcat.admin.dealer_wallet_to_bank_logs.verify');
}
/**
* Handle the form request.
*
* @param array $input
*
* @return mixed
*/
public function handle(array $input)
{
$id = $this->payload['id'] ?? 0;
try {
DB::beginTransaction();
$log = DealerWalletToBankLog::findOrFail($id);
$log->update([
'pay_info' => $log->getPayInfo(),
'pay_image' => $input['pay_image']??null,
'status' => DealerWalletToBankLog::STATUS_AGREE,
]);
DB::commit();
} catch (Throwable $th) {
DB::rollBack();
report($th);
return $this->response()->error('操作失败:'.$th->getMessage());
}
return $this->response()
->success(__('admin.update_succeeded'))
->refresh();
}
/**
* Build a form here.
*/
public function form()
{
$this->image('pay_image')
->move('dealer-pay/'.Carbon::now()->toDateString())
->saveFullUrl()
->removable(false)
->autoUpload();
}
}

View File

@ -0,0 +1,68 @@
<?php
namespace App\Admin\Forms;
use App\Enums\DealerWalletAction;
use App\Models\DealerWalletToBankLog;
use App\Services\Dealer\WalletService;
use Dcat\Admin\Contracts\LazyRenderable;
use Dcat\Admin\Traits\LazyWidget;
use Dcat\Admin\Widgets\Form;
use Illuminate\Support\Facades\DB;
use Throwable;
class DealerWalletRefuse extends Form implements LazyRenderable
{
use LazyWidget;
/**
* @param Model|Authenticatable|HasPermissions|null $user
*
* @return bool
*/
protected function authorize($user): bool
{
return $user->can('dcat.admin.dealer_wallet_to_bank_logs.verify');
}
/**
* Handle the form request.
*
* @param array $input
*
* @return mixed
*/
public function handle(array $input)
{
$id = $this->payload['id'] ?? 0;
try {
DB::beginTransaction();
$log = DealerWalletToBankLog::findOrFail($id);
$log->update([
'remark' => $input['remark']??'',
'status' => DealerWalletToBankLog::STATUS_REFUSE,
]);
//打回余额
$walletService = new WalletService();
$walletService->changeBalance($log->user, $log->amount, DealerWalletAction::WithdrawFiled, '提现-失败', $log);
DB::commit();
} catch (Throwable $th) {
DB::rollBack();
report($th);
return $this->response()->error('操作失败:'.$th->getMessage());
}
return $this->response()
->success(__('admin.update_succeeded'))
->refresh();
}
/**
* Build a form here.
*/
public function form()
{
$this->text('remarks', '备注')->required();
}
}

View File

@ -0,0 +1,16 @@
<?php
namespace App\Admin\Repositories;
use App\Models\DealerWalletToBankLog as Model;
use Dcat\Admin\Repositories\EloquentRepository;
class DealerWalletToBankLog extends EloquentRepository
{
/**
* Model.
*
* @var string
*/
protected $eloquentClass = Model::class;
}

View File

@ -186,6 +186,11 @@ Route::group([
$router->get('dealer-manage-subsidy-logs', 'DealerManageSubsidyLogController@index')->name('dealer_manage_subsidy_logs.index');
$router->get('dealer-purchase-logs', 'DealerPurchaseLogController@index')->name('dealer_purchase_logs.index');
//批零余额提现
$router->resource('dealer-wallet-to-bank-logs', 'DealerWalletToBankLogController')->only([
'index', 'show',
])->names('dealer_wallet_to_bank_logs');
/** api接口 **/
$router->get('api/product-categories', 'ProductCategoryController@categories')->name('api.product_categories');
$router->get('api/product-group-details', 'ProductGroupController@details')->name('api.product_group_details');

View File

@ -46,7 +46,7 @@ class WalletController extends Controller
$user = $request->user();
$amount = Arr::get($input, 'amount', 0);
if (is_null($user->dealer->pay_info)) {
if (empty($user->dealer->pay_info)) {
throw new BizException('请先绑定设置收款信息');
}
//校验是否关闭提现
@ -58,7 +58,6 @@ class WalletController extends Controller
if (bcdiv($amount, 100, 2) < app_settings('dealer.withdraw_threshold_amount', 0)) {
throw new BizException('提现金额需大于'.app_settings('dealer.withdraw_threshold_amount', 0).'元');
}
try {
DB::beginTransaction();
@ -70,14 +69,14 @@ class WalletController extends Controller
//生成提现记录
$log = DealerWalletToBankLog::create([
'user_id' =>$user->id,
'amount'=> $amount,
'amount'=> bcdiv($amount, 100, 2),
'rate' => $rate,
'service_amount' => $serviceAmount,
'account_amount' => $amount-$serviceAmount,
'service_amount' => bcdiv($serviceAmount, 100, 2),
'account_amount' => bcdiv($amount-$serviceAmount, 100, 2),
]);
//减去用户可提金额
$walletService->changeBalance($user, -$amount, DealerWalletAction::WithdrawBank, '提现', $log);
$walletService->changeBalance($user, -bcdiv($amount, 100, 2), DealerWalletAction::WithdrawBank, '提现', $log);
DB::commit();
} catch (BizException $th) {
DB::rollBack();

View File

@ -4,4 +4,5 @@ namespace App\Enums;
enum DealerWalletAction: int {
case WithdrawBank = 4;
case WithdrawFiled = 6;
}

View File

@ -349,6 +349,11 @@ class AdminMenuSeeder extends Seeder
'icon' => '',
'uri'=>'dealer-manager-sales-logs',
],
[
'title' =>'余额提现',
'icon' =>'',
'uri'=>'dealer-wallet-to-bank-logs',
],
],
],
[

View File

@ -162,6 +162,10 @@ namespace Dcat\Admin {
* @property Grid\Column|Collection change_sales_value
* @property Grid\Column|Collection before_lvl
* @property Grid\Column|Collection change_lvl
* @property Grid\Column|Collection account_amount
* @property Grid\Column|Collection rate
* @property Grid\Column|Collection service_amount
* @property Grid\Column|Collection withdrawable
* @property Grid\Column|Collection bonds
* @property Grid\Column|Collection contracted_lvl_at
* @property Grid\Column|Collection self_sales_value
@ -300,10 +304,6 @@ namespace Dcat\Admin {
* @property Grid\Column|Collection phone_verified_at
* @property Grid\Column|Collection register_ip
* @property Grid\Column|Collection status_remark
* @property Grid\Column|Collection account_amount
* @property Grid\Column|Collection rate
* @property Grid\Column|Collection service_amount
* @property Grid\Column|Collection withdrawable
*
* @method Grid\Column|Collection created_at(string $label = null)
* @method Grid\Column|Collection dimensions(string $label = null)
@ -456,6 +456,10 @@ namespace Dcat\Admin {
* @method Grid\Column|Collection change_sales_value(string $label = null)
* @method Grid\Column|Collection before_lvl(string $label = null)
* @method Grid\Column|Collection change_lvl(string $label = null)
* @method Grid\Column|Collection account_amount(string $label = null)
* @method Grid\Column|Collection rate(string $label = null)
* @method Grid\Column|Collection service_amount(string $label = null)
* @method Grid\Column|Collection withdrawable(string $label = null)
* @method Grid\Column|Collection bonds(string $label = null)
* @method Grid\Column|Collection contracted_lvl_at(string $label = null)
* @method Grid\Column|Collection self_sales_value(string $label = null)
@ -594,10 +598,6 @@ namespace Dcat\Admin {
* @method Grid\Column|Collection phone_verified_at(string $label = null)
* @method Grid\Column|Collection register_ip(string $label = null)
* @method Grid\Column|Collection status_remark(string $label = null)
* @method Grid\Column|Collection account_amount(string $label = null)
* @method Grid\Column|Collection rate(string $label = null)
* @method Grid\Column|Collection service_amount(string $label = null)
* @method Grid\Column|Collection withdrawable(string $label = null)
*/
class Grid {}
@ -755,6 +755,10 @@ namespace Dcat\Admin {
* @property Show\Field|Collection change_sales_value
* @property Show\Field|Collection before_lvl
* @property Show\Field|Collection change_lvl
* @property Show\Field|Collection account_amount
* @property Show\Field|Collection rate
* @property Show\Field|Collection service_amount
* @property Show\Field|Collection withdrawable
* @property Show\Field|Collection bonds
* @property Show\Field|Collection contracted_lvl_at
* @property Show\Field|Collection self_sales_value
@ -893,10 +897,6 @@ namespace Dcat\Admin {
* @property Show\Field|Collection phone_verified_at
* @property Show\Field|Collection register_ip
* @property Show\Field|Collection status_remark
* @property Show\Field|Collection account_amount
* @property Show\Field|Collection rate
* @property Show\Field|Collection service_amount
* @property Show\Field|Collection withdrawable
*
* @method Show\Field|Collection created_at(string $label = null)
* @method Show\Field|Collection dimensions(string $label = null)
@ -1049,6 +1049,10 @@ namespace Dcat\Admin {
* @method Show\Field|Collection change_sales_value(string $label = null)
* @method Show\Field|Collection before_lvl(string $label = null)
* @method Show\Field|Collection change_lvl(string $label = null)
* @method Show\Field|Collection account_amount(string $label = null)
* @method Show\Field|Collection rate(string $label = null)
* @method Show\Field|Collection service_amount(string $label = null)
* @method Show\Field|Collection withdrawable(string $label = null)
* @method Show\Field|Collection bonds(string $label = null)
* @method Show\Field|Collection contracted_lvl_at(string $label = null)
* @method Show\Field|Collection self_sales_value(string $label = null)
@ -1187,10 +1191,6 @@ namespace Dcat\Admin {
* @method Show\Field|Collection phone_verified_at(string $label = null)
* @method Show\Field|Collection register_ip(string $label = null)
* @method Show\Field|Collection status_remark(string $label = null)
* @method Show\Field|Collection account_amount(string $label = null)
* @method Show\Field|Collection rate(string $label = null)
* @method Show\Field|Collection service_amount(string $label = null)
* @method Show\Field|Collection withdrawable(string $label = null)
*/
class Show {}

View File

@ -0,0 +1,23 @@
<?php
return [
'labels' => [
'DealerWalletToBankLog' => '余额提现',
'dealer-wallet-to-bank-logs' => '余额提现',
],
'fields' => [
'user_id' => '用户',
'user'=>[
'phone' => '手机号',
],
'pay_image' => '打款凭证',
'amount' => '提现金额',
'rate' => '费率',
'service_amount' => '手续费',
'account_amount' => '到账金额',
'status' => '状态',
'remarks' => '备注',
],
'options' => [
],
];