add order route

This commit is contained in:
Your Name
2021-06-19 23:26:37 +03:00
parent fe4db1b3e0
commit d328ffa7b0
9 changed files with 144 additions and 6 deletions

View File

@@ -221,6 +221,37 @@ function client_find_email_kuri($mail){
}
# узнаем id клиента по мылу или создаем его
function api_add_client($mail){
$find_mail = dbl_get("SELECT `client_id`, `clienthash` FROM `clients` WHERE `clientmail` = '$mail' LIMIT 1");
if (isset($find_mail['client_id'])){
$result = $find_mail['clienthash'];
}
else {
$add['clientmail'] = $mail;
$add['clienthash'] = md5($mail);
$add['clientdate'] = date("Y-m-d H:i:s");
$res = db_insert('clients', $add, 'chitatel');
if ($res > 0){
$result = $add['clienthash'];
}
else{
$result = false;
}
}
return $result;
}
function client_find_hash($hash){

View File

@@ -7,7 +7,7 @@ function bookid_kuri($slug) {
$query = "
SELECT
`price_id`, `pricename`, `categoryname`, `categoryslug`, price.category_id AS category_id, `BeginDate`, `priceanons`, `priceimg`, `pricehash`, `price`, `sub`
`price_id`, `pricename`, `categoryname`, `priceslug`, `categoryslug`, price.category_id AS category_id, `BeginDate`, `priceanons`, `priceimg`, `pricehash`, `price`, `offline_price`, `sub`
FROM
`price`
LEFT JOIN `pricecategory`

View File

@@ -31,6 +31,8 @@ define('VIEWPATH', SITEPATH.'views/');
define('API', 'http://api.argumenti.ru/');
define('IMGSRV', 'https://imgurl.argumenti.ru/');
define('PAYSITE', 'https://pay.argumenti.ru/'); //сервис оплаты
/** отправка уведомлений */
/*set('noreply',
[
@@ -57,3 +59,4 @@ db_config('reader', 'mysql:host=mysql;dbname=argumentiru', 'reader', 'ghjyjkUIOh
db_config('chitatel', 'mysql:host=mysql;dbname=argumentiru', 'chitatel', 'hjYu78kl*90Uio');
db_config('klan', 'mysql:host=mysql;dbname=argumentiru', 'klan', 'zpFGhyuRty765Jk');
// GRANT ALL PRIVILEGES ON argumentiru.* TO 'hitatel'@'%' IDENTIFIED BY 'hjYu78kl*90Uio'

View File

@@ -11,6 +11,7 @@ require 'routes/auth.php';
require 'routes/pdfserver.php';
require 'routes/email.php';
require 'routes/books.php';
require 'routes/order.php';
#api
require 'api/apiclient.php';

View File

@@ -4,7 +4,6 @@ function product_kuri($slug){
$book = bookid_kuri($slug);
$breadcrumbs = [
$book['categoryname'] => SITE.'category/'.$book['categoryslug'],
'page' => $book['pricename']
@@ -25,6 +24,11 @@ function product_kuri($slug){
# купил ли эту книжку
$buy_status = client_status_book($books['book_id'], CLIENT_ID);
}
# линки на оформление заказа
$link_online = SITE.'checkout/'.$book['priceslug'].'/1';
$link_offline = SITE.'checkout/'.$book['priceslug'].'/2';
$link_subscript = SITE.'checkout/podpiska-na-elektronnuyu-versiyu-gazety-argumenty-nedeli-na-god/1';
$tempcontent = VIEWPATH.'book.phtml';
include VIEWPATH.'layout.phtml';

View File

@@ -92,8 +92,6 @@ function restoration_kuri(){
$hashlink = SITE.'resetlink/'.$hash;
}
echo $hashlink;
$tempcontent = VIEWPATH.'restore_add.phtml';
include VIEWPATH.'layout.phtml';
}

69
app/routes/order.php Normal file
View File

@@ -0,0 +1,69 @@
<?php
/**
* оформление заказа
*/
function checkout_kuri($priceslug, $buy_type = 1){
$price_id = db_get("SELECT * FROM `price` WHERE `priceslug` = '$priceslug' LIMIT 1");
if (isset($price_id['price_id'])) {
if ($buy_type == 1){ // тип товара
$price = $price_id['price']; // электронная книжка
}
else {
$price = $price_id['offline_price']; // бумажная книжка
}
if (defined('CLIENT_ID')){
$client = client_find_id(CLIENT_ID);
if (isset($client['result']['client_id'])){
$clienthash = $client['result']['clienthash'];
}
}
if (isset($_POST['clientmail'])){
$clientmail = $_POST['clientmail'];
if (!filter_var($clientmail, FILTER_VALIDATE_EMAIL)){
$error_mail = True;
}
else {
# получаем хэш клиента чтобы отправить на оплату
$clienthash = api_add_client($clientmail);
}
}
if (isset($clienthash) and $clienthash) {
$paylink = PAYSITE."anpay/$priceslug/$clienthash";
header("Location: $paylink");
return True;
}
}
else {
$error_price = True;
}
$submit_link = SITE."checkout/$priceslug/$buy_type";
include VIEWPATH.'checkout.phtml';
}

View File

@@ -12,8 +12,16 @@
<p class="price"><a href="<?=$book['links']['download']?>">Скачать PDF</a></p>
<?endif?>
<?else:?>
<?$paylink = 'https://argumenti.ru/robomail/'.$book['price_id']?>
<p class="price"><a href="<?=$paylink?>">Купить за <?=$book['price']?> руб.</a></p>
<?if ($book['price'] > 0):?>
<p class="price"><a href="<?=$link_online?>">Электронная за <?=$book['price']?> руб.</a></p>
<?endif?>
<?if ($book['sub'] == 1):?>
<p class="price"><a href="<?=$link_subscript?>">Доступ к библиотеке за 490 руб. в год</a></p>
<?endif?>
<?if ($book['offline_price'] > 0):?>
<p class="price"><a href="<?=$link_offline?>">Бумажная за <?=$book['offline_price']?> руб.</a></p>
<?endif?>
<?endif?>
</div>
</section>

24
app/views/checkout.phtml Normal file
View File

@@ -0,0 +1,24 @@
<?if (isset($error_price)):?>
<p style="color: red;">Просим прощения, но такой товар не найден!</p>
<?else:?>
<form id="clientform" class="clientform" action="<?=$submit_link?>" method="POST">
<?if (isset($error_mail)):?>
<p style="color: red;">Неверный адрес электронной почты</p>
<?endif?>
<p><label for="clientmail">Для покупки этого товара введите свой электронный адрес ниже:</label></p>
<p><input type="email" id="clientemail" name="clientmail"></p>
<p><label>Нажимая кнопку «Купить», я соглашаюсь <a href="https://argumenti.ru/subscribe_condition">с условиями подписки</a></label></p>
<p><input type="submit" id="submit" value="Купить"></p>
</form>
<?endif?>