Example #1
0
 public function init()
 {
     header("Content-type: text/html; charset=" . $this->encoding);
     $this->model = new Model();
     $this->safebox = Safebox::getInstance();
     $this->user = $this->safebox->get('user');
     if ($this->user == null) {
         $this->user = Common::autoLoginUserInfo();
         $this->safebox->set('user', $this->user);
     }
     $category = Category::getInstance();
     $this->category = $category->getCategory();
     $cart = Cart::getCart();
     $action = Req::args("act");
     switch ($action) {
         case 'order_detail':
             $action = 'order';
             break;
         case 'refund_detail':
             $action = 'refund';
             break;
     }
     $this->assign("actionId", $action);
     $this->assign("cart", $cart->all());
     $this->assign("cart_num", $cart->getNum());
     $this->assign("sidebar", $this->sidebar);
     $this->assign("category", $this->category);
     $this->assign("seo_title", "用户中心");
 }
 public function relatedCategoriesQuery()
 {
     $categories = Category::getInstance();
     $res = $categories->getRelatedCategories($_GET['id_category']);
     while ($row = PDOQuery::getInstance()->next_row($res)) {
         $query .= $row['id_children_category'] . ',';
     }
     return rtrim($query, ",");
 }
 public function setCategoriesInSmarty()
 {
     $product = Category::getInstance();
     $res = $product->getCategories();
     while ($row = PDOQuery::getInstance()->next_row($res)) {
         $this->smarty_categories[] = array('id_category' => $row['id_category'], 'category_name' => $row['category_name'], 'color' => $row['color']);
     }
     $this->context->smarty->assign("categoryList", $this->smarty_categories);
 }
 public function setSmarty()
 {
     $this->context->smarty->assign('category_name', strtoupper(Category::getInstance()->getCategoryName()));
     $this->context->smarty->assign("page_title", "Sale cancellation");
     $this->addJS(array('Product.js', 'Validator.js'));
     if ($this->hasChildrenCategories(intval($_GET['id_category']))) {
         $this->context->smarty->assign('hasChildrenCategories', 'true');
     }
     $this->context->smarty->display("product_cancellation.tpl");
 }
Example #5
0
 public function init()
 {
     header("Content-type: text/html; charset=" . $this->encoding);
     $this->model = new Model();
     $this->safebox = Safebox::getInstance();
     $this->user = $this->safebox->get('user');
     $category = Category::getInstance();
     $this->category = $category->getCategory();
     $cart = Cart::getCart();
     $this->assign("cart_num", $cart->getNum());
     $this->assign("cart", $cart->all());
     $this->assign("category", $this->category);
 }
Example #6
0
 /**
  * Defines the process for adding a new row.
  */
 protected function addRow()
 {
     $name = \Faker\Lorem::word();
     $fields = array('CategoryID' => Category::getInstance()->getRandomId(), 'InsertUserID' => User::getInstance()->getRandomId(), 'Name' => \Faker\Lorem::sentence(), 'Body' => \Faker\Lorem::paragraph());
     $this->prepareAndInsert($fields);
 }
