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.
132 lines
6.6 KiB
132 lines
6.6 KiB
<?php
|
|
|
|
namespace App\Http\Controllers\Mobile;
|
|
|
|
use App\Helpers\ResponseCode;
|
|
use App\Models\Study;
|
|
use App\Models\Visit;
|
|
use App\Models\VisitArea;
|
|
use App\Models\VisitAudit;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
|
class VisitController extends CommonController
|
|
{
|
|
|
|
/**
|
|
* @OA\Post(
|
|
* path="/api/mobile/visit/visit-save",
|
|
* tags={"小程序-保存拜访"},
|
|
* summary="更新",
|
|
* description="",
|
|
* @OA\Parameter(name="id", in="query", @OA\Schema(type="int"), required=true, description="Id(存在更新,不存在新增)"),
|
|
* @OA\Parameter(name="date", in="query", @OA\Schema(type="string"), required=true, description="到访日期"),
|
|
* @OA\Parameter(name="visit_time_id", in="query", @OA\Schema(type="string"), required=false, description="时间段id"),
|
|
* @OA\Parameter(name="visit_area_id", in="query", @OA\Schema(type="string"), required=false, description="区域id"),
|
|
* @OA\Parameter(name="reason", in="query", @OA\Schema(type="string"), required=false, description="事由"),
|
|
* @OA\Parameter(name="remark", in="query", @OA\Schema(type="string"), required=false, description="备注"),
|
|
* @OA\Parameter(name="name", in="query", @OA\Schema(type="string"), required=false, description="名字"),
|
|
* @OA\Parameter(name="mobile", in="query", @OA\Schema(type="string"), required=false, description="电话"),
|
|
* @OA\Parameter(name="credent", in="query", @OA\Schema(type="string"), required=false, description="证件类型1身份证2护照"),
|
|
* @OA\Parameter(name="idcard", in="query", @OA\Schema(type="string"), required=false, description="证件号码"),
|
|
* @OA\Parameter(name="company_name", in="query", @OA\Schema(type="string"), required=false, description="单位名称"),
|
|
* @OA\Parameter(name="follw_people", in="query", @OA\Schema(type="string"), required=false, description="随访人员"),
|
|
* @OA\Parameter(name="cars", in="query", @OA\Schema(type="string"), required=false, description="到访车辆"),
|
|
* @OA\Parameter(name="start_date", in="query", @OA\Schema(type="string"), required=false, description="开始时间"),
|
|
* @OA\Parameter(name="end_date", in="query", @OA\Schema(type="string"), required=false, description="结束时间"),
|
|
* @OA\Parameter(name="accpet_department_id", in="query", @OA\Schema(type="string"), required=false, description="接待部门"),
|
|
* @OA\Parameter(name="accept_admin_id", in="query", @OA\Schema(type="string"), required=false, description="接待人员"),
|
|
* @OA\Parameter(name="plate", in="query", @OA\Schema(type="string"), required=false, description="车牌号"),
|
|
* @OA\Parameter(name="type", in="query", @OA\Schema(type="string"), required=false, description="类型1访客2施工3车辆"),
|
|
* @OA\Parameter(name="long_time", in="query", @OA\Schema(type="string"), required=false, description="是否长期0否1是"),
|
|
* @OA\Parameter(name="audit_status", in="query", @OA\Schema(type="string"), required=false, description="审核状态-1待学习0待审核1通过(待进厂)2驳回3已进厂4已离厂"),
|
|
* @OA\Parameter(name="file", in="query", @OA\Schema(type="string"), required=false, description="附件数组"),
|
|
* @OA\Parameter(name="accept_goods_admin_id", in="query", @OA\Schema(type="string"), required=false, description="收货人id"),
|
|
* @OA\Parameter(name="work_start_time", in="query", @OA\Schema(type="string"), required=false, description="施工开始时间"),
|
|
* @OA\Parameter(name="work_end_time", 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 visitSave()
|
|
{
|
|
$all = \request()->all();
|
|
$messages = [
|
|
'name.required' => '名称必填',
|
|
'visit_area_id.required' => '区域id必填'
|
|
];
|
|
$validator = Validator::make($all, [
|
|
'name' => 'required',
|
|
'visit_area_id' => 'required'
|
|
], $messages);
|
|
if ($validator->fails()) {
|
|
return $this->fail([ResponseCode::ERROR_PARAMETER, implode(',', $validator->errors()->all())]);
|
|
}
|
|
DB::beginTransaction();
|
|
try {
|
|
if (isset($all['id'])) {
|
|
$model = Visit::find($all['id']);
|
|
} else {
|
|
$model = new Visit();
|
|
$all['user_id'] = $this->getUserId();
|
|
$all['code'] = randStr(6, true);
|
|
}
|
|
$model->fill($all);
|
|
$model->save();
|
|
// 创建时候审核流程写入
|
|
$area = VisitArea::find($all['visit_area_id']);
|
|
if ($area->audit_admin && !isset($all['id'])) {
|
|
$audit_admin = collect($area->audit_admin)->sortBy('level');
|
|
foreach ($audit_admin as $item) {
|
|
VisitAudit::create([
|
|
'visit_id' => $model->id,
|
|
'audit_admin_id' => $item->admin_id,
|
|
'status' => 0,
|
|
'level' => $item->level
|
|
]);
|
|
}
|
|
}
|
|
DB::commit();
|
|
return $this->success('更新成功');
|
|
} catch (\Exception $exception) {
|
|
DB::rollBack();
|
|
return $this->fail([$exception->getCode(), $exception->getMessage()]);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @OA\Get(
|
|
* path="/api/mobile/visit/get-ask",
|
|
* tags={"小程序-获取学习内容"},
|
|
* summary="列表",
|
|
* description="",
|
|
* @OA\Parameter(name="type", in="query", @OA\Schema(type="string"), required=false, description="类型1访客2施工3车辆"),
|
|
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
|
|
* @OA\Response(
|
|
* response="200",
|
|
* description="暂无"
|
|
* )
|
|
* )
|
|
*/
|
|
public function getAsk()
|
|
{
|
|
$all = \request()->all();
|
|
$messages = [
|
|
'type.required' => '类型必填'
|
|
];
|
|
$validator = Validator::make($all, [
|
|
'type' => 'required'
|
|
], $messages);
|
|
if ($validator->fails()) {
|
|
return $this->fail([ResponseCode::ERROR_PARAMETER, implode(',', $validator->errors()->all())]);
|
|
}
|
|
$detail = Study::with('asks')->where('type', $all['type'])->first();
|
|
return $this->success($detail);
|
|
}
|
|
|
|
|
|
}
|