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.
155 lines
5.8 KiB
155 lines
5.8 KiB
|
3 years ago
|
<?php
|
||
|
|
|
||
|
|
namespace App\Http\Controllers\Admin;
|
||
|
|
|
||
|
|
use App\Models\VisitAudit;
|
||
|
|
use Illuminate\Support\Facades\DB;
|
||
|
|
use Illuminate\Support\Facades\Validator;
|
||
|
|
use App\Helpers\ResponseCode;
|
||
|
|
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 拜访审核
|
||
|
|
*/
|
||
|
|
class VisitAuditController extends CommonController
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* @OA\Get(
|
||
|
|
* path="/api/admin/visit_audit/index",
|
||
|
|
* tags={"拜访审核"},
|
||
|
|
* summary="列表",
|
||
|
|
* 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();
|
||
|
|
$list = VisitAudit::with('visit')->where(function ($query) use ($all) {
|
||
|
|
$query->where('audit_admin_id', $this->getUserId());
|
||
|
|
|
||
|
|
})->orderBy($all['sort_name'] ?? 'id', $all['sort_type'] ?? 'desc')
|
||
|
|
->paginate($all['page_size'] ?? 20);
|
||
|
|
return $this->success($list);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @OA\Get(
|
||
|
|
* path="/api/admin/visit_audit/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();
|
||
|
|
$messages = [
|
||
|
|
'id.required' => 'Id必填',
|
||
|
|
];
|
||
|
|
$validator = Validator::make($all, [
|
||
|
|
'id' => 'required'
|
||
|
|
], $messages);
|
||
|
|
if ($validator->fails()) {
|
||
|
|
return $this->fail([ResponseCode::ERROR_PARAMETER, implode(',', $validator->errors()->all())]);
|
||
|
|
}
|
||
|
|
$detail = VisitAudit::find($all['id']);
|
||
|
|
return $this->success($detail);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @OA\Post(
|
||
|
|
* path="/api/admin/visit_audit/save",
|
||
|
|
* tags={"拜访审核"},
|
||
|
|
* summary="更新",
|
||
|
|
* description="",
|
||
|
|
* @OA\Parameter(name="id", in="query", @OA\Schema(type="int"), required=true, description="Id(存在更新,不存在新增)"),
|
||
|
|
* @OA\Parameter(name="admin_id", in="query", @OA\Schema(type="string"), required=false, description="不用填"),
|
||
|
|
* @OA\Parameter(name="department_id", in="query", @OA\Schema(type="string"), required=false, description="不用填"),
|
||
|
|
* @OA\Parameter(name="visit_id", in="query", @OA\Schema(type="string"), required=true, description="参观id"),
|
||
|
|
* @OA\Parameter(name="audit_admin_id", in="query", @OA\Schema(type="string"), required=true, description="审核人员id"),
|
||
|
|
* @OA\Parameter(name="status", in="query", @OA\Schema(type="string"), required=false, description="状态0待审核1通过2驳回"),
|
||
|
|
* @OA\Parameter(name="reason", 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()
|
||
|
|
{
|
||
|
|
$all = \request()->all();
|
||
|
|
$messages = [
|
||
|
|
'name.required' => '名称必填'
|
||
|
|
];
|
||
|
|
$validator = Validator::make($all, [
|
||
|
|
'name' => 'required'
|
||
|
|
], $messages);
|
||
|
|
if ($validator->fails()) {
|
||
|
|
return $this->fail([ResponseCode::ERROR_PARAMETER, implode(',', $validator->errors()->all())]);
|
||
|
|
}
|
||
|
|
DB::beginTransaction();
|
||
|
|
try {
|
||
|
|
if (isset($all['id'])) {
|
||
|
|
$model = VisitAudit::find($all['id']);
|
||
|
|
} else {
|
||
|
|
$model = new VisitAudit();
|
||
|
|
$all['admin_id'] = $this->getUserId();
|
||
|
|
$all['department_id'] = $this->getUser()->department_id;
|
||
|
|
}
|
||
|
|
$model->fill($all);
|
||
|
|
$model->save();
|
||
|
|
DB::commit();
|
||
|
|
return $this->success('更新成功');
|
||
|
|
} catch (\Exception $exception) {
|
||
|
|
DB::rollBack();
|
||
|
|
return $this->fail([$exception->getCode(), $exception->getMessage()]);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @OA\Get(
|
||
|
|
* path="/api/admin/visit_audit/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();
|
||
|
|
$messages = [
|
||
|
|
'id.required' => 'Id必填',
|
||
|
|
];
|
||
|
|
$validator = Validator::make($all, [
|
||
|
|
'id' => 'required'
|
||
|
|
], $messages);
|
||
|
|
if ($validator->fails()) {
|
||
|
|
return $this->fail([ResponseCode::ERROR_PARAMETER, implode(',', $validator->errors()->all())]);
|
||
|
|
}
|
||
|
|
VisitAudit::where('id', $all['id'])->delete();
|
||
|
|
return $this->success('删除成功');
|
||
|
|
}
|
||
|
|
}
|