diff --git a/app/Http/Controllers/Admin/ConfigController.php b/app/Http/Controllers/Admin/ConfigController.php index fab82255..e4d4a65e 100755 --- a/app/Http/Controllers/Admin/ConfigController.php +++ b/app/Http/Controllers/Admin/ConfigController.php @@ -86,6 +86,10 @@ class ConfigController extends Controller ], 'email' => [ 'email_template' => config('v2board.email_template', 'default') + ], + 'telegram' => [ + 'telegram_bot_enable' => config('v2board.telegram_bot_enable', 0), + 'telegram_bot_token' => config('v2board.telegram_bot_token') ] ] ]); diff --git a/app/Http/Requests/Admin/ConfigSave.php b/app/Http/Requests/Admin/ConfigSave.php index 6b858dae..39b0db14 100755 --- a/app/Http/Requests/Admin/ConfigSave.php +++ b/app/Http/Requests/Admin/ConfigSave.php @@ -61,7 +61,10 @@ class ConfigSave extends FormRequest 'apple_id' => 'email', 'apple_id_password' => '', // email - 'email_template' => '' + 'email_template' => '', + // telegram + 'telegram_bot_enable' => 'in:0,1', + 'telegram_bot_token' => '' ]; /** diff --git a/app/Services/OrderService.php b/app/Services/OrderService.php index 9a35ddcb..4b667fbf 100644 --- a/app/Services/OrderService.php +++ b/app/Services/OrderService.php @@ -120,9 +120,12 @@ class OrderService 'month_price' => 1, 'quarter_price' => 3, 'half_year_price' => 6, - 'year_price' => 12 + 'year_price' => 12, + 'onetime_price' => 0 ]; - $orderModel = Order::where('user_id', $user->id)->where('cycle', '!=', 'reset_price')->where('status', 3); + $orderModel = Order::where('user_id', $user->id) + ->where('cycle', '!=', 'reset_price') + ->where('status', 3); $totalValue = $orderModel->sum('total_amount') + $orderModel->sum('balance_amount'); if ($totalValue <= 0) { diff --git a/library/Telegram.php b/library/Telegram.php new file mode 100644 index 00000000..63d9cfab --- /dev/null +++ b/library/Telegram.php @@ -0,0 +1,29 @@ +api = 'https://api.telegram.org/bot' . config('v2board.telegram_bot_token') . '/'; + } + + public function sendMessage(int $chatId, string $text, string $parseMode = '') + { + $this->request('sendMessage', [ + 'chat_id' => $chatId, + 'text' => $text, + 'parse_mode' => $parseMode + ]); + } + + private function request(string $method, array $params) + { + $curl = new Curl(); + $curl->post($this->api . $method, http_build_query($params)); + $curl->close(); + } +}