Browse Source

feat(api): 新增员工信息获取和资源共享功能

- 新增获取全部员工信息接口和功能
- 新增资源共享分配员工功能
- 优化资源共享列表查询,增加时间筛选条件
- 修复和完善人员信息获取接口返回结构
master
liutong 11 months ago
parent
commit
fb2d2f4dd2
  1. 124
      niucloud/app/api/controller/apiController/Personnel.php
  2. 43
      niucloud/app/api/controller/apiController/ResourceSharing.php
  3. 5
      niucloud/app/api/route/route.php
  4. 26
      niucloud/app/model/customer_resources/CustomerResources.php
  5. 72
      niucloud/app/service/api/apiService/PersonnelService.php
  6. 81
      niucloud/app/service/api/apiService/ResourceSharingService.php

124
niucloud/app/api/controller/apiController/Personnel.php

@ -36,10 +36,10 @@ class Personnel extends BaseApiService
'id'=>$this->member_id, 'id'=>$this->member_id,
]; ];
$res = (new PersonnelService())->info($where); $res = (new PersonnelService())->info($where);
if(!$res){ if(!$res['code']){
return fail('账户信息有误'); return fail($res['msg']);
} }
return success($res); return success($res['data']);
} }
//员工修改 //员工修改
@ -66,114 +66,20 @@ class Personnel extends BaseApiService
return success([]); return success([]);
} }
/** //人力资源-人员表
* 登录 public function getPersonnelAll(Request $request){
* @return Response //获取员工信息
*/ $where = [
public function login() 'account_type' => $request->param('account_type', ''),//账号类型|teacher=老师,market=销售
{ 'personnel_id' => $request->param('personnel_id', ''),//员工id
$data = $this->request->params([ ];
['username', ''], $field = 'id,name';
['password', ''], $res = (new PersonnelService())->getAll($where,$field);
]); if(!$res){
//校验登录注册配置 return fail('账户信息有误');
(new ConfigService())->checkLoginConfig(MemberLoginTypeDict::USERNAME);
//参数验证
//验证码验证
$result = (new LoginService())->account($data['username'], $data['password']);
if (!$result) {
//账号密码错误, 重置验证码
return fail('ACCOUNT_OR_PASSWORD_ERROR');
} }
return success($result); return success($res);
}
/**
* 登出
* @return Response
*/
public function logout()
{
(new LoginService)->logout();
return success('MEMBER_LOGOUT');
}
/**
* 创建验证码
* @return Response
*/
public function captcha()
{
return success((new CaptchaService())->create());
}
/**
* 发送手机验证码
* @param $type
* @return Response
* @throws Exception
*/
public function sendMobileCode($type)
{
$data = $this->request->params([
['mobile', ''],
]);
return success((new LoginService())->sendMobileCode($data['mobile'], $type));
}
/**
* 手机号登录
* @return Response
*/
public function mobile()
{
$data = $this->request->params([
['mobile', ''],
['nickname', ''],
['headimg', ''],
['mobile', '']
]);
//校验登录注册配置
(new ConfigService())->checkLoginConfig(MemberLoginTypeDict::MOBILE);
return success((new LoginService())->mobile($data));
}
/**
* 重置密码
* @return Response
*/
public function resetPassword()
{
$data = $this->request->params([
['mobile', ''],
['password', '']
]);
//参数验证
$this->validate($data, 'app\validate\member\Member.reset_password');
(new LoginService())->resetPassword($data['mobile'], $data['password']);
return success('PASSWORD_RESET_SUCCESS');
} }
//销售教师人员登陆
public function personnelLogin()
{
$data = $this->request->params([
['phone', ''],
['password', ''],
['login_type', ''],//登陆类型|1=教练,2=销售
]);
//验证码验证
$result = (new LoginService())->loginByPersonnel($data);
if(!$result['user_type']){
if($data['login_type'] == 1){
$msg = '暂无教练权限';
}else{
$msg = '暂无销售权限';
}
return fail($msg);//code|0错误
}
return success($result);//code|1正确
}
} }

43
niucloud/app/api/controller/apiController/ResourceSharing.php

