Exemplo n.º 1
0
 public function actionShow($id)
 {
     $this->good = $this->goods->get($id);
     if (!$this->good) {
         $this->flashMessage('Výrobek se nepodařilo načíst.', 'danger');
         $this->redirect(':Front:Catalog:default');
     }
     $goodsSimilar = array();
     $goodsSameManufacturer = $this->goods->createSelectionInstance()->where("manufacturer_id = ?", $this->good->manufacturer->id)->order('id DESC')->limit(2);
     $goodCG = $this->good->related('category_goods');
     $goodCategoryIds = array();
     foreach ($goodCG as $cg) {
         $goodCategoryIds[] = $cg->category->id;
     }
     $goodsSimilarCG = $this->categoryGoods->createSelectionInstance()->where('category_id IN ?', $goodCategoryIds);
     foreach ($goodsSimilarCG as $cg) {
         if ($cg->good->id == $this->good->id) {
             continue;
         }
         $goodsSimilar[] = $cg->good;
     }
     foreach ($goodsSameManufacturer as $good) {
         if ($good->id == $this->good->id) {
             continue;
         }
         $goodsSimilar[] = $good;
     }
     $this->goodsSimilar = array_unique($goodsSimilar);
 }
Exemplo n.º 2
0
 /**
  * @param $goodsId
  * @throws Nette\Application\BadRequestException
  * @internal param $id
  */
 public function actionCreate($goodsId)
 {
     $goods = $this->goods->get($goodsId);
     if (!$goods) {
         $this->error('Výrobek, k kterému nahráváte fotografie, nebyl nalezen v databázi.', 404);
     }
     $this->template->goods = $goods;
 }
Exemplo n.º 3
0
 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;
         }
     }
 }
Exemplo n.º 4
0
 public function getGoodsAttribute()
 {
     $goods = Goods::find($this->goods_id);
     if ($goods == null) {
         return '';
     }
     return $goods->toArray();
 }
Exemplo n.º 5
0
 public function getGoodsItemAttribute()
 {
     if ($this->type != 0) {
         return null;
     } else {
         return Goods::find($this->item_id)->toArray();
     }
 }
Exemplo n.º 6
0
 public function actionToggleRecommended($id)
 {
     $item = $this->item->get($id);
     if (!$item) {
         $this->error('Data pod ID ' . $id . ' nebyla nalezena v databázi.', 404);
     }
     $item->update(array('recommended' => !$item->recommended));
     $this->flashMessage('Doporučení výrobku ' . $item->name . " bylo změněno.", 'success');
     $this->redirect('default');
 }
Exemplo n.º 7
0
 public function actionCreate($id)
 {
     if ($good = $this->goods->get($id)) {
         $saleId = $this->sale->insert(['goods_id' => $id, 'enable' => 0, 'color' => '#333333', 'bgcolor' => '#FFFFF8', 'border' => '#FFFF33', 'start' => new \DateTime('now')]);
         $this->flashMessage('Akce k výrobku ' . $good->manufacturer->name . ' ' . $good->name . ' byla vytvořena.', 'success');
         $this->redirect('edit', $saleId);
     } else {
         $this->flashMessage('Vytvoření akce selhalo.', 'danger');
         $this->redirect('default');
     }
 }
Exemplo n.º 8
0
 public function getGoodsAttribute()
 {
     return Goods::find($this->goods_id)->toArray();
 }
