Commit 753ab4d3 by 宁成龙

完善禁用/启用操作

parent 5e446ea2
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace App\Admin\Actions\User; namespace App\Admin\Actions\User;
use App\Admin\Service\UserService;
use App\Models\Order as OrderModel; use App\Models\Order as OrderModel;
use App\Models\User; use App\Models\User;
use Dcat\Admin\Grid\BatchAction; use Dcat\Admin\Grid\BatchAction;
...@@ -29,7 +30,7 @@ class UserStatusAction extends RowAction ...@@ -29,7 +30,7 @@ class UserStatusAction extends RowAction
public function title() public function title()
{ {
$buttonName = "启用"; $buttonName = "启用";
if ($this->row->status==User::STATUS_NORMAL){ if ($this->row->status == User::STATUS_NORMAL) {
$buttonName = "禁用"; $buttonName = "禁用";
} }
return $buttonName; return $buttonName;
...@@ -39,7 +40,7 @@ class UserStatusAction extends RowAction ...@@ -39,7 +40,7 @@ class UserStatusAction extends RowAction
{ {
$class = $this->getElementClass(); $class = $this->getElementClass();
$color = "btn btn-primary btn-sm btn-mini"; $color = "btn btn-primary btn-sm btn-mini";
if ($this->row->status==User::STATUS_NORMAL){ if ($this->row->status == User::STATUS_NORMAL) {
$color = "btn btn-danger btn-sm btn-mini"; $color = "btn btn-danger btn-sm btn-mini";
} }
// 获取当前行数据ID // 获取当前行数据ID
...@@ -59,7 +60,7 @@ class UserStatusAction extends RowAction ...@@ -59,7 +60,7 @@ class UserStatusAction extends RowAction
public function confirm() public function confirm()
{ {
$buttonName = "启用"; $buttonName = "启用";
if ($this->row->status==User::STATUS_NORMAL){ if ($this->row->status == User::STATUS_NORMAL) {
$buttonName = "禁用"; $buttonName = "禁用";
} }
return ["是否确认 {$buttonName} ?"]; return ["是否确认 {$buttonName} ?"];
...@@ -78,8 +79,13 @@ class UserStatusAction extends RowAction ...@@ -78,8 +79,13 @@ class UserStatusAction extends RowAction
// 获取 parameters 方法传递的参数 // 获取 parameters 方法传递的参数
$rowData = $request->get('rowData'); $rowData = $request->get('rowData');
try {
return $this->response()->success('取消成功')->refresh(); UserService::updateUserStatus($id,
$rowData['status'] == User::STATUS_NORMAL ? User::STATUS_DISABLE : User::STATUS_NORMAL);
} catch (\Throwable $e) {
return $this->response()->error($e->getMessage());
}
return $this->response()->success('操作成功')->refresh();
} }
/** /**
...@@ -95,6 +101,4 @@ class UserStatusAction extends RowAction ...@@ -95,6 +101,4 @@ class UserStatusAction extends RowAction
} }
} }
...@@ -8,12 +8,13 @@ use App\Admin\Actions\User\UserAssignAction; ...@@ -8,12 +8,13 @@ use App\Admin\Actions\User\UserAssignAction;
use App\Admin\Actions\User\UserStatusAction; use App\Admin\Actions\User\UserStatusAction;
use App\Admin\Actions\User\UserTransferAction; use App\Admin\Actions\User\UserTransferAction;
use App\Models\Cms\CmsUser; use App\Models\Cms\CmsUser;
use App\Models\User;
use Dcat\Admin\Grid; use Dcat\Admin\Grid;
class UserService class UserService
{ {
public static function userListFilter(Grid $grid){ public static function userListFilter(Grid $grid)
{
$grid->filter(function ($filter) { $grid->filter(function ($filter) {
$filter->expand(true); $filter->expand(true);
$filter->whereBetween('create_time', function ($q) { $filter->whereBetween('create_time', function ($q) {
...@@ -26,16 +27,17 @@ class UserService ...@@ -26,16 +27,17 @@ class UserService
$filter->startWith('user_sn')->width(2); $filter->startWith('user_sn')->width(2);
$filter->startWith('name')->width(2); $filter->startWith('name')->width(2);
$filter->equal('status')->select(admin_trans('user.options.status'))->width(2); $filter->equal('status')->select(admin_trans('user.options.status'))->width(2);
$filter->equal('sales_id',trans('inquiry.fields.sales_name'))->select(CmsUser::pluck('name', 'userId')->toArray())->width(3); $filter->equal('sale_id', trans('user.fields.sale_name'))->select(CmsUser::pluck('name', 'userId')
->toArray())->width(3);
$filter->equal('reg_source')->select(admin_trans('user.options.reg_source'))->width(2); $filter->equal('reg_source')->select(admin_trans('user.options.reg_source'))->width(2);
}); });
} }
public static function userListListField(Grid $grid){ public static function userListListField(Grid $grid)
{
$grid->column('company_name'); $grid->column('company_name');
$grid->column('user_sn')->link(function ($user_sn) { $grid->column('user_sn')->link(function ($user_sn) {
return admin_url('smc_user/'.$user_sn); return admin_url('smc_user/' . $user_sn);
}); });
$grid->column('name'); $grid->column('name');
$grid->column('phone'); $grid->column('phone');
...@@ -46,18 +48,18 @@ class UserService ...@@ -46,18 +48,18 @@ class UserService
return $time ? date('Y-m-d H:i:s', $time) : ''; return $time ? date('Y-m-d H:i:s', $time) : '';
})->sortable();; })->sortable();;
$grid->column('status')->using(admin_trans('user.options.status')); $grid->column('status')->using(admin_trans('user.options.status'));
} }
public static function userListTool(Grid $grid){ public static function userListTool(Grid $grid)
{
$grid->tools([ $grid->tools([
new UserAssignAction("分配销售"), new UserAssignAction("分配销售"),
new UserTransferAction("转移销售"), new UserTransferAction("转移销售"),
]); ]);
} }
public static function userListActions(Grid $grid){ public static function userListActions(Grid $grid)
{
$grid->setActionClass(Grid\Displayers\Actions::class); $grid->setActionClass(Grid\Displayers\Actions::class);
$grid->actions(function (Grid\Displayers\Actions $actions) { $grid->actions(function (Grid\Displayers\Actions $actions) {
$actions->disableDelete(); $actions->disableDelete();
...@@ -71,10 +73,14 @@ class UserService ...@@ -71,10 +73,14 @@ class UserService
$id = $actions->getKey(); $id = $actions->getKey();
//状态按钮 //状态按钮
$actions->append(new UserStatusAction()); $actions->append(new UserStatusAction());
}); });
} }
public static function updateUserStatus($id, $status)
{
$update = [
"status" => $status
];
User::updateById($id, $update);
}
} }
...@@ -30,9 +30,39 @@ class User extends Model ...@@ -30,9 +30,39 @@ class User extends Model
{ {
use HasDateTimeFormatter; use HasDateTimeFormatter;
protected $table = 'users'; protected $table = 'users';
public $timestamps = false;
const STATUS_NORMAL = 1; const STATUS_NORMAL = 1;
const STATUS_DISABLE = -1; const STATUS_DISABLE = -1;
public static function insertData($data)
{
return self::insertGetId($data);
}
public static function updateById($id, $update)
{
return self::where("id", $id)->update($update);
}
public static function getInfoByUserId($userId)
{
$res = self::where('user_id', $userId)->first();
return ($res) ? $res->toArray() : [];
}
// 批量获取用户信息
public static function getInfoByUserIds($userId)
{
return self::whereIn('user_id', $userId)->get()->keyBy('user_id')->toArray();
}
public static function getListByIdArr($userIdArr)
{
$res = self::wherein('user_id', $userIdArr)->get();
return ($res) ? $res->toArray() : [];
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment