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.
193 lines
5.8 KiB
193 lines
5.8 KiB
10 months ago
|
<?php
|
||
|
|
||
|
namespace app\api\controller\v1\school;
|
||
|
|
||
|
use app\Request;
|
||
|
use app\services\crud\SchoolServices; //学校
|
||
|
use app\services\crud\SchoolGradeServices; //年级
|
||
|
use app\services\crud\SchoolGradeClassServices; //班级
|
||
|
use app\services\crud\SchoolClassIpcServices; //班级与设备关联表
|
||
|
use app\services\user\IpcServices;
|
||
|
|
||
|
use crmeb\exceptions\AuthException;
|
||
|
|
||
|
class SchoolController
|
||
|
{
|
||
|
protected $services = NUll;
|
||
|
public function __construct(SchoolServices $services, Request $request)
|
||
|
{
|
||
|
$this->services = $services;
|
||
|
$user = $request->user()->toArray();
|
||
|
if ($user['is_ipc_view'] != 1) {
|
||
|
// return app('json')->fail('没有观看权限');
|
||
|
throw new AuthException('没有观看权限');
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 获取学校下的年级班级
|
||
|
*/
|
||
|
public function getGradeAndClass(Request $request)
|
||
|
{
|
||
|
$user = $request->user()->toArray();
|
||
|
$school_id = $user['school_id'];
|
||
|
$resData = [];
|
||
|
if ($user['group_id'] != 1) {
|
||
|
return app('json')->success($resData);
|
||
|
}
|
||
|
|
||
|
// 年级数据
|
||
|
$SchoolGradeServices = app()->make(SchoolGradeServices::class);
|
||
|
$gradeData = $SchoolGradeServices->selectSchoolGradeData($school_id);
|
||
|
// 班级数据
|
||
|
$SchoolGradeClassServices = app()->make(SchoolGradeClassServices::class);
|
||
|
$classData = $SchoolGradeClassServices->selectSchoolClass($school_id);
|
||
|
// 树状数据
|
||
|
$treeData = $this->getTreeData($gradeData, $classData);
|
||
|
// 返回数据
|
||
|
$resData['gradeData'] = $gradeData;
|
||
|
$resData['classData'] = $classData;
|
||
|
$resData['treeData'] = $treeData;
|
||
|
return app('json')->success($resData);
|
||
|
}
|
||
|
|
||
|
private function getTreeData($gradeData, $classData)
|
||
|
{
|
||
|
if (empty($gradeData)) {
|
||
|
return [];
|
||
|
}
|
||
|
if (empty($classData)) {
|
||
|
return $gradeData;
|
||
|
}
|
||
|
foreach ($gradeData as $key => $value) {
|
||
|
foreach ($classData as $val) {
|
||
|
if ($val['grade_id'] == $value['grade_id']) {
|
||
|
$gradeData[$key]['childen'][] = $val;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return $gradeData;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 家长端-宝贝在线
|
||
|
*/
|
||
|
public function parentBabyOnline(Request $request)
|
||
|
{
|
||
|
$user = $request->user()->toArray();
|
||
|
$class_id = $user['class_id'];
|
||
|
if ($user['group_id'] == 2 || $user['group_id'] == 3) {
|
||
|
$data = $this->getParentGradeAndClass($class_id);
|
||
|
return app('json')->success(['ipcList' => $data]);
|
||
|
}
|
||
|
return app('json')->fail(500060);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 获取设备列表
|
||
|
* @return array
|
||
|
*/
|
||
|
private function getParentGradeAndClass($class_id)
|
||
|
{
|
||
|
$SchoolGradeClassServices = app()->make(SchoolGradeClassServices::class);
|
||
|
$code = $SchoolGradeClassServices->selectClassCode($class_id);
|
||
|
if (empty($code)) {
|
||
|
return $code;
|
||
|
}
|
||
|
$IpcServices = app()->make(IpcServices::class);
|
||
|
$ipcList = $IpcServices->getDeviceId($code['class_code']);
|
||
|
$ipcList = empty($ipcList) ? $ipcList : $IpcServices->setTimeToTime($ipcList);
|
||
|
return $ipcList;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 老师端-宝贝在线
|
||
|
*/
|
||
|
public function teacherBabyOnline(Request $request)
|
||
|
{
|
||
|
$data = $request->getMore([
|
||
|
['classId', 0],
|
||
|
['gradeId', 0]
|
||
|
]);
|
||
|
$user = $request->user()->toArray();
|
||
|
$school_id = $user['school_id'];
|
||
|
|
||
|
if ($user['group_id'] != 1) {
|
||
|
return app('json')->fail(500060);
|
||
|
}
|
||
|
|
||
|
$ipcList = $classList = [];
|
||
|
|
||
|
$SchoolGradeClassServices = app()->make(SchoolGradeClassServices::class);
|
||
|
$classList = $SchoolGradeClassServices->getCrudListIndex([], $school_id, $data['gradeId']);
|
||
|
|
||
|
if ($data['classId'] > 0) {
|
||
|
$code = $SchoolGradeClassServices->selectClassCode($data['classId']);
|
||
|
if (!empty($code)) {
|
||
|
$IpcServices = app()->make(IpcServices::class);
|
||
|
$ipcList = $IpcServices->getDeviceId($code['class_code']);
|
||
|
$ipcList = empty($ipcList) ? $ipcList : $IpcServices->setTimeToTime($ipcList);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$resData = [
|
||
|
'ipcList' => $ipcList,
|
||
|
'classList' => $classList,
|
||
|
];
|
||
|
return app('json')->success($resData);
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* 获取设备录像列表
|
||
|
*/
|
||
|
public function QueryRecord(Request $request)
|
||
|
{
|
||
|
$data = $request->postMore([
|
||
|
['IotId', '']
|
||
|
]);
|
||
|
|
||
|
if (empty($data['IotId'])) {
|
||
|
return app('json')->fail(100100);
|
||
|
}
|
||
|
|
||
|
$IpcServices = app()->make(IpcServices::class);
|
||
|
$res = $IpcServices->QueryRecord($data['IotId']);
|
||
|
if ($res['success'] == true) {
|
||
|
$res = get_object_vars($res['data']);
|
||
|
|
||
|
$list = is_array($res['list']) ? $res['list'] : [];
|
||
|
|
||
|
foreach ($list as $value) {
|
||
|
$value->beginTime = substr($value->beginTime, 5);
|
||
|
$value->endTime = substr($value->endTime, 5);
|
||
|
}
|
||
|
|
||
|
return app('json')->success($list);
|
||
|
}
|
||
|
return app('json')->fail($res);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 获取录像文件播放地址
|
||
|
*/
|
||
|
public function QueryRecordUrlRequest(Request $request)
|
||
|
{
|
||
|
$data = $request->postMore([
|
||
|
['IotId', ''],
|
||
|
['fileName', '']
|
||
|
]);
|
||
|
|
||
|
if (empty($data['IotId']) || empty($data['fileName'])) {
|
||
|
return app('json')->fail(100100);
|
||
|
}
|
||
|
|
||
|
$IpcServices = app()->make(IpcServices::class);
|
||
|
$res = $IpcServices->QueryRecordUrlRequest($data['fileName'], $data['IotId']);
|
||
|
if ($res['success'] == true) {
|
||
|
return app('json')->success($res['data']);
|
||
|
}
|
||
|
return app('json')->fail($res);
|
||
|
}
|
||
|
}
|