6
0
Fork 0

批零经销商变更余额

release
李静 2022-04-24 10:35:14 +08:00
parent 454e5d39d3
commit bee6098028
5 changed files with 31 additions and 17 deletions

View File

@ -2,15 +2,15 @@
namespace App\Admin\Actions\Grid; 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\Grid\RowAction;
use Dcat\Admin\Widgets\Modal; use Dcat\Admin\Widgets\Modal;
class DealerWalletRecharge extends RowAction class DealerWalletChange extends RowAction
{ {
public function title() public function title()
{ {
return '<i class="feather grid-action-icon icon-plus-circle"></i> 充值&nbsp;&nbsp;'; return '<i class="feather grid-action-icon icon-credit-card"></i> 变更余额&nbsp;&nbsp;';
} }
/** /**
@ -20,12 +20,12 @@ class DealerWalletRecharge extends RowAction
*/ */
protected function authorize($user): bool protected function authorize($user): bool
{ {
return $user->can('dcat.admin.dealers.wallet_recharge'); return $user->can('dcat.admin.dealers.wallet_change');
} }
public function render() public function render()
{ {
$form = DealerWalletRechargeForm::make()->payload(['id'=>$this->getKey()]); $form = DealerWalletChangeForm::make()->payload(['id'=>$this->getKey()]);
return Modal::make() return Modal::make()
->lg() ->lg()

View File

@ -5,7 +5,7 @@ namespace App\Admin\Controllers;
use App\Admin\Actions\Grid\DealerBonds; use App\Admin\Actions\Grid\DealerBonds;
use App\Admin\Actions\Grid\DealerEditLvl; use App\Admin\Actions\Grid\DealerEditLvl;
use App\Admin\Actions\Grid\DealerEditProduct; 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\DealerEarningSimpleTable;
use App\Admin\Renderable\DealerSubordinateCard; use App\Admin\Renderable\DealerSubordinateCard;
use App\Admin\Renderable\DealerUserProductLogSimpleTable; use App\Admin\Renderable\DealerUserProductLogSimpleTable;
@ -84,8 +84,8 @@ class DealerController extends AdminController
if (Admin::user()->can('dcat.admin.dealers.edit_lvl')) { if (Admin::user()->can('dcat.admin.dealers.edit_lvl')) {
$actions->append(new DealerEditLvl()); $actions->append(new DealerEditLvl());
} }
if (Admin::user()->can('dcat.admin.dealers.wallet_recharge')) { if (Admin::user()->can('dcat.admin.dealers.wallet_change')) {
$actions->append(new DealerWalletRecharge()); $actions->append(new DealerWalletChange());
} }
if ($actions->row->lvl->value >= DealerLvl::Special->value && Admin::user()->can('dcat.admin.dealers.bonds')) { if ($actions->row->lvl->value >= DealerLvl::Special->value && Admin::user()->can('dcat.admin.dealers.bonds')) {
$actions->append(new DealerBonds()); $actions->append(new DealerBonds());

View File

@ -12,7 +12,7 @@ use Dcat\Admin\Widgets\Form;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Throwable; use Throwable;
class DealerWalletRecharge extends Form implements LazyRenderable class DealerWalletChange extends Form implements LazyRenderable
{ {
use LazyWidget; use LazyWidget;
@ -23,7 +23,7 @@ class DealerWalletRecharge extends Form implements LazyRenderable
*/ */
protected function authorize($user): bool 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) public function handle(array $input)
{ {
if (($input['change_balance'] ?? 0) <= 0) { if (bccomp($input['change_balance'], '0', 2) === -1) {
return $this->response()->error('充值金额必须大于0'); return $this->response()->error('金额必须大于0');
} }
$dealer = Dealer::findOrFail($this->payload['id']); $dealer = Dealer::findOrFail($this->payload['id']);
$action = DealerWalletAction::from($input['action']);
try { try {
DB::beginTransaction(); DB::beginTransaction();
(new WalletService())->changeBalance( (new WalletService())->changeBalance(
$dealer->user, $dealer->user,
$input['change_balance'], match ($action) {
DealerWalletAction::Recharge, DealerWalletAction::Recharge => bcmul($input['change_balance'], '1', 2),
'充值', DealerWalletAction::Deduct => bcmul($input['change_balance'], '-1', 2),
},
$action,
$input['remarks'],
Admin::user() Admin::user()
); );
@ -71,7 +76,15 @@ class DealerWalletRecharge extends Form implements LazyRenderable
*/ */
public function form() 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('是否确认充值?', '提交后该动作无法逆转'); $this->confirm('是否确认充值?', '提交后该动作无法逆转');
} }
} }

View File

@ -17,4 +17,5 @@ enum DealerWalletAction: int {
case EarningOut = 12; case EarningOut = 12;
case DeliveryBillPaid = 13; case DeliveryBillPaid = 13;
case Recharge = 14; // 充值 case Recharge = 14; // 充值
case Deduct = 15; // 扣除
} }

View File

@ -319,7 +319,7 @@ class AdminPermissionSeeder extends Seeder
'edit_lvl'=>['name' =>'修改经销商等级'], 'edit_lvl'=>['name' =>'修改经销商等级'],
'bonds'=>['name' =>'填写保证金'], 'bonds'=>['name' =>'填写保证金'],
'edit_product'=>['name' =>'调整库存'], 'edit_product'=>['name' =>'调整库存'],
'wallet_recharge' => ['name' => '充值'], 'wallet_change' => ['name' => '变更余额'],
], ],
], ],
'dealer_products'=>[ 'dealer_products'=>[