/** * @return LibShop */ static function getInstance() { if (empty(self::$instance)) { self::$instance = new self(); } return self::$instance; }
function actSendOrder() { global $ST, $post; $basket = $this->getBasketInfo($post->get()); if ($error = $this->checkOrder($post, $basket)) { echo printJSON(array('error' => $error)); exit; } else { $address = $post->getString('address'); /* Информация о заказчике */ $data = array('phone' => $post->get('phone')); if ($city = $post->get('city')) { $data['city'] = $city; } if ($address) { $data['address'] = $address; } //Добавим реферала if ($refid = $post->getInt('refid')) { $rs = DB::select("SELECT * FROM sc_users WHERE u_id={$refid}"); if ($rs->next()) { $data['refid'] = $post->getInt('refid'); } else { //Если неправильный refid } } if (!$this->getUserId() && $post->getInt('reg') == 1) { //&& $post->exists('want_reg') if ($post->exists('mail')) { $data['login'] = $post->get('mail'); $data['mail'] = $post->get('mail'); if ($post->exists('auto_pass')) { //Всегда назначать пароль $password = substr(md5(time()), 0, 6); $data[] = "password=MD5('" . $password . "')"; } else { $password = $post->get('password'); $data[] = "password=MD5('" . SQL::slashes($password) . "')"; } if (!session_id()) { session_set_cookie_params(3600 * 24 * 15, '/'); session_start(); } $_SESSION['_USER']['u_id'] = $ST->insert('sc_users', $data, 'u_id'); //уведомление о регистрации $this->sendTemplateMail($data['mail'], 'notice_new_user', array('FROM_SITE' => FROM_SITE, 'LOGIN' => $data['login'], 'PASSWORD' => $password)); //уведомление о регистрации админу $this->sendTemplateMail($this->cfg('MAIL'), 'notice_new_user4admin', array('FROM_SITE' => FROM_SITE, 'LOGIN' => $data['login'], 'name' => $data['name'])); $this->noticeICQ($this->cfg('ICQ'), 'Новый пользователь на сайте'); } } elseif ($this->getUserId()) { //Обновим пользователя if (!empty($basket['bonus'])) { $data['bonus'] = $this->getUser('bonus') - $basket['bonus']; $inc = array('userid' => $this->getUserId(), 'sum' => $basket['bonus'], 'balance' => $data['bonus'], 'type' => 'bonus', 'description' => 'Списание бонуса', 'time' => date('Y-m-d H:i:s')); $ST->insert('sc_income', $inc); } $ST->update('sc_users', $data, 'u_id=' . $this->getUserId()); } $this->setUser($data); $data = array('userid' => $this->getUserId(), 'fullname' => $this->getUser('name'), 'mail' => $post->get('mail') ? $post->get('mail') : $this->getUser('mail'), 'pay_system' => $post->get('pay_system'), 'phone' => $post->get('phone'), 'additionally' => $post->get('additionally'), 'price' => $basket['sum'], 'total_price' => $basket['total_sum'], 'order_status' => 0, 'pay_system' => $post->get('pay_system'), 'delivery' => $basket['delivery'], 'pay_bonus' => $basket['bonus'], 'discount' => $basket['discount'], 'margin' => $basket['margin']); if (Cfg::get("SHOP_DELIVERY_ENABLED")) { $data['date'] = $post->get('date') ? dte($post->get('date'), 'Y-m-d') : date('Y-m-d'); $time = $post->getString('time'); if ($t = $this->enum('sh_delivery_time', $time)) { $time = $t; } $delivery_type = 1; //доставка курьером if ($post->getInt('delivery_type')) { $delivery_type = $post->getInt('delivery_type'); } if ($basket['delivery'] === false) { //доставка не возможна $delivery_type = 2; } $data['city'] = $address; $data['address'] = $post->get('city'); $data['delivery_type'] = $delivery_type; } // $order_data=array( // 'from_name'=>$post->get('from_name'), // 'from_phone'=>$post->get('from_phone'), // 'from_city'=>$post->get('from_city'), // 'remember'=>$post->get('remember'), // 'report'=>$post->get('report'), // 'call'=>$post->get('call'), // 'call_no_report'=>$post->get('call_no_report'), // ); // $data['order_data']=printJSON($order_data); // if(!trim($data['address'])){ // $data['address']=serialize(array( //// 'region'=>$post->get('region'), // 'city'=>$post->get('city'), // 'district'=>$post->get('district'), // 'street'=>$post->get('street'), // 'house'=>$post->get('house'), // 'flat'=>$post->get('flat'), // 'porch'=>$post->get('porch'), // 'floor'=>$post->get('floor'), // )); // // } //Добавим заказ $id = LibShop::addOrder($data, $basket['basket']); if ($refid = $post->getInt('refid')) { ShopBonus::addRefAwards($refid, $basket['basket']); } elseif ($refid = ShopBonus::getPromoRefId($post->get('promo'))) { ShopBonus::addRefAwards($refid, $basket['basket']); } $ps_href = ''; if (isset($data['pay_system']) && $data['pay_system'] == 3 && $data['total_price']) { //Если электронные платежи и есть сумма $rs1 = $ST->select("SELECT * FROM sc_pay_system WHERE name='paymaster'"); if ($rs1->next()) { include_once "core/lib/PSPaymaster.class.php"; $ps = new PSPaymaster(unserialize($rs1->get('config'))); $ps->setDesc('Покупка товара'); $ps->setSumm($data['total_price']); $ps->setEmail($this->getUser('mail')); $ps->setOrderNum($id); $ps_href = $ps->getUrl(); } } // $icq_notice = "Новый заказ на сайте {$_SERVER['HTTP_HOST']}\n"; // // // $icq_notice.="Итого: {$basket['sum']}\n"; // $icq_notice.="Заказчик: {$post->get('from_name')}\n"; // $icq_notice.="Контактный телефон: {$post->get('from_phone')}\n"; // $icq_notice.="Адрес: {$post->get('address')}\n"; //// $icq_notice.="Сообщение: {$post->get('comment')}\n"; // $icq_notice.="Время доставки: {$post->get('date')} {$post->get('time')}\n"; //уведомление о заказе пользователю $notice = $data; //+$order_data; if (!empty($notice['date'])) { $notice['date'] = dte($notice['date']); } // $notice['description']=''; // foreach (array('remember','report','call','call_no_report',) as $v){ // $notice['description'].=$this->enum('field_label',@"{$v}_{$notice[$v]}")."<br>"; // } $notice['ps_href'] = ''; if ($ps_href) { $notice['ps_href'] = "Для того, чтобы оплатить заказа перейдите по ссылке <a href=\"{$ps_href}\">ОПЛАТИТЬ</a>"; } $delivery_list = $this->enum('sh_delivery_type'); $pay_system_list = $this->enum('sh_pay_system'); $notice['ORDER_NUM'] = $order_num = $id; // $notice['ORDER_NUM']=$order_num; $notice['NAME'] = $this->getUser('name'); $notice['FROM_SITE'] = FROM_SITE; $notice['basket'] = $this->render(array_merge($basket, array('is_order' => true, 'is_letter' => true)), dirname(__FILE__) . '/basket_content.tpl.php'); $notice['delivery_type'] = @$delivery_list[$notice['delivery_type']]; $notice['pay_system'] = @$pay_system_list[$notice['pay_system']]; include 'function.tpl.php'; if (!empty($notice['address'])) { $notice['address'] = parsAddr($notice['address']); } // $url="http://{$_SERVER['HTTP_HOST']}/prnt/SHET/?id=$id&PHPSESSID=".session_id(); // $url="http://{$_SERVER['HTTP_HOST']}/prnt/SBER/?id=$id&PHPSESSID=".session_id(); // $content=file_get_contents($url); $att = array(); if (isset($data['pay_system']) && $data['pay_system'] == 1) { $url = "http://{$_SERVER['HTTP_HOST']}/prnt/SBERpdf/?id={$id}"; $notice['ps_href'] = "<a href=\"{$url}\">Распечатать счёт</a>"; // $att[]=array('name'=>'Счёт.xls','file'=>$url."&access=allow"); } /* if($post->getInt('is_jur')){ //Печатать не надо $url="http://{$_SERVER['HTTP_HOST']}/prnt/SchetWord/?id=$id"; $notice['ps_href']="<a href=\"{$url}\">Распечатать счёт</a>"; $att[]=array('name'=>'na_oplatu'.date('Y_m_d').'.doc','file'=>$url."&access=allow"); } */ $mail = $post->exists('mail') ? $post->get('mail') : $this->getUser('mail'); if ($mail) { $this->sendTemplateMail($post->get('mail'), 'notice_new_order', $notice, $att); } //уведомление о заказе админу // $mail_contacts=$this->enum('mail_contacts',$this->getRegion()); $this->sendTemplateMail($this->cfg('MAIL'), 'notice_new_order4admin', $notice); // $this->noticeICQ($this->cfg('ICQ'), $icq_notice); $d = $this->getOrderData(); unset($d['additionally']); $this->saveOrderData($d); $this->saveBasketData(array()); // setcookie('basket',null,0,'/');//Очистим корзину Cookie::set('order_id', $id); $redirect_href = "/catalog/success/?id={$id}"; if ($ps_href) { $redirect_href = $ps_href; } echo printJSON(array('id' => $id, 'order_num' => $order_num, 'error' => '', 'count' => $basket['count'], 'delivery' => $data['delivery'], 'total_price' => $data['total_price'], 'ps_href' => $notice['ps_href'], 'redirect_href' => $redirect_href, 'date' => "{$post->get('date')} {$post->get('time')}")); exit; } }