Answer the question
In order to leave comments, you need to log in
Where are the extraneous entries in the codeigniter database coming from?
Greetings! I made a small CI web application for accounting for goods (add a product, bought a product, edit a product).
A couple of times a day, left records appear in the database about purchases, for example:
they bought 1 product with a certain ID and immediately 1-2 more purchases are recorded with the same ID and with a chaotic quantity (20,12,4,3, etc. ).
I can’t track down why this is happening. errors appear with different products, and may not be. I did logging (when writing to the database, writing to a file) - for some reason these erroneous records are not logged.
The function that is responsible for the purchase has already broken my head :
function kupleno(){
//это для логов
include($_SERVER['DOCUMENT_ROOT'].'/class.php');
Logger::$PATH = 'logs';
$array = $this->input->post("ii");
$this->load->model('News_model');
$data["time"] = date("Y-m-d H:i:s");
//перебор отправленных товаров
foreach($array as $ar){
$data["code"] = $ar['cod'];
$data["kol"] = $ar['kol'];
$data["ver"] = $ar['ver'];
$kol = $ar['kol'];
//отнимает от количества в списке продуктов
$this->db->where('code',$data["code"]);
$this->db->set('kol', 'kol - '.(int)$kol, FALSE);
$this->db->set('kup', $kol);
$this->db->update('prod');
//получаем всю инфу по товару
$this->db->where('code',$data["code"]);
$q = $this->db->get('prod');
$arr = $q->row_array();
//вычисляем прибыль
$getprice = $this->getprice($arr["price"],$arr["kurs"],$arr["sale"],$arr['proc']);
$prib = $getprice["summ"]-$getprice["price"];
if(!empty($arr["sale"])){$prib = $getprice["summ"]-$getprice["saletg"];}
$data["pribil"] =(ceil($prib/10)*10)*$kol;
//проверяем был ли куплен товар уже сегодня, в магазине или с доставкой
$dt = date("Y-m-d");
$this->db->where('code',$data["code"]);
$this->db->where('ver',$data["ver"]);
$this->db->where("DATE_FORMAT(time,'%Y-%m-%d') = '$dt'");
$q = $this->db->get('kupleno');
//если да то обновляем
if($q->num_rows() > 0){
$this->db->where('code',$data["code"]);
$this->db->set('kol', 'kol + '.(int)$kol, FALSE);
$this->db->set('pribil', 'pribil + '.(int)$data["pribil"], FALSE);
$this->db->set('time', date("Y-m-d H:i:s"));
$this->db->update('kupleno');
Logger::getLogger(date("d-m-Y"))->log('ipdate id - '.$ar['cod'].'/'.$ar['kol'].'/'.$ar['ver']);
}else{
Logger::getLogger(date("d-m-Y"))->log('kuplen id - '.$ar['cod'].'/'.$ar['kol'].'/'.$ar['ver']);
$this->News_model->kupleno($data);
}
}
print "Товар продан";
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question