Пример #1
0
    public function getList()
    {
        $start = microtime(true);
        $data = array('list' => array(), 'categories' => array());
        $parentIds = array();
        $sql = '
			SELECT DISTINCT {{catalog}}.*, {{tree}}.* FROM {{catalog}}
			INNER JOIN {{tree}} ON {{catalog}}.tree={{tree}}.id
			WHERE {{catalog}}.market=1 AND {{catalog}}.price>0 AND {{tree}}.visible=1 AND available=1
			ORDER BY num
		';
        //print DB::prefix($sql);
        $catalog = DB::getPagi($sql);
        $fields = Fields::getReserveFieldsByModulePath($tab);
        $k = 1;
        $date_b = explode('.', Funcs::$conf['akcia']['date_begin']);
        $date_e = explode('.', Funcs::$conf['akcia']['date_end']);
        $date_b = mktime(0, 0, 0, $date_b[1], $date_b[0], $date_b[2]);
        $date_e = mktime(23, 59, 59, $date_e[1], $date_e[0], $date_e[2]);
        $today = mktime();
        $yes = 0;
        if ($today >= $date_b && $today <= $date_e) {
            $yes = 1;
        }
        foreach ($catalog as $i => $model) {
            $akcia = '0';
            //if ($yes==1)
            //$akcia=$model['akcia'];
            $data['list'][] = array('id' => $model['id'], 'parent' => $model['parent'], 'fields' => Fields::getFieldsByTree($model['tree'], 'wide'), 'name' => Market::clearInfo($model['name']), 'path' => Catalog::getPathToTree($model['tree']), 'available' => $model['available'], 'bid' => $model['bid'], 'akcia' => $akcia, 'cbid' => $model['cbid'], 'typePrefix' => $model['typePrefix'], 'vendor' => Funcs::$referenceId['vendor'][$model['vendor']]['name'], 'yandex_description' => Market::clearInfo($model['yandex_description']), 'price' => $model['price'], 'local_delivery_cost' => $model['price'] < 4000 ? '200' : '0', 'manufacturer_warranty' => $model['manufacturer_warranty']);
            $parentIds[] = $model['parent'];
            $k++;
            //echo $k.' Время выполнения скрипта '.(microtime(true) - $start).'<br />';
        }
        $parentIds = array_unique($parentIds);
        if (count($parentIds) > 0) {
            $sql = '
				SELECT * FROM {{tree}} WHERE id IN (' . implode(',', $parentIds) . ')
			';
            $list = DB::getAll($sql);
            $parentIds = array();
            foreach ($list as $item) {
                $data['categories'][] = array('id' => $item['id'], 'parent' => $item['parent'], 'name' => $item['name']);
                $parentIds[] = $item['parent'];
            }
            if (count($parentIds) > 0) {
                $sql = '
					SELECT * FROM {{tree}} WHERE id IN (' . implode(',', $parentIds) . ')
				';
                $list = DB::getAll($sql);
                foreach ($list as $item) {
                    $data['categories'][] = array('id' => $item['id'], 'name' => $item['name']);
                }
            }
        }
        return $data;
    }
Пример #2
0
    public function getOne($id)
    {
        //die($id);
        if (!Cache::get('model' . $id)) {
            $fields = Fields::getReserveFieldsByModulePath('catalog');
            $sql = '
				SELECT {{catalog}}.*, {{tree}}.* FROM {{catalog}} 
				INNER JOIN {{tree}} ON {{catalog}}.tree={{tree}}.id
				WHERE {{tree}}.id =' . $id . '
			';
            $model = DB::getRow($sql);
            if ($model) {
                foreach ($fields as $key => $item) {
                    if (in_array($item['path'], OneSSA::$catalogStandart)) {
                        $temp[$item['path']] = $model[$item['path']];
                    }
                }
                $return = $temp;
                $return['id'] = $id;
                $parentpath = Tree::getPathToTree($model['parent']);
                $return['path'] = $parentpath . $id . '/';
                $return['tree'] = $id;
                $return['name'] = $model['name'];
                $return['parent'] = $model['parent'];
                $return['rating'] = $model['rating'];
                $return['report'] = Catalog::getCountReport($id);
                $return['sale'] = $item['price'] - $item['supprice'];
                $fields = Fields::getFieldsByTree($id, 'wide');
                $return['pics'] = $fields['files_gal']['image'];
                /*$date_b=explode('.', Funcs::$conf['akcia']['date_begin']);
                		$date_e=explode('.', Funcs::$conf['akcia']['date_end']);
                		$date_b=mktime(0,0,0,$date_b[1], $date_b[0],$date_b[2]);
                		$date_e=mktime(23,59,59,$date_e[1], $date_e[0],$date_e[2]);
                		$today=mktime();
                		$yes=0;
                		if (($today>=$date_b)&&($today<=$date_e))
                		$yes=1;
                		$akcia='0';
                		if ($yes==1)
                		$akcia=$model['akcia'];*/
                $return['akcia'] = $akcia;
                $return['files'] = $fields['files_gal']['application'];
                $multi = Fields::getMultiFields($id);
                if (count($multi['tv']) > 0) {
                    $return['descr1'] = 'Телевидение';
                    $return['descr2'] = Funcs::$referenceId['tv'][$multi['tv'][0]]['name'];
                }
                unset($fields['files_gal']);
                unset($fields['gal']);
                $return['additional'] = Catalog::getAdditionalFieldsArray($fields);
                Cache::set('model' . $id, $return);
                return $return;
            }
        } else {
            return Cache::get('model' . $id);
        }
    }