|
|
@ -4,6 +4,8 @@ namespace app\admin\service; |
|
|
|
|
|
|
|
use app\model\AdminModel; |
|
|
|
use app\model\AuthGroupAccessModel; |
|
|
|
use app\model\AwsIvsModel; |
|
|
|
use app\model\CustomerRelationalModel; |
|
|
|
use app\model\UserModel; |
|
|
|
|
|
|
|
class AgentService extends AdminBaseService |
|
|
@ -151,4 +153,178 @@ class AgentService extends AdminBaseService |
|
|
|
return $this->toData('1', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public function customerList($param) |
|
|
|
{ |
|
|
|
try { |
|
|
|
if (empty($param['page']) || !is_numeric($param['page'])) { |
|
|
|
return $this->toData('1', '参错错误'); |
|
|
|
} |
|
|
|
|
|
|
|
// 角色ID |
|
|
|
$roleId = 11; |
|
|
|
// 代理ID |
|
|
|
$agentId = 0; |
|
|
|
if (isset($param['agent_id']) && is_numeric($param['agent_id'])) { |
|
|
|
$agentId = $param['agent_id']; |
|
|
|
} |
|
|
|
$list = AdminModel::when($agentId, function ($query) use ($agentId) { |
|
|
|
$query->where('parent_id', $agentId)->order('id', 'desc'); //查询代理下的客服列表 |
|
|
|
}, function ($query) use($roleId) { |
|
|
|
$query->where('role_id', $roleId)->order('id', 'desc'); //查询所有客服列表 |
|
|
|
})->paginate([ |
|
|
|
'list_rows' => 15, // 每页显示 10 条 |
|
|
|
'page' => $param['page'], // 使用前端传递的页码 |
|
|
|
]); |
|
|
|
|
|
|
|
return $this->toData('0', 'SUCCESS', [ |
|
|
|
'list' => $list->items(), // 当前页的数据 |
|
|
|
'page' => $list->currentPage(), // 当前页码 |
|
|
|
'total' => $list->total(), // 总记录数 |
|
|
|
'last_page' => $list->lastPage(), // 最后一页页码 |
|
|
|
'agent_id' => $agentId, |
|
|
|
]); |
|
|
|
} catch (\Exception $exception) { |
|
|
|
return $this->toData('1', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public function customerUser($param) |
|
|
|
{ |
|
|
|
try { |
|
|
|
if (empty($param['customer_id']) || !is_numeric($param['customer_id'])) { |
|
|
|
return $this->toData('1', '参错错误'); |
|
|
|
} |
|
|
|
if (empty($param['page']) || !is_numeric($param['page'])) { |
|
|
|
return $this->toData('1', '参错错误'); |
|
|
|
} |
|
|
|
// 查询当前客服下的用户 |
|
|
|
$list = CustomerRelationalModel::where('customer_id', $param['customer_id'])->order('id', 'desc')->paginate([ |
|
|
|
'list_rows' => 15, // 每页显示 10 条 |
|
|
|
'page' => $param['page'], // 使用前端传递的页码 |
|
|
|
]); |
|
|
|
$userIds = array_column($list->items(), 'user_id'); // 获取当前页的用户id |
|
|
|
// 根据user_id查询用户列表 |
|
|
|
$userDetails = UserModel::whereIn('id', $userIds)->select()->toArray(); |
|
|
|
|
|
|
|
return $this->toData('0', 'SUCCESS', [ |
|
|
|
'list' => $list->items(), // 当前页的数据 |
|
|
|
'user_details' => $userDetails, |
|
|
|
'page' => $list->currentPage(), // 当前页码 |
|
|
|
'total' => $list->total(), // 总记录数 |
|
|
|
'last_page' => $list->lastPage(), // 最后一页页码 |
|
|
|
]); |
|
|
|
} catch (\Exception $exception) { |
|
|
|
return $this->toData('1', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public function awsIvsList($param) |
|
|
|
{ |
|
|
|
try { |
|
|
|
if (empty($param['page']) || !is_numeric($param['page'])) { |
|
|
|
return $this->toData('1', '参错错误'); |
|
|
|
} |
|
|
|
|
|
|
|
if (isset($param['title'])) { |
|
|
|
$list = AwsIvsModel::where('title', $param['title'])->order('id', 'desc')->paginate([ |
|
|
|
'list_rows' => 15, |
|
|
|
'page' => $param['page'], |
|
|
|
]); |
|
|
|
} else { |
|
|
|
$list = AwsIvsModel::order('id', 'desc')->paginate([ |
|
|
|
'list_rows' => 15, |
|
|
|
'page' => $param['page'], |
|
|
|
]); |
|
|
|
} |
|
|
|
|
|
|
|
return $this->toData('0', 'SUCCESS', [ |
|
|
|
'list' => $list->items(), // 当前页的数据 |
|
|
|
'page' => $list->currentPage(), // 当前页码 |
|
|
|
'total' => $list->total(), // 总记录数 |
|
|
|
'last_page' => $list->lastPage(), // 最后一页页码 |
|
|
|
]); |
|
|
|
} catch (\Exception $exception) { |
|
|
|
return $this->toData('1', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public function awsIvsAdd($param) |
|
|
|
{ |
|
|
|
try { |
|
|
|
if (empty($param['title'])) { |
|
|
|
return $this->toData('1', 'Missing param title'); |
|
|
|
} |
|
|
|
if (empty($param['anchor_name'])) { |
|
|
|
return $this->toData('1', 'Missing param anchor_name'); |
|
|
|
} |
|
|
|
if (empty($param['desc'])) { |
|
|
|
return $this->toData('1', 'Missing param desc'); |
|
|
|
} |
|
|
|
if (empty($param['push_url'])) { |
|
|
|
return $this->toData('1', 'Missing param push_url'); |
|
|
|
} |
|
|
|
if (empty($param['secret_key'])) { |
|
|
|
return $this->toData('1', 'Missing param secret_key'); |
|
|
|
} |
|
|
|
if (empty($param['play_url'])) { |
|
|
|
return $this->toData('1', 'Missing param play_url'); |
|
|
|
} |
|
|
|
$res = AwsIvsModel::create([ |
|
|
|
'title' => $param['title'], |
|
|
|
'anchor_name' => $param['anchor_name'], |
|
|
|
'avatar' => $param['avatar'], |
|
|
|
'desc' => $param['desc'], |
|
|
|
'push_url' => $param['push_url'], |
|
|
|
'secret_key' => $param['secret_key'], |
|
|
|
'play_url' => $param['play_url'] |
|
|
|
]); |
|
|
|
return $this->toData('0', 'SUCCESS', ['id' => $res->id]); |
|
|
|
} catch (\Exception $exception) { |
|
|
|
return $this->toData('1', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public function awsIvsEdit($param) |
|
|
|
{ |
|
|
|
try { |
|
|
|
if (empty($param['id'])) { |
|
|
|
return $this->toData('1', 'Missing param id'); |
|
|
|
} |
|
|
|
if (empty($param['title'])) { |
|
|
|
return $this->toData('1', 'Missing param title'); |
|
|
|
} |
|
|
|
if (empty($param['anchor_name'])) { |
|
|
|
return $this->toData('1', 'Missing param anchor_name'); |
|
|
|
} |
|
|
|
if (empty($param['desc'])) { |
|
|
|
return $this->toData('1', 'Missing param desc'); |
|
|
|
} |
|
|
|
if (empty($param['push_url'])) { |
|
|
|
return $this->toData('1', 'Missing param push_url'); |
|
|
|
} |
|
|
|
if (empty($param['secret_key'])) { |
|
|
|
return $this->toData('1', 'Missing param secret_key'); |
|
|
|
} |
|
|
|
if (empty($param['play_url'])) { |
|
|
|
return $this->toData('1', 'Missing param play_url'); |
|
|
|
} |
|
|
|
// 检查是否存在数据 |
|
|
|
$ckInfo = AwsIvsModel::where('id', $param['id'])->find(); |
|
|
|
if (empty($ckInfo)) { |
|
|
|
return $this->toData('1', '编辑的数据不存在'); |
|
|
|
} |
|
|
|
$ckInfo->title = $param['title']; |
|
|
|
$ckInfo->anchor_name = $param['anchor_name']; |
|
|
|
$ckInfo->avatar = $param['avatar']; |
|
|
|
$ckInfo->desc = $param['desc']; |
|
|
|
$ckInfo->push_url = $param['push_url']; |
|
|
|
$ckInfo->secret_key = $param['secret_key']; |
|
|
|
$ckInfo->play_url = $param['play_url']; |
|
|
|
$ckInfo->save(); |
|
|
|
return $this->toData('1', 'Successful'); |
|
|
|
} catch (\Exception $exception) { |
|
|
|
return $this->toData('1', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]); |
|
|
|
} |
|
|
|
} |
|
|
|
} |