Exemplo n.º 9
0
 /**
  *
  * @SWG\Api(
  *   path="/collection/batch_store",
  *   @SWG\Operation(
  *     method="POST", summary="批量添加收藏", notes="批量添加收藏",
  *     @SWG\ResponseMessage(code=0, message="成功"),
  *     @SWG\Parameter(
  *         name="collection_list",
  *         description="提交的收藏信息",
  *         paramType="body",
  *         required=true,
  *         type="newCollectionList"
  *     )
  *   )
  * )
  */
 public function batchStore(Request $request)
 {
     DB::beginTransaction();
     $response = new BaseResponse();
     $content = json_decode($request->getContent(false));
     $itemList = $content->itemList;
     foreach ($itemList as $v) {
         $co = Collection::where('user_id', $v->user_id)->where('type', $v->type)->where('item_id', $v->item_id)->first();
         if ($co == null) {
             if ($v->type == 0) {
                 $item = Goods::find($v->item_id);
             } else {
                 $item = Themes::find($v->item_id);
             }
             if ($item == null) {
                 DB::rollback();
                 return (new BaseResponse(BaseResponse::CODE_ERROR_BUSINESS, '该项不存在'))->toJson();
             }
             $collection = new Collection();
             $collection->user_id = $v->user_id;
             $collection->type = $v->type;
             $collection->item_id = $v->item_id;
             $collection->save();
         }
     }
     DB::commit();
     return $response->toJson();
 }
Exemplo n.º 10
0
 /**
  *
  * @SWG\Api(
  *   path="/wap/goods_detail/{id}",
  *   @SWG\Operation(
  *     method="GET", summary="商品详情wap", notes="商品详情wap",
  *     @SWG\ResponseMessage(code=0, message="成功"),
  *     @SWG\Parameter(
  *         name="id",
  *         description="商品 id",
  *         paramType="path",
  *         required=true,
  *         allowMultiple=false,
  *         type="integer",
  *     )
  *
  *   )
  * )
  */
 public function goodsDetail($id)
 {
     $data['goods'] = Goods::find($id)->toArray();
     //echo $data['goods']['detailed_introduction'];exit;
     return view('wap.goods_detail', $data);
 }
Exemplo n.º 11
0
 public function renderDefault()
 {
     $this->template->goodsRecommended = $this->goods->where('recommended != 0')->order('id DESC')->limit(12);
 }
Exemplo n.º 12
0
 public function update(Request $requests, $id)
 {
     $params = $requests->all();
     $goods = Goods::find($id);
     if ($goods != null) {
         $properties = [];
         foreach ($params as $k => $v) {
             $pos = strpos($k, 'property_');
             if ($pos !== false) {
                 $id = substr($k, strlen('property_'), strlen($k));
                 if (is_numeric($id)) {
                     $properties[$id] = $v;
                     unset($params[$k]);
                 }
             }
         }
         $params['category_id'] = $params['category'];
         unset($params['category']);
         unset($params['_token']);
         $images = $params['images'];
         unset($params['images']);
         unset($params['uploadImages']);
         if ($requests->hasFile('coverImage')) {
             $file = $requests->file('coverImage');
             $fileName = time() . '.' . $file->getClientOriginalExtension();
             $file->move(base_path() . '/public/upload', $fileName);
             $params['cover'] = '/upload/' . $fileName;
         }
         unset($params['coverImage']);
         if ($requests->hasFile('evaluationPersonImage')) {
             $file = $requests->file('evaluationPersonImage');
             $fileName = md5(uniqid()) . '.' . $file->getClientOriginalExtension();
             $file->move(base_path() . '/public/upload', $fileName);
             $params['evaluation_person_image'] = '/upload/' . $fileName;
         }
         unset($params['evaluationPersonImage']);
         $params['goods_description'] = $params['description'];
         unset($params['description']);
         $activityClassification = $params['activityClassification'];
         unset($params['activityClassification']);
         $freePost = $params['freePost'];
         unset($params['freePost']);
         foreach ($params as $n => $p) {
             $goods->{$n} = $p;
         }
         $goods->save();
         ActivityClassificationGoods::where('goods_id', $goods->id)->delete();
         if ($activityClassification != -1) {
             ActivityClassificationGoods::create(['activity_classification_id' => $activityClassification, 'goods_id' => $goods->id]);
         }
         FreePostGoods::where('goods_id', $goods->id)->delete();
         if ($freePost != -1) {
             FreePostGoods::create(['free_posts_id' => $freePost, 'goods_id' => $goods->id]);
         }
         GoodsCategoryProperty::where('goods_id', $goods->id)->delete();
         foreach ($properties as $key => $value) {
             $arr = explode(',', $value);
             foreach ($arr as $i) {
                 GoodsCategoryProperty::create(['category_property_id' => $key, 'goods_id' => $goods->id, 'value' => $i]);
             }
         }
         GoodsImages::where('goods_id', $goods->id)->delete();
         $len = strlen($images);
         if ($len > 0) {
             $images = substr($images, 0, $len - 1);
             $images = explode(',', $images);
             foreach ($images as $i) {
                 $goodsImage = new GoodsImages();
                 $goodsImage->goods_id = $goods->id;
                 $goodsImage->image_id = $i;
                 $goodsImage->save();
             }
         }
     }
     return redirect()->action('Admin\\GoodsController@show');
 }
