<?php

namespace app\admin\controller;
use think\Controller;
use think\Db;
use think\Request;
use app\common\controller\Backend;
use fast\Tree;

// +----------------------------------------------------------------------
// | WindSNS 国内领先企业级社交开源SNS框架系统
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2020 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
// +----------------------------------------------------------------------
class Windsnsgoodshop extends Backend
{

  //好店分类列表页面
    public function windsnsgoodshop_list()
    {
        $windsns_goodshoptypeinfos = Db::name('goodshoptype')->order('shoptypeid', 'desc')->paginate(20); //店铺分类列表
		$page = $windsns_goodshoptypeinfos->render();
		$this->assign('windsns_goodshoptypeinfos', $windsns_goodshoptypeinfos);
		$this->assign('page', $page);
        return $this->view->fetch('windsns_index');
    }

   
   //店铺分类添加
    public function windsnsshoptype_add()
    {
        $time = time();
		$paytimess = date('Y-m-d H:i:s',$time);
	    $thistimes = strtotime($paytimess);//获取当前时间
	    $wsshoptypenames = $this->request->request('shoptypenames');
	    $windsns_shoptypeadd['shoptypenames'] =  input('post.shoptypenames'); // 店铺分类名称
	    $thisshopname = input('post.shoptypenames'); // 获取应用标题
	    $windsns_shoptypeadd['shoptypeopenid'] =  input('post.shoptypeopenid'); // 开启状态：1正常2关闭隐藏
	    $windsns_shoptypeadd['shoptypeaddtime'] =  $thistimes;  // 获取添加时间	 
        $sqllittle  = Db::name('goodshoptype')->where(['shoptypenames'=>$thisshopname])->find();//分类名称重复判断！
		
		if(!$wsshoptypenames){
    	return $this->view->fetch('windsns_addtypenoa');//标题为空判断，保存失败！
        }elseif($sqllittle){
	       return $this->view->fetch('windsns_shoptypeaddno');//标题存在重复，保存失败！
		}else{
		 $wedid = Db::name('goodshoptype')->insert($windsns_shoptypeadd);//   保存SQL
		 return $this->view->fetch('windsns_shoptypeaddok');//保存成功！
		}
		
    }

     //分类状态切换 ----隐藏
    public function windsnsshop_typenulldo()
    {
	    $urlshoptypeid  =  input('get.shoptypeid'); //  获取地址栏栏目ID
	    $data['shoptypeopenid'] =  2; // 状态: 1、开启 2、隐藏
	    $xiugaizhuangtai = Db::name('goodshoptype')->where('shoptypeid', $urlshoptypeid)->update($data);// 
	    return  $this->fetch('widsns_shoptypedook');//操作OK！，更新隐藏状态2
    }

      //分类状态切换 ----开启
    public function windsnsshop_typeokdo()
    {
    	
	    $urlshoptypeid  =  input('get.shoptypeid'); //  获取地址栏栏目ID
	    $data['shoptypeopenid'] =  1; // 状态: 1、开启 2、隐藏
	    $xiugaizhuangtai = Db::name('goodshoptype')->where('shoptypeid', $urlshoptypeid)->update($data);// 
	    return  $this->fetch('widsns_shoptypedook');//操作OK！，更新隐藏状态2
    }  
   

