批零经销商变更余额
parent
454e5d39d3
commit
bee6098028
|
|
@ -2,15 +2,15 @@
|
|||
|
||||
namespace App\Admin\Actions\Grid;
|
||||
|
||||
use App\Admin\Forms\DealerWalletRecharge as DealerWalletRechargeForm;
|
||||
use App\Admin\Forms\DealerWalletChange as DealerWalletChangeForm;
|
||||
use Dcat\Admin\Grid\RowAction;
|
||||
use Dcat\Admin\Widgets\Modal;
|
||||
|
||||
class DealerWalletRecharge extends RowAction
|
||||
class DealerWalletChange extends RowAction
|
||||
{
|
||||
public function title()
|
||||
{
|
||||
return '<i class="feather grid-action-icon icon-plus-circle"></i> 充值 ';
|
||||
return '<i class="feather grid-action-icon icon-credit-card"></i> 变更余额 ';
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -20,12 +20,12 @@ class DealerWalletRecharge extends RowAction
|
|||
*/
|
||||
protected function authorize($user): bool
|
||||
{
|
||||
return $user->can('dcat.admin.dealers.wallet_recharge');
|
||||
return $user->can('dcat.admin.dealers.wallet_change');
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
$form = DealerWalletRechargeForm::make()->payload(['id'=>$this->getKey()]);
|
||||
$form = DealerWalletChangeForm::make()->payload(['id'=>$this->getKey()]);
|
||||
|
||||
return Modal::make()
|
||||
->lg()
|
||||
|
|
@ -5,7 +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\Actions\Grid\DealerWalletChange;
|
||||
use App\Admin\Renderable\DealerEarningSimpleTable;
|
||||
use App\Admin\Renderable\DealerSubordinateCard;
|
||||
use App\Admin\Renderable\DealerUserProductLogSimpleTable;
|
||||
|
|
@ -84,8 +84,8 @@ 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 (Admin::user()->can('dcat.admin.dealers.wallet_change')) {
|
||||
$actions->append(new DealerWalletChange());
|
||||
}
|
||||
if ($actions->row->lvl->value >= DealerLvl::Special->value && Admin::user()->can('dcat.admin.dealers.bonds')) {
|
||||
$actions->append(new DealerBonds());
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ use Dcat\Admin\Widgets\Form;
|
|||
use Illuminate\Support\Facades\DB;
|
||||
use Throwable;
|
||||
|
||||
class DealerWalletRecharge extends Form implements LazyRenderable
|
||||
class DealerWalletChange extends Form implements LazyRenderable
|
||||
{
|
||||
use LazyWidget;
|
||||
|
||||
|
|
@ -23,7 +23,7 @@ class DealerWalletRecharge extends Form implements LazyRenderable
|
|||
*/
|
||||
protected function authorize($user): bool
|
||||
{
|
||||
return $user->can('dcat.admin.dealers.wallet_recharge');
|
||||
return $user->can('dcat.admin.dealers.wallet_change');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -35,20 +35,25 @@ class DealerWalletRecharge extends Form implements LazyRenderable
|
|||
*/
|
||||
public function handle(array $input)
|
||||
{
|
||||
if (($input['change_balance'] ?? 0) <= 0) {
|
||||
return $this->response()->error('充值金额必须大于0');
|
||||
if (bccomp($input['change_balance'], '0', 2) === -1) {
|
||||
return $this->response()->error('金额必须大于0');
|
||||
}
|
||||
|
||||
$dealer = Dealer::findOrFail($this->payload['id']);
|
||||
|
||||
$action = DealerWalletAction::from($input['action']);
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
(new WalletService())->changeBalance(
|
||||
$dealer->user,
|
||||
$input['change_balance'],
|
||||
DealerWalletAction::Recharge,
|
||||
'充值',
|
||||
match ($action) {
|
||||
DealerWalletAction::Recharge => bcmul($input['change_balance'], '1', 2),
|
||||
DealerWalletAction::Deduct => bcmul($input['change_balance'], '-1', 2),
|
||||
},
|
||||
$action,
|
||||
$input['remarks'],
|
||||
Admin::user()
|
||||
);
|
||||
|
||||
|
|
@ -71,7 +76,15 @@ class DealerWalletRecharge extends Form implements LazyRenderable
|
|||
*/
|
||||
public function form()
|
||||
{
|
||||
$this->currency('change_balance', '充值金额')->symbol('¥')->required();
|
||||
$this->radio('action', '操作')
|
||||
->options([
|
||||
DealerWalletAction::Recharge->value => '充值',
|
||||
DealerWalletAction::Deduct->value => '扣除',
|
||||
])
|
||||
->default(DealerWalletAction::Recharge->value)
|
||||
->required();
|
||||
$this->currency('change_balance', '金额')->symbol('¥')->required();
|
||||
$this->textarea('remarks', '备注')->required();
|
||||
$this->confirm('是否确认充值?', '提交后该动作无法逆转');
|
||||
}
|
||||
}
|
||||
|
|
@ -17,4 +17,5 @@ enum DealerWalletAction: int {
|
|||
case EarningOut = 12;
|
||||
case DeliveryBillPaid = 13;
|
||||
case Recharge = 14; // 充值
|
||||
case Deduct = 15; // 扣除
|
||||
}
|
||||
|
|
|
|||
|
|
@ -319,7 +319,7 @@ class AdminPermissionSeeder extends Seeder
|
|||
'edit_lvl'=>['name' =>'修改经销商等级'],
|
||||
'bonds'=>['name' =>'填写保证金'],
|
||||
'edit_product'=>['name' =>'调整库存'],
|
||||
'wallet_recharge' => ['name' => '充值'],
|
||||
'wallet_change' => ['name' => '变更余额'],
|
||||
],
|
||||
],
|
||||
'dealer_products'=>[
|
||||
|
|
|
|||
Loading…
Reference in New Issue