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.

203 lines
6.3 KiB

<?php
namespace App\Repositories;
use App\Models\AppointmentConfig;
use App\Models\ThirdAppointmentLog;
/**
* 会议第三方
*/
class MeetRepository
{
public $baseUrl;
public $account;
public $password;
public $companyId;
public function __construct()
{
$this->baseUrl = 'https://www.aiyuyue.cn';
$this->account = '13771971407';
$this->password = '123456';
$this->companyId = 'b6fbd3f82db94dd5bb7f8e5768540528';
}
/**
* 获取公司 Id
* @return false|mixed
*/
public function login()
{
$url = $this->baseUrl . '/services/showInfo.ashx';
$header[] = 'Content-Type: application/json';
$params = [
'method' => 'login',
'account' => $this->account,
'password' => $this->password
];
try {
$result = httpCurl($url, 'GET', $params, $header);
$result = json_decode($result, true);
if ($result['success']) {
return $result['companyId'];
} else {
return false;
}
} catch (\Exception $e) {
return false;
}
}
/**
* 会议室列表
*/
public function index()
{
$url = $this->baseUrl . '/services/api/MeetingRoomService.aspx';
$header[] = 'Content-Type: application/json';
$params = [
'method' => 'find',
'account' => $this->account,
'password' => md5($this->password)
];
try {
$result = httpCurl($url, 'GET', $params, $header);
$result = json_decode($result, true);
if ($result['success']) {
// 更新下config配置
foreach ($result['data'] as $item) {
$where = ['value' => $item['id']];
$data = ['remark' => $item['name'], 'value' => $item['id'], 'room' => json_encode($item, JSON_UNESCAPED_UNICODE)];
AppointmentConfig::updateOrCreate($where, $data);
}
return $result['data'];
} else {
return false;
}
} catch (\Exception $e) {
return false;
}
}
/**
* 会议室预约
*/
public function appointment($model, $appointmentConfig, &$out)
{
$meetOther = json_decode($appointmentConfig->room, true);
$url = $this->baseUrl . '/services/api/BookingService.aspx';
$header[] = 'Content-Type: application/json';
$params = [
'account' => $this->account,
'password' => md5($this->password),
'roomName' => $appointmentConfig->name,
'roomCode' => $meetOther['code'],
'roomAddress' => $meetOther['address'],
'beginTime' => $model->start_time,
'endTime' => $model->end_time,
'speaker' => $model->name,
'subject' => empty($model->content) ? '预约会议室' : $model->content,
'booker' => "{$model->name};{$model->mobile};",
'attendance' => "{$model->name};{$model->mobile};",
'signUrl' => ''
];
$result = [];
$finally = 0;
try {
$resultJson = httpCurl($url, 'GET', $params, $header);
$out = $resultJson;
$result = json_decode($resultJson, true);
if ($result['success']) {
$finally = 1;
$meetIds = explode(',', $model->meet_id);
array_push($meetIds, $result['data']);
$meetIds = array_filter($meetIds);
$model->meet_id = implode(',', $meetIds);
$model->save();
ThirdAppointmentLog::add($model->id, 0, $model->user_id, $url, $params, $result, $finally, '会议室预约');
return true;
} else {
$out = $resultJson;
ThirdAppointmentLog::add($model->id, 0, $model->user_id, $url, $params, $result, $finally, '会议室预约');
return false;
}
} catch (\Exception $e) {
$out = $e->getMessage();
ThirdAppointmentLog::add($model->id, 0, $model->user_id, $url, $params, $result, $finally, '会议室预约');
return false;
}
}
/**
* 会议室删除
*/
public function cancelAppointment($model, $meetId, &$out)
{
if (empty($meetId)) return true;
$url = $this->baseUrl . '/services/api/BookingService.aspx';
$header[] = 'Content-Type: application/json';
$params = [
'account' => $this->account,
'password' => md5($this->password),
'method' => 'delete',
'id' => $meetId
];
$result = [];
$finally = 0;
try {
$resultJson = httpCurl($url, 'GET', $params, $header);
$out = $resultJson;
$result = json_decode($resultJson, true);
if ($result['success']) {
$finally = 1;
return true;
} else {
$out = $resultJson;
return false;
}
} catch (\Exception $e) {
$out = $e->getMessage();
return false;
} finally {
// 写日志
ThirdAppointmentLog::add($model->id, 0, $model->user_id, $url, $params, $result, $finally, '会议室预约取消');
}
}
/**
* 会议室信息
*/
public function meetingService($roomId, $startDate, $endDate, &$out)
{
$url = $this->baseUrl . '/services/api/MeetingService.aspx';
$header[] = 'Content-Type: application/json';
$params = [
'account' => $this->account,
'password' => md5($this->password),
'method' => 'find',
'roomId' => $roomId,
'begin' => $startDate,
'end' => $endDate,
];
try {
$resultJson = httpCurl($url, 'GET', $params, $header);
$out = $resultJson;
$result = json_decode($resultJson, true);
if ($result['success']) {
$out = $result['data'];
return true;
} else {
$out = $resultJson;
return false;
}
} catch (\Exception $e) {
$out = $e->getMessage();
return false;
}
}
}