改进 工单系统
支持 工单投递给平台
This commit is contained in:
parent
fecf0efd74
commit
7e36657e36
@ -29,16 +29,6 @@ public function store(Request $request): JsonResponse
|
||||
'host_id' => 'nullable|sometimes|exists:hosts,id',
|
||||
]);
|
||||
|
||||
// module_id 和 host_id 必须有个要填写
|
||||
if ($request->input('module_id') === null && $request->input('host_id') === null) {
|
||||
$message = 'module_id 和 host_id 必须有个要填写';
|
||||
|
||||
throw ValidationException::withMessages([
|
||||
'module_id' => $message,
|
||||
'host_id' => $message,
|
||||
]);
|
||||
}
|
||||
|
||||
$workOrder = (new WorkOrder)->create([
|
||||
'title' => $request->input('title'),
|
||||
'content' => $request->input('content'),
|
||||
@ -68,7 +58,7 @@ public function update(Request $request, WorkOrder $workOrder): JsonResponse
|
||||
|
||||
// 访客不能关闭
|
||||
if ($request->input('status') === 'closed' && !auth('sanctum')->check()) {
|
||||
return $this->error('访客不能修改工单状态。');
|
||||
return $this->forbidden('访客不能修改工单状态。');
|
||||
}
|
||||
|
||||
$workOrder->update($request->only('status'));
|
||||
|
@ -10,8 +10,6 @@
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
// use Illuminate\Contracts\Queue\ShouldBeUnique;
|
||||
|
||||
class PushWorkOrderJob implements ShouldQueue
|
||||
{
|
||||
use InteractsWithQueue, Queueable, SerializesModels;
|
||||
@ -33,9 +31,15 @@ public function __construct()
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
//
|
||||
(new WorkOrder)->whereIn('status', ['pending'])->with(['module', 'user', 'host', 'replies'])->chunk(100, function ($workOrders) {
|
||||
foreach ($workOrders as $workOrder) {
|
||||
if ($workOrder->isPlatform()) {
|
||||
if ($workOrder->status == 'pending') {
|
||||
$workOrder->update(['status' => 'open']);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($workOrder->host) {
|
||||
if ($workOrder->host->status === 'pending') {
|
||||
@ -43,7 +47,6 @@ public function handle(): void
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($workOrder->status === 'error') {
|
||||
continue;
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ class Reply implements ShouldQueue
|
||||
*/
|
||||
public function __construct(WorkOrderReply $reply, $type = 'post')
|
||||
{
|
||||
$this->reply = $reply;
|
||||
$this->reply = $reply->load(['workOrder', 'user']);
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
@ -33,7 +33,14 @@ public function __construct(WorkOrderReply $reply, $type = 'post')
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
$this->reply->load(['workOrder', 'user']);
|
||||
if ($this->reply->workOrder->isPlatform()) {
|
||||
if ($this->reply->is_pending) {
|
||||
$this->reply->update(['is_pending' => false]);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->reply->workOrder->load(['module']);
|
||||
|
||||
$reply = $this->reply->toArray();
|
||||
@ -52,6 +59,16 @@ public function handle(): void
|
||||
}
|
||||
|
||||
} else if ($this->type == 'patch') {
|
||||
|
||||
// 不更新 is_pending
|
||||
if ($this->reply->workOrder->isPlatform()) {
|
||||
$this->reply->update([
|
||||
'is_pending' => false
|
||||
]);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->reply->workOrder->module->http()->patch('work-orders/' . $this->reply->workOrder->id . '/replies/' . $this->reply->id, $reply);
|
||||
} else if ($this->type == 'delete') {
|
||||
$response = $this->reply->workOrder->module->http()->delete('work-orders/' . $this->reply->workOrder->id . '/replies/' . $this->reply->id);
|
||||
|
@ -24,7 +24,7 @@ class WorkOrder implements ShouldQueue
|
||||
*/
|
||||
public function __construct(WorkOrderModel $workOrder, $type = 'post')
|
||||
{
|
||||
$this->workOrder = $workOrder;
|
||||
$this->workOrder = $workOrder->load(['module']);
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
@ -35,7 +35,10 @@ public function __construct(WorkOrderModel $workOrder, $type = 'post')
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
$this->workOrder->load(['module']);
|
||||
if ($this->workOrder->isPlatform()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if ($this->type == 'post') {
|
||||
$response = $this->workOrder->module->http()->post('work-orders', $this->workOrder->toArray());
|
||||
|
@ -34,7 +34,7 @@ protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
static::creating(function (self $model) {
|
||||
$model->is_pending = 1;
|
||||
$model->is_pending = false;
|
||||
|
||||
// load work order
|
||||
$model->load(['workOrder']);
|
||||
@ -70,6 +70,10 @@ protected static function boot()
|
||||
|
||||
$model->workOrder->save();
|
||||
|
||||
if ($model->workOrder->isPlatform()) {
|
||||
$model->is_pending = false;
|
||||
}
|
||||
|
||||
$model->ip = request()->ip();
|
||||
});
|
||||
|
||||
|
@ -85,7 +85,7 @@ protected static function boot()
|
||||
static::updated(function (self $model) {
|
||||
dispatch(new WorkOrderJob($model, 'put'));
|
||||
|
||||
if ($model->notify) {
|
||||
if ($model->notify && $model->isDirty('status')) {
|
||||
$model->notify(new WorkOrderNotification($model));
|
||||
}
|
||||
});
|
||||
@ -136,6 +136,11 @@ public function isClosed(): bool
|
||||
return $this->status === 'closed';
|
||||
}
|
||||
|
||||
public function isPlatform(): bool
|
||||
{
|
||||
return $this->module_id === null && $this->host_id === null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws CommonException
|
||||
*/
|
||||
|
@ -73,11 +73,7 @@ public function toArray(WorkOrderModel $workOrder): array
|
||||
{
|
||||
$array = $workOrder->toArray();
|
||||
|
||||
$array['event'] = 'WorkOrder.updated';
|
||||
|
||||
if ($workOrder->status === 'replied') {
|
||||
$array['event'] = 'WorkOrder.replied';
|
||||
}
|
||||
$array['event'] = 'work-order.' . $workOrder->status;
|
||||
|
||||
return $array;
|
||||
}
|
||||
@ -86,12 +82,16 @@ public function toWeCom(WorkOrderModel $workOrder): false|array
|
||||
{
|
||||
$workOrder->load(['module', 'user']);
|
||||
|
||||
$module = $workOrder->module;
|
||||
$module = null;
|
||||
if ($workOrder->module) {
|
||||
$module = $workOrder->module;
|
||||
|
||||
// 取消隐藏字段
|
||||
$module->makeVisible(['wecom_key']);
|
||||
// 取消隐藏字段
|
||||
$module->makeVisible(['wecom_key']);
|
||||
|
||||
if ($module->wecom_key == null) {
|
||||
}
|
||||
|
||||
if ($module?->wecom_key == null) {
|
||||
$wecom_key = config('settings.wecom.robot_hook.default');
|
||||
} else {
|
||||
$wecom_key = $module->wecom_key;
|
||||
|
@ -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->string('module_id')->nullable()->change();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('work_orders', function (Blueprint $table) {
|
||||
$table->string('module_id')->nullable(false)->change();
|
||||
});
|
||||
}
|
||||
};
|
@ -30,11 +30,15 @@
|
||||
</a>
|
||||
</td>
|
||||
<td>
|
||||
<a
|
||||
href="{{ route('admin.modules.show', $workOrder->module_id) }}"
|
||||
class="module_name"
|
||||
module="{{ $workOrder->module_id }}">{{ $workOrder->module_id }}
|
||||
</a>
|
||||
@if ($workOrder->module_id)
|
||||
<a
|
||||
href="{{ route('admin.modules.show', $workOrder->module_id) }}"
|
||||
class="module_name"
|
||||
module="{{ $workOrder->module_id }}">{{ $workOrder->module_id }}
|
||||
</a>
|
||||
@else
|
||||
{{ config('app.display_name') }}
|
||||
@endif
|
||||
</td>
|
||||
<td>
|
||||
@if ($workOrder->host_id)
|
||||
|
@ -4,63 +4,77 @@
|
||||
|
||||
@switch ($data->status)
|
||||
@case('pending')
|
||||
@php
|
||||
$title = '工单挂起';
|
||||
@endphp
|
||||
@break
|
||||
@php
|
||||
$title = '工单挂起';
|
||||
@endphp
|
||||
@break
|
||||
|
||||
@case('open')
|
||||
@php
|
||||
$title = '工单投递成功,并且已开启';
|
||||
@endphp
|
||||
@break
|
||||
@php
|
||||
$title = '工单投递成功,并且已开启';
|
||||
@endphp
|
||||
@break
|
||||
|
||||
@case('user_replied')
|
||||
@php
|
||||
$title = '用户已回复';
|
||||
@endphp
|
||||
@break
|
||||
@php
|
||||
$title = '用户已回复';
|
||||
@endphp
|
||||
@break
|
||||
|
||||
@case('closed')
|
||||
@php
|
||||
$title = '已结单';
|
||||
@endphp
|
||||
@break
|
||||
@php
|
||||
$title = '已结单';
|
||||
@endphp
|
||||
@break
|
||||
|
||||
@case('replied')
|
||||
@php
|
||||
$title = '工作人员已回复';
|
||||
@endphp
|
||||
@break
|
||||
@php
|
||||
$title = '工作人员已回复';
|
||||
@endphp
|
||||
@break
|
||||
|
||||
@case('on_hold')
|
||||
@php
|
||||
$title = '挂起';
|
||||
@endphp
|
||||
@break
|
||||
@php
|
||||
$title = '挂起';
|
||||
@endphp
|
||||
@break
|
||||
|
||||
@case('in_progress')
|
||||
@php
|
||||
$title = '正在处理中';
|
||||
@endphp
|
||||
@break
|
||||
@php
|
||||
$title = '正在处理中';
|
||||
@endphp
|
||||
@break
|
||||
|
||||
@case('error')
|
||||
@php
|
||||
$title = '投递失败';
|
||||
@endphp
|
||||
@break
|
||||
@php
|
||||
$title = '投递失败';
|
||||
@endphp
|
||||
@break
|
||||
|
||||
@case('read')
|
||||
@php
|
||||
$title = '工作人员已读';
|
||||
@endphp
|
||||
@break
|
||||
|
||||
@case('user_read')
|
||||
@php
|
||||
$title = '用户已读';
|
||||
@endphp
|
||||
@break
|
||||
|
||||
@default
|
||||
@php
|
||||
$title = '状态更新';
|
||||
@endphp
|
||||
@break
|
||||
@php
|
||||
$title = '状态更新';
|
||||
@endphp
|
||||
@break
|
||||
@endswitch
|
||||
|
||||
# 标题: {{ $title }}
|
||||
|
||||
# 模块: {{ $data->module->name }}
|
||||
@if ($data->module)
|
||||
# 模块: {{ $data->module->name }}
|
||||
@endif
|
||||
|
||||
## 客户 {{ $data->user->name }}
|
||||
##### 邮箱 {{ $data->user->email }}
|
||||
|
Loading…
Reference in New Issue
Block a user