Example #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();
 }
 public function add_score()
 {
     $json_raw = file_get_contents("php://input");
     $json_data = json_decode($json_raw);
     $score = $json_data->score;
     $tags = $json_data->tags;
     $content = $json_data->content;
     $img_url = $json_data->img_url;
     $good_type_id = $json_data->good_type_id;
     $good_id = $json_data->good_id;
     $order_time = $json_data->order_time;
     $user_id = $this->check_user();
     //往comment表里面插入数据
     $CommentModel = new \Home\Model\CommentModel();
     $status = $CommentModel->add_comment($good_id, $user_id, $order_time, $tags, $score, $content, $good_type_id);
     if (!$status) {
         echo json_encode(array("status" => "0"));
         return;
     } else {
         //更新订单状态
         switch ($good_type_id) {
             case '1':
                 $tableName = 'orderlist';
                 break;
             case '2':
                 $tableName = 'seckill_orderlist';
                 break;
             case '3':
                 $tableName = 'teambuy_orderlist';
                 break;
             case '4':
                 $tableName = 'trial_orderlist';
                 break;
             case '5':
                 $tableName = 'book_orderlist';
                 break;
             default:
                 return false;
         }
         $tableModel = M($tableName);
         $ordstatus_data["ordstatus"] = 8;
         $status = $tableModel->where("userid={$user_id} and ordtime='{$order_time}' and ordertype={$good_type_id} and productid={$good_id}")->data($ordstatus_data)->save();
         if (!$status) {
             echo json_encode(array("status" => "0"));
             return;
         }
     }
     //更新comment_tags列表
     $CommentTagModel = new \Home\Model\CommentTagModel();
     foreach ($tags as $tag) {
         $status = $CommentTagModel->add_tag($good_id, $good_type_id, $tag);
         if (!$status) {
             echo json_encode(array("status" => "0"));
             return;
         }
     }
     //更新bask_order表
     $BaskModel = new \Home\Model\BaskModel();
     foreach ($img_url as $piece) {
         $status = $BaskModel->add_img($user_id, $good_id, $good_type_id, $piece, $order_time);
         if (!$status) {
             echo json_encode(array("status" => "0"));
             return;
         }
     }
     echo json_encode(array("status" => "1"));
 }
 public function score()
 {
     $id = $this->id;
     $result_array = array();
     $result_array_amend = array();
     //查询各个里面的等待评价的单子
     $orderTableArray = array("orderlist", "seckill_orderlist", "teambuy_orderlist", "trial_orderlist", "book_orderlist");
     foreach ($orderTableArray as $tablePiece) {
         $Model = M($tablePiece);
         $result_array = array_merge($result_array, $Model->where("ordstatus=3 and userid={$id}")->select());
     }
     foreach ($result_array as $piece) {
         switch ($piece["ordertype"]) {
             case '1':
                 $goodPrefix = 'good/index';
                 break;
             case '2':
                 $goodPrefix = 'good/seckill';
                 break;
             case '3':
                 $goodPrefix = 'good/teambuy';
                 break;
             case '4':
                 $goodPreifx = 'good/trial';
                 break;
             case '5':
                 $goodPrefix = 'good/book';
                 break;
             default:
                 return false;
         }
         $piece["goodPrefix"] = $goodPrefix;
         //查询所有的标签
         $CommentTagModel = new \Home\Model\CommentTagModel();
         $tag_array = $CommentTagModel->search_important_tag($piece["productid"], $piece["ordertype"]);
         $piece["tag_array"] = $tag_array;
         array_push($result_array_amend, $piece);
     }
     $this->assign("ordlist_to_score", $result_array_amend);
     //渲染已经评价过的
     $orderTableArray = array("orderlist", "seckill_orderlist", "teambuy_orderlist", "trial_orderlist", "book_orderlist");
     $done_result_array = array();
     $done_array_amend = array();
     foreach ($orderTableArray as $tablePiece) {
         $Model = M($tablePiece);
         $done_result_array = array_merge($done_result_array, $Model->where("ordstatus=6 and userid={$id}")->select());
     }
     $BaskModel = new \Home\Model\BaskModel();
     $CommentModel = new \Home\Model\CommentModel();
     foreach ($done_result_array as $piece) {
         switch ($piece["ordertype"]) {
             case '1':
                 $goodPrefix = 'good/index';
                 break;
             case '2':
                 $goodPrefix = 'good/seckill';
                 break;
             case '3':
                 $goodPrefix = 'good/teambuy';
                 break;
             case '4':
                 $goodPreifx = 'good/trial';
                 break;
             case '5':
                 $goodPrefix = 'good/book';
                 break;
             default:
                 return false;
         }
         $img_urls = $BaskModel->search_img($piece["userid"], $piece["productid"], $piece["ordertype"], $piece["ordtime"]);
         $comment_info = $CommentModel->search_user_comment($piece["userid"], $piece["productid"], $piece["ordertype"], $piece["ordtime"]);
         $piece["comment_info"] = $comment_info;
         $piece["img"] = $img_urls;
         $piece["goodPrefix"] = $goodPrefix;
         array_push($done_array_amend, $piece);
     }
     $this->assign("done_comment", $done_array_amend);
     $this->display();
 }
 public function comment()
 {
     $comment = I("comment");
     $car_type = I("type");
     if (!empty($comment)) {
         if ($_SESSION["name"]) {
             $com = new \Home\Model\CommentModel();
             $res_com = $com->comModel($comment, $car_type);
             if ($res_com > 1) {
                 //返回上一页
                 $this->success('感谢你的评价', 'javascript:history.go(-1)');
             } else {
                 $this->error('评价失败', 'javascript:history.go(-1)');
             }
         } else {
             $this->redirect("/Home/user/login");
         }
     } else {
         $this->error('请输入评价信息', 'javascript:history.go(-1)');
     }
 }