Exemplo n.º 13
0
 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");
     }
 }
Exemplo n.º 14
0
 /**
  *
  * @SWG\Api(
  *   path="/goods/{id}",
  *   @SWG\Operation(
  *     method="PUT", summary="更新分享次数", notes="更新分享次数",
  *     @SWG\ResponseMessage(code=0, message="成功"),
  *     @SWG\Parameter(
  *         name="id",
  *         description="商品id",
  *         paramType="path",
  *         required=true,
  *         type="string"
  *     )
  *   )
  * )
  */
 public function update(Request $request, $id)
 {
     $response = new BaseResponse();
     $goods = Goods::find($id);
     if ($goods != null) {
         $goods->share_times = $goods->share_times + 1;
         $goods->save();
     }
     return $response->toJson();
 }
Exemplo n.º 15
0
 /**
  *
  * @SWG\Api(
  *   path="/orders/{out_trade_no}",
  *   @SWG\Operation(
  *     method="PUT", summary="更新订单状态", notes="更新订单状态",type="string",
  *     @SWG\ResponseMessage(code=0, message="成功"),
  *     @SWG\Parameter(
  *         name="out_trade_no",
  *         description="订单号",
  *         paramType="path",
  *         required=true,
  *         type="string"
  *     ),
  *     @SWG\Parameter(
  *         name="status",
  *         description="状态 2:取消订单 4:确认收货",
  *         paramType="query",
  *         required=true,
  *         type="string"
  *     )
  *   )
  * )
  */
 public function update(Request $request, $out_trade_no)
 {
     DB::beginTransaction();
     $response = new BaseResponse();
     $status = $request->input('status');
     if ($out_trade_no == null) {
         $response->Code = BaseResponse::CODE_ERROR_CHECK;
         $response->Message = '缺少参数';
         return $response->toJson();
     }
     $order = Order::where('out_trade_no', $out_trade_no)->first();
     if ($order == null) {
         $response->Code = BaseResponse::CODE_ERROR_BUSINESS;
         $response->Message = '未找到对应项目';
         return $response->toJson();
     }
     $order->status = $status;
     $order->save();
     if ($status == 2) {
         $goodsList = OrderGoods::where('order_id', $order->id)->get()->toArray();
         foreach ($goodsList as $g) {
             $goods = Goods::find($g['goods_id']);
             if ($goods == null) {
                 $response->Code = BaseResponse::CODE_ERROR_BUSINESS;
                 $response->Message = "商品不存在";
                 DB::rollback();
                 return $response->toJson();
             }
             $goods->num = $goods->num + $g['num'];
             $goods->save();
             //是否是新用户福利商品
             $homeButtonGoods = HomeButtonGoods::where('goods_id', $goods->id)->first();
             if ($homeButtonGoods != null) {
                 //判断是否购买过
                 $homeButtonGoodsBuyRecords = HomeButtonGoodsBuyRecords::where('home_button_goods_id', $homeButtonGoods->id)->first();
                 if ($homeButtonGoodsBuyRecords != null) {
                     $homeButtonGoodsBuyRecords->delete();
                 }
             }
         }
     }
     DB::commit();
     return $response->toJson();
 }
Exemplo n.º 16
0
 /**
  *
  * @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();
 }