<?php
// +----------------------------------------------------------------------
// | WindSNS 国内领先企业级社交开源SNS框架系统
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2028 http://windsns.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 常州微诺信息科技有限公司 http://www.weinuo.net
// +----------------------------------------------------------------------
// | E-mail: open@weinuo.net
// +----------------------------------------------------------------------
namespace app\index\controller;
use app\common\controller\Frontend;
use think\Config;
use think\Hook;
use think\Db;
use think\Request;

class Goodshop extends Frontend
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = '';
	/**
	 * 协议
	 * @author   Devil
	 * @blog     http://www.weinuo.net
	 * @version  0.0.1
	 * @datetime 2020-03-03
	 */
    public function index()  //好店首页
    {
        $this->view->assign('title', __('好店'));
        $windsns_goodshopsinfos = Db::name('goodshop') -> alias('a') -> join('ws_goodshoptype w','a.shop_fenleiid = w.shoptypeid') -> join('ws_goodshopregion c','a.shop_diquid = c.shopdiquid') -> join('ws_user e','a.shop_uid = e.id') ->
        where(['shop_opentype' => 2]) -> order('shopid', 'desc')->paginate(20);
		$page = $windsns_goodshopsinfos->render();
		$this->assign('windsns_goodshopsinfos', $windsns_goodshopsinfos);
		$this->assign('page', $page);
		
	
        return $this->view->fetch('windsns_goodshop');
      

    }




    public function windsnsshop()
    {
    	$getwindsnsshop =  input('get.wsshopid'); 
    	$this->assign('getwindsnsshop', $getwindsnsshop);
    	$sqinfosid = Db::name('goodshop')->where(['shopid'=>$getwindsnsshop])->find();
    	$windsnsshopnames =  $sqinfosid['shop_names'];
    	$this->assign('windsnsshopnames', $windsnsshopnames);
    	$sqlliulan = Db::name('goodshop')->where('shopid',$getwindsnsshop)->setInc('shop_sumliulan', 1);
    	$windsnsshopinfos = Db::name('goodshop') -> where(['shopid'=>$getwindsnsshop]) -> select();
    	$this->assign('windsnsshopinfos', $windsnsshopinfos);
        $goodshopcommentlist = Db::name('goodshopcomment')->alias('a')->join('ws_user w','a.shopcomment_uid = w.id')-> where(['shopcommentdel'=>1,'shopcomment_shopid'=>$getwindsnsshop])-> order('shopcommentid', 'desc') -> paginate(10,false,['query' => request()->param()]);; //评论列表
        $page = $goodshopcommentlist->render();
    	$this->assign('goodshopcommentlist', $goodshopcommentlist);
        $this->assign('page', $page);
        $windsns_pinglunsum = Db::name('goodshopcomment')->where(['shopcomment_shopid' => $getwindsnsshop,'shopcommentdel' => 1])->count();
  	    $this->assign('windsns_pinglunsum', $windsns_pinglunsum);
        
        $sqlshop= Db::name('goodshop')->where(['shopid'=>$getwindsnsshop,'shop_opentype'=>2])->find();
        if(!$sqinfosid){
			    return $this->view->fetch('windsns_goodshopnull');
			}elseif(!$sqlshop){
				return $this->view->fetch('windsns_goodshopnulla');
			}else{
				$this->view->assign('title', __($windsnsshopnames.'-'.'好店'));
				return $this->view->fetch('windsns_goodshopinfos');
			}

    }
    
	/**
	 * 协议
	 * @author   Devil
	 * @blog     http://www.weinuo.net
	 * @version  0.0.1
	 * @datetime 2020-03-03
	 */

}
