<?php
namespace Smi\Controller;

use Think\Controller;

header("Content-Type:text/html;CharSet=UTF-8");
class PriceController extends BaseController
{
	//价格反馈列表
   public function priceList()
   {

   		auth_check("shop_read");
        $l = 10;
        $Model = M(""); 
        //$where = 1;      
         if($_GET['search']){
           $search=I('search'); 
           $whereGoods['C.name|G.goods_name']=$search;
           $result = $Model->table('am_villages_price V')
            ->join('LEFT JOIN am_region_village C ON C.id = V.village_id')
            ->join('LEFT JOIN am_goods G ON G.id = V.good_id')
            ->where($whereGoods)
            ->field('C.id,G.id')
            ->find();                     
           	$where['V.village_id|V.good_id']=array('like',"%{$result['id']}%");         
        }
        
        $count = $Model->table('am_villages_price V')
            ->join('LEFT JOIN am_region_village C ON C.id = V.village_id')
            ->join('LEFT JOIN am_goods G ON G.id = V.good_id')
            ->where($where)
            ->order("G.id desc")
            ->count();
        $Page = new \Think\Page($count, $l);
        $show = $Page->show();// 分页显示输出
        $list = $Model->table('am_villages_price V')
            ->join('LEFT JOIN am_region_village C ON C.id = V.village_id')
            ->join('LEFT JOIN am_goods G ON G.id = V.good_id')
            ->field("V.*,C.name,G.goods_name,G.thumb")
            ->limit($Page->firstRow . ',' . $Page->listRows)
            ->where($where)
            ->order('V.id desc')
            ->select();
            $lists = M('goods_village_set')->select();
            $lens = count($lists);
            $len = count($list);
            for($i=0;$i<$len;++$i){
            	$list[$i]['vil_price'] = 0;
            	for($j=0;$j<$lens;++$j){
            		if($list[$i]['village_id']==$lists[$j]['village_id'] && $list[$i]['good_id'] == $lists[$j]['good_id']){
            			$list[$i]['vil_price'] = $lists[$j]['price'];
            		}
            	}
            }      
        $this->assign('page', $show);// 赋值分页输出
        //定义变量并显示模板
        $this->assign("list", $list);
        $this->display();
   }

}