|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Conversations; |
|
4
|
|
|
|
|
5
|
|
|
use App\Http\Requests\Auth\LoginRequest; |
|
6
|
|
|
use App\Models\Order; |
|
7
|
|
|
use App\Models\User; |
|
8
|
|
|
use App\Support\Auth\MultipleIdentifier; |
|
9
|
|
|
use BotMan\BotMan\Messages\Incoming\Answer; |
|
10
|
|
|
use BotMan\Drivers\Telegram\Extensions\Keyboard; |
|
11
|
|
|
use BotMan\Drivers\Telegram\Extensions\KeyboardButton; |
|
12
|
|
|
use Illuminate\Support\Facades\Auth; |
|
13
|
|
|
|
|
14
|
|
|
class CheckOrderStatusConversation extends Conversation |
|
15
|
|
|
{ |
|
16
|
|
|
use MultipleIdentifier; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Start the conversation. |
|
20
|
|
|
* |
|
21
|
|
|
* @return $this |
|
22
|
|
|
*/ |
|
23
|
|
|
public function run() |
|
24
|
|
|
{ |
|
25
|
|
|
return $this->askCode(); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Ask order code. |
|
30
|
|
|
* |
|
31
|
|
|
* @param string|null $validationErrorMessage |
|
32
|
|
|
* @return $this |
|
33
|
|
|
*/ |
|
34
|
|
|
protected function askCode(string $validationErrorMessage = null) |
|
35
|
|
|
{ |
|
36
|
|
|
$this->displayValidationErrorMessage($validationErrorMessage); |
|
37
|
|
|
|
|
38
|
|
|
return $this->askRenderable('conversations.check-order-status.ask-code', function (Answer $answer) { |
|
39
|
|
|
if (trim($answer->getText()) === $this->cancelText()) { |
|
40
|
|
|
return $this->cancelCheck(); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
if (!$order = Order::firstWhere('code', $answer->getText())) { |
|
44
|
|
|
return $this->askCode(trans('No Results Found.')); |
|
|
|
|
|
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
$order->load('customer:id,fullname', 'user:id,fullname', 'branch', 'items.denomination'); |
|
48
|
|
|
|
|
49
|
|
|
return $this->sayRenderable('conversations.check-order-status.alert-order', compact('order')); |
|
50
|
|
|
}, additionalParameters: Keyboard::create(Keyboard::TYPE_KEYBOARD)->addRow( |
|
51
|
|
|
KeyboardButton::create($this->cancelText()) |
|
52
|
|
|
)->toArray()); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Return cancel login text. |
|
57
|
|
|
* |
|
58
|
|
|
* @return string |
|
59
|
|
|
*/ |
|
60
|
|
|
protected function cancelText(): string |
|
61
|
|
|
{ |
|
62
|
|
|
return trim(view('conversations.check-order-status.cancel')->render()); |
|
|
|
|
|
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Cancel check order code process. |
|
67
|
|
|
* |
|
68
|
|
|
* @return $this |
|
69
|
|
|
*/ |
|
70
|
|
|
protected function cancelCheck() |
|
71
|
|
|
{ |
|
72
|
|
|
return $this->sayRenderable('conversations.check-order-status.alert-cancel', additionalParameters: ['reply_markup' => json_encode([ |
|
73
|
|
|
'remove_keyboard' => true, |
|
74
|
|
|
])]); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|