Guest User

Untitled

a guest
Dec 29th, 2018
2,167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 252.24 KB | None | 0 0
  1. <?php
  2.  
  3. class SiteController extends Controller {
  4. /**
  5. * Declares class-based actions.
  6. */
  7. public function actions() {
  8. return array(
  9. // captcha action renders the CAPTCHA image displayed on the contact page
  10. 'captcha' => array('class' => 'CCaptchaAction', 'backColor' => 0xFFFFFF ),
  11. // page action renders "static" pages stored under 'protected/views/site/pages'
  12. // They can be accessed via: index.php?r=site/page&view=FileName
  13. 'page' => array('class' => 'CViewAction' ) );
  14. }
  15.  
  16. public function filters() {
  17. return array('accessControl', // perform access control for CRUD operations
  18. 'ajaxOnly + RegisterAjax + ajaxnews + OrderDo + faktura+EditFaktura+MyCommitmentAjax', );
  19. }
  20.  
  21. public function accessRules()
  22. {
  23. return array(
  24.  
  25. array(
  26. 'allow',
  27. 'actions' => array('auth','exchange','testlayout','forgetpassword','resetpassword','login','registerajax','mycommitmentajax','activate','smscheck','thanks', 'ordersum'),
  28. 'users' => array('?'),
  29. ),
  30.  
  31. array('allow',
  32. 'actions'=>array('OrderDo','Settings','order','kupon','kuponal','bundle','test', 'messages', 'messagedetail', 'tasks', 'task', 'endTask', 'addTask', 'logout',
  33. 'Balance','Profile','succesorder','myorder','faktura','newInvoice','addBeyenname','errorPayment','pay','pymnt','successPayment','ulinks','complate','EditFaktura',
  34. 'Orderdetails', 'Orderedit','Orderdelete','Deleteorder','checkBalance','payShipping','paymentproduct','callbackpayment','callbackpaymentmore','basketaccept',
  35. 'paymentproductpaytr','callbackpaymentpaytrsuccess','callbackpaymentpaytrfailure','CancelCourierOrder','EmailConfirm','EmailActivate','TestMandril',
  36. 'Basketdetails','Basketedit','BasketDelete','AddBasket',
  37. 'MultiPayShipping','ShippingWithCard','MultiPayShipping1',
  38. 'MyCommitment','AddCommitment','DeleteCommitment','EditCommitment'
  39.  
  40.  
  41. ),
  42. 'users'=>array('@'),
  43. ),
  44. array('allow',
  45. 'actions' => array('post', 'orderTracking','fromUsa','mailgun','login','auth','d','dd','index','sms','CalcPrice','size','recomended','sites','news','contact','ordernow','addLink','addLinks','addBasketLink','deleteNotPaidOrders',
  46. 'error','error2','ajaxnews','captcha','faq','GetParentCategories','GetChildCategories','GetLinks','Getshopsite',
  47. 'gettourslider','orderfromapp','Ajaxlogin','RegisterAjaxApp','Getlinkfromuser','Smsactive','getmenu','getprofile',
  48. 'Apptoken','Notificationlist','Howitworks','register','mailgrabber','agreement','ordersum','paytrinfo','getpostivr',
  49. 'postturkey','getturkeyorders','updateturkeyorder','updateorderturkey','userslocation','etgb','etgb2','getorderswithoutinvoice','orderfrommarkam','monthlyinvoices'/*'multiplesms'*/),
  50. 'users' => array('*')
  51. ),
  52. array('deny',
  53. 'users' => array('*'),
  54. ),
  55.  
  56. );
  57. }
  58.  
  59. public function actionFromUsa(){
  60. /*error_reporting(E_ALL);
  61. ini_set('display_errors', 1);*/
  62. $sql = "SELECT * FROM cms_brcd_orders WHERE stat = '0' GROUP BY users_id ";
  63. $orders = Yii::app()->db->createCommand($sql)->queryAll();
  64. //var_dump($orders); die;
  65. foreach($orders as $item){
  66.  
  67.  
  68. $u_id = $item['users_id'] + 100000;
  69. $message_text = "Hormetli ".ucfirst($item['name'])." ".ucfirst($item['surname']).", Sifarish etdiyiniz mehsul Bakida ofisimize chatmishdir. Kuryer sifarishi uchun: mover.az/d?u=".$u_id;
  70. Sms::Send($item['mobile'],$message_text);
  71.  
  72. $order = Orders::model()->findByPk($item['order_id']);
  73. $message = Yii::app()->mailgun->newMessage();
  74.  
  75. $message->setFrom('info@mover.az', 'Mover MMC');
  76. $message->addTo($item['email'], ucfirst($item['name'])." ".ucfirst($item['surname']));
  77. $message->setSubject('BAĞLAMANIZ GƏLDİ');
  78.  
  79. $message->renderHtml($item['country_id'].'_5', array('order' => $order));
  80.  
  81. $message->send();
  82.  
  83.  
  84. $sql = "UPDATE cms_brcd_orders SET stat = '1' WHERE id = '".$item['id']."' ";
  85. $orders = Yii::app()->db->createCommand($sql)->queryAll();
  86. }
  87. }
  88.  
  89. public function actionMailgun(){
  90. $message = Yii::app()->mailgun->newMessage();
  91.  
  92. $message->setFrom('info@mover.az', 'Mover MMC');
  93. $message->addTo('sahib777.5@mail.ru', 'Sahib Huseynov');
  94. $message->setSubject('Mailgun API library test');
  95. //$message->renderText('myView', array('myParam' => 'Awesome!'));
  96. $message->setText('salam');
  97. if($message->send()) echo 1;
  98. echo $message->send();
  99. }
  100.  
  101. public function actionDd(){
  102. $this->pageTitle = 'Mover.az - Kuryer sifarişi';
  103. if(isset($_GET['u'])){
  104. if(intval($_GET["u"])){
  105. $user_id = (int) $_GET['u'] - 100000;
  106. }else{
  107. $user_ids = $_GET["u"];
  108. $sql="SELECT * FROM `cms_users` WHERE email ='$user_ids'";
  109. $cc = Yii::app()->db->createCommand($sql)->queryAll();
  110. $user_id = $cc[0]["id"];
  111. }
  112.  
  113. $User = Users::model()->findByPk($user_id);
  114. $model = new DeliveryAddress;
  115. $this->render('delivery_address', ['user' => $User, 'model' => $model]);
  116. }
  117.  
  118. if(isset($_POST['DeliveryAddress'])){
  119. $address = $_POST['DeliveryAddress']['address'];
  120. $region = $_POST['DeliveryAddress']['region'];
  121. $urgent = $_POST['DeliveryAddress']['urgent'];
  122. $naddress = $region.": ".$address;
  123. $users_id = $_POST['DeliveryAddress']['users_id'];
  124. $DeliveryAddress = new DeliveryAddress();
  125. $DeliveryAddress->address = $naddress;
  126. $DeliveryAddress->urgent = $urgent;
  127. $DeliveryAddress->users_id = $users_id;
  128. $DeliveryAddress->date = date('Y-m-d H:i:s');
  129. $DeliveryAddress->date = date('Y-m-d H:i:s');
  130. $DeliveryAddress->save(false);
  131. echo CJSON::encode(['success' => true]);
  132. Yii::app()->end();
  133. }
  134.  
  135. }
  136.  
  137. public function actionulinks(){
  138. if(empty(Yii::app()->user->id)){
  139. $this->redirect(Yii::app()->homeUrl);
  140. }else{
  141. $this->render('ulinksforupdate', ['userid' => Yii::app()->user->id]);
  142. }
  143. }
  144.  
  145. public function actionD(){
  146.  
  147.  
  148. $this->pageTitle = 'Mover.az - Kuryer sifarişi';
  149. if(isset($_GET['u'])){
  150. if(intval($_GET["u"])){
  151. $user_id = (int) $_GET['u'] - 100000;
  152. }else{
  153. $user_ids = $_GET["u"];
  154. $sql="SELECT * FROM `cms_users` WHERE email ='$user_ids'";
  155. $cc = Yii::app()->db->createCommand($sql)->queryAll();
  156. $user_id = $cc[0]["id"];
  157. }
  158.  
  159. $User = Users::model()->findByPk($user_id);
  160. $model = new DeliveryAddress;
  161. $this->render('delivery_address2', ['user' => $User, 'model' => $model]);
  162. }
  163.  
  164.  
  165. if(isset($_POST['DeliveryAddress']))
  166. {
  167. $address = $_POST['DeliveryAddress']['address'];
  168. $region = intval($_POST['DeliveryAddress']['region']);
  169. $orders = $_POST['DeliveryAddress']['orders'];
  170.  
  171. $urgent = $_POST['DeliveryAddress']['urgent'];
  172.  
  173. $courier_amount;
  174. if($urgent == 1)
  175. {
  176. $courier_amount = 3;
  177. }
  178.  
  179. $sql="SELECT * FROM cms_districts WHERE id='$region'";
  180.  
  181. $district_price = Yii::app()->db->createCommand($sql)->queryRow();
  182.  
  183. $regionPrice = $district_price["price"];
  184.  
  185.  
  186. if(!$district_price){
  187. return $this->redirect('/');
  188. }
  189. $tot = 0;
  190. $sum = 0;
  191. $order_all= explode(',',$_POST['DeliveryAddress']['orders']);
  192. array_pop($order_all);
  193.  
  194. $criteria = new CDbCriteria();
  195. $criteria ->condition = 'users_id=:id';
  196. $criteria -> params = array(":id" => Yii::app()->user->id);
  197. $criteria->addInCondition('id', $order_all);
  198. $result = Orders::model()->findAll($criteria);
  199.  
  200. if($result)
  201. {
  202. foreach( $result as $order)
  203. {
  204. $MehsulCodes = MehsulCodes::model()->findByPk((int) $order->type);
  205. $tarif = ($order->date1 >= '2018-02-15' || $order->date1 == '0000-00-00' ||$order->date1 < '2013-01-01');
  206. if($order->paid == 0)
  207. {
  208. $tot += Orders::calculateShipping($MehsulCodes->type, $order->width, $order->height, $order->length,$order->weight, $tarif, $order->country_id);
  209. }
  210.  
  211. }
  212.  
  213.  
  214. $tot =$tot*1.7;
  215. $user_info = Users::model()->findByPk(Yii::app()->user->id);
  216. if($user_info->balance<0)
  217. {
  218. $sum = $courier_amount+$tot-$user_info->balance+$regionPrice;
  219. }
  220. else
  221. {
  222. $sum = $courier_amount+$tot+$regionPrice;
  223. }
  224.  
  225. $totalprice = $_POST['DeliveryAddress']['totalprice'];
  226. $naddress = $address;
  227. $users_id = $_POST['DeliveryAddress']['users_id'];
  228. $DeliveryAddress = new DeliveryAddressNew();
  229. $DeliveryAddress->address = $naddress;
  230. $DeliveryAddress->urgent = $urgent;
  231. $DeliveryAddress->totalprice = number_format($sum,2);
  232. $DeliveryAddress->district_id = $region;
  233. $DeliveryAddress->users_id = $users_id;
  234. $DeliveryAddress->date = date('Y-m-d H:i:s');
  235. $DeliveryAddress->date = date('Y-m-d H:i:s');
  236. $DeliveryAddress->save(false);
  237.  
  238.  
  239. $lastid = $DeliveryAddress->id;
  240. $command = Yii::app()->db->createCommand();
  241.  
  242. foreach ($order_all as $key => $value) {
  243. $command->insert('cms_delivery_order', array(
  244. 'order_id'=>$value,
  245. 'delivery_id'=>$lastid,
  246. ));
  247.  
  248. }
  249. echo CJSON::encode(['success' => true]);
  250. Yii::app()->end();
  251. }
  252.  
  253.  
  254. }
  255.  
  256.  
  257. }
  258. public function actionExchange(){
  259. $url = "https://www.yapikredi.com.az/az/mezenne";
  260. $file = file_get_contents($url);
  261. preg_match_all('#<table[^>]+>(.+?)</table>#ims', $file, $table);
  262. preg_match_all('#<td>(.+?)</td>#ims', $table[1][0], $td);
  263. $data = [];
  264. $data['usd_buy'] = $td[1][2];
  265. $data['usd_sell'] = $td[1][3];
  266. $data['eur_buy'] = $td[1][8];
  267. $data['eur_sell'] = $td[1][9];
  268. $data['rub_buy'] = $td[1][14];
  269. $data['rub_sell'] = $td[1][15];
  270.  
  271.  
  272. $this->otherBanks($data);
  273. }
  274.  
  275. public function otherBanks($data){
  276.  
  277.  
  278. if(isset($data['usd_buy'])){
  279. $Data = new BankExchange();
  280. $Data->organization = 'yapikredi';
  281. $Data->date = date('Y-m-d');
  282. $Data->currency_code = 'USD';
  283. $Data->buy = ($data['usd_buy'] == '---')? 0 : $data['usd_buy'];
  284. $Data->sell = ($data['usd_sell'] == '---')? 0 : $data['usd_sell'];
  285. $Data->save();
  286. }
  287.  
  288. if(isset($data['eur_buy'])){
  289. $Data = new BankExchange();
  290. $Data->organization = 'yapikredi';
  291. $Data->date = date('Y-m-d');
  292. $Data->currency_code = 'EUR';
  293. $Data->buy = ($data['eur_buy'] == '---')? 0 : $data['eur_buy'];
  294. $Data->sell = ($data['eur_sell'] == '---')? 0 : $data['eur_sell'];
  295. $Data->save();
  296. }
  297.  
  298. if(isset($data['rub_buy'])){
  299. $Data = new BankExchange();
  300. $Data->organization = 'yapikredi';
  301. $Data->date = date('Y-m-d');
  302. $Data->currency_code = 'RUB';
  303. $Data->buy = ($data['rub_buy'] == '---')? 0 : $data['rub_buy'];
  304. $Data->sell = ($data['rub_sell'] == '---')? 0 : $data['rub_sell'];
  305. $Data->save();
  306. }
  307.  
  308. if(isset($data['try_buy'])){
  309. $Data = new BankExchange();
  310. $Data->organization = 'yapikredi';
  311. $Data->date = date('Y-m-d');
  312. $Data->currency_code = 'TRY';
  313. $Data->buy = ($data['try_buy'] == '---')? 0 : $data['try_buy'];
  314. $Data->sell = ($data['try_sell'] == '---')? 0 : $data['try_sell'];
  315. $Data->save();
  316. }
  317.  
  318. }
  319.  
  320. public function actionFaq()
  321. {
  322. if(Yii::app()->language=="az")
  323. {
  324. $this->pageTitle = 'Ən çox verilən suallar | Mover.az';
  325. Yii::app() -> clientScript -> registerMetaTag(Yii::t('text', 'mover.az, türkiyə alış-veriş saytları, türkiyədən çatdırılma, paltar sifarişi, türk geyimləri'), 'keywords');
  326. }
  327. elseif(Yii::app()->language=="en")
  328. {
  329. $this->pageTitle = 'F.A.Q | Mover.az';
  330. Yii::app() -> clientScript -> registerMetaTag(Yii::t('text', 'mover.az, online shopping sites turkey, delivery from turkey, dress order, turkish dress'), 'keywords');
  331. }
  332. $this->render("fag");
  333.  
  334. }
  335.  
  336. public function actionPay()
  337. {
  338. //$mebleg = floatval($_POST["mebleg"]);
  339.  
  340.  
  341. if (isset($_POST["mebleg"]) && !empty($_POST["mebleg"]) ){
  342. // && is_numeric($_POST["mebleg"])
  343.  
  344. $mebleg = $_POST["mebleg"];
  345.  
  346. if($mebleg<=50)
  347. {
  348. $mebleg = str_replace(",",".",$mebleg);
  349. $desc = CHtml::encode($_POST["desc"]);
  350. $desc = str_replace(' ','_',$desc);
  351. $desc = MyClass::slugify($desc);
  352.  
  353. $reference=rand(000000, 999999);
  354. $payment = new Millikart($mebleg,$reference,$desc);
  355. $response = $payment->getURL();
  356. header("Location: ".$response);
  357. }
  358. else
  359. $this->redirect(CHtml::normalizeUrl(array("site/balance")));
  360.  
  361.  
  362. }else{
  363.  
  364. $this->redirect(Yii::app()->homeUrl);
  365. }
  366.  
  367. }
  368.  
  369. public function actionPymnt(){
  370.  
  371. if (isset($_POST["mebleg"]) && !empty($_POST["mebleg"]) ){
  372.  
  373. $amount = abs($_POST["mebleg"]);
  374.  
  375. if( is_numeric($amount) && $amount <= 50 ){
  376.  
  377. $desc = CHtml::encode($_POST["desc"]);
  378. $desc = str_replace(' ','_',$desc);
  379. $desc = MyClass::slugify($desc);
  380.  
  381. $payment = new PashaBank($amount,$desc);
  382. $t_id = $payment->setTid();
  383.  
  384. $topupBalnce = new TopupBalanceWpc();
  385. $topupBalnce->user_id = Yii::app()->user->id;
  386. $topupBalnce->transaction_id = $t_id;
  387. $topupBalnce->balance = $amount;
  388. $topupBalnce->status_id = 0;
  389. $topup_save = $topupBalnce->save();
  390.  
  391. if($topup_save)
  392. {
  393. $payment->runPayment($t_id);
  394. }
  395. else
  396. {
  397. $this->render('paymentsuccess',array("res"=>"Ödənişdə xəta baş verdi","mebleg"=>$amount));
  398. }
  399.  
  400.  
  401. //$this->render('paymentsuccess',array("mebleg"=>$amount));
  402. }else{
  403. $this->redirect(CHtml::normalizeUrl(array("site/balance")));
  404. }
  405.  
  406.  
  407. }else{
  408.  
  409. echo $amount = $_POST["mebleg"];
  410. }
  411.  
  412. }
  413.  
  414. public function actionPaymentproduct($id=0)
  415. {
  416. include "/home/mover.az/protected/components/iyzipay/samples/config.php";
  417. $id = intval($id);
  418.  
  419. $getLoginUser = Users::model()->with('city')->findByPk(Yii::app()->user->id);
  420.  
  421. if(isset($_GET['id']) && !empty($_GET['id']))
  422. {
  423. $getProduct = Myorder::model()->findByAttributes(array("id"=>$id,"users_id"=>Yii::app()->user->id,"basket"=>'0'));
  424.  
  425. if($getProduct && $getLoginUser)
  426. {
  427. if($getProduct->count==0)
  428. $count = 1;
  429. else
  430. $count = $getProduct->count;
  431.  
  432. $conversation_id = $getLoginUser->user_key;
  433.  
  434. if($getProduct->order_type==1)
  435. $price = $getProduct->price;
  436. else
  437. $price = $getProduct->price+$getProduct->price*0.05;
  438.  
  439. $request = new \Iyzipay\Request\CreateCheckoutFormInitializeRequest();
  440. $request->setLocale(\Iyzipay\Model\Locale::TR);
  441. $request->setConversationId($conversation_id);
  442. $request->setPrice($price*$count);
  443. $request->setPaidPrice($price*$count);
  444. $request->setCurrency(\Iyzipay\Model\Currency::TL);
  445. $request->setBasketId($getProduct->id);
  446. $request->setPaymentGroup(\Iyzipay\Model\PaymentGroup::PRODUCT);
  447. $request->setCallbackUrl("https://mover.az/callbackpayment");
  448. $request->setEnabledInstallments(array(2, 3, 6, 9));
  449.  
  450. $buyer = new \Iyzipay\Model\Buyer();
  451. $buyer->setId(Yii::app()->user->id);
  452. $buyer->setName($getLoginUser->name);
  453. $buyer->setSurname($getLoginUser->surname);
  454. $buyer->setGsmNumber($getLoginUser->mobile);
  455. $buyer->setEmail($getLoginUser->email);
  456. $buyer->setIdentityNumber($getLoginUser->user_key);
  457. //$buyer->setLastLoginDate("2015-10-05 12:43:35");
  458. //$buyer->setRegistrationDate("2013-04-21 15:12:09");
  459. $buyer->setRegistrationAddress($getLoginUser->address);
  460. $buyer->setIp($_SERVER['REMOTE_ADDR']);
  461. $buyer->setCity("Istanbul");
  462. $buyer->setCountry("Turkey");
  463. //$buyer->setZipCode("34732");
  464.  
  465. $request->setBuyer($buyer);
  466. $shippingAddress = new \Iyzipay\Model\Address();
  467. $shippingAddress->setContactName($getLoginUser->name." ".$getLoginUser->surname);
  468. $shippingAddress->setCity("Istanbul");
  469. $shippingAddress->setCountry("Turkey");
  470. $shippingAddress->setAddress($getLoginUser->address);
  471. //$shippingAddress->setZipCode("34742");
  472. $request->setShippingAddress($shippingAddress);
  473.  
  474. $billingAddress = new \Iyzipay\Model\Address();
  475. $billingAddress->setContactName($getLoginUser->name." ".$getLoginUser->surname);
  476. $billingAddress->setCity("Istanbul");
  477. $billingAddress->setCountry("Turkey");
  478. $billingAddress->setAddress($getLoginUser->address);
  479. //$billingAddress->setZipCode("34742");
  480. $request->setBillingAddress($billingAddress);
  481.  
  482. $basketItems = array();
  483. $firstBasketItem = new \Iyzipay\Model\BasketItem();
  484. $firstBasketItem->setId($getProduct->id);
  485. $firstBasketItem->setName($getProduct->comment);
  486. $firstBasketItem->setCategory1("product");
  487. $firstBasketItem->setCategory2("product");
  488. $firstBasketItem->setItemType(\Iyzipay\Model\BasketItemType::PHYSICAL);
  489. $firstBasketItem->setPrice($price*$count);
  490. $basketItems[0] = $firstBasketItem;
  491.  
  492. $request->setBasketItems($basketItems);
  493. }
  494. else
  495. $request = '';
  496.  
  497. $datatype = "get";
  498. }
  499. elseif(isset($_POST['pay_submit']) and isset($_POST['pay']))
  500. {
  501. $pay = implode(",",$_POST['pay']);
  502.  
  503. $sql="
  504. SELECT * FROM `cms_myorder` WHERE id IN (".$pay.")
  505. ";
  506.  
  507. $myorders = Yii::app()->db->createCommand($sql)->queryAll();
  508.  
  509. // var_dump($myorders);
  510.  
  511. if($myorders)
  512. {
  513. $a = 0;
  514. $i = 1;
  515. $ids = '';
  516. foreach ($myorders as $myorder)
  517. {
  518. if($i==count($myorders))
  519. $delimeter = '';
  520. else
  521. $delimeter = '-';
  522.  
  523. if($myorder['count']==0)
  524. $count_myorder = 1;
  525. else
  526. $count_myorder = $myorder['count'];
  527.  
  528. if($myorder['order_type']==1)
  529. $price_end = $myorder['price'];
  530. else
  531. $price_end = $myorder['price']+$myorder['price']*0.05;
  532.  
  533. $ids .= $myorder['id'].$delimeter;
  534. $a += $price_end*$count_myorder;
  535. $i++;
  536. }
  537.  
  538. $conversation_id = $getLoginUser->user_key;
  539.  
  540. // $rand_basket = rand(000000,999999);
  541.  
  542. $request = new \Iyzipay\Request\CreateCheckoutFormInitializeRequest();
  543. $request->setLocale(\Iyzipay\Model\Locale::TR);
  544. $request->setConversationId($conversation_id);
  545. $request->setPrice($a);
  546. $request->setPaidPrice($a);
  547. $request->setCurrency(\Iyzipay\Model\Currency::TL);
  548. $request->setBasketId($ids);
  549. $request->setPaymentGroup(\Iyzipay\Model\PaymentGroup::PRODUCT);
  550. $request->setCallbackUrl("https://mover.az/callbackpaymentmore");
  551. $request->setEnabledInstallments(array(2, 3, 6, 9));
  552.  
  553. $buyer = new \Iyzipay\Model\Buyer();
  554. $buyer->setId(Yii::app()->user->id);
  555. $buyer->setName($getLoginUser->name);
  556. $buyer->setSurname($getLoginUser->surname);
  557. $buyer->setGsmNumber($getLoginUser->mobile);
  558. $buyer->setEmail($getLoginUser->email);
  559. $buyer->setIdentityNumber($getLoginUser->user_key);
  560. //$buyer->setLastLoginDate("2015-10-05 12:43:35");
  561. //$buyer->setRegistrationDate("2013-04-21 15:12:09");
  562. $buyer->setRegistrationAddress($getLoginUser->address);
  563. $buyer->setIp($_SERVER['REMOTE_ADDR']);
  564. $buyer->setCity("Istanbul");
  565. $buyer->setCountry("Turkey");
  566. //$buyer->setZipCode("34732");
  567.  
  568. $request->setBuyer($buyer);
  569. $shippingAddress = new \Iyzipay\Model\Address();
  570. $shippingAddress->setContactName($getLoginUser->name." ".$getLoginUser->surname);
  571. $shippingAddress->setCity("Istanbul");
  572. $shippingAddress->setCountry("Turkey");
  573. $shippingAddress->setAddress($getLoginUser->address);
  574. //$shippingAddress->setZipCode("34742");
  575. $request->setShippingAddress($shippingAddress);
  576.  
  577. $billingAddress = new \Iyzipay\Model\Address();
  578. $billingAddress->setContactName($getLoginUser->name." ".$getLoginUser->surname);
  579. $billingAddress->setCity("Istanbul");
  580. $billingAddress->setCountry("Turkey");
  581. $billingAddress->setAddress($getLoginUser->address);
  582. //$billingAddress->setZipCode("34742");
  583. $request->setBillingAddress($billingAddress);
  584.  
  585. $basketItems = array();
  586.  
  587. $sql="
  588. SELECT * FROM `cms_myorder` WHERE id IN (".$pay.")
  589. ";
  590.  
  591. $myorders2 = Yii::app()->db->createCommand($sql)->queryAll();
  592.  
  593. $i=0;
  594. foreach ($myorders2 as $myorder)
  595. {
  596. if($myorder['count']==0)
  597. $count = 1;
  598. else
  599. $count = $myorder['count'];
  600.  
  601. if($myorder['order_type']==1)
  602. $price_end = $myorder['price'];
  603. else
  604. $price_end = $myorder['price']+$myorder['price']*0.05;
  605.  
  606. $firstBasketItem = new \Iyzipay\Model\BasketItem();
  607. $firstBasketItem->setId($myorder['id']);
  608. $firstBasketItem->setName($myorder['comment']);
  609. $firstBasketItem->setCategory1("product");
  610. $firstBasketItem->setCategory2("product");
  611. $firstBasketItem->setItemType(\Iyzipay\Model\BasketItemType::PHYSICAL);
  612. $firstBasketItem->setPrice($price_end*$count);
  613. $basketItems[$i] = $firstBasketItem;
  614.  
  615. $i++;
  616. }
  617.  
  618. $request->setBasketItems($basketItems);
  619.  
  620. $datatype = "post";
  621.  
  622. $getProduct = $myorders;
  623. }
  624. else
  625. $this->redirect(Yii::app()->homeUrl);
  626.  
  627. }
  628. else $this->redirect(CHtml::normalizeUrl(array("site/order")));
  629.  
  630. $this->render('paymentproduct',array("getProduct"=>$getProduct,"request"=>$request,"datatype"=>$datatype));
  631. }
  632.  
  633. public function actionMessages(){
  634. $this->pageTitle = Yii::t('text','Amerikadan və Türkiyədən çatdırılma xidməti | Mover.az');
  635. $criteria = new CDbCriteria;
  636. $criteria->condition = "user_id= :user_id";
  637. $criteria->order = 'id desc';
  638. $criteria->params = array(':user_id' => (int)Yii::app()->user->id);
  639. $messages = Messages::model()->findAll($criteria);
  640. $cr = new CDbCriteria;
  641. $cr->condition = "user_id= :user_id and readen = 0";
  642. $cr->params = array(':user_id' => (int)Yii::app()->user->id);
  643. $msg = Messages::model()->findAll($cr);
  644. foreach($msg as $item){
  645. $item->readen = 1;
  646. $item->save(false);
  647. }
  648. $this->render('messages', array('messages' => $messages));
  649. }
  650.  
  651. public function actionTasks(){
  652.  
  653. $this->pageTitle = Yii::t('text','Amerikadan və Türkiyədən çatdırılma xidməti | Mover.az');
  654. $criteria = new CDbCriteria;
  655. $criteria->with = 'taskComments';
  656. $criteria->condition = "t.creator= :user_id";
  657. $criteria->order = 't.id desc';
  658. $criteria->params = array(':user_id' => (int)Yii::app()->user-> id);
  659. $tasks = Tasks::model()->findAll($criteria);
  660. $model = new Tasks();
  661. $this->render('tasks', array('tasks' => $tasks, 'model' => $model));
  662. }
  663.  
  664. public function actionTask($id){
  665. if(isset($_POST['comment'])){
  666. $comment = strip_tags($_POST['comment']);
  667. $model = new TaskComments;
  668. $model->task_id = (int) $id;
  669. $model->author_id = (int)Yii::app()->user->id;
  670. $model->comment = $comment;
  671. $model->created_at = date('Y-m-d H:I:S');
  672. $model->save(false);
  673. $Task = Tasks::model()->findByPk($model->task_id);
  674. $Task->answered = 0;
  675. $Task->total_unread_messages = 0;
  676. $Task->save(false);
  677. $this->redirect(CHtml::normalizeUrl(array("site/task/".(int) $id)));
  678. }else{
  679. $this->pageTitle = Yii::t('text','Amerikadan və Türkiyədən çatdırılma xidməti | Mover.az');
  680.  
  681. $criteria = new CDbCriteria;
  682. $criteria->with = 'taskComments';
  683. $criteria->condition = "t.creator= :user_id and t.id = :id";
  684. $criteria->order = 't.id asc';
  685. $criteria->params = array(':user_id' => (int)Yii::app()->user->id, ':id' => (int) $id);
  686.  
  687. $tasks = Tasks::model()->find($criteria);
  688. $Task = Tasks::model()->findByPk((int) $id);
  689. $Task->total_unread_messages = 0;
  690. $Task->save(false);
  691.  
  692. $this->render('task_details', array('tasks' => $tasks));
  693. }
  694.  
  695. }
  696.  
  697. public function actionAddTask(){
  698. $model = new Tasks;
  699. if (isset($_POST['Tasks'])) {
  700. $newPhoto = CUploadedFile::getInstance($model, 'file');
  701. $model->kime = $_POST['Tasks']['kime'];
  702. $model->creator = Yii::app()->user->id;
  703. $model->status = 1;
  704. $model->baslama_tarixi = date('Y-m-d H:i:s');
  705. $model->prioritet = $_POST['Tasks']['prioritet'];
  706. $this -> performAjaxValidation($model);
  707. $model->ad = strip_tags($_POST['Tasks']['ad']);
  708. $model->melumat = strip_tags($_POST['Tasks']['melumat']);
  709. $model->link = strip_tags($_POST['Tasks']['link']);
  710. $model->mail = Yii::app()->user->getEmail();
  711. $model->fullname = Yii::app()->user->getFirstName()." ".Yii::app()->user->getSurname();
  712. if ($model->validate()) {
  713. $model->file = empty($newPhoto) ? $model->file : $newPhoto;
  714. if(!empty($newPhoto)) {
  715. $a = pathinfo($name);
  716. if($a["extension"]!="jpg" OR $a["extension"]!="png" OR $a["extension"]!="pdf" ){
  717. die( "olmaz");
  718. }
  719. $photoPath = Yii::app()->params['tasks_path'];
  720.  
  721. if (!file_exists($photoPath)) {
  722. mkdir($photoPath, 0777, true);
  723. }
  724. $name = time() . $newPhoto->getName();
  725.  
  726. $a = pathinfo($name);
  727. $name = md5($a['filename']) . "." . $a['extension'];
  728.  
  729.  
  730. $model->file->saveAs($photoPath . $name);
  731. $model->file = $name;
  732. }
  733. if (!$model->save(false)) {
  734. echo CJSON::encode($model->getErrors());
  735. Yii::app()->end();
  736. }
  737. echo CJSON::encode(array('status' => 'success', 'alert' => Yii::t('text', 'Sorğunuz qəbul edildi qısam müddət ərzində sizə cavab veriləcək')));
  738. Yii::app()->end();
  739. }else{
  740. $error = CActiveForm::validate($model);
  741. echo $error;
  742. Yii::app() -> end();
  743. }
  744. }
  745. }
  746.  
  747. public function actionAddTaskVoice(){
  748.  
  749. }
  750.  
  751. public function actionEndTask($id){
  752. $model = Tasks::model()->findByPk((int) $id);
  753. $model->status = 0;
  754. $model->bitme_tarixi = date('Y-m-d H:i:s');
  755. $model->save(false);
  756. echo CJSON::encode(array('status' => 'success'));
  757. Yii::app()->end();
  758.  
  759. }
  760.  
  761. public function actionPaymentproductpaytr($id=0)
  762. {
  763. $id = intval($id);
  764.  
  765. $getLoginUser = Users::model()->with('city')->findByPk(Yii::app()->user->id);
  766.  
  767. if(isset($_GET['id']) && !empty($_GET['id']))
  768. {
  769. $getProduct = Myorder::model()->findByAttributes(array("id"=>$id,"users_id"=>Yii::app()->user->id,"basket"=>'0'));
  770.  
  771. if($getProduct && $getLoginUser)
  772. {
  773. if($getProduct->count==0)
  774. $count = 1;
  775. else
  776. $count = $getProduct->count;
  777.  
  778. if($getProduct->order_type==1)
  779. $price = $getProduct->price;
  780. else
  781. $price = $getProduct->price+$getProduct->price*0.05;
  782.  
  783. ## 1. ADIM için örnek kodlar ##
  784.  
  785. ####################### DÜZENLEMESİ ZORUNLU ALANLAR #######################
  786. #
  787. ## API Entegrasyon Bilgileri - Mağaza paneline giriş yaparak BİLGİ sayfasından alabilirsiniz.
  788. $merchant_id = '109349';
  789. $merchant_key = 'khPZ6dN4gC8aZ4e9';
  790. $merchant_salt = 'BLeRAbrwku83Mrk8';
  791. #
  792. ## Müşterinizin sitenizde kayıtlı veya form vasıtasıyla aldığınız eposta adresi
  793. $email = $getLoginUser->email;
  794. #
  795. ## Tahsil edilecek tutar.
  796. $payment_amount = round($price*100); //9.99 için 9.99 * 100 = 999 gönderilmelidir.
  797. #
  798. ## Sipariş numarası: Her işlemde benzersiz olmalıdır!! Bu bilgi bildirim sayfanıza yapılacak bildirimde geri gönderilir.
  799. $merchant_oid = $getLoginUser->id.rand(0,9999);
  800. #
  801. ## Müşterinizin sitenizde kayıtlı veya form aracılığıyla aldığınız ad ve soyad bilgisi
  802. $user_name = $getLoginUser->name." ".$getLoginUser->surname;
  803. #
  804. ## Müşterinizin sitenizde kayıtlı veya form aracılığıyla aldığınız adres bilgisi
  805. $user_address = $getLoginUser->address;
  806. #
  807. ## Müşterinizin sitenizde kayıtlı veya form aracılığıyla aldığınız telefon bilgisi
  808. $user_phone = $getLoginUser->mobile;
  809. #
  810. ## Başarılı ödeme sonrası müşterinizin yönlendirileceği sayfa
  811. ## !!! Bu sayfa siparişi onaylayacağınız sayfa değildir! Yalnızca müşterinizi bilgilendireceğiniz sayfadır!
  812. ## !!! Siparişi onaylayacağız sayfa "Bildirim URL" sayfasıdır (Bakınız: 2.ADIM Klasörü).
  813. $merchant_ok_url = "https://www.mover.az/callbackpaymentpaytrsuccess";
  814. #
  815. ## Ödeme sürecinde beklenmedik bir hata oluşması durumunda müşterinizin yönlendirileceği sayfa
  816. ## !!! Bu sayfa siparişi iptal edeceğiniz sayfa değildir! Yalnızca müşterinizi bilgilendireceğiniz sayfadır!
  817. ## !!! Siparişi iptal edeceğiniz sayfa "Bildirim URL" sayfasıdır (Bakınız: 2.ADIM Klasörü).
  818. $merchant_fail_url = "https://www.mover.az/callbackpaymentpaytrfailure";
  819. #
  820. ## Müşterinin sepet/sipariş içeriği
  821. $user_basket = base64_encode(json_encode(array(
  822. array($getProduct->comment, $price, $count) // 1. ürün (Ürün Ad - Birim Fiyat - Adet )
  823. )));
  824. #
  825. /* ÖRNEK $user_basket oluşturma - Ürün adedine göre array'leri çoğaltabilirsiniz
  826. $user_basket = base64_encode(json_encode(array(
  827. array("Örnek ürün 1", "18.00", 1), // 1. ürün (Ürün Ad - Birim Fiyat - Adet )
  828. array("Örnek ürün 2", "33.25", 2), // 2. ürün (Ürün Ad - Birim Fiyat - Adet )
  829. array("Örnek ürün 3", "45.42", 1) // 3. ürün (Ürün Ad - Birim Fiyat - Adet )
  830. )));
  831. */
  832. ############################################################################################
  833.  
  834. ## Kullanıcının IP adresi
  835. if( isset( $_SERVER["HTTP_CLIENT_IP"] ) ) {
  836. $ip = $_SERVER["HTTP_CLIENT_IP"];
  837. } elseif( isset( $_SERVER["HTTP_X_FORWARDED_FOR"] ) ) {
  838. $ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
  839. } else {
  840. $ip = $_SERVER["REMOTE_ADDR"];
  841. }
  842.  
  843. ## !!! Eğer bu örnek kodu sunucuda değil local makinanızda çalıştırıyorsanız
  844. ## buraya dış ip adresinizi (https://www.whatismyip.com/) yazmalısınız. Aksi halde geçersiz paytr_token hatası alırsınız.
  845. $user_ip=$ip;
  846. ##
  847.  
  848. ## İşlem zaman aşımı süresi - dakika cinsinden
  849. $timeout_limit = "30";
  850.  
  851. ## Hata mesajlarının ekrana basılması için entegrasyon ve test sürecinde 1 olarak bırakın. Daha sonra 0 yapabilirsiniz.
  852. $debug_on = 1;
  853.  
  854. ## Mağaza canlı modda iken test işlem yapmak için 1 olarak gönderilebilir.
  855. if(Yii::app()->user->id==4198)
  856. $test_mode = 1;
  857. else
  858. $test_mode = 0;
  859.  
  860. $no_installment = 0; // Taksit yapılmasını istemiyorsanız, sadece tek çekim sunacaksanız 1 yapın
  861.  
  862. ## Sayfada görüntülenecek taksit adedini sınırlamak istiyorsanız uygun şekilde değiştirin.
  863. ## Sıfır (0) gönderilmesi durumunda yürürlükteki en fazla izin verilen taksit geçerli olur.
  864. $max_installment = 0;
  865.  
  866. $currency = "TL";
  867.  
  868. ####### Bu kısımda herhangi bir değişiklik yapmanıza gerek yoktur. #######
  869. $hash_str = $merchant_id .$user_ip .$merchant_oid .$email .$payment_amount .$user_basket.$no_installment.$max_installment.$currency.$test_mode;
  870. $paytr_token=base64_encode(hash_hmac('sha256',$hash_str.$merchant_salt,$merchant_key,true));
  871. $post_vals=array(
  872. 'merchant_id'=>$merchant_id,
  873. 'user_ip'=>$user_ip,
  874. 'merchant_oid'=>$merchant_oid,
  875. 'email'=>$email,
  876. 'payment_amount'=>$payment_amount,
  877. 'paytr_token'=>$paytr_token,
  878. 'user_basket'=>$user_basket,
  879. 'debug_on'=>$debug_on,
  880. 'no_installment'=>$no_installment,
  881. 'max_installment'=>$max_installment,
  882. 'user_name'=>$user_name,
  883. 'user_address'=>$user_address,
  884. 'user_phone'=>$user_phone,
  885. 'merchant_ok_url'=>$merchant_ok_url,
  886. 'merchant_fail_url'=>$merchant_fail_url,
  887. 'timeout_limit'=>$timeout_limit,
  888. 'currency'=>$currency,
  889. 'test_mode'=>$test_mode
  890. );
  891.  
  892. $ch=curl_init();
  893. curl_setopt($ch, CURLOPT_URL, "https://www.paytr.com/odeme/api/get-token");
  894. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  895. curl_setopt($ch, CURLOPT_POST, 1) ;
  896. curl_setopt($ch, CURLOPT_POSTFIELDS, $post_vals);
  897. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  898. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  899. curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
  900. curl_setopt($ch, CURLOPT_TIMEOUT, 20);
  901. $result = @curl_exec($ch);
  902.  
  903. if(curl_errno($ch))
  904. die("PAYTR IFRAME connection error. err:".curl_error($ch));
  905.  
  906. curl_close($ch);
  907.  
  908. $result=json_decode($result,1);
  909.  
  910. if($result['status']=='success')
  911. $token=$result['token'];
  912. else
  913. die("PAYTR IFRAME failed. reason:".$result['reason']);
  914.  
  915. #########################################################################
  916.  
  917. // $paymentproduct = new PaymentProducts();
  918. // $paymentproduct->users_id = Yii::app()->user->id;
  919. // $paymentproduct->created = time();
  920. // $paymentproduct->currency = $currency;
  921. // $paymentproduct->price = $payment_amount;
  922. // $paymentproduct->myorder_id = intval($_GET['id']);
  923. // $paymentproduct->merchant_oid = $merchant_oid;
  924. // $paymentproduct->status = "loading";
  925. // $paymentproduct->save();
  926.  
  927. $payment_amount2 = $payment_amount/100;
  928.  
  929. Yii::app() -> db -> createCommand("INSERT INTO
  930. `cms_payment_products` (`users_id`, `created`,`currency`, `price`,`myorder_id`,`merchant_oid`,`status`)
  931. VALUES (:users_id,".time().",:currency,:price,:myorder_id,:merchant_oid,'loading')")
  932. -> bindParam(':users_id', Yii::app()->user->id, PDO::PARAM_INT)
  933. -> bindParam(':currency', $currency, PDO::PARAM_STR)
  934. -> bindParam(':price', $payment_amount2, PDO::PARAM_STR)
  935. -> bindParam(':myorder_id', intval($_GET['id']), PDO::PARAM_INT)
  936. -> bindParam(':merchant_oid', $merchant_oid, PDO::PARAM_INT)
  937. -> execute();
  938.  
  939. $hesab = Hesablar::model()->findByPk(4);
  940. $hesab->hesab_mebleg = (float) $hesab->hesab_mebleg + (float) $payment_amount2;
  941. $hesab->save(false);
  942.  
  943. }
  944. else
  945. $token = '';
  946.  
  947. $datatype = "get";
  948. }
  949. elseif(isset($_POST['pay_submit']) and isset($_POST['pay']))
  950. {
  951. $pay = implode(",",$_POST['pay']);
  952.  
  953. $sql="
  954. SELECT * FROM `cms_myorder` WHERE id IN (".$pay.")
  955. ";
  956.  
  957. $myorders = Yii::app()->db->createCommand($sql)->queryAll();
  958.  
  959. if($myorders)
  960. {
  961. $sql="
  962. SELECT * FROM `cms_myorder` WHERE id IN (".$pay.")
  963. ";
  964.  
  965. $myorders = Yii::app()->db->createCommand($sql)->queryAll();
  966.  
  967. ## 1. ADIM için örnek kodlar ##
  968.  
  969. ####################### DÜZENLEMESİ ZORUNLU ALANLAR #######################
  970. #
  971. ## API Entegrasyon Bilgileri - Mağaza paneline giriş yaparak BİLGİ sayfasından alabilirsiniz.
  972. $merchant_id = '109349';
  973. $merchant_key = 'khPZ6dN4gC8aZ4e9';
  974. $merchant_salt = 'BLeRAbrwku83Mrk8';
  975. #
  976. ## Müşterinizin sitenizde kayıtlı veya form vasıtasıyla aldığınız eposta adresi
  977. $email = $getLoginUser->email;
  978. #
  979. #
  980. ## Sipariş numarası: Her işlemde benzersiz olmalıdır!! Bu bilgi bildirim sayfanıza yapılacak bildirimde geri gönderilir.
  981. $merchant_oid = $getLoginUser->id.rand(0,9999);
  982. #
  983. ## Müşterinizin sitenizde kayıtlı veya form aracılığıyla aldığınız ad ve soyad bilgisi
  984. $user_name = $getLoginUser->name." ".$getLoginUser->surname;
  985. #
  986. ## Müşterinizin sitenizde kayıtlı veya form aracılığıyla aldığınız adres bilgisi
  987. $user_address = $getLoginUser->address;
  988. #
  989. ## Müşterinizin sitenizde kayıtlı veya form aracılığıyla aldığınız telefon bilgisi
  990. $user_phone = $getLoginUser->mobile;
  991. #
  992. ## Başarılı ödeme sonrası müşterinizin yönlendirileceği sayfa
  993. ## !!! Bu sayfa siparişi onaylayacağınız sayfa değildir! Yalnızca müşterinizi bilgilendireceğiniz sayfadır!
  994. ## !!! Siparişi onaylayacağız sayfa "Bildirim URL" sayfasıdır (Bakınız: 2.ADIM Klasörü).
  995. $merchant_ok_url = "https://www.mover.az/callbackpaymentpaytrsuccess";
  996. #
  997. ## Ödeme sürecinde beklenmedik bir hata oluşması durumunda müşterinizin yönlendirileceği sayfa
  998. ## !!! Bu sayfa siparişi iptal edeceğiniz sayfa değildir! Yalnızca müşterinizi bilgilendireceğiniz sayfadır!
  999. ## !!! Siparişi iptal edeceğiniz sayfa "Bildirim URL" sayfasıdır (Bakınız: 2.ADIM Klasörü).
  1000. $merchant_fail_url = "https://www.mover.az/callbackpaymentpaytrfailure";
  1001.  
  1002. $currency = "TL";
  1003.  
  1004. $i=$a=0;
  1005. $user_basket_arr = array();
  1006. foreach ($myorders as $myorder)
  1007. {
  1008. if($myorder['count']==0)
  1009. $count = 1;
  1010. else
  1011. $count = $myorder['count'];
  1012.  
  1013. if($myorder['order_type']==1)
  1014. $price_end = $myorder['price'];
  1015. else
  1016. $price_end = $myorder['price']+$myorder['price']*0.05;
  1017.  
  1018. if($myorder['count']==0)
  1019. $count_myorder = 1;
  1020. else
  1021. $count_myorder = $myorder['count'];
  1022.  
  1023. $a += $price_end*$count_myorder;
  1024.  
  1025. ## Müşterinin sepet/sipariş içeriği
  1026.  
  1027. //$user_basket_arr[] = array($myorder['comment'], $price_end, $count);
  1028. array_push($user_basket_arr,array($myorder['comment'], $price_end, $count));
  1029.  
  1030.  
  1031. #
  1032. /* ÖRNEK $user_basket oluşturma - Ürün adedine göre array'leri çoğaltabilirsiniz
  1033. $user_basket = base64_encode(json_encode(array(
  1034. array("Örnek ürün 1", "18.00", 1), // 1. ürün (Ürün Ad - Birim Fiyat - Adet )
  1035. array("Örnek ürün 2", "33.25", 2), // 2. ürün (Ürün Ad - Birim Fiyat - Adet )
  1036. array("Örnek ürün 3", "45.42", 1) // 3. ürün (Ürün Ad - Birim Fiyat - Adet )
  1037. )));
  1038. */
  1039. ############################################################################################
  1040.  
  1041. Yii::app() -> db -> createCommand("INSERT INTO
  1042. `cms_payment_products` (`users_id`, `created`,`currency`, `price`,`myorder_id`,`merchant_oid`,`status`)
  1043. VALUES (:users_id,".time().",:currency,:price,:myorder_id,:merchant_oid,'loading')")
  1044. -> bindParam(':users_id', Yii::app()->user->id, PDO::PARAM_INT)
  1045. -> bindParam(':currency', $currency, PDO::PARAM_STR)
  1046. -> bindParam(':price', $price_end, PDO::PARAM_STR)
  1047. -> bindParam(':myorder_id', $myorder['id'], PDO::PARAM_INT)
  1048. -> bindParam(':merchant_oid', $merchant_oid, PDO::PARAM_INT)
  1049. -> execute();
  1050.  
  1051. $i++;
  1052. }
  1053.  
  1054. // if(Yii::app()->user->id==4198)
  1055. // print_r($user_basket_arr);
  1056.  
  1057. // $user_basket = base64_encode(json_encode($user_basket_arr));
  1058.  
  1059.  
  1060. /*$masspay = array(
  1061. array("Örnek ürün 1", "18.00", 1), // 1. ürün (Ürün Ad - Birim Fiyat - Adet )
  1062. array("Örnek ürün 2", "33.25", 2), // 2. ürün (Ürün Ad - Birim Fiyat - Adet )
  1063. array("Örnek ürün 3", "45.42", 1) // 3. ürün (Ürün Ad - Birim Fiyat - Adet )
  1064. );*/
  1065. $user_basket = base64_encode(json_encode($user_basket_arr));
  1066.  
  1067. ## Tahsil edilecek tutar.
  1068. $payment_amount = intval($a*100); //9.99 için 9.99 * 100 = 999 gönderilmelidir.
  1069.  
  1070. ## Kullanıcının IP adresi
  1071. if( isset( $_SERVER["HTTP_CLIENT_IP"] ) ) {
  1072. $ip = $_SERVER["HTTP_CLIENT_IP"];
  1073. } elseif( isset( $_SERVER["HTTP_X_FORWARDED_FOR"] ) ) {
  1074. $ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
  1075. } else {
  1076. $ip = $_SERVER["REMOTE_ADDR"];
  1077. }
  1078.  
  1079. ## !!! Eğer bu örnek kodu sunucuda değil local makinanızda çalıştırıyorsanız
  1080. ## buraya dış ip adresinizi (https://www.whatismyip.com/) yazmalısınız. Aksi halde geçersiz paytr_token hatası alırsınız.
  1081. $user_ip=$ip;
  1082. ##
  1083.  
  1084. ## İşlem zaman aşımı süresi - dakika cinsinden
  1085. $timeout_limit = "30";
  1086.  
  1087. ## Hata mesajlarının ekrana basılması için entegrasyon ve test sürecinde 1 olarak bırakın. Daha sonra 0 yapabilirsiniz.
  1088. $debug_on = 1;
  1089.  
  1090. ## Mağaza canlı modda iken test işlem yapmak için 1 olarak gönderilebilir.
  1091. if(Yii::app()->user->id==4198)
  1092. $test_mode = 1;
  1093. else
  1094. $test_mode = 0;
  1095.  
  1096. $no_installment = 0; // Taksit yapılmasını istemiyorsanız, sadece tek çekim sunacaksanız 1 yapın
  1097.  
  1098. ## Sayfada görüntülenecek taksit adedini sınırlamak istiyorsanız uygun şekilde değiştirin.
  1099. ## Sıfır (0) gönderilmesi durumunda yürürlükteki en fazla izin verilen taksit geçerli olur.
  1100. $max_installment = 0;
  1101.  
  1102. ####### Bu kısımda herhangi bir değişiklik yapmanıza gerek yoktur. #######
  1103. $hash_str = $merchant_id .$user_ip .$merchant_oid .$email .$payment_amount .$user_basket.$no_installment.$max_installment.$currency.$test_mode;
  1104. $paytr_token=base64_encode(hash_hmac('sha256',$hash_str.$merchant_salt,$merchant_key,true));
  1105. $post_vals=array(
  1106. 'merchant_id'=>$merchant_id,
  1107. 'user_ip'=>$user_ip,
  1108. 'merchant_oid'=>$merchant_oid,
  1109. 'email'=>$email,
  1110. 'payment_amount'=>$payment_amount,
  1111. 'paytr_token'=>$paytr_token,
  1112. 'user_basket'=>$user_basket,
  1113. 'debug_on'=>$debug_on,
  1114. 'no_installment'=>$no_installment,
  1115. 'max_installment'=>$max_installment,
  1116. 'user_name'=>$user_name,
  1117. 'user_address'=>$user_address,
  1118. 'user_phone'=>$user_phone,
  1119. 'merchant_ok_url'=>$merchant_ok_url,
  1120. 'merchant_fail_url'=>$merchant_fail_url,
  1121. 'timeout_limit'=>$timeout_limit,
  1122. 'currency'=>$currency,
  1123. 'test_mode'=>$test_mode
  1124. );
  1125.  
  1126. $ch=curl_init();
  1127. curl_setopt($ch, CURLOPT_URL, "https://www.paytr.com/odeme/api/get-token");
  1128. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  1129. curl_setopt($ch, CURLOPT_POST, 1) ;
  1130. curl_setopt($ch, CURLOPT_POSTFIELDS, $post_vals);
  1131. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  1132. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  1133. curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
  1134. curl_setopt($ch, CURLOPT_TIMEOUT, 20);
  1135. $result = @curl_exec($ch);
  1136.  
  1137. if(curl_errno($ch))
  1138. die("PAYTR IFRAME connection error. err:".curl_error($ch));
  1139.  
  1140. curl_close($ch);
  1141.  
  1142. $result=json_decode($result,1);
  1143.  
  1144. if($result['status']=='success')
  1145. $token=$result['token'];
  1146. else
  1147. die("PAYTR IFRAME failed. reason:".$result['reason']);
  1148.  
  1149. #########################################################################
  1150.  
  1151. $datatype = "post";
  1152.  
  1153. $getProduct = $myorders;
  1154. }
  1155. else
  1156. $this->redirect(Yii::app()->homeUrl);
  1157.  
  1158. }
  1159. else $this->redirect(CHtml::normalizeUrl(array("site/order")));
  1160.  
  1161. $this->render('paymentproductpaytr',array("getProduct"=>$getProduct,"datatype"=>$datatype,"token"=>$token));
  1162. }
  1163.  
  1164. public function actionCallbackpaymentpaytrsuccess()
  1165. {
  1166. $this->render('callbackpaymentpaytrsuccess');
  1167. }
  1168.  
  1169. public function actionCallbackpaymentpaytrfailure()
  1170. {
  1171. $this->render('callbackpaymentpaytrfailure');
  1172. }
  1173.  
  1174. public function actionPaytrinfo()
  1175. {
  1176.  
  1177. $post = $_POST;
  1178.  
  1179. $merchant_key = 'khPZ6dN4gC8aZ4e9';
  1180. $merchant_salt = 'BLeRAbrwku83Mrk8';
  1181. $hash = base64_encode( hash_hmac('sha256', $post['merchant_oid'].$merchant_salt.$post['status'].$post['total_amount'], $merchant_key, true) );
  1182.  
  1183. if( $hash != $post['hash'] )
  1184. die('PAYTR notification failed: bad hash');
  1185. $getProduct = PaymentProducts::model()->findByAttributes(array("merchant_oid"=>$post['merchant_oid'],"status"=>"loading"));
  1186.  
  1187. if($getProduct->status == "onay" || $getProduct->status == "iptal"){
  1188. echo "OK";
  1189. exit;
  1190. }
  1191.  
  1192. if( $post['status'] == 'success' ) { ## Ödeme Onaylandı
  1193.  
  1194. $user_basket_explode = explode("-",$post['user_basket']);
  1195.  
  1196. $merchant_oid = $post['merchant_oid'];
  1197. $match = 'coupon';
  1198. if(strpos($merchant_oid, $match) !== false)
  1199. {
  1200. $criteria = new CDbCriteria;
  1201. $criteria->addCondition("merchant_oid='$post[merchant_oid]' and paymentstatus='loading'");
  1202. CouponAction::model() -> updateAll(array('token'=>$post['hash'],'paymentstatus'=>"SUCCESS",'created'=>time(),"cardtype"=>$post['payment_type']), $criteria);
  1203.  
  1204. $coupon_action = CouponAction::model() -> find('merchant_oid=:tr_id', array(':tr_id' => $post['merchant_oid']));
  1205. $coupon_balance = $coupon_action->price/1.05;
  1206. $coupon_balance = round($coupon_balance, 2);
  1207.  
  1208. $getUserInfo = Users::model()->findByPk($coupon_action->user_id);
  1209. $newBalance = $coupon_balance+$getUserInfo->coupon_balance;
  1210.  
  1211. Users::model() -> updateByPk($coupon_action->user_id, array('coupon_balance' => $newBalance));
  1212.  
  1213. $coupon_log = New CouponHistory();
  1214. $coupon_log->user_id = $getUserInfo->id;
  1215. $coupon_log->date = date('Y-m-d H:i:s');
  1216. $coupon_log->log = '+'.$coupon_balance.' TL kupon alışı. Hal hazırki balans '.$newBalance.') TL | Onlayn kupon balans artımı. Coupone transaction_id | '.$post[merchant_oid].'';
  1217. $coupon_log->type = 'add';
  1218. $coupon_log->save();
  1219. }
  1220. else
  1221. {
  1222. $criteria = new CDbCriteria;
  1223. $criteria->addCondition("merchant_oid='$post[merchant_oid]' and status='loading'");
  1224.  
  1225. PaymentProducts::model()->updateAll(array('token'=>$post['hash'],'paymentstatus'=>"SUCCESS",'created'=>time(),"cardtype"=>$post['payment_type'],"status"=>'onay'), $criteria);
  1226. foreach($getProduct as $product){
  1227. Myorder::model()->updateByPk((int)$product->myorder_id, array('paid' => '1'));
  1228. }
  1229. }
  1230.  
  1231.  
  1232.  
  1233. } else {
  1234.  
  1235. $merchant_oid = $post['merchant_oid'];
  1236. $match = 'coupon';
  1237. if(strpos($merchant_oid, $match) !== false)
  1238. {
  1239. $criteria = new CDbCriteria;
  1240. $criteria->addCondition("merchant_oid='$post[merchant_oid]' and paymentstatus='loading'");
  1241. CouponAction::model()->updateAll(array('token'=>$post['hash'],'paymentstatus'=>"FAILED",'created'=>time(),"cardtype"=>$post['payment_type'],"failed_reason_code"=>$post['failed_reason_code'],"failed_reason_msg"=>$post['failed_reason_msg']), $criteria);
  1242.  
  1243. }
  1244. else
  1245. {
  1246. $criteria = new CDbCriteria;
  1247. $criteria->addCondition("merchant_oid='$post[merchant_oid]' and status='loading'");
  1248.  
  1249. PaymentProducts::model()->updateAll(array('token'=>$post['hash'],'paymentstatus'=>"FAILED",'created'=>time(),"cardtype"=>$post['payment_type'],"status"=>'iptal',"failed_reason_code"=>$post['failed_reason_code'],"failed_reason_msg"=>$post['failed_reason_msg']), $criteria);
  1250.  
  1251. }
  1252.  
  1253.  
  1254. }
  1255. echo "OK";
  1256. exit;
  1257. }
  1258.  
  1259. protected function get_domain($url)
  1260. {
  1261. $pieces = parse_url($url);
  1262. $domain = isset($pieces['host']) ? $pieces['host'] : '';
  1263. if (preg_match('/(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i', $domain, $regs)) {
  1264. return $regs['domain'];
  1265. }
  1266. return false;
  1267. }
  1268.  
  1269. public function actionCallbackPayment()
  1270. {
  1271. $getLoginUser = Users::model()->findByPk(Yii::app()->user->id);
  1272. include "./protected/components/iyzipay/samples/config.php";
  1273.  
  1274. //var_dump($_POST);
  1275. $token = $_POST['token'];
  1276. # create request class
  1277. $request = new \Iyzipay\Request\RetrieveCheckoutFormRequest();
  1278. $request->setLocale(\Iyzipay\Model\Locale::TR);
  1279. $request->setConversationId($getLoginUser->user_key);
  1280. $request->setToken($token);
  1281.  
  1282. $order_id = 0;
  1283.  
  1284. # make request
  1285. $checkoutForm = \Iyzipay\Model\CheckoutForm::retrieve($request, Config::options());
  1286.  
  1287. // var_dump(json_decode($checkoutForm->getRawResult()));
  1288.  
  1289. // var_dump($checkoutForm->getPaymentItems());
  1290.  
  1291. // echo "<pre>";
  1292. // $dcount = (array)$checkoutForm->getPaymentItems()[0];
  1293. // foreach ($dcount as $k=>$x){
  1294. // echo str_replace("Iyzipay\Model\PaymentItem","",$k)." ---- ".$x."<br>";
  1295. // }
  1296. // foreach ($checkoutForm->getPaymentItems() as $key=>$item)
  1297. // echo $item[$key]
  1298.  
  1299. $sql="
  1300. SELECT * FROM `cms_payment_products` WHERE `token`='$token'
  1301. ";
  1302.  
  1303. $checktoken = Yii::app()->db->createCommand($sql)->bindParam(":token",$token,PDO::PARAM_STR)->queryAll();
  1304.  
  1305.  
  1306. if($checkoutForm->getStatus()=="success" && $token==$checkoutForm->getToken() && !$checktoken)
  1307. {
  1308. if($checkoutForm->getPaymentStatus()=="SUCCESS")
  1309. {
  1310. $message = "paymentSuccess";
  1311.  
  1312. $myoders = Myorder::model()->findByPk($checkoutForm->getBasketId());
  1313. Myorder::model()->updateByPk((int)$checkoutForm->getBasketId(), array('status' => '1'));
  1314. Myorder::model()->updateByPk((int)$checkoutForm->getBasketId(), array('paid' => '1'));
  1315.  
  1316. $explode = explode(".",$this->get_domain($myoders->link));
  1317.  
  1318. $model = new Orders();
  1319. $model->link = $myoders->link;
  1320. $model->users_id = Yii::app()->user->id;
  1321. $model->comments = $myoders->comment;
  1322. $model->order_key = $myoders->order_key;
  1323. $model->order_type = $myoders->order_type;
  1324. $model->price = $myoders->price;
  1325. $model->image = $myoders->image;
  1326. $model->country_id = 1;
  1327. $model->valute_id = 3;
  1328. $model->count = $myoders->count;
  1329. $model->status = '3';
  1330. // $model->delivery = '1';
  1331. // $model->date1 = date("Y-m-d");
  1332. $model->paid = '1';
  1333. $model->shop = ucfirst($explode[0]);
  1334. $model->save(false);
  1335.  
  1336. $order_id = $model->id;
  1337. }
  1338. else
  1339. $message = "paymentFailure";
  1340. }
  1341. else
  1342. $message = "tokenFailure";
  1343.  
  1344. if($token)
  1345. Yii::app() -> db -> createCommand("INSERT INTO
  1346. `cms_payment_products` (`users_id`, `created`,`order_id`,`token`,`paymentstatus`,`currency`, `price`, `paymentid`, `cardtype`, `cardassociation`,`myorder_id`)
  1347. VALUES (:users_id,".time().",:order_id,:token,:paymentstatus,:currency,:price,:paymentid,:cardtype,:cardassociation,:myorder_id)")
  1348. -> bindParam(':users_id', Yii::app()->user->id, PDO::PARAM_INT)
  1349. -> bindParam(':order_id', $order_id, PDO::PARAM_INT)
  1350. -> bindParam(':token', $checkoutForm->getToken(), PDO::PARAM_STR)
  1351. -> bindParam(':paymentstatus', $checkoutForm->getPaymentStatus() , PDO::PARAM_INT)
  1352. -> bindParam(':currency', $checkoutForm->getCurrency(), PDO::PARAM_STR)
  1353. -> bindParam(':price', $checkoutForm->getPrice(), PDO::PARAM_STR)
  1354. -> bindParam(':paymentid', $checkoutForm->getPaymentId(), PDO::PARAM_STR)
  1355. -> bindParam(':cardtype', $checkoutForm->getCardType(), PDO::PARAM_STR)
  1356. -> bindParam(':cardassociation', $checkoutForm->getCardAssociation(), PDO::PARAM_STR)
  1357. -> bindParam(':myorder_id', $checkoutForm->getBasketId(), PDO::PARAM_INT)
  1358. -> execute();
  1359.  
  1360.  
  1361. // $payment = new PaymentProducts();
  1362. // $payment->users_id = Yii::app()->user->id;
  1363. // $payment->date = time();
  1364. // $payment->order_id = $checkoutForm->getBasketId();
  1365. // $payment->token = $checkoutForm->getToken();
  1366. // $payment->paymentstatus = $checkoutForm->getPaymentStatus();
  1367. // $payment->currency = $checkoutForm->getCurrency();
  1368. // $payment->price = $checkoutForm->getPrice();
  1369. // $payment->paymentid = $checkoutForm->getPaymentId();
  1370. // $payment->cardtype = $checkoutForm->getCardType();
  1371. // $payment->cardassociation = $checkoutForm->getCardAssociation();
  1372. // $payment->save();
  1373.  
  1374. $this->render('callbackpayment', array("message"=>$message));
  1375. }
  1376.  
  1377. public function actionCallbackPaymentMore()
  1378. {
  1379. $getLoginUser = Users::model()->findByPk(Yii::app()->user->id);
  1380. include "./protected/components/iyzipay/samples/config.php";
  1381.  
  1382. //var_dump($_POST);
  1383. $token = $_POST['token'];
  1384. # create request class
  1385. $request = new \Iyzipay\Request\RetrieveCheckoutFormRequest();
  1386. $request->setLocale(\Iyzipay\Model\Locale::TR);
  1387. $request->setConversationId($getLoginUser->user_key);
  1388. $request->setToken($token);
  1389.  
  1390. $order_id = 0;
  1391.  
  1392. # make request
  1393. $checkoutForm = \Iyzipay\Model\CheckoutForm::retrieve($request, Config::options());
  1394.  
  1395. // var_dump($checkoutForm);
  1396.  
  1397. if(strpos($checkoutForm->getBasketId(),"-")>0)
  1398. $explode_id = explode("-",$checkoutForm->getBasketId());
  1399. else
  1400. $explode_id = $checkoutForm->getBasketId();
  1401.  
  1402.  
  1403. $sql="
  1404. SELECT * FROM `cms_payment_products` WHERE `token`='$token'
  1405. ";
  1406.  
  1407. $checktoken = Yii::app()->db->createCommand($sql)->bindParam(":token",$token,PDO::PARAM_STR)->queryAll();
  1408.  
  1409. $order_id = array();
  1410.  
  1411. if($checkoutForm->getStatus()=="success" && $token==$checkoutForm->getToken() && !$checktoken)
  1412. {
  1413. if($checkoutForm->getPaymentStatus()=="SUCCESS")
  1414. {
  1415. $message = "paymentSuccess";
  1416.  
  1417. if(is_array($explode_id))
  1418. {
  1419. foreach ($explode_id as $id)
  1420. {
  1421. $myoders = Myorder::model()->findByPk($id);
  1422. Myorder::model()->updateByPk((int)$id, array('status' => '1'));
  1423. Myorder::model()->updateByPk((int)$id, array('paid' => '1'));
  1424.  
  1425. $explode = explode(".",$this->get_domain($myoders->link));
  1426.  
  1427. $model = new Orders();
  1428. $model->link = $myoders->link;
  1429. $model->users_id = Yii::app()->user->id;
  1430. $model->comments = $myoders->comment;
  1431. $model->order_key = $myoders->order_key;
  1432. $model->order_type = $myoders->order_type;
  1433. $model->price = $myoders->price;
  1434. $model->image = $myoders->image;
  1435. $model->country_id = 1;
  1436. $model->valute_id = 3;
  1437. $model->count = $myoders->count;
  1438. $model->status = '3';
  1439. // $model->delivery = '1';
  1440. // $model->date1 = date("Y-m-d");
  1441. $model->paid = '1';
  1442. $model->shop = ucfirst($explode[0]);
  1443. $model->save(false);
  1444.  
  1445. $order_id[] = $model->id;
  1446. }
  1447. }
  1448. else
  1449. {
  1450. $myoders = Myorder::model()->findByPk($explode_id);
  1451. Myorder::model()->updateByPk((int)$explode_id, array('status' => '1'));
  1452. Myorder::model()->updateByPk((int)$explode_id, array('paid' => '1'));
  1453.  
  1454. $explode = explode(".",$this->get_domain($myoders->link));
  1455.  
  1456. $model = new Orders();
  1457. $model->link = $myoders->link;
  1458. $model->users_id = Yii::app()->user->id;
  1459. $model->comments = $myoders->comment;
  1460. $model->order_key = $myoders->order_key;
  1461. $model->order_type = $myoders->order_type;
  1462. $model->price = $myoders->price;
  1463. $model->image = $myoders->image;
  1464. $model->country_id = 1;
  1465. $model->valute_id = 3;
  1466. $model->count = $myoders->count;
  1467. $model->status = '3';
  1468. // $model->delivery = '1';
  1469. // $model->date1 = date("Y-m-d");
  1470. $model->paid = '1';
  1471. $model->shop = ucfirst($explode[0]);
  1472. $model->save(false);
  1473.  
  1474. $order_id = $model->id;
  1475. }
  1476. }
  1477. else
  1478. $message = "paymentFailure";
  1479. }
  1480. else
  1481. $message = "tokenFailure";
  1482.  
  1483.  
  1484. if(is_array($order_id))
  1485. {
  1486. $i=0;
  1487. foreach ($order_id as $id)
  1488. {
  1489. $orders = Orders::model()->findByPk($id);
  1490.  
  1491. if($orders->order_type==1)
  1492. $price = $orders->price;
  1493. else
  1494. $price = $orders->price+$orders->price*0.05;
  1495.  
  1496. Yii::app() -> db -> createCommand("INSERT INTO
  1497. `cms_payment_products` (`users_id`, `created`,`order_id`,`token`,`paymentstatus`,`currency`, `price`, `paymentid`, `cardtype`, `cardassociation`,`myorder_id`)
  1498. VALUES (:users_id,".time().",:order_id,:token,:paymentstatus,:currency,:price,:paymentid,:cardtype,:cardassociation,:myorder_id)")
  1499. -> bindParam(':users_id', Yii::app()->user->id, PDO::PARAM_INT)
  1500. -> bindParam(':order_id', $id, PDO::PARAM_INT)
  1501. -> bindParam(':token', $checkoutForm->getToken(), PDO::PARAM_STR)
  1502. -> bindParam(':paymentstatus', $checkoutForm->getPaymentStatus() , PDO::PARAM_INT)
  1503. -> bindParam(':currency', $checkoutForm->getCurrency(), PDO::PARAM_STR)
  1504. -> bindParam(':price', $price, PDO::PARAM_STR)
  1505. -> bindParam(':paymentid', $checkoutForm->getPaymentId(), PDO::PARAM_STR)
  1506. -> bindParam(':cardtype', $checkoutForm->getCardType(), PDO::PARAM_STR)
  1507. -> bindParam(':cardassociation', $checkoutForm->getCardAssociation(), PDO::PARAM_STR)
  1508. -> bindParam(':myorder_id', $explode_id[$i], PDO::PARAM_INT)
  1509. -> execute();
  1510.  
  1511. $i++;
  1512. }
  1513. }
  1514. else
  1515. {
  1516. Yii::app() -> db -> createCommand("INSERT INTO
  1517. `cms_payment_products` (`users_id`, `created`,`order_id`,`token`,`paymentstatus`,`currency`, `price`, `paymentid`, `cardtype`, `cardassociation`,`myorder_id`)
  1518. VALUES (:users_id,".time().",:order_id,:token,:paymentstatus,:currency,:price,:paymentid,:cardtype,:cardassociation,:myorder_id)")
  1519. -> bindParam(':users_id', Yii::app()->user->id, PDO::PARAM_INT)
  1520. -> bindParam(':order_id', $order_id, PDO::PARAM_INT)
  1521. -> bindParam(':token', $checkoutForm->getToken(), PDO::PARAM_STR)
  1522. -> bindParam(':paymentstatus', $checkoutForm->getPaymentStatus() , PDO::PARAM_INT)
  1523. -> bindParam(':currency', $checkoutForm->getCurrency(), PDO::PARAM_STR)
  1524. -> bindParam(':price', $checkoutForm->getPrice(), PDO::PARAM_STR)
  1525. -> bindParam(':paymentid', $checkoutForm->getPaymentId(), PDO::PARAM_STR)
  1526. -> bindParam(':cardtype', $checkoutForm->getCardType(), PDO::PARAM_STR)
  1527. -> bindParam(':cardassociation', $checkoutForm->getCardAssociation(), PDO::PARAM_STR)
  1528. -> bindParam(':myorder_id', $checkoutForm->getBasketId(), PDO::PARAM_INT)
  1529. -> execute();
  1530. }
  1531.  
  1532.  
  1533. // $payment = new PaymentProducts();
  1534. // $payment->users_id = Yii::app()->user->id;
  1535. // $payment->date = time();
  1536. // $payment->order_id = $checkoutForm->getBasketId();
  1537. // $payment->token = $checkoutForm->getToken();
  1538. // $payment->paymentstatus = $checkoutForm->getPaymentStatus();
  1539. // $payment->currency = $checkoutForm->getCurrency();
  1540. // $payment->price = $checkoutForm->getPrice();
  1541. // $payment->paymentid = $checkoutForm->getPaymentId();
  1542. // $payment->cardtype = $checkoutForm->getCardType();
  1543. // $payment->cardassociation = $checkoutForm->getCardAssociation();
  1544. // $payment->save();
  1545.  
  1546. $this->render('callbackpaymentmore', array("message"=>$message));
  1547. }
  1548.  
  1549. public function actionComplate()
  1550. {
  1551. if (!isset($_GET['reference']) || empty($_GET['reference'])){
  1552. $this->redirect(Yii::app()->homeUrl);
  1553. exit;
  1554. }
  1555. $mid = "mover";
  1556. $reference = $_GET['reference'];
  1557. $reference = (string)$reference;
  1558. $reference = strip_tags($reference);
  1559.  
  1560.  
  1561. //$production_url = "https://test.millikart.az:7444";
  1562. $production_url = "https://pay.millikart.az";
  1563. $data_url = "/gateway/payment/status?mid=".$mid."&reference=".$reference;
  1564. //$data_url = "/gateway/payment/status?mid=".$mid."&reference=".$reference;
  1565. $full_url = $production_url.$data_url;
  1566. $xml = file_get_contents($full_url);
  1567.  
  1568. $xml = simplexml_load_string($xml);
  1569.  
  1570.  
  1571. $ref = htmlspecialchars($reference);
  1572. $pay = PayReference::model()->findByAttributes(array('reference'=>$ref));
  1573.  
  1574.  
  1575. if($xml->RC == "000" && $xml->description == "OK" && $xml->code == "0" && $pay == NULL)
  1576. {
  1577.  
  1578. // Reference id bazaya yazilir
  1579. $p = new PayReference();
  1580. $p ->users_id = Yii::app()->user->id;
  1581. $p ->reference = $ref;
  1582. $p->save();
  1583.  
  1584. $user = Users::model()->findByPk(Yii::app()->user->id);
  1585.  
  1586. if(strpos($ref, 'shipping')!== false)
  1587. {
  1588. $exist_reference = PayShippingWithCard::model()->find('reference=:reference', array(':reference'=>$ref));
  1589. $order_ids = explode(',', $exist_reference->order_ids);
  1590.  
  1591. $criteria = new CDbCriteria();
  1592. $criteria->addInCondition("id", $order_ids);
  1593. $criteria->addInCondition("users_id",array(Yii::app()->user->id));
  1594. $orders = Orders::model()->findAll($criteria);
  1595.  
  1596. if($exist_reference)
  1597. {
  1598.  
  1599. if($user->balance <= 0)
  1600. {
  1601. $new_balance = $xml->amount/100 + $user->balance;
  1602. Users::model() -> updateByPk(Yii::app()->user->id, array('balance' => $new_balance));
  1603. $ph = new PaymentHistory();
  1604. $ph ->users_id = Yii::app()->user->id;
  1605. $ph ->date = time();
  1606. $ph ->log = '+ '.($xml->amount/100).'AZN ( Hazırkı balans : '.$new_balance.') AZN | Onlayn balans artımı';
  1607. $ph->save();
  1608.  
  1609. $ph = new PaymentHistory();
  1610. $ph ->users_id = Yii::app()->user->id;
  1611. $ph ->date = time();
  1612. $ph ->log = '- '.($new_balance).'AZN catdirilma haqqi ucun balansdan cixildi.( Hazırkı balans : 0)';
  1613. $ph->save();
  1614.  
  1615. $command = Yii::app()->db->createCommand();
  1616. $gen_code = $command
  1617. ->select('secret_code')
  1618. ->from('wh_door_lock')
  1619. ->where('customer_code=:customer_code AND status=:status', array(':customer_code'=>Yii::app()->user->id+100000,'status'=>'0'))
  1620. ->queryRow();
  1621.  
  1622.  
  1623. $secret_code= rand(1000,9999);
  1624.  
  1625. if(empty($gen_code))
  1626. {
  1627. $command->insert('wh_door_lock', array(
  1628. 'customer_code' => Yii::app()->user->id+100000,
  1629. 'secret_code' => $secret_code,
  1630. 'createdDate' => date('Y-m-d H:i:s'),
  1631. 'status' => '0'
  1632. ));
  1633.  
  1634. }
  1635. else
  1636. {
  1637. $secret_code = $gen_code['secret_code'];
  1638. }
  1639.  
  1640. Sms::Send(Users::model()->findByPk(Yii::app()->user->id) -> mobile, '- '.($new_balance).'AZN catdirilma haqqi ucun balansdan cixildi.( Hazırkı balans :0). Giris kodu:'.$secret_code);
  1641.  
  1642. Users::model() -> updateByPk(Yii::app()->user->id, array('balance' => 0));
  1643. Orders::model()->updateAll(array( 'paid' => 1),$criteria);
  1644. }
  1645. else
  1646. {
  1647. $new_balance = $xml->amount/100 + $user->balance;
  1648. Users::model() -> updateByPk(Yii::app()->user->id, array('balance' => $new_balance));
  1649. $ph = new PaymentHistory();
  1650. $ph ->users_id = Yii::app()->user->id;
  1651. $ph ->date = time();
  1652. $ph ->log = '+ '.($xml->amount/100).'AZN ( Hazırkı balans : '.$new_balance.') AZN | Onlayn balans artımı';
  1653. $ph->save();
  1654.  
  1655. $ph = new PaymentHistory();
  1656. $ph ->users_id = Yii::app()->user->id;
  1657. $ph ->date = time();
  1658. $ph ->log = '- '.($new_balance).'AZN catdirilma haqqi ucun balansdan cixildi.( Hazırkı balans : 0)';
  1659. $ph->save();
  1660.  
  1661. $command = Yii::app()->db->createCommand();
  1662. $gen_code = $command
  1663. ->select('secret_code')
  1664. ->from('wh_door_lock')
  1665. ->where('customer_code=:customer_code AND status=:status', array(':customer_code'=>Yii::app()->user->id+100000,'status'=>'0'))
  1666. ->queryRow();
  1667.  
  1668.  
  1669. $secret_code= rand(1000,9999);
  1670.  
  1671. if(empty($gen_code))
  1672. {
  1673. $command->insert('wh_door_lock', array(
  1674. 'customer_code' => Yii::app()->user->id+100000,
  1675. 'secret_code' => $secret_code,
  1676. 'createdDate' => date('Y-m-d H:i:s'),
  1677. 'status' => '0'
  1678. ));
  1679.  
  1680. }
  1681. else
  1682. {
  1683. $secret_code = $gen_code['secret_code'];
  1684. }
  1685.  
  1686. Sms::Send(Users::model()->findByPk(Yii::app()->user->id) -> mobile, '- '.($new_balance).'AZN catdirilma haqqi ucun balansdan cixildi.( Hazırkı balans :0). Giris kodu:'.$secret_code);
  1687.  
  1688.  
  1689. Users::model() -> updateByPk(Yii::app()->user->id, array('balance' => 0));
  1690. Orders::model()->updateAll(array( 'paid' => 1),$criteria);
  1691.  
  1692. }
  1693.  
  1694. $resp = true;
  1695. }
  1696. }
  1697. else
  1698. {
  1699. if ($user)
  1700. {
  1701.  
  1702. $new_balance = $user->balance + ($xml->amount/100);
  1703. Users::model() -> updateByPk(Yii::app()->user->id, array('balance' => $new_balance));
  1704.  
  1705. // balans loqlari
  1706. $ph = new PaymentHistory();
  1707. $ph ->users_id = Yii::app()->user->id;
  1708. $ph ->date = time();
  1709. $ph ->log = '+ '.($xml->amount/100).'AZN ( Hazırkı balans : '.$new_balance.') AZN | Onlayn balans artımı';
  1710. $ph->save();
  1711. // balans loq END
  1712. $hesab = Hesablar::model()->findByPk(1);
  1713. $hesab->hesab_mebleg = (float) $hesab->hesab_mebleg + (float) $xml->amount/100;
  1714. $hesab->save(false);
  1715. $resp = true;
  1716. }
  1717. }
  1718. }
  1719. else
  1720. $resp = false;
  1721.  
  1722.  
  1723. $this->render('paymentcomplate',array('xml'=>$xml,'resp'=>$resp));
  1724. }
  1725.  
  1726. public function actionsuccessPayment(){
  1727.  
  1728. if (!isset($_POST['trans_id']) || empty($_POST['trans_id'])){
  1729. $this->redirect(Yii::app()->homeUrl);
  1730.  
  1731. }
  1732.  
  1733. $ca = "/home/mover.az/protected/components/pasha/PSroot.pem";
  1734. $key = "/home/mover.az/protected/components/pasha/private.0010045.pem";
  1735. $cert = "/home/mover.az/protected/components/pasha/imakstore.0010045.pem";
  1736. $password = "P@ssword";
  1737. $merchant_handler = "https://ecomm.pashabank.az:18443/ecomm2/MerchantHandler";
  1738. $client_handler = "https://ecomm.pashabank.az:8463/ecomm2/ClientHandler";
  1739. $success_page = "success.html";
  1740. $card_expired_page = "card_expired.html";
  1741. $insufficient_funds_page = "insufficient_funds.html";
  1742. $system_malfunction_page = "system_malfunction.html";
  1743.  
  1744. $trans_id = filter_input(INPUT_POST,'trans_id');
  1745. if(strlen($trans_id) != 20 ||
  1746. base64_encode(base64_decode($trans_id)) != $trans_id) {
  1747. }
  1748.  
  1749. $params['command'] = "C";
  1750. $params['trans_id'] = $trans_id;
  1751.  
  1752. if (filter_input(INPUT_SERVER, 'REMOTE_ADDR') != null) {
  1753. $params['client_ip_addr'] = filter_input(INPUT_SERVER, 'REMOTE_ADDR');
  1754. }elseif(filter_input(INPUT_SERVER, 'HTTP_X_FORWARDED_FOR') != null){
  1755. $params['client_ip_addr'] = filter_input(INPUT_SERVER, 'HTTP_X_FORWARDED_FOR');
  1756. }elseif(filter_input(INPUT_SERVER, 'HTTP_CLIENT_IP') != null){
  1757. $params['client_ip_addr'] = filter_input(INPUT_SERVER, 'HTTP_CLIENT_IP');
  1758. }else{
  1759. $params['client_ip_addr'] = "10.10.10.10";
  1760. }
  1761. $qstring = http_build_query($params);
  1762. $ch = curl_init();
  1763.  
  1764. curl_setopt($ch, CURLOPT_URL, $merchant_handler);
  1765. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  1766. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  1767. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  1768.  
  1769. curl_setopt($ch, CURLOPT_POSTFIELDS, $qstring);
  1770. curl_setopt($ch, CURLOPT_SSLCERT, $cert);
  1771. curl_setopt($ch, CURLOPT_SSLKEY, $key);
  1772. curl_setopt($ch, CURLOPT_SSLKEYTYPE, "PEM");
  1773. curl_setopt($ch, CURLOPT_SSLKEYPASSWD, $password);
  1774. curl_setopt($ch, CURLOPT_CAPATH, $ca);
  1775. curl_setopt($ch, CURLOPT_SSLCERTTYPE, "P12");
  1776. curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
  1777. $result = curl_exec($ch);
  1778. if (curl_error($ch)) {
  1779. header("Location: " . $system_malfunction_page);
  1780. }
  1781. curl_close($ch);
  1782.  
  1783. //print_R($result); exit();
  1784. $res = explode(":",$result)[1];
  1785. $res = explode("RESULT_CODE",$res);
  1786.  
  1787.  
  1788. $res = trim($res[0]);
  1789.  
  1790. $ref = urlencode($trans_id);
  1791.  
  1792.  
  1793. //$pay = PayReference::model()->findByAttributes(array('reference'=>$ref));
  1794.  
  1795.  
  1796.  
  1797. $topupBalnace = TopupBalanceWpc::model()->find('transaction_id=:transaction_id', array(':transaction_id'=>$ref));
  1798.  
  1799. if($res == "OK"){
  1800.  
  1801. if($topupBalnace && $topupBalnace->status_id == 3){
  1802. $this->redirect(Yii::app()->homeUrl);
  1803. }
  1804.  
  1805. $topupBalnace->status_id = 1;
  1806. $topupBalnace->save();
  1807.  
  1808. if($topupBalnace && $topupBalnace->status_id == 1){
  1809. $p = new PayReference();
  1810. $p ->users_id = Yii::app()->user->id;
  1811. $p ->reference = $ref;
  1812. $p->save();
  1813.  
  1814.  
  1815.  
  1816. $user = Users::model()->findByPk(Yii::app()->user->id);
  1817.  
  1818. if ($user){
  1819. //$mblg = $_COOKIE["amnt"];
  1820. $new_balance = $user->balance + $topupBalnace->balance;
  1821. Users::model() -> updateByPk(Yii::app()->user->id, array('balance' => $new_balance));
  1822.  
  1823. // balans loqlari
  1824. $ph = new PaymentHistory();
  1825. $ph ->users_id = Yii::app()->user->id;
  1826. $ph ->date = time();
  1827. $ph ->log = '+ '.$topupBalnace->balance.' AZN Onlayn balans artımı ( Hazırkı balans : '.$new_balance.') AZN | Onlayn balans artımı';
  1828. $ph->save();
  1829. // balans loq END
  1830. $hesab = Hesablar::model()->findByPk(1);
  1831. $hesab->hesab_mebleg = (float) $hesab->hesab_mebleg + $topupBalnace->balance;
  1832. $hesab->save(false);
  1833. $resp = true;
  1834. }
  1835. $topupBalnace->status_id = 3;
  1836. $topupBalnace->save();
  1837. }else{
  1838. $topupBalnce->status_id = 2;
  1839. $topupBalnce->save();
  1840. }
  1841. }else{
  1842. $resp = false;
  1843. }
  1844. $this->render('paymentsuccess',array('res'=>$res,'mblg'=>$topupBalnace->balance));
  1845.  
  1846.  
  1847. }
  1848.  
  1849. public function actionerrorPayment(){
  1850. $this->render('paymenterror');
  1851. }
  1852.  
  1853. public function actionIndex() {
  1854.  
  1855.  
  1856. if(Yii::app()->language=="az")
  1857. {
  1858. Yii::app() -> clientScript -> registerMetaTag(Yii::t('text', 'mover.az, onlayn alış-veriş, çatdırılma xidməti, türkiyədən sifariş, türkiyə saytları, etibarlı şirkət, geyim sifarişi, ayaqqabı sifarişi'), 'keywords');
  1859. $this->pageTitle = Yii::t('text','Amerikadan və Türkiyədən çatdırılma xidməti | Mover.az');
  1860. }
  1861. elseif(Yii::app()->language=="en")
  1862. {
  1863. Yii::app() -> clientScript -> registerMetaTag(Yii::t('text', 'mover.az, online shopping, delivery service, order from turkey, turkey online shopping webpages, trusted company, dress order, shoes order'), 'keywords');
  1864. $this->pageTitle = Yii::t('text','Let the mover.az deliver all your orders from Turkey | Mover.az');
  1865. }
  1866.  
  1867.  
  1868.  
  1869. Yii::app()->params['OG_IMAGE'] = 'http://mover.az/media/img/ogimg.jpg';
  1870. Yii::app()->params['OG_URL'] = 'http://mover.az';
  1871. Yii::app()->params['OG_TITLE'] = 'Mover.az';
  1872. Yii::app()->params['OG_TEXT'] = Yii::t('text','Türkiyədən və Amerikadan məhsulların çatdırılma xidməti');
  1873. Yii::app()->clientScript->registerLinkTag('canonical', null, Yii::app()->request->getHostInfo() . '/' . Yii::app()->request->getPathInfo());
  1874. $this -> render('index');
  1875. }
  1876.  
  1877. public function actionOrder() {
  1878.  
  1879. $this->pageTitle = 'Mover.az - '. Yii::t('text','Sifarişlərim');
  1880. Yii::app()->clientScript->registerLinkTag('canonical', null, $this -> createAbsoluteUrl('site/Order'));
  1881. $criteria = new CDbCriteria;
  1882. $criteria->with = 'users';
  1883. $criteria->condition = "t.status='1' and t.users_id= :user_id";
  1884. $criteria->order = 't.id asc';
  1885. $criteria->params = array(':user_id' => (int)Yii::app() -> user -> id);
  1886. $orders = Orders::model()->findAll($criteria);
  1887.  
  1888. $last_order = end($orders);
  1889. $model = new Orders();
  1890. $this -> render('order',array('orders'=>$orders,'last_order'=>$last_order,'model'=>$model));
  1891.  
  1892. }
  1893.  
  1894.  
  1895. public function actionBundle() {
  1896.  
  1897. $this->pageTitle = 'Mover.az - '. Yii::t('text','Bağlamalarım');
  1898. Yii::app()->clientScript->registerLinkTag('canonical', null, $this -> createAbsoluteUrl('site/Order'));
  1899. $criteria = new CDbCriteria;
  1900. $criteria->with = 'users';
  1901. $criteria->condition = "t.status='1' and t.users_id= :user_id";
  1902. $criteria->order = 't.id asc';
  1903. $criteria->params = array(':user_id' => (int)Yii::app() -> user -> id);
  1904. $orders = Orders::model()->findAll($criteria);
  1905.  
  1906. $last_order = end($orders);
  1907. $model = new Orders();
  1908. $this -> render('bundle',array('orders'=>$orders,'last_order'=>$last_order,'model'=>$model));
  1909.  
  1910. }
  1911.  
  1912. public function actionKuponal(){
  1913.  
  1914. $getLoginUser = Users::model()->findByPk(Yii::app()->user->id);
  1915. $price = abs($_POST['coupon_buy']);
  1916.  
  1917. if(isset($_POST['coupon_buy']))
  1918. {
  1919. if($price < 10)
  1920. {
  1921. Yii::app()->user->setFlash('amount_great_less','Məbləğ 10 TL-dən az olmamalıdir');
  1922. return $this->redirect('/kuponal');
  1923. }
  1924. }
  1925.  
  1926. switch ($price) {
  1927. case 50:
  1928. $coupon_type = 1;
  1929. break;
  1930. case 100:
  1931. $coupon_type = 2;
  1932. break;
  1933. case 250:
  1934. $coupon_type = 3;
  1935. break;
  1936. case 500:
  1937. $coupon_type = 4;
  1938. break;
  1939. case 1000:
  1940. $coupon_type = 5;
  1941. break;
  1942. case 2000:
  1943. $coupon_type = 6;
  1944. break;
  1945. default:
  1946. $coupon_type = 7;
  1947. }
  1948.  
  1949. $price = $price*1.05;
  1950. if(isset($_POST['coupon_buy']) && $getLoginUser)
  1951. {
  1952.  
  1953. ## 1. ADIM için örnek kodlar ##
  1954.  
  1955. ####################### DÜZENLEMESİ ZORUNLU ALANLAR #######################
  1956. #
  1957. ## API Entegrasyon Bilgileri - Mağaza paneline giriş yaparak BİLGİ sayfasından alabilirsiniz.
  1958. $merchant_id = '109349';
  1959. $merchant_key = 'khPZ6dN4gC8aZ4e9';
  1960. $merchant_salt = 'BLeRAbrwku83Mrk8';
  1961. #
  1962. ## Müşterinizin sitenizde kayıtlı veya form vasıtasıyla aldığınız eposta adresi
  1963. $email = $getLoginUser->email;
  1964. #
  1965. ## Tahsil edilecek tutar.
  1966. $payment_amount = round($price*100); //9.99 için 9.99 * 100 = 999 gönderilmelidir.
  1967. #
  1968. ## Sipariş numarası: Her işlemde benzersiz olmalıdır!! Bu bilgi bildirim sayfanıza yapılacak bildirimde geri gönderilir.
  1969. $merchant_oid = $getLoginUser->id.rand(0,9999).'coupon';
  1970. #
  1971. ## Müşterinizin sitenizde kayıtlı veya form aracılığıyla aldığınız ad ve soyad bilgisi
  1972. $user_name = $getLoginUser->name." ".$getLoginUser->surname;
  1973. #
  1974. ## Müşterinizin sitenizde kayıtlı veya form aracılığıyla aldığınız adres bilgisi
  1975. $user_address = $getLoginUser->address;
  1976. #
  1977. ## Müşterinizin sitenizde kayıtlı veya form aracılığıyla aldığınız telefon bilgisi
  1978. $user_phone = $getLoginUser->mobile;
  1979. #
  1980. ## Başarılı ödeme sonrası müşterinizin yönlendirileceği sayfa
  1981. ## !!! Bu sayfa siparişi onaylayacağınız sayfa değildir! Yalnızca müşterinizi bilgilendireceğiniz sayfadır!
  1982. ## !!! Siparişi onaylayacağız sayfa "Bildirim URL" sayfasıdır (Bakınız: 2.ADIM Klasörü).
  1983. $merchant_ok_url = "https://www.mover.az/callbackpaymentpaytrsuccess?coupone=$merchant_oid";
  1984. #
  1985. ## Ödeme sürecinde beklenmedik bir hata oluşması durumunda müşterinizin yönlendirileceği sayfa
  1986. ## !!! Bu sayfa siparişi iptal edeceğiniz sayfa değildir! Yalnızca müşterinizi bilgilendireceğiniz sayfadır!
  1987. ## !!! Siparişi iptal edeceğiniz sayfa "Bildirim URL" sayfasıdır (Bakınız: 2.ADIM Klasörü).
  1988. $merchant_fail_url = "https://www.mover.az/callbackpaymentpaytrfailure";
  1989. #
  1990. ## Müşterinin sepet/sipariş içeriği
  1991. $user_basket = base64_encode(json_encode(array(
  1992. array($price) // 1. ürün (Ürün Ad - Birim Fiyat - Adet )
  1993. )));
  1994. #
  1995. /* ÖRNEK $user_basket oluşturma - Ürün adedine göre array'leri çoğaltabilirsiniz
  1996. $user_basket = base64_encode(json_encode(array(
  1997. array("Örnek ürün 1", "18.00", 1), // 1. ürün (Ürün Ad - Birim Fiyat - Adet )
  1998. array("Örnek ürün 2", "33.25", 2), // 2. ürün (Ürün Ad - Birim Fiyat - Adet )
  1999. array("Örnek ürün 3", "45.42", 1) // 3. ürün (Ürün Ad - Birim Fiyat - Adet )
  2000. )));
  2001. */
  2002. ############################################################################################
  2003.  
  2004. ## Kullanıcının IP adresi
  2005. if( isset( $_SERVER["HTTP_CLIENT_IP"] ) ) {
  2006. $ip = $_SERVER["HTTP_CLIENT_IP"];
  2007. } elseif( isset( $_SERVER["HTTP_X_FORWARDED_FOR"] ) ) {
  2008. $ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
  2009. } else {
  2010. $ip = $_SERVER["REMOTE_ADDR"];
  2011. }
  2012.  
  2013. ## !!! Eğer bu örnek kodu sunucuda değil local makinanızda çalıştırıyorsanız
  2014. ## buraya dış ip adresinizi (https://www.whatismyip.com/) yazmalısınız. Aksi halde geçersiz paytr_token hatası alırsınız.
  2015. $user_ip=$ip;
  2016. ##
  2017.  
  2018. ## İşlem zaman aşımı süresi - dakika cinsinden
  2019. $timeout_limit = "30";
  2020.  
  2021. ## Hata mesajlarının ekrana basılması için entegrasyon ve test sürecinde 1 olarak bırakın. Daha sonra 0 yapabilirsiniz.
  2022. $debug_on = 1;
  2023.  
  2024. ## Mağaza canlı modda iken test işlem yapmak için 1 olarak gönderilebilir.
  2025. if(Yii::app()->user->id==23114)
  2026. $test_mode = 1;
  2027. else
  2028. $test_mode = 0;
  2029.  
  2030. $no_installment = 0; // Taksit yapılmasını istemiyorsanız, sadece tek çekim sunacaksanız 1 yapın
  2031.  
  2032. ## Sayfada görüntülenecek taksit adedini sınırlamak istiyorsanız uygun şekilde değiştirin.
  2033. ## Sıfır (0) gönderilmesi durumunda yürürlükteki en fazla izin verilen taksit geçerli olur.
  2034. $max_installment = 0;
  2035.  
  2036. $currency = "TL";
  2037.  
  2038. ####### Bu kısımda herhangi bir değişiklik yapmanıza gerek yoktur. #######
  2039. $hash_str = $merchant_id .$user_ip .$merchant_oid .$email .$payment_amount .$user_basket.$no_installment.$max_installment.$currency.$test_mode;
  2040. $paytr_token=base64_encode(hash_hmac('sha256',$hash_str.$merchant_salt,$merchant_key,true));
  2041. $post_vals=array(
  2042. 'merchant_id'=>$merchant_id,
  2043. 'user_ip'=>$user_ip,
  2044. 'merchant_oid'=>$merchant_oid,
  2045. 'email'=>$email,
  2046. 'payment_amount'=>$payment_amount,
  2047. 'paytr_token'=>$paytr_token,
  2048. 'user_basket'=>$user_basket,
  2049. 'debug_on'=>$debug_on,
  2050. 'no_installment'=>$no_installment,
  2051. 'max_installment'=>$max_installment,
  2052. 'user_name'=>$user_name,
  2053. 'user_address'=>$user_address,
  2054. 'user_phone'=>$user_phone,
  2055. 'merchant_ok_url'=>$merchant_ok_url,
  2056. 'merchant_fail_url'=>$merchant_fail_url,
  2057. 'timeout_limit'=>$timeout_limit,
  2058. 'currency'=>$currency,
  2059. 'test_mode'=>$test_mode
  2060. );
  2061.  
  2062. $ch=curl_init();
  2063. curl_setopt($ch, CURLOPT_URL, "https://www.paytr.com/odeme/api/get-token");
  2064. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  2065. curl_setopt($ch, CURLOPT_POST, 1) ;
  2066. curl_setopt($ch, CURLOPT_POSTFIELDS, $post_vals);
  2067. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  2068. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  2069. curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
  2070. curl_setopt($ch, CURLOPT_TIMEOUT, 20);
  2071. $result = @curl_exec($ch);
  2072.  
  2073. if(curl_errno($ch))
  2074. die("PAYTR IFRAME connection error. err:".curl_error($ch));
  2075.  
  2076. curl_close($ch);
  2077.  
  2078. $result=json_decode($result,1);
  2079.  
  2080. if($result['status']=='success')
  2081.  
  2082. {
  2083. $token=$result['token'];
  2084.  
  2085. }
  2086. else
  2087. die("PAYTR IFRAME failed. reason:".$result['reason']);
  2088.  
  2089.  
  2090. $payment_amount2 = $payment_amount/100;
  2091.  
  2092. $couponBuy = new CouponAction();
  2093. $couponBuy->user_id = Yii::app()->user->id;
  2094. $couponBuy->price = $payment_amount2;
  2095. $couponBuy->merchant_oid = $merchant_oid;
  2096. $couponBuy->paymentstatus = "loading";
  2097. $couponBuy->coupontype = $coupon_type;
  2098. $couponBuy->created = time();
  2099. $couponBuy->save();
  2100.  
  2101.  
  2102.  
  2103. $hesab = Hesablar::model()->findByPk(4);
  2104. $hesab->hesab_mebleg = (float) $hesab->hesab_mebleg + (float) $payment_amount2;
  2105. $hesab->save(false);
  2106.  
  2107. return $this->render('buycouponpaytr',array("getProduct"=>"","datatype"=>"","token"=>$token));
  2108.  
  2109. }
  2110.  
  2111. $this->render('kuponal');
  2112. }
  2113.  
  2114. public function actionKupon(){
  2115.  
  2116. $user = Users::model()->findByPk(Yii::app()->user->id);
  2117.  
  2118. $c = new CDbCriteria();
  2119. $c ->condition = "user_id = '".Yii::app()->user->id."' ";
  2120. $c ->order = "`id` DESC";
  2121. $logs = CouponHistory::model()->findAll($c);
  2122.  
  2123. $sendUserId = Yii::app()->user->id;
  2124. $sendUserInfo = Users::model()->findByPk($sendUserId);
  2125. $sendUserCouponBalance = $sendUserInfo->coupon_balance;
  2126.  
  2127.  
  2128. if(Yii::app()->request->isPostRequest)
  2129. {
  2130. $sendCouponBalance = Yii::app()->request->getPost('coupone_balance');
  2131. $recipientClientId = Yii::app()->request->getPost('recipient_client_id');
  2132. $receiveUserId = $recipientClientId - 100000;
  2133.  
  2134. $receiveUserInfo = Users::model()->findByPk($receiveUserId);
  2135.  
  2136. if($sendCouponBalance == '' || $recipientClientId == '')
  2137. {
  2138. Yii::app()->user->setFlash('is_not_empty', "Xanalar boş olmamalıdır.");
  2139. return $this->render('coupon_balance',array('user' =>$user ,'logs' =>$logs,'aa'=>$aa));
  2140. }
  2141.  
  2142. if($sendUserId+100000 == $recipientClientId)
  2143. {
  2144. Yii::app()->user->setFlash('dont_same_id', "Müştəri kodu eyni ola bilməz.");
  2145. return $this->render('coupon_balance',array('user' =>$user ,'logs' =>$logs));
  2146. }
  2147.  
  2148.  
  2149. if(!$receiveUserInfo)
  2150. {
  2151. Yii::app()->user->setFlash('dont_exist_clinet', "Bu koda uyğun müştəri mövcud deyil.");
  2152.  
  2153. return $this->render('coupon_balance',array('user' =>$user ,'logs' =>$logs));
  2154. }
  2155.  
  2156. if(!is_numeric($sendCouponBalance))
  2157. {
  2158. Yii::app()->user->setFlash('not_numeric', "Məbləğ rəqəm olmalıdır.");
  2159. return $this->render('coupon_balance',array('user' =>$user ,'logs' =>$logs));
  2160. }
  2161.  
  2162. if($sendCouponBalance < 0)
  2163. {
  2164. Yii::app()->user->setFlash('great_than', "Məbləğ 10 TL-dən az olmamalıdır.");
  2165. return $this->render('coupon_balance',array('user' =>$user ,'logs' =>$logs));
  2166. }
  2167.  
  2168. if($sendUserCouponBalance < $_POST['coupone_balance'])
  2169. {
  2170. Yii::app() -> user -> setFlash('insufficient_fund', "Bu əməliyyatı yerinə yetirmək üçün kupon balansınız kifayət qədər deyil");
  2171. return $this->render('coupon_balance',array('user' =>$user ,'logs' =>$logs));
  2172. }
  2173.  
  2174. else
  2175. {
  2176.  
  2177. $subtractionNewBalance = $sendUserCouponBalance - $sendCouponBalance;
  2178. Users::model() -> updateByPk($sendUserId, array('coupon_balance' => $subtractionNewBalance));
  2179.  
  2180. $coupon_send_log = New CouponHistory();
  2181. $coupon_send_log->user_id = $sendUserId;
  2182. $coupon_send_log->date = date('Y-m-d H:i:s');
  2183. $coupon_send_log->log = '- '.$recipientClientId.' kodlu müştəriyə '.$sendCouponBalance.' TL kupon köçürməsi.Hal hazırki balans '.$subtractionNewBalance.') TL | Kupon Tansfer | '.$recipientClientId.' ';
  2184. $coupon_send_log->type = 'send_transfer';
  2185. $coupon_send_log->save();
  2186.  
  2187. $receiveAddBalance = $receiveUserInfo->coupon_balance + $sendCouponBalance;
  2188. Users::model() -> updateByPk($receiveUserId, array('coupon_balance' => $receiveAddBalance));
  2189.  
  2190.  
  2191. $sendClientId = $sendUserId+100000;
  2192. $coupon_receive_log = New CouponHistory();
  2193. $coupon_receive_log->user_id = $receiveUserId;
  2194. $coupon_receive_log->date = date('Y-m-d H:i:s');
  2195. $coupon_receive_log->log = '+'.$sendClientId.' kodlu müştəridən balansa '.$sendCouponBalance.'TL köçürmə.Hal hazırki balans '.$receiveAddBalance.') TL | Kupon Tansfer | '.$sendClientId.' ';
  2196. $coupon_receive_log->type = 'add_transfer';
  2197. $coupon_receive_log->save();
  2198.  
  2199.  
  2200.  
  2201. if($coupon_send_log && $coupon_receive_log )
  2202. {
  2203. $user = Users::model()->findByPk(Yii::app()->user->id);
  2204.  
  2205. $c = new CDbCriteria();
  2206. $c ->condition = "user_id = '".Yii::app()->user->id."' ";
  2207. $c ->order = "`id` DESC";
  2208. $logs = CouponHistory::model()->findAll($c);
  2209.  
  2210. Yii::app()->user->setFlash('success', "Əməliyyat uğurla yerinə yetirlidi.");
  2211. return $this->render('coupon_balance',array('user' =>$user ,'logs' =>$logs));
  2212. }
  2213. else
  2214. {
  2215. Yii::app()->user->setFlash('fail', "Əməliyyatda xəta baş verdi.");
  2216. return $this->render('coupon_balance',array('user' =>$user ,'logs' =>$logs));
  2217. }
  2218.  
  2219.  
  2220.  
  2221. }
  2222.  
  2223. }
  2224.  
  2225.  
  2226. $this->render('coupon_balance',array('user' =>$user ,'logs' =>$logs));
  2227. }
  2228.  
  2229.  
  2230. public function actionTest() {
  2231.  
  2232. $this->pageTitle = 'Mover.az - '. Yii::t('text','Sifarişlərim');
  2233. Yii::app()->clientScript->registerLinkTag('canonical', null, $this -> createAbsoluteUrl('site/Order'));
  2234. $criteria = new CDbCriteria;
  2235. $criteria->with = 'users';
  2236. $criteria->condition = "t.status='1' and t.users_id= :user_id";
  2237. $criteria->order = 't.id asc';
  2238. $criteria->params = array(':user_id' => (int)Yii::app() -> user -> id);
  2239. $orders = Orders::model()->findAll($criteria);
  2240.  
  2241. $last_order = end($orders);
  2242. $model = new Orders();
  2243. $this -> render('test',array('orders'=>$orders,'last_order'=>$last_order,'model'=>$model));
  2244.  
  2245. }
  2246.  
  2247. public function actionOrderDo() {
  2248.  
  2249. $p = Yii::app() -> request -> getPost('key');
  2250. $p = MyClass::purify($p);
  2251. $orders = Orders::model() -> with('users') -> findAll('t.delivery="' . $p . '" and t.status="1" and users_id=:user_id', array(":user_id" => Yii::app() -> user -> id));
  2252. /*if ($orders == NULL)
  2253. throw new CHttpException(404, 'Səhv müraciət');*/
  2254.  
  2255. $this -> renderPartial('orderdo', array('orders' => $orders));
  2256. }
  2257.  
  2258. public function actionTestlayout(){
  2259.  
  2260. $this->layout = "testlayout";
  2261. $this->render('index');
  2262. }
  2263.  
  2264. public function actionMyorder() {
  2265.  
  2266. $id = Yii::app()->user->id;
  2267. $criteria = new CDbCriteria;
  2268. $criteria ->condition = 'users_id=:id AND basket = "0" ';
  2269. $criteria->order = 'id DESC';
  2270. $criteria -> params = array(":id" => $id);
  2271. $orders = Myorder::model()->findAll($criteria);
  2272.  
  2273. $this -> renderPartial('myorder', array('orders' => $orders));
  2274. }
  2275.  
  2276. public function actionForgetPassword() {
  2277. Yii::app()->clientScript->registerLinkTag('canonical', null, $this -> createAbsoluteUrl('site/ForgetPassword'));
  2278. $this->pageTitle = 'Mover.az - '.Yii::t('text','Şifrəni unutmusunuz?');
  2279. Yii::app()->params['OG_IMAGE'] = 'http://mover.az/media/img/ogimg.jpg';
  2280. Yii::app()->params['OG_URL'] = 'http://mover.az';
  2281. Yii::app()->params['OG_TITLE'] = 'Mover.az';
  2282. Yii::app()->params['OG_TEXT'] = Yii::t('text','Şifrəni unutmusunuz?');
  2283. $model = new ForgotPassword();
  2284.  
  2285. if (isset($_POST['ForgotPassword'])) {
  2286. $model -> attributes = CHtml::encodeArray($_POST['ForgotPassword']);
  2287.  
  2288. if ($model -> validate()) {
  2289. $code = sha1(md5(MyClass::RandomPassword(10)));
  2290.  
  2291. Users::model() -> updateByPk($model -> userdata -> id, array('user_activation_key' => $code));
  2292.  
  2293. $to = $model -> userdata -> email;
  2294. $from_name = Yii::app() -> name;
  2295. $from = Yii::app() -> params['adminEmail'];
  2296. $subject = "Şifrə yeniləmə";
  2297. $text_message = "";
  2298. $link = $this -> createAbsoluteUrl('site/resetpassword', array('key' => $code));
  2299. $html_message = "<a href=\"$link\">Şifrəni yeniləmək üçün click edin</a>";
  2300.  
  2301. require '/home/mover.az/mailgun-php/vendor/autoload.php';
  2302. //$httpClient = new Http\Adapter\Guzzle6\Client();
  2303. $mailgunClient = new Mailgun\Mailgun('060c1707ab0899fcf36396af78c8ffa8-059e099e-9f1fe8d6');
  2304. $domain = 'mail.mover.az';
  2305.  
  2306. # Make the call to the client.
  2307. $result = $mailgunClient->sendMessage($domain, array(
  2308. 'from' => 'MOVER.AZ <info@mover.az>',
  2309. 'to' => $to,
  2310. 'subject' => 'Şifrə yeniləmə',
  2311. 'html' => $html_message,
  2312. ));
  2313.  
  2314. if($result->http_response_code == 200)
  2315. {
  2316. Yii::app() -> user -> setFlash('congrat', "Şifrənin dəyişdirilməsi üçün müraciət e-mail ünvanınıza göndərildi");
  2317. $this -> refresh();
  2318. }
  2319.  
  2320.  
  2321.  
  2322. }
  2323.  
  2324. }
  2325.  
  2326. $this -> render('forgetpassword', array('model' => $model));
  2327. }
  2328.  
  2329. public function actionResetPassword($key = NULL) {
  2330.  
  2331. $this->pageTitle = 'Mover.az - '.Yii::t('text','Şifrəni yenilə');
  2332. Yii::app()->params['OG_IMAGE'] = 'http://mover.az/media/img/ogimg.jpg';
  2333. Yii::app()->params['OG_URL'] = 'http://mover.az';
  2334. Yii::app()->params['OG_TITLE'] = 'Mover.az';
  2335. Yii::app()->params['OG_TEXT'] = Yii::t('text','Şifrəni yenilə');
  2336.  
  2337. if ($key == NULL)
  2338. throw new CHttpException(404, 'Səhv müraciət');
  2339. $now = time();
  2340.  
  2341. $user = Users::model() -> findByAttributes(array('user_activation_key' => $key));
  2342.  
  2343. if ($user == NULL)
  2344. throw new CHttpException(404, 'Səhv müraciət');
  2345.  
  2346. $model = new ResetPassword();
  2347. //$model -> user_id = $id;
  2348.  
  2349. if (isset($_POST['ResetPassword'])) {
  2350. $model -> attributes = CHtml::encodeArray($_POST['ResetPassword']);
  2351. $model -> a_key = $key;
  2352. if ($model -> validate()) {
  2353.  
  2354. $new_password = md5(md5($model -> new_password));
  2355. $user -> password = $new_password;
  2356.  
  2357. if ($user -> update(array('password'))) {
  2358. Yii::app() -> user -> setFlash('success', 'Şifrə uğurla yeniləndi');
  2359. }
  2360.  
  2361.  
  2362. }
  2363. }
  2364.  
  2365. $this -> render('resetpassword', array('model' => $model));
  2366. }
  2367.  
  2368. public function actionRegisterAjax() {
  2369.  
  2370. //$this -> setPageTitle('APA - Qeydiyyat forması');
  2371. $model = new Users;
  2372. $model -> scenario = 'register';
  2373.  
  2374. if (isset($_POST['Users'])) {
  2375. $model -> attributes = CHtml::encodeArray($_POST['Users']);
  2376. $day = $_POST['day'];
  2377. $month = $_POST['month'];
  2378. $year = $_POST['year'];
  2379. $sex = $_POST['sex'];
  2380. $optional = intval($_POST['optional']);
  2381. $optional_desc = strip_tags($_POST['optional_desc']);
  2382. $model -> user_activation_key = sha1(md5(time() + rand(999, 999999999)));
  2383. $model -> activation_sms_key = MyClass::GenerateSMSKey();
  2384. $model -> rdate = time();
  2385. $model -> bday = implode('/', array($day,$month,$year));
  2386. $model->sex = $sex;
  2387. $model->status = '1';
  2388. $model->optional = $optional;
  2389. $model->optional_desc = $optional_desc;
  2390. #echo $model -> bday;exit;
  2391. $this -> performAjaxValidation($model);
  2392.  
  2393. if ($model -> validate()) {
  2394.  
  2395. if ($model -> save(FALSE)) {
  2396. // Sms::Send($model -> mobile, "Tesdiqleme kodu: {$model -> activation_sms_key}");
  2397. //$model -> sendActivation();
  2398. }
  2399.  
  2400. echo CJSON::encode(array('status' => 'success','url'=>Yii::app()->createAbsoluteUrl('site/login')));
  2401. Yii::app() -> end();
  2402. } else {
  2403. $error = CActiveForm::validate($model);
  2404. echo $error;
  2405. Yii::app() -> end();
  2406. }
  2407. }
  2408. }
  2409.  
  2410.  
  2411. //beyanname formu
  2412. public function actionFaktura() {
  2413.  
  2414. //$this -> setPageTitle('APA - Qeydiyyat forması');
  2415. $model = new Orders;
  2416. //$model -> scenario = 'register';
  2417.  
  2418. if (isset($_POST['Orders'])) {
  2419. $newPhoto = CUploadedFile::getInstance($model, 'file');
  2420. if(!$newPhoto){
  2421. echo CJSON::encode(array('status' => 'failed','Orders_file'=>Yii::t('text','İnvoice boşdur')));
  2422. Yii::app() -> end();
  2423. }
  2424. $model -> attributes = CHtml::encodeArray($_POST['Orders']);
  2425. $model->users_id = Yii::app()->user->id;
  2426. //$model->userkey = $model->users->user_key;
  2427. $model->delivery = '1';
  2428. $model->status = '1';
  2429. $model->addedbyuser = '1';
  2430. $model->date1 = $_POST['Orders']['date1'];
  2431. $model->order_key = substr(uniqid(mt_rand()) , 0, 8);
  2432. $model->add_date = date("Y-m-d H:i:s");
  2433. $this -> performAjaxValidation($model);
  2434. if ($model -> validate()) {
  2435. $model->file = empty($newPhoto) ? $model->file : $newPhoto;
  2436. if(!empty($newPhoto))
  2437. {
  2438. $photoPath = Yii::app()->params['invoice_path'];
  2439.  
  2440. if (!file_exists($photoPath)) {
  2441. mkdir($photoPath, 0777, true);
  2442. }
  2443. $name = time().$newPhoto->getName();
  2444.  
  2445. $a = pathinfo($name);
  2446. $name = md5($a['filename']).".".$a['extension'];
  2447.  
  2448.  
  2449. $model->file->saveAs($photoPath.$name);
  2450. $model->file = $name;
  2451. }
  2452.  
  2453.  
  2454. $model -> save(FALSE);
  2455. echo CJSON::encode(array('status' => 'success','alert'=>Yii::t('text','Bəyannamə göndərildi')));
  2456. Yii::app() -> end();
  2457. } else {
  2458. $error = CActiveForm::validate($model);
  2459. echo $error;
  2460. Yii::app() -> end();
  2461. }
  2462. }
  2463. }
  2464.  
  2465. public function actionNewInvoice() {
  2466. //var_dump($_POST); die;
  2467. $model = new Orders;
  2468.  
  2469. if (isset($_POST['Orders'])) {
  2470. $model -> attributes = CHtml::encodeArray($_POST['Orders']);
  2471. $newPhoto = CUploadedFile::getInstance($model, 'file');
  2472. if($_POST['gift'] == 1 ){
  2473. $model->price = 0;
  2474. }else{
  2475. if((!isset($_POST['Orders']['from']) || $_POST['Orders']['from'] != 'other') && !$newPhoto){
  2476. echo CJSON::encode(array('status' => 'failed','Orders_file'=>Yii::t('text','İnvoice boşdur')));
  2477. Yii::app() -> end();
  2478. }
  2479. }
  2480.  
  2481. $model->users_id = Yii::app()->user->id;
  2482. //$model->userkey = $model->users->user_key;
  2483. $model->delivery = '1';
  2484. $model->status = '1';
  2485. $model->valute_id = $_POST['Orders']['valute_id'];
  2486. $model->addedbyuser = '1';
  2487. $model->date1 = $_POST['Orders']['date1'];
  2488. $model->order_key = substr(uniqid(mt_rand()) , 0, 8);
  2489. if($_POST['Orders']['magaza_tracking'] == 1)
  2490. {
  2491. $model->magaza_order_id = $_POST['Orders']['magaza_order_id'];
  2492. }
  2493. elseif($_POST['Orders']['magaza_tracking'] == 2)
  2494. {
  2495. $model->magaza_tracking = $_POST['Orders']['magaza_order_id'];
  2496. }
  2497. $model->add_date = date("Y-m-d H:i:s");
  2498. $this -> performAjaxValidation($model);
  2499. if ($model -> validate()) {
  2500. $model->file = empty($newPhoto) ? $model->file : $newPhoto;
  2501. if(!empty($newPhoto))
  2502. {
  2503. $photoPath = Yii::app()->params['invoice_path'];
  2504.  
  2505. if (!file_exists($photoPath)) {
  2506. mkdir($photoPath, 0777, true);
  2507. }
  2508. $name = time().$newPhoto->getName();
  2509.  
  2510. $a = pathinfo($name);
  2511. $name = md5($a['filename']).".".$a['extension'];
  2512.  
  2513.  
  2514. $model->file->saveAs($photoPath.$name);
  2515. $model->file = $name;
  2516. }
  2517.  
  2518.  
  2519. $model -> save(FALSE);
  2520.  
  2521. if(isset($_POST['Orders']['from']) && $_POST['Orders']['from'] == 'other'){
  2522. $Receiver = new Receiver;
  2523. $Receiver->order_id = $model->id;
  2524. $Receiver->users_id = $model->users_id;
  2525. $Receiver->fullname = $_POST['Orders']['receiver_fullname'];
  2526. $Receiver->phone = $_POST['Orders']['receiver_phone'];
  2527. $Receiver->address = $_POST['Orders']['receiver_address'];
  2528. $Receiver->uid = $_POST['Orders']['receiver_id'];
  2529. if(!$Receiver->save(false)){
  2530. var_dump($Receiver);
  2531. $error = CActiveForm::validate($Receiver);
  2532. echo $error;
  2533. Yii::app() -> end();
  2534. }
  2535. }
  2536.  
  2537. echo CJSON::encode(array('status' => 'success','alert'=>Yii::t('text','Bəyannamə göndərildi')));
  2538. Yii::app() -> end();
  2539.  
  2540. } else {
  2541. $error = CActiveForm::validate($model);
  2542. echo $error;
  2543. Yii::app() -> end();
  2544. }
  2545. }
  2546. }
  2547.  
  2548. public function actionAddBeyenname() {
  2549.  
  2550. $model = Orders::model()->findByPk((int)$_POST['Orders']['id']);
  2551. $old = clone $model;
  2552.  
  2553. if ($model == NULL)
  2554. throw new CHttpException(404, 'Səhv müraciət');
  2555. if ($model->users_id != Yii::app()->user->id)
  2556. throw new CHttpException(404, 'Səhv müraciət');
  2557.  
  2558. if (isset($_POST['Orders'])) {
  2559. $newPhoto = CUploadedFile::getInstance($model, 'file');
  2560. if(!$newPhoto && strlen($model->file) <2){
  2561. echo CJSON::encode(array('status' => 'failed','Orders_file'=>Yii::t('text','İnvoice boşdur')));
  2562. Yii::app() -> end();
  2563. }
  2564. $model -> attributes = CHtml::encodeArray($_POST['Orders']);
  2565.  
  2566. $model->delivery = ($model->delivery == '1')? '1':'8';
  2567. $model->edit_date = date("Y-m-d H:i:s");
  2568. $model->date8 = date("Y-m-d");
  2569.  
  2570. $this -> performAjaxValidation($model);
  2571. if ($model -> validate()) {
  2572.  
  2573. $model->file = empty($newPhoto) ? $model->file : $newPhoto;
  2574. if(!empty($newPhoto))
  2575. {
  2576. $photoPath = Yii::app()->params['invoice_path'];
  2577.  
  2578. if (!file_exists($photoPath)) {
  2579. mkdir($photoPath, 0777, true);
  2580. }
  2581. $name = time().$newPhoto->getName();
  2582.  
  2583. $a = pathinfo($name);
  2584. $name = md5($a['filename']).".".$a['extension'];
  2585.  
  2586.  
  2587. $model->file->saveAs($photoPath.$name);
  2588. $model->file = $name;
  2589. }
  2590.  
  2591. $model -> save(FALSE);
  2592.  
  2593.  
  2594. /*********************************************
  2595. * Istifadeci melumatlari deyishende loqlamaq
  2596. *********************************************/
  2597. $message = "İstifadəçi məhsulun dəyişdi:";
  2598. $message .= "Ölkə: ".$old ->country_id ." -> ".$model ->country_id ;
  2599. $message .= "Qiymət: ".$old ->price ." -> ". $model ->price ;
  2600. $message .= "Valyuta: ".$old ->valute_id ." -> ".$model ->valute_id;
  2601. $message .= "Bağlama sayı: ".$old ->count ." -> ".$model ->count;
  2602. $message .= "Sifariş tarixi: ".$old ->date1 ." -> ".$model ->date1;
  2603. $message .= "Şərh: ".$old ->comments ." -> ".$model ->comments;
  2604. $message .= "Mağaza: ".$old ->shop ." -> ".$model ->shop;
  2605.  
  2606.  
  2607. Iplog::write($message);
  2608. /*********************************
  2609. * Log end
  2610. *******************************/
  2611.  
  2612. echo CJSON::encode(array('status' => 'success','alert'=>Yii::t('text','Redaktə edildi')));
  2613. Yii::app() -> end();
  2614. } else {
  2615. $error = CActiveForm::validate($model);
  2616. echo $error;
  2617. Yii::app() -> end();
  2618. }
  2619. }
  2620. }
  2621.  
  2622. public function actionEditFaktura() {
  2623.  
  2624. /*print_r($_POST);
  2625. exit;*/
  2626. //$this -> setPageTitle('APA - Qeydiyyat forması');
  2627. $model = Orders::model()->findByPk((int)$_POST['Orders']['id']);
  2628. $old = clone $model;
  2629.  
  2630. if ($model == NULL)
  2631. throw new CHttpException(404, 'Səhv müraciət');
  2632. if ($model->users_id != Yii::app()->user->id)
  2633. throw new CHttpException(404, 'Səhv müraciət');
  2634. //$model -> scenario = 'register';
  2635.  
  2636. if (isset($_POST['Orders'])) {
  2637.  
  2638. $newPhoto = CUploadedFile::getInstance($model, 'file');
  2639. if(!$newPhoto){
  2640. echo CJSON::encode(array('status' => 'failed','Orders_file'=>Yii::t('text','İnvoice boşdur')));
  2641. Yii::app() -> end();
  2642. }
  2643. $model -> attributes = CHtml::encodeArray($_POST['Orders']);
  2644. $model->users_id = Yii::app()->user->id;
  2645. //$model->userkey = $model->users->user_key;
  2646. $model->status = '1';
  2647. $model->edit_date = date("Y-m-d H:i:s");
  2648. $this -> performAjaxValidation($model);
  2649.  
  2650. if ($model -> validate()) {
  2651.  
  2652.  
  2653. $model->file = empty($newPhoto) ? $model->file : $newPhoto;
  2654. if(!empty($newPhoto))
  2655. {
  2656. $photoPath = Yii::app()->params['invoice_path'];
  2657.  
  2658. if (!file_exists($photoPath)) {
  2659. mkdir($photoPath, 0777, true);
  2660. }
  2661. $name = time().$newPhoto->getName();
  2662.  
  2663. $a = pathinfo($name);
  2664. $name = md5($a['filename']).".".$a['extension'];
  2665.  
  2666.  
  2667. $model->file->saveAs($photoPath.$name);
  2668. $model->file = $name;
  2669. }
  2670.  
  2671. $model -> save(FALSE);
  2672.  
  2673.  
  2674. /*********************************************
  2675. * Istifadeci melumatlari deyishende loqlamaq
  2676. *********************************************/
  2677. $message = "İstifadəçi məhsulun dəyişdi:";
  2678. $message .= "Ölkə: ".$old ->country_id ." -> ".$model ->country_id ;
  2679. $message .= "Qiymət: ".$old ->price ." -> ". $model ->price ;
  2680. $message .= "Valyuta: ".$old ->valute_id ." -> ".$model ->valute_id;
  2681. $message .= "Bağlama sayı: ".$old ->count ." -> ".$model ->count;
  2682. $message .= "Sifariş tarixi: ".$old ->date1 ." -> ".$model ->date1;
  2683. $message .= "Şərh: ".$old ->comments ." -> ".$model ->comments;
  2684. $message .= "Mağaza: ".$old ->shop ." -> ".$model ->shop;
  2685.  
  2686.  
  2687. Iplog::write($message);
  2688. /*********************************
  2689. * Log end
  2690. *******************************/
  2691.  
  2692. echo CJSON::encode(array('status' => 'success','alert'=>Yii::t('text','Redaktə edildi')));
  2693. Yii::app() -> end();
  2694. } else {
  2695. $error = CActiveForm::validate($model);
  2696. echo $error;
  2697. Yii::app() -> end();
  2698. }
  2699. }
  2700. }
  2701.  
  2702. public function actionLogin() {
  2703.  
  2704. if(isset(Yii::app()->user->id)){
  2705. return $this->redirect(array('site/bundle'));
  2706. }
  2707. $model = new LoginForm;
  2708. $is_cookie = isset(Yii::app()->request->cookies['order_details']);
  2709.  
  2710. if (isset($_POST['ajax']) && $_POST['ajax'] === 'login-form') {
  2711. $errors = CActiveForm::validate($model);
  2712. if ($errors != '[]') {
  2713. echo $errors;
  2714. Yii::app() -> end();
  2715. }
  2716.  
  2717. }
  2718.  
  2719. // <span class="IL_AD" id="IL_AD4">collect</span> user input data
  2720. if (isset($_POST['LoginForm'])) {
  2721. $model -> attributes = CHtml::encodeArray($_POST['LoginForm']);
  2722.  
  2723. $lg = $model -> login();
  2724. if ($model -> validate() && $lg['result'] ) {
  2725. $cookie1 = new CHttpCookie('name',Yii::app()->user->getFirstName());
  2726. $cookie1->expire = time() + ($lg['duration']);
  2727. Yii::app()->request->cookies['name'] = $cookie1;
  2728.  
  2729.  
  2730. $cookie2 = new CHttpCookie('surname',Yii::app()->user->getSurname());
  2731. $cookie2->expire = time() + ($lg['duration']);
  2732. Yii::app()->request->cookies['surname'] = $cookie2;
  2733.  
  2734.  
  2735. $cookie3 = new CHttpCookie('userkey',Yii::app()->user->getUserCode());
  2736. $cookie3->expire = time() + ($lg['duration']);
  2737. Yii::app()->request->cookies['userkey'] = $cookie3;
  2738.  
  2739. $cookie4 = new CHttpCookie('email',Yii::app()->user->getEmail());
  2740. $cookie4->expire = time() + ($lg['duration']);
  2741. Yii::app()->request->cookies['email'] = $cookie4;
  2742.  
  2743. $cookie5 = new CHttpCookie('moverauth',base64_encode(Yii::app()->user->id));
  2744. $cookie5->expire = time() + ($lg['duration']);
  2745. Yii::app()->request->cookies['moverauth'] = $cookie5;
  2746.  
  2747.  
  2748. Users::model() -> updateByPk(Yii::app()->user->id, array('ldate' => time()));
  2749.  
  2750.  
  2751. if (!empty($lg['redirect'])){
  2752. echo CJSON::encode(array('authenticated' => true,'redirectUrl'=>$lg['redirect']));
  2753. Yii::app() -> end();
  2754. }
  2755.  
  2756. if($is_cookie) {
  2757. $cook = json_decode(Yii::app()->request->cookies['order_details']->value);
  2758. $order = new Myorder;
  2759. $order->link = $cook->link;
  2760. $order->comment = $cook->comment;
  2761. $order->users_id = Yii::app()->user->id;
  2762. $order->order_key = $cook->code;
  2763. $order->date = time();
  2764. $order->save(FALSE);
  2765. //$this -> redirect(array('succesorder', 'code' => $cook->code));
  2766. $redirect_url = CHtml::normalizeUrl(array("site/succesorder","code"=>$cook->code));
  2767. }
  2768. else {
  2769. $redirect_url = CHtml::normalizeUrl(array("site/bundle"));
  2770. }
  2771.  
  2772. if (isset($_POST['ajax']) && $_POST['ajax'] === 'login-form') {
  2773.  
  2774. echo CJSON::encode(array('authenticated' => true, 'redirectUrl' =>$redirect_url
  2775. //"param" => "Any additional param"
  2776. ));
  2777. Yii::app() -> end();
  2778. }
  2779. $this -> redirect(Yii::app() -> user -> returnUrl);
  2780. }
  2781. }
  2782. // display the login form
  2783. $this -> render('login', array('model' => $model));
  2784.  
  2785. }
  2786.  
  2787. protected function performAjaxValidation($model) {
  2788.  
  2789. if (isset($_POST['ajax']) && $_POST['ajax'] === 'users-form') {
  2790. echo CActiveForm::validate($model);
  2791. Yii::app() -> end();
  2792. }
  2793. }
  2794.  
  2795. public function actionRegister() {
  2796.  
  2797. $this -> setPageTitle('Mover.az - Qeydiyyat forması');
  2798. $model = new Users;
  2799. $model -> scenario = 'register';
  2800. // Uncomment the following line if AJAX validation is needed
  2801. //$this->performAjaxValidation($model);
  2802.  
  2803. if (isset($_POST['Users'])) {
  2804. $model -> attributes = CHtml::encodeArray($_POST['Users']);
  2805. $model -> status = '1';
  2806. $model -> rdate = time();
  2807. //$model -> mobile = $model->mobile;
  2808. $model -> user_activation_key = sha1(md5(time() + rand(999, 999999999)));
  2809. if ($model -> save()) {
  2810. Yii::app() -> user -> setFlash('saved', "Qeydiyyatdan keçildi");
  2811.  
  2812. if ($model -> sendActivation())
  2813. $this -> redirect(array('thankyou', 'id' => $model -> id));
  2814. else
  2815. throw new CHttpException(200, "Email aktivasiyası alınmadı");
  2816. } else {
  2817. Yii::app() -> user -> setFlash('failure', "Xəta var");
  2818. }
  2819. }
  2820.  
  2821. $this -> render('register', array('model' => $model, ));
  2822.  
  2823. }
  2824.  
  2825. public function actionThankYou() {
  2826.  
  2827. $this -> setPageTitle('Mover.az - Təşəkkür mesajı');
  2828. $this -> render('thankyou', array(
  2829. //'model'=>$model,
  2830. ));
  2831. }
  2832.  
  2833. public function actionActivate($a) {
  2834. if ($a != '') {
  2835. $model = Users::model() -> find('user_activation_key=:a', array(':a' => $a));
  2836.  
  2837. if ($model) {
  2838. // /$model->activate='';
  2839. if ($model -> status != 1) {
  2840. $model -> status = 1;
  2841. $model -> balance = 0;
  2842. $model -> user_activation_key = '';
  2843. $model -> activation_sms_key = '';
  2844. if ($model -> update(array('status', 'user_activation_key', 'activation_sms_key','balance'))) {
  2845.  
  2846. $this -> render('activate', array('model' => $model, 'status' => 'success'));
  2847. }
  2848. } else {
  2849. Yii::app() -> user -> logout();
  2850. $this -> render('activate', array('model' => $model, 'status' => 'already'));
  2851. }
  2852. } else {
  2853. throw new CHttpException(404, "Yalnış altivasiya kodu");
  2854. }
  2855. } else {
  2856. $this -> redirect(Yii::app() -> homeUrl);
  2857. }
  2858. }
  2859.  
  2860. public function actionSMSCheck($a) {
  2861.  
  2862. if ($a != '') {
  2863. $user = Users::model() -> findByAttributes(array('user_activation_key' => $a));
  2864. if($user) {
  2865. $model = new SMSForm();
  2866. if (isset($_POST['SMSForm'])) {
  2867. $model -> attributes = CHtml::encodeArray($_POST['SMSForm']);
  2868. $model -> a_key = $a;
  2869.  
  2870. if ($model -> validate()) {
  2871.  
  2872. if ($user -> status != 1) {
  2873. $user -> status = 1;
  2874. $user -> balance = 0;
  2875. $user -> user_activation_key = '';
  2876. $user -> activation_sms_key = '';
  2877. if ($user -> update(array('status', 'user_activation_key', 'activation_sms_key','balance'))) {
  2878.  
  2879. Yii::app() -> user -> setFlash('smsactivate','<p>Sizin hesabınız aktivləşdirildi. Daxil ola bilərsiniz</p>');
  2880. }
  2881. else {
  2882.  
  2883. Yii::app() -> user -> setFlash('smsactivate','<p>Hesabınız artıq aktivləşdirilib.Daxil ola bilərsiniz </p>');
  2884. }
  2885. }
  2886. else {
  2887. $this -> redirect(Yii::app() -> homeUrl);
  2888. }
  2889. }
  2890. }
  2891. }
  2892. else {
  2893. throw new CHttpException(404, "Yalnış altivasiya kodu");
  2894. }
  2895.  
  2896. } else {
  2897. $this -> redirect(Yii::app() -> homeUrl);
  2898. }
  2899.  
  2900. $this -> render('sms', array('model' => $model));
  2901. }
  2902.  
  2903. public function actionError() {
  2904. if ($error = Yii::app() -> errorHandler -> error) {
  2905. if (Yii::app() -> request -> isAjaxRequest)
  2906. echo $error['message'];
  2907. else
  2908. $this -> render('error', $error);
  2909. }
  2910. }
  2911.  
  2912. public function actionError2() {
  2913. if ($error = Yii::app() -> errorHandler -> error) {
  2914. if (Yii::app() -> request -> isAjaxRequest)
  2915. echo $error['message'];
  2916. else
  2917. $this -> render('error_2', $error);
  2918. }
  2919. }
  2920.  
  2921. public function actionThanks(){
  2922. $this -> render('thanks');
  2923. }
  2924.  
  2925. public function actionContact() {
  2926.  
  2927. if(Yii::app()->language=="az")
  2928. {
  2929. $this->pageTitle = 'Əlaqə | Mover.az';
  2930. Yii::app() -> clientScript -> registerMetaTag(Yii::t('text', 'mover.az, əlaqə məlumatları, mover ünvan, mover telefon, çatdırılma xidməti, türkiyədən geyim sifarişi'), 'keywords');
  2931. }
  2932. elseif(Yii::app()->language=="en")
  2933. {
  2934. $this->pageTitle = 'Contacts | Mover.az';
  2935. Yii::app() -> clientScript -> registerMetaTag(Yii::t('text', 'mover.az, contact information, mover.az address, mover.az telephone, courier service, order dress from turkey'), 'keywords');
  2936. }
  2937.  
  2938. Yii::app()->params['OG_IMAGE'] = 'http://mover.az/media/img/ogimg.jpg';
  2939. Yii::app()->params['OG_URL'] = $this->createAbsoluteUrl('site/contact');
  2940. Yii::app()->params['OG_TITLE'] = 'Mover.az';
  2941. Yii::app()->params['OG_TEXT'] = Yii::t('text','Əlaqə');
  2942. Yii::app()->clientScript->registerLinkTag('canonical', null, $this -> createAbsoluteUrl('site/Contact'));
  2943. $model = new ContactForm;
  2944. if (isset($_POST['ContactForm'])) {
  2945. $model -> attributes = CHtml::encodeArray($_POST['ContactForm']);
  2946. if ($model -> validate()) {
  2947.  
  2948. $body = '<h2> Ad,Soyad:' . $model -> name . '</h2><h4> Email:' . $model -> email . '</h4><p>Mətn:<br>' . $model -> body . '</p>';
  2949.  
  2950. $mail = new PHPMailer();
  2951. $mail -> IsSMTP();
  2952. $mail -> SMTPAuth = true;
  2953. $mail -> Host = 'smtp.gmail.com';
  2954. $mail -> Port = 587;
  2955. $mail -> SMTPSecure = 'tls';
  2956. $mail -> Username = 'apanoreplyregister@apa.az';
  2957. $mail -> Password = 'delixanamania!';
  2958. $mail -> SetFrom($mail -> Username, 'MOVER.AZ');
  2959. $mail -> AddAddress('info@mover.az');
  2960. $mail -> CharSet = 'UTF-8';
  2961. $mail -> Subject = 'Kontakt form - Mover';
  2962.  
  2963. $mail -> MsgHTML($body);
  2964.  
  2965. if ($mail -> Send()) {
  2966.  
  2967. if(isset(Yii::app()->user->id))
  2968. {
  2969. $task = new Tasks;
  2970. $task->kime = 1;
  2971. $task->creator = Yii::app()->user->id;
  2972. $task->status = 1;
  2973. $task->baslama_tarixi = date('Y-m-d H:i:s');
  2974. $task->prioritet = 1;
  2975. $task->ad = 'Əlaqə formundan';
  2976. $task->melumat = strip_tags($model -> body);
  2977. $task->mail = Yii::app()->user->getEmail();
  2978. $task->fullname = Yii::app()->user->getFirstName()." ".Yii::app()->user->getSurname();
  2979. $task->save(false);
  2980. }else{
  2981. $task = new Feedback;
  2982. $task->message = strip_tags($model -> body);
  2983. $task->email = strip_tags($model -> email);
  2984. $task->fullname = strip_tags($model->name);
  2985. $task->save(false);
  2986. }
  2987.  
  2988.  
  2989. Yii::app() -> user -> setFlash('contact', 'Məktubunuz göndərildi');
  2990. $this -> refresh();
  2991. }
  2992.  
  2993.  
  2994. }
  2995. }
  2996. $this -> render('contact', array('model' => $model));
  2997. }
  2998.  
  2999.  
  3000. public function actionNews($id = null,$view=1) {
  3001.  
  3002. if ($id == null) {
  3003. //$this->pageTitle = Yii::t('text','Yeniliklər və xəbərlər');
  3004. $c = new CDbCriteria();
  3005. $c -> condition = "status=:status";
  3006. $c -> order = "data_created DESC";
  3007. $c -> params = array(":status" => "1");
  3008.  
  3009. $model = News::model() -> find($c);
  3010. } else {
  3011. $model = News::model() -> with(array('newsContents' => array('condition' => "news_id=:id", 'params' => array(':id' => $id)))) -> find();
  3012. }
  3013.  
  3014. if(Yii::app()->language=="az")
  3015. {
  3016. $this->pageTitle = 'Xəbərlər | Mover.az';
  3017. Yii::app() -> clientScript -> registerMetaTag(Yii::t('text', 'mover.az endirimlər, kampaniyalar, xidmətlər'), 'keywords');
  3018. }
  3019. elseif(Yii::app()->language=="en")
  3020. {
  3021. $this->pageTitle = 'News | Mover.az';
  3022. Yii::app() -> clientScript -> registerMetaTag(Yii::t('text', 'mover.az discounts, campaigns, services'), 'keywords');
  3023. }
  3024.  
  3025. if (!$model || !$model->newsContents)
  3026. $this -> redirect(Yii::app() -> homeUrl);
  3027.  
  3028. $con = new CDbCriteria();
  3029. $con -> condition = "status=:status AND id <> :current_news";
  3030. $con -> order = "data_created DESC";
  3031. $con -> limit = 5;
  3032. $con -> params = array(":status" => "1", ":current_news" => $model -> id);
  3033.  
  3034. Yii::app()->params['OG_IMAGE'] = News::image($model->image);
  3035. Yii::app()->params['OG_URL'] = $this->createAbsoluteUrl('site/news',array('id'=>$model -> id));
  3036. Yii::app()->params['OG_TITLE'] = 'Mover.az';
  3037. Yii::app()->params['OG_TEXT'] = $model->newsContents->title;
  3038. Yii::app()->clientScript->registerLinkTag('canonical', null, $this->createAbsoluteUrl('site/news',array('id'=>$model -> id)));
  3039. $other_news = News::model() -> findAll($con);
  3040.  
  3041.  
  3042. if ($view == 1){
  3043. $this -> render('news', array('model' => $model, 'othernews' => $other_news));
  3044. }else{
  3045. $this -> render('news_other', array('model' => $model, 'othernews' => $other_news));
  3046. }
  3047.  
  3048. }
  3049.  
  3050.  
  3051. public function actionAjaxNews() {
  3052.  
  3053. if (!Yii::app() -> request -> isAjaxRequest)
  3054. throw new CHttpException(404, 'Səhifə tapılmadı');
  3055.  
  3056. if (!isset($_POST['page']) || empty($_POST['page']) || !isset($_POST[Yii::app() -> request -> csrfTokenName]))
  3057. $page = 1;
  3058. else
  3059.  
  3060. $page = (int)($_POST['page']);
  3061.  
  3062. $limit = 5;
  3063.  
  3064. $offset = ($page - 1) * $limit;
  3065.  
  3066. $criteria = new CDbCriteria();
  3067. $criteria -> order = '`data_created` DESC ';
  3068. //, `id` ASC
  3069. $criteria -> condition = '`status` = "1" and `data_created` <' . time();
  3070. $criteria -> limit = $limit;
  3071. $criteria -> offset = $offset;
  3072.  
  3073. $news = News::model() -> findAll($criteria);
  3074.  
  3075. /* end of the ajax request */
  3076.  
  3077. if ($news == NULL)
  3078. Yii::app() -> end();
  3079.  
  3080. $this -> renderPartial('ajaxnews', array('news' => $news));
  3081.  
  3082. }
  3083.  
  3084. public function actionPost($id) {
  3085.  
  3086. $about = false;
  3087. $model = Post::model() -> with(array('postContents' => array('condition' => "post_id=:id", 'params' => array(':id' => $id)))) -> find();
  3088.  
  3089. if ($model == null) {
  3090. $this -> redirect('index');
  3091. }
  3092.  
  3093. if ($id==9) {
  3094. Yii::app()->params['OG_IMAGE'] = 'http://mover.az/upload/post/images/img.png';
  3095. $about = true;
  3096. if(Yii::app()->language=="az")
  3097. {
  3098. Yii::app() -> clientScript -> registerMetaTag(Yii::t('text', 'mover.az, peşəkar xidmət, sərfəli qiymət, türkiyədən çatdırılma, Azərbaycan şirkəti, yüklərin daşınması xidməti'), 'keywords');
  3099. $this->pageTitle = 'Haqqımızda | Mover.az';
  3100. }
  3101. elseif(Yii::app()->language=="en")
  3102. {
  3103. Yii::app() -> clientScript -> registerMetaTag(Yii::t('text', 'mover.az, professional service, affordable price, delivery from turkey, azerbaijan company, logistic company'), 'keywords');
  3104. $this->pageTitle = 'About us | Mover.az';
  3105. }
  3106. }
  3107. else
  3108. {
  3109. if(Yii::app()->language=="az")
  3110. Yii::app() -> clientScript -> registerMetaTag(Yii::t('text', 'mover.az, onlayn alış-veriş, çatdırılma xidməti, türkiyədən sifariş, türkiyə saytları, etibarlı şirkət, geyim sifarişi, ayaqqabı sifarişi'), 'keywords');
  3111. elseif(Yii::app()->language=="en")
  3112. Yii::app() -> clientScript -> registerMetaTag(Yii::t('text', 'mover.az, online shopping, delivery service, order from turkey, turkey online shopping webpages, trusted company, dress order, shoes order'), 'keywords');
  3113.  
  3114. $this->pageTitle = 'Mover.az - '. $model->postContents[0]->title;
  3115. }
  3116.  
  3117. Yii::app()->params['OG_URL'] = $this->createAbsoluteUrl('site/post',array('id'=>$id));
  3118. Yii::app()->params['OG_TITLE'] = 'Mover.az';
  3119. Yii::app()->params['OG_TEXT'] = $model->postContents[0]->title;
  3120. Yii::app()->clientScript->registerLinkTag('canonical', null, $this->createAbsoluteUrl('site/post',array('id'=>$id)));
  3121. $this -> render('post', array('model' => $model, 'about' => $about));
  3122.  
  3123. }
  3124.  
  3125. public function actionProfile() {
  3126.  
  3127. $this->pageTitle = 'Mover.az - '. Yii::t('text','Profilim');
  3128. $model = new Users();
  3129. $order = new Orders();
  3130. $criteria = new CDbCriteria;
  3131. $criteria->condition = "users_id = ".Yii::app()->user->id." and sundurma=1";
  3132. $sundurma = Orders::model()->findAll($criteria);
  3133. $this -> render('profile',array('model'=>$order, 'sundurma' =>$sundurma));
  3134. }
  3135.  
  3136. public function actionSites($id = null) {
  3137.  
  3138. if(Yii::app()->language=="az")
  3139. {
  3140. $this->pageTitle = 'Nümunə saytlar | Mover.az';
  3141. Yii::app() -> clientScript -> registerMetaTag(Yii::t('text', 'mover.az, onlayn geyim saytları, türkiyə saytları, alış-veriş'), 'keywords');
  3142. }
  3143. elseif(Yii::app()->language=="en")
  3144. {
  3145. $this->pageTitle = 'List of webpages | Mover.az';
  3146. Yii::app() -> clientScript -> registerMetaTag(Yii::t('text', 'mover.az, online dress shopping, online turkey sites'), 'keywords');
  3147. }
  3148. //$this->pageTitle = 'Mover.az - '. Yii::t('text','Alış-veriş saytları');
  3149. Yii::app()->params['OG_IMAGE'] = 'http://mover.az/media/img/ogimg.jpg';
  3150. Yii::app()->params['OG_URL'] = $this->createAbsoluteUrl('site/sites');
  3151. Yii::app()->params['OG_TITLE'] = 'Mover.az';
  3152. Yii::app()->params['OG_TEXT'] = Yii::t('text','Alış-veriş saytları');
  3153. Yii::app()->clientScript->registerLinkTag('canonical', null, $this->createAbsoluteUrl('site/sites'));
  3154. $categories = Category::model() -> with(array('categoryContents' => array('condition' => 'status="1"', 'order' => 't.order asc'))) -> findAll();
  3155. if (empty($id)) {
  3156. $model_tr = Sites::model() -> with('sitesContents') -> findAll(array('condition' => "category_id=:cat_id and status='1'", 'params' => array(':cat_id' => 2), 'order' => 't.order asc'));
  3157. $model_us = Sites::model() -> with('sitesContents') -> findAll(array('condition' => "category_id=:cat_id and status='1'", 'params' => array(':cat_id' => 1), 'order' => 't.order asc'));
  3158. } else {
  3159. $model = Sites::model() -> with('sitesContents') -> findAll(array('order' => 't.order asc', 'condition' => "category_id=:cat_id and status='1'", 'params' => array(':cat_id' => $id)));
  3160. }
  3161. //$model = Sites::model() -> with('sitesContents') -> findAll();
  3162. //print_r($model);exit;
  3163.  
  3164. /*if ($model == null) {
  3165. $this -> redirect('index');
  3166. }*/
  3167.  
  3168. $this -> render('sites', array('model_tr' => $model_tr,'model_us' => $model_us, 'categories' => $categories, 'id' => $id));
  3169.  
  3170. }
  3171.  
  3172. public function actionCalcPrice() {
  3173.  
  3174.  
  3175. $model = Post::model() -> with('postContents') -> findByPk(10);
  3176. $this->pageTitle = 'Mover.az - '. $model->postContents[0]->title;
  3177. Yii::app()->params['OG_IMAGE'] = 'http://mover.az/media/img/ogimg.jpg';
  3178. Yii::app()->params['OG_URL'] = $this->createAbsoluteUrl('site/CalcPrice');
  3179. Yii::app()->params['OG_TITLE'] = 'Mover.az';
  3180. Yii::app()->params['OG_TEXT'] = $model->postContents[0]->title;
  3181. Yii::app()->clientScript->registerLinkTag('canonical', null, $this->createAbsoluteUrl('site/CalcPrice'));
  3182. $this -> render('del_price', array('model' => $model));
  3183. }
  3184.  
  3185. public function actionSize()
  3186. {
  3187.  
  3188. $this->pageTitle = 'Mover.az - '. Yii::t('text','Həcmə görə çəki');
  3189. Yii::app()->params['OG_IMAGE'] = 'http://mover.az/media/img/ogimg.jpg';
  3190. Yii::app()->params['OG_URL'] = $this->createAbsoluteUrl('site/size');
  3191. Yii::app()->params['OG_TITLE'] = 'Mover.az';
  3192. Yii::app()->params['OG_TEXT'] = Yii::t('text','Həcmə görə çəki');
  3193. Yii::app()->clientScript->registerLinkTag('canonical', null, $this->createAbsoluteUrl('site/size'));
  3194. $this -> render('size');
  3195. }
  3196.  
  3197. public function actionRecomended() {
  3198. Yii::app()->params['OG_IMAGE'] = 'http://mover.az/media/img/ogimg.jpg';
  3199. Yii::app()->params['OG_URL'] = $this->createAbsoluteUrl('site/Recomended');
  3200. Yii::app()->params['OG_TITLE'] = 'Mover.az';
  3201. Yii::app()->params['OG_TEXT'] = Yii::t('text','Tövsiyyə edilən məhsullar');
  3202. $this->pageTitle = 'Mover.az - '. Yii::t('text','Tövsiyyə edilən məhsullar');
  3203. Yii::app()->clientScript->registerLinkTag('canonical', null, $this->createAbsoluteUrl('site/Recomended'));
  3204. $json = file_get_contents('cat.json');
  3205. $arr = json_decode($json, true);
  3206. $k = array_rand($arr);
  3207. $v = $arr[$k];
  3208. $cat = $v['id'];
  3209. $json = $this->get_web_page("http://api.shopstyle.com/action/apiSearch?pid=sugar&site=www.shopstyle.com&format=json&cat={$cat}&fts=&min=0&count=24");
  3210. $array = json_decode($json['content']);
  3211. if(empty($array)) {
  3212. $this->redirect('Recomended');
  3213. }
  3214. $this -> render('recomended', array('array' => $array));
  3215. }
  3216.  
  3217. protected function get_web_page($url)
  3218. {
  3219. $user_agent = 'Mozilla/5.0 (Windows NT 6.1; rv:8.0) Gecko/20100101 Firefox/8.0';
  3220. $options = array(CURLOPT_CUSTOMREQUEST => "GET", //set request type post or get
  3221. CURLOPT_POST => false, //set to GET
  3222. CURLOPT_USERAGENT => $user_agent, //set user agent
  3223. CURLOPT_COOKIEFILE => "cookie.txt", //set cookie file
  3224. CURLOPT_COOKIEJAR => "cookie.txt", //set cookie jar
  3225. CURLOPT_RETURNTRANSFER => true, // return web page
  3226. CURLOPT_HEADER => false, // don't return headers
  3227. CURLOPT_FOLLOWLOCATION => true, // follow redirects
  3228. CURLOPT_ENCODING => "", // handle all encodings
  3229. CURLOPT_AUTOREFERER => true, // set referer on redirect
  3230. // CURLOPT_PROXY => '127.0.0.1:8888'
  3231.  
  3232. );
  3233.  
  3234. $ch = curl_init($url);
  3235. curl_setopt_array($ch, $options);
  3236. $content = curl_exec($ch);
  3237. $err = curl_errno($ch);
  3238. $errmsg = curl_error($ch);
  3239. $header = curl_getinfo($ch);
  3240. curl_close($ch);
  3241.  
  3242. $header['errno'] = $err;
  3243. $header['errmsg'] = $errmsg;
  3244. $header['content'] = $content;
  3245. return $header;
  3246. }
  3247.  
  3248. public function actionBalance() {
  3249. $user = Users::model()->findByPk(Yii::app()->user->id);
  3250.  
  3251. $c = new CDbCriteria();
  3252. $c ->condition = "users_id = '".Yii::app()->user->id."' ";
  3253. $c ->order = "`id` DESC";
  3254. $logs = PaymentHistory::model()->findAll($c);
  3255.  
  3256. $c = new CDbCriteria();
  3257. $c ->condition = "users_id = '".Yii::app()->user->id."' AND paymentstatus = 'SUCCESS' ";
  3258. $c ->order = "`id` DESC";
  3259. $card_logs = PaymentProducts::model()->findAll($c);
  3260.  
  3261. if(Yii::app()->user->id == '23114')
  3262. {
  3263.  
  3264. //$array = (array) $card_logs;
  3265. // print_r($array);
  3266. }
  3267.  
  3268.  
  3269. $this -> render('balance',array('user'=>$user, 'logs' =>$logs, 'card_logs' =>$card_logs));
  3270. }
  3271.  
  3272. public function actionSuccesOrder($code) {
  3273.  
  3274. unset(Yii::app()->request->cookies['order_details']);
  3275. $model = Myorder::model()->findByAttributes(array('order_key'=>$code));
  3276.  
  3277. if($model==null)
  3278. throw new CHttpException(404, 'Səhv müraciət');
  3279.  
  3280. $this -> render('succesorder',array('model'=>$model));
  3281. }
  3282.  
  3283. public function actionSettings() {
  3284.  
  3285.  
  3286. $this->pageTitle = 'Mover.az - '. Yii::t('text','Tənzimləmələr');
  3287.  
  3288. $model = Users::model() -> findByPk(Yii::app() -> user -> id);
  3289. $old = clone $model;
  3290. $model -> scenario = 'update';
  3291. // Uncomment the following line if AJAX validation is needed
  3292. //$this->performAjaxValidation($model);
  3293.  
  3294. if (isset($_POST['Users'])) {
  3295.  
  3296. $model -> attributes = CHtml::encodeArray($_POST['Users']);
  3297.  
  3298. if(CUploadedFile::getInstance($model,'photo'))
  3299. $photo=$model->photo=CUploadedFile::getInstance($model,'photo');
  3300.  
  3301.  
  3302.  
  3303. if ($model -> validate(array('name','surname','old_password','new_password','address','id_card','photo', 'mobile','fin'))) {
  3304.  
  3305. if (isset($photo))
  3306. {
  3307.  
  3308. # Photo new name
  3309. $new_name = time().'_'.$photo->getName();
  3310. $pathBigPhoto = Yii::app()->params['users_image_path'].'passport/';
  3311.  
  3312. //$pathSmallPhoto = Yii::app()->params['smallPhoto'].$id.'/';
  3313.  
  3314. if (!is_dir($pathBigPhoto) )//&& !is_dir($pathSmallPhoto)
  3315. {
  3316.  
  3317. @mkdir($pathBigPhoto, 0777, true);
  3318. }
  3319. $wayBig = $pathBigPhoto.$new_name;
  3320.  
  3321.  
  3322. //$waySmall = $pathSmallPhoto.$new_name;
  3323. $photo->saveAs($wayBig);
  3324. $model->photo = $new_name ;
  3325.  
  3326.  
  3327. }
  3328.  
  3329. $model -> save(false,array('name','surname','old_password','new_password','address','id_card','fin','photo', 'mobile'));
  3330.  
  3331. /*
  3332. Istifadeci melumatlari deyishende loqlamaq
  3333. */
  3334. $message = "İstifadəçi məlumatları yeniləndi:";
  3335. if ($old ->name != $model ->name)
  3336. $message .= "Ad: ".$old ->name." -> ".$model ->name."";
  3337. if ($old ->surname != $model ->surname)
  3338. $message .= "Soyad: ".$old ->surname." -> ".$model ->surname."";
  3339. if (!empty($model ->old_password) && !empty($model ->new_password))
  3340. $message .= "Şifrə: ".$model ->old_password." -> ".$model ->new_password."";
  3341. if ($old ->address != $model ->address)
  3342. $message .= "Ünvan:".$old ->address." -> ".$model ->address."";
  3343. if ($old ->id_card != $model ->id_card)
  3344. $message .= "Şəxsiyyət v.N:".$old ->id_card." -> ".$model ->id_card."";
  3345. if ($old ->mobile != $model ->mobile)
  3346. $message .= "Telefon:".$old ->mobile." -> ".$model ->mobile."";
  3347. Iplog::write($message);
  3348. /*
  3349. Log end
  3350. */
  3351.  
  3352. Yii::app() -> user -> setFlash('saved', "Qeydiyyatdan keçildi");
  3353. }
  3354. }
  3355.  
  3356. $this -> render('settings', array('model' => $model, ));
  3357.  
  3358. }
  3359.  
  3360.  
  3361. public function actionAddLink($id = 1){
  3362. $this->pageTitle = 'Mover.az - '. Yii::t('text','Sifariş et');
  3363. Yii::app()->params['OG_IMAGE'] = 'http://mover.az/media/img/sebet.png';
  3364. Yii::app()->params['OG_URL'] = $this->createAbsoluteUrl('site/ordernow');
  3365. Yii::app()->params['OG_TITLE'] = 'Mover.az';
  3366. Yii::app()->params['OG_TEXT'] = 'Sifariş et';
  3367. Yii::app()->clientScript->registerLinkTag('canonical', null, $this->createAbsoluteUrl('site/ordernow'));
  3368. $model_order = new OrderForm;
  3369. $model_login = new LoginForm();
  3370. $model = new Users();
  3371. $kargo_tr = KargoPrice::model()->findAllByAttributes(array('country_id' => 1));
  3372. $kargo_usa = KargoPrice::model()->findAllByAttributes(array('country_id' => 2));
  3373. if(isset($_POST)){
  3374. $link = $_POST['link'];
  3375. $price = $_POST['price'];
  3376. $urgently = isset($_POST['urgently'])? 1 : 0;
  3377. }
  3378.  
  3379. $this -> render('addLink',array('model_order'=>$model_order, 'kargo_tr' => $kargo_tr , 'kargo_usa' => $kargo_usa ,'model_login'=>$model_login,'model'=>$model, 'country_id' =>$id));
  3380. }
  3381.  
  3382. public function actionAddLinks(){
  3383. if (isset(Yii::app()->user->id)) {
  3384. $id = Yii::app()->user->id;
  3385.  
  3386. if (isset($_POST)) {
  3387. $success = false;
  3388. $country_id = $_POST['country_id'];
  3389. if($country_id == 1){
  3390. $link = $_POST['link'];
  3391. $price = $_POST['price'];
  3392. $qeyd = $_POST['qeyd'];
  3393. $size = $_POST['size'];
  3394. $pname = $_POST['pname'];
  3395. $pid = $_POST['pid'];
  3396. }else{
  3397. $link = $_POST['link_usa'];
  3398. $price = $_POST['price_usa'];
  3399. $qeyd = $_POST['qeyd_usa'];
  3400. $size = '0';
  3401. $pname = '0';
  3402. $pid = '0';
  3403. }
  3404.  
  3405. $urgently = isset($_POST['urgently']) ? 1 : 0;
  3406. foreach ($link as $key => $val) {
  3407. //$qeyd[$key] = isset($size[$key]) ? 'Ölcü '.explode(':', $size[$key])[0] : '';
  3408. $order_key = substr(md5(uniqid(mt_rand(), true)), 0, 8);
  3409.  
  3410. $price_percent = $price[$key] * 0.05 + $price[$key];
  3411.  
  3412. // Image upload
  3413. $getUrlDetails = file_get_contents("http://mover.az/diffbot.php?productPageUrl=" . $val . "");
  3414. $getUrlDetails = json_decode($getUrlDetails, true);
  3415.  
  3416. $image_url = $getUrlDetails['objects'][0]['images'][0]['url'];
  3417.  
  3418. $info = pathinfo($image_url);
  3419. $newfilename = '';
  3420. if (isset($info['extension'])) {
  3421. $ext = $info['extension'];
  3422. $newfilename = md5(time()) . '.' . $ext;
  3423.  
  3424. $pth = Yii::app()->params['myorder_image_path'] . $newfilename;
  3425.  
  3426. copy($image_url, $pth);
  3427. }
  3428.  
  3429. // Image upload
  3430.  
  3431. if (strpos($price[$key], ",") > 0)
  3432. $price_new = str_replace(",", ".", $price[$key]);
  3433. else
  3434. $price_new = $price[$key];
  3435.  
  3436. $sql = "INSERT INTO
  3437. cms_myorder (`link`,`image`, `comment`,`users_id`,`order_key`,`price`,`ourprice`,`count`,`date`, `urgently`, `country_id`, `size`, `pname`, `pid`)
  3438. VALUES (:link,:image,:comment,:users_id,:order_key,:price,:price,1," . time() . ", " . $urgently . ", " . $country_id . ", :size, :pname, :pid)";
  3439. $command = Yii::app()->db->createCommand($sql)
  3440. ->bindParam(':link', $val, PDO::PARAM_STR)
  3441. ->bindParam(':image', $newfilename, PDO::PARAM_STR)
  3442. ->bindParam(':comment', $qeyd[$key], PDO::PARAM_STR)
  3443. ->bindParam(':order_key', $order_key, PDO::PARAM_STR)
  3444. ->bindParam(':users_id', $id, PDO::PARAM_INT)
  3445. ->bindParam(':price', $price_new, PDO::PARAM_STR)
  3446. ->bindParam(':size', $size[$key], PDO::PARAM_STR)
  3447. ->bindParam(':pname', $pname[$key], PDO::PARAM_STR)
  3448. ->bindParam(':pid', $pid[$key], PDO::PARAM_STR)
  3449. ->execute();
  3450.  
  3451.  
  3452. try {
  3453. if ($command) {
  3454. $success = true;
  3455. }
  3456.  
  3457. } catch (Exception $ex) {
  3458. $success = false;
  3459. }
  3460.  
  3461.  
  3462. }
  3463. if ($success && $urgently == 1) {
  3464. $User = Users::model()->findByPk($id);
  3465. $User->balance = $User->balance - 3.4;
  3466. $User->save(false);
  3467. $history = new PaymentHistory();
  3468. $history->date = time();
  3469. $history->users_id = $id;
  3470. $history->log = '- 3.4 AZN ( Hazırkı balans : '.$User->balance.') AZN Təcili Sİfariş üçün';
  3471. $history->save(false);
  3472.  
  3473. }
  3474. echo json_encode(['success' => true]);
  3475. }
  3476. }
  3477. }
  3478.  
  3479. public function actionAddBasketLink(){
  3480.  
  3481.  
  3482. $id = Yii::app()->user->id;
  3483.  
  3484. if(isset($_POST))
  3485. {
  3486.  
  3487. if($_POST['basket_link'] != '' && $_POST['basket_login'] != '' && $_POST['basket_password'] != '' && $_POST['basket_amount'] != '' && $_POST['basket_note'] != '' )
  3488. {
  3489.  
  3490. $basket_link = Yii::app()->getRequest()->getPost('basket_link');
  3491. $basket_login = Yii::app()->getRequest()->getPost('basket_login');
  3492. $basket_password = Yii::app()->getRequest()->getPost('basket_password');
  3493. $basket_amount = Yii::app()->getRequest()->getPost('basket_amount');
  3494. $basket_note = Yii::app()->getRequest()->getPost('basket_note');
  3495. $country_id = Yii::app()->getRequest()->getPost('country_id');
  3496. if($_POST['default'] == 1)
  3497. {
  3498. $urgently = 0;
  3499. }
  3500. else
  3501. {
  3502. $urgently= isset($_POST['urgently1']) ? 1 : 0;
  3503. }
  3504.  
  3505.  
  3506. if (strpos($basket_amount, ",") > 0)
  3507. {
  3508. $price= str_replace(",", ".", $basket_amount);
  3509. }
  3510. else
  3511. {
  3512. $price = $basket_amount;
  3513. }
  3514.  
  3515. $command = Yii::app()->db->createCommand();
  3516. $command->insert('cms_basket', array(
  3517. 'users_id' => Yii::app()->user->id,
  3518. 'basket_link' => $basket_link,
  3519. 'basket_login' => $basket_login,
  3520. 'basket_password' => $basket_password,
  3521. 'total_amount_basket' => $price,
  3522. 'note' => $basket_note,
  3523. 'paid' => '0',
  3524. 'status' => '0',
  3525. 'urgently' => $urgently,
  3526. 'country_id' => $country_id,
  3527. 'date' => date('Y-m-d H:i:s')
  3528. ));
  3529.  
  3530.  
  3531. try{
  3532. if($command){
  3533. $success = true;
  3534. }
  3535. }
  3536. catch (CDbException $e) {
  3537. $success = false;
  3538. }
  3539.  
  3540.  
  3541. if ($success && $urgently == 1)
  3542. {
  3543. $User = Users::model()->findByPk($id);
  3544. $User->balance = $User->balance - 3.4;
  3545. $User->save(false);
  3546. $history = new PaymentHistory();
  3547. $history->date = time();
  3548. $history->users_id = $id;
  3549. $history->log = '- 3.4 AZN ( Hazırkı balans : '.$User->balance.') AZN Təcili Sİfariş üçün';
  3550. $history->save(false);
  3551.  
  3552. }
  3553.  
  3554. echo CJSON::encode(array('result' => true, 'message' =>'successfully added'));
  3555. Yii::app() -> end();
  3556.  
  3557. }
  3558.  
  3559. else
  3560. {
  3561. echo CJSON::encode(array('result' => false, 'message' =>'Bütün xanaları doldurun!'));
  3562. Yii::app() -> end();
  3563. }
  3564.  
  3565. }
  3566.  
  3567.  
  3568. }
  3569.  
  3570. public function actionAddBasket()
  3571. {
  3572.  
  3573. $this->render('addbasketlink');
  3574. }
  3575.  
  3576.  
  3577. public function actionBasketdetails()
  3578. {
  3579. $id = Yii::app()->user->id;
  3580. $basket_id = intval($_POST['basket_id']);
  3581.  
  3582.  
  3583. $command = Yii::app()->db->createCommand();
  3584. $basket_detail = $command
  3585. ->select('id,basket_link,basket_login,basket_password,note,total_amount_basket')
  3586. ->from('cms_basket')
  3587. ->where('users_id=:users_id and id=:id',array(':users_id'=>$id,':id'=>$basket_id))
  3588. ->queryRow();
  3589.  
  3590. $this -> renderPartial('basketedit', array('basket' => $basket_detail));
  3591. }
  3592.  
  3593. public function actionBasketedit()
  3594. {
  3595. if ($_POST['basket_id']) {
  3596.  
  3597. $basket_id = intval($_POST['basket_id']);
  3598. $basket_link = Yii::app()->getRequest()->getPost('basket_link');
  3599. $basket_login = Yii::app()->getRequest()->getPost('basket_login');
  3600. $basket_password = Yii::app()->getRequest()->getPost('basket_password');
  3601. $total_amount_basket = Yii::app()->getRequest()->getPost('total_amount_basket');
  3602. $basket_note = Yii::app()->getRequest()->getPost('note');
  3603.  
  3604. $command = Yii::app()->db->createCommand();
  3605. $command->update('cms_basket', array(
  3606. 'basket_link' => $basket_link,
  3607. 'basket_login' => $basket_login,
  3608. 'basket_password' => $basket_password,
  3609. 'total_amount_basket' => $total_amount_basket,
  3610. 'note' => $basket_note,
  3611. 'date' => date('Y-m-d H:i:s'),
  3612. ), 'id=:id', array(':id'=>$basket_id));
  3613.  
  3614. }
  3615.  
  3616. $this->redirect(CHtml::normalizeUrl(array("site/order")));
  3617. }
  3618.  
  3619. public function actionBasketdelete()
  3620. {
  3621. $basket_id = intval($_POST['basket_id']);
  3622.  
  3623. $command = Yii::app()->db->createCommand();
  3624. $baskets = $command->select('*')
  3625. ->from('cms_basket')
  3626. ->where('users_id=:users_id and id=:id' ,array(':users_id'=>$id,':id'=>$basket_id))
  3627. ->queryRow();
  3628.  
  3629. $soft_delete = $command->update('cms_basket', array('status' => 2),'id=:id', array(':id'=>$basket_id));
  3630.  
  3631. if($baskets)
  3632. {
  3633. if($delete)
  3634. echo CJSON::encode(array('status' => 1, 'error' => 'deleted'));
  3635. else
  3636. echo CJSON::encode(array('status' => 0, 'error' => 'not delete'));
  3637. }
  3638. else
  3639. echo CJSON::encode(array('status' => 0, 'error' => 'not found'));
  3640.  
  3641.  
  3642. }
  3643.  
  3644.  
  3645. public function actionOrdernow() {
  3646. $this->pageTitle = 'Mover.az - '. Yii::t('text','Sifariş et');
  3647. Yii::app()->params['OG_IMAGE'] = 'http://mover.az/media/img/sebet.png';
  3648. Yii::app()->params['OG_URL'] = $this->createAbsoluteUrl('site/ordernow');
  3649. Yii::app()->params['OG_TITLE'] = 'Mover.az';
  3650. Yii::app()->params['OG_TEXT'] = 'Sifariş et';
  3651. Yii::app()->clientScript->registerLinkTag('canonical', null, $this->createAbsoluteUrl('site/ordernow'));
  3652. $model_order = new OrderForm;
  3653. $order = new Orders;
  3654. if (isset($_POST['OrderForm'])) {
  3655. $_POST['OrderForm']['price'] = str_replace(',', '.', $_POST['OrderForm']['price']);
  3656. $model_order -> attributes = CHtml::encodeArray($_POST['OrderForm']);
  3657. $name = strip_tags($_POST['OrderForm']['name']);
  3658. $surname = strip_tags($_POST['OrderForm']['surname']);
  3659. $email = strip_tags(trim($_POST['OrderForm']['email']));
  3660. $price = strip_tags(trim($_POST['OrderForm']['price']));
  3661. $urgently = ($_POST['OrderForm']['urgently']) ? 1 :0;
  3662. #echo $name; exit;
  3663.  
  3664. $order_key = substr(md5(uniqid(mt_rand(), true)) , 0, 8);
  3665. if ($model_order -> validate()) {
  3666.  
  3667. if (isset(Yii::app()->user->id)) {
  3668. $id = Yii::app()->user->id;
  3669. $price_percent = $model_order->price*0.05+$model_order->price;
  3670.  
  3671. // Image upload
  3672. $getUrlDetails = file_get_contents("http://mover.az/diffbot.php?productPageUrl=".$model_order->link."");
  3673. $getUrlDetails = json_decode($getUrlDetails,true);
  3674.  
  3675. $image_url = $getUrlDetails['objects'][0]['images'][0]['url'];
  3676.  
  3677. $info = pathinfo($image_url);
  3678.  
  3679. $ext = $info['extension'];
  3680. $newfilename = md5(time()).'.'.$ext;
  3681.  
  3682. $pth = Yii::app()->params['myorder_image_path'].$newfilename;
  3683.  
  3684. copy($image_url, $pth);
  3685. // Image upload
  3686.  
  3687. if(strpos($model_order->price,",")>0)
  3688. $price_new = str_replace(",",".",$model_order->price);
  3689. else
  3690. $price_new = $model_order->price;
  3691.  
  3692. $command = Yii::app() -> db -> createCommand("INSERT INTO
  3693. cms_myorder (`link`,`image`, `comment`,`users_id`,`order_key`,`price`,`count`,`date`, `urgently`)
  3694. VALUES (:link,:image,:comment,:users_id,:order_key,:price,1,".time().", ".$urgently.")")
  3695. -> bindParam(':link', $model_order->link, PDO::PARAM_STR)
  3696. -> bindParam(':image', $newfilename, PDO::PARAM_STR)
  3697. -> bindParam(':comment', $model_order->notes, PDO::PARAM_STR)
  3698. -> bindParam(':order_key', $order_key, PDO::PARAM_STR)
  3699. -> bindParam(':users_id', $id , PDO::PARAM_INT)
  3700. -> bindParam(':price', $price_new, PDO::PARAM_STR)
  3701. -> execute();
  3702. if($command){
  3703.  
  3704. $this -> redirect(array('succesorder', 'code' => $order_key));
  3705. }
  3706.  
  3707. }
  3708. else {
  3709.  
  3710. $cookie = new CHttpCookie('order_details', json_encode(array('link'=>$model_order->link,'comment'=>$model_order->notes,'code'=>$order_key,'name'=>$name,'surname'=>$surname,'email'=>$email)));
  3711. $cookie->expire = time()+60*60*24;
  3712. Yii::app()->request->cookies['cookie_name'] = $cookie;
  3713. $this->redirect('auth');
  3714.  
  3715. }
  3716. }
  3717. }
  3718. $model_login = new LoginForm();
  3719. $model = new Users();
  3720. $model -> scenario = 'register';
  3721. $is_cookie = isset(Yii::app()->request->cookies['order_details']);
  3722. if (isset($_POST['LoginForm'])) {
  3723. $model_login -> attributes = CHtml::encodeArray($_POST['LoginForm']);
  3724.  
  3725. $lg = $model_login -> login();
  3726.  
  3727.  
  3728. // validate user input and redirect to the previous page if valid
  3729. if ($model_login -> validate() && $lg['result']) {
  3730.  
  3731.  
  3732. Users::model() -> updateByPk(Yii::app()->user->id, array('ldate' => time()));
  3733.  
  3734.  
  3735. $cookie1 = new CHttpCookie('name',Yii::app()->user->getFirstName());
  3736. $cookie1->expire = time() + (60*60*72); // 24 hours
  3737. Yii::app()->request->cookies['name'] = $cookie1;
  3738.  
  3739.  
  3740. $cookie2 = new CHttpCookie('surname',Yii::app()->user->getSurname());
  3741. $cookie2->expire = time() + (60*60*72); // 24 hours
  3742. Yii::app()->request->cookies['surname'] = $cookie2;
  3743.  
  3744.  
  3745. $cookie3 = new CHttpCookie('userkey',Yii::app()->user->getUserCode());
  3746. $cookie3->expire = time() + (60*60*72); // 24 hours
  3747. Yii::app()->request->cookies['userkey'] = $cookie3;
  3748.  
  3749. $cookie4 = new CHttpCookie('email',Yii::app()->user->getEmail());
  3750. $cookie4->expire = time() + (60*60*72); // 24 hours
  3751. Yii::app()->request->cookies['email'] = $cookie4;
  3752.  
  3753.  
  3754. $cookie5 = new CHttpCookie('moverauth',base64_encode(Yii::app()->user->id));
  3755. $cookie5->expire = time() + (60*60*24); // 24 hours
  3756. Yii::app()->request->cookies['moverauth'] = $cookie5;
  3757.  
  3758.  
  3759. if (!empty($lg['redirect'])){
  3760. $this -> redirect($lg['redirect']);
  3761. Yii::app() -> end();
  3762. }
  3763.  
  3764.  
  3765. if($is_cookie) {
  3766. $cook = json_decode(Yii::app()->request->cookies['order_details']->value);
  3767. $order = new Myorder;
  3768. $order->link = $cook->link;
  3769. $order->comment = $cook->comment;
  3770. $order->users_id = Yii::app()->user->id;
  3771. $order->order_key = $cook->code;
  3772. $order->date = time();
  3773. $order->save(FALSE);
  3774. $this -> redirect(array('succesorder', 'code' => $cook->code));
  3775.  
  3776. }
  3777. $this -> redirect('Profile');
  3778. }
  3779. }
  3780. else if (isset($_POST['Users'])) {
  3781. $model -> attributes = CHtml::encodeArray($_POST['Users']);
  3782.  
  3783. $model -> user_activation_key = sha1(md5(time() + rand(999, 999999999)));
  3784. $model -> activation_sms_key = MyClass::GenerateSMSKey();
  3785. $model -> rdate = time();
  3786. if ($model -> save()) {
  3787.  
  3788. Sms::Send($model -> mobile, "Tesdiqleme kodu: {$model -> activation_sms_key}");
  3789. /*if ($model -> sendActivation())*/
  3790. Yii::app() -> user -> setFlash('activate', "<h3>Qeydiyyatdan keçdiyiniz üçün təşəkkür edirik!</h3>
  3791. <p>Qeyd etdiyiniz nömrəyə təsdiqləmə kodu göndərilmişdir.</p>
  3792. <p>Hesabı aktivləşdirdikdən sonra daxil ola bilərsiniz.</p>");
  3793. /*else
  3794. throw new CHttpException(200, "Email aktivasiyası alınmadı");*/
  3795. }
  3796. }
  3797. $this -> render('ordernow',array('model_order'=>$model_order,'model_login'=>$model_login,'model'=>$model));
  3798. }
  3799. /*
  3800. public function actionDeleteNotPaidOrders(){
  3801.  
  3802. $time = time() - 30*60;
  3803. $orders = Myorder::getNotPaidOrdersByTime($time);
  3804. $model = array();
  3805. $i = 0;
  3806. foreach($orders as $order){
  3807. $model[$i] = Myorder::model()->findByPk((int)$order['id']);
  3808. $model[$i]->status = '0';
  3809. $model[$i]->save();
  3810. $i++;
  3811. }
  3812. }
  3813. */
  3814. public function actionAuth() {
  3815. /*if(isset(Yii::app()->user->id)){
  3816. return $this->redirect('profile');
  3817. }*/
  3818. $this->pageTitle = 'Mover.az - '. Yii::t('text','Daxil ol və ya qeydiyyatdan keç');
  3819. Yii::app()->params['OG_IMAGE'] = 'http://mover.az/media/img/ogimg.jpg';
  3820. Yii::app()->params['OG_URL'] = $this->createAbsoluteUrl('site/auth');
  3821. Yii::app()->params['OG_TITLE'] = 'Mover.az';
  3822. Yii::app()->params['OG_TEXT'] = Yii::t('text','Daxil ol və ya qeydiyyatdan keç');
  3823. Yii::app()->clientScript->registerLinkTag('canonical', null, $this->createAbsoluteUrl('site/Auth'));
  3824. $model_login = new LoginForm;
  3825. $model = new Users();
  3826. $model -> scenario = 'register';
  3827. $is_cookie = isset(Yii::app()->request->cookies['order_details']);
  3828. $active_tab = 'login';
  3829. if (isset($_POST['LoginForm'])) {
  3830. $model_login ->attributes = CHtml::encodeArray($_POST['LoginForm']);
  3831.  
  3832. $lg = $model_login -> login();
  3833.  
  3834. // validate user input and redirect to the previous page if valid
  3835. if ($model_login -> validate() && $lg['result']) {
  3836.  
  3837.  
  3838. Users::model() -> updateByPk(Yii::app()->user->id, array('ldate' => time()));
  3839.  
  3840.  
  3841. $cookie1 = new CHttpCookie('name',Yii::app()->user->getFirstName());
  3842. $cookie1->expire = time() + (60*60*72); // 24 hours
  3843. Yii::app()->request->cookies['name'] = $cookie1;
  3844.  
  3845.  
  3846. $cookie2 = new CHttpCookie('surname',Yii::app()->user->getSurname());
  3847. $cookie2->expire = time() + (60*60*72); // 24 hours
  3848. Yii::app()->request->cookies['surname'] = $cookie2;
  3849.  
  3850.  
  3851. $cookie3 = new CHttpCookie('userkey',Yii::app()->user->getUserCode());
  3852. $cookie3->expire = time() + (60*60*72); // 24 hours
  3853. Yii::app()->request->cookies['userkey'] = $cookie3;
  3854.  
  3855. $cookie4 = new CHttpCookie('email',Yii::app()->user->getEmail());
  3856. $cookie4->expire = time() + (60*60*72); // 24 hours
  3857. Yii::app()->request->cookies['email'] = $cookie4;
  3858.  
  3859.  
  3860. $cookie5 = new CHttpCookie('moverauth',base64_encode(Yii::app()->user->id));
  3861. $cookie5->expire = time() + (60*60*24); // 24 hours
  3862. Yii::app()->request->cookies['moverauth'] = $cookie5;
  3863.  
  3864.  
  3865. if (!empty($lg['redirect'])){
  3866. $this -> redirect($lg['redirect']);
  3867. Yii::app() -> end();
  3868. }
  3869.  
  3870.  
  3871. if($is_cookie) {
  3872. $cook = json_decode(Yii::app()->request->cookies['order_details']->value);
  3873. $order = new Myorder;
  3874. $order->link = $cook->link;
  3875. $order->comment = $cook->comment;
  3876. $order->users_id = Yii::app()->user->id;
  3877. $order->order_key = $cook->code;
  3878. $order->date = time();
  3879. $order->save(FALSE);
  3880. $this -> redirect(array('succesorder', 'code' => $cook->code));
  3881.  
  3882. }
  3883.  
  3884.  
  3885.  
  3886.  
  3887.  
  3888. $this -> redirect('Profile');
  3889. }
  3890. }
  3891. else if (isset($_POST['Users'])) {
  3892. $model -> attributes = CHtml::encodeArray($_POST['Users']);
  3893.  
  3894. $sex = $_POST['sex'];
  3895.  
  3896. $model -> user_activation_key = sha1(md5(time() + rand(999, 999999999)));
  3897. $model -> activation_sms_key = MyClass::GenerateSMSKey();
  3898. $model -> rdate = time();
  3899. $model->sex = $sex;
  3900. $optional = intval($_POST['optional']);
  3901. $optional_desc = strip_tags($_POST['optional_desc']);
  3902.  
  3903. $model->optional = $optional;
  3904. $model->optional_desc = $optional_desc;
  3905. if ($model -> save()) {
  3906. return $this->redirect(CHtml::normalizeUrl(array("site/login")));
  3907. //Sms::Send($model -> mobile, "Tesdiqleme kodu: {$model -> activation_sms_key}");
  3908. /*if ($model -> sendActivation())*/
  3909. /*Yii::app() -> user -> setFlash('activate', "<h3>Qeydiyyatdan keçdiyiniz üçün təşəkkür edirik!</h3>
  3910. <p>Qeyd etdiyiniz nömrəyə təsdiqləmə kodu göndərilmişdir.</p>
  3911. <p>Hesabı aktivləşdirdikdən sonra daxil ola bilərsiniz.</p>");*/
  3912. /*else
  3913. throw new CHttpException(200, "Email aktivasiyası alınmadı");*/
  3914. }
  3915. $active_tab = 'register';
  3916. }
  3917.  
  3918. $this -> render('auth', array('model' => $model, 'model_login' => $model_login, 'active_tab'=>$active_tab));
  3919. }
  3920.  
  3921. /**
  3922. * Logs out the current user and redirect to homepage.
  3923. */
  3924. public function actionLogout($rand) {
  3925. if ($rand == Yii::app()->request->csrfToken){
  3926. Yii::app()->user->logout();
  3927. @session_destroy();
  3928.  
  3929. unset(Yii::app()->request->cookies['moverauth']);
  3930. }
  3931. $this -> redirect(Yii::app() -> homeUrl);
  3932. }
  3933.  
  3934.  
  3935.  
  3936. public function actionGetParentCategories()
  3937. {
  3938. // ...
  3939.  
  3940. $c = new CDbCriteria();
  3941. $c ->condition = "confirm='1' AND parent_id IS NULL";
  3942. $c ->select = "id,icon,name";
  3943. $c ->order = "`order` ASC";
  3944.  
  3945. $a = Categories::model()->findAll($c);
  3946. //$b = CHtml::listData($a,'id', 'name','icon');
  3947. foreach($a as $b ){
  3948.  
  3949.  
  3950. $img = 'http://mover.az'.Categories::getcatimage($b->icon);
  3951. $mas[] = array(
  3952. 'id' => $b->id,
  3953. 'icon' => $img,
  3954. 'name' => $b->name
  3955. );
  3956. }
  3957.  
  3958. echo json_encode($mas,JSON_UNESCAPED_SLASHES);
  3959. //print_r($a);
  3960.  
  3961. }
  3962.  
  3963. public function actionGetChildCategories($id)
  3964. {
  3965.  
  3966. $c = new CDbCriteria();
  3967. $c ->condition = "confirm='1' AND parent_id =:parent_id ";
  3968. $c ->select = "id,name";
  3969. $c ->order = "`order` ASC";
  3970. $c ->params = array(":parent_id"=>$id);
  3971.  
  3972. $a = Categories::model()->findAll($c);
  3973.  
  3974. //$b = CHtml::listData($a,'id', 'name','icon');
  3975. foreach($a as $b ){
  3976. $mas[] = array(
  3977. 'id' => $b->id,
  3978. 'name' => $b->name
  3979. );
  3980. }
  3981.  
  3982. echo json_encode($mas,JSON_UNESCAPED_SLASHES);
  3983.  
  3984.  
  3985. }
  3986.  
  3987. public function actionGettourslider(){
  3988. $tourimage[] = array("image"=>"http://vaweave.com/wp-content/uploads/bfi_thumb/pro_test_1_3-mljvkxqiv322x2yurz628rmuqkml39j2689dr2uz1s.jpg");
  3989. $tourimage[] = array("image"=>"http://vaweave.com/wp-content/uploads/bfi_thumb/pro_test_2_2-mljvklime8lcq5glrbvwucpv0katb76jsjs2ihd3ao.jpg");
  3990. $tourimage[] = array("image"=>"http://vaweave.com/wp-content/uploads/bfi_thumb/pro_test_0-mljvlbu3plldr8edhn9gs62rncp3aq31861ny8a2gg.jpg");
  3991. echo json_encode($tourimage,JSON_UNESCAPED_SLASHES);
  3992. }
  3993.  
  3994. public function actionGetLinks($id)
  3995. {
  3996. $sql='
  3997. SELECT url,l.name,icon as thumb FROM {{type}} as t
  3998. RIGHT JOIN {{links}} as l ON(t.link_id = l.id)
  3999. WHERE t.category_id = :category_id AND l.confirm = "1"
  4000. ORDER BY l.`order` ASC;
  4001. ';
  4002.  
  4003. $all = Yii::app()->db->createCommand($sql)->bindParam(":category_id",$id,PDO::PARAM_INT)->queryAll();
  4004. if ($all){
  4005. foreach($all as $b ){
  4006.  
  4007. if (!empty($b['thumb'])){
  4008. $img = 'http://mover.az'.Links::getlinkimage($b['thumb']);
  4009. }else{
  4010. $img = "";
  4011. }
  4012. $mas[] = array(
  4013. 'url' => $b['url'],
  4014. 'name' => $b['name'],
  4015. 'thumb' => $img
  4016. );
  4017. }
  4018. }else{
  4019. $mas = array();
  4020. }
  4021.  
  4022.  
  4023. echo json_encode($mas,JSON_UNESCAPED_SLASHES);
  4024. //print_r($users);
  4025. }
  4026.  
  4027.  
  4028. public function actionAjaxlogin() {
  4029. $model = new LoginForm;
  4030.  
  4031. $redirect_url = '';
  4032. // if it is ajax validation request
  4033. if (isset($_POST['ajax']) && $_POST['ajax'] === 'login-form') {
  4034. $errors = CActiveForm::validate($model);
  4035. if ($errors != '[]') {
  4036. echo $errors;
  4037. Yii::app() -> end();
  4038. }
  4039.  
  4040. }
  4041.  
  4042. // <span class="IL_AD" id="IL_AD4">collect</span> user input data
  4043. if (isset($_POST['LoginForm'])) {
  4044. $model -> attributes = CHtml::encodeArray($_POST['LoginForm']);
  4045.  
  4046. $lg = $model -> login();
  4047.  
  4048. if ($model -> validate() && $lg['result'] ) {
  4049.  
  4050.  
  4051.  
  4052.  
  4053. $user = Users::model()->findByPk(Yii::app()->user->id);
  4054.  
  4055. if (!empty($lg['redirect'])){
  4056.  
  4057.  
  4058.  
  4059. echo CJSON::encode(array(
  4060. 'authenticated' => true,
  4061. 'keyforactivation' => $user->activation_sms_key,));
  4062.  
  4063. Yii::app() -> end();
  4064. }
  4065.  
  4066.  
  4067.  
  4068. if (isset($_POST['ajax']) && $_POST['ajax'] === 'login-form') {
  4069.  
  4070.  
  4071. $t = time() + Yii::app()->user->id;
  4072. $token = md5(md5($t));
  4073. $user ->token = $token;
  4074. $user ->save(false,array('token'));
  4075.  
  4076. $_SESSION['token'] = $token;
  4077.  
  4078. echo CJSON::encode(array(
  4079. 'authenticated' => true,
  4080. 'token' => $_SESSION['token'],
  4081. 'name' => $user->name,
  4082. 'surname' => $user->surname,
  4083. 'address1' => "Merkez mahalle, Evren sokak, No18, daire 3 l65902 MOVER MMC",
  4084. 'address2' => $user->user_key."MOVER MMC",
  4085. 'city' => "İstanbul",
  4086. 'region' => "Gaziosmanpaşa",
  4087. 'zip' => "34275",
  4088. 'country' => "Turkey",
  4089. 'tc' => "66823284324",
  4090. 'phone' => "5318964270",
  4091.  
  4092. ));
  4093.  
  4094. Yii::app() -> end();
  4095. }
  4096.  
  4097. }
  4098. }
  4099. // display the login form
  4100. //$this -> render('login', array('model' => $model));
  4101.  
  4102. }
  4103.  
  4104.  
  4105. public function actionRegisterAjaxApp() {
  4106.  
  4107. //$this -> setPageTitle('APA - Qeydiyyat forması');
  4108. $model = new Users;
  4109. $model -> scenario = 'register';
  4110.  
  4111. if (isset($_POST['Users']))
  4112. {
  4113.  
  4114. $model -> attributes = CHtml::encodeArray($_POST['Users']);
  4115.  
  4116. $model -> user_activation_key = sha1(md5(time() + rand(999, 999999999)));
  4117.  
  4118. $model -> activation_sms_key = MyClass::GenerateSMSKey();
  4119.  
  4120. $model -> rdate = time();
  4121. $model->status = '1';
  4122.  
  4123. //$this -> performAjaxValidation($model);
  4124.  
  4125. if ($model -> validate()) {
  4126.  
  4127. if ($model -> save(FALSE)) {
  4128. //Sms::Send($model -> mobile, "Tesdiqleme kodu: {$model -> activation_sms_key}");
  4129. //$model -> sendActivation();
  4130. }
  4131.  
  4132. echo CJSON::encode(array('status' => 'success','keyforactivation'=>$model -> user_activation_key,));
  4133. Yii::app() -> end();
  4134. } else {
  4135. $error = CActiveForm::validate($model);
  4136. echo $error;
  4137. Yii::app() -> end();
  4138. }
  4139. }else{
  4140. echo CJSON::encode(array('status' => 'error'));
  4141. }
  4142. }
  4143.  
  4144.  
  4145. public function actionGetmenu()
  4146. {
  4147. $sql='
  4148. SELECT url,name
  4149. FROM {{appleftmenu}}
  4150. WHERE confirm = "1"
  4151. ORDER BY `order` ASC;
  4152. ';
  4153.  
  4154. $all = Yii::app()->db->createCommand($sql)->queryAll();
  4155.  
  4156. //$ar = array(array("url"=>"http://link1","name"=>"menu 1"),array("url"=>"http://link2","name"=>"menu 2"),array("url"=>"http://link3","name"=>"menu 3"),array("url"=>"http://link4","name"=>"menu 4"));
  4157.  
  4158.  
  4159. echo json_encode($all,JSON_UNESCAPED_SLASHES);
  4160.  
  4161. }
  4162.  
  4163. public function actionGetprofile($token)
  4164. {
  4165.  
  4166. $token = strip_tags(addslashes($token));
  4167. $model = Users::model() -> findByAttributes(array('token'=>$token));
  4168. if ($model)
  4169. {
  4170.  
  4171. //$model);
  4172. $ar ['status'] ="success";
  4173. $ar ['info']['name'] = $model->name;
  4174. $ar ['info']['surname'] = $model->surname;
  4175. $ar ['info']['email'] = $model->email;
  4176. $ar ['info']['mobile'] = $model->mobile;
  4177. $ar ['info']['address'] = $model->address;
  4178. $ar ['info']['id_card'] = $model->id_card;
  4179.  
  4180. }else{
  4181. $ar ['status'] ="error";
  4182. }
  4183.  
  4184. echo json_encode($ar);
  4185.  
  4186.  
  4187. }
  4188.  
  4189. public function actionGetshopsite(){
  4190.  
  4191. $sql='
  4192. SELECT url,name,icon as thumb
  4193. FROM {{links}}
  4194. WHERE confirm = "1"
  4195. ORDER BY `order` ASC;
  4196. ';
  4197.  
  4198. $all = Yii::app()->db->createCommand($sql)->queryAll();
  4199.  
  4200.  
  4201. if ($all){
  4202. foreach($all as $b ){
  4203.  
  4204. if (!empty($b['thumb'])){
  4205. $img = 'http://mover.az'.Links::getlinkimage($b['thumb']);
  4206. }else{
  4207. $img = "";
  4208. }
  4209. $mas[] = array(
  4210. 'url' => $b['url'],
  4211. 'name' => $b['name'],
  4212. 'thumb' => $img
  4213. );
  4214. }
  4215. }else{
  4216. $mas = array();
  4217. }
  4218.  
  4219.  
  4220. echo json_encode($mas,JSON_UNESCAPED_SLASHES);
  4221.  
  4222. //echo json_encode($all,JSON_UNESCAPED_SLASHES);
  4223.  
  4224. }
  4225.  
  4226. public function actionGetlinkfromuser($token)
  4227. {
  4228. $model = new OrderForm;
  4229.  
  4230. $user = Users::model() -> findByAttributes(array('token'=>$token));
  4231.  
  4232.  
  4233.  
  4234.  
  4235. if (isset($_POST) && $user) {
  4236. //$model -> attributes = CHtml::encodeArray($_POST['OrderForm']);
  4237.  
  4238. $model ->link = CHtml::encode($_POST['url']);
  4239. $model->notes = "Appdan gonderilmish link";
  4240.  
  4241. $order_key = substr(md5(uniqid(mt_rand(), true)) , 0, 8);
  4242.  
  4243.  
  4244.  
  4245. if ($model -> validate()) {
  4246.  
  4247.  
  4248. $id = $user->id;
  4249.  
  4250. $command = Yii::app() -> db -> createCommand("INSERT INTO
  4251. cms_myorder (`link`, `comment`,`users_id`,`order_key`,`date`)
  4252. VALUES (:link,:comment,:users_id,:order_key,".time().")")
  4253. -> bindParam(':link', $model->link, PDO::PARAM_STR)
  4254. -> bindParam(':comment', $model->notes, PDO::PARAM_STR)
  4255. -> bindParam(':order_key', $order_key, PDO::PARAM_STR)
  4256. -> bindParam(':users_id', $id , PDO::PARAM_INT)
  4257. -> execute();
  4258. if($command){
  4259.  
  4260. //$this -> redirect(array('succesorder', 'code' => $order_key));
  4261.  
  4262. echo CJSON::encode(array('status' => 'success','code'=>$order_key ));
  4263.  
  4264. }
  4265.  
  4266.  
  4267. }else{
  4268.  
  4269. $errors = CActiveForm::validate($model);
  4270. if ($errors != '[]') {
  4271. echo $errors;
  4272. Yii::app() -> end();
  4273. }
  4274.  
  4275. }
  4276. }
  4277.  
  4278. }
  4279.  
  4280. public function actionOrderfromapp($token)
  4281. {
  4282.  
  4283. $model = new OrderForm;
  4284. $user = Users::model() -> findByAttributes(array('token'=>$token));
  4285. $model->price = '0.00';
  4286.  
  4287. if (/*isset($_POST['OrderForm']) && */ $user) {
  4288. $model -> attributes = CHtml::encodeArray($_POST['OrderForm']);
  4289.  
  4290.  
  4291. $order_key = substr(md5(uniqid(mt_rand(), true)) , 0, 8);
  4292. $model->price = "0.00";
  4293.  
  4294.  
  4295. if ($model -> validate()) {
  4296.  
  4297.  
  4298. $id = $user->id;
  4299.  
  4300. $command = Yii::app() -> db -> createCommand("INSERT INTO
  4301. cms_myorder (`link`, `comment`,`users_id`,`order_key`,`date`)
  4302. VALUES (:link,:comment,:users_id,:order_key,".time().")")
  4303. -> bindParam(':link', $model->link, PDO::PARAM_STR)
  4304. -> bindParam(':comment', $model->notes, PDO::PARAM_STR)
  4305. -> bindParam(':order_key', $order_key, PDO::PARAM_STR)
  4306. -> bindParam(':users_id', $id , PDO::PARAM_INT)
  4307. -> execute();
  4308. if($command){
  4309.  
  4310. //$this -> redirect(array('succesorder', 'code' => $order_key));
  4311.  
  4312. echo CJSON::encode(array('status' => 'success','code'=>$order_key ));
  4313.  
  4314. }
  4315.  
  4316.  
  4317. }else{
  4318. $errors = CActiveForm::validate($model);
  4319. if ($errors != '[]') {
  4320. echo $errors;
  4321. Yii::app() -> end();
  4322. }
  4323. }
  4324. }
  4325.  
  4326.  
  4327. }
  4328.  
  4329.  
  4330.  
  4331. public function actionSmsactive($a) {
  4332.  
  4333.  
  4334. $user = Users::model() -> findByAttributes(array('user_activation_key' => $a));
  4335. if($user) {
  4336. $model = new SMSForm();
  4337. if (isset($_POST['SMSForm'])) {
  4338. $model -> attributes = CHtml::encodeArray($_POST['SMSForm']);
  4339. $model -> a_key = $a;
  4340.  
  4341. if ($model -> validate()) {
  4342.  
  4343. if ($user -> status != 1)
  4344. {
  4345. $user -> status = 1;
  4346. $user -> balance = 0;
  4347. $user -> user_activation_key = '';
  4348. $user -> activation_sms_key = '';
  4349.  
  4350.  
  4351. $t = time() + $user->id;
  4352. $token = md5(md5($t));
  4353. $user ->token = $token;
  4354.  
  4355. $_SESSION['token'] = $token;
  4356.  
  4357. //$user ->save(false,array('token'));
  4358. if ($user -> update(array('status', 'user_activation_key', 'activation_sms_key','balance','token'))) {
  4359.  
  4360. echo CJSON::encode(array('status' => 'success','token'=>$_SESSION['token']));
  4361. }
  4362. else {
  4363. echo CJSON::encode(array('status' => 'error'));
  4364. }
  4365. }
  4366. else {
  4367. echo CJSON::encode(array('status' => 'success'));
  4368. }
  4369. }else{
  4370. $error = CActiveForm::validate($model);
  4371. echo $error;
  4372. Yii::app() -> end();
  4373. }
  4374. }
  4375. }else{
  4376. echo CJSON::encode(array('status' => 'error'));
  4377. }
  4378.  
  4379. }
  4380.  
  4381. public function actionApptoken($token,$notif_token)
  4382. {
  4383. $usertoken = strip_tags(CHtml::encode($token));
  4384. $notiftoken = strip_tags(CHtml::encode($notif_token));
  4385.  
  4386.  
  4387. $user = Users::model() -> findByAttributes(array('token'=>$usertoken));
  4388.  
  4389. if ($user){
  4390.  
  4391. $user -> notiftoken = $notiftoken;
  4392. if($user->save(false,array('notiftoken')))
  4393. {
  4394. echo CJSON::encode(array('status' => 'success'));
  4395. }else{
  4396. echo CJSON::encode(array('status' => 'error'));
  4397. }
  4398.  
  4399. }else{
  4400. echo CJSON::encode(array('status' => 'error'));
  4401. }
  4402.  
  4403. //$command = Yii::app() -> db -> createCommand("INSERT INTO {{appusers}} (`token`) VALUES (:token)")-> bindParam(':token', $token, PDO::PARAM_STR) -> execute();
  4404.  
  4405. }
  4406.  
  4407. public function actionNotificationlist()
  4408. {
  4409. /*$ar[] = array("title"=>"Test 1","body"=>"Notification body 1");
  4410. $ar[] = array("title"=>"Test 2","body"=>"Notification body 2");
  4411. $ar[] = array("title"=>"Test 3","body"=>"Notification body 3");
  4412. $ar[] = array("title"=>"Test 4","body"=>"Notification body 4");
  4413. $ar[] = array("title"=>"Test 5","body"=>"Notification body 5");
  4414. $ar[] = array("title"=>"Test 5","body"=>"http://urun.n11.com/market11/alo-sivi-camasir-deterjani-ekstra-ferah-bahar-33-yikama-x4-P137745449");
  4415. */
  4416.  
  4417. $sql='
  4418. SELECT title,body,url
  4419. FROM {{notification}}
  4420. ORDER BY `id` DESC;
  4421. ';
  4422.  
  4423. $all = Yii::app()->db->createCommand($sql)->queryAll();
  4424. $m = array();
  4425. foreach($all as $row){
  4426.  
  4427.  
  4428. if ( !empty($row['url']) )
  4429. {
  4430. $body = $row['body']." ".$row['url'];
  4431. }else{
  4432. $body = $row['body'];
  4433. }
  4434.  
  4435. $m[] = array('title'=>$row['title'],'body'=>$body);
  4436.  
  4437. }
  4438.  
  4439. echo json_encode($m);
  4440.  
  4441. }
  4442.  
  4443. public function actionHowitworks() {
  4444. // $this->redirect('index');
  4445.  
  4446. $model = Post::model() -> with('postContents') -> findByPk(24);
  4447. $this->pageTitle = 'Mover.az - '. $model->postContents[0]->title;
  4448. Yii::app()->params['OG_IMAGE'] = 'http://mover.az/media/img/ogimg.jpg';
  4449. Yii::app()->params['OG_URL'] = $this->createAbsoluteUrl('site/Howitworks');
  4450. Yii::app()->params['OG_TITLE'] = 'Mover.az';
  4451. Yii::app()->params['OG_TEXT'] = $model->postContents[0]->title;
  4452. Yii::app()->clientScript->registerLinkTag('canonical', null, $this->createAbsoluteUrl('site/Howitworks'));
  4453. $this -> render('howitwork', array('model' => $model));
  4454. }
  4455.  
  4456. public function actionAgreement()
  4457. {
  4458. $this -> render('agreement');
  4459. }
  4460.  
  4461. public function actionOrderdetails()
  4462. {
  4463. $id = Yii::app()->user->id;
  4464. $order_id = intval($_POST['order_id']);
  4465.  
  4466. $model = Myorder::model() -> findByPk($order_id);
  4467.  
  4468. if($model->count==0)
  4469. $model->count = 1;
  4470.  
  4471. $this -> renderPartial('orderedit', array('model' => $model));
  4472. }
  4473.  
  4474. public function actionOrderedit()
  4475. {
  4476. $model = Myorder::model()->findByPk((int)$_POST['order_id']);
  4477.  
  4478. if ($model == NULL)
  4479. throw new CHttpException(404, 'Səhv müraciət');
  4480. //$model -> scenario = 'register';
  4481.  
  4482. if ($_POST['order_id']) {
  4483.  
  4484. // Image upload
  4485. if($model->link!=$_POST['link'] || $model->image=='')
  4486. {
  4487. $getUrlDetails = file_get_contents("http://mover.az/diffbot.php?productPageUrl=".$_POST['link']."");
  4488. $getUrlDetails = json_decode($getUrlDetails,true);
  4489.  
  4490. $image_url = $getUrlDetails['objects'][0]['images'][0]['url'];
  4491.  
  4492. $info = pathinfo($image_url);
  4493.  
  4494. $ext = $info['extension'];
  4495. $newfilename = md5(time()).'.'.$ext;
  4496.  
  4497. $pth = Yii::app()->params['myorder_image_path'].$newfilename;
  4498.  
  4499. copy($image_url, $pth);
  4500.  
  4501. $model->image = $newfilename;
  4502. }
  4503. // Image upload
  4504.  
  4505. // $model -> attributes = CHtml::encodeArray($_POST['Myorder']);
  4506. $model->link = $_POST['link'];
  4507. $model->count = (int)$_POST['count'];
  4508. $model->comment = $_POST['comment'];
  4509. $model->price = $_POST['price'];
  4510. // $this -> performAjaxValidation($model);
  4511.  
  4512. if ($_POST['link']!='' and $_POST['count']!='' and $_POST['comment']!='' and $_POST['price']!="") {
  4513.  
  4514. $model -> save(FALSE);
  4515.  
  4516.  
  4517.  
  4518. // echo CJSON::encode(array('status' => 'success','alert'=>Yii::t('text','Düzəliş edildi')));
  4519. // Yii::app() -> end();
  4520. }
  4521. }
  4522.  
  4523. $this->redirect(CHtml::normalizeUrl(array("site/order")));
  4524.  
  4525. }
  4526.  
  4527. public function actionOrdersum()
  4528. {
  4529. // $criteria = new CDbCriteria;
  4530. // $criteria->condition = "balance<0";
  4531. // $users = Users::model()->findAll($criteria);
  4532. // $a=0;
  4533. //
  4534. // foreach ($users as $row)
  4535. // {
  4536. //// $a+=$row['weight'];
  4537. //// $a+=round(($row['count']*MyClass::GetPrice($row['width'],$row['length'],$row['height'],$row['weight'],$row['country_id'],$row['unit'],$row['type']))+2*$row['mergedpackcount'], 2);
  4538. // $a+=$row['balance'];
  4539. // }
  4540. // echo $a;
  4541. // exit;
  4542.  
  4543. $criteria = new CDbCriteria;
  4544. // $criteria->condition = "(date6>='2017-07-07' and date6<='2017-08-17')";
  4545. $criteria->condition = "delivery='2'";
  4546. $orders = Orders::model()->findAll($criteria);
  4547. $a = 0;
  4548.  
  4549. // echo count($orders)."<br>";
  4550.  
  4551. foreach ($orders as $row)
  4552. {
  4553. $a+=$row['weight'];
  4554. // $a+=round(($row['count']*MyClass::GetPrice($row['width'],$row['length'],$row['height'],$row['weight'],$row['country_id'],$row['unit'],$row['type']))+2*$row['mergedpackcount'], 2);
  4555. // $a+=round(($row['count']*MyClass::GetPrice($row['width'],$row['length'],$row['height'],$row['weight'],$row['country_id'],$row['unit']))+2*$row['mergedpackcount'], 2);
  4556. // $a+=$row['price'];
  4557. }
  4558.  
  4559. echo $a;
  4560. }
  4561.  
  4562. public function actionOrderdelete()
  4563. {
  4564. $order_id = intval($_POST['order_id']);
  4565.  
  4566. $criteria = new CDbCriteria;
  4567. $criteria->condition = "id=:id and users_id=:users_id";
  4568. $criteria->params = array(':id'=>$order_id,':users_id' => (int)Yii::app() -> user -> id);
  4569. $orders = Myorder::model()->find();
  4570.  
  4571. $delete = Myorder::model()->deleteByPk(array('id'=>$order_id,'users_id'=>(int)Yii::app() -> user -> id));
  4572.  
  4573. if($orders)
  4574. {
  4575. if($delete)
  4576. echo CJSON::encode(array('status' => 1, 'error' => 'deleted'));
  4577. else
  4578. echo CJSON::encode(array('status' => 0, 'error' => 'not delete'));
  4579. }
  4580. else
  4581. echo CJSON::encode(array('status' => 0, 'error' => 'not found'));
  4582.  
  4583.  
  4584. }
  4585.  
  4586. public function actionPayShipping()
  4587. {
  4588. $order_id = intval($_POST['order_id']);
  4589.  
  4590. $pay = (float)$_POST['pay'];
  4591.  
  4592. $criteria = new CDbCriteria;
  4593. $criteria->condition = "id=:id and users_id=:users_id";
  4594. $criteria->params = array(':id'=>$order_id,':users_id' => (int)Yii::app() -> user -> id);
  4595. $orders = Orders::model()->find($criteria);
  4596.  
  4597. if(!$orders)
  4598. {
  4599. echo CJSON::encode(array('status' => 2));
  4600. Yii::app()->end();
  4601. }
  4602.  
  4603. $MehsulCodes = MehsulCodes::model()->findByPk((int) $edit_dec->type);
  4604. $tarif = ($orders->date1 >= '2018-02-15' || $orders->date1 == '0000-00-00' || $orders->date1 < '2013-01-01');
  4605. $tot_pay = Orders::calculateCh($orders->id);
  4606.  
  4607. $exchange = Yii::app()->db->createCommand()
  4608. ->select('usd_azn')
  4609. ->from('central_bank_rates')
  4610. ->limit(1)
  4611. ->order('date DESC')
  4612. ->queryRow();
  4613.  
  4614. $tot_pay = $tot_pay*(float)$exchange['usd_azn'];
  4615.  
  4616. $user = Users::model()->findByPk(Yii::app()->user->id);
  4617.  
  4618. if($user->balance > $tot_pay){
  4619.  
  4620. $command = Yii::app()->db->createCommand();
  4621. $gen_code = $command
  4622. ->select('secret_code')
  4623. ->from('wh_door_lock')
  4624. ->where('customer_code=:customer_code AND status=:status', array(':customer_code'=>Yii::app()->user->id+100000,'status'=>'0'))
  4625. ->queryRow();
  4626.  
  4627. //$secret_code= hexdec(uniqid());
  4628. //$secret_code = substr($secret_code,-4);
  4629. $secret_code= rand(1000,9999);
  4630. if(empty($gen_code)){
  4631.  
  4632.  
  4633. $command->insert('wh_door_lock', array(
  4634. 'customer_code' => Yii::app()->user->id+100000,
  4635. 'secret_code' => $secret_code,
  4636. 'createdDate' => date('Y-m-d H:i:s'),
  4637. 'status' => '0'
  4638. ));
  4639.  
  4640. }
  4641. else
  4642. {
  4643. $secret_code = $gen_code['secret_code'];
  4644. }
  4645.  
  4646.  
  4647. $new_balance = $user->balance - $tot_pay;
  4648. Users::model() -> updateByPk($user->id, array('balance' => $new_balance));
  4649.  
  4650. $ph = new PaymentHistory();
  4651. $ph ->users_id = Yii::app()->user->id;
  4652. $ph ->date = time();
  4653. $ph ->log = '- '.($pay).'AZN ( Hazırkı balans : '.$new_balance.') AZN (id:'.$order_id.':) nömrəli sifariş üçün balansdan çatdırılma haqqı';
  4654. Sms::Send($user -> mobile, '- '.($pay).'AZN ( Hazırkı balans : '.$new_balance.') AZN. '.$order_id.' nömrəli sifariş üçün balansdan çatdırılma haqqı. Giris kodu:'.$secret_code);
  4655. $ph->save(false);
  4656.  
  4657. Orders::model() -> updateByPk($order_id, array('paid' => '1'));
  4658.  
  4659.  
  4660. echo CJSON::encode(array('status' => 1));
  4661. Yii::app()->end();
  4662. }
  4663.  
  4664. else
  4665. {
  4666. echo CJSON::encode(array('status' => 0));
  4667. Yii::app()->end();
  4668. }
  4669.  
  4670.  
  4671.  
  4672. }
  4673.  
  4674. public function actionMultiPayShipping1(){
  4675.  
  4676. if(isset($_POST['datas1']) && !empty($_POST['datas1']))
  4677. {
  4678. $datas_id = $_POST['datas1'];
  4679. $user_id = Yii::app()->user->id;
  4680. $all_orders_id =array();
  4681. $total_amount = 0;
  4682. $exchange = Yii::app()->db->createCommand()->select('usd_azn')->from('central_bank_rates')->limit(1)->order('date DESC')->queryRow();
  4683.  
  4684. foreach($datas_id as $data)
  4685. {
  4686. if (strpos($data, ',') !== false) {
  4687.  
  4688. $count_bundle = substr_count($data, ',', strpos($data, ',') );
  4689.  
  4690. if($count_bundle > 2){
  4691.  
  4692. $multiple_ids = explode(',',$data);
  4693.  
  4694. $array_second_part = end($multiple_ids);
  4695. $array_second_part = explode('_',$array_second_part);
  4696.  
  4697. $bundle_date = $array_second_part[0];
  4698. $country_id = $array_second_part[1];
  4699.  
  4700. array_pop($multiple_ids);
  4701. $all_orders_id = array_merge($all_orders_id, $multiple_ids);
  4702.  
  4703. $sql="SELECT * FROM cms_orders WHERE users_id ='$user_id' AND date6 = '$bundle_date' AND delivery = 5 AND country_id = '$country_id' ";
  4704. $same_date_bundle = Yii::app()->db->createCommand($sql)->queryAll();
  4705. $bundle_count = count($same_date_bundle);
  4706.  
  4707. $i = 0;$amount = $tot_width = $tot_height = $tot_length = $tot_weight = 0;
  4708.  
  4709. foreach($same_date_bundle as $bundle){
  4710.  
  4711. if(in_array($bundle['id'],$multiple_ids))
  4712. {
  4713.  
  4714. $tarif = ($bundle['date1'] >= '2018-02-15' || $bundle['date1'] == '0000-00-00' || $bundle['date1'] < '2013-01-01');
  4715. $tot_width += $bundle['width'];
  4716. $tot_height += $bundle['height'];
  4717. $tot_length += $bundle['length'];
  4718. $tot_weight += $bundle['weight'];
  4719.  
  4720. if(++$i == $bundle_count) {
  4721.  
  4722. $MehsulCodes = MehsulCodes::model()->findByPk((int) $bundle['type']);
  4723. $amount = Orders::calculateShipping($MehsulCodes->type, $tot_width , $tot_height , $tot_length , $tot_weight ,$tarif, $bundle['country_id']);
  4724. $amount +=$bundle_count;
  4725.  
  4726. $total_amount += round($amount*$exchange['usd_azn'],2);
  4727.  
  4728. }
  4729. }
  4730. else{
  4731. echo CJSON::encode(array('status' =>404, 'message' => Yii::app()->homeUrl));
  4732. Yii::app()->end();
  4733. }
  4734.  
  4735. //print_R($same_date_new);
  4736. }
  4737. }
  4738. else{
  4739. echo CJSON::encode(array('status' =>404, 'message' => Yii::app()->homeUrl));
  4740. Yii::app()->end();
  4741. }
  4742.  
  4743. }
  4744. elseif(strpos($data, ':') !== false){
  4745. $count_bundle = substr_count($data, ':', strpos($data, ':') );
  4746.  
  4747. if($count_bundle == 1)
  4748. {
  4749. $one_bundle = explode(':',$data);
  4750. $one_bundle_order_id = $one_bundle[0];
  4751. $one_bundle_order_date = $one_bundle[1];
  4752.  
  4753. array_push($all_orders_id, $one_bundle_order_id);
  4754.  
  4755. $sql="SELECT * FROM cms_orders WHERE users_id ='$user_id' AND date6 = '$one_bundle_order_date' AND delivery = 5 AND id = '$one_bundle_order_id'";
  4756. $one_bundle_info = Yii::app()->db->createCommand($sql)->queryRow();
  4757. $amount = 0;
  4758. if(!empty($one_bundle_info))
  4759. {
  4760. $MehsulCodes = MehsulCodes::model()->findByPk((int) $one_bundle_info['type']);
  4761. $tarif = ($one_bundle_info['type'] >= '2018-02-15' || $one_bundle_info['type'] == '0000-00-00' || $one_bundle_info['type'] < '2013-01-01');
  4762. $amount = Orders::calculateShipping($MehsulCodes->type, $one_bundle_info['width'], $one_bundle_info['height'], $one_bundle_info['length'],$one_bundle_info['weight'], $tarif, $one_bundle_info['country_id']);
  4763. $amount = round($amount*$exchange['usd_azn'],2);
  4764. $total_amount += round($amount,2);
  4765.  
  4766. }
  4767. else
  4768. {
  4769. echo CJSON::encode(array('status' =>404, 'message' => Yii::app()->homeUrl));
  4770. Yii::app()->end();
  4771. }
  4772.  
  4773. }
  4774. else
  4775. {
  4776. echo CJSON::encode(array('status' =>404, 'message' => Yii::app()->homeUrl));
  4777. Yii::app()->end();
  4778. }
  4779.  
  4780. }
  4781. else
  4782. {
  4783. echo CJSON::encode(array('status' =>404, 'message' => Yii::app()->homeUrl));
  4784. Yii::app()->end();
  4785. }
  4786. }
  4787.  
  4788. $criteria = new CDbCriteria();
  4789. $criteria->addInCondition("id", $all_orders_id);
  4790. $criteria->addInCondition("users_id",array($user_id));
  4791. $orders = Orders::model()->findAll($criteria);
  4792.  
  4793. $user_balance = Users::model()->findByPk($user_id)->balance;
  4794.  
  4795. if($user_balance >= $total_amount)
  4796. {
  4797. $command = Yii::app()->db->createCommand();
  4798. $gen_code = $command
  4799. ->select('secret_code')
  4800. ->from('wh_door_lock')
  4801. ->where('customer_code=:customer_code AND status=:status', array(':customer_code'=>$user_id+100000,'status'=>'0'))
  4802. ->queryRow();
  4803.  
  4804.  
  4805. $secret_code= rand(1000,9999);
  4806.  
  4807. if(empty($gen_code))
  4808. {
  4809. $command->insert('wh_door_lock', array(
  4810. 'customer_code' => $user_id+100000,
  4811. 'secret_code' => $secret_code,
  4812. 'createdDate' => date('Y-m-d H:i:s'),
  4813. 'status' => '0'
  4814. ));
  4815.  
  4816. }
  4817. else
  4818. {
  4819. $secret_code = $gen_code['secret_code'];
  4820. }
  4821.  
  4822. $new_user_balance = $user_balance - $total_amount;
  4823. Users::model() -> updateByPk($user_id, array('balance' => $new_user_balance));
  4824.  
  4825. Orders::model()->updateAll(array( 'paid' => 1),$criteria);
  4826.  
  4827. $ph = new PaymentHistory();
  4828. $ph ->users_id = $user_id;
  4829. $ph ->date = time();
  4830. $ph ->log = '- '.($total_amount).'AZN catdirilma haqqi ucun balansdan cixildi.( Hazırkı balans : '.$new_user_balance.')';
  4831. Sms::Send(Users::model()->findByPk($user_id) -> mobile, '- '.($total_amount).'AZN catdirilma haqqi ucun balansdan cixildi.( Hazırkı balans : '.$new_user_balance.'). Giris kodu:'.$secret_code);
  4832. $ph->save(false);
  4833.  
  4834. echo CJSON::encode(array('status' => 200, 'message' => 'Əməliyyat uğurla tamamlandı'));
  4835. Yii::app()->end();
  4836. }
  4837. else
  4838. {
  4839. $reminder_paid_amount = New PayShippingWithCard();
  4840. $reminder_paid_amount->user_id = $user_id;
  4841. $reminder_paid_amount->total_paid_amount = $total_amount;
  4842. $reminder_paid_amount->paid_from_card = round($total_amount - $user_balance,2);
  4843. $reminder_paid_amount->order_ids = implode(",",$all_orders_id);
  4844. $reminder_paid_amount->reference = rand(000000, 999999).'shipping';
  4845. $reminder_paid_amount->save();
  4846.  
  4847. if($user_balance<0)
  4848. {
  4849. echo CJSON::encode(array('status' => 202,
  4850. 'message' => "Sizin balansınızda <strong>$user_balance AZN</strong> borc olduğu üçün toplam ödəyəcəyiniz məbləğ <strong>$reminder_paid_amount->paid_from_card AZN</strong>",
  4851. 'reference'=>'<a class="btn btn-success" href ="/site/shippingwithcard?reference='.$reminder_paid_amount->reference.'" >Plastik kartla ödə</a>'));
  4852. }
  4853. else
  4854. {
  4855. echo CJSON::encode(array('status' => 202,
  4856. 'message' => "Balansınızdan <strong>$user_balance AZN </strong> qədər məbləğ olduğundan bu əməliyyatı yerinə yetirmək üçün <strong>$reminder_paid_amount->paid_from_card AZN çatmır.</strong> ",
  4857. 'reference'=>'<a class="btn btn-success" href ="/site/shippingwithcard?reference='.$reminder_paid_amount->reference.'" >Plastik kartla ödə</a>'));
  4858. }
  4859.  
  4860. Yii::app()->end();
  4861.  
  4862.  
  4863. }
  4864.  
  4865. }
  4866. else
  4867. {
  4868. echo CJSON::encode(array('status' =>404, 'message' => Yii::app()->homeUrl));
  4869. Yii::app()->end();
  4870.  
  4871. }
  4872. }
  4873.  
  4874. public function actionMultiPayShipping()
  4875. {
  4876. $user_id = Yii::app()->user->id;
  4877. if(isset($_POST['datas']))
  4878. {
  4879. $criteria = new CDbCriteria();
  4880. $criteria->addInCondition("id", $_POST['datas']);
  4881. $criteria->addInCondition("users_id",array($user_id));
  4882. $orders = Orders::model()->findAll($criteria);
  4883.  
  4884. if($orders)
  4885. {
  4886. $exchange = Yii::app()->db->createCommand()->select('usd_azn')->from('central_bank_rates')->limit(1)->order('date DESC')->queryRow();
  4887.  
  4888. foreach($orders as $order)
  4889. {
  4890. $MehsulCodes = MehsulCodes::model()->findByPk((int) $order->type);
  4891. $tarif = ($order->date1 >= '2018-02-15' || $order->date1 == '0000-00-00' || $order->date1 < '2013-01-01');
  4892. $amount = Orders::calculateCh($order->id);
  4893. $tot = round($amount*$exchange['usd_azn'],2);
  4894. $total_amount += $tot;
  4895. }
  4896.  
  4897. }
  4898. else
  4899. {
  4900. echo CJSON::encode(array('status' =>0, 'message' => 'Sifarişinizə uyğun məlumat tapılmadı'));
  4901. Yii::app()->end();
  4902. }
  4903. $user_balance = Users::model()->findByPk($user_id)->balance;
  4904.  
  4905. if($user_balance >= $total_amount)
  4906. {
  4907. $command = Yii::app()->db->createCommand();
  4908. $gen_code = $command
  4909. ->select('secret_code')
  4910. ->from('wh_door_lock')
  4911. ->where('customer_code=:customer_code AND status=:status', array(':customer_code'=>$user_id+100000,'status'=>'0'))
  4912. ->queryRow();
  4913.  
  4914.  
  4915. $secret_code= rand(1000,9999);
  4916.  
  4917. if(empty($gen_code))
  4918. {
  4919. $command->insert('wh_door_lock', array(
  4920. 'customer_code' => $user_id+100000,
  4921. 'secret_code' => $secret_code,
  4922. 'createdDate' => date('Y-m-d H:i:s'),
  4923. 'status' => '0'
  4924. ));
  4925.  
  4926. }
  4927. else
  4928. {
  4929. $secret_code = $gen_code['secret_code'];
  4930. }
  4931.  
  4932. $new_user_balance = $user_balance - $total_amount;
  4933. Users::model() -> updateByPk($user_id, array('balance' => $new_user_balance));
  4934.  
  4935. Orders::model()->updateAll(array( 'paid' => 1),$criteria);
  4936.  
  4937. $ph = new PaymentHistory();
  4938. $ph ->users_id = $user_id;
  4939. $ph ->date = time();
  4940. $ph ->log = '- '.($total_amount).'AZN catdirilma haqqi ucun balansdan cixildi.( Hazırkı balans : '.$new_user_balance.')';
  4941. Sms::Send(Users::model()->findByPk($user_id) -> mobile, '- '.($total_amount).'AZN catdirilma haqqi ucun balansdan cixildi.( Hazırkı balans : '.$new_user_balance.'). Giris kodu:'.$secret_code);
  4942. $ph->save(false);
  4943.  
  4944. echo CJSON::encode(array('status' => 1, 'message' => 'Əməliyyat uğurla tamamlandı'));
  4945. Yii::app()->end();
  4946. }
  4947. else
  4948. {
  4949.  
  4950.  
  4951. $reminder_paid_amount = New PayShippingWithCard();
  4952. $reminder_paid_amount->user_id = $user_id;
  4953. $reminder_paid_amount->total_paid_amount = $total_amount;
  4954. $reminder_paid_amount->paid_from_card = round($total_amount - $user_balance,2);
  4955. $reminder_paid_amount->order_ids = implode(",",$_POST['datas']);
  4956. $reminder_paid_amount->reference = rand(000000, 999999).'shipping';
  4957. $reminder_paid_amount->save();
  4958.  
  4959. $command = Yii::app()->db->createCommand();
  4960. $gen_code = $command
  4961. ->select('secret_code')
  4962. ->from('wh_door_lock')
  4963. ->where('customer_code=:customer_code AND status=:status', array(':customer_code'=>$user_id+100000,'status'=>'0'))
  4964. ->queryRow();
  4965.  
  4966.  
  4967. $secret_code= rand(1000,9999);
  4968.  
  4969. if(empty($gen_code))
  4970. {
  4971. $command->insert('wh_door_lock', array(
  4972. 'customer_code' => $user_id+100000,
  4973. 'secret_code' => $secret_code,
  4974. 'createdDate' => date('Y-m-d H:i:s'),
  4975. 'status' => '0'
  4976. ));
  4977.  
  4978. }
  4979. else
  4980. {
  4981. $secret_code = $gen_code['secret_code'];
  4982. }
  4983.  
  4984. if($user_balance<0)
  4985. {
  4986. echo CJSON::encode(array('status' => 2,
  4987. 'message' => "Sizin balansınızda <strong>$user_balance AZN</strong> borc olduğu üçün toplam ödəyəcəyiniz məbləğ <strong>$reminder_paid_amount->paid_from_card AZN</strong>",
  4988. 'reference'=>'<a class="btn btn-success" href ="/site/shippingwithcard?reference='.$reminder_paid_amount->reference.'" >Plastik kartla ödə</a>'));
  4989. }
  4990. else
  4991. {
  4992. echo CJSON::encode(array('status' => 2,
  4993. 'message' => "Balansınızdan <strong>$user_balance AZN </strong> qədər məbləğ olduğundan bu əməliyyatı yerinə yetirmək üçün <strong>$reminder_paid_amount->paid_from_card AZN çatmır.</strong> ",
  4994. 'reference'=>'<a class="btn btn-success" href ="/site/shippingwithcard?reference='.$reminder_paid_amount->reference.'" >Plastik kartla ödə</a>'));
  4995. }
  4996.  
  4997. Yii::app()->end();
  4998.  
  4999.  
  5000. }
  5001. }
  5002.  
  5003. }
  5004. public function actionShippingWithCard(){
  5005.  
  5006. if(isset($_GET['reference']))
  5007. {
  5008. $ref = str_replace(' ', '', $_GET['reference']);
  5009. $exist_reference = PayShippingWithCard::model()->find('reference=:reference', array(':reference'=>$ref));
  5010.  
  5011. if($exist_reference)
  5012. {
  5013. $mebleg = str_replace(",",".",$exist_reference->paid_from_card);
  5014. $desc = CHtml::encode(Yii::app()->user->id."-".Yii::app()->user->getFirstName()." ".Yii::app()->user->getSurname());
  5015. $desc = str_replace(' ','_',$desc);
  5016. $desc = MyClass::slugify($desc);
  5017.  
  5018. $payment = new Millikart($exist_reference->paid_from_card,$exist_reference->reference,$desc);
  5019. $response = $payment->getURL();
  5020. header("Location: ".$response);
  5021. }
  5022.  
  5023. else
  5024. {
  5025. $this->redirect(Yii::app()->homeUrl);
  5026. }
  5027.  
  5028. }
  5029. else{
  5030. $this->redirect(Yii::app()->homeUrl);
  5031. }
  5032.  
  5033. }
  5034.  
  5035. public function actionDeleteorder()
  5036. {
  5037. $order_id = intval($_POST['order_id']);
  5038.  
  5039. $criteria = new CDbCriteria;
  5040. $criteria->condition = "id=:id and users_id=:users_id";
  5041. $criteria->params = array(':id'=>$order_id,':users_id' => (int)Yii::app() -> user -> id);
  5042. $orders = Orders::model()->find($criteria);
  5043.  
  5044. $orders->status = 2;
  5045.  
  5046.  
  5047. $delete = Orders::model()->deleteByPk(array('id'=>$order_id,'users_id'=>(int)Yii::app() -> user -> id));
  5048.  
  5049. if($orders)
  5050. {
  5051. if($orders->save(false))
  5052. echo CJSON::encode(array('status' => 1, 'error' => 'deleted'));
  5053. else
  5054. echo CJSON::encode(array('status' => 0, 'error' => 'not delete'));
  5055. }
  5056. else
  5057. echo CJSON::encode(array('status' => 0, 'error' => 'not found'));
  5058.  
  5059.  
  5060. }
  5061.  
  5062. public function actionBasketaccept($id)
  5063. {
  5064. $id = intval($_GET['id']);
  5065.  
  5066. Myorder::model() -> updateByPk($id, array('basket' => '0'));
  5067.  
  5068. $this->redirect(CHtml::normalizeUrl(array("site/order")));
  5069. }
  5070.  
  5071. public function actionMultiplesms()
  5072. {
  5073. $offset = intval($_GET['offset']);
  5074. $limit = intval($_GET['limit']);
  5075. $sql="
  5076. SELECT id,mobile FROM `cms_users` WHERE `status`='1' and `mobile`!='' LIMIT $offset,$limit
  5077. ";
  5078.  
  5079. $myorders = Yii::app()->db->createCommand($sql)->queryAll();
  5080.  
  5081. echo count($myorders);
  5082.  
  5083. foreach ($myorders as $val)
  5084. Sms::Send($val['mobile'], "Hormetli musterimiz nezerinize catdiraq ki, sifarislerin verilmesi berpa olundu. Linklerinizi gondere bilersiniz.");
  5085.  
  5086. // Sms::Send(994506877836, "Hormetli musterimiz nezerinize catdiraq ki, sifarislerin verilmesi berpa olundu. Linklerinizi gondere bilersiniz.");
  5087.  
  5088. // var_dump($myorders);
  5089. }
  5090.  
  5091. public function actionGetpostivr(){
  5092.  
  5093.  
  5094. header('Content-Type: application/json');
  5095.  
  5096. if(isset($_GET['phone']) && !empty($_GET['phone'])){
  5097.  
  5098. $phone = intval($_GET['phone']);
  5099.  
  5100. $getUserByPhone = Users::model()->findByAttributes(array("phone"=>$phone));
  5101. $getUserByMobile = Users::model()->findByAttributes(array("mobile"=>$phone));
  5102.  
  5103. if(count($getUserByPhone)>0) $user_id_2 = $getUserByPhone->id;
  5104. elseif(count($getUserByMobile)>0) $user_id_2 = $getUserByMobile->id;
  5105. else $user_id_2 = 0;
  5106. }elseif(isset($_GET['user_id']) && !empty($_GET['user_id'])){
  5107. $user_id_2 = intval($_GET['user_id']);
  5108. $user_id_2 = $user_id_2-100000;
  5109. }
  5110. else
  5111. $user_id_2 = 0;
  5112.  
  5113. if($user_id_2>0)
  5114. $getUser = Users::model()->findByPk($user_id_2);
  5115. else
  5116. $getUser = null;
  5117.  
  5118. if($getUser)
  5119. {
  5120.  
  5121. /*$orders = Orders::model()->findAllByAttributes(array('users_id' => $user_id_2));
  5122.  
  5123. $delivery_names = array(
  5124. 1 => 'sifarish_verilib',
  5125. 2 => 'anbardadir',
  5126. 3 => 'gonderilib',
  5127. 4 => 'daxil_olub',
  5128. 5 => 'catib',
  5129. 6 => 'tehvil_verilib',
  5130. 7 => 'beyenname_gozleyir',
  5131. 8 => 'beyenname_elave_olunub'
  5132. );
  5133.  
  5134.  
  5135.  
  5136. $delivery_count = array(
  5137. 1 => 0,
  5138. 2 => 0,
  5139. 3 => 0,
  5140. 4 => 0,
  5141. 5 => 0,
  5142. 6 => 0,
  5143. 7 => 0,
  5144. 8 => 0
  5145. );
  5146. foreach($orders as $order){
  5147. $delivery_count[(int)$order->delivery] += 1;
  5148. }
  5149.  
  5150. $response = [];
  5151.  
  5152. foreach($delivery_count as $key => $val){
  5153. $response[$delivery_names[$key]] = $val;
  5154. }
  5155.  
  5156. $response['gozleyir'] = 0;
  5157. $response['odenis_olmayan'] = 0;*/
  5158.  
  5159. // Sifarishi gozleyenler
  5160. //$getmyorders = Myorder::model()->findAllByAttributes(array("users_id"=>$user_id_2,"status"=>'1'));
  5161.  
  5162. $getmyorders = Myorder::model()->findAllByAttributes(array("users_id"=>$user_id_2,"status"=>'1'));
  5163. $gozleyen = 0;
  5164. $odenisolmayan = 0;
  5165. foreach($getmyorders as $mo){
  5166. $status = PaymentProducts::model()->findByAttributes(array('myorder_id' =>$mo->id, 'paymentstatus' => 'SUCCESS'));
  5167. if($status){
  5168. $gozleyen ++;
  5169. }else{
  5170. $odenisolmayan ++;
  5171. }
  5172. }
  5173. /*$myorders_count = count($getmyorders);
  5174.  
  5175. $getmyorders2 = Myorder::model()->findAllByAttributes(array("users_id"=>$user_id_2,"status"=>'1', 'order_type' => 'is null'));
  5176. $myorders2_count = count($getmyorders2);*/
  5177.  
  5178. // Sifairshi verilenler
  5179. $getOrders1 = Orders::model()->findAllByAttributes(array("users_id"=>$user_id_2,"delivery"=>'1',"status"=>'1'));
  5180. $anbar_date_tr1 = null;
  5181. $anbar_date_tr2 = null;
  5182. foreach($getOrders1 as $order){
  5183. if($order['anbar_date_tr1'] !== null) $anbar_date_tr1 = $order['anbar_date_tr1'];
  5184. if($order['anbar_date_tr2'] !== null) $anbar_date_tr2 = $order['anbar_date_tr2'];
  5185. }
  5186.  
  5187.  
  5188. $delivery1_count = count($getOrders1);
  5189.  
  5190. // Turkiye anbarina daxil olmush sifar1ishler
  5191. $getOrders2 = Orders::model()->findAllByAttributes(array("users_id"=>$user_id_2,"delivery"=>'2',"status"=>'1'));
  5192.  
  5193. $plus_day = array(
  5194. 0 => '+2 days',
  5195. 1 => '+1 days',
  5196. 2 => '+3 days',
  5197. 3 => '+2 days',
  5198. 4 => '+1 days',
  5199. 5 => '+4 days',
  5200. 6 => '+3 days',
  5201. );
  5202. foreach ($getOrders2 as $anbar){
  5203. $weekday = date("w",strtotime($anbar->date2));
  5204. $date = date("Y-m-d",strtotime($anbar->date2));
  5205. $flight_day = date("Y-m-d",strtotime($date.$plus_day[$weekday]));
  5206. }
  5207.  
  5208.  
  5209. $delivery2_count = count($getOrders2);
  5210.  
  5211. //$getOrders3 = Orders::model()->findAllByAttributes(array("users_id"=>$user_id_2,"delivery"=>'3',"status"=>'1'));
  5212. $delivery3_count = 0;
  5213.  
  5214. $date3 = null;
  5215. /*foreach ($getOrders3 as $order){
  5216. if($date3 === null){
  5217. $date3 = date('Y-m-d', strtotime($order->date3 . ' +1 day'));
  5218. break;
  5219. }
  5220. }*/
  5221.  
  5222. $getOrders5 = Orders::model()->findAllByAttributes(array("users_id"=>$user_id_2,"delivery"=>'5',"status"=>'1'));
  5223. $delivery5_count = count($getOrders5);
  5224.  
  5225. $getOrders7 = Orders::model()->findAllByAttributes(array("users_id"=>$user_id_2,"delivery"=>'7',"status"=>'1'));
  5226. $delivery7_count = count($getOrders7);
  5227.  
  5228. echo CJSON::encode(array('status' => 1, 'info' =>
  5229. array(
  5230. "gozleme"=>$gozleyen,
  5231. "odenis_olunmayan"=>$odenisolmayan,
  5232. "verilen"=>
  5233. array(
  5234. "count"=>$delivery1_count,
  5235. "anbar_date_tr1"=>$anbar_date_tr1,
  5236. "anbar_date_tr2"=>$anbar_date_tr2
  5237. ),
  5238. "daxilolmush"=>
  5239. array(
  5240. "count"=>$delivery2_count,
  5241. "anbar_date_baku"=>$flight_day
  5242. ),
  5243. "gonderilen"=>
  5244. array(
  5245. "count"=>$delivery3_count,
  5246. "anbar_date_baku"=>$date3
  5247. ),
  5248. "beyenname_gozleyen"=>
  5249. array(
  5250. "count"=>$delivery7_count,
  5251. "anbar_date_baku"=>$flight_day
  5252. ),
  5253. "catib"=>$delivery5_count)
  5254. ));
  5255.  
  5256. }
  5257. else
  5258. echo CJSON::encode(array("status" => 0, "info" => "User not found"));
  5259.  
  5260.  
  5261. }
  5262.  
  5263. public function actionPostturkey($key)
  5264. {
  5265. $login = 'mover';
  5266. $pass = '0c5ff531018309164d347bc8b18fdcc8';//remover
  5267.  
  5268. if( ( @md5(md5($_SERVER['PHP_AUTH_PW'])) != $pass || @$_SERVER['PHP_AUTH_USER'] != $login)|| !@$_SERVER['PHP_AUTH_USER'])
  5269. {
  5270. header('WWW-Authenticate: Basic realm="Access denied"');
  5271. header('HTTP/1.0 401 Unauthorized');
  5272. echo 'Auth failed';
  5273. exit;
  5274. }
  5275.  
  5276. if($key=="mov3rp0stk4y")
  5277. {
  5278. if(!empty($_POST["save"])){
  5279. extract($_POST);
  5280. echo "<script>document.getElementById('successmesaj').style.display = 'block';</script>";
  5281. }
  5282. $this -> render('postturkey');
  5283. }
  5284. else{
  5285. $this->redirect(Yii::app()->homeUrl);
  5286. }
  5287. }
  5288.  
  5289. public function actionGetturkeyorders()
  5290. {
  5291. $post_val = strip_tags($_POST['input_val']);
  5292. $type = intval($_POST['input_type']);
  5293. //receive username from DB
  5294.  
  5295.  
  5296.  
  5297. if($type==1)
  5298. {
  5299. $sql="
  5300. SELECT * FROM `cms_orders` WHERE `magaza_tracking`='$post_val' and delivery='1' and status='1'";
  5301.  
  5302. $orders = Yii::app()->db->createCommand($sql)->queryAll();
  5303. $getUserId = $orders[0]['users_id'];
  5304. $getUsername = Users::model()->findByPk($getUserId);
  5305.  
  5306. }
  5307. elseif($type==2)
  5308. {
  5309. $getUserId = Users::model()->findByAttributes(array("user_key"=>$post_val));
  5310. $getUsername = Users::model()->findByPk($getUserId->id);
  5311.  
  5312. $sql="SELECT * FROM `cms_orders` WHERE `users_id`='$getUserId->id' and delivery='1' and status='1'";
  5313.  
  5314. $orders = Yii::app()->db->createCommand($sql)->queryAll();
  5315. }
  5316. else
  5317. $orders = 0;
  5318.  
  5319. $this->renderPartial('getturkeyinfo',array('orders' => $orders,'getUsername'=>$getUsername));
  5320. }
  5321.  
  5322. public function actionUpdateturkeyorder()
  5323. {
  5324. $order_id = intval($_POST['order_id']);
  5325. $order_type = intval($_POST['order_type']);
  5326. $no = intval($_POST['no']);
  5327.  
  5328. $order = Orders::model()->findByPk($order_id);
  5329.  
  5330. $this->renderPartial('orderinfoturkey',array('order'=>$order,'order_type'=>$order_type,'no'=>$no));
  5331. }
  5332.  
  5333. public function actionUpdateorderturkey()
  5334. {
  5335. $order_id = intval($_POST['order_id']);
  5336. $order_type = intval($_POST['order_type']);
  5337.  
  5338. if($order_type==3)
  5339. {
  5340. $height = $_POST['height'];
  5341. $width = $_POST['width'];
  5342. $length = $_POST['length'];
  5343. $weight = $_POST['weight'];
  5344.  
  5345. Orders::model()->updateByPk((int)$order_id, array('height' => $height,'width' => $width,'weight' => $weight, 'length' => $length, 'postturkey' => 1,'delivery' => '2','date2' => date('Y-m-d')));
  5346. }
  5347. else
  5348. {
  5349. $weight = $_POST['weight'];
  5350.  
  5351. Orders::model()->updateByPk((int)$order_id, array('weight' => $weight, 'postturkey' => 1,'delivery' => '2','date2' => date('Y-m-d')));
  5352. }
  5353. }
  5354.  
  5355. public function actionUserslocation()
  5356. {
  5357. $sql="
  5358. SELECT address FROM `cms_users` WHERE `address`!='' and status='1'";
  5359.  
  5360. $users = Yii::app()->db->createCommand($sql)->queryAll();
  5361. foreach ($users as $user)
  5362. {
  5363. $getcoord = file_get_contents("https://maps.google.com/maps/api/geocode/xml?address=".urlencode($user['address'])."&sensor=false&key=AIzaSyDC_3TnJ0yUYMRPyoctLKqoBtNnLTNwzKc");
  5364. if(!$getcoord) {
  5365. echo "Err: No access to Google service: ".$a."<br/>\n";
  5366. }else {
  5367. $get = simplexml_load_string($getcoord);
  5368.  
  5369. if ($get->status == "OK") {
  5370. $lat = (float) $get->result->geometry->location->lat;
  5371. $long = (float) $get->result->geometry->location->lng;
  5372. echo "lat: ".$lat."; long: ".$long."; ".$a."<br/>\n";
  5373. }else{
  5374. echo "Err: address not found: ".$a."<br/>\n";
  5375. }
  5376. }
  5377.  
  5378. }
  5379. }
  5380.  
  5381. public function actionetgb(){
  5382. if($_GET["key"] == "delixana1"){
  5383. $generalDetailsQuery = "SELECT count(*) as count, sum(price) as totalPrice, sum(weight) as totalWeight FROM mover.cms_orders WHERE shop NOT LIKE '%flo%' AND addedbyuser = '0' AND delivery = '2' AND status = '1'";
  5384.  
  5385. $typesQuery = "SELECT count(*) as count,type FROM mover.cms_orders WHERE shop NOT LIKE '%flo%' AND addedbyuser = '0' AND delivery = '2' AND status = '1' GROUP BY type";
  5386.  
  5387. $generalDetails = Yii::app()->db->createCommand($generalDetailsQuery)->queryAll();
  5388. $types = Yii::app()->db->createCommand($typesQuery)->queryAll();
  5389.  
  5390. echo "Toplam sifariş sayı: ".$generalDetails[0]["count"]."<br>";
  5391. echo "Toplam dəyər: ".$generalDetails[0]["totalPrice"]."<br>";
  5392. echo "Toplam çəki: ".$generalDetails[0]["totalWeight"]."<br>";
  5393.  
  5394. echo "<hr>";
  5395. foreach($types as $type){
  5396. $typeName;
  5397. if($type["type"] == "1"){
  5398. $typeName = "Geyim";
  5399. }else if($type["type"] == "2"){
  5400. $typeName = "Ayaqqabi";
  5401. }else if($type["type"] == "3"){
  5402. $typeName = "Diger";
  5403. }else if($type["type"] == "4"){
  5404. $typeName = "Kitab";
  5405. }
  5406. echo $typeName.": ".$type["count"]."<br>";
  5407. }
  5408. }
  5409. }
  5410.  
  5411. public function actionMailgrabber(){
  5412. $apiKey = 'delixana1';
  5413. $trackNumber = isset($_POST["trackNumber"]) ? $_POST["trackNumber"] : NULL;
  5414. $website = isset($_POST["website"]) ? $_POST["website"] : NULL;
  5415. $invoiceLink = isset($_POST["invoiceLink"]) ? $_POST["invoiceLink"] : NULL;
  5416. $status = isset($_POST["status"]) ? $_POST["status"] : NULL;
  5417.  
  5418. if(!isset($_POST["apiKey"]) || hash('sha256',$apiKey) != $_POST["apiKey"]){
  5419. http_response_code(401);
  5420. $this->sendJSONResponse(array(
  5421. "error" => "Not authorized.",
  5422. // "your" => $_POST["apiKey"],
  5423. // "needed" => hash('sha256',$apiKey),
  5424. // "website" => $website
  5425. ));
  5426. Yii::app()->end();
  5427. }
  5428.  
  5429. if($trackNumber && $invoiceLink && $website){
  5430. $this->addInvoiceFile($website,$trackNumber,$invoiceLink);
  5431. }else if($trackNumber && $status){
  5432. $this->updateOrderDeliveryStatus($trackNumber,$status);
  5433. }else{
  5434. http_response_code(400);
  5435.  
  5436. $this->sendJSONResponse(array(
  5437. "error" => "Not enough parameters sent"
  5438. ));
  5439.  
  5440. Yii::app()->end();
  5441. }
  5442.  
  5443. // $this->sendJSONResponse(array(
  5444. // "success" => true
  5445. // ));
  5446. Yii::app()->end();
  5447. }
  5448.  
  5449. private function addInvoiceFile($website,$trackNumber,$invoiceLink){
  5450. $criteria = new CDbCriteria;
  5451. // $criteria->condition = "magaza_tracking=:magaza_tracking";
  5452. $criteria->addSearchCondition("magaza_tracking","%".$trackNumber."%",false);
  5453. // $criteria->params = array(':magaza_tracking' => $trackNumber);
  5454. $order = Orders::model()->find($criteria);
  5455.  
  5456. // $order->file = $fileName;
  5457. // $order->save();
  5458. // exit;
  5459.  
  5460.  
  5461. if($order == NULL){
  5462. http_response_code(404);
  5463.  
  5464. $this->sendJSONResponse(array(
  5465. "error" => "An order with given track number doesn't exists"
  5466. ));
  5467.  
  5468. Yii::app()->end();
  5469. }else if($order->file != NULL){
  5470. http_response_code(403);
  5471.  
  5472. $this->sendJSONResponse(array(
  5473. "error" => "Invoice already exists"
  5474. ));
  5475.  
  5476. Yii::app()->end();
  5477. }else if($website == "trendyol.com"){
  5478. $fileName = round(microtime(true) * 1000).".pdf";
  5479. $filePath = Yii::app()->params['invoice_path'];
  5480.  
  5481. if (!file_exists($filePath)) {
  5482. mkdir($filePath, 0777, true);
  5483. }
  5484.  
  5485. file_put_contents($filePath.$fileName, file_get_contents($invoiceLink));
  5486.  
  5487.  
  5488. $order->file = $fileName;
  5489. $order->shop = $website;
  5490. $order->save();
  5491.  
  5492. // var_dump($order->errors);
  5493. // exit;
  5494.  
  5495. http_response_code(200);
  5496.  
  5497. $this->sendJSONResponse(array(
  5498. "fileName" => $fileName,
  5499. "fullPath" => $filePath.$fileName
  5500. ));
  5501. }else{
  5502. http_response_code(400);
  5503.  
  5504. $this->sendJSONResponse(array(
  5505. "error" => "Request parameters didn't match any condition"
  5506. ));
  5507.  
  5508. Yii::app()->end();
  5509. }
  5510. }
  5511.  
  5512. private function updateOrderDeliveryStatus($trackNumber,$status){
  5513. $criteria = new CDbCriteria;
  5514. $criteria->condition = "tracking=:tracking";
  5515. $criteria->params = array(':tracking' => $trackNumber);
  5516. $order = Orders::model()->find($criteria);
  5517.  
  5518. if($order == NULL){
  5519. http_response_code(404);
  5520. $this->sendJSONResponse(array(
  5521. "error" => "An order with given track number doesn't exists"
  5522. ));
  5523. Yii::app()->end();
  5524. }else{
  5525. $deliveryStatus = $order["delivery"];
  5526.  
  5527. if($status > 6){
  5528. http_response_code(400);
  5529. Yii::app()->end();
  5530. }else if($status > $deliveryStatus){
  5531. $order->delivery = $status;
  5532. $order->save();
  5533. }
  5534. }
  5535. }
  5536.  
  5537. public function actionGetOrdersWithoutInvoice(){
  5538. $arr = array();
  5539. $ordersQuery = "SELECT year(order_date), month(order_date), magaza_tracking, id, `file`, shop, price, order_key FROM mover.cms_orders WHERE magaza_tracking <> '' AND year(order_date) = 2018 AND month(order_date) = 1 AND `file` = '' AND lower(shop) LIKE '%trend%' ORDER BY id ASC";
  5540.  
  5541. // $typesQuery = "SELECT count(*) as count,type FROM mover.cms_orders WHERE shop NOT LIKE '%flo%' AND addedbyuser = '0' AND delivery = '2' AND status = '1' GROUP BY type";
  5542.  
  5543. $orders = Yii::app()->db->createCommand($ordersQuery)->queryAll();
  5544.  
  5545. // echo "<hr>";
  5546. foreach($orders as $order){
  5547. if(preg_match("/(\d+){8}/",$order['magaza_tracking'])){
  5548. array_push($arr,$order['magaza_tracking']);
  5549. }
  5550. }
  5551.  
  5552. $this->sendJSONResponse($arr);
  5553. }
  5554.  
  5555. public function sendJSONResponse($arr)
  5556. {
  5557. header('Content-type: application/json');
  5558. echo json_encode($arr);
  5559. Yii::app()->end();
  5560. }
  5561.  
  5562. private function generateRandomString($length = 10) {
  5563. $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  5564. $charactersLength = strlen($characters);
  5565. $randomString = '';
  5566. for ($i = 0; $i < $length; $i++) {
  5567. $randomString .= $characters[rand(0, $charactersLength - 1)];
  5568. }
  5569. return $randomString;
  5570. }
  5571.  
  5572. public function actionMonthlyInvoices($year = null,$month = null){
  5573.  
  5574. if($year == null || $month == null){
  5575. echo "Ay ve ya il duzgun yazilmayib";
  5576. }else{
  5577. $arr = array();
  5578. $ordersQuery = "SELECT id,`file` FROM mover.cms_orders WHERE magaza_tracking <> '' AND year(order_date) = ".$year." AND month(order_date) = ".$month." AND `file` <> '' AND lower(shop) LIKE '%trend%' ORDER BY id ASC;";
  5579.  
  5580. // $typesQuery = "SELECT count(*) as count,type FROM mover.cms_orders WHERE shop NOT LIKE '%flo%' AND addedbyuser = '0' AND delivery = '2' AND status = '1' GROUP BY type";
  5581.  
  5582. $orders = Yii::app()->db->createCommand($ordersQuery)->queryAll();
  5583.  
  5584. // echo "<hr>";
  5585. foreach($orders as $order){
  5586. echo $order["file"]."\n";
  5587. }
  5588. }
  5589. }
  5590.  
  5591. public function actionOrderfrommarkam(){
  5592.  
  5593. /*$_POST = $_GET;
  5594. error_reporting(E_ALL);
  5595.  
  5596. ini_set('display_errors', 1);*/
  5597. if(!$_POST){
  5598. return $this->sendJSONResponse(['success' => false, 'message' => 'Only post request']);
  5599. }
  5600.  
  5601. $name = $_POST['name'];
  5602. $surname = $_POST['surname'];
  5603. $phone = $_POST['phone'];
  5604. $size_id = $_POST['size_id'];
  5605. $product_id = $_POST['product_id'];
  5606. $address = $_POST['address'];
  5607. $price = $_POST['price'];
  5608. $link = $_POST['link'];
  5609. $count = $_POST['count'];
  5610. $order_id = $_POST['order_id'];
  5611. $comment = $_POST['comment'];
  5612.  
  5613. $success = false;
  5614. foreach ($link as $key => $val) {
  5615.  
  5616. if (strpos($price[$key], ",") > 0)
  5617. $price_new = str_replace(",", ".", $price[$key]);
  5618. else
  5619. $price_new = $price[$key];
  5620.  
  5621. $sql = "INSERT INTO
  5622. cms_markam_links (`comment`,`name`,`surname`,`phone`,`address`,`size`,`pid`,`link`,`price`,`count`,`date`, `country_id`, `m_order_id`)
  5623. VALUES (:comment,:name,:surname,:phone,:address,:size,:pid,:link,:price,$count[$key]," . time() . ", 1, " . $order_id . ")";
  5624. //echo $sql;
  5625. $command = Yii::app()->db->createCommand($sql)
  5626. ->bindParam(':name', $name, PDO::PARAM_STR)
  5627. ->bindParam(':surname', $surname, PDO::PARAM_STR)
  5628. ->bindParam(':phone', $phone, PDO::PARAM_STR)
  5629. ->bindParam(':address', $address, PDO::PARAM_STR)
  5630. ->bindParam(':size', $size_id[$key], PDO::PARAM_STR)
  5631. ->bindParam(':comment', $comment[$key], PDO::PARAM_STR)
  5632. ->bindParam(':pid', $product_id[$key], PDO::PARAM_STR)
  5633. ->bindParam(':link', $val, PDO::PARAM_STR)
  5634. ->bindParam(':price', $price_new, PDO::PARAM_STR)
  5635. ->execute();
  5636.  
  5637.  
  5638.  
  5639. }
  5640.  
  5641. try {
  5642. if ($command) {
  5643. $success = true;
  5644. }
  5645.  
  5646. } catch (Exception $ex) {
  5647. //$ex->getMessage();
  5648. $success = false;
  5649. }
  5650.  
  5651. echo json_encode(['success' => $success]);
  5652.  
  5653.  
  5654.  
  5655. }
  5656.  
  5657. public function actionOrderTracking($id = 0){
  5658. $order = Orders::model()->findByPk((int) $id);
  5659. $data = [];
  5660. if($order){
  5661. $date = 'date'.$order->delivery;
  5662. $data['success'] = true;
  5663. $data['status'] = $order->delivery;
  5664. $data['date'] = $order->{$date};
  5665.  
  5666. return $this->sendJSONResponse($data);
  5667. }
  5668.  
  5669. $data['success'] = false;
  5670. $data['message'] = 'Order not exists';
  5671. return $this->sendJSONResponse($data);
  5672.  
  5673. }
  5674.  
  5675. public function actionCancelCourierOrder(){
  5676.  
  5677. if(isset($_POST['courier_order_data']))
  5678. {
  5679. $user = Users::model()->findByPk(Yii::app()->user->id);
  5680.  
  5681. $data = explode(':',$_POST['courier_order_data']);
  5682.  
  5683. $courier_order_id = $data[0];
  5684. $status_id = $data[1];
  5685.  
  5686. if($status_id == 0 ){
  5687.  
  5688. DeliveryAddressNew::model() -> updateByPk($courier_order_id, array('status' => 4));
  5689.  
  5690. }
  5691. elseif($status_id == 1 ){
  5692.  
  5693. $new_user_balance = $user->balance - 5;
  5694. DeliveryAddressNew::model() -> updateByPk($courier_order_id, array('status' => 3));
  5695. Users::model() -> updateByPk($user->id, array('balance' => $new_user_balance));
  5696.  
  5697. // balans loqlari
  5698. $ph = new PaymentHistory();
  5699. $ph ->users_id = Yii::app()->user->id;
  5700. $ph ->date = time();
  5701. $ph ->log = '- 5 AZN Kuryer sifarişinin ləğvi ( Hazırkı balans : '.$new_user_balance.') AZN ';
  5702. $ph->save();
  5703.  
  5704. $order_ids = Yii::app()->db->createCommand()
  5705. ->select('*')
  5706. ->from('cms_delivery_order')
  5707. ->where('delivery_id=:delivery_id', array(':delivery_id'=>$courier_order_id))
  5708. ->queryAll();
  5709.  
  5710. foreach($order_ids as $order_id)
  5711. {
  5712. Orders::model() -> updateByPk($order_id['order_id'], array('delivery' => '5'));
  5713. }
  5714.  
  5715. }
  5716.  
  5717. Yii::app()->end();
  5718. }
  5719.  
  5720.  
  5721.  
  5722. }
  5723.  
  5724.  
  5725. /* public function actionEmailConfirm()
  5726. {
  5727. if(isset($_POST['user_email']))
  5728.  
  5729. {
  5730. $user = Users::model()->find('email=:email', array(':email'=>$_POST['user_email']));
  5731. $user_activation_key = sha1(md5(time() + rand(999, 999999999)));
  5732.  
  5733. Users::model() -> updateByPk($user->id, array('user_activation_key' => $user_activation_key));
  5734. $body="Hörmətli ".$user->name." ".$user->surname." \r\n <br>";
  5735. $body.="Aşağıdakı linkdən istifadə edərək hesabınızı təstiqləyin \r\n <br>";
  5736. $body.="<a href='".Yii::app()->createAbsoluteUrl('site/emailactivate',array('code'=>$user_activation_key))."'>".Yii::app()->createAbsoluteUrl('site/emailactivate',array('code'=>$user_activation_key))."</a> \r\n \r\n<br>";
  5737. $body.="Təşəkkür edirik.<br>";
  5738.  
  5739. $mail = new PHPMailer();
  5740. $mail->isSMTP();
  5741. $mail->Host = 'smtp.zoho.com';
  5742. $mail->SMTPAuth = true;
  5743. $mail->SMTPSecure = 'ssl';
  5744. $mail->Port = 465;
  5745. $mail->Username = 'info@mover.az';
  5746. $mail->Password = '3lf3c!n@';
  5747. $mail->SetFrom($mail->Username, 'MOVER.AZ');
  5748. $mail->AddAddress($user->email);
  5749. $mail->CharSet = 'UTF-8';
  5750. $mail->Subject = 'Email təsdiqləməsi - Mover';
  5751.  
  5752. $mail->MsgHTML($body);
  5753.  
  5754.  
  5755. if(!$mail->send())
  5756. {
  5757. echo CJSON::encode(['error' => $mail->ErrorInfo]);
  5758. Yii::app()->end();
  5759. }
  5760. else
  5761. {
  5762. echo CJSON::encode(['success' => 'Təsdiq maili göndərildi:']);
  5763. Yii::app()->end();
  5764. }
  5765.  
  5766. }
  5767.  
  5768.  
  5769. }*/
  5770.  
  5771. public function actionEmailActivate($code) {
  5772. if ($code != '') {
  5773. $model = Users::model() -> find('user_activation_key=:code', array(':code' => $code));
  5774.  
  5775. if ($model) {
  5776. // /$model->activate='';
  5777. if ($model -> verified_email == 0) {
  5778. $model -> verified_email = 1;
  5779. if ($model -> update(array('verified_email'))) {
  5780.  
  5781. $this -> render('emailactivate', array('model' => $model, 'status' => 'success'));
  5782. }
  5783. } else {
  5784. //Yii::app() -> user -> logout();
  5785. $this -> render('emailactivate', array('model' => $model, 'status' => 'already'));
  5786. }
  5787. } else {
  5788. throw new CHttpException(404, "Yalnış altivasiya kodu");
  5789. }
  5790. } else {
  5791. $this -> redirect(Yii::app() -> homeUrl);
  5792. }
  5793. }
  5794.  
  5795.  
  5796. public function actionEmailConfirm(){
  5797.  
  5798.  
  5799. if(isset($_POST['user_email']))
  5800.  
  5801. {
  5802.  
  5803. $user = Users::model()->find('email=:email', array(':email'=>$_POST['user_email']));
  5804. $user_activation_key = sha1(md5(time() + rand(999, 999999999)));
  5805.  
  5806. Users::model() -> updateByPk($user->id, array('user_activation_key' => $user_activation_key));
  5807.  
  5808. $body="Hörmətli ".$user->name." ".$user->surname." \r\n <br>";
  5809. $body.="Aşağıdakı linkdən istifadə edərək hesabınızı təstiqləyin \r\n <br>";
  5810. $body.="<a href='".Yii::app()->createAbsoluteUrl('site/emailactivate',array('code'=>$user_activation_key))."'>".Yii::app()->createAbsoluteUrl('site/emailactivate',array('code'=>$user_activation_key))."</a> \r\n \r\n<br>";
  5811. $body.="Təşəkkür edirik.<br>";
  5812.  
  5813. require '/home/mover.az/mailgun-php/vendor/autoload.php';
  5814. //$httpClient = new Http\Adapter\Guzzle6\Client();
  5815. $mailgunClient = new Mailgun\Mailgun('060c1707ab0899fcf36396af78c8ffa8-059e099e-9f1fe8d6');
  5816. $domain = 'mail.mover.az';
  5817.  
  5818. # Make the call to the client.
  5819. $result = $mailgunClient->sendMessage($domain, array(
  5820. 'from' => 'MOVER.AZ <info@mover.az>',
  5821. 'to' => $user->email,
  5822. 'subject' => 'Email təsdiqləməsi - Mover',
  5823. 'html' => $body,
  5824. ));
  5825.  
  5826. if($result->http_response_code == 200)
  5827. {
  5828. echo CJSON::encode(['response' => 'Təsdiq maili göndərildi:']);
  5829. Yii::app()->end();
  5830. }
  5831. elseif($result->http_response_code == 500)
  5832. {
  5833. echo CJSON::encode(['response' => 'Sistemde xeta baş verdi:']);
  5834. Yii::app()->end();
  5835. }
  5836. }
  5837.  
  5838. }
  5839.  
  5840. public function actionMyCommitment()
  5841. {
  5842.  
  5843. $user_id =Yii::app()->user->id;
  5844. $criteria = new CDbCriteria();
  5845. $criteria->addCondition("users_id=:users_id");
  5846. $criteria->params = array(':users_id' => $user_id);
  5847. $commitment = Commitment::model()->findAll($criteria);
  5848.  
  5849. $this -> render('commitment', array('commitment' => $commitment));
  5850.  
  5851. }
  5852.  
  5853.  
  5854. public function actionAddCommitment()
  5855. {
  5856.  
  5857. $model = new Commitment;
  5858.  
  5859. if(isset($_POST['c_name']))
  5860. {
  5861. $commitmentName = Yii::app()->request->getPost('c_name');
  5862. $commitmentSurname = Yii::app()->request->getPost('c_surname');
  5863. $commitmentEnddate = Yii::app()->request->getPost('end_date');
  5864. $date = date("Y-m-d");
  5865.  
  5866. $commitmetImage = Yii::app()->request->getPost('image');
  5867.  
  5868. if($_POST['c_name'] == '')
  5869. {
  5870. Yii::app()->user->setFlash('empty_info','Bütün məlumatları daxil edin');
  5871. return $this -> render('addcommitment', array('model' => $model));
  5872.  
  5873. }
  5874.  
  5875. if($_POST['c_surname'] == '')
  5876. {
  5877. Yii::app()->user->setFlash('empty_info','Bütün məlumatları daxil edin');
  5878. return $this -> render('addcommitment', array('model' => $model));
  5879.  
  5880. }
  5881.  
  5882. if($_POST['end_date'] == '')
  5883. {
  5884. Yii::app()->user->setFlash('empty_info','Bütün məlumatları daxil edin');
  5885. return $this -> render('addcommitment', array('model' => $model));
  5886.  
  5887. }
  5888.  
  5889. if($_FILES['image']['name'] == '')
  5890. {
  5891. Yii::app()->user->setFlash('empty_image','Fayl seçilməyib');
  5892. return $this -> render('addcommitment', array('model' => $model));
  5893.  
  5894. }
  5895.  
  5896.  
  5897. $model->users_id=Yii::app()->user->id;
  5898. $model->attributes = $_POST;
  5899.  
  5900. $type=$_FILES['image']['type'];
  5901. $extension = strtolower(pathinfo($_FILES['image']['name'], PATHINFO_EXTENSION));
  5902.  
  5903. $path = Yii::app()->params['users_image_path'].'/commitment';
  5904.  
  5905.  
  5906. $type_files=array('image/jpg','image/jpeg','image/png','image/bmp');
  5907. $type_extension=array('jpg','jpeg','png','bmp');
  5908.  
  5909. if(in_array($type, $type_files) && in_array($extension,$type_extension)){
  5910.  
  5911. $model->image =time().uniqid(rand()).$_FILES['image']['name'];
  5912. move_uploaded_file($_FILES["image"]["tmp_name"],$path.'/'.$model->image);
  5913. $model->end_date = date('Y-m-d', strtotime($date . ' +'.$commitmentEnddate.' day'));
  5914. if($model->save());
  5915. {
  5916. $this->redirect('/mycommitment');
  5917. }
  5918. }
  5919. else
  5920. {
  5921. Yii::app()->user->setFlash('image_type','Faylın tipi düzgün deyil');
  5922. return $this -> render('addcommitment', array('model' => $model));
  5923. }
  5924.  
  5925. }
  5926.  
  5927. $this -> render('addcommitment', array('model' => $model));
  5928. }
  5929.  
  5930. public function actionDeleteCommitment(){
  5931.  
  5932. $commitment_id = intval($_POST['commitment_id']);
  5933.  
  5934. $criteria = new CDbCriteria;
  5935. $criteria->condition = "id=:id and users_id=:users_id";
  5936. $criteria->params = array(':id'=>$commitment_id,':users_id' => (int)Yii::app() -> user -> id);
  5937. $commitment = Commitment::model()->find($criteria);
  5938.  
  5939.  
  5940.  
  5941.  
  5942. $delete = Commitment::model()->deleteByPk(array('id'=>$commitment_id,'users_id'=>(int)Yii::app() -> user -> id));
  5943.  
  5944. if($delete)
  5945. {
  5946. echo CJSON::encode(array('status' => 1, 'error' => 'deleted'));
  5947.  
  5948. }
  5949. else
  5950. echo CJSON::encode(array('status' => 0, 'error' => 'not found'));
  5951.  
  5952.  
  5953. }
  5954.  
  5955. public function actionEditCommitment($id = 0){
  5956.  
  5957. $id=intval($id);
  5958. $criteria = new CDbCriteria;
  5959. $criteria->condition = "id=:id and users_id=:users_id";
  5960. $criteria->params = array(':id'=>$id,':users_id' => (int)Yii::app() -> user -> id);
  5961. $commitment = Commitment::model()->find($criteria);
  5962.  
  5963. if(isset($_POST['c_name']))
  5964. {
  5965. $commitmentName = Yii::app()->request->getPost('c_name');
  5966. $commitmentSurname = Yii::app()->request->getPost('c_surname');
  5967. $commitmentEnddate = Yii::app()->request->getPost('end_date');
  5968.  
  5969. $type=$_FILES['image']['type'];
  5970. $extension = strtolower(pathinfo($_FILES['image']['name'], PATHINFO_EXTENSION));
  5971.  
  5972. $path = Yii::app()->params['users_image_path'].'/commitment';
  5973.  
  5974.  
  5975. $type_files=array('image/jpg','image/jpeg','image/png','image/bmp');
  5976. $type_extension=array('jpg','jpeg','png','bmp');
  5977. if($_FILES['image']['name'] != '')
  5978. {
  5979. if(in_array($type, $type_files) && in_array($extension,$type_extension))
  5980. {
  5981. $commitment->c_name = $commitmentName;
  5982. $commitment->c_surname = $commitmentSurname;
  5983. $commitment->image =time().uniqid(rand()).$_FILES['image']['name'];
  5984. move_uploaded_file($_FILES["image"]["tmp_name"],$path.'/'.$commitment->image);
  5985.  
  5986.  
  5987. if($commitment->save());
  5988. {
  5989. $this->redirect('/mycommitment');
  5990. }
  5991. }
  5992. else
  5993. {
  5994. Yii::app()->user->setFlash('image_type','Faylın tipi düzgün deyil');
  5995. return $this -> render('editCommitment', array('model' => $commitment));
  5996. }
  5997. }
  5998.  
  5999. else
  6000. {
  6001.  
  6002. $commitment->c_name = $commitmentName;
  6003. $commitment->c_surname = $commitmentSurname;
  6004. $commitment->end_date = date('Y-m-d', strtotime($date . ' +'.$commitmentEnddate.' day'));
  6005. if($commitment->save());
  6006. {
  6007. $this->redirect('/mycommitment');
  6008. }
  6009. }
  6010. }
  6011.  
  6012. $this->render('editCommitment',array('commitment' =>$commitment));
  6013.  
  6014. }
  6015.  
  6016. public function actionTestMandril(){
  6017.  
  6018. //$this->render('popup');
  6019. // $controller = Yii::app()->getController();
  6020. Yii::app()->params['users_image_path'];
  6021. }
  6022.  
  6023.  
  6024. }
Add Comment
Please, Sign In to add comment