public function getIndexProductListByCat($cat_id) { $category_service = \Yii::createObject('categoryservice'); $cat_list = $category_service->getChildrenCat($cat_id); $product_list = Product::getInstance()->getIndexProductList($cat_list); $product_id_list = []; $image_id_list = []; foreach ($product_list as $product) { $product_id_list[] = $product['product_id']; $image_id_list[] = $product['image_default_id']; } //获取商品图片 $image_list = Images::getInstance()->getDefaultImages($image_id_list); $middle_img_list = []; if ($image_list) { foreach ($image_list as $value) { $middle_img_list[$value->image_id] = $value->middle_url; } } foreach ($product_list as $k => $product) { if (array_key_exists($product['image_default_id'], $middle_img_list)) { $product_list[$k]['img'] = Yii::$app->params['img_url'] . $middle_img_list[$product['image_default_id']]; } else { $product_list[$k]['img'] = ''; } } //获取商品库存 $client = new \GuzzleHttp\Client(); //$res = $client->get('http://www.pzfresh.com'); return $product_list; }
public function allListProduct() { $list_products = Product::getInstance()->getAlls(); if (count($list_products) > 0) { foreach ($list_products as &$product) { $id = $product->id; $sql_product = 'SELECT * FROM order_custome WHERE key_r_order = ' . $id . ' ORDER BY price_order DESC LIMIT 6'; $order_products = app('db')->select($sql_product); $product->order_price = $order_products; } } return view('product', array('list_products' => $list_products)); }