2022-08-19 15:27:57 +00:00
|
|
|
<?php
|
|
|
|
|
2022-11-16 02:29:50 +00:00
|
|
|
namespace App\Jobs\Module\WorkOrder;
|
2022-08-19 15:27:57 +00:00
|
|
|
|
2022-09-22 06:00:03 +00:00
|
|
|
use App\Events\UserEvent;
|
2022-11-06 11:28:22 +00:00
|
|
|
use App\Models\WorkOrder\Reply as WorkOrderReply;
|
2022-08-19 15:27:57 +00:00
|
|
|
use Illuminate\Bus\Queueable;
|
2022-11-06 11:28:22 +00:00
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
|
|
use Illuminate\Queue\InteractsWithQueue;
|
2022-08-19 15:27:57 +00:00
|
|
|
use Illuminate\Queue\SerializesModels;
|
2022-11-06 11:28:22 +00:00
|
|
|
use Illuminate\Support\Facades\Http;
|
2022-09-08 16:12:02 +00:00
|
|
|
|
|
|
|
// use Illuminate\Contracts\Queue\ShouldBeUnique;
|
2022-08-19 15:27:57 +00:00
|
|
|
|
|
|
|
class Reply implements ShouldQueue
|
|
|
|
{
|
2022-09-08 16:12:02 +00:00
|
|
|
use InteractsWithQueue, Queueable, SerializesModels;
|
2022-08-19 15:27:57 +00:00
|
|
|
|
|
|
|
protected $reply;
|
2022-11-16 05:16:56 +00:00
|
|
|
|
2022-08-19 15:27:57 +00:00
|
|
|
/**
|
|
|
|
* Create a new job instance.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __construct(WorkOrderReply $reply)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
$this->reply = $reply;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the job.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
|
|
|
//
|
2022-08-29 17:11:19 +00:00
|
|
|
$this->reply->load(['workOrder', 'user']);
|
|
|
|
$this->reply->workOrder->load(['module']);
|
2022-09-08 16:12:02 +00:00
|
|
|
|
2022-11-16 02:29:50 +00:00
|
|
|
$http = Http::module($this->reply->workOrder->module->api_token, $this->reply->workOrder->module->url);
|
2022-08-19 15:27:57 +00:00
|
|
|
|
2022-08-29 17:11:19 +00:00
|
|
|
$reply = $this->reply->toArray();
|
|
|
|
|
|
|
|
$response = $http->post('work-orders/' . $this->reply->workOrder->id . '/replies', $reply);
|
2022-08-19 15:27:57 +00:00
|
|
|
|
|
|
|
if ($response->successful()) {
|
2022-10-31 11:03:38 +00:00
|
|
|
$this->reply->update([
|
|
|
|
'is_pending' => false
|
|
|
|
]);
|
2022-09-22 06:00:03 +00:00
|
|
|
|
|
|
|
broadcast(new UserEvent($this->reply->workOrder->user_id, 'work-order.replied', $this->reply));
|
|
|
|
|
2022-08-19 15:27:57 +00:00
|
|
|
} else {
|
2022-10-31 11:03:38 +00:00
|
|
|
$this->reply->update([
|
|
|
|
'is_pending' => true
|
|
|
|
]);
|
2022-08-19 15:27:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|