    public function windsns_shoptypedel($shoptypeid) //删除资讯栏目
    {
        $urlshoptypeid  =  input('get.shoptypeid'); //  获取地址栏栏目ID
        $typewoldsum = Db::name('goodshop')->where(['shop_fenleiid' => $urlshoptypeid])->count();//查询该栏目下存在的资讯数量 
        if($typewoldsum > 1 or $typewoldsum == 1){
            return $this->view->fetch('windsns_shopdeltypenoa');//如果该栏目ID下存在文章数，删除失败！
        }else{
         	$shanchu = Db::name('goodshoptype')->where('shoptypeid',$urlshoptypeid)->delete();
 	        if($shanchu){
	            return $this->view->fetch('windsns_shoptypedeltypeok');//删除成功！
	        }else{
	          	return $this->view->fetch('windsns_shopdelno');//删除失败！
				exit;
	        }

        }

   }
   
   
      //栏目更新执行
    public function windsns_shoptypeup($shoptypeid)
    {
      $appstid =   Request::instance()->request('shoptypeid');//获取当前栏目的ID 
      $articleadtypenames['shoptypenames'] =  input('post.shoptypenames'); // 获取资讯栏目名称
      $thisarticlenames = input('post.shoptypenames'); // 获取资讯栏目名称
      $sqlnames  = Db::name('goodshoptype')->where(['shoptypenames'=>$thisarticlenames])->find();//重复判断！
      if(!$articleadtypenames['shoptypenames']){
         	return $this->view->fetch('windsns_addtypenoa');//标题为空判断，保存失败！
      }elseif($sqlnames){
			return $this->view->fetch('windsns_shoptypeaddno');//标题存在重复，保存失败！
		}else{
      	    $xiugaizhuangtai = Db::name('goodshoptype')->where('shoptypeid', $appstid)->update($articleadtypenames);// 
            return  $this->fetch('widsns_shoptypedook');//操作OK！，更新隐藏状态2
      }

    }

    //地区列表页面
    public function windsnsshopregion_list()
    {
        $windsns_shopdiqutypeinfos = Db::name('goodshopregion')->order('shopdiquid', 'desc')->paginate(20); //店铺分类列表
		$page = $windsns_shopdiqutypeinfos->render();
		$this->assign('windsns_shopdiqutypeinfos', $windsns_shopdiqutypeinfos);
		$this->assign('page', $page);
        return $this->view->fetch('windsns_shopregion');
    }
 
      //地区分类添加
    public function windsnsshopdiqutype_add()
    {
        $time = time();
		$paytimess = date('Y-m-d H:i:s',$time);
	    $thistimes = strtotime($paytimess);//获取当前时间
	    $wsshoptypenames = $this->request->request('shopdiqunames');
	    $windsns_shoptypeadd['shopdiqunames'] =  input('post.shopdiqunames'); // 店铺分类名称
	    $thisshopname = input('post.shopdiqunames'); // 获取应用标题
	    $windsns_shoptypeadd['shopdiquopenid'] =  input('post.shopdiquopenid'); // 开启状态：1正常2关闭隐藏
	    $windsns_shoptypeadd['shopdiquaddtime'] =  $thistimes;  // 获取添加时间	 
        $sqllittle  = Db::name('goodshopregion')->where(['shopdiqunames'=>$thisshopname])->find();//分类名称重复判断！
		if(!$wsshoptypenames){
    	return $this->view->fetch('windsns_addtypenoa');//标题为空判断，保存失败！
        }elseif($sqllittle){
	       return $this->view->fetch('windsns_shoptypeaddno');//标题存在重复，保存失败！
		}else{
		 $wedid = Db::name('goodshopregion')->insert($windsns_shoptypeadd);//   保存SQL
		 return $this->view->fetch('windsns_shopdiquaddok');//保存成功！
		
		}
		
    }
   

      //分类状态切换 ----隐藏
    public function windsnsshop_typediqunulldo()
    {
	    $urlshopdiqutypeid  =  input('get.diqutypeid'); //  获取地址栏栏目ID
	    $data['shopdiquopenid'] =  2; // 状态: 1、开启 2、隐藏
	    $xiugaizhuangtai = Db::name('goodshopregion')->where('shopdiquid', $urlshopdiqutypeid)->update($data);// 
	    return  $this->fetch('widsns_shopdiqutypedook');//操作OK！，更新隐藏状态2
    }