@ -31,12 +31,55 @@ class ResourceSharing extends BaseApiService
$page = $request->param('page','1');// $page = $request->param('page','1');//
$limit = $request->param('limit','10');// $limit = $request->param('limit','10');//
$shared_by = $request->param('shared_by','');//共享人ID $shared_by = $request->param('shared_by','');//共享人ID
$shared_at_arr = $request->param('shared_at_arr',[]);//共享时间|[开始时间(Y-m-d),结束时间(Y-m-d)]
$where = [ $where = [
'shared_by'=>$shared_by, 'shared_by'=>$shared_by,
'shared_at_arr'=>$shared_at_arr,
]; ];
$res= (new ResourceSharingService())->getList($where); $res= (new ResourceSharingService())->getList($where);
return success($res); return success($res);
} }
//把资源分配给指定员工
public function assign(Request $request)
{
$id = $request->param('resource_sharing_id', '');//资源共享表
$shared_by = $request->param('shared_by', '');//共享人ID
if (empty($id) || empty($shared_by)) {
return fail('缺少必要参数');
}
$where = [
'id' => $id,
];
$data = [
'shared_by' => $shared_by
];
$info = (new ResourceSharingService())->info($where);//获取详情
if (!$info['code']) {
return fail($info['msg']);
} else {
if ($info['data']['shared_by'] > 0) {
if ($info['data']['shared_by'] == $shared_by) {
return success('当前资源已分享给该用户');
} else {
return fail('该资源已被分享给其他用户');
}
}
}
$res = (new ResourceSharingService())->editData($where, $data);//更新
if (!$res['code']) {
return fail('操作失败');
}
return success('操作成功');
}
} }

5
niucloud/app/api/route/route.php

@ -202,12 +202,15 @@ Route::group(function () {
Route::get('personnel/info', 'apiController.Personnel/info'); Route::get('personnel/info', 'apiController.Personnel/info');
//员工端-修改 //员工端-修改
Route::post('personnel/edit', 'apiController.Personnel/edit'); Route::post('personnel/edit', 'apiController.Personnel/edit');
//员工端-获取全部人员列表
Route::get('personnel/getPersonnelAll', 'apiController.Personnel/getPersonnelAll');
//客户资源-添加 //客户资源-添加
Route::post('customerResources/add', 'apiController.CustomerResources/add'); Route::post('customerResources/add', 'apiController.CustomerResources/add');
//资源共享-列表 //资源共享-列表
Route::get('resourceSharing/index', 'apiController.ResourceSharing/index'); Route::get('resourceSharing/index', 'apiController.ResourceSharing/index');
//资源共享-分配员工
Route::post('resourceSharing/assign', 'apiController.ResourceSharing/assign');

26
niucloud/app/model/customer_resources/CustomerResources.php

@ -11,6 +11,7 @@
namespace app\model\customer_resources; namespace app\model\customer_resources;
use app\model\dict\Dict;
use app\model\resource_sharing\ResourceSharing; use app\model\resource_sharing\ResourceSharing;
use core\base\BaseModel; use core\base\BaseModel;
use think\model\concern\SoftDelete; use think\model\concern\SoftDelete;
@ -99,4 +100,29 @@ class CustomerResources extends BaseModel
} }
/**
* 获取客户初步意向度类型名称
* @param $value
* @param $data
* @return array|mixed|string
*/
public function getInitialIntentNameAttr($value, $data)
{
if (isset($data['initial_intent']) && $data['initial_intent'] !== '') {
$dict = Dict::where('key','preliminarycustomerintention')->find();
$dictionary = $dict['dictionary'] ?? [];
// 查找匹配的 name
$res = '';
foreach ($dictionary as $item) {
if ($item['value'] === $data['initial_intent']) {
$res = $item['name'];
break;
}
}
return $res;
} else {
return '';
}
}
} }

72
niucloud/app/service/api/apiService/PersonnelService.php

