6
0
Fork 0
jiqu-library-server/app/Admin/Actions/Show/DealerEarningPay.php

101 lines
3.2 KiB
PHP

<?php
namespace App\Admin\Actions\Show;
use App\Admin\Forms\DealerEarningPay as DealerEarningPayForm;
use App\Enums\DealerEarningStatus;
use App\Enums\DealerWalletAction;
use App\Models\DealerChannelSubsidyLog;
use App\Models\DealerEarning;
use App\Models\DealerManagerSubsidy;
use App\Models\DealerManageSubsidy;
use App\Services\Dealer\WalletService;
use Dcat\Admin\Show\AbstractTool;
use Dcat\Admin\Widgets\Modal;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Throwable;
class DealerEarningPay extends AbstractTool
{
/**
* @return string
*/
protected $title = '<i class="feather icon-file-text"></i>&nbsp;打款';
/**
* 按钮样式定义,默认 btn btn-white waves-effect
*
* @var string
*/
protected $style = 'btn btn-sm btn-danger';
// public function render()
// {
// $form = DealerEarningPayForm::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;");
// }
public function handle(Request $request)
{
// 获取主键
$key = $this->getKey();
try {
DB::beginTransaction();
$earning = DealerEarning::findOrFail($key);
$earning->update([
'pay_way' => DealerEarning::PAY_WAY_WALLET,
'pay_info' => $earning->getPayInfo(),
'pay_at' => now(),
'status' => DealerEarningStatus::Completed,
]);
//打款到余额;
$walletService = new WalletService();
switch ($earning->earningable_type) {
case (new DealerManagerSubsidy())->getMorphClass():
$action = DealerWalletAction::ManagerSubsidyIn;
break;
case (new DealerManageSubsidy())->getMorphClass():
$action = DealerWalletAction::ManageSubsidyIn;
break;
case (new DealerChannelSubsidyLog())->getMorphClass():
$action = DealerWalletAction::ChannelSubsidyIn;
break;
default:
$action = DealerWalletAction::PurchaseSubsidyIn;
break;
}
$walletService->changeBalance($earning->user, $earning->total_earnings, $action, '收入-'.$earning->earningable_type_text, $earning);
DB::commit();
} catch (Throwable $th) {
DB::rollBack();
report($th);
return $this->response()->error('操作失败:'.$th->getMessage());
}
return $this->response()
->success(__('admin.update_succeeded'))
->refresh();
}
public function html()
{
return parent::html().'&nbsp;&nbsp;';
}
/**
* 确认弹窗信息,如不需要可以删除此方法
*
* @return string|array|void
*/
public function confirm()
{
return ['是否确认打款?', '该操作不可逆,确认后将打款到余额。'];
}
}