添加后台调整用户身份
parent
fd0c7e11cf
commit
47458b27a4
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Actions\Grid;
|
||||
|
||||
use App\Admin\Forms\DealerEditLvl as DealerEditLvlForm;
|
||||
use Dcat\Admin\Grid\RowAction;
|
||||
use Dcat\Admin\Widgets\Modal;
|
||||
|
||||
class DealerEditLvl extends RowAction
|
||||
{
|
||||
public function title()
|
||||
{
|
||||
if ($this->title) {
|
||||
return $this->title;
|
||||
}
|
||||
return '<i class="feather grid-action-icon icon-shuffle"></i> 修改等级 ';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Model|Authenticatable|HasPermissions|null $user
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorize($user): bool
|
||||
{
|
||||
return $user->can('dcat.admin.users.edit_agent');
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
$form = DealerEditLvlForm::make()->payload(['id'=>$this->getKey()]);
|
||||
return Modal::make()
|
||||
->lg()
|
||||
->title($this->title())
|
||||
->body($form)
|
||||
->button($this->title());
|
||||
}
|
||||
}
|
||||
|
|
@ -2,7 +2,9 @@
|
|||
|
||||
namespace App\Admin\Controllers;
|
||||
|
||||
use App\Admin\Actions\Grid\DealerEditLvl;
|
||||
use App\Admin\Repositories\Dealer;
|
||||
use Dcat\Admin\Admin;
|
||||
use Dcat\Admin\Form;
|
||||
use Dcat\Admin\Grid;
|
||||
use Dcat\Admin\Http\Controllers\AdminController;
|
||||
|
|
@ -32,8 +34,14 @@ class DealerController extends AdminController
|
|||
// $grid->column('pay_info');
|
||||
$grid->column('created_at')->sortable();
|
||||
|
||||
$grid->actions(function (Grid\Displayers\Actions $actions) {
|
||||
if (Admin::user()->can('dcat.admin.dealers.edit_lvl')) {
|
||||
$actions->append(new DealerEditLvl());
|
||||
}
|
||||
});
|
||||
|
||||
$grid->filter(function (Grid\Filter $filter) {
|
||||
$filter->equal('id');
|
||||
$filter->panel();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,81 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Forms;
|
||||
|
||||
use App\Enums\DealerLvl;
|
||||
use App\Exceptions\BizException;
|
||||
use App\Models\Dealer;
|
||||
use App\Models\UserInfo;
|
||||
use Dcat\Admin\Contracts\LazyRenderable;
|
||||
use Dcat\Admin\Traits\LazyWidget;
|
||||
use Dcat\Admin\Widgets\Form;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Throwable;
|
||||
|
||||
class DealerEditLvl extends Form implements LazyRenderable
|
||||
{
|
||||
use LazyWidget;
|
||||
|
||||
/**
|
||||
* @param Model|Authenticatable|HasPermissions|null $user
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorize($user): bool
|
||||
{
|
||||
return $user->can('dcat.admin.dealers.edit_lvl');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the form request.
|
||||
*
|
||||
* @param array $input
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle(array $input)
|
||||
{
|
||||
$id = $this->payload['id'] ?? 0;
|
||||
$dealer = Dealer::findOrFail($id);
|
||||
if ($dealer?->lvl >= $input['lvl']) {
|
||||
throw new BizException('请选择大于当前的等级');
|
||||
}
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
//执行自己升级
|
||||
$dealer->update([
|
||||
'lvl'=>$input['lvl'],
|
||||
]);
|
||||
|
||||
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()
|
||||
{
|
||||
// dd(UserInfo::$agentLevelTexts);
|
||||
$this->select('lvl', '经销商级别')->options(DealerLvl::texts())
|
||||
->help('请选择大于当前的身份')
|
||||
->required();
|
||||
}
|
||||
|
||||
public function default()
|
||||
{
|
||||
$id = $this->payload['id'] ?? 0;
|
||||
$dealer = Dealer::findOrFail($id);
|
||||
return [
|
||||
'lvl' => $dealer->lvl->value,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -167,7 +167,7 @@ Route::group([
|
|||
$router->resource('dealer-orders', 'DealerOrderController')->only([
|
||||
'index', 'edit', 'update',
|
||||
])->names('dealer_orders');
|
||||
$router->resource('dealers', 'DealerController')->only([
|
||||
$router->resource('dealer-users', 'DealerController')->only([
|
||||
'index',
|
||||
])->names('dealers');
|
||||
|
||||
|
|
|
|||
|
|
@ -174,7 +174,6 @@ Route::group([
|
|||
Route::post('order/orders/{order}/cancel', [OrderController::class, 'cancel']);
|
||||
Route::get('order/orders/{order}/packages', [OrderController::class, 'orderPackages']);
|
||||
Route::get('order/orders/{package}/shipping-info', [OrderController::class, 'shippingInfo']);
|
||||
<<<<<<< Updated upstream
|
||||
});
|
||||
|
||||
Route::group([
|
||||
|
|
@ -250,7 +249,5 @@ Route::group([
|
|||
Route::post('orders/{order}/shippinged', [Dealer\OrderController::class, 'shippingedOrder']);
|
||||
//取消订单
|
||||
Route::post('orders/{order}/cancel', [Dealer\OrderController::class, 'cancelOrder']);
|
||||
=======
|
||||
>>>>>>> Stashed changes
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -4,10 +4,13 @@ namespace App\Models;
|
|||
|
||||
use App\Casts\JsonArray;
|
||||
use App\Enums\DealerLvl;
|
||||
use Dcat\Admin\Traits\HasDateTimeFormatter;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Dealer extends Model
|
||||
{
|
||||
use HasDateTimeFormatter;
|
||||
|
||||
protected $attributes = [
|
||||
'lvl' => DealerLvl::None,
|
||||
'is_sale' => false,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
<?php
|
||||
|
||||
return [
|
||||
'labels' => [
|
||||
'Dealer' => 'Dealer',
|
||||
|
|
@ -6,6 +7,21 @@ return [
|
|||
],
|
||||
'fields' => [
|
||||
'user_id' => '用户ID',
|
||||
'user'=>[
|
||||
'phone'=>'手机号',
|
||||
],
|
||||
'userInfo'=>[
|
||||
'avatar' => '头像',
|
||||
'nickname' => '昵称',
|
||||
'agent_level'=>'管理级别',
|
||||
'growth_value'=>'消费值',
|
||||
'group_sales_value'=>'业绩',
|
||||
'inviterInfo'=>[
|
||||
'user'=>[
|
||||
'phone' =>'推荐人手机',
|
||||
],
|
||||
],
|
||||
],
|
||||
'lvl' => '经销商等级',
|
||||
'is_sale' => '是否可销售',
|
||||
'is_manager' => '是否是管理者',
|
||||
|
|
|
|||
Loading…
Reference in New Issue