示例#1
0
 public function actionIndex()
 {
     $request = Yii::$app->getRequest();
     $id = current($request->get());
     //查询商品数据
     $goods = Goods::findOne($id);
     //查询收藏数量
     $collectNum = Collect::find()->where(['gid' => $id])->count('id');
     //颜色
     $goodsColor = GoodsColor::findAll(['gid' => $id]);
     $waresDir = 'static/uploaded/wares/i' . $id;
     //读取放大镜图片
     $files = scandir($waresDir);
     foreach ($files as $file) {
         if ($file == '.' || $file == '..' || $file == 'thumbnail') {
             continue;
         }
         $waresFilePath[] = $waresDir . '/' . $file;
     }
     $imgextraDir = 'static/uploaded/imgextra/i' . $id;
     //读取介绍图片
     $files = scandir($imgextraDir);
     foreach ($files as $file) {
         if ($file == '.' || $file == '..' || $file == 'thumbnail') {
             continue;
         }
         $imgextraFilePath[] = $imgextraDir . '/' . $file;
     }
     //查询商品评论
     $discuss = Discuss::findAll(['gid' => $id]);
     // 查询出商品库存总数和尺码
     $inventory = GoodsInventory::findAll(['gid' => $id]);
     $num = 0;
     foreach ($inventory as $key => $value) {
         $num += $value['inventory'];
         $size[$value['size']] = $value['size'];
     }
     $data = ['goods' => $goods, 'size' => $size, 'inventory' => $num, 'discuss' => $discuss, 'color' => $goodsColor, 'collectNum' => $collectNum, 'waresFile' => $waresFilePath, 'imgextraFile' => $imgextraFilePath];
     // print_r($goods);exit;
     return $this->render('index', $data);
 }
示例#2
0
 public static function showColor($gid)
 {
     return GoodsColor::findAll(['gid' => $gid]);
 }