Пример #1
0
 public function index()
 {
     $trialFocus = M("trial_focus");
     $types1 = M("goods_type1");
     $type1 = $types1->field("id,name,logo")->where("display=1 and typebelong=0")->order("weight desc")->select();
     $this->assign("type1", $type1);
     //商品的编号
     $id = $_GET["id"];
     //商品的信息
     $goods = M("goods");
     $result = $goods->where("id={$id}")->select();
     if (!$result) {
         $this->redirect("index/index");
     }
     $this->assign("result", $result);
     if ($result[0]["mall_id"] == 0) {
         //葵花自营
         $system_info = M("system_info");
         $custom_service = $system_info->field("qq,wangwang")->find();
         $this->assign("custom_service", $custom_service);
     } else {
         if ($result[0]["shop_id"] = 0) {
             //商城自营
             $mall_id = $result[0]["mall_id"];
             $mall_info = M("mall");
             $custom_service = $mall_info->where("id={$mall_id}")->field("qq,wangwang")->find();
             $this->assign("custom_service", $custom_service);
         } else {
             //商铺商品
             $shop_id = $result[0]["shop_id"];
             $mall_info = M("shop");
             $custom_service = $mall_info->where("id={$shop_id}")->field("qq,wangwang")->find();
             $this->assign("custom_service", $custom_service);
         }
     }
     //商品的一些可选属性
     for ($i = 1; $i <= 4; $i++) {
         if ($result[0]["extattribute" . $i]) {
             $temp = explode(":", $result[0]["extattribute" . $i]);
             $extattribute[$i]["name"] = $temp[0];
             $extattribute[$i]["value"] = explode(",", $temp[1]);
         }
     }
     $this->assign("extattribute", $extattribute);
     //商品所在的一级分类
     $type1 = $result[0]["type1"];
     $types1 = M("goods_type1");
     $type1_result = $types1->where("id={$type1}")->field("id,name")->select();
     $this->assign("type1_result", $type1_result);
     //商品所在的二级分类
     $type2 = $result[0]["type2"];
     $types2 = M("goods_type2");
     $type2_result = $types2->where("type1_id={$type1}")->field("id,name")->select();
     $current_type2 = $types2->where("id={$type2}")->field("id,name")->select();
     $this->assign("current_type2", $current_type2);
     $this->assign("type2_result", $type2_result);
     //商品所在的三级分类
     $type3 = $result[0]["type3"];
     $types3 = M("goods_type3");
     $type3_result = $types3->where("type1_id={$type1} and type2_id={$type2}")->field("id,name")->select();
     $current_type3 = $types3->where("id={$type3}")->field("id,name")->select();
     $this->assign("current_type3", $current_type3);
     $this->assign("type3_result", $type3_result);
     //商品所在的三级分类销量排行榜
     $type3_sell = $goods->where("type3={$type3}")->field("id,name,image_url,sell,price")->order("sell desc")->limit(5)->select();
     $this->assign("type3_sell", $type3_sell);
     //获取商品的图片
     $goods_pictures = M("goods_pictures");
     $pic_result = $goods_pictures->where("goods_id={$id}")->select();
     $this->assign("photo", $pic_result);
     //获取商品的评价列表
     //by ning
     $CommentModel = new \Home\Model\CommentModel();
     $comment_lists = $CommentModel->search_comments($id, 1);
     //目前这里只针对普通商品
     $pass_comments_info = array();
     $UserModel = new \Home\Model\UserManageModel();
     $BaskModel = new \Home\Model\BaskModel();
     $OrderModel = new \Home\Model\OrderModel();
     //暂时只针对普通商品
     foreach ($comment_lists as $piece) {
         //加入用户名
         $username = $UserModel->get_username($piece["user_id"]);
         $piece["username"] = $username;
         //加入用户晒单的图片
         $img_urls = $BaskModel->search_img($piece["user_id"], $piece["good_id"], $piece["good_type"], $piece["order_time"]);
         $piece["img"] = $img_urls;
         //加入商品的样式
         $good_type_info = $OrderModel->get_good_type_info($piece["user_id"], $piece["good_id"], $piece["order_time"]);
         $piece["good_type_info"] = $good_type_info;
         array_push($pass_comments_info, $piece);
     }
     //print_r($pass_comments_info);
     $this->assign("comments_info", $pass_comments_info);
     $this->display();
 }