Example #7
0
 private function parseCondition()
 {
     $page = intval(Req::args("p"));
     $page_size = 36;
     $sort = Filter::int(Req::args("sort"));
     $sort = $sort == null ? 0 : $sort;
     $cid = Filter::int(Req::args("cid"));
     $cid = $cid == null ? 0 : $cid;
     $brand = Filter::int(Req::args("brand"));
     $price = Req::args("price");
     //下面已进行拆分过滤
     $keyword = urldecode(Req::args('keyword'));
     $keyword = Filter::text($keyword);
     $keyword = Filter::commonChar($keyword);
     //初始化数据
     $attrs = $specs = $spec_attr = $category_child = $spec_attr_selected = $selected = $has_category = $category = $current_category = array();
     $where = $spec_attr_where = $url = "";
     $condition_num = 0;
     $model = $this->model;
     //基本条件的建立
     //关于搜索的处理
     $action = strtolower(Req::args("act"));
     if ($action == 'search') {
         // xuzhongyi
         $seo_title = "分类检索";
         $seo_keywords = "全部分类";
         $seo_description = "所有分类商品";
         //取得商品的子分类
         $category_ids = "";
         $categ = Category::getInstance();
         //set:$cid = 5;
         if ($cid == 0) {
             $category_child = $categ->getCategoryChild(0, 1);
         } else {
             $current_category = $this->model->table("goods_category as gc")->fields("gc.*,gt.name as gname,gt.attr,gt.spec,gc.seo_title,gc.seo_keywords,gc.seo_description")->join("left join goods_type as gt on gc.type_id = gt.id")->where("gc.id = {$cid}")->find();
             if ($current_category) {
                 $path = trim($current_category['path'], ',');
                 $rows = $this->model->table("goods_category")->where("path like '{$current_category['path']}%'")->order("field(`id`,{$path})")->findAll();
                 $category = $this->model->table("goods_category")->where("id in ({$path})")->order("field(`id`,{$path})")->findAll();
                 foreach ($rows as $row) {
                     $category_ids .= $row['id'] . ',';
                 }
                 $category_ids = trim($category_ids, ",");
                 $category_child = $categ->getCategoryChild($path, 1);
                 $attrs = unserialize($current_category['attr']);
                 $specs = unserialize($current_category['spec']);
                 $attrs = is_array($attrs) ? $attrs : array();
                 $specs = is_array($specs) ? $specs : array();
             }
         }
         $seo_category = $model->table('goods_category')->where("id={$cid}")->find();
         if ($seo_category) {
             if ($seo_category['seo_title'] != '') {
                 $seo_title = $seo_category['seo_title'];
             } else {
                 $seo_title = $seo_category['name'];
             }
             if ($seo_category['seo_keywords'] != '') {
                 $seo_keywords = $seo_category['name'] . ',' . $seo_category['seo_keywords'];
             } else {
                 $seo_keywords = $seo_category['name'];
             }
             if ($seo_category['seo_description'] != '') {
                 $seo_description = $seo_category['seo_description'];
             } else {
                 $seo_description = $seo_category['name'];
             }
         }
         if ($category_ids != "") {
             $where = "go.category_id in ({$category_ids})";
         } else {
             $where = "1=1";
         }
         //关于类型的处理
         ////提取商品下的类型
         $seo_title = $seo_keywords = $keyword;
         $where = "name like '%{$keyword}%'";
         $rows = $model->table("goods")->fields("category_id,count(id) as num")->where($where)->group("category_id")->findAll();
         $category_ids = "";
         $category_count = array();
         foreach ($rows as $row) {
             $category_ids .= $row['category_id'] . ',';
             $category_count[$row['category_id']] = $row['num'];
         }
         $category_ids = trim($category_ids, ",");
         $has_category = array();
         $seo_description = '';
         if ($category_ids) {
             //搜索到内容且真正的点击搜索时进行统计
             if ($this->getModule()->checkToken()) {
                 $keyword = urldecode(Req::args('keyword'));
                 $keyword = Filter::sql($keyword);
                 $keyword = trim($keyword);
                 $len = String::strlen($keyword);
                 if ($len >= 2 && $len <= 8) {
                     $model = new Model("tags");
                     $obj = $model->where("name='{$keyword}'")->find();
                     if ($obj) {
                         $model->data(array('num' => "`num`+1"))->where("id=" . $obj['id'])->update();
                     } else {
                         $model->data(array('name' => $keyword))->insert();
                     }
                 }
             }
             $rows = $model->table("goods_category")->where("id in ({$category_ids})")->findAll();
             foreach ($rows as $row) {
                 $path = trim($row['path'], ',');
                 $paths = explode(',', $path);
                 $root = 0;
                 if (is_array($paths)) {
                     $root = $paths[0];
                 }
                 $row['num'] = $category_count[$row['id']];
                 $has_category[$root][] = $row;
                 $seo_description .= $row['name'] . ',';
             }
         }
         if ($cid != 0) {
             $where = "category_id={$cid} and name like '%{$keyword}%'";
             $category = $model->table("goods_category as gc ")->join("left join goods_type as gt on gc.type_id = gt.id")->where("gc.id={$cid}")->find();
             if ($category) {
                 $attrs = unserialize($category['attr']);
                 $specs = unserialize($category['spec']);
                 if ($category['seo_title'] != '') {
                     $seo_title = $category['seo_title'];
                 } else {
                     $seo_title = $category['name'];
                 }
                 if ($category['seo_keywords'] != '') {
                     $seo_keywords = $category['seo_keywords'];
                 }
                 if ($category['seo_description'] != '') {
                     $seo_description = $category['seo_description'];
                 }
             }
         }
         //关于分类检索的处理
     } else {
         if ($action == 'category') {
             $seo_title = "分类检索";
             $seo_keywords = "全部分类";
             $seo_description = "所有分类商品";
             //取得商品的子分类
             $category_ids = "";
             $categ = Category::getInstance();
             if ($cid == 0) {
                 $category_child = $categ->getCategoryChild(0, 1);
             } else {
                 $current_category = $this->model->table("goods_category as gc")->fields("gc.*,gt.name as gname,gt.attr,gt.spec,gc.seo_title,gc.seo_keywords,gc.seo_description")->join("left join goods_type as gt on gc.type_id = gt.id")->where("gc.id = {$cid}")->find();
                 if ($current_category) {
                     $path = trim($current_category['path'], ',');
                     $rows = $this->model->table("goods_category")->where("path like '{$current_category['path']}%'")->order("field(`id`,{$path})")->findAll();
                     $category = $this->model->table("goods_category")->where("id in ({$path})")->order("field(`id`,{$path})")->findAll();
                     foreach ($rows as $row) {
                         $category_ids .= $row['id'] . ',';
                     }
                     $category_ids = trim($category_ids, ",");
                     $category_child = $categ->getCategoryChild($path, 1);
                     $attrs = unserialize($current_category['attr']);
                     $specs = unserialize($current_category['spec']);
                     $attrs = is_array($attrs) ? $attrs : array();
                     $specs = is_array($specs) ? $specs : array();
                 }
             }
             $seo_category = $model->table('goods_category')->where("id={$cid}")->find();
             if ($seo_category) {
                 if ($seo_category['seo_title'] != '') {
                     $seo_title = $seo_category['seo_title'];
                 } else {
                     $seo_title = $seo_category['name'];
                 }
                 if ($seo_category['seo_keywords'] != '') {
                     $seo_keywords = $seo_category['name'] . ',' . $seo_category['seo_keywords'];
                 } else {
                     $seo_keywords = $seo_category['name'];
                 }
                 if ($seo_category['seo_description'] != '') {
                     $seo_description = $seo_category['seo_description'];
                 } else {
                     $seo_description = $seo_category['name'];
                 }
             }
             if ($category_ids != "") {
                 $where = "go.category_id in ({$category_ids})";
             } else {
                 $where = "1=1";
             }
         }
     }
     //品牌筛选
     $rows = $model->table("goods as go")->fields("brand_id,count(id) as num")->where($where)->group("brand_id")->findAll();
     $brand_ids = '';
     $brand_num = $has_brand = array();
     foreach ($rows as $row) {
         $brand_ids .= $row['brand_id'] . ',';
         $brand_num[$row['brand_id']] = $row['num'];
     }
     $brand_ids = trim($brand_ids, ',');
     //价格区间
     $prices = $model->table("goods as go")->fields("max(sell_price) as max,min(sell_price) as min,avg(sell_price) as avg")->where($where)->find();
     $price_range = Common::priceRange($prices);
     if ($brand_ids) {
         $has_brand = $model->table("brand")->where("id in ({$brand_ids})")->findAll();
     }
     //var_dump($price_range);exit();
     if (!empty($price_range)) {
         $has_price = array_flip($price_range);
     } else {
         $has_price = array();
     }
     if ($price && isset($has_price[$price])) {
         $prices = explode('-', $price);
         if (count($prices) == 2) {
             $where .= " and sell_price>=" . Filter::int($prices[0]) . " and sell_price <=" . Filter::int($prices[1]);
         } else {
             $where .= " and sell_price>=" . Filter::int($prices[0]);
         }
         $url .= "/price/{$price}";
     }
     if ($brand && isset($brand_num[$brand])) {
         $url .= "/brand/{$brand}";
         $where .= " and brand_id = {$brand} ";
     }
     //规格与属性的处理
     if ($attrs != null) {
         foreach ($attrs as $attr) {
             if ($attr['show_type'] == 1) {
                 $spec_attr[$attr['id']] = $attr;
             }
         }
     }
     if ($specs != null) {
         foreach ($specs as $spec) {
             $spec['values'] = unserialize($spec['value']);
             unset($spec['value'], $spec['spec']);
             $spec_attr[$spec['id']] = $spec;
         }
     }
     foreach ($selected as $key => $value) {
         if (isset($spec_attr[$key])) {
             $spec_attr_selected[$key] = $spec_attr[$key];
             foreach ($spec_attr_selected[$key]['values'] as $k => $v) {
                 if ($value == $v['id']) {
                     $spec_attr_selected[$key]['values'] = $v;
                     break;
                 }
             }
         }
     }
     //规格处属性的筛选
     $args = Req::args();
     unset($args['con'], $args['act'], $args['p'], $args['sort'], $args['brand'], $args['price']);
     foreach ($args as $key => $value) {
         if (is_numeric($key) && is_numeric($value)) {
             if (isset($spec_attr[$key])) {
                 $spec_attr_where .= "or (`key`={$key} and `value` = {$value}) ";
                 $condition_num++;
                 $url .= '/' . $key . '/' . $value;
             }
         }
         $selected[$key] = $value;
     }
     $selected['price'] = $price;
     $selected['brand'] = $brand;
     $spec_attr_where = trim($spec_attr_where, "or");
     $where .= ' and go.is_online =0';
     if ($condition_num > 0) {
         $where .= " and go.id in (select goods_id from tiny_spec_attr where {$spec_attr_where} group by goods_id having count(goods_id) >= {$condition_num})";
     }
     //排序的处理
     switch ($sort) {
         case '1':
             $goods_model = $model->table("goods as go")->join("left join tiny_order_goods as og on go.id = og.goods_id")->fields("go.*,sum(og.goods_nums) as sell_num")->order("sell_num desc")->group("go.id");
             break;
         case '2':
             $goods_model = $model->table("goods as go")->join("left join tiny_review as re on go.id = re.goods_id")->fields("go.*,count(re.goods_id) as renum")->group("go.id")->order("renum desc");
             break;
         case '3':
             $goods_model = $model->table("goods as go")->order("sell_price desc");
             break;
         case '4':
             $goods_model = $model->table("goods as go")->order("sell_price");
             break;
         case '5':
             $goods_model = $model->table("goods as go")->order("id desc");
             break;
         default:
             $goods_model = $model->table("goods as go")->order("sort desc");
             break;
     }
     //var_dump($where);exit;
     //提取商品
     $goods = $goods_model->where($where)->findPage($page, $page_size);
     //品牌处理
     preg_match_all('!(<(a|span)[^>]+>(上一页|下一页)</\\2>)!', $goods['html'], $matches);
     $topPageBar = "";
     if (count($matches[0]) > 0) {
         $topPageBar = implode("", $matches[0]);
     }
     $this->assign("topPageBar", $topPageBar);
     //赋值处理
     $this->assign('seo_title', $seo_title);
     $this->assign('seo_keywords', $seo_keywords);
     $this->assign('seo_description', '对应的商品共有' . $goods['page']['total'] . '件商品,包括以下分类:' . $seo_description);
     $this->assign("keyword", $keyword);
     $this->assign("sort", $sort);
     $this->assign("has_brand", $has_brand);
     $this->assign("brand_num", $brand_num);
     $this->assign("current_category", $current_category);
     $this->assign("goods", $goods);
     $this->assign("selected", $selected);
     $this->assign("spec_attr", $spec_attr);
     $this->assign("spec_attr_selected", $spec_attr_selected);
     $this->assign("category_child", $category_child);
     $this->assign("price_range", $price_range);
     $this->assign("category_nav", $category);
     $this->assign("has_category", $has_category);
     if ($action == 'search') {
         $this->assign("url", "/index/search/keyword/" . $keyword . "/cid/{$cid}/sort/{$sort}" . $url);
     } else {
         $this->assign("url", "/index/category/cid/" . $cid . "/sort/{$sort}" . $url);
     }
     $this->redirect();
 }