class Zaym { static $logoPath ='upload/zaym/'; static $sumDefault = 500; static $termDefault = 5; static function getLink($d) { return '/zajm/'.$d['alias'].'-'.$d['zaymId'].'/'; } static function getCompanyLink($d) { return '/mfo/'.$d['companyAlias'].'/'; } static function getZaymLink($d) { return '/'.$d['alias'].'/'; } static function getLandings($d) { return [ [ 'title'=>'Ofertas', 'type'=>'type', 'level'=>1, 'parentAlias'=>'', 'pages'=>[ // 'prestamos-personales'=> ['get'=> [],'title'=>'Préstamos personales','topTextHeader'=>'Si está interesado en un préstamo inmediato en línea, ¡obtenerlo es fácil! Los préstamos personales inmediatos en México ahora están disponibles en línea. Puede encontrar y elegir ofertas adecuadas en esta página web.','type'=>'zaym' ], ] ], [ 'title'=>'Popular', 'type'=>'type', 'level'=>1, 'parentAlias'=>'', 'pages'=>[ // 'prestamos-en-linea'=> ['get'=> [],'title'=>'Préstamos en línea','topTextHeader'=>'Además de los préstamos tradicionales, que han estado disponibles para los residentes de México durante varias décadas, en los últimos años también se han ofrecido préstamos en línea rápidos. Su principal ventaja es la rapidez con la que se pueden conseguir préstamos de dinero online para solucionar pequeñas dificultades financieras en el camino. El tiempo de espera suele ser de 15 minutos a 24 horas, dependiendo de la cantidad.','type'=>'zaym' ], 'pozyczki-pozabankowe-ratalne'=> ['get'=> [],'title'=>'Pożyczki Pozabankowe Długoterminowe Przez Internet','topTextHeader'=>'','type'=>'zaym' ], 'pozyczka-na-swieta'=> ['get'=> [],'title'=>'Pożyczka na Święta','topTextHeader'=>'','type'=>'zaym' ], 'darmowa-pozyczka'=> ['get'=> [],'title'=>'Ranking Darmowych Pożyczek – Pierwsza Chwilówka Gratis','topTextHeader'=>'','type'=>'zaym' ], 'chwilowka-w-weekend'=> ['get'=> [],'title'=>'Pożyczka w weekend','topTextHeader'=>'','type'=>'zaym' ], 'erif'=> ['get'=> [],'title'=>'Chwilówki bez ERIF','topTextHeader'=>'','type'=>'zaym' ], 'pozyczka-bez-zdolnosci-kredytowej'=> ['get'=> [],'title'=>'Pożyczki bez zdolności kredytowej','topTextHeader'=>'','type'=>'zaym' ], 'pozyczka-bez-weryfikacji-telefonicznej'=> ['get'=> [],'title'=>'Pożyczki bez weryfikacji telefonicznej','topTextHeader'=>'','type'=>'zaym' ], 'pozyczka-na-60-dni'=> ['get'=> [],'title'=>'Pożyczki na 60 dni','topTextHeader'=>'','type'=>'zaym' ], 'pozyczka-na-dowod'=> ['get'=> [],'title'=>'Pożyczki na dowód','topTextHeader'=>'','type'=>'zaym' ], ''=> ['get'=> [],'title'=>'','topTextHeader'=>'','type'=>'zaym' ], ] ], [ // 'title'=>'Сумма '.$d['partTitleRp'], 'title'=>'Monto del préstamo', 'type'=>'sum', 'level'=>1, 'parentAlias'=>'', 'pages'=>[ 'pozyczka-100-zl'=> ['get'=> ['field1'=>100],'title'=>'','topTextHeader'=>'','type'=>'zaym' ], 'pozyczka-200-zl'=> ['get'=> ['field1'=>200],'title'=>'','topTextHeader'=>'','type'=>'zaym' ], 'pozyczka-300-zl'=> ['get'=> ['field1'=>300],'title'=>'','topTextHeader'=>'','type'=>'zaym' ], 'pozyczka-400-zl'=> ['get'=> ['field1'=>400],'title'=>'','topTextHeader'=>'','type'=>'zaym' ], 'pozyczka-500-zl'=> ['get'=> ['field1'=>500],'title'=>'','topTextHeader'=>'','type'=>'zaym' ], 'pozyczka-1000-zl'=> ['get'=> ['field1'=>1000],'title'=>'','topTextHeader'=>'','type'=>'zaym' ], 'pozyczka-2000-zl'=> ['get'=> ['field1'=>2000],'title'=>'','topTextHeader'=>'','type'=>'zaym' ], 'pozyczka-3000-zl'=> ['get'=> ['field1'=>3000],'title'=>'','topTextHeader'=>'','type'=>'zaym' ], 'pozyczka-5000-zl'=> ['get'=> ['field1'=>5000],'title'=>'','topTextHeader'=>'','type'=>'zaym' ], 'pozyczka-10000-zl'=> ['get'=> ['field1'=>10000],'title'=>'','topTextHeader'=>'','type'=>'zaym' ], ] ], //[ // 'title'=>'Срок '.$d['partTitleRp'], // 'type'=>'srok', // 'level'=>1, // 'parentAlias'=>'', // 'pages'=>[ // '5-dney'=> ['get'=> ['field2'=>5],'title'=>'5 дней','type'=>'zaym' ], // '7-dney'=> ['get'=> ['field2'=>7],'title'=>'7 дней','type'=>'zaym' ], // '10-dney'=> ['get'=> ['field2'=>10],'title'=>'10 дней','type'=>'zaym' ], // '14-dney'=> ['get'=> ['field2'=>14],'title'=>'14 дней','type'=>'zaym' ], // '21-den'=> ['get'=> ['field2'=>21],'title'=>'21 день','type'=>'zaym' ], // '30-dney'=> ['get'=> ['field2'=>30],'title'=>'30 дней','type'=>'zaym' ], // '1-mes'=> ['get'=> ['field2'=>30],'title'=>'1 месяц','type'=>'zaym' ], // '2-mes'=> ['get'=> ['field2'=>60],'title'=>'2 месяца','type'=>'zaym' ], // '3-mes'=> ['get'=> ['field2'=>90],'title'=>'3 месяца','type'=>'zaym' ], // '6-mes'=> ['get'=> ['field2'=>180],'title'=>'6 месяцев','type'=>'zaym' ], // '1-god'=> ['get'=> ['field2'=>365],'title'=>'1 год','type'=>'zaym' ] // ] // ], // [ // 'title'=>'Возраст заемщика', // 'type'=>'age', // 'level'=>1, // 'parentAlias'=>'', // 'pages'=>[ // '18-let'=> ['get'=> ['field3'=>18],'title'=>'18 лет','type'=>'zaym' ], // '19-let'=> ['get'=> ['field3'=>19],'title'=>'19 лет','type'=>'zaym' ], // '20-let'=> ['get'=> ['field3'=>20],'title'=>'20 лет','type'=>'zaym' ], // '21-god'=> ['get'=> ['field3'=>21],'title'=>'21 год','type'=>'zaym' ], // 'do-75-let'=> ['get'=> ['field3'=>75],'title'=>'до 75 лет','type'=>'zaym' ], // 'do-80-let'=> ['get'=> ['field3'=>80],'title'=>'до 80 лет','type'=>'zaym' ] // ] // ], // [ // 'title'=>'Способ получения', // 'type'=>'poluchenie', // 'level'=>1, // 'parentAlias'=>'', // 'pages'=>[ // 'karta'=> ['get'=> ['field5'=>1],'title'=>'Карта','type'=>'zaym','titleBread'=>'На карту'], // 'nalichnye'=> ['get'=> ['field5'=>2],'title'=>'Наличные','type'=>'zaym' ], // 'bankovskiy-schet'=> ['get'=> ['field5'=>3],'title'=>'Банковский счет','type'=>'zaym'], // 'zolotaya-korona'=> ['get'=> ['field5'=>4],'title'=>'Золотая Корона','type'=>'zaym' ], // 'qiwi'=> ['get'=> ['field5'=>5],'title'=>'QIWI кошелек','type'=>'zaym' ], // 'yandex'=> ['get'=> ['field5'=>6],'title'=>'Яндекс Деньги','type'=>'zaym' ], // ] // ], //[ // 'title'=>'На карту', // 'type'=>'card', // 'level'=>2, // 'parentAlias'=>'karta', // 'pages'=>[ // 'karta/do-zarplaty'=> ['get'=> ['field5'=>1],'title'=>'До зарплаты','type'=>'zaym'], // 'karta/studentam'=> ['get'=> ['field5'=>1],'title'=>'Студентам','type'=>'zaym'], // 'karta/pensioneram'=> ['get'=> ['field5'=>1],'title'=>'Пенсионерам','type'=>'zaym'], // 'karta/bezrabotnym'=> ['get'=> ['field5'=>1],'title'=>'Безработным','type'=>'zaym'], // 'karta/bez-zaloga'=> ['get'=> ['field5'=>1],'title'=>'Без залога','type'=>'zaym'], // 'karta/bez-spravok'=> ['get'=> ['field5'=>1],'title'=>'Без справок','type'=>'zaym'], // 'karta/s-plohoj-kreditnoj-istoriej'=> ['get'=> ['field5'=>1],'title'=>'С плохой кредитной историей','type'=>'zaym'], // 'karta/bez-otkaza'=> ['get'=> ['field5'=>1],'title'=>'Без отказа','type'=>'zaym'], // 'karta/bez-proverok'=> ['get'=> ['field5'=>1],'title'=>'Без проверок','type'=>'zaym'], // 'karta/bez-procentov'=> ['get'=> ['field5'=>1],'title'=>'Без процентов','type'=>'zaym'], // 'karta/pod-nizkij-procent'=> ['get'=> ['field5'=>1],'title'=>'Под низкий процент','type'=>'zaym'], // 'karta/kruglosutochno'=> ['get'=> ['field5'=>1],'title'=>'Круглосуточно','type'=>'zaym'], // 'karta/momentalno'=> ['get'=> ['field5'=>1],'title'=>'Моментально','type'=>'zaym'], // 'karta/srochno'=> ['get'=> ['field5'=>1],'title'=>'Срочно','type'=>'zaym'], // 'karta/18-let'=> ['get'=> ['field5'=>1,'field3'=>18],'title'=>'С 18 лет','type'=>'zaym'], // 'karta/do-75-let'=> ['get'=> ['field5'=>1,'field3'=>75],'title'=>'До 75 лет','type'=>'zaym'], // 'karta/do-80-let'=> ['get'=> ['field5'=>1,'field3'=>80],'title'=>'До 80 лет','type'=>'zaym'] // // ] // ] ]; } static function getMeta($d) { $s = 'SELECT * FROM zaym_meta WHERE cityId = '.(int)$d['cityId'].' AND landing = '.db::q($d['landing']).' AND type = '.db::q($d['type']).' '; $aMeta = db::one($s); if(!$aMeta) { return []; } $aSearch = ['%SITE_NAME%','%year%']; $aReplace = [SITE_NAME,date('Y')]; $aMeta['metaTitle'] = str_replace($aSearch,$aReplace,$aMeta['metaTitle']); $aMeta['metaDescr'] = str_replace($aSearch,$aReplace,$aMeta['metaDescr']); $aMeta['h1'] = str_replace($aSearch,$aReplace,$aMeta['h1']); return $aMeta; } static function getLanding($d) { $s = ' SELECT '; if(isset($d['region'])) { if($d['region']) { $s.= ' zl.landingId, zl.alias, zl.metaTitleReg, zl.metaDescrReg, zl.h1Reg'; } else { $s.= 'zl.* '; } } else { $s.= 'zl.landingId, zl.alias, zl.metaTitle, zl.metaDescr, zl.h1, zl.topText, zl.botText, zl.metaTitleReg, zl.metaDescrReg, zl.h1Reg'; } $s.=' FROM zaym_landings zl WHERE 1 '; if(!empty($d['alias'])) { $s.= ' AND zl.alias = '.db::q($d['alias']).' '; } if(!empty($d['type'])) { $s.= ' AND zl.type = '.db::q($d['type']).' '; } $aMeta = db::one($s); if(!$aMeta) { return []; } $aSearch = ['%SITE_NAME%','%year%']; $aReplace = [SITE_NAME,date('Y')]; $aMeta['metaTitle'] = str_replace($aSearch,$aReplace,$aMeta['metaTitle']); $aMeta['metaDescr'] = str_replace($aSearch,$aReplace,$aMeta['metaDescr']); $aMeta['h1'] = str_replace($aSearch,$aReplace,$aMeta['h1']); $aMeta['metaTitleReg'] = str_replace($aSearch,$aReplace,$aMeta['metaTitleReg']); $aMeta['metaDescrReg'] = str_replace($aSearch,$aReplace,$aMeta['metaDescrReg']); $aMeta['h1Reg'] = str_replace($aSearch,$aReplace,$aMeta['h1Reg']); return $aMeta; } static function getZaym($d) { if(!empty($d['field1'])) { $aField1 = explode('-',$d['field1']); } if(!empty($d['field2'])) { $aField2 = explode('-',$d['field2']); } if(!empty($d['field3'])) { $aField3 = explode('-',$d['field3']); } $s = ' SELECT z.zaymId, z.title, z.alias, z.field0, z.field0_max, z.field0t, z.field1_min, z.field1_max, z.field2_min, z.field2_max, z.field3_min, z.field3_max, z.field4, z.field4t, zc.feature, zc.companyId, zc.company, zc.outLink, zc.rating, zc.short_info, zc.commission_new_client, zc.companyAlias, zc.logo FROM zaym z JOIN zaym_companies zc ON z.companyId = zc.companyId '; if(!empty($d['field5'])) { $s.=' JOIN zaym_fields zf ON (zf.zaymId = z.zaymId AND zf.fieldId = 5 AND zf.value = '.(int)$d['field5'].') '; } if(!empty($d['field6'])) { $s.=' JOIN zaym_fields zf ON (zf.zaymId = z.zaymId AND zf.fieldId = 6 AND zf.value = '.(int)$d['field6'].') '; } $s.= ' WHERE 1 '; if(!empty($aField1)) { if(count($aField1) == 1) { $s.= ' AND field1_min <= '.(int)$aField1[0].' AND field1_max >= '.(int)$aField1[0].' '; } else { $s.= ' AND (((field1_min <= '.(int)$aField1[0].' AND field1_max >= '.(int)$aField1[0].') OR (field1_min <= '.(int)$aField1[1].' AND field1_max >= '.(int)$aField1[1].') OR (field1_min >='.(int)$aField1[0].' AND field1_max <= '.(int)$aField1[1].') ) ) '; } } if(!empty($aField2)) { if(count($aField2) == 1) { $s.= ' AND field2_min <= '.(int)$aField2[0].' AND field2_max >= '.(int)$aField2[0].' '; } else { $s.= ' AND (((field2_min <= '.(int)$aField2[0].' AND field2_max >= '.(int)$aField2[0].') OR (field2_min <= '.(int)$aField2[1].' AND field2_max >= '.(int)$aField2[1].') OR (field2_min >='.(int)$aField2[0].' AND field2_max <= '.(int)$aField2[1].') ) ) '; } } if(!empty($aField3)) { if(count($aField3) == 1) { $s.= ' AND field3_min <= '.(int)$aField3[0].' AND field3_max >= '.(int)$aField3[0].' '; } else { $s.= ' AND (((field3_min <= '.(int)$aField3[0].' AND field3_max >= '.(int)$aField3[0].') OR (field3_min <= '.(int)$aField3[1].' AND field3_max >= '.(int)$aField3[1].') OR (field3_min >='.(int)$aField3[0].' AND field3_max <= '.(int)$aField3[1].') ) ) '; } } if(isset($d['field0'])) { $s.=' AND z.field0 = '.db::q($d['field0']).' '; } if(!empty($d['cityId'])) { $s.=' AND z.companyId IN(SELECT companyId FROM zaym_companies_cities WHERE cityId = '.(int)$d['cityId'].') '; } $s.= ' AND zc.hidden = 0 ORDER BY zc.weight DESC, field0 '; if(!empty($d['limit'])) { $s.= ' LIMIT '.$d['limit'].' '; } $a = db::fa($s); if(!$a) { return false; } $aZaymIds = []; $aFeatures = self::getFeatures(); foreach($a as &$v) { $aZaymIds[] = $v['zaymId']; $v['link'] = self::getLink($v); if(!empty($v['feature'])) { foreach($aFeatures as $kf=>$f) { if($kf == $v['feature']) { $v['featureTitle'] = $f['title']; } } } $v['over'] = 0; if(!empty($aField1[0]) && !empty($aField2[0])) { //p($aField1); // p($aField2); // p($v); $v['over'] = $aField1[0]/100 * $v['field0'] * $aField2[0]; $v['total'] = $aField1[0] + $v['over']; } } // if(isset($_COOKIE['dev1'])) // { // p($a); // } $aFields = db::fa(' SELECT zaymId, fieldId, value FROM zaym_fields WHERE zaymId IN('.join(',',$aZaymIds).') '); $aFieldsSorted = []; if($aFields) { foreach($aFields as $f) { $aFieldsSorted[$f['zaymId']][$f['fieldId']][] = $f['value']; } } if($aFieldsSorted) { foreach($a as &$v2) { if(array_key_exists($v2['zaymId'],$aFieldsSorted)) { $v2['fields'] = $aFieldsSorted[$v2['zaymId']]; } } } return $a; } static function getPopupCompany() { $s = ' SELECT zc.logo, zc.company, zc.outLink, zc.commission_new_client FROM zaym z JOIN zaym_companies zc WHERE zc.popup = 1 ORDER BY RAND() '; $company = db::one($s); if(!$company) { return []; } $company['maxSum'] = db::item('SELECT MAX(field1_max) FROM zaym'); return $company; } static function getFeatures() { return [ 1=> [ 'title'=>'100% online' ], 2=> [ 'title'=>'Natychmiastowe zatwierdzenie' ], 3=> [ 'title'=>'Gwarantowane zatwierdzenie' ], 4=> [ 'title'=>'Szybko i łatwo!' ], 5=> [ 'title'=>'Nowy!' ], 7=> [ 'title'=>'Szybka pożyczka' ], 8=> [ 'title'=>'Szybko' ], ]; } //Способы получения займа static function getField5Types() { return [ 1=>'на карту', 2=>'наличные', 3=>'на счет', 4=>'Золотая Корона', 5=>'QIWI кошелек', 6=>'Яндекс Деньги' ]; } //Способы погашения займа static function getField6Types() { return [ 1=>'Касса24', 2=>'QIWI кошелек', 3=>'платежная карта', 4=>'банковский перевод', 5=>'наличными' ]; } static function getField4tTypes() { return [ 1=>'min', 2=>'час', 3=>'дн' ]; } static function getField0tTypes() { return [ 1=>'za miesiąc', 2=>'za dzień' ]; } static function getCompanies() { $s = ' SELECT companyId, company, outLink, companyAlias, logo FROM zaym_companies ORDER BY weight DESC, company '; $a = db::fa($s); if(!$a) { return false; } foreach($a as &$v) { $v['link'] = self::getCompanyLink(['companyAlias'=>$v['companyAlias']]); } // p($a); return $a; } static function getCompaniesForEdit($d = []) { $order = 'companyId'; $orderType = 'DESC'; if(!empty($d['order'])) { switch($d['order']) { case 'name': $order='company'; $orderType='asc'; break; case 'weight': $order='weight'; break; } } $s = ' SELECT companyId, company, popup, feature, hidden, weight, companyAlias FROM zaym_companies WHERE 1 ORDER BY '.$order.' '.$orderType.' '; return db::fa($s); } static function getZaymForEdit() { return db::fa(' SELECT z.zaymId, z.title, z.alias, zc.company FROM zaym z JOIN zaym_companies zc ON z.companyId = zc.companyId ORDER BY z.zaymId DESC '); } static function getOneCompanyForEdit($companyId) { $a = db::one(' SELECT * FROM zaym_companies WHERE companyId = '.(int)$companyId.' '); if(!$a) { return false; } $aCities = self::getCitiesForCompany($companyId); $a['cities'] = $aCities ? $aCities : []; $a['blocks'] = db::fa(' SELECT * FROM zaym_companies_blocks WHERE companyId = '.(int)$companyId.' ORDER BY weight'); return $a; } static function getCitiesForCompany($companyId) { $s = ' SELECT cityId FROM zaym_companies_cities WHERE companyId = '.(int)$companyId.' '; return db::col($s); } static function getOneCompany($d = []) { $s = ' SELECT * FROM zaym_companies zc WHERE 1 '; if(!empty($d['alias'])) { $s.=' AND zc.companyAlias = '.db::q($d['alias']).' '; } $a = db::one($s); if(empty($a)) { return false; } $a['blocks'] = db::fa(' SELECT * FROM zaym_companies_blocks WHERE companyId = '.(int)$a['companyId'].' ORDER BY weight'); return $a; } static function getOneZaymForEdit($zaymId) { $s = ' SELECT * FROM zaym WHERE zaymId = '.(int)$zaymId.' '; $a = db::one($s); if(!$a) { return false; } $a['field0'] = preg_replace('|\.?0+$|','',$a['field0']); $a['field0_max'] = preg_replace('|\.?0+$|','',$a['field0_max']); $a['field7'] = preg_replace('|\.?0+$|','',$a['field7']); $aFields = db::fa(' SELECT zaymId, fieldId, value FROM zaym_fields WHERE zaymId = '.(int)$zaymId.' '); $a['fields'] = []; if($aFields) { foreach($aFields as $v) { $a['fields'][$v['fieldId']][] = $v['value']; } } return $a; } static function getOneZaym($zaymId) { $s = ' SELECT z.zaymId, z.title, z.metaTitle, z.metaDescr, z.alias, z.companyId, z.field0, z.field0_max, z.field1_min, z.field1_max, z.field2_min, z.field2_max, z.field3_min, z.field3_max, z.field4, z.field4t, z.field7, zc.company, zc.outLink, zc.logo FROM zaym z JOIN zaym_companies zc ON z.companyId = zc.companyId WHERE zaymId = '.(int)$zaymId.' '; $a = db::one($s); if(!$a) { return false; } $aFields = db::fa(' SELECT zaymId, fieldId, value FROM zaym_fields WHERE zaymId = '.(int)$zaymId.' '); $a['fields'] = []; if($aFields) { foreach($aFields as $v) { $a['fields'][$v['fieldId']][] = $v['value']; } } $a['field0'] = preg_replace('|\.?0+$|','',$a['field0']); $a['field0_max'] = preg_replace('|\.?0+$|','',$a['field0_max']); $a['field7'] = preg_replace('|\.?0+$|','',$a['field7']); return $a; } static function getAverageZaym($d = []) { $s = ' SELECT MIN(field0) field0_min, MAX(field0_max) field0_max, MIN(field1_min) field1_min, MAX(field1_max) field1_max, MIN(field2_min) field2_min, MAX(field2_max) field2_max, MIN(field3_min) field3_min, MAX(field3_max) field3_max, MIN(field4t) field4t_min, MAX(field4t) field4t_max, MIN(field7) field7_min, MAX(field7) field7_max FROM zaym WHERE companyId = '.(int)$d['companyId'].' '; $a = db::one($s); $field4_min = db::item('SELECT MIN(field4) FROM zaym WHERE companyId = '.(int)$d['companyId'].' AND field4t = '.(int)$a['field4t_min'].' LIMIT 1'); $field4_max = db::item('SELECT MAX(field4) FROM zaym WHERE companyId = '.(int)$d['companyId'].' AND field4t = '.(int)$a['field4t_max'].' LIMIT 1'); $a4Types = self::getField4tTypes(); if($a['field4t_min'] == $a['field4t_max'] && $field4_min == $field4_max) { $a['field4'] = $field4_min; foreach($a4Types as $k=>$v) { if($a['field4t_min'] == $k) { $a['field4'] .= ' '.$v; } } } else { $a['field4'] = $field4_min; foreach($a4Types as $k=>$v) { if($a['field4t_min'] == $k) { $a['field4'] .= ' '.$v; } } ' - '.$a['field4'] .= $field4_max; foreach($a4Types as $k=>$v) { if($a['field4t_max'] == $k) { $a['field4'] .= ' '.$v; } } } // p($a); $a['field0_min'] = preg_replace('|\.?0+$|','',$a['field0_min']); $a['field0_max'] = preg_replace('|\.?0+$|','',$a['field0_max']); $a['field7_min'] = preg_replace('|\.?0+$|','',$a['field7_min']); $a['field7_max'] = preg_replace('|\.?0+$|','',$a['field7_max']); //минимальный срок рассмотрения $a['field0'] = ($a['field0_min']!=$a['field0_max']) ? $a['field0_min'].' - '.$a['field0_max'] : $a['field0_min']; $a['field7'] = ($a['field7_min']!=$a['field7_max']) ? $a['field7_min'].' - '.$a['field7_max'] : $a['field7_min']; // $a['field1'] = ($a['field1_min']!=$a['field1_max']) ? (float)$a['field1_min'].' - '.(float)$a['field1_max'] : (float)$a['field1_min']; $aFields = db::fa(' SELECT DISTINCT fieldId, value FROM zaym_fields WHERE zaymId IN( SELECT zaymId FROM zaym WHERE companyId = '.(int)$d['companyId'].') '); $a['fields'] = []; if($aFields) { foreach($aFields as $v) { $a['fields'][$v['fieldId']][] = $v['value']; } } return $a; } static function addCompany($d) { $logo = !empty($d['logo']) ? $d['logo'] : ''; $popup = !empty($d['popup']) ? 1 : 0; if(isset($d['files']['logo'])) { if($d['files']['logo']['tmp_name']) { $logo = translit($d['files']['logo']['name'],['include'=>'\.']); move_uploaded_file($d['files']['logo']['tmp_name'], BASEDIR.self::$logoPath.$logo); } } //удаляем старый логотип if($d['companyId']) { $logoOld = db::item(' SELECT logo FROM zaym_companies WHERE companyId = '.(int)$d['companyId'].' '); if($logoOld && $logoOld != $logo) { unlink(BASEDIR.self::$logoPath.$logoOld); } } $img8 = !empty($d['img8']) ? $d['img8'] : ''; if(isset($d['files']['img8'])) { if($d['files']['img8']['tmp_name']) { $aName = explode('.',$d['files']['img8']['name']); $ext = end($aName); $img8 = mt_rand(1000000000,9999999999).'_'.mt_rand(1000000000,9999999999).'.'.$ext; move_uploaded_file($d['files']['img8']['tmp_name'], BASEDIR.self::$logoPath.$img8); } } //удаляем старый логотип if($d['companyId']) { $imgOld = db::item(' SELECT img8 FROM zaym_companies WHERE companyId = '.(int)$d['companyId'].' '); if($imgOld && $imgOld != $img8) { unlink(BASEDIR.self::$logoPath.$imgOld); } } if($d['companyId']) { $s = ' UPDATE '; } else { $s = ' INSERT INTO '; } $s .= ' zaym_companies SET company = '.db::q($d['company']).', popup = '.(int)$popup.', outLink = '.db::q($d['outLink']).', sendOrder = '.db::q($d['sendOrder']).', companyAlias = '.db::q($d['companyAlias']).', feature = '.(int)$d['feature'].', logo = '.db::q($logo).', img8 = '.db::q($img8).', weight = '.db::q($d['weight']).', rating = '.db::q(comma2dot($d['rating'])).', short_info = '.db::q($d['short_info']).', commission_new_client = '.db::q(comma2dot($d['commission_new_client'])).', h1 = '.db::q($d['h1']).', meta_title = '.db::q($d['meta_title']).', meta_descr = '.db::q($d['meta_descr']).', field3 = '.db::q($d['field3'],false).', field5 = '.db::q($d['field5']).', field7t = '.db::q($d['field7t']).', field7 = '.db::q($d['field7'],false).', contact_name = '.db::q($d['contact_name']).', contact_adr = '.db::q($d['contact_adr']).', contact_site = '.db::q($d['contact_site']).', contact_phone = '.db::q($d['contact_phone']).', contact_email = '.db::q($d['contact_email']).', contact_worktime1 = '.db::q($d['contact_worktime1']).', contact_worktime2 = '.db::q($d['contact_worktime2']).' '; if($d['companyId']) { $s .= ' WHERE companyId = '.(int)$d['companyId'].' '; } // p($s,1); db::exec($s); $companyId = $d['companyId'] ? $d['companyId'] : db::item('SELECT LAST_INSERT_ID()'); if($d['companyId']) { db::exec(' DELETE FROM zaym_companies_cities WHERE companyId = '.(int)$companyId.' '); } if(!empty($d['cities'])) { foreach($d['cities'] as $v) { db::exec(' INSERT INTO zaym_companies_cities SET companyId = '.(int)$d['companyId'].', cityId = '.(int)$v.' '); } } db::exec('DELETE FROM zaym_companies_blocks WHERE companyId = '.(int)$companyId.''); if(!empty($d['block5'])) { $i = 0; foreach($d['block5'] as $v) { db::exec(' INSERT INTO zaym_companies_blocks SET companyId = '.(int)$companyId.', block5 = '.db::q($d['block5'][$i],false).', block6 = '.db::q($d['block6'][$i],false).', block7 = '.db::q($d['block7'][$i],false).', weight = '.(int)($i+1).' '); $i++; } } return $companyId; } static function addZaym($d) { // p($d,1); if(empty($d['field0'])) { $d['field0'] = 0; } if(empty($d['field7'])) { $d['field7'] = 0; } if($d['zaymId']) { $s = ' UPDATE '; } else { $s = ' INSERT INTO '; } $s .= ' zaym SET title = '.db::q($d['title']).', metaTitle = '.db::q($d['metaTitle']).', metaDescr = '.db::q($d['metaDescr']).', alias = '.db::q(translit(trimText($d['title'],50))).', companyId = '.(int)$d['companyId'].', field0 = '.db::q(num($d['field0'])).', field0_max = '.db::q(num($d['field0_max'])).', field0t = '.(int)$d['field0t'].', field1_min = '.db::q(num($d['field1_min'])).', field1_max = '.db::q(num($d['field1_max'])).', field2_min = '.(int)$d['field2_min'].', field2_max = '.(int)$d['field2_max'].', field3_min = '.(int)$d['field3_min'].', field3_max = '.(int)$d['field3_max'].', field4 = '.db::q($d['field4']).', field4t = '.(int)$d['field4t'].', field7 = '.db::q(num($d['field7'])).' '; if($d['zaymId']) { $s .= ' WHERE zaymId = '.(int)$d['zaymId'].' '; } // p($s,1); db::exec($s); $zaymId = $d['zaymId'] ? $d['zaymId'] : db::item('SELECT LAST_INSERT_ID()'); db::exec(' DELETE FROM zaym_fields WHERE zaymId = '.(int)$zaymId.' AND fieldId IN(5,6) '); //поля со множественными значениями if(!empty($d['field5'])) { foreach($d['field5'] as $v) { db::exec(' INSERT INTO zaym_fields SET zaymId = '.(int)$zaymId.', fieldId = 5, value = '.(int)$v.' '); } } if(!empty($d['field6'])) { foreach($d['field6'] as $v) { db::exec(' INSERT INTO zaym_fields SET zaymId = '.(int)$zaymId.', fieldId = 6, value = '.(int)$v.' '); } } return $zaymId; } static function deleteCompany($companyId) { db::exec(' DELETE FROM zaym_companies WHERE companyId = '.(int)$companyId.' '); } static function deleteZaym($zaymId) { db::exec(' DELETE FROM zaym WHERE zaymId = '.(int)$zaymId.' '); db::exec(' DELETE FROM zaym_fields WHERE zaymId = '.(int)$zaymId.' '); } static function bottomNavigation($botText) { $navigation = '