|
|
<?php
|
|
|
/**
|
|
|
* 预约
|
|
|
*/
|
|
|
|
|
|
namespace App\Http\Controllers\Mobile;
|
|
|
|
|
|
use App\Helpers\ResponseCode;
|
|
|
use App\Helpers\StarterResponseCode;
|
|
|
use App\Models\Appointment;
|
|
|
use App\Models\AppointmentConfig;
|
|
|
use App\Models\Config;
|
|
|
use App\Models\User;
|
|
|
use App\Repositories\DoorRepository;
|
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
|
|
|
class ScheduleController extends CommonController
|
|
|
{
|
|
|
/**
|
|
|
* @OA\Get(
|
|
|
* path="/api/mobile/schedule/index",
|
|
|
* tags={"小程序-预约管理"},
|
|
|
* summary="预约列表",
|
|
|
* description="",
|
|
|
* @OA\Parameter(name="status", in="query", @OA\Schema(type="string", format="date"), description="status"),
|
|
|
* @OA\Parameter(name="page", in="query", @OA\Schema(type="string", format="date"), description="页码"),
|
|
|
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
|
|
|
* @OA\Response(
|
|
|
* response="200",
|
|
|
* description=""
|
|
|
* )
|
|
|
* )
|
|
|
*/
|
|
|
public function index()
|
|
|
{
|
|
|
$all = \request()->all();
|
|
|
$list = Appointment::with('appointmentAccompany')
|
|
|
->where(function ($query) use ($all) {
|
|
|
if (isset($all['status'])) {
|
|
|
$query->where('status', $all['status']);
|
|
|
}
|
|
|
})->where('user_id', $this->getUserId())->orderBy('id', 'desc')
|
|
|
->paginate(10);
|
|
|
return $this->success($list);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* @OA\Get(
|
|
|
* path="/api/mobile/schedule/detail",
|
|
|
* tags={"小程序-预约管理"},
|
|
|
* summary="预约详情",
|
|
|
* description="",
|
|
|
* @OA\Parameter(name="id", in="query", @OA\Schema(type="string", format="date"), description="id"),
|
|
|
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
|
|
|
* @OA\Response(
|
|
|
* response="200",
|
|
|
* description=""
|
|
|
* )
|
|
|
* )
|
|
|
*/
|
|
|
public function detail()
|
|
|
{
|
|
|
$all = \request()->all();
|
|
|
$messages = [
|
|
|
'id.numeric' => 'id必填',
|
|
|
];
|
|
|
$validator = Validator::make($all, [
|
|
|
'id' => 'required|numeric',
|
|
|
], $messages);
|
|
|
if ($validator->fails()) {
|
|
|
return $this->fail([StarterResponseCode::START_ERROR_PARAMETER, implode(',', $validator->errors()->all())]);
|
|
|
}
|
|
|
$list = Appointment::with( 'appointmentAccompany')
|
|
|
->where('user_id', $this->getUserId())
|
|
|
->find($all['id']);
|
|
|
// 获取二维码
|
|
|
$doorRepository = new DoorRepository();
|
|
|
// 获取门禁二维码
|
|
|
$list['qrcode'] = $doorRepository->getEmpQrCode($list, $out);
|
|
|
return $this->success($list);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @OA\Get(
|
|
|
* path="/api/mobile/schedule/check",
|
|
|
* tags={"小程序-预约管理"},
|
|
|
* summary="检测是否可预约",
|
|
|
* description="",
|
|
|
* @OA\Parameter(name="site", in="query", @OA\Schema(type="integer"), description="预约地点id,从config接口获取"),
|
|
|
* @OA\Parameter(name="myself", in="query", @OA\Schema(type="integer"), description="是否检测自己的数据0否1是"),
|
|
|
* @OA\Parameter(name="start_time", in="query", @OA\Schema(type="string", format="date-time"), description="开始时间,例如:2023-01-01 11:11:11"),
|
|
|
* @OA\Parameter(name="end_time", in="query", @OA\Schema(type="string", format="date-time"), description="结束时间,例如:2023-01-01 11:11:11"),
|
|
|
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
|
|
|
* @OA\Response(
|
|
|
* response="200",
|
|
|
* description=""
|
|
|
* )
|
|
|
* )
|
|
|
*/
|
|
|
public function check()
|
|
|
{
|
|
|
$all = \request()->all();
|
|
|
$messages = [
|
|
|
'start_time.required' => '开始时间必填',
|
|
|
'end_time.required' => '结束时间必填',
|
|
|
'site.required' => '地点必填',
|
|
|
'myself.required' => '是否检测自己的数据必填',
|
|
|
];
|
|
|
$validator = Validator::make($all, [
|
|
|
'start_time' => 'required',
|
|
|
'end_time' => 'required',
|
|
|
'site' => 'required',
|
|
|
'myself' => 'required',
|
|
|
], $messages);
|
|
|
if ($validator->fails()) {
|
|
|
return $this->fail([ResponseCode::ERROR_PARAMETER, implode(',', $validator->errors()->all())]);
|
|
|
}
|
|
|
$userId = 0;
|
|
|
if ($all['myself'] == 1) $userId = $this->getUserId();
|
|
|
$appointment = Appointment::checkAppointment($all['start_time'], $all['end_time'], $all['site'], $userId);
|
|
|
if ($appointment) {
|
|
|
return $this->success($appointment);
|
|
|
}
|
|
|
return $this->success([]);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @OA\Post(
|
|
|
* path="/api/mobile/schedule/save",
|
|
|
* tags={"小程序-预约管理"},
|
|
|
* summary="创建更新预约",
|
|
|
* description="",
|
|
|
* @OA\Parameter(name="id", in="query", @OA\Schema(type="string", format="date"), description="存在更新,不存在新增"),
|
|
|
* @OA\Parameter(name="date", in="query", @OA\Schema(type="string", format="date"), description="预约日期"),
|
|
|
* @OA\Parameter(name="start_time", in="query", @OA\Schema(type="string", format="date-time"), description="开始时间,例如:2023-01-01 11:11:11"),
|
|
|
* @OA\Parameter(name="end_time", in="query", @OA\Schema(type="string", format="date-time"), description="结束时间,例如:2023-01-01 11:11:11"),
|
|
|
* @OA\Parameter(name="content", in="query", @OA\Schema(type="string"), description="预约事项"),
|
|
|
* @OA\Parameter(name="site", in="query", @OA\Schema(type="integer"), description="预约地点id,从config接口获取"),
|
|
|
* @OA\Parameter(name="plate", in="query", @OA\Schema(type="string"), description="车牌号。多个英文逗号分隔"),
|
|
|
* @OA\Parameter(name="accompany_total", in="query", @OA\Schema(type="integer"), description="陪同人数"),
|
|
|
* @OA\Parameter(name="status", in="query", @OA\Schema(type="integer"), description="状态 0未审核 1审核通过 2审核不通过3取消"),
|
|
|
* @OA\Parameter(name="reason", in="query", @OA\Schema(type="string"), description="审核不通过原因"),
|
|
|
* @OA\Parameter(name="accompany", in="query", @OA\Schema(type="string"), description="陪同人员,二维数组,包括:name,idcard,mobile"),
|
|
|
* @OA\Parameter(name="idcard", in="query", @OA\Schema(type="string"), required=true, description="身份证号码"),
|
|
|
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
|
|
|
* @OA\Response(
|
|
|
* response="200",
|
|
|
* description=""
|
|
|
* )
|
|
|
* )
|
|
|
*/
|
|
|
public function save()
|
|
|
{
|
|
|
$all = \request()->all();
|
|
|
$messages = [
|
|
|
'date.required' => '日期必填',
|
|
|
'start_time.required' => '开始时间必填',
|
|
|
'end_time.required' => '结束时间必填',
|
|
|
'content.required' => '预约事项必填',
|
|
|
'site.required' => '地点必填',
|
|
|
'accompany_total.required' => '陪同人数必填',
|
|
|
];
|
|
|
$validator = Validator::make($all, [
|
|
|
'date' => 'required',
|
|
|
'start_time' => 'required',
|
|
|
'end_time' => 'required',
|
|
|
'content' => 'required',
|
|
|
'site' => 'required',
|
|
|
'accompany_total' => 'required'
|
|
|
], $messages);
|
|
|
if ($validator->fails()) {
|
|
|
return $this->fail([ResponseCode::ERROR_PARAMETER, implode(',', $validator->errors()->all())]);
|
|
|
}
|
|
|
// 会议室同行人数不能超过上限
|
|
|
$appointmentConfig = AppointmentConfig::find($all['site']);
|
|
|
if (isset($all['id'])) {
|
|
|
$model = Appointment::find($all['id']);
|
|
|
} else {
|
|
|
$model = new Appointment();
|
|
|
// 检测是否有预约次数
|
|
|
if (empty(User::getHasAppointment($this->getUserId()))) {
|
|
|
return $this->fail([ResponseCode::ERROR_BUSINESS, '预约次数不足']);
|
|
|
}
|
|
|
if ($appointmentConfig->room) {
|
|
|
if ((count($all['accompany']) + 1) > $appointmentConfig->total) {
|
|
|
return $this->fail([ResponseCode::ERROR_BUSINESS, '会议室同行人数不能超过上限']);
|
|
|
}
|
|
|
}
|
|
|
$all['code'] = randStr(8);
|
|
|
}
|
|
|
// 判断游客只能预约特定项目
|
|
|
if (empty($this->getUser()->mobile) && $appointmentConfig->use_student == 1) {
|
|
|
return $this->fail([ResponseCode::ERROR_BUSINESS, '游客暂无法预约']);
|
|
|
}
|
|
|
// 预约时间必须是当前时间之后
|
|
|
if (time() >= strtotime($all['start_time'])) {
|
|
|
return $this->fail([ResponseCode::ERROR_BUSINESS, '预约开始时间必须晚于当前时间']);
|
|
|
}
|
|
|
// 判断空闲了会议室才能预约
|
|
|
if ($appointmentConfig->value) {
|
|
|
$appointment = Appointment::checkAppointment($all['start_time'], $all['end_time'], $all['site']);
|
|
|
if ($appointment) {
|
|
|
return $this->fail([ResponseCode::ERROR_BUSINESS, '会议室已被占用']);
|
|
|
}
|
|
|
}
|
|
|
$all['user_id'] = $this->getUserId();
|
|
|
$all['name'] = $this->getUser()->name;
|
|
|
$all['mobile'] = $this->getUser()->mobile;
|
|
|
$model->fill($all);
|
|
|
$model->save();
|
|
|
// 写入陪同人员
|
|
|
if (isset($all['accompany']) && !empty($all['accompany'])) {
|
|
|
$model->appointmentAccompany()->createMany($all['accompany']);
|
|
|
}
|
|
|
// 短信通知审核人
|
|
|
$smsSign = Config::getValueByKey('sms_sign');
|
|
|
$appointment_mobile = Config::getValueByKey('appointment_mobile');
|
|
|
$appointment_mobile = explode(',', $appointment_mobile);
|
|
|
$content = "{$smsSign}您收到一个新预约,【{$this->getUser()->name}】申请预约【{$appointmentConfig->name}】,预约时间:{$model->start_time}-{$model->end_time},请您登陆管理后台进行审核。";
|
|
|
foreach ($appointment_mobile as $mobile) {
|
|
|
ymSms($mobile, $content);
|
|
|
}
|
|
|
return $this->success($model);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @OA\Get(
|
|
|
* path="/api/mobile/schedule/cancel",
|
|
|
* tags={"小程序-预约管理"},
|
|
|
* summary="取消预约",
|
|
|
* description="",
|
|
|
* @OA\Parameter(name="id", in="query", @OA\Schema(type="string", format="date"), description="id"),
|
|
|
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
|
|
|
* @OA\Response(
|
|
|
* response="200",
|
|
|
* description=""
|
|
|
* )
|
|
|
* )
|
|
|
*/
|
|
|
public function cancel()
|
|
|
{
|
|
|
$all = \request()->all();
|
|
|
$messages = [
|
|
|
'id.numeric' => 'id必填',
|
|
|
];
|
|
|
$validator = Validator::make($all, [
|
|
|
'id' => 'required|numeric',
|
|
|
], $messages);
|
|
|
if ($validator->fails()) {
|
|
|
return $this->fail([StarterResponseCode::START_ERROR_PARAMETER, implode(',', $validator->errors()->all())]);
|
|
|
}
|
|
|
$detail = Appointment::where('user_id', $this->getUserId())->find($all['id']);
|
|
|
if ($detail) {
|
|
|
$detail->status = 3;
|
|
|
$detail->save();
|
|
|
// 取消预约
|
|
|
Appointment::sendCancelAppoin($detail);
|
|
|
}
|
|
|
return $this->success($detail);
|
|
|
}
|
|
|
|
|
|
}
|