master
parent
109b760b71
commit
4e91817e14
@ -0,0 +1,131 @@
|
||||
<?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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class GateLog extends SoftDeletesModel
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
|
||||
public static function add($admin_id, $code = '', $remark = '')
|
||||
{
|
||||
return self::create([
|
||||
'admin_id' => $admin_id,
|
||||
'code' => $code,
|
||||
'remark' => $remark
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,12 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class Study extends SoftDeletesModel
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
protected $guarded = ['id'];
|
||||
|
||||
protected $casts = [
|
||||
'file' => 'array'
|
||||
];
|
||||
protected $appends = ['file_detail'];
|
||||
|
||||
public function asks()
|
||||
{
|
||||
return $this->hasMany(StudyAsk::class, 'study_id', 'id');
|
||||
}
|
||||
|
||||
public function asks(){
|
||||
return $this->hasMany(StudyAsk::class,'study_id','id');
|
||||
}
|
||||
public function getFileDetailAttribute()
|
||||
{
|
||||
if (empty($this->file)) {
|
||||
return [];
|
||||
}
|
||||
return Upload::whereIn('id', $this->file)->get();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,8 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class VisitArea extends SoftDeletesModel
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
protected $guarded = ['id'];
|
||||
|
||||
}
|
||||
protected $casts = [
|
||||
'audit_admin' => 'array'
|
||||
];
|
||||
}
|
||||
|
||||
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration {
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('visits', function (Blueprint $table) {
|
||||
$table->integer('user_id')->comment('用户id')->nullable();
|
||||
$table->string('code')->comment('编号')->nullable();
|
||||
$table->string('accept_admin_sign')->comment('被访人签字图片id')->nullable();
|
||||
$table->json('file')->nullable()->comment('附件id数组');
|
||||
$table->string('accept_goods_admin_id')->comment('收货人id')->nullable();
|
||||
$table->date('work_start_time')->comment('施工开始时间')->nullable();
|
||||
$table->date('work_end_time')->comment('施工结束时间')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('visits', function (Blueprint $table) {
|
||||
$table->dropColumn('user_id');
|
||||
$table->dropColumn('code');
|
||||
$table->dropColumn('accept_admin_sign');
|
||||
$table->dropColumn('file');
|
||||
$table->dropColumn('accept_goods_admin_id');
|
||||
$table->dropColumn('work_start_time');
|
||||
$table->dropColumn('work_end_time');
|
||||
});
|
||||
}
|
||||
};
|
||||
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration {
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('studies', function (Blueprint $table) {
|
||||
$table->string('type')->default('1')->comment('类型1访客2施工3车辆')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('studies', function (Blueprint $table) {
|
||||
$table->dropColumn('type');
|
||||
});
|
||||
}
|
||||
};
|
||||
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateGateLogsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('gate_logs', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->integer('admin_id')->nullable();
|
||||
$table->string('code', 50)->nullable();
|
||||
$table->string('remark')->nullable();
|
||||
$table->dateTime('created_at')->nullable();
|
||||
$table->dateTime('updated_at')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('gate_logs');
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('blacklists', function (Blueprint $table) {
|
||||
$table->string('remark')->nullable()->comment('备注');
|
||||
$table->string('company_name')->nullable()->comment('单位名字');
|
||||
$table->json('file')->nullable()->comment('附件');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('blacklists', function (Blueprint $table) {
|
||||
$table->dropColumn('remark');
|
||||
$table->dropColumn('company_name');
|
||||
$table->dropColumn('file');
|
||||
});
|
||||
}
|
||||
};
|
||||
Loading…
Reference in new issue