return $this->asJson($mess);
}
- public function actionSendMessage()
- {
+// public function actionSendMessage()
+// {
+// Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
+// $data = file_get_contents('php://input');
+// $result = json_decode($data, true);
+//
+// $__API_PARAMS = ['store_id', 'seller_id', 'phone'];
+//
+// foreach ($__API_PARAMS as $paramName) {
+// if (empty($result[$paramName])) {
+//
+// if ($paramName != 'phone') {
+// LogService::apiErrorLog(json_encode(["error_id" => 1, "error" => "$paramName is required"], JSON_UNESCAPED_UNICODE));
+// }
+//
+// return $this->asJson(["error" => "$paramName is required"]);
+// }
+// }
+//
+// $phone = ClientHelper::phoneClear($result['phone']);
+// if (!ClientHelper::phoneVerify($phone)) {
+// return $this->asJson(["error_id" => 0.2, "error" => "phone is required"]);
+// }
+// $result['phone'] = $phone;
+//
+// $user = Users::find()->where(['phone' => $result['phone']])->andWhere(['phone_true' => '1'])->andWhere(['black_list' => '0'])->one();
+// if (!$user) {
+// $mess["error"] = "Покупателя " . $result['phone'] . " нет в бонусной программе!";
+//
+// return $this->asJson($mess);
+// }
+// $keycode = $user->keycode;
+//
+// $mess = [];
+// $mess["result"] = true;
+//
+// $mess['auth_code'] = $user->keycode;
+// $mess['message_cashier'] = 'Отсканируйте QR код из телеграм бота или введите его руками';
+//
+// LogService::apiLogs(1, json_encode($mess, JSON_UNESCAPED_UNICODE));
+//
+// return $this->asJson($mess);
+// }
+
+ public function actionSendMessage() {
Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
$data = file_get_contents('php://input');
$result = json_decode($data, true);
return $this->asJson($mess);
}
- $keycode = $user->keycode;
- $mess = [];
- $mess["result"] = true;
+ $mess["message_cashier"] = "Звонок-последние 4 цифры телефона";
+
+ $userAuthCallLog = UsersAuthCallLog::find()->select(['COUNT(*) as cnt'])->where(['phone' => $result['phone']])
+ ->andWhere(['store_id' => $result['store_id']])->andWhere(['>=', 'date', date('Y-m-d H:i:s', strtotime('-10 minutes'))])->one();
+
+ $cnt = $userAuthCallLog ? $userAuthCallLog->cnt : 1;
+
+ if ($cnt < 2) {
+ $body = @file_get_contents("https://sms.ru/code/call?phone=" . $result['phone'] . "&api_id=4DFE45F9-1897-79C0-6872-08F05D6B7FA4&ip=" . $_SERVER["REMOTE_ADDR"]);
+ $json_res = json_decode($body, true, 512, JSON_UNESCAPED_UNICODE);
+ if ($json_res["status"] == "OK") {
+ $keycode = $json_res["code"];
+ $user->keycode = '' . $keycode;
+ $user->password = ClientHelper::generatePassword(8);;
+ $user->save();
+ if ($user->getErrors()) {
+ LogService::apiErrorLog(json_encode(["error_id" => 3.1415, "error" => $user->getErrors()], JSON_UNESCAPED_UNICODE));
+ return $this->asJson(["error_id" => 3.1415, "error" => $user->getErrors()]);
+ }
+ $mess["auth_code"] = $keycode;
+ $mess["message_cashier"] = "Попытка:$cnt Звонок клиенту! последние 4 цифры номера";
+ }
+ } elseif ($cnt > 2) {
+ $mess["message_cashier"] = "Попытка $cnt -извиняемся перед клиентом";
+ }
+ $name = "$keycode Попытка $cnt " . $_SERVER["REMOTE_ADDR"];
+ $userAuthCallLog = new UsersAuthCallLog;
+ $userAuthCallLog->date = date('Y-m-d H:i:s');
+ $userAuthCallLog->store_id = $result['store_id'];
+ $userAuthCallLog->seller_id = $result['seller_id'];
+ $userAuthCallLog->phone = $result['phone'];
+ $userAuthCallLog->name = $name;
+ $userAuthCallLog->save();
+ if ($userAuthCallLog->getErrors()) {
+ LogService::apiErrorLog(json_encode(["error_id" => 4.15, "error" => $userAuthCallLog->getErrors()], JSON_UNESCAPED_UNICODE));
+ return $this->asJson(["error_id" => 4.15, "error" => $userAuthCallLog->getErrors()]);
+ }
- $mess['auth_code'] = $user->keycode;
- $mess['message_cashier'] = 'Отсканируйте QR код из телеграм бота или введите его руками';
+ file_put_contents(self::$USERS_AUTH_CALL_LOG2,
+ "" . date("d.m.Y H:i:s", time()) . " keykod=" . $user->keycode
+ . " store_id=" . $result['store_id'] . " seller_id=" . $result['seller_id'] . " phone=" . $result['phone'] . " $name\n",
+ FILE_APPEND | LOCK_EX);
+
+ $mess["timeout"] = 15;
LogService::apiLogs(1, json_encode($mess, JSON_UNESCAPED_UNICODE));
return $this->asJson($mess);
}
+
// $mess["message_cashier"] = "Звонок-последние 4 цифры телефона";
//
// $userAuthCallLog = UsersAuthCallLog::find()->select(['COUNT(*) as cnt'])->where(['phone' => $result['phone']])