54 lines
1.5 KiB
PHP
54 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Actions\Grid;
|
|
|
|
use App\Admin\Services\DealerEarningService;
|
|
use App\Models\DealerManagerSubsidy;
|
|
use Dcat\Admin\Grid\BatchAction;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Throwable;
|
|
|
|
class DealerManagerSubsidyBatchPay extends BatchAction
|
|
{
|
|
protected $title = '<i class="feather grid-action-icon icon-stop-circle"></i> 付款';
|
|
|
|
/**
|
|
* @param Model|Authenticatable|HasPermissions|null $user
|
|
*
|
|
* @return bool
|
|
*/
|
|
protected function authorize($user): bool
|
|
{
|
|
return $user->can('dcat.admin.dealer_manager_subsidies.batch_pay');
|
|
}
|
|
|
|
// 确认弹窗信息
|
|
public function confirm()
|
|
{
|
|
return '您确定要支付选中的管理者津贴吗?';
|
|
}
|
|
|
|
// 处理请求
|
|
public function handle(Request $request)
|
|
{
|
|
try {
|
|
DB::transaction(function () {
|
|
foreach ($this->getKey() as $id) {
|
|
$dealerManagerSubsidy = DealerManagerSubsidy::lockForUpdate()->settled()->find($id);
|
|
|
|
if ($dealerManagerSubsidy?->isPending()) {
|
|
(new DealerEarningService())->pay(
|
|
$dealerManagerSubsidy->earning->setRelation('earningable', $dealerManagerSubsidy)
|
|
);
|
|
}
|
|
}
|
|
});
|
|
} catch (Throwable $e) {
|
|
return $this->response()->error('操作失败:'.$e->getMessage())->refresh();
|
|
}
|
|
|
|
return $this->response()->success('操作成功')->refresh();
|
|
}
|
|
}
|