Commit 9384e9c0 by 孙龙
parents 17b8b07a fa1595cd
...@@ -19,16 +19,16 @@ class UserAssignAction extends BatchAction ...@@ -19,16 +19,16 @@ class UserAssignAction extends BatchAction
protected $action; protected $action;
protected $htmlClasses = ['btn btn-primary btn-sm btn-mini']; protected $htmlClasses = ['btn btn-primary btn-sm btn-mini'];
// 注意action的构造方法参数一定要给默认值 // 注意action的构造方法参数一定要给默认值 1指派,2转让
public function __construct() public function __construct($action=1)
{ {
$this->title = ""; $this->title = "";
$this->action = 1; $this->action = $action;
} }
public function render() public function render()
{ {
$form = AssignUserHandle::make(); $form = AssignUserHandle::make(['action' => $this->action]);
$buttonName = trans('user.labels.assign'); $buttonName = trans('user.labels.assign');
return Modal::make()->lg()->title($this->title)->body($form->payload([]))->onLoad($this->getModalScript())->button('<button class="btn btn-primary"> return Modal::make()->lg()->title($this->title)->body($form->payload([]))->onLoad($this->getModalScript())->button('<button class="btn btn-primary">
<i class="feather icon-check-circle"></i><span class="d-none d-sm-inline" style="margin-left: 5px">' . $buttonName . '</span> <i class="feather icon-check-circle"></i><span class="d-none d-sm-inline" style="margin-left: 5px">' . $buttonName . '</span>
......
...@@ -91,7 +91,7 @@ class UserController extends AdminController ...@@ -91,7 +91,7 @@ class UserController extends AdminController
]; ];
$validator = Validator::make($params, [ $validator = Validator::make($params, [
'company_name' => 'required', // 'company_name' => 'required',
'first_name' => 'required', 'first_name' => 'required',
'last_name' => 'required', 'last_name' => 'required',
'phone' => 'required', 'phone' => 'required',
...@@ -112,6 +112,12 @@ class UserController extends AdminController ...@@ -112,6 +112,12 @@ class UserController extends AdminController
$error = $validator->errors()->first(); $error = $validator->errors()->first();
throw new \Exception($error); throw new \Exception($error);
} }
if ($params['account_properties'] == \App\Models\User::ACCOUNT_PROPERTIES_ENTERPRISE) {
if (empty($params['company_name'])) {
throw new \Exception(trans("user.error_msg.requiredByCompanyName"));
}
}
UserService::createUserAndAddress($params); UserService::createUserAndAddress($params);
} catch (\Throwable $throwable) { } catch (\Throwable $throwable) {
// var_dump((string)$throwable); // var_dump((string)$throwable);
......
...@@ -43,7 +43,7 @@ class AssignUserHandle extends Form implements LazyRenderable ...@@ -43,7 +43,7 @@ class AssignUserHandle extends Form implements LazyRenderable
{ {
$this->disableResetButton(); $this->disableResetButton();
$this->hidden('id')->attribute('id', 'id'); $this->hidden('id')->attribute('id', 'id');
$this->select('sale_id')->options(CmsUser::pluck('name', 'userId')->toArray())->default(0)->required(); $this->select('sale_id')->options(CmsUser::getUserList())->default(0)->required();
} }
/** /**
......
...@@ -33,6 +33,11 @@ class EditUserHandle extends Form implements LazyRenderable ...@@ -33,6 +33,11 @@ class EditUserHandle extends Form implements LazyRenderable
$input = array_filter($input, function ($value) { $input = array_filter($input, function ($value) {
return $value !== null; return $value !== null;
}); });
if ($input['account_properties'] == \App\Models\User::ACCOUNT_PROPERTIES_ENTERPRISE) {
if (empty($input['company_name'])) {
throw new \Exception(trans("user.error_msg.requiredByCompanyName"));
}
}
User::updateById($id, $input); User::updateById($id, $input);
return $this return $this
...@@ -53,7 +58,7 @@ class EditUserHandle extends Form implements LazyRenderable ...@@ -53,7 +58,7 @@ class EditUserHandle extends Form implements LazyRenderable
$this->disableResetButton(); $this->disableResetButton();
$this->hidden('id')->attribute('id', 'id')->width(4); $this->hidden('id')->attribute('id', 'id')->width(4);
$this->row(function (Row $form) { $this->row(function (Row $form) {
$form->width(5)->text('company_name')->required(); $form->width(5)->text('company_name');
$form->width(5)->text('user_sn')->disable(); $form->width(5)->text('user_sn')->disable();
}); });
$this->row(function (Row $form) { $this->row(function (Row $form) {
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace App\Admin\Forms\User; namespace App\Admin\Forms\User;
use App\Admin\Service\PermService;
use App\Admin\Service\UserService; use App\Admin\Service\UserService;
use App\Models\Cms\CmsUser; use App\Models\Cms\CmsUser;
use App\Models\Inquiry; use App\Models\Inquiry;
...@@ -32,10 +33,47 @@ class TransferUserHandle extends Form implements LazyRenderable ...@@ -32,10 +33,47 @@ class TransferUserHandle extends Form implements LazyRenderable
->refresh(); ->refresh();
} catch (\Throwable $throwable) { } catch (\Throwable $throwable) {
// var_dump((string)$throwable); // var_dump((string)$throwable);
return $this->response()->error(trans('admin.update_failed').": {$throwable->getMessage()}"); return $this->response()->error(trans('admin.update_failed') . ": {$throwable->getMessage()}");
} }
} }
public function getCmsUserList()
{
CmsUser::getUserList();
$where = [];
$where[] = [
function ($query) {
$viewList = User::$ruleViewList;
$adminUser = "userId";
$nowSaleId = getAdminUserId();
if ($nowSaleId == 1000) {
return $query;
}
//查看所有
if (checkPerm($viewList[0])) {
return $query;
}
//查看下级
if (checkPerm($viewList[1])) { //查看下级的权限//获取用户部门下的所有用户
$userIds = PermService::getSubUserId($nowSaleId);
if (!empty($userIds)) {
return $query->whereIn($adminUser, $userIds);
}
}
//查看同组
$user_info = CmsUser::getInfoByUserId($nowSaleId);
if (empty($user_info) || !$user_info['department_id']) {
return $query->where($adminUser, $nowSaleId);
}
// 获取下级部门的人员
$sub_user_ids = CmsUser::getUserIdsByDepartmentIds([$user_info['department_id']]);
return $query->whereIn($adminUser, $sub_user_ids);
}
];
return CmsUser::where($where)->pluck('name', 'userId')->toArray();
}
/** /**
* Build a form here. * Build a form here.
*/ */
...@@ -43,7 +81,7 @@ class TransferUserHandle extends Form implements LazyRenderable ...@@ -43,7 +81,7 @@ class TransferUserHandle extends Form implements LazyRenderable
{ {
$this->disableResetButton(); $this->disableResetButton();
$this->hidden('id')->attribute('id', 'id'); $this->hidden('id')->attribute('id', 'id');
$this->select('sale_id')->options(CmsUser::pluck('name', 'userId')->toArray())->default(0)->required(); $this->select('sale_id')->options($this->getCmsUserList())->default(0)->required();
} }
/** /**
......
...@@ -26,7 +26,7 @@ class CreateUser extends \Dcat\Admin\Support\LazyRenderable ...@@ -26,7 +26,7 @@ class CreateUser extends \Dcat\Admin\Support\LazyRenderable
$form->disableResetButton(); $form->disableResetButton();
$form->disableCreatingCheck(); $form->disableCreatingCheck();
$form->row(function (Form\Row $form) { $form->row(function (Form\Row $form) {
$form->width(4)->text('company_name')->required(); $form->width(4)->text('company_name');
$form->width(4)->text('user_sn')->disable(); $form->width(4)->text('user_sn')->disable();
}); });
$form->row(function (Form\Row $form) { $form->row(function (Form\Row $form) {
......
...@@ -9,16 +9,13 @@ class CmsUserService ...@@ -9,16 +9,13 @@ class CmsUserService
/** /**
* 根据不同的部门权限以及部门id来获取员工列表 * 根据不同的部门权限以及部门id来获取员工列表
* getCmsUserListByDepartmentType * getCmsUserListByDepartmentType
* @param $departmentType
* @param $departmentId
* @return array * @return array
* @author tioncico * @author tioncico
* Time: 9:38 AM * Time: 9:38 AM
*/ */
public static function getCmsUserListByDepartmentType($departmentType,$departmentId) public static function getCmsUserListByDepartmentType()
{ {
$res = CmsUser::pluck('name', 'userId') $res = CmsUser::getUserList();
->toArray();
return $res; return $res;
} }
......
...@@ -34,7 +34,7 @@ class UserService ...@@ -34,7 +34,7 @@ class UserService
$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('sale_id', trans('user.fields.sale_name'))->select $filter->equal('sale_id', trans('user.fields.sale_name'))->select
(CmsUserService::getCmsUserListByDepartmentType(1, 0))->width(3); (CmsUser::getUserList())->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);
}); });
} }
......
...@@ -2,9 +2,10 @@ ...@@ -2,9 +2,10 @@
namespace App\Models\Cms; namespace App\Models\Cms;
use App\Models\BaseModel;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
class CmsUser extends Model class CmsUser extends BaseModel
{ {
protected $connection = 'cms'; protected $connection = 'cms';
protected $table = 'user_info'; protected $table = 'user_info';
......
...@@ -48,4 +48,7 @@ return [ ...@@ -48,4 +48,7 @@ return [
"2" => "Enterprise" "2" => "Enterprise"
], ],
], ],
"error_msg"=>[
"requiredByCompanyName"=>"Company name is required when account properties is company",
]
]; ];
...@@ -48,4 +48,7 @@ return [ ...@@ -48,4 +48,7 @@ return [
"2" => "企业" "2" => "企业"
], ],
], ],
"error_msg"=>[
"requiredByCompanyName"=>"当帐户属性为公司时,需要公司名称必填",
]
]; ];
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