调整后台补贴打款
parent
dcff4c9a17
commit
d594300b38
|
|
@ -3,8 +3,18 @@
|
|||
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
|
||||
{
|
||||
|
|
@ -18,15 +28,72 @@ class DealerEarningPay extends AbstractTool
|
|||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $style = 'btn-danger';
|
||||
protected $style = 'btn btn-sm btn-danger';
|
||||
|
||||
public function render()
|
||||
// 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> ");
|
||||
// }
|
||||
|
||||
public function handle(Request $request)
|
||||
{
|
||||
$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> ");
|
||||
// 获取主键
|
||||
$key = $this->getKey();
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
$earning = DealerEarning::findOrFail($key);
|
||||
$earning->update([
|
||||
'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->type_name, $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().' ';
|
||||
}
|
||||
|
||||
/**
|
||||
* 确认弹窗信息,如不需要可以删除此方法
|
||||
*
|
||||
* @return string|array|void
|
||||
*/
|
||||
public function confirm()
|
||||
{
|
||||
return ['是否确认打款?', '该操作不可逆,确认后将打款到余额。'];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,12 @@
|
|||
namespace App\Admin\Forms;
|
||||
|
||||
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 Carbon\Carbon;
|
||||
use Dcat\Admin\Contracts\LazyRenderable;
|
||||
use Dcat\Admin\Traits\LazyWidget;
|
||||
|
|
@ -45,6 +50,24 @@ class DealerEarningPay extends Form implements LazyRenderable
|
|||
'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->type_name, $earning);
|
||||
DB::commit();
|
||||
} catch (Throwable $th) {
|
||||
DB::rollBack();
|
||||
|
|
|
|||
|
|
@ -3,6 +3,10 @@
|
|||
namespace App\Enums;
|
||||
|
||||
enum DealerWalletAction: int {
|
||||
case WithdrawBank = 4;
|
||||
case ManagerSubsidyIn = 1;
|
||||
case ManageSubsidyIn = 2;
|
||||
case PurchaseSubsidyIn = 3;
|
||||
case ChannelSubsidyIn = 4;
|
||||
case WithdrawBank = 5;
|
||||
case WithdrawFiled = 6;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ class AppServiceProvider extends ServiceProvider
|
|||
'dealer_channel_subsidy_log' => \App\Models\DealerChannelSubsidyLog::class,
|
||||
'dealer_purchase_subsidy' => \App\Models\DealerPurchaseSubsidy::class,
|
||||
'dealer_wallet_to_bank_log' => \App\Models\DealerWalletToBankLog::class,
|
||||
'dealer_earnings'=> \App\Models\DealerEarning::class,
|
||||
]);
|
||||
|
||||
JsonResource::withoutWrapping();
|
||||
|
|
|
|||
Loading…
Reference in New Issue