namespace app\controllers;
-use GuzzleHttp\Client;
+use app\jobs\SendBonusInfoToSiteJob;
use DateTime;
use DateTimeZone;
use Yii;
LogService::apiErrorLog(json_encode(["error_id" => 5, "error" => $userBonus2->getErrors()], JSON_UNESCAPED_UNICODE));
return $this->asJson(["error_id" => 5, "error" => $userBonus2->getErrors()]);
+ } else {
+ Yii::$app->queue->push(new SendBonusInfoToSiteJob([
+ 'phone' => $phone,
+ 'bonus' => $back,
+ 'bonus_created_at' => date("Y-m-d H:i:s"),
+ ]));
}
file_put_contents(self::OUT_DIR . '/sale_bonuses_' . $fl . '.json', PHP_EOL . '--' . __LINE__, FILE_APPEND);
LogService::apiErrorLog(json_encode(["error_id" => 5.2, "error" => $userBonus2->getErrors()], JSON_UNESCAPED_UNICODE));
return $this->asJson(["error_id" => 5.2, "error" => $userBonus2->getErrors()]);
+ } else {
+ Yii::$app->queue->push(new SendBonusInfoToSiteJob([
+ 'phone' => $phone,
+ 'bonus' => $back,
+ 'bonus_created_at' => date("Y-m-d H:i:s"),
+ ]));
}
if ($userFound->telegram_created_at == null) {
$userFound->telegram_created_at = date("Y-m-d H:i:s");
LogService::apiLogs(1, json_encode($mess, JSON_UNESCAPED_UNICODE));
file_put_contents(self::OUT_DIR . '/sale_bonuses_' . $fl . '.json', PHP_EOL . '--' . __LINE__ . ' OK ', FILE_APPEND);
- $client = new Client();
- try {
- $result = $client->post('https://api2.dev1.erp-flowers.ru/balance/test?key=getJH6GFi4tpU84YVPW9M__Xe_eQ24baWRFGl9ance', [
- 'phone' => $phone,
- 'balance' => $user->balans,
- 'created_at' => date('Y-m-d H:i:s'),
- ]);
- $mess['resultSiteSendAAA'] = json_encode($result->getBody()->getContents(), JSON_UNESCAPED_UNICODE);
- } catch (\Exception $e) {
- LogService::apiErrorLog(json_encode(["error_id" => 7, "error" => "Ошибка отправки сообщения на сайт: " .
- $e->getMessage()], JSON_UNESCAPED_UNICODE));
- }
-
return $this->asJson($mess);
}
--- /dev/null
+<?php
+
+namespace app\jobs;
+
+
+use Yii;
+use yii\queue\JobInterface;
+use yii_app\services\SiteService;
+
+class SendBonusInfoToSiteJob extends \yii\base\BaseObject implements JobInterface
+{
+ public $messageData;
+
+ public function execute($queue) {
+ $phone = ($this->messageData)['phone'];
+ $bonus = ($this->messageData)['bonus'];
+ $bonus_created_at = ($this->messageData)['bonus_created_at'];
+
+ try {
+ $result = SiteService::notifySiteAboutBonuses($phone, $bonus, $bonus_created_at);
+ if ($result == "OK") {
+ Yii::warning("Сообщение успешно отправлено на сайт", 'site');
+ } else {
+ Yii::warning("Сообщение не удалось отправить на сайт", 'site');
+ }
+ } catch (\Exception $e) {
+ Yii::error(
+ "Сообщение не удалось отправить на сайт: " . $e->getMessage(),
+ 'site'
+ );
+ }
+ }
+}
--- /dev/null
+<?php
+
+namespace yii_app\services;
+
+use GuzzleHttp\Client;
+
+class SiteService {
+ public static function notifySiteAboutBonuses($phone, $bonus, $bonus_created_at) {
+ $client = new Client();
+ $result = null;
+ try {
+ $result = $client->post('https://api2.dev1.erp-flowers.ru/balance/test?key=getJH6GFi4tpU84YVPW9M__Xe_eQ24baWRFGl9ance', [
+ 'phone' => $phone,
+ 'bonus' => $bonus,
+ 'created_at' => $bonus_created_at,
+ ]);
+ $result = $result->getBody()->getContents();
+ } catch (\Exception $e) {
+ LogService::apiErrorLog(json_encode(["error_id" => 7, "error" => "Ошибка отправки сообщения на сайт: " .
+ $e->getMessage()], JSON_UNESCAPED_UNICODE));
+ }
+ return $result;
+ }
+}