<?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 Goodshopjoin extends Frontend
{

	
    protected $noNeedLogin = ['login', 'mobilelogin', 'register', 'resetpwd', 'changeemail', 'changemobile', 'third'];
    protected $noNeedRight = '*';

    public function _initialize()
    {
        parent::_initialize();
    }
    
	/**
	 * 协议
	 * @author   Devil
	 * @blog     http://www.weinuo.net
	 * @version  0.0.1
	 * @datetime 2020-03-03
	 */
    public function windsnsgoodsshopjoin()
    {
    
      $this->view->assign('title', __('好店入驻'));
      $userid = $this->auth->getUserinfo()['user_id'];
      $this->assign('userid', $userid);
      $windsns_goodshopopen = Db::name('goodshop') -> where(['shop_uid' => $userid]) -> find();
      $windsns_goodshopopentype = $windsns_goodshopopen['shop_opentype'];
      $windsnsshoptype = Db::name('goodshoptype') -> where(['shoptypeopenid' => 1]) -> order('shoptypeid', 'desc')->select(); //行业分类打印
      $this->assign('windsnsshoptype', $windsnsshoptype);
      $windsnsshopdiqu = Db::name('goodshopregion') -> where(['shopdiquopenid' => 1]) -> order('shopdiquid', 'desc')->select(); //地区分类打印
      $this->assign('windsnsshopdiqu', $windsnsshopdiqu);
      	  if($windsns_goodshopopentype == 1){
	      return $this->view->fetch('index@goodshop/windsns_goodshopjoinshenhe');
	      }elseif($windsns_goodshopopentype == 3){
	      	return $this->view->fetch('index@goodshop/windsns_goodshopjoindongjie');
	      }elseif($windsns_goodshopopentype == 2){
	      	$this->view->assign('title', __('店铺管理'));	
	      	$windsns_goodshopinfosa = Db::name('goodshop')->where(['shop_uid'=>$userid])->select();
            $this->assign('windsns_goodshopinfosa', $windsns_goodshopinfosa);
	      	$windsns_goodshopinfosb = Db::name('goodshop')->where(['shop_uid'=>$userid])->select();
            $this->assign('windsns_goodshopinfosb', $windsns_goodshopinfosb);
	      	$windsns_goodshopinfosc = Db::name('goodshop')->where(['shop_uid'=>$userid])->select();
            $this->assign('windsns_goodshopinfosc', $windsns_goodshopinfosc);	      	
	      	return $this->view->fetch('index@goodshop/windsns_goodsshop_home');
	      }elseif($windsns_goodshopopentype == 4){
	      	return $this->view->fetch('index@goodshop/windsns_goodshopjoinguanbi');
	      }
	      else{
	      	return $this->view->fetch('index@goodshop/windsns_goodsshop_join');
	      }
    
      
    }

    public function windsns_shopadddo()  
    {

        $time = time();
		$paytimess = date('Y-m-d H:i:s',$time);
		$paymenttimes = strtotime($paytimess);
	    $getruluid  =  input('get.uid'); 
	    $userid = $this->auth->getUserinfo()['user_id'];
	    $this->assign('userid', $userid);
        $windsns_goodshopadd['shop_uid'] =  $userid; 
	    $windsns_goodshopadd['shop_names'] =  input('post.shop_names'); 
	    $windsns_goodshopadd['shop_diquid'] =  input('post.shop_diquid'); 
	    $windsns_goodshopadd['shop_fenleiid'] =  input('post.shop_fenleiid'); 
	    $windsns_goodshopadd['shop_address'] =  input('post.shop_address');
	    $windsns_goodshopadd['shop_tel'] =  input('post.shop_tel');
	    $windsns_goodshopadd['shop_jianjie'] =  input('post.shop_jianjie');
	    $windsns_goodshopadd['shop_authentication'] = 1;
        $windsns_goodshopadd['shop_opentype'] = 1; 
        $windsns_goodshopadd['shop_addtimes'] = $paymenttimes;
        $windsns_goodshopsum = Db::name('goodshop') -> where(['shop_opentype' => 2,'shop_uid' => $userid]) -> count();// SQl正常开启的店铺的数量
        $thisuseridsum = Db::name('goodshop')->where(['shop_uid' => $userid])->count();
      	if($getruluid!= $userid){
			$this->view->assign('title', __('非法操作'));							
			return $this->view->fetch('index@goodshop/windsns_goodshopjoinno');						
			}elseif($windsns_goodshopsum > 1 or $windsns_goodshopsum == 1){
			$this->view->assign('title', __('操作失败'));							
			return $this->view->fetch('index@goodshop/windsns_goodshopjoinexistence');
			}else{
			    if($thisuseridsum > 0 or $thisuseridsum >1){
	      	    return $this->view->fetch('index@goodshop/windsns_goodshopnot');
		        }else{
	        	$this->view->assign('title', __('操作成功'));	
				$wedid = Db::name('goodshop')->insert($windsns_goodshopadd);
				return $this->view->fetch('index@goodshop/windsns_goodshopjoinok');
		        }
	       }
    }

 public function windsns_shoplogoup() 
    {
      $urlgoodshopid  =  input('get.goodshopid'); 
      $userid = $this->auth->getUserinfo()['user_id'];
	  $file = request()->file('shop_logo'); 
	  if($file){
        $info = $file->validate(['size'=>2000000000,'ext'=>'jpg,png'])->move(ROOT_PATH . 'public/static' . DS . 'uploads/goodshopimg');
        if($info){
        	
            	$imgpath = $info->getSaveName();
                $imgnames = $info->getFilename();
    	        $articleadd['shop_logo']=  $imgpath; 
				$xiugaizhuangtai = Db::name('goodshop')-> where(['shop_uid' => $userid,'shopid' => $urlgoodshopid])->update($articleadd);// 
                return $this->view->fetch('index@goodshop/windsns_goodshoplogouook');
	        }else{
                return $this->view->fetch('index@goodshop/windsns_goodshoplogouono');
                }

            }else{
                return $this->view->fetch('index@goodshop/windsns_goodshoplogouook');
            }    

    }

 public function windsns_shoptexup()
    {
      $urlgoodshopid  =  input('get.goodshopid');
      $userid = $this->auth->getUserinfo()['user_id'];
	  $articleadd['shop_txt'] =  input('post.shop_txt');
	  
	  $xiugaizhuangtai = Db::name('goodshop')-> where(['shop_uid' => $userid,'shopid' => $urlgoodshopid])->update($articleadd);// 
      return $this->view->fetch('index@goodshop/windsns_goodshoplogouook');

    }


 public function windsns_shopinfosup()
    {
      $urlgoodshopid  =  input('get.goodshopid');
      $userid = $this->auth->getUserinfo()['user_id'];
	  $articleadd['shop_names'] =  input('post.shop_names'); 
	  $articleadd['shop_tel'] =  input('post.shop_tel'); 
	  $articleadd['shop_address'] =  input('post.shop_address'); 
	  $xiugaizhuangtai = Db::name('goodshop')-> where(['shop_uid' => $userid,'shopid' => $urlgoodshopid])->update($articleadd);// 
      return $this->view->fetch('index@goodshop/windsns_goodshoplogouook');

    }



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


}