@ -38,10 +38,20 @@ class PersonnelService extends BaseApiService
//获取员工信息 //获取员工信息
public function info(array $where,string $field = '*'){ public function info(array $where,string $field = '*'){
$model = $this->model; $model = $this->model;
$res = [
'code'=>0,
'msg'=>'请添加检索条件',
'data'=>[]
];
if(!$where){
return $res;
}
if(!empty($where['id'])){ if(!empty($where['id'])){
$model = $model->where('id',$where['id']); $model = $model->where('id',$where['id']);
} }
$res = $model->field($field)->find();//员工信息 $data = $model->field($field)->find();//员工信息
//查询部门信息 //查询部门信息
$campus_person_role = CampusPersonRole::where('person_id',$where['id'])->select()->toArray(); $campus_person_role = CampusPersonRole::where('person_id',$where['id'])->select()->toArray();
@ -63,16 +73,23 @@ class PersonnelService extends BaseApiService
$department_name_str = implode(',',$department_name_arr); $department_name_str = implode(',',$department_name_arr);
if($res){ if($data){
$res = $res->toArray(); $data = $data->toArray();
$res['role']=$role; $data['role']=$role;
$res['role_name_str'] = $role_name_str; $data['role_name_str'] = $role_name_str;
$res['role_key_arr'] = $role_key_arr; $data['role_key_arr'] = $role_key_arr;
$res['department_name_str'] = $department_name_str; $data['department_name_str'] = $department_name_str;
$res['code'] = 1;
$res['msg'] = '操作成功';
$res['data'] = $data;
}else{ }else{
$res = []; $data = [];
$res['code'] = 0;
$res['msg'] = '为找到数据';
$res['data'] = $data;
} }
return $res; return $res;
} }
@ -109,6 +126,45 @@ class PersonnelService extends BaseApiService
} }
//员工信息-获取全部用户
public function getAll(array $where,string $field = '*')
{
if (!$where) {
return [
'code' => 0,
'msg' => '查询条件不能为空'
];
}
$model = $this->model;
//存在员工id的时候
if ((!empty($where['personnel_id']) || isset($where['personnel_id'])) && $where['personnel_id'] !== '') {
//查询这个员工的校区id
$campus_id = CampusPersonRole::where('person_id', $where['personnel_id'])
->distinct(true)
->column('campus_id');
if ($campus_id) {
$person_id_arr = CampusPersonRole::whereIn('campus_id', $campus_id)
->distinct(true)
->column('person_id');
if ($person_id_arr) {
//根据校区id获取校区下的全部员工
$model = $model->whereIn('id', $person_id_arr);
}
}
}
if (empty($where['account_type'])) {
$model = $model->where('account_type', $where['account_type']);
}
$res = $model->field($field)
->select()
->toArray();//员工信息
return $res;
}

81
niucloud/app/service/api/apiService/ResourceSharingService.php

@ -38,20 +38,32 @@ class ResourceSharingService extends BaseApiService
$person_id = $this->member_id;//当前登录的员工id $person_id = $this->member_id;//当前登录的员工id
//查当前用户的归属校区 //查当前用户的归属校区
$campus_id = CampusPersonRole::where('person_id',$person_id)->value('campus_id'); $campus_id = CampusPersonRole::where('person_id',$person_id)
->distinct(true)
->column('campus_id');
//查当前用户校区下的全部员工id //查当前用户校区下的全部员工id
$person_id_arr = CampusPersonRole::where('campus_id',$campus_id) ->distinct(true) $person_id_arr = CampusPersonRole::whereIn('campus_id',$campus_id)
->distinct(true)
->column('person_id'); ->column('person_id');
$model = $this->model; $model = $this->model;
if (!isset($where['shared_by']) && $where['shared_by'] !== '') {
if ((!empty($where['shared_by']) || isset($where['shared_by'])) && $where['shared_by'] !== '') {
$model = $model->where('shared_by', $where['shared_by']); $model = $model->where('shared_by', $where['shared_by']);
} }
if (!empty($where['shared_at_arr'])) {
$model = $model->where('shared_at', '>=', $where['shared_at_arr'][0])->where('shared_at', '<=', $where['shared_at_arr'][1]);
}
$model = $model->whereIn('user_id', $person_id_arr); $model = $model->whereIn('user_id', $person_id_arr);
//分页查询 //分页查询
$res = $model->with([ $res = $model->with([
'customerResource'=>function($query){} 'customerResource'=>function($query){
$query->append(['initial_intent_name']);
}
])->paginate([ ])->paginate([
'list_rows' => $limit, 'list_rows' => $limit,
'page' => $page, 'page' => $page,
@ -61,4 +73,65 @@ class ResourceSharingService extends BaseApiService
} }
//查询资源共享详情
public function info(array $where, string $field = '*')
{
$res = [
'code' => 0,
'msg' => '操作失败',
'data' => []
];
if (!$where) {
$res['msg'] = '缺少查询条件';
return $res;
}
$model = $this->model;
if (!empty($where['id'])) {
$model = $model->where('id', $where['id']);
}
$data = $model->field($field)->find();
if ($data) {
$res['code'] = 1;
$res['msg'] = '操作成功';
$res['data'] = $data->toArray();
} else {
$res['code'] = 0;
$res['msg'] = '未找到数据';
$res['data'] = [];
}
return $res;
}
//更新资源共享表
public function editData(array $where, array $data)
{
$res = [
'code' => 0,
'msg' => '操作失败',
'data' => []
];
if (!$where) {
$res['msg'] = '查询条件不能为空';
return $res;
}
$model = $this->model;
if ($where['id']) {
$model = $model->where('id', $where['id']);
}
$data = $model->update($data);
if ($data) {
$res = [
'code' => 1,
'msg' => '操作成功',
'data' => []
];
}
return $res;
}
} }

Loading…
Cancel
Save