|
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
|
|
|
|
|
|
|
|
use App\Http\Requests\VisitTimeRequest;
|
|
|
|
|
|
use App\Models\VisitTime;
|
|
|
|
|
|
use App\Helpers\ResponseCode;
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @OA\Tag(
|
|
|
|
|
|
* name="拜访时间管理",
|
|
|
|
|
|
* description="拜访时间相关接口"
|
|
|
|
|
|
* )
|
|
|
|
|
|
*/
|
|
|
|
|
|
class VisitTimeController extends BaseController
|
|
|
|
|
|
{
|
|
|
|
|
|
public function __construct()
|
|
|
|
|
|
{
|
|
|
|
|
|
parent::__construct(new VisitTime());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @OA\Get(
|
|
|
|
|
|
* path="/api/admin/visit-times/index",
|
|
|
|
|
|
* tags={"拜访时间管理"},
|
|
|
|
|
|
* summary="拜访时间列表",
|
|
|
|
|
|
* description="获取拜访时间列表",
|
|
|
|
|
|
* @OA\Parameter(name="is_export", in="query", @OA\Schema(type="string"), required=false, description="是否导出0否1是"),
|
|
|
|
|
|
* @OA\Parameter(name="export_fields", in="query", @OA\Schema(type="string"), required=false, description="需要导出的字段数组"),
|
|
|
|
|
|
* @OA\Parameter(name="filter", in="query", @OA\Schema(type="string"), required=false, description="查询条件。数组"),
|
|
|
|
|
|
* @OA\Parameter(name="show_relation", in="query", @OA\Schema(type="string"), required=false, description="需要输出的关联关系数组,填写输出指定数据"),
|
|
|
|
|
|
* @OA\Parameter(name="page_size", in="query", @OA\Schema(type="string"), required=false, description="每页显示的条数"),
|
|
|
|
|
|
* @OA\Parameter(name="page", in="query", @OA\Schema(type="string"), required=false, description="页码"),
|
|
|
|
|
|
* @OA\Parameter(name="sort_name", in="query", @OA\Schema(type="string"), required=false, description="排序字段名字"),
|
|
|
|
|
|
* @OA\Parameter(name="sort_type", in="query", @OA\Schema(type="string"), required=false, 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();
|
|
|
|
|
|
$filter = $all['filter'] ?? [];
|
|
|
|
|
|
$show_relation = $all['show_relation'] ?? [];
|
|
|
|
|
|
$page_size = $all['page_size'] ?? 10;
|
|
|
|
|
|
$page = $all['page'] ?? 1;
|
|
|
|
|
|
$sort_name = $all['sort_name'] ?? 'id';
|
|
|
|
|
|
$sort_type = $all['sort_type'] ?? 'desc';
|
|
|
|
|
|
|
|
|
|
|
|
$query = $this->model->query();
|
|
|
|
|
|
|
|
|
|
|
|
// 应用过滤条件
|
|
|
|
|
|
if (!empty($filter)) {
|
|
|
|
|
|
$query = $this->applyFilters($query, $filter);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 应用排序
|
|
|
|
|
|
$query->orderBy($sort_name, $sort_type);
|
|
|
|
|
|
|
|
|
|
|
|
// 加载关联关系
|
|
|
|
|
|
if (!empty($show_relation)) {
|
|
|
|
|
|
$query->with($show_relation);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 分页
|
|
|
|
|
|
$result = $query->paginate($page_size, ['*'], 'page', $page);
|
|
|
|
|
|
|
|
|
|
|
|
return $this->success($result);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @OA\Get(
|
|
|
|
|
|
* path="/api/admin/visit-times/show",
|
|
|
|
|
|
* tags={"拜访时间管理"},
|
|
|
|
|
|
* summary="拜访时间详情",
|
|
|
|
|
|
* description="获取指定的拜访时间详情",
|
|
|
|
|
|
* @OA\Parameter(name="id", in="query", @OA\Schema(type="string"), required=true, description="拜访时间ID"),
|
|
|
|
|
|
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
|
|
|
|
|
|
* @OA\Response(
|
|
|
|
|
|
* response="200",
|
|
|
|
|
|
* description="成功获取拜访时间详情"
|
|
|
|
|
|
* )
|
|
|
|
|
|
* )
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function show()
|
|
|
|
|
|
{
|
|
|
|
|
|
$all = request()->all();
|
|
|
|
|
|
$detail = $this->model->find($all['id']);
|
|
|
|
|
|
|
|
|
|
|
|
return $this->success($detail);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @OA\Post(
|
|
|
|
|
|
* path="/api/admin/visit-times/save",
|
|
|
|
|
|
* tags={"拜访时间管理"},
|
|
|
|
|
|
* summary="新增/更新拜访时间",
|
|
|
|
|
|
* description="创建或更新拜访时间",
|
|
|
|
|
|
* @OA\Parameter(name="id", in="query", @OA\Schema(type="string"), required=false, description="拜访时间ID,更新时必填"),
|
|
|
|
|
|
* @OA\Parameter(name="name", in="query", @OA\Schema(type="string"), required=true, description="时间段名称"),
|
|
|
|
|
|
* @OA\Parameter(name="start_time", in="query", @OA\Schema(type="string"), required=true, description="开始时间"),
|
|
|
|
|
|
* @OA\Parameter(name="end_time", in="query", @OA\Schema(type="string"), required=true, description="结束时间"),
|
|
|
|
|
|
* @OA\Parameter(name="max_visitors", in="query", @OA\Schema(type="string"), required=false, description="最大访客数"),
|
|
|
|
|
|
* @OA\Parameter(name="is_enabled", in="query", @OA\Schema(type="string"), required=false, description="是否启用"),
|
|
|
|
|
|
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
|
|
|
|
|
|
* @OA\Response(
|
|
|
|
|
|
* response="200",
|
|
|
|
|
|
* description="成功保存拜访时间"
|
|
|
|
|
|
* )
|
|
|
|
|
|
* )
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function save()
|
|
|
|
|
|
{
|
|
|
|
|
|
$request = new VisitTimeRequest();
|
|
|
|
|
|
$request->setContainer(app());
|
|
|
|
|
|
$request->setRedirector(app('redirect'));
|
|
|
|
|
|
|
|
|
|
|
|
DB::beginTransaction();
|
|
|
|
|
|
try {
|
|
|
|
|
|
$data = $request->validated();
|
|
|
|
|
|
$all = request()->all();
|
|
|
|
|
|
|
|
|
|
|
|
if (isset($all['id'])) {
|
|
|
|
|
|
// 更新
|
|
|
|
|
|
$visitTime = $this->model->find($all['id']);
|
|
|
|
|
|
if (!$visitTime) {
|
|
|
|
|
|
return $this->fail([ResponseCode::ERROR_BUSINESS, __('visit_time.not_found')]);
|
|
|
|
|
|
}
|
|
|
|
|
|
$visitTime->update($data);
|
|
|
|
|
|
$message = __('visit_time.updated_successfully');
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// 新增
|
|
|
|
|
|
$visitTime = $this->model->create($data);
|
|
|
|
|
|
$message = __('visit_time.created_successfully');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DB::commit();
|
|
|
|
|
|
return $this->success($visitTime);
|
|
|
|
|
|
} catch (\Exception $exception) {
|
|
|
|
|
|
DB::rollBack();
|
|
|
|
|
|
return $this->fail([$exception->getCode(), $exception->getMessage()]);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @OA\Get(
|
|
|
|
|
|
* path="/api/admin/visit-times/destroy",
|
|
|
|
|
|
* tags={"拜访时间管理"},
|
|
|
|
|
|
* summary="删除拜访时间",
|
|
|
|
|
|
* description="删除指定的拜访时间",
|
|
|
|
|
|
* @OA\Parameter(name="id", in="query", @OA\Schema(type="string"), required=true, description="拜访时间ID"),
|
|
|
|
|
|
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
|
|
|
|
|
|
* @OA\Response(
|
|
|
|
|
|
* response="200",
|
|
|
|
|
|
* description="成功删除拜访时间"
|
|
|
|
|
|
* )
|
|
|
|
|
|
* )
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function destroy()
|
|
|
|
|
|
{
|
|
|
|
|
|
$all = request()->all();
|
|
|
|
|
|
$visitTime = $this->model->find($all['id']);
|
|
|
|
|
|
if (!$visitTime) {
|
|
|
|
|
|
return $this->fail([ResponseCode::ERROR_BUSINESS, __('visit_time.not_found')]);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DB::beginTransaction();
|
|
|
|
|
|
try {
|
|
|
|
|
|
$visitTime->delete();
|
|
|
|
|
|
|
|
|
|
|
|
DB::commit();
|
|
|
|
|
|
return $this->success(__('visit_time.deleted_successfully'));
|
|
|
|
|
|
} catch (\Exception $exception) {
|
|
|
|
|
|
DB::rollBack();
|
|
|
|
|
|
return $this->fail([$exception->getCode(), $exception->getMessage()]);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 应用过滤条件
|
|
|
|
|
|
*/
|
|
|
|
|
|
private function applyFilters($query, $filter)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach ($filter as $key => $value) {
|
|
|
|
|
|
if (is_array($value)) {
|
|
|
|
|
|
$query->whereIn($key, $value);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$query->where($key, $value);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return $query;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|