public function renderDefault() { $currentDate = date('Y-m-d H:i:s'); // povolene akce s aktualnim datem platnosti serazene od nejnovejsi $this->template->sales = $this->sale->where("enable != 0 AND ((start IS NULL AND end IS NULL) OR (start < '{$currentDate}' AND end > '{$currentDate}') OR (start IS NULL AND end > '{$currentDate}') OR (start < '{$currentDate}' AND end IS NULL))")->order('created DESC'); $this->template->goodsRecommended = $this->goods->where('recommended != 0')->order('id DESC')->limit(6); $this->template->text = ""; foreach ($this->article->where(['menu' => self::SALE_PAGE_MENU])->limit(1) as $a) { if (strip_tags($a->text)) { $this->template->text = $a->text; } } }
public function renderDefault() { $this->template->goodsRecommended = $this->goods->where('recommended != 0')->order('id DESC')->limit(12); }
public function renderFilter($categoryId = null, $manufacturerId = null) { $this->template->goodsRecommended = array(); $this->template->goodsOther = array(); $this->template->selectedCategoryId = $categoryId; $this->template->selectedSubcategoryId = $categoryId; $this->template->selectedManufacturerId = $manufacturerId; if ($categoryId && $manufacturerId) { $category = $this->category->createSelectionInstance()->get($categoryId); $manufacturer = $this->manufacturer->get($manufacturerId); if (!$category || !$manufacturer) { $this->flashMessage('Kategorie nebo výrobce nebyl nalezen.', 'warning'); } else { $parentCategory = $category->parent ? $this->category->createSelectionInstance()->get($category->parent) : null; $this->template->filterName = ($parentCategory ? $parentCategory->name . ' - ' : '') . $category->name . " od " . $manufacturer->name; $this->template->og = ['title' => $this->template->filterName . ' - alena.cz', 'description' => strip_tags($category->description)]; $in = $category . ','; $subcategories = $category->related('category.parent'); foreach ($subcategories as $subcategory) { $in .= $subcategory . ','; } $in = rtrim($in, ','); $sql = "SELECT g.id\n\t\t\t\t\t\tFROM category_goods cg\n\t\t\t\t\t\tJOIN goods g ON cg.`goods_id` = g.id\n\t\t\t\t\t\tJOIN category c ON cg.`category_id` = c.id\n\t\t\t\t\t\tWHERE cg.`category_id` IN ({$in}) AND g.`manufacturer_id` = {$manufacturerId} AND g.recommended = "; $this->template->goodsRecommended = $this->good->createSelectionInstance()->where('id', $this->database->getConnection()->query($sql . "1 GROUP BY id")->fetchPairs()); $this->template->goodsOther = $this->good->createSelectionInstance()->where('id', $this->database->getConnection()->query($sql . "0 GROUP BY id")->fetchPairs()); if ($category->parent) { $this->template->selectedCategoryId = $category->parent; $this->template->selectedSubCategoryId = $categoryId; } else { $this->template->selectedCategoryId = $categoryId; } } } elseif ($categoryId) { $category = $this->category->createSelectionInstance()->get($categoryId); if (!$category) { $this->flashMessage('Kategorie nebyla nalezena.', 'warning'); } else { $parentCategory = $category->parent ? $this->category->createSelectionInstance()->get($category->parent) : null; $this->template->filterName = ($parentCategory ? $parentCategory->name . ' - ' : '') . $category->name; $this->template->og = ['title' => $this->template->filterName . ' - alena.cz', 'description' => strip_tags($category->description)]; $in = $category . ','; $subcategories = $category->related('category.parent'); foreach ($subcategories as $subcategory) { $in .= $subcategory . ','; } $in = rtrim($in, ','); $sql = "SELECT g.id\n\t\t\t\t\t\tFROM category_goods cg\n\t\t\t\t\t\tJOIN goods g ON cg.`goods_id` = g.id\n\t\t\t\t\t\tJOIN category c ON cg.`category_id` = c.id\n\t\t\t\t\t\tWHERE cg.`category_id` IN ({$in}) AND g.recommended = "; $this->template->goodsRecommended = $this->good->createSelectionInstance()->where('id', $this->database->getConnection()->query($sql . "1 GROUP BY id")->fetchPairs()); $this->template->goodsOther = $this->good->createSelectionInstance()->where('id', $this->database->getConnection()->query($sql . "0 GROUP BY id")->fetchPairs()); if ($category->parent) { $this->template->selectedCategoryId = $category->parent; $this->template->selectedSubCategoryId = $categoryId; } else { $this->template->selectedCategoryId = $categoryId; } } } elseif ($manufacturerId) { $manufacturer = $this->manufacturer->get($manufacturerId); if (!$manufacturer) { $this->flashMessage('Výrobce nebyl nalezen.', 'warning'); } else { $this->template->filterName = $manufacturer->name; $this->template->goodsRecommended = $this->good->where('manufacturer_id = ? AND recommended != 0', $manufacturerId)->order('id DESC'); $this->template->goodsOther = $this->good->createSelectionInstance()->where('manufacturer_id = ? AND recommended = 0', $manufacturerId)->order('id DESC'); $this->template->selectedManufacturer = $manufacturerId; $this->template->og = ['title' => $this->template->filterName . ' - alena.cz', 'description' => strip_tags($manufacturer->description)]; } } else { $this->redirect("default"); } }
public function index(Request $request) { $start = $request->input('start', 0); $length = $request->input('length', 5); $draw = $request->input('draw', 1); $show_putaway = $request->input('show_putaway', 0); $category_id = $request->input('category_id'); if ($category_id != null) { if ($show_putaway == 0) { $goods = Goods::where('is_putaway', 1); $goods = $goods->where('category_id', $category_id); } else { $goods = Goods::where('category_id', $category_id); } $count = $goods->count(); $goods->skip($start)->take($length)->orderBy('id', 'desc'); } else { if ($show_putaway == 0) { $goods = Goods::where('is_putaway', 1); $count = $goods->count(); $goods = $goods->skip($start)->take($length)->orderBy('id', 'desc'); } else { $goods = Goods::orderBy('goods.id', 'desc'); $keywords = $request->input('key_words'); if ($keywords != null && $keywords != '') { $goods = $goods->where('goods.name', 'like', '%' . $keywords . '%')->orWhere('goods.goods_description', 'like', '%' . $keywords . '%'); } $baoyou = $request->input('baoyou'); if ($baoyou != 0) { $goods = $goods->join('free_post_goods', 'free_post_goods.goods_id', '=', 'goods.id'); } $baopin = $request->input('baopin'); if ($baopin != 0) { $goods = $goods->join('conversion_goods', 'conversion_goods.goods_id', '=', 'goods.id'); } $guanlian = $request->input('guanlian'); if ($guanlian != 0) { $goods = $goods->join('theme_goods', 'theme_goods.goods_id', '=', 'goods.id'); } $fenlei = $request->input('fenlei'); if ($fenlei != -1) { $goods = $goods->join('activity_classification_goods', 'activity_classification_goods.goods_id', '=', 'goods.id')->where('activity_classification_goods.activity_classification_id', '=', $fenlei); } $presell = $request->input('presell'); if ($presell != 0) { $goods = $goods->where('goods.is_presell', '=', 1); } $goods = $goods->select('goods.*'); $count = $goods->count(); $goods = $goods->skip($start)->take($length); } } $goods = $goods->get(); $arrGoodsList = []; foreach ($goods as $g) { $arrGoods['id'] = $g->id; $arrGoods['name'] = $g->name; $arrGoods['price'] = $g->price; $arrGoods['original_price'] = $g->original_price; $arrGoods['use_coupon'] = $g->use_coupon; $arrGoods['coupon_amount'] = $g->coupon_amount; $arrGoods['express_way'] = $g->express_way; $arrGoods['express_fee'] = $g->express_fee; $arrGoods['returned_goods'] = $g->returned_goods; $arrGoods['is_putaway'] = $g->is_putaway; //$arrGoods['express_fee']=$g->express_fee; $arrGoodsList[] = $arrGoods; } echo json_encode(array("draw" => intval($draw), "recordsTotal" => intval($count), "recordsFiltered" => intval($count), "data" => $arrGoodsList)); }
/** * * @SWG\Api( * path="/search", * description="搜索(新20160216)", * @SWG\Operation( * method="GET", summary="获得搜索列表", notes="获得搜索列表", * type="array", * @SWG\ResponseMessage(code=0, message="成功"), * @SWG\Parameter( * name="user_id", * description="用户id", * paramType="query", * required=false, * allowMultiple=false, * type="integer", * defaultValue=-1 * ),@SWG\Parameter( * name="device_token", * description="设备号", * paramType="query", * required=true, * allowMultiple=false, * type="integer" * ),@SWG\Parameter( * name="type", * description="搜索类型,0:商品,1:主题", * paramType="query", * required=false, * allowMultiple=false, * type="integer", * defaultValue=0 * ),@SWG\Parameter( * name="keywords", * description="搜索关键字", * paramType="query", * required=true, * allowMultiple=false, * type="string" * ), * @SWG\Parameter( * name="PageNum", * description="分页开始位置", * paramType="query", * required=false, * allowMultiple=false, * type="integer", * defaultValue=1 * ),@SWG\Parameter( * name="PerPage", * description="取得长度", * paramType="query", * required=false, * allowMultiple=false, * type="integer", * defaultValue=10 * ) * * ) * ) */ public function index(Request $request) { $start = $request->input('PageNum', 0); $length = $request->input('PerPage', 10); $type = $request->input('type', 0); //0--->商品 1--->主题 $keywords = $request->input('keywords', ''); $user_id = $request->input('user_id', -1); $device_token = $request->input('device_token'); $response = new BaseResponse(); $start = ($start - 1) * $length; if ($type == 0) { $goods = Goods::where('name', 'like', '%' . $keywords . '%')->orWhere('goods_description', 'like', '%' . $keywords . '%'); $total = $goods->count(); $goods = $goods->skip($start)->take($length)->orderBy('id', 'desc'); $rows = $goods->get()->toArray(); } else { $themes = Themes::where('title', 'like', '%' . $keywords . '%')->orWhere('subhead', 'like', '%' . $keywords . '%')->orWhere('themes_description', 'like', '%' . $keywords . '%'); $total = $themes->count(); $themes = $themes->skip($start)->take($length)->orderBy('id', 'desc'); $rows = $themes->get()->toArray(); } foreach ($rows as &$v) { $v['has_collection'] = 0; if ($user_id != -1 && $user_id != 0) { $collection = Collection::where('user_id', $user_id)->where('type', $type)->where('id', $v['id'])->first(); if ($collection != null) { $v['has_collection'] = 1; } } } //搜索记录 $searchRecords = new SearchRecords(); $searchRecords->user_id = $user_id; $searchRecords->device_token = $device_token; $searchRecords->keywords = $keywords; $searchRecords->save(); $response->rows = $rows; $response->total = $total; return $response->toJson(); }