<?php
/**
 * 活动列表
 * @Copyright (C) 2017 汉潮 All rights reserved.
 * @License http://www.hanchao9999.com
 * @Author chang <13331202938@126.com>
 */
namespace Mobile\Controller;
use Think\Controller;
class DpController extends BaseController {
	//点评详情页
    public function index(){
        $map = $o_map = array();
        $param=I('param.');
        $order_id = $param['order_id'];
        $map['order_id'] = $order_id;
        $field='og.id,og.order_id,og.goods_id,og.goods_name,og.goods_number,og.goods_price,og.goods_attr,g.img,g.dp_count,g.avg_score,g.avg_point';
        $goods_info=M('OrderGoods')->alias('og')->where($map)->field($field)->join('LEFT JOIN __GOODS__ g on og.goods_id=g.id')->select();
        foreach($goods_info as $k=>$v){
	        $goods_attr=unserialize($v['goods_attr']);
	        $goods_info[$k]['goods_attr']=$goods_attr['name'];
	        $goods_info[$k]['avg_point']=$v['avg_point']*100;
        }
        $this->assign('order_id',$order_id);
        $this->assign('list',$goods_info);

        if($order_id){
	        $o_map['id'] = $order_id;
	        $order_info = M('OrderInfo')->where($o_map)->field(true)->find();
	        if($order_info['is_comment'] == 1){
		        $this->error('评论过了！');
	        }
	        $order_goods = M('OrderGoods')->where($map)->getField('goods_id');
	        if($order_info['type'] == 14){
		        $param['type'] = 1;
	        }elseif($order_info['type'] == 11){
		        $param['type'] = 2;
	        }
	        $param['goods_id'] = $order_goods;

        }
        $data=D('Common/LocationDp')->get_dp_cfg($param);
        $this->assign($data);
		
		$this->assign($param);
        $this->assign('tplseo_title','评论详情_'.C('WEB_SITE_TITLE'));
        $this->assign('page_title','商品评论');
        $this->display();
    }
	//添加点评
	public function add_dp(){
	      $param=I("param.");
		  $is_map = array();$is_map['order_id'] =$param['order_id'];
		  $count = M('MemberDpList')->where($is_map)->count();
		  $data = array();
		  if($count){
			  $data['status'] = 0;$data['info'] = '该订单已经评论过了！';
		  }else{
			  $uid = $this->member_info['id'];
			  if($uid){
				  $data['url'] = getjumpurl('JUMP_1');
			  }

			  $dp_og = array();
			  foreach ($param as $key => $value) {
				  foreach ($value as $k => $v) {
					  $dp_og[$k][$key] = $v;
					  $dp_og[$k]['order_id'] = $param['order_id'];
					  $dp_og[$k]['type'] = $param['type'];
				  }
			  }unset($k,$v,$key,$value);
			  if(count($dp_og)>1){
				  foreach ($dp_og as $k => $v) {
					  $data=D('Common/LocationDp')->save_review($uid,$v);
				  }
			  }else{
				  foreach ($dp_og as $key => $value) {
					  $arr = $value;
				  }
				  $data=D('Common/LocationDp')->save_review($uid,$arr);
			  }
			  if($data['status'] == 1){
				  $save['is_comment'] = 1;
				  M('OrderInfo')->where('id = '.$param['order_id'])->save($save);
			  }
		  }
		  $data['url']=U('Mobile/OrderInfo/no_comment');
	      $this->ajaxReturn($data);
	}
	//点评详情
	public function dp_cont(){
		$param=I("param.");
		$map=array();
		if($param['order']==1)$order=' dp_point desc,addtime desc ';
		if($param['order']==2)$order=' dp_point asc,addtime desc ';
		$data=D('Common/LocationDp')->get_dp_cont($param,$map,$order);
		$this->assign($data);
		$ret['head_html']=$this->fetch('header');
		$ret['html']=$this->fetch('list');
		$this->ajaxReturn($ret);
		
	}
	//验证点评权限
	public function check_dp(){
		$param=I('param.');
		$data=D('Common/LocationDp')->check_dp_status($this->member_info['id'],$param);
		if($data['status']==1){
			$data['jumpurl']=U('Dp/index',$param);
		}
		$this->ajaxReturn($data);
	}
}
?>