You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
186 lines
6.8 KiB
186 lines
6.8 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | Niucloud-admin 企业快速开发的多应用管理平台
|
|
// +----------------------------------------------------------------------
|
|
// | 官方网址:https://www.niucloud.com
|
|
// +----------------------------------------------------------------------
|
|
// | niucloud团队 版权所有 开源版本可自由商用
|
|
// +----------------------------------------------------------------------
|
|
// | Author: Niucloud Team
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace app\api\controller\apiController;
|
|
|
|
use app\Request;
|
|
use app\service\api\apiService\ResourceSharingService;
|
|
use core\base\BaseApiService;
|
|
|
|
/**
|
|
* 资源共享表相关接口
|
|
* Class Personnel
|
|
* @package app\api\controller\apiController
|
|
*/
|
|
class ResourceSharing extends BaseApiService
|
|
{
|
|
|
|
//资源共享列表
|
|
public function index(Request $request)
|
|
{
|
|
$user_id = $this->member_id;//当前登陆的用户id
|
|
|
|
$shared_by = $request->param('shared_by','');//共享人ID
|
|
$name = $request->param('name','');////客户资源表-姓名
|
|
$phone_number = $request->param('phone_number','');//客户资源表-手机号
|
|
$campus_name = $request->param('campus_name','');//客户资源表-校区
|
|
|
|
// 新增搜索参数
|
|
$source = $request->param('source','');//来源类型
|
|
$source_channel = $request->param('source_channel','');//来源渠道
|
|
$attendance_type = $request->param('attendance_type','');//到课类型
|
|
$deal_type = $request->param('deal_type','');//成交类型
|
|
$valid_type = $request->param('valid_type','');//资源有效类型
|
|
$communication_status = $request->param('communication_status','');//沟通情况
|
|
$course_search = $request->param('course_search','');//课程检索
|
|
$shared_scope = $request->param('shared_scope', '');
|
|
$assignee_role_ids = $request->param('assignee_role_ids', []);
|
|
|
|
if (is_string($assignee_role_ids) && $assignee_role_ids !== '') {
|
|
$assignee_role_ids = array_filter(array_map('intval', explode(',', $assignee_role_ids)));
|
|
} elseif (!is_array($assignee_role_ids)) {
|
|
$assignee_role_ids = [];
|
|
}
|
|
|
|
$shared_at_str = $request->param('shared_at_str','');//共享时间|[开始时间(Y-m-d),结束时间(Y-m-d)]
|
|
$shared_at_arr = [];
|
|
if(!empty($shared_at_str)){
|
|
$shared_at_arr = explode(' ~ ',$shared_at_str);
|
|
$shared_at_arr[0] = "{$shared_at_arr[0]} 00:00:00";
|
|
$shared_at_arr[1] = "{$shared_at_arr[1]} 23:59:59";
|
|
}
|
|
|
|
$where = [
|
|
'shared_by'=>$shared_by,
|
|
'shared_at_arr'=>$shared_at_arr,
|
|
'name'=>$name,
|
|
'phone_number'=>$phone_number,
|
|
'campus_name' => $campus_name,
|
|
'source' => $source,
|
|
'source_channel' => $source_channel,
|
|
'attendance_type' => $attendance_type,
|
|
'deal_type' => $deal_type,
|
|
'valid_type' => $valid_type,
|
|
'communication_status' => $communication_status,
|
|
'course_search' => $course_search,
|
|
'shared_scope' => $shared_scope,
|
|
'assignee_role_ids' => $assignee_role_ids
|
|
];
|
|
$res = (new ResourceSharingService())->getList($where);
|
|
return success($res);
|
|
}
|
|
//资源共享-详情
|
|
public function info(Request $request)
|
|
{
|
|
$resource_sharing_id = $request->param('resource_sharing_id','');//资源共享表id
|
|
|
|
if(!$resource_sharing_id){
|
|
return fail('缺少参数');
|
|
}
|
|
|
|
$where = [
|
|
'id' => $resource_sharing_id
|
|
];
|
|
|
|
$res = (new ResourceSharingService())->info($where);
|
|
if (!$res['code']) {
|
|
return fail($res['msg']);
|
|
}
|
|
return success($res['data']);
|
|
}
|
|
|
|
//把资源分配给指定员工(兼容旧接口)
|
|
public function assign(Request $request)
|
|
{
|
|
$id = $request->param('resource_sharing_id', '');//资源共享表ID
|
|
$shared_by = $request->param('shared_by', '');//分配给的用户ID
|
|
|
|
if (empty($id) || empty($shared_by)) {
|
|
return fail('缺少必要参数');
|
|
}
|
|
|
|
$service = new ResourceSharingService();
|
|
|
|
// 使用新的分配方法(兼容旧接口)
|
|
$res = $service->assignResourceLegacy($id, $shared_by);
|
|
|
|
if (!$res['code']) {
|
|
return fail($res['msg']);
|
|
}
|
|
return success($res['msg']);
|
|
}
|
|
|
|
//新的资源分配接口 - 支持用户和角色分配
|
|
public function assignNew(Request $request)
|
|
{
|
|
$resource_id = $request->param('resource_id', '');//资源ID
|
|
$assignee_type = $request->param('assignee_type', 'user');//分配对象类型:user/role
|
|
$assignee_id = $request->param('assignee_id', '');//分配对象ID
|
|
$is_primary = $request->param('is_primary', false);//是否为主责分配
|
|
$campus_id = $request->param('campus_id', null);//校区ID
|
|
|
|
if (empty($resource_id) || empty($assignee_id)) {
|
|
return fail('缺少必要参数');
|
|
}
|
|
|
|
if (!in_array($assignee_type, ['user', 'role'])) {
|
|
return fail('分配对象类型错误');
|
|
}
|
|
|
|
$service = new ResourceSharingService();
|
|
$res = $service->assignResource($resource_id, $assignee_type, $assignee_id, $is_primary, $campus_id);
|
|
|
|
if (!$res['code']) {
|
|
return fail($res['msg']);
|
|
}
|
|
return success($res['msg'], $res['data']);
|
|
}
|
|
|
|
//移除资源分配
|
|
public function removeAssignment(Request $request)
|
|
{
|
|
$resource_id = $request->param('resource_id', '');//资源ID
|
|
$assignee_type = $request->param('assignee_type', 'user');//分配对象类型:user/role
|
|
$assignee_id = $request->param('assignee_id', '');//分配对象ID
|
|
|
|
if (empty($resource_id) || empty($assignee_id)) {
|
|
return fail('缺少必要参数');
|
|
}
|
|
|
|
if (!in_array($assignee_type, ['user', 'role'])) {
|
|
return fail('分配对象类型错误');
|
|
}
|
|
|
|
$service = new ResourceSharingService();
|
|
$res = $service->removeAssignment($resource_id, $assignee_type, $assignee_id);
|
|
|
|
if (!$res['code']) {
|
|
return fail($res['msg']);
|
|
}
|
|
return success($res['msg']);
|
|
}
|
|
|
|
//获取资源的所有分配信息
|
|
public function assignments(Request $request)
|
|
{
|
|
$resource_id = $request->param('resource_id', '');//资源ID
|
|
|
|
if (empty($resource_id)) {
|
|
return fail('缺少资源ID参数');
|
|
}
|
|
|
|
$service = new ResourceSharingService();
|
|
$assignments = $service->getResourceAssignments($resource_id);
|
|
|
|
return success('获取成功', $assignments);
|
|
}
|
|
|
|
}
|
|
|