Swipe
Новичок
Доброго времени суток,столкнулся с проблемой: Код не обрабатывает запрос на покупку дизайна (только дизайн не покупает, а установить можно)
P.S. После нажатия на кнопку "купить" выводит ошибку с текстом "не достаточно денег"
PHP:
P.S. После нажатия на кнопку "купить" выводит ошибку с текстом "не достаточно денег"
PHP:
- public function buy($id)
- {
- $default = $this->load->database('default', TRUE, FALSE);
- $id = preg_replace('/[^0-9]/', '', $id);
- $bil = $this->load->database('billing', TRUE, FALSE);
- $template = $bil->get_where('market_templates', array('id' => $id))->result();
- $site = $bil->get_where('arenda', array('domain' => $_SERVER['HTTP_HOST']))->result();
- $user = $bil->get_where('arenda', array('id' => $site[0]->user_id))->result();
- $buy = $bil->get_where('market_prices', array('id_user' => $user[0]->id , 'id_template' => $id))->result();
- if (empty($buy[0]->id)) { $buy = "0";} else { $buy = "1"; }
- if ($template[0]->price == 0 or $buy == 1 ) {
- echo 'sweetAlert("Ошибка", "Вы уже приобрели данный шаблон .", "error");';
- } elseif($user[0]->money < $template[0]->price) {
- echo 'sweetAlert("Ошибка", "У вас недостаточно денег на балансе .", "error");';
- } else {
- $balance = $user[0]->money - $template[0]->price ;
- $data = array('money' => $balance);
- $bil->where('id', $user[0]->id);
- $bil->update('users', $data);
- $data = array( 'id_user' => $user[0]->id , 'id_template' => $id );
- $bil->insert('market_prices', $data);
- echo 'swal("Успех!", "Вы успешно купили данный шаблон .", "success");location.reload(true);';
- }
- }