diff --git a/app/Admin/Actions/Show/DealerEarningPay.php b/app/Admin/Actions/Show/DealerEarningPay.php
index 8250a1fb..804e08e7 100644
--- a/app/Admin/Actions/Show/DealerEarningPay.php
+++ b/app/Admin/Actions/Show/DealerEarningPay.php
@@ -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("style}\">{$this->title} ");
+ // }
+
+ public function handle(Request $request)
{
- $form = DealerEarningPayForm::make()->payload(['id'=>$this->getKey()]);
- return Modal::make()
- ->lg()
- ->title($this->title)
- ->body($form)
- ->button("style}\">{$this->title} ");
+ // 获取主键
+ $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 ['是否确认打款?', '该操作不可逆,确认后将打款到余额。'];
}
}
diff --git a/app/Admin/Forms/DealerEarningPay.php b/app/Admin/Forms/DealerEarningPay.php
index ea3371f2..0bd1a573 100644
--- a/app/Admin/Forms/DealerEarningPay.php
+++ b/app/Admin/Forms/DealerEarningPay.php
@@ -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();
diff --git a/app/Enums/DealerWalletAction.php b/app/Enums/DealerWalletAction.php
index fdcec0eb..9619f5fc 100644
--- a/app/Enums/DealerWalletAction.php
+++ b/app/Enums/DealerWalletAction.php
@@ -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;
}
diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php
index 56e48311..1ffe66ac 100644
--- a/app/Providers/AppServiceProvider.php
+++ b/app/Providers/AppServiceProvider.php
@@ -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();