经销商余额充值
parent
e06c590496
commit
77ee89c1aa
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Actions\Grid;
|
||||
|
||||
use App\Admin\Forms\DealerWalletRecharge as DealerWalletRechargeForm;
|
||||
use Dcat\Admin\Grid\RowAction;
|
||||
use Dcat\Admin\Widgets\Modal;
|
||||
|
||||
class DealerWalletRecharge extends RowAction
|
||||
{
|
||||
public function title()
|
||||
{
|
||||
return '<i class="feather grid-action-icon icon-plus-circle"></i> 充值 ';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Model|Authenticatable|HasPermissions|null $user
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorize($user): bool
|
||||
{
|
||||
return $user->can('dcat.admin.dealers.wallet_recharge');
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
$form = DealerWalletRechargeForm::make()->payload(['id'=>$this->getKey()]);
|
||||
|
||||
return Modal::make()
|
||||
->lg()
|
||||
->title($this->title())
|
||||
->body($form)
|
||||
->button($this->title());
|
||||
}
|
||||
}
|
||||
|
|
@ -5,6 +5,7 @@ namespace App\Admin\Controllers;
|
|||
use App\Admin\Actions\Grid\DealerBonds;
|
||||
use App\Admin\Actions\Grid\DealerEditLvl;
|
||||
use App\Admin\Actions\Grid\DealerEditProduct;
|
||||
use App\Admin\Actions\Grid\DealerWalletRecharge;
|
||||
use App\Admin\Renderable\DealerEarningSimpleTable;
|
||||
use App\Admin\Renderable\DealerSubordinateCard;
|
||||
use App\Admin\Renderable\DealerUserProductLogSimpleTable;
|
||||
|
|
@ -83,6 +84,9 @@ class DealerController extends AdminController
|
|||
if (Admin::user()->can('dcat.admin.dealers.edit_lvl')) {
|
||||
$actions->append(new DealerEditLvl());
|
||||
}
|
||||
if (Admin::user()->can('dcat.admin.dealers.wallet_recharge')) {
|
||||
$actions->append(new DealerWalletRecharge());
|
||||
}
|
||||
if ($actions->row->lvl->value >= DealerLvl::Special->value && Admin::user()->can('dcat.admin.dealers.bonds')) {
|
||||
$actions->append(new DealerBonds());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Forms;
|
||||
|
||||
use App\Enums\DealerWalletAction;
|
||||
use App\Models\Dealer;
|
||||
use App\Services\Dealer\WalletService;
|
||||
use Dcat\Admin\Admin;
|
||||
use Dcat\Admin\Contracts\LazyRenderable;
|
||||
use Dcat\Admin\Traits\LazyWidget;
|
||||
use Dcat\Admin\Widgets\Form;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Throwable;
|
||||
|
||||
class DealerWalletRecharge extends Form implements LazyRenderable
|
||||
{
|
||||
use LazyWidget;
|
||||
|
||||
/**
|
||||
* @param Model|Authenticatable|HasPermissions|null $user
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorize($user): bool
|
||||
{
|
||||
return $user->can('dcat.admin.dealers.wallet_recharge');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the form request.
|
||||
*
|
||||
* @param array $input
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle(array $input)
|
||||
{
|
||||
if (($input['change_balance'] ?? 0) <= 0) {
|
||||
return $this->response()->error('充值金额必须大于0');
|
||||
}
|
||||
|
||||
$dealer = Dealer::findOrFail($this->payload['id']);
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
(new WalletService())->changeBalance(
|
||||
$dealer->user,
|
||||
$input['change_balance'],
|
||||
DealerWalletAction::Recharge,
|
||||
'充值',
|
||||
Admin::user()
|
||||
);
|
||||
|
||||
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->currency('change_balance', '充值金额')->symbol('¥')->required();
|
||||
$this->confirm('是否确认充值?', '提交后该动作无法逆转');
|
||||
}
|
||||
}
|
||||
|
|
@ -16,4 +16,5 @@ enum DealerWalletAction: int {
|
|||
case EarningIn = 11;
|
||||
case EarningOut = 12;
|
||||
case DeliveryBillPaid = 13;
|
||||
case Recharge = 14; // 充值
|
||||
}
|
||||
|
|
|
|||
|
|
@ -318,6 +318,7 @@ class AdminPermissionSeeder extends Seeder
|
|||
'edit_lvl'=>['name' =>'修改经销商等级'],
|
||||
'bonds'=>['name' =>'填写保证金'],
|
||||
'edit_product'=>['name' =>'调整库存'],
|
||||
'wallet_recharge' => ['name' => '充值'],
|
||||
],
|
||||
],
|
||||
'dealer_products'=>[
|
||||
|
|
|
|||
Loading…
Reference in New Issue