<?php
namespace Payment\Controller;
/**
 * 后台首页控制器
 * @author 麦当苗儿 <zuojiazi@vip.qq.com>
 */
class UserController extends BaseController
{
    
    public function _initialize()
    {
        $this->admininfo = session('payment_user');;
        // $this->DBModel = M("CompanyStatementPool","tab_");
        parent::_initialize();
    }
    public function index()
    {
        $params = I('get.');
        $page = $params['p'] ? intval($params['p']) : 1;
        $row = $params['row'] ? intval($params['row']) : 10;

        $data =  M("PaymentMember","tab_")->page($page,$row)->order("id desc")->select();
        $count = M("PaymentMember","tab_")->count("id");
        $page = set_pagination($count, $row);
        if ($page) {
            $this->assign('_page', $page);
        }
        $this->meta_title = '打款结算单';
        $this->assign("data",$data);
       
        $this->display();
    }
    public function add()
    {

        if (IS_POST) {
            $p = $_REQUEST;
            $mobile = $p['mobile'];
            /*检测用户名是否为空*/
            if (empty($p['mobile'])) {
                $this->error('手机号码不能为空!');
            }
            if (!preg_match('/^1[1-9]\d{9}$/', $p['mobile'])) {
                return $this->error("手机号码格式错误");
            }
            if (empty($p['real_name'])) {
                $this->error('姓名允许为空');
            }
            //判断手机唯一
            $check_mobile = M("Kv")->field("value")->where("`key`='payment_check_mobile' AND `value`= '{$mobile}'")->find();
            if(empty($check_mobile)){
                //获取普通登陆
                $plogin =  M("payment_member","tab_")->where("`mobile`= '{$mobile}'")->find();
                if(!empty($plogin)){
                    $this->error('手机号码已存在');
                }
            }else{
                $this->error('手机号码已存在');
            }
            M("payment_member","tab_")->add($p);
            $this->success('用户添加成功!', U('index'));
        } else {
            $this->meta_title = '新增制表人';
            $this->display();
        }
    }
    public function delete($id)
    {
        $res = M('payment_member',"tab_")->where("id = '{$id}'")->delete();
        if ($res) {
            $this->success('删除成功');
        } else {
            $this->error('删除失败');
        }
    }

   


}