core/api/modules/lk-tovar/ajax.php

63 lines
2.8 KiB
PHP
Raw Normal View History

2022-12-11 13:55:49 +05:00
<?php
if ( !$_SESSION['user_id'] ) die ( 'Кыш' );
require_once MYDIR . '/api/php/db.php';
require_once MYDIR . '/api/php/clean.php';
switch( @$_POST['act'] ) {
/* ----------------------------------------------------------------------
19.11.2022
Ищем улицу
---------------------------------------------------------------------- */
case 'findStreet':
$citys = DB::getAll('SELECT `txt` FROM `street` WHERE `txt` LIKE "' . Clean::str( $_POST['street'] ) . '%" AND `city_id` = ' . Clean::int( $_POST['city_id'] ));
//echo 'SELECT `txt` FROM `street` WHERE `txt` LIKE ' . Clean::str( $_POST['street'] ) . ' AND `city_id` = ' . Clean::int( $_POST['city_id'] );
if (count($citys)==1){
$res[0]['txt']=$citys[0]['txt'];
$res[0]['ok']="1";
}else{
$res['ok']="0";
}
echo $db->to_j($res);
break;
/* ----------------------------------------------------------------------
05.06.2022
Сохраняем адрес доставки
---------------------------------------------------------------------- */
case 'addAdres':
//Смотрим есть ли улица в базе, если нет - добавляем
$citys = DB::getAll('SELECT `txt`, `id` FROM `street` WHERE `txt` = "' . Clean::str( $_POST['street'] ) . '" AND `city_id` = ' . Clean::int( $_POST['city_id'] ));
if (count($citys)==0){
$post=array(Clean::str( $_POST['street'] ), Clean::int( $_POST['city_id'] ), Clean::int( $_POST['region_id'] ), 1);
$insert_id = DB::add("INSERT INTO `street` SET `txt` = ?, `city_id` = ?, `region_id`= ?, `strana_id` = ?", $post);
}else{
$insert_id = $citys[0]['id'];
}
//Добавляем адрес доставки
$post2=array(
Clean::str( $insert_id ),
Clean::str( $_POST['dom'] ),
Clean::int( $_POST['city_id'] ),
Clean::int( $_POST['region_id'] ),
Clean::int( $_SESSION['user_id'] )
);
$adres_id = DB::add("INSERT INTO `adres_dostavki` SET `street` = ?, `dom` = ?, `city_id` =?,`region_id`= ?, `user_id` = ?", $post2);
//Получаеи данные чтобы добавить в табличку
$res[0]['adres_id']=$adres_id;
$res[0]['dom']=$_POST['dom'];
$res[0]['street']= DB::getValue("SELECT `txt` FROM `street` WHERE `id` = " . $insert_id);
$res[0]['city']= DB::getValue("SELECT `txt` FROM `city` WHERE `id` = " . Clean::int( $_POST['city_id'] ));
echo $db->to_j($res);
break;
/* ----------------------------------------------------------------------
23.11.2022
Удаляем адрес
---------------------------------------------------------------------- */
case 'delAdres':
DB::set("DELETE FROM `adres_dostavki` WHERE `id` = ? AND `user_id` = ?", array($_POST['id'], $_SESSION['user_id']));
break;
default:
}