      //分类状态切换 ----开启
    public function windsnsshop_typediquokdo()
    {
	    $urlshopdiqutypeid  =  input('get.diqutypeid'); //  获取地址栏栏目ID
	    $data['shopdiquopenid'] =  1; // 状态: 1、开启 2、隐藏
	    $xiugaizhuangtai = Db::name('goodshopregion')->where('shopdiquid', $urlshopdiqutypeid)->update($data);// 
	    return  $this->fetch('widsns_shopdiqutypedook');//操作OK！，更新隐藏状态2
    }  
         //地区更新执行
    public function windsns_shopdiqutypeup($diqutypeid)
    {
      $appstid =   Request::instance()->request('diqutypeid');//获取当前栏目的ID 
      $articleadtypenames['shopdiqunames'] =  input('post.shopdiqunames'); // 获取资讯栏目名称
      $thisarticlenames = input('post.shopdiqunames'); // 获取资讯栏目名称
      $sqlnames  = Db::name('goodshopregion')->where(['shopdiqunames'=>$thisarticlenames])->find();//重复判断！
      
      if(!$articleadtypenames['shopdiqunames']){
         	return $this->view->fetch('windsns_addtypenoa');//标题为空判断，保存失败！
      }elseif($sqlnames){
			return $this->view->fetch('windsns_shoptypeaddno');//标题存在重复，保存失败！
		}else{
      	    $xiugaizhuangtai = Db::name('goodshopregion')->where('shopdiquid', $appstid)->update($articleadtypenames);// 
            return  $this->fetch('widsns_shopdiqutypedook');//操作OK！，更新隐藏状态2
      }

    }

   
  public function windsns_shopdiqutypedel($diqutypeid) //删除资讯栏目
    {
        $urlshoptypeid  =  input('get.diqutypeid'); //  获取地址栏栏目ID
        $typewoldsum = Db::name('goodshop') -> where(['shop_diquid' => $urlshoptypeid]) -> count();//查询该栏目下存在的资讯数量
        if($typewoldsum > 1 or $typewoldsum == 1){
            return $this->view->fetch('windsns_shopdeltypenoa');//如果该栏目ID下存在文章数，删除失败！
        }else{
         	
         	$shanchu = Db::name('goodshopregion')->where('shopdiquid',$urlshoptypeid)->delete();
 	        if($shanchu){
	            return $this->view->fetch('windsns_shopdiqutypedeltypeok');//删除成功！
	        }else{
	          	return $this->view->fetch('windsns_shopdelno');//删除失败！
	        }
        }

   }  
   
   
   
// 待审核店铺列表


 public function windsns_shopsreviewedlist()
    {
    $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' => 1])
    -> order('shopid', 'desc')->paginate(20); //店铺分类列表
		$page = $windsns_goodshopsinfos->render();
		$this->assign('windsns_goodshopsinfos', $windsns_goodshopsinfos);
		$this->assign('page', $page);
        return $this->view->fetch('windsns_shopsreviewedlist');
    }
    
// 店铺列表--正常店铺
   public function windsns_shopslist()
    {
    $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_shopslist');
    }
 
      //店铺状态切换 ----开启
    public function windsns_shopcheckok()
    {
	    $urlshopid  =  input('get.windsnsshopsid'); //  获取地址栏栏目ID
	    $data['shop_opentype'] =  2; // 店铺开启状态：1、审核中2正常开启3已经冻结4已经关闭',
	    $xiugaizhuangtai = Db::name('goodshop')->where('shopid', $urlshopid)->update($data);// 
	    return  $this->fetch('widsns_shopcheckok');//操作OK！，更新隐藏状态2
    }     
   
      //店铺状态切换 ----审核中
    public function windsns_shopchecknow()
    {
	    $urlshopid  =  input('get.windsnsshopsid'); //  获取地址栏栏目ID
	    $data['shop_opentype'] =  1; // 店铺开启状态：1、审核中2正常开启3已经冻结4已经关闭',
	    $xiugaizhuangtai = Db::name('goodshop')->where('shopid', $urlshopid)->update($data);// 
	    return  $this->fetch('widsns_shopchecknow');//操作OK！，更新隐藏状态1
    }  
   
   
   
   
    public function windsns_shopdeldo($windsnsshopsid) //删除店铺
    {
        $urlshoptypeid  =  input('get.windsnsshopsid'); //  获取地址栏栏目ID
       
         	$shanchu = Db::name('goodshop')->where('shopid',$urlshoptypeid)->delete();
 	        if($shanchu){
	            return $this->view->fetch('windsns_shopdelok');//删除成功！
	        }else{
	          	return $this->view->fetch('windsns_shopdelno');//删除失败！
	        }
        }

  
   
   
   
   
   
   
   
   
   
   
}
