|
@@ -8,6 +8,7 @@ namespace app\api\controller;
|
|
|
|
|
|
|
|
|
use app\api\BaseController;
|
|
|
+use app\api\exception\ApiException;
|
|
|
use app\api\model\BrandModel;
|
|
|
use app\api\model\GroupModel;
|
|
|
use app\api\model\StaffModel;
|
|
@@ -37,14 +38,17 @@ class Staff extends BaseController {
|
|
|
$model = new StaffModel();
|
|
|
$model->setPage($input['page'] ?? 1);
|
|
|
$model->setPageSize($input['pageSize'] ?? 10);
|
|
|
+ $where = [];
|
|
|
if ($this->isAdmin()) {
|
|
|
- $where = [];
|
|
|
+ if (!empty($input['status'])) {
|
|
|
+ $where[] = ['s.status', '=', $input['status']];
|
|
|
+ }
|
|
|
} else {
|
|
|
$where[] = ['s.status', '=', $model::NORMAL];
|
|
|
}
|
|
|
|
|
|
if (!empty($input['name'])) {
|
|
|
- $where[] = ['s.staff_name', 'like', "%{$input['name']}%"];
|
|
|
+ $where[] = ['s.staff_name|s.staff_code', 'like', "%{$input['name']}%"];
|
|
|
}
|
|
|
|
|
|
if (!empty($input['mobile'])) {
|
|
@@ -58,7 +62,11 @@ class Staff extends BaseController {
|
|
|
|
|
|
if (!empty($input['groupId'])) {
|
|
|
$arr = explode(',',$input['groupId']);
|
|
|
- $where[] = ['s.group_id', 'in', $arr];
|
|
|
+ $where[] = ['sto.group_id', 'in', $arr];
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($this->isAdmin()) {
|
|
|
+ $where[] = ['gr.admin_id','=',$this->adminId];
|
|
|
}
|
|
|
$model->setWhere($where);
|
|
|
$data = $model->getStaffList();
|
|
@@ -100,6 +108,10 @@ class Staff extends BaseController {
|
|
|
Until::check($rule, $input);
|
|
|
$model = new StaffModel();
|
|
|
if (!empty($input['id'])) {
|
|
|
+ $rs = $model::where([['code','=',$input['code'],['id','<>',$input['id']]]])->find();
|
|
|
+ if (!empty($rs)) {
|
|
|
+ throw new ApiException('工号不可重复');
|
|
|
+ }
|
|
|
$id = (int)$input['id'];
|
|
|
$model::where(['id' => $id])->update([
|
|
|
'staff_name' => $input['name'],
|
|
@@ -111,6 +123,10 @@ class Staff extends BaseController {
|
|
|
'status' => $input['status'] ?? $model::NORMAL
|
|
|
]);
|
|
|
} else {
|
|
|
+ $rs = $model::where([['code','=',$input['code']]])->find();
|
|
|
+ if (!empty($rs)) {
|
|
|
+ throw new ApiException('工号不可重复');
|
|
|
+ }
|
|
|
$id = $model->insertGetId([
|
|
|
'staff_name' => $input['name'],
|
|
|
'staff_code' => $input['code'],
|