예제 #1
0
파일: Orders.php 프로젝트: ariol/adminshop
     return array('created_at');
 }
 public function save(Validation $validation = NULL)
 {
     parent::save($validation);
     if ($this->status == 4) {
         $order = $this;
         $PDO = ORM::factory('Orders')->PDO();
         $orders_flag = $PDO->query("SELECT success_flag FROM orders WHERE id = '{$order->id}'")->fetchAll(PDO::FETCH_ASSOC);
         if ($orders_flag[0]['success_flag'] != 1) {
             $time = time();
             $time_end = $time + 86400 * 180;
             $time_end = date("Y-m-d", $time_end);
             $time_end_coupon = $time + 86400 * 60;
             $time_end_coupon = date("Y-m-d", $time_end_coupon);
             $full_price = 0;
             $success_flag_query = "UPDATE orders SET success_flag = 1 WHERE id = '{$order->id}'";
             $PDO->exec($success_flag_query);
             $PDO = ORM::factory('OrderProduct')->PDO();
             $query = "SELECT order_product.quantity, order_product.price\r                          FROM order_product\r                          WHERE order_id = '{$order->id}'";
             $order_data = $PDO->query($query)->fetchAll(PDO::FETCH_ASSOC);
             $discount = $PDO->query("SELECT coupons.code, coupons.discount, coupons.time_end\r                                    FROM coupons\r                                    WHERE coupons.order_id = '{$order->id}'")->fetch();
             if ($discount['discount']) {
                 $PDO_coupon = ORM::factory('Coupons')->PDO();
                 $PDO_coupon->query("UPDATE coupons SET time_end = '{$time_end_coupon}', active = 1  WHERE order_id = '{$order->id}'");
                 if ($order->email != '') {
                     $user_message = View::factory('admin/order/usermessage_delivery', array('name' => $order->name, 'email' => $order->email, 'phone' => $order->phone, 'adress' => $order->adress, 'city' => $order->city, 'index' => $order->index, 'time' => $time_end, 'discount' => $discount['discount'], 'code' => $discount['code']))->render();
                     Helpers_Email::send($order->email, 'Новый заказ ' . $order->name . ' ' . $order->phone, $user_message, true);
                 }
             }
             $PDO_order_certificate = ORM::factory('OrderCertificate')->PDO();
             $query_validity_certificate = "SELECT id, time_end\r                                                FROM order_certificate\r                                                WHERE order_id = '{$order->id}'";
             $validity_data = $PDO_order_certificate->query($query_validity_certificate)->fetchAll(PDO::FETCH_ASSOC);
             foreach ($validity_data as $v_data) {
                 $time = time();
                 $time_end_certificate = $time + 86400 * $v_data['time_end'];
                 $time_end_certificate = date("Y-m-d", $time_end_certificate);
                 $update_validity_query = "UPDATE order_certificate SET time_end = '{$time_end_certificate}', active = 1 WHERE id = '{$v_data['id']}'";
                 $PDO_order_certificate->query($update_validity_query);
             }
         }
예제 #2
0
파일: Cart.php 프로젝트: ariol/adminshop
 public function action_order()
 {
     $this->set_metatags_and_content('', 'page');
     $this->template->set_layout('site/global');
     if ($this->request->is_ajax()) {
         $name = $this->request->post('name');
         $email = $this->request->post('email');
         $phone = $this->request->post('phone');
         $adress = $this->request->post('adress');
         $city = $this->request->post('city');
         $index = $this->request->post('index');
         $delivery = $this->request->post('delivery');
         $admin_order = $this->request->post('admin_order');
         $comment = $this->request->post('comment');
         $PDO_coupons = ORM::factory('Coupons')->PDO();
         $date = date('Y-m-d');
         $stmt = $PDO_coupons->prepare("SELECT coupons.code, coupons.discount\r                                    FROM coupons\r                                    WHERE code = :code AND active = 1 AND time_end > '{$date}'");
         $stmt->bindParam(':code', $this->request->post('coupon'));
         $stmt->execute();
         foreach ($stmt as $row) {
             $code = $row['code'];
             $coupon_discount = $row['discount'];
         }
         $PDO_order_certificate = ORM::factory('OrderCertificate')->PDO();
         $date = date('Y-m-d');
         $stmt = $PDO_order_certificate->prepare("SELECT order_certificate.code, to_amount\r                                                        FROM order_certificate\r                                                        WHERE code = :code_certificate AND active = 1 AND time_end > '{$date}'");
         $stmt->bindParam(':code_certificate', $this->request->post('certificate'));
         $stmt->execute();
         foreach ($stmt as $row) {
             $code_certificate = $row['code'];
             $to_amount = $row['to_amount'];
         }
         $cart = Session::instance()->get('cart');
         $certificate = Session::instance()->get('cart_certificate');
         $cartitems = json_decode($cart['cart']);
         $certificateitems = json_decode($certificate['cart_certificate']);
         $order = ORM::factory('Orders');
         $order->name = $name;
         $order->email = $email;
         $order->phone = $phone;
         $order->adress = $adress;
         $order->code_coupon = $code;
         $order->delivery = $delivery;
         $order->code_certificate = $code_certificate;
         $order->city = $city;
         $order->index = $index;
         $order->comment = $comment;
         $order->save();
         $PDO_order_product = ORM::factory('OrderProduct')->PDO();
         $stmt = $PDO_order_product->prepare("INSERT INTO order_product (order_id, price, product_id, quantity, color)\r                                                  VALUES(:order_id, :price, :product_id, :quantity, :color)");
         $fullprice_product = 0;
         $fullprice_certificate = 0;
         if ($cartitems) {
             foreach ($cartitems as $items) {
                 $price = ORM::factory('Product')->getPriceValue($items->id);
                 if ($items->color) {
                     $color = $items->color;
                 } else {
                     $color = "";
                 }
                 $stmt->bindParam(':price', $price, PDO::PARAM_INT);
                 $stmt->bindParam(':product_id', $items->id, PDO::PARAM_INT);
                 $stmt->bindParam(':quantity', $items->quantity, PDO::PARAM_INT);
                 $stmt->bindParam(':order_id', $order->id, PDO::PARAM_INT);
                 $stmt->bindParam(':color', $color);
                 $stmt->execute();
                 $price_product = $price * $items->quantity;
                 $fullprice_product += $price_product;
             }
         }
         if ($certificateitems) {
             foreach ($certificateitems as $crcitems) {
                 $validity = ORM::factory('Certificate')->PDO()->query("SELECT certificate.validity, certificate.sum, certificate.price\r                                                                       FROM certificate\r                                                                       WHERE id = '{$crcitems->id}'")->fetch();
                 $i = 0;
                 while ($i < $crcitems->quantity) {
                     $certificate = $PDO_order_certificate->prepare("INSERT INTO order_certificate (certificate_id, order_id, code, price, time_end, to_amount)\r                                              VALUES(:certificate_id, :order_id, :certificate_code, :price, :time_end, :to_amount)");
                     $certificate_code = substr(md5(microtime()), rand(0, 5), rand(11, 16));
                     $certificate->bindParam(':certificate_id', $crcitems->id, PDO::PARAM_INT);
                     $certificate->bindParam(':order_id', $order->id, PDO::PARAM_INT);
                     $certificate->bindParam(':price', $validity['price'], PDO::PARAM_INT);
                     $certificate->bindParam(':certificate_code', $certificate_code, PDO::PARAM_STR);
                     $certificate->bindParam(':time_end', $validity['validity']);
                     $certificate->bindParam(':to_amount', $validity['sum']);
                     $certificate->execute();
                     $i++;
                     $fullprice_certificate += $validity['price'];
                 }
             }
         }
         $fullprice = $fullprice_product + $fullprice_certificate;
         switch ($fullprice) {
             case $fullprice >= 2000000:
                 $discount = 20;
                 break;
             case $fullprice >= 1800000:
                 $discount = 15;
                 break;
             case $fullprice >= 1500000:
                 $discount = 13;
                 break;
             case $fullprice >= 1200000:
                 $discount = 10;
                 break;
             case $fullprice >= 900000:
                 $discount = 7;
                 break;
             case $fullprice >= 600000:
                 $discount = 5;
                 break;
             case $fullprice >= 300000:
                 $discount = 3;
                 break;
         }
         $time_end = 60;
         $active = 0;
         $stmt = $PDO_coupons->prepare("UPDATE coupons SET active = :active WHERE code = :code");
         $stmt->bindParam(':code', $code);
         $stmt->bindParam(':active', $active);
         $stmt->execute();
         if ($discount) {
             $create_code = substr(md5(microtime()), rand(0, 5), rand(11, 16));
             $stmt = $PDO_coupons->prepare("INSERT INTO coupons (code, time_end, active, discount, order_id) VALUES(:code, :time_end, :active, :discount, :order_id)");
             $stmt->bindParam(':code', $create_code);
             $stmt->bindParam(':time_end', $time_end);
             $stmt->bindParam(':active', $active, PDO::PARAM_INT);
             $stmt->bindParam(':discount', $discount, PDO::PARAM_INT);
             $stmt->bindParam(':order_id', $order->id, PDO::PARAM_INT);
             $stmt->execute();
         }
         $PDO_order_certificate->query("UPDATE order_certificate SET active = {$active} WHERE code = '{$code_certificate}'");
         $cart_mail = $cart['cart'];
         if ($email) {
             $user_message = View::factory('site/order/usermessage', array('name' => $name, 'email' => $email, 'phone' => $phone, 'adress' => $adress, 'city' => $city, 'index' => $index, 'delivery' => $delivery, 'cart' => json_decode($cart_mail), 'certificate_mail' => $certificateitems, 'code_certificate' => $code_certificate, 'code' => $code, 'coupon_discount' => $coupon_discount, 'to_amount' => $to_amount, 'comment' => $comment))->render();
         }
         $admin_message = View::factory('site/order/adminmessage', array('name' => $name, 'email' => $email, 'phone' => $phone, 'adress' => $adress, 'city' => $city, 'index' => $index, 'delivery' => $delivery, 'cart' => json_decode($cart_mail), 'certificate_mail' => $certificateitems, 'code_certificate' => $code_certificate, 'code' => $code, 'coupon_discount' => $coupon_discount, 'to_amount' => $to_amount, 'comment' => $comment))->render();
         Helpers_Email::send(Kohana::$config->load('mailer.admin'), 'Новый заказ ' . $name . ' ' . $phone, $admin_message, true);
         Helpers_Email::send($email, 'Новый заказ ' . $name . ' ' . $phone, $user_message, true);
         if ($admin_order != true) {
             Session::instance()->destroy('cart');
             Session::instance()->destroy('cart_certificate');
         }
         exit(json_encode(array('order_id' => $order->id)));
     }
     $this->forward_404();
 }
예제 #3
0
파일: Order.php 프로젝트: ariol/cosm.by
     $this->template->to_amount = $to_amount;
 }
 public function action_change_order()
 {
     if ($this->request->is_ajax()) {
         $order_id = $this->request->post('order_id');
         $name = $this->request->post('name');
         $email = $this->request->post('email');
         $phone = $this->request->post('phone');
         $adress = $this->request->post('adress');
         $code = $this->request->post('coupon');
         $city = $this->request->post('city');
         $index = $this->request->post('index');
         $delivery = $this->request->post('delivery');
         $comment = $this->request->post('comment');
         $code_certificate = $this->request->post('certificate');
         $active = 0;
         $cart = Session::instance()->get('cart');
         $certificate = Session::instance()->get('cart_certificate');
         $cartitems = json_decode($cart['cart']);
         $certificateitems = json_decode($certificate['cart_certificate']);
         $PDO = ORM::factory('Orders')->PDO();
         $date = date('Y-m-d');
         $dataCertificate = $PDO->query("SELECT order_certificate.code, to_amount\r                                            FROM order_certificate\r                                            WHERE code = '{$code_certificate}' AND time_end > '{$date}'")->fetch();
         $dataCoupon = $PDO->query("SELECT coupons.code, coupons.discount\r                                            FROM coupons\r                                            WHERE code = '{$code}'  AND time_end > '{$date}'")->fetch();
         $query = "UPDATE  orders SET orders.name = '{$name}',\r                                              orders.email = '{$email}',\r                                              orders.phone = '{$phone}',\r                                              orders.adress = '{$adress}',\r                                              orders.code_coupon = '{$code}',\r                                              orders.code_certificate = '{$code_certificate}',\r                                              orders.delivery = '{$delivery}',\r                                              orders.city = '{$city}',\r                                              orders.index = '{$index}',\r                                              orders.comment = '{$comment}'\r                                               WHERE orders.id = '{$order_id}'";
         $PDO->exec($query);
         $delete_query = "DELETE FROM order_product WHERE order_id = '{$order_id}'";
         $PDO->query($delete_query);
         $stmt = $PDO->prepare("INSERT INTO order_product (order_id, price, product_id, quantity, color)\r                                      VALUES(:order_id, :price, :product_id, :quantity, :color)");
         foreach ($cartitems as $items) {
             if ($items->color) {
                 $color = $items->color;
             } else {
                 $color = "";
             }
             $stmt->bindParam(':price', $items->price, PDO::PARAM_INT);
             $stmt->bindParam(':product_id', $items->id, PDO::PARAM_INT);
             $stmt->bindParam(':quantity', $items->quantity, PDO::PARAM_INT);
             $stmt->bindParam(':order_id', $order_id, PDO::PARAM_INT);
             $stmt->bindParam(':color', $color);
             $stmt->execute();
         }
         $delete_query_certificate = "DELETE FROM order_certificate WHERE order_id = '{$order_id}'";
         $PDO->query($delete_query_certificate);
         foreach ($certificateitems as $crcitems) {
             $validity = $PDO->query("SELECT certificate.validity, certificate.sum\r                                                                           FROM certificate\r                                                                           WHERE id = '{$crcitems->id}'")->fetch();
             $i = 0;
             while ($i < $crcitems->quantity) {
                 $certificate = $PDO->prepare("INSERT INTO order_certificate (certificate_id,\r                                                                                      order_id,\r                                                                                      code,\r                                                                                      price,\r                                                                                      time_end,\r                                                                                      to_amount,\r                                                                                      active)\r                                                                            VALUES(:certificate_id,\r                                                                                    :order_id,\r                                                                                    :certificate_code,\r                                                                                    :price,\r                                                                                    :time_end,\r                                                                                    :to_amount,\r                                                                                    :active)");
                 $certificate_code = substr(md5(microtime()), rand(0, 5), rand(11, 16));
                 $certificate->bindParam(':certificate_id', $crcitems->id, PDO::PARAM_INT);
                 $certificate->bindParam(':order_id', $order_id, PDO::PARAM_INT);
                 $certificate->bindParam(':price', $crcitems->price, PDO::PARAM_INT);
                 $certificate->bindParam(':certificate_code', $certificate_code, PDO::PARAM_STR);
                 $certificate->bindParam(':time_end', $validity['validity']);
                 $certificate->bindParam(':to_amount', $validity['sum']);
                 $certificate->bindParam(':active', $active);
                 $certificate->execute();
                 $i++;
             }
         }
         $stmt = $PDO->prepare("UPDATE coupons SET active = :active WHERE code = :code");
         $stmt->bindParam(':code', $code);
         $stmt->bindParam(':active', $active);
         $stmt->execute();
         $cart_mail = $cart['cart'];
         if ($email) {
             $user_message = View::factory('admin/order/usermessage', array('name' => $name, 'email' => $email, 'phone' => $phone, 'adress' => $adress, 'city' => $city, 'index' => $index, 'code_certificate' => $code_certificate, 'code' => $code, 'delivery' => $delivery, 'to_amount' => $dataCertificate['to_amount'], 'coupon_discount' => $dataCoupon['discount'], 'cart' => json_decode($cart_mail), 'cert' => $certificateitems))->render();
         }
         $admin_message = View::factory('admin/order/adminmessage', array('name' => $name, 'email' => $email, 'phone' => $phone, 'adress' => $adress, 'city' => $city, 'index' => $index, 'code_certificate' => $code_certificate, 'code' => $code, 'delivery' => $delivery, 'to_amount' => $dataCertificate['to_amount'], 'coupon_discount' => $dataCoupon['discount'], 'cart' => json_decode($cart_mail), 'cert' => $certificateitems))->render();
         Helpers_Email::send(Kohana::$config->load('mailer.admin'), 'Новый заказ ' . $name . ' ' . $phone, $admin_message, true);
         Helpers_Email::send($email, 'Новый заказ ' . $name . ' ' . $phone, $user_message, true);
         exit(json_encode(array('order_id' => $order_id)));
     }
예제 #4
0
파일: Auth.php 프로젝트: ariol/adminshop
 public function action_ajax_light_register()
 {
     if ($this->request->is_ajax()) {
         $email = trim($this->request->post('email'));
         $role = 2;
         $invalidEmail = !filter_var($email, FILTER_VALIDATE_EMAIL);
         $emailExists = ORM::factory('User')->where('email', '=', $email)->find();
         $errors = array('invalid_email' => $invalidEmail, 'email_exists' => $emailExists->loaded());
         $textErrors = array();
         $errors_exists = false;
         foreach ($errors as $key => $error) {
             if ($error) {
                 $errors_exists = true;
             }
         }
         if ($errors['invalid_email']) {
             $textErrors[] = 'Неверный формат email адреса!';
         }
         if ($errors['email_exists']) {
             $textErrors[] = 'Данный email адрес занят!';
         }
         if (!$errors_exists) {
             $token = md5(time() . $email);
             $emailParts = explode('@', $email);
             $password = Text::limit_chars(md5(time() . 'hello world' . $email), 8, '');
             $user = ORM::factory('User');
             $user->name = Arr::get($emailParts, 0);
             $user->username = Arr::get($emailParts, 0);
             $user->email = $email;
             $user->roles = $role;
             $user->password = $password;
             $user->register_token = $token;
             $user->save();
             $message = sprintf("Спасибо за регистрацию <br/>" . "Ваш логин: %s <br/>" . "Ваш пароль: %s <br/>" . "Ваш email: %s <br/>" . "Ссылка для активации: %s", Arr::get($emailParts, 0), $password, $email, HTML::anchor(URL::base('http') . 'module_auth/token?email=' . $email . '&token=' . $token));
             Helpers_Email::send($email, 'Регистрация', $message, true);
         }
         echo json_encode(array('errors' => $textErrors, 'errors_exists' => $errors_exists));
     }
     exit;
 }