添加后台打款动作
parent
184139d425
commit
76b1da0907
|
|
@ -0,0 +1,32 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Admin\Actions\Show;
|
||||||
|
|
||||||
|
use App\Admin\Forms\DealerEarningPay as DealerEarningPayForm;
|
||||||
|
use Dcat\Admin\Show\AbstractTool;
|
||||||
|
use Dcat\Admin\Widgets\Modal;
|
||||||
|
|
||||||
|
class DealerEarningPay extends AbstractTool
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected $title = '<i class="feather icon-file-text"></i> 打款';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按钮样式定义,默认 btn btn-white waves-effect
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $style = '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> ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,7 +2,9 @@
|
||||||
|
|
||||||
namespace App\Admin\Controllers;
|
namespace App\Admin\Controllers;
|
||||||
|
|
||||||
|
use App\Admin\Actions\Show\DealerEarningPay;
|
||||||
use App\Admin\Repositories\DealerEarning;
|
use App\Admin\Repositories\DealerEarning;
|
||||||
|
use App\Enums\DealerEarningStatus;
|
||||||
use App\Models\DealerChannelSubsidyLog;
|
use App\Models\DealerChannelSubsidyLog;
|
||||||
use App\Models\DealerEarning as DealerEarningModel;
|
use App\Models\DealerEarning as DealerEarningModel;
|
||||||
use App\Models\DealerManagerSalesLog;
|
use App\Models\DealerManagerSalesLog;
|
||||||
|
|
@ -120,7 +122,7 @@ class DealerEarningController extends AdminController
|
||||||
$show->field('payer.phone', '打款人')->as(function () {
|
$show->field('payer.phone', '打款人')->as(function () {
|
||||||
return $this->payer_id ? $this->payer?->phone : '公司';
|
return $this->payer_id ? $this->payer?->phone : '公司';
|
||||||
});
|
});
|
||||||
$show->field('pay_image');
|
$show->field('pay_image')->image();
|
||||||
// $show->field('pay_info');
|
// $show->field('pay_info');
|
||||||
$show->field('pay_at');
|
$show->field('pay_at');
|
||||||
$show->field('settle_at');
|
$show->field('settle_at');
|
||||||
|
|
@ -178,6 +180,11 @@ class DealerEarningController extends AdminController
|
||||||
->tools(function (Show\Tools $tools) use ($show) {
|
->tools(function (Show\Tools $tools) use ($show) {
|
||||||
$tools->disableEdit();
|
$tools->disableEdit();
|
||||||
$tools->disableDelete();
|
$tools->disableDelete();
|
||||||
|
if ($show->model()->status == DealerEarningStatus::Pending) {
|
||||||
|
if (!$show->model()->payer_id || $show->model()->payer_id == 1) {
|
||||||
|
$tools->append(new DealerEarningPay());
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,71 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Admin\Forms;
|
||||||
|
|
||||||
|
use App\Enums\DealerEarningStatus;
|
||||||
|
use App\Models\DealerEarning;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Dcat\Admin\Contracts\LazyRenderable;
|
||||||
|
use Dcat\Admin\Traits\LazyWidget;
|
||||||
|
use Dcat\Admin\Widgets\Form;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
|
class DealerEarningPay extends Form implements LazyRenderable
|
||||||
|
{
|
||||||
|
use LazyWidget;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Model|Authenticatable|HasPermissions|null $user
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function authorize($user): bool
|
||||||
|
{
|
||||||
|
return $user->can('dcat.admin.dealer_earnings.pay');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle the form request.
|
||||||
|
*
|
||||||
|
* @param array $input
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function handle(array $input)
|
||||||
|
{
|
||||||
|
$id = $this->payload['id'] ?? 0;
|
||||||
|
|
||||||
|
try {
|
||||||
|
DB::beginTransaction();
|
||||||
|
$earning = DealerEarning::findOrFail($id);
|
||||||
|
$earning->update([
|
||||||
|
'pay_info' => $earning->getPayInfo(),
|
||||||
|
'pay_image' => $input['pay_image']??null,
|
||||||
|
'pay_at' => now(),
|
||||||
|
'status' => DealerEarningStatus::Completed,
|
||||||
|
]);
|
||||||
|
DB::commit();
|
||||||
|
} catch (Throwable $th) {
|
||||||
|
DB::rollBack();
|
||||||
|
report($th);
|
||||||
|
return $this->response()->error('操作失败:'.$th->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->response()
|
||||||
|
->success(__('admin.update_succeeded'))
|
||||||
|
->refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build a form here.
|
||||||
|
*/
|
||||||
|
public function form()
|
||||||
|
{
|
||||||
|
$this->image('pay_image')
|
||||||
|
->move('dealer-pay/'.Carbon::now()->toDateString())
|
||||||
|
->saveFullUrl()
|
||||||
|
->removable(false)
|
||||||
|
->autoUpload();
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue