解决 工单回复 以及 大量 SQL 查询
This commit is contained in:
parent
253947604c
commit
dee318ecab
@ -26,7 +26,6 @@ public function __construct(HostModel $host, $type = 'post')
|
|||||||
{
|
{
|
||||||
//
|
//
|
||||||
$this->host = $host;
|
$this->host = $host;
|
||||||
$this->host->load(['module']);
|
|
||||||
$this->type = $type;
|
$this->type = $type;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,7 +37,8 @@ public function __construct(HostModel $host, $type = 'post')
|
|||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
|
$this->host->load(['module']);
|
||||||
|
|
||||||
$http = Http::remote($this->host->module->api_token, $this->host->module->url);
|
$http = Http::remote($this->host->module->api_token, $this->host->module->url);
|
||||||
|
|
||||||
switch ($this->type) {
|
switch ($this->type) {
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
use Illuminate\Contracts\Queue\ShouldBeUnique;
|
use Illuminate\Contracts\Queue\ShouldBeUnique;
|
||||||
use App\Models\WorkOrder\Reply as WorkOrderReply;
|
use App\Models\WorkOrder\Reply as WorkOrderReply;
|
||||||
|
use Log;
|
||||||
|
|
||||||
class Reply implements ShouldQueue
|
class Reply implements ShouldQueue
|
||||||
{
|
{
|
||||||
@ -25,10 +26,6 @@ public function __construct(WorkOrderReply $reply)
|
|||||||
{
|
{
|
||||||
//
|
//
|
||||||
$this->reply = $reply;
|
$this->reply = $reply;
|
||||||
$this->reply->load(['workOrder']);
|
|
||||||
$this->reply->workOrder->load(['module']);
|
|
||||||
// $this->reply->user = $this->reply->workOrder->user;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -39,9 +36,14 @@ public function __construct(WorkOrderReply $reply)
|
|||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
|
$this->reply->load(['workOrder', 'user']);
|
||||||
|
$this->reply->workOrder->load(['module']);
|
||||||
|
|
||||||
$http = Http::remote($this->reply->workOrder->module->api_token, $this->reply->workOrder->module->url);
|
$http = Http::remote($this->reply->workOrder->module->api_token, $this->reply->workOrder->module->url);
|
||||||
|
|
||||||
$response = $http->post('work-orders/' . $this->reply->workOrder->id . '/replies', $this->reply->toArray());
|
$reply = $this->reply->toArray();
|
||||||
|
|
||||||
|
$response = $http->post('work-orders/' . $this->reply->workOrder->id . '/replies', $reply);
|
||||||
|
|
||||||
if ($response->successful()) {
|
if ($response->successful()) {
|
||||||
$this->reply->is_pending = false;
|
$this->reply->is_pending = false;
|
||||||
|
@ -26,9 +26,7 @@ public function __construct(WorkOrderWorkOrder $workOrder, $type = 'post')
|
|||||||
{
|
{
|
||||||
//
|
//
|
||||||
$this->workOrder = $workOrder;
|
$this->workOrder = $workOrder;
|
||||||
$this->workOrder->load(['module']);
|
|
||||||
$this->type = $type;
|
$this->type = $type;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -38,6 +36,7 @@ public function __construct(WorkOrderWorkOrder $workOrder, $type = 'post')
|
|||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
|
$this->workOrder->load(['module']);
|
||||||
|
|
||||||
$http = Http::remote($this->workOrder->module->api_token, $this->workOrder->module->url);
|
$http = Http::remote($this->workOrder->module->api_token, $this->workOrder->module->url);
|
||||||
if ($this->type == 'put') {
|
if ($this->type == 'put') {
|
||||||
|
@ -61,6 +61,15 @@ public function remoteRequest($method, $func, $requests)
|
|||||||
|
|
||||||
$requests['user_id'] = auth('sanctum')->id();
|
$requests['user_id'] = auth('sanctum')->id();
|
||||||
|
|
||||||
|
$user = auth('sanctum')->user();
|
||||||
|
|
||||||
|
if ($method == 'post') {
|
||||||
|
// add user to requests
|
||||||
|
$requests['user'] = $user;
|
||||||
|
}
|
||||||
|
|
||||||
|
$requests['user_id'] = $user['id'];
|
||||||
|
|
||||||
$response = $http->{$method}("functions/{$func}", $requests);
|
$response = $http->{$method}("functions/{$func}", $requests);
|
||||||
|
|
||||||
$json = $response->json();
|
$json = $response->json();
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
namespace App\Models\WorkOrder;
|
namespace App\Models\WorkOrder;
|
||||||
|
|
||||||
use App\Exceptions\CommonException;
|
use App\Exceptions\CommonException;
|
||||||
|
use App\Models\User;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
|
||||||
@ -24,6 +25,11 @@ public function workOrder()
|
|||||||
return $this->belongsTo(WorkOrder::class);
|
return $this->belongsTo(WorkOrder::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function user()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(User::class);
|
||||||
|
}
|
||||||
|
|
||||||
public function scopeWorkOrderId($query, $work_order_id)
|
public function scopeWorkOrderId($query, $work_order_id)
|
||||||
{
|
{
|
||||||
return $query->where('work_order_id', $work_order_id);
|
return $query->where('work_order_id', $work_order_id);
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
namespace App\Models\WorkOrder;
|
namespace App\Models\WorkOrder;
|
||||||
|
|
||||||
use App\Exceptions\CommonException;
|
use App\Exceptions\CommonException;
|
||||||
|
use App\Models\User;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
|
||||||
@ -24,6 +25,11 @@ public function workOrder()
|
|||||||
return $this->belongsTo(WorkOrder::class);
|
return $this->belongsTo(WorkOrder::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function user()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(User::class);
|
||||||
|
}
|
||||||
|
|
||||||
public function scopeWorkOrderId($query, $work_order_id)
|
public function scopeWorkOrderId($query, $work_order_id)
|
||||||
{
|
{
|
||||||
return $query->where('work_order_id', $work_order_id);
|
return $query->where('work_order_id', $work_order_id);
|
||||||
|
Loading…
Reference in New Issue
Block a user