增加 工单角色

This commit is contained in:
iVampireSP.com 2023-01-01 21:36:06 +08:00
parent e4b8eeb312
commit 3a19269ab6
No known key found for this signature in database
GPG Key ID: 2F7B001CA27A8132
3 changed files with 54 additions and 9 deletions

View File

@ -70,6 +70,7 @@ class Reply extends Model
'name', 'name',
'module_id', 'module_id',
'is_pending', 'is_pending',
'role'
]; ];
protected static function boot() protected static function boot()
@ -88,19 +89,27 @@ protected static function boot()
throw_if($model->workOrder->isFailure(), CommonException::class, '工单还没有就绪。'); throw_if($model->workOrder->isFailure(), CommonException::class, '工单还没有就绪。');
// change work order status // change work order status
if (auth('sanctum')->check()) { if (auth('sanctum')->check()) {
$model->user_id = auth()->id(); $model->user_id = auth('sanctum')->id();
$model->role = 'user';
$model->workOrder->status = 'user_replied'; $model->workOrder->status = 'user_replied';
}
if (auth('module')->check() || auth('admin')->check()) { } else if (auth('module')->check()) {
$model->user_id = null; $model->user_id = null;
$model->role = 'module';
$model->workOrder->status = 'replied'; $model->workOrder->status = 'replied';
broadcast(new UserEvent($model->user_id, 'work-order.replied', $model->workOrder)); broadcast(new UserEvent($model->user_id, 'work-order.replied', $model->workOrder));
} else if (auth('admin')->check()) {
$model->role = 'admin';
} else {
$model->role = 'guest';
} }
$model->workOrder->save(); $model->workOrder->save();
}); });

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_order_replies', function (Blueprint $table) {
$table->string('role')->default('user')->comment('回复角色')->after('module_id');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down(): void
{
Schema::table('work_order_replies', function (Blueprint $table) {
$table->dropColumn('role');
});
}
};

View File

@ -15,17 +15,21 @@
@foreach($replies as $reply) @foreach($replies as $reply)
<div class="card border-light mb-3 shadow"> <div class="card border-light mb-3 shadow">
<div class="card-header d-flex w-100 justify-content-between"> <div class="card-header d-flex w-100 justify-content-between">
@if ($reply->user_id) @if ($reply->role === 'user')
<a href="{{ route('admin.users.edit', $reply->user) }}">{{ $workOrder->user->name }}</a> @if ($reply->user_id)
@elseif($reply->module_id) <a href="{{ route('admin.users.edit', $reply->user) }}">{{ $workOrder->user->name }}</a>
@else
{{ $reply->name }}
@endif
@elseif ($reply->role === 'admin')
<span class="text-primary">{{ config('app.display_name') }}</span>
@elseif ($reply->role === 'module')
<a href="{{ route('admin.modules.edit', $workOrder->module_id) }}">{{ $workOrder->module->name }} <a href="{{ route('admin.modules.edit', $workOrder->module_id) }}">{{ $workOrder->module->name }}
@if ($reply->name) @if ($reply->name)
{{ $reply->name }} {{ $reply->name }}
@endif @endif
</a> </a>
@elseif ($reply->name === null && $reply->user_id === null && $reply->module_id === null) @elseif ($reply->role === 'guest')
<span class="text-primary">{{ config('app.display_name') }}</span>
@else
{{ $reply->name }} {{ $reply->name }}
@endif @endif