<?php
namespace app\hsycms\controller;
use think\Controller;
use app\hsycms\controller\Base;

class Member extends Base
{
	
	//会员列表
  public function index(){		
		if(input('s_status')!=""){			
			$map['status'] = input('s_status');
		}
		if(input('s_type')!=""){			
			$map['type'] = input('s_type');
		}
		if(input('title')!=""){			
			$map['mobile|name'] = array('like','%'.input('title').'%');
		}	
		$list = db('member')->where($map)->order($order)->paginate(10,false,['query' => request()->param()]);
		$page = $list->render();		
		$this->assign("list",$list);
		return $this->fetch(); 
    }
	
	//查看详情
	public function detail(){
		$id = input('id','','intval');
		$one = db('member')->where(['id'=>$id])->find();
		$this->assign("v",$one);
		return $this->fetch(); 
	}	
	
	//修改会员资料
	public function edit(){
		$data = input("post.");
		if($data['password']!=''){ $data['password'] = md5($data['password']); }else{ unset($data['password']);}
		if(db('member')->where(['id'=>$data['id']])->update($data)!==false)
		return json(['status'=>'y','info'=>'编辑成功']);
	}
	
	//批量审核
	public function status(){		
		$status  = input('status','','intval');					
		if($_POST['id']){
			foreach($_POST['id'] as $v){				
				db('member')->where(['id'=>$v])->setField('status',$status);
			}
			$txt = $status == 1 ? '锁定' : '取消锁定';
			$this->success("批量".$txt."成功");	
		}else{
			$this->error("请选择要操作的内容");		
		}	
	}
	
	//删除
	public function del(){	
		$id  = input('id');						
		db('member')->where('id',$id)->delete();		
		return json(['status'=>'y','info'=>'删除成功']);				
	}
	
	//指量删除
	public function delall(){
		if($_POST['id'])foreach($_POST['id'] as $v){				
			db('member')->where(['id'=>$v])->delete();			
		}
		$this->success("批量删除成功");
	}
	
	
	
}