|
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Mobile;
|
|
|
|
|
|
|
|
|
|
|
|
use App\Helpers\ResponseCode;
|
|
|
|
|
|
use App\Models\Admin;
|
|
|
|
|
|
use App\Models\Department;
|
|
|
|
|
|
use App\Models\Study;
|
|
|
|
|
|
use App\Models\StudyLog;
|
|
|
|
|
|
use App\Models\Visit;
|
|
|
|
|
|
use App\Models\VisitArea;
|
|
|
|
|
|
use App\Models\VisitAudit;
|
|
|
|
|
|
use App\Models\VisitLog;
|
|
|
|
|
|
use App\Models\VisitTime;
|
|
|
|
|
|
use Illuminate\Support\Carbon;
|
|
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
|
|
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="accompany_id", in="query", @OA\Schema(type="string"), required=false, description="陪同人id"),
|
|
|
|
|
|
* @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必填',
|
|
|
|
|
|
'accept_admin_id.required' => '接待人必填'
|
|
|
|
|
|
];
|
|
|
|
|
|
$validator = Validator::make($all, [
|
|
|
|
|
|
'name' => 'required',
|
|
|
|
|
|
'visit_area_id' => 'required',
|
|
|
|
|
|
'accept_admin_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'])) {
|
|
|
|
|
|
// 被访问做第一级审核
|
|
|
|
|
|
VisitAudit::create([
|
|
|
|
|
|
'visit_id' => $model->id,
|
|
|
|
|
|
'audit_admin_id' => $all['accept_admin_id'],
|
|
|
|
|
|
'status' => 0,
|
|
|
|
|
|
'level' => 0
|
|
|
|
|
|
]);
|
|
|
|
|
|
// 其他按设置审核
|
|
|
|
|
|
$audit_admin = collect($area->audit_admin)->sortBy('level');
|
|
|
|
|
|
foreach ($audit_admin as $key => $item) {
|
|
|
|
|
|
if (empty($item['admin_id'])) {
|
|
|
|
|
|
// 上级审核
|
|
|
|
|
|
$admin = Admin::find($all['accept_admin_id']);
|
|
|
|
|
|
if (empty($admin->department_id)) {
|
|
|
|
|
|
return $this->fail([ResponseCode::ERROR_BUSINESS, '接待人部门不存在']);
|
|
|
|
|
|
}
|
|
|
|
|
|
$department = Department::find($admin->department_id);
|
|
|
|
|
|
if (empty($department->manager_id)) {
|
|
|
|
|
|
return $this->fail([ResponseCode::ERROR_BUSINESS, '接待人部门不存在负责人']);
|
|
|
|
|
|
}
|
|
|
|
|
|
$item['admin_id'] = $department->manager_id;
|
|
|
|
|
|
}
|
|
|
|
|
|
// 判断不能重复
|
|
|
|
|
|
if ($item['admin_id'] == $all['accept_admin_id']) {
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
VisitAudit::create([
|
|
|
|
|
|
'visit_id' => $model->id,
|
|
|
|
|
|
'audit_admin_id' => $item['admin_id'],
|
|
|
|
|
|
'status' => 0,
|
|
|
|
|
|
'level' => $item['level'] + 1
|
|
|
|
|
|
]);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
VisitLog::add('', $this->getUser(), $model->id, isset($all['id']) ? '更新拜访记录' : '新增拜访记录');
|
|
|
|
|
|
// 通知
|
|
|
|
|
|
$visitTime = VisitTime::find($all['visit_time_id']);
|
|
|
|
|
|
$acceptAdmin = Admin::find($all['accept_admin_id']);
|
|
|
|
|
|
$accpetDepartment = Department::find($all['accpet_department_id']);
|
|
|
|
|
|
$templateData = [
|
|
|
|
|
|
'date1' => [
|
|
|
|
|
|
'value' => $all['date']
|
|
|
|
|
|
],
|
|
|
|
|
|
'name2' => [
|
|
|
|
|
|
'value' => $all['name']
|
|
|
|
|
|
],
|
|
|
|
|
|
'phone_number3' => [
|
|
|
|
|
|
'value' => $all['mobile']
|
|
|
|
|
|
],
|
|
|
|
|
|
'name4' => [
|
|
|
|
|
|
'value' => $acceptAdmin->name ?? '',
|
|
|
|
|
|
],
|
|
|
|
|
|
'thing6' => [
|
|
|
|
|
|
'value' => $accpetDepartment->name ?? ''
|
|
|
|
|
|
],
|
|
|
|
|
|
];
|
|
|
|
|
|
$res = Visit::subMsg('DmzNRREPFdZrMWconNDdbj_ebtVPRWufq27kRQ25eNg', $this->getUser()->openid, $templateData, $model->id);
|
|
|
|
|
|
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);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @OA\Get(
|
|
|
|
|
|
* path="/api/mobile/visit/visit-area",
|
|
|
|
|
|
* tags={"小程序-拜访区域"},
|
|
|
|
|
|
* summary="列表",
|
|
|
|
|
|
* description="",
|
|
|
|
|
|
* @OA\Parameter(name="keyword", 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 visitArea()
|
|
|
|
|
|
{
|
|
|
|
|
|
$all = request()->all();
|
|
|
|
|
|
$list = VisitArea::where(function ($query) use ($all) {
|
|
|
|
|
|
if (isset($all['keyword'])) {
|
|
|
|
|
|
$query->where('name', 'like', '%' . $all['keyword'] . '%');
|
|
|
|
|
|
}
|
|
|
|
|
|
})->get();
|
|
|
|
|
|
return $this->success($list);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @OA\Get(
|
|
|
|
|
|
* path="/api/mobile/visit/visit-time",
|
|
|
|
|
|
* tags={"小程序-拜访时间段"},
|
|
|
|
|
|
* summary="列表",
|
|
|
|
|
|
* description="",
|
|
|
|
|
|
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
|
|
|
|
|
|
* @OA\Response(
|
|
|
|
|
|
* response="200",
|
|
|
|
|
|
* description="暂无"
|
|
|
|
|
|
* )
|
|
|
|
|
|
* )
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function visitTime()
|
|
|
|
|
|
{
|
|
|
|
|
|
$all = request()->all();
|
|
|
|
|
|
$list = VisitTime::where(function ($query) use ($all) {
|
|
|
|
|
|
|
|
|
|
|
|
})->get();
|
|
|
|
|
|
return $this->success($list);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @OA\Get(
|
|
|
|
|
|
* path="/api/mobile/visit/ask-log",
|
|
|
|
|
|
* tags={"小程序-学习"},
|
|
|
|
|
|
* summary="获取学习记录",
|
|
|
|
|
|
* description="",
|
|
|
|
|
|
* @OA\Parameter(name="type", 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 askLog()
|
|
|
|
|
|
{
|
|
|
|
|
|
$type = request('type');
|
|
|
|
|
|
$log = StudyLog::where('type', $type)->where('user_id', $this->getUserId())->orderBy('id', 'desc')->first();
|
|
|
|
|
|
if (empty($log)) {
|
|
|
|
|
|
return $this->fail([ResponseCode::ERROR_BUSINESS, '未学习']);
|
|
|
|
|
|
}
|
|
|
|
|
|
$diff = Carbon::parse($log->created_at)->diffInDays(Carbon::now());
|
|
|
|
|
|
if ($diff > $log->expire_day) {
|
|
|
|
|
|
return $this->fail([ResponseCode::ERROR_BUSINESS, '学习过期']);
|
|
|
|
|
|
}
|
|
|
|
|
|
return $this->success("学习有效中");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @OA\Post(
|
|
|
|
|
|
* path="/api/mobile/visit/ask-save",
|
|
|
|
|
|
* tags={"小程序-学习"},
|
|
|
|
|
|
* summary="保存学习记录",
|
|
|
|
|
|
* description="",
|
|
|
|
|
|
* @OA\Parameter(name="content", in="query", @OA\Schema(type="string"), required=true, description="内容json"),
|
|
|
|
|
|
* @OA\Parameter(name="ask", in="query", @OA\Schema(type="string"), required=true, description="问题json"),
|
|
|
|
|
|
* @OA\Parameter(name="expire_day", in="query", @OA\Schema(type="string"), required=true, description="有效天数"),
|
|
|
|
|
|
* @OA\Parameter(name="type", in="query", @OA\Schema(type="string"), required=true, description="类型 init型"),
|
|
|
|
|
|
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
|
|
|
|
|
|
* @OA\Response(
|
|
|
|
|
|
* response="200",
|
|
|
|
|
|
* description="暂无"
|
|
|
|
|
|
* )
|
|
|
|
|
|
* )
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function askSave()
|
|
|
|
|
|
{
|
|
|
|
|
|
$all = request()->all();
|
|
|
|
|
|
$model = new StudyLog();
|
|
|
|
|
|
$all['user_id'] = $this->getUserId();
|
|
|
|
|
|
$model->fill($all);
|
|
|
|
|
|
$res = $model->save();
|
|
|
|
|
|
return $this->success($model);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|