增加 工单通知选项

This commit is contained in:
iVampireSP.com 2023-01-02 20:25:38 +08:00
parent d9b648d2e4
commit f6351b8802
No known key found for this signature in database
GPG Key ID: 2F7B001CA27A8132
6 changed files with 122 additions and 72 deletions

View File

@ -66,16 +66,6 @@ public function store(Request $request): RedirectResponse
}
private function rules(): array
{
return [
'id' => 'required|string|max:255',
'name' => 'required|string|max:255',
'url' => 'required|url',
'status' => 'required|string|in:up,down,maintenance',
];
}
/**
* Display the specified resource.
*
@ -116,25 +106,22 @@ public function edit(Module $module): View
*/
public function update(Request $request, Module $module): RedirectResponse
{
//
$request->validate($this->rules());
if ($request->reset_api_token) {
if ($request->input('reset_api_token')) {
$module->api_token = Str::random(60);
}
$module->id = $request->id;
$module->name = $request->name;
$module->url = $request->url;
$module->status = $request->status;
$module->id = $request->input('id');
$module->name = $request->input('name');
$module->url = $request->input('url');
$module->status = $request->input('status');
$module->save();
$text = '模块更新成功';
if ($request->reset_api_token) {
if ($request->input('reset_api_token')) {
$text .= ', API Token 为 ' . $module->api_token . '。';
} else {
$text .= '。';
@ -152,7 +139,6 @@ public function update(Request $request, Module $module): RedirectResponse
*/
public function destroy(Module $module): RedirectResponse
{
//
$module->delete();
return redirect()->route('admin.modules.index')->with('success', '模块已删除。');
@ -200,4 +186,13 @@ public function fast_login(Module $module): View|RedirectResponse
}
}
private function rules(): array
{
return [
'id' => 'required|string|max:255',
'name' => 'required|string|max:255',
'url' => 'required|url',
'status' => 'required|string|in:up,down,maintenance',
];
}
}

View File

@ -54,8 +54,6 @@ public function show(WorkOrder $workOrder): View
*/
public function edit(WorkOrder $workOrder): View
{
//
return view('admin.work-orders.edit', compact('workOrder'));
}
@ -69,17 +67,17 @@ public function edit(WorkOrder $workOrder): View
*/
public function update(Request $request, WorkOrder $workOrder): RedirectResponse
{
//
$request->validate([
'status' => 'required|string|in:open,closed,read,user_read,replied,user_replied,on_hold,in_progress',
'notify' => 'nullable|boolean',
]);
$workOrder->update([
'status' => $request->status
'status' => $request->input('status'),
'notify' => $request->input('notify'),
]);
return back()->with('success', '工单更新成功');
return back()->with('success', '工单更新成功');
}
/**

View File

@ -82,52 +82,12 @@ class WorkOrder extends Model
'user_id',
'module_id',
'status',
'notify'
];
protected static function boot()
{
parent::boot();
static::creating(function (self $model) {
// 生成 uuid
$model->uuid = Str::uuid()->toString();
if ($model->host_id) {
$model->load(['host']);
$model->module_id = $model->host->module_id;
}
if (auth('sanctum')->check()) {
$model->user_id = auth()->id();
if ($model->host_id) {
if (!$model->user_id == $model->host->user_id) {
throw new CommonException('user_id not match host user_id');
}
}
} else {
if (!$model->user_id) {
throw new CommonException('user_id is required');
}
}
if ($model->host_id) {
$model->host->load('module');
$module = $model->host->module;
if ($module === null) {
$model->status = 'open';
} else {
$model->status = 'pending';
}
}
});
// updated
static::updated(function ($model) {
dispatch(new WorkOrderJob($model, 'put'));
});
}
protected $casts = [
'notify' => 'boolean'
];
public function scopeThisModule($query)
{
@ -187,4 +147,49 @@ public function safeDelete(): bool
return true;
}
protected static function boot()
{
parent::boot();
static::creating(function (self $model) {
// 生成 uuid
$model->uuid = Str::uuid()->toString();
if ($model->host_id) {
$model->load(['host']);
$model->module_id = $model->host->module_id;
}
if (auth('sanctum')->check()) {
$model->user_id = auth()->id();
if ($model->host_id) {
if (!$model->user_id == $model->host->user_id) {
throw new CommonException('user_id not match host user_id');
}
}
} else {
if (!$model->user_id) {
throw new CommonException('user_id is required');
}
}
if ($model->host_id) {
$model->host->load('module');
$module = $model->host->module;
if ($module === null) {
$model->status = 'open';
} else {
$model->status = 'pending';
}
}
});
// updated
static::updated(function ($model) {
dispatch(new WorkOrderJob($model, 'put'));
});
}
}

View File

@ -50,6 +50,11 @@ public function toGroup($notifiable)
$workOrder->load(['module', 'user']);
$module = $workOrder->module;
if (!$workOrder->notify) {
return;
}
} else if ($notifiable instanceof Reply) {
$view = 'notifications.work_order.reply';
@ -61,6 +66,10 @@ public function toGroup($notifiable)
$reply = $workOrder;
$workOrder = $workOrder->workOrder;
if (!$workOrder->notify) {
return;
}
$module = $workOrder->module;
} else {
return;

View File

@ -0,0 +1,32 @@
<?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(): void
{
Schema::table('work_orders', function (Blueprint $table) {
$table->boolean('notify')->default(true)->comment('是否通知')->after('status');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down(): void
{
Schema::table('work_orders', function (Blueprint $table) {
$table->dropColumn('notify');
});
}
};

View File

@ -20,14 +20,25 @@
<select class="form-control" id="status" name="status">
<option value="open" {{ $workOrder->status == 'open' ? 'selected' : '' }}>已开启</option>
<option value="closed" {{ $workOrder->status == 'closed' ? 'selected' : '' }}>关闭</option>
<option value="user_read" {{ $workOrder->status == 'user_read' ? 'selected' : '' }}>用户已读</option>
<option value="user_read" {{ $workOrder->status == 'user_read' ? 'selected' : '' }}>用户已读
</option>
<option value="user_replied" {{ $workOrder->status == 'user_replied' ? 'selected' : '' }}>用户已回复
</option>
<option value="replied" {{ $workOrder->status == 'replied' ? 'selected' : '' }}>已回复</option>
<option value="read" {{ $workOrder->status == 'read' ? 'selected' : '' }}>已读</option>
<option value="in_progress" {{ $workOrder->status == 'in_progress' ? 'selected' : '' }}>处理中</option>
<option value="in_progress" {{ $workOrder->status == 'in_progress' ? 'selected' : '' }}>处理中
</option>
</select>
</div>
{{-- 启用通知 --}}
<div class="form-group">
<label for="notify" class="col-sm-2 col-form-label">通知</label>
<select class="form-control" id="notify" name="notify">
<option value="1"></option>
<option value="0" @if($workOrder->notify === 0) selected @endif></option>
</select>
</div>