php think-Model类(方法)实例源码

下面列出了php think-Model 类(方法)源码代码实例,从而了解它的用法。

作者:chenyahu    项目:online-cha   
public function getFriend($userid)
 {
     $sql = "select u.name,u.id from __USERS__ as u,(select user2 from __FRIEND__ where user1 = {$userid} \r\n               UNION select user1 from  __FRIEND__ where user2 = {$userid}) as f where u.id = f.user2";
     $model = new Model();
     $data = $model->query($sql);
     return $data;
 }

作者:lisgrou    项目:userprojec   
public function header_city()
 {
     $city1 = new \Think\Model();
     $sql = "select r.* from __PREFIX__store_shipping_region as ssr left join __PREFIX__region as r on ssr.city=r.region_id where ssr.city>0 group by ssr.city";
     $rs = $city1->query($sql);
     var_dump($rs);
 }

作者:XQ-quadran    项目:gbCM   
public function listView($cate)
 {
     $cate_atc = M('cate_atc');
     $count = $cate_atc->where(['status' => 1, 'cate' => $cate])->count();
     $Page = new \Think\Page($count, 16);
     // 实例化分页类 传入总记录数和每页显示的记录数
     $show = $Page->show();
     // 分页显示输出
     $list = $cate_atc->where(['cate' => $cate])->order('createtime')->limit($Page->firstRow . ',' . $Page->listRows)->select();
     $model = new Model();
     foreach ($list as $k => $v) {
         $modelInfo = get_model_info($v['model_id']);
         //获每条数据的模型信息
         //echo $modelInfo['identity'];
         $raw = $model->query("select author from {$modelInfo['identity']} where id = {$v['atc_id']}");
         $list[$k]['author'] = $raw[0]['author'];
         $d = strtotime($v['createtime']);
         $list[$k]['createtime'] = '<div>' . date("Y/m/d", $d) . '</div>' . '<div>' . date("H:i:s", $d) . '</div>';
         //编辑时间格式
     }
     //var_dump($show);
     /* $Page->setConfig('f_decorate','<li>');
        $Page->setConfig('b_decorate','</li>');*/
     $this->assign('page', $show);
     $this->assign('list', $list);
     $this->assign('model_list', get_cate_Model($cate));
     //$this->assign("cate_id",1);
     $this->assign("cate", $cate);
     $this->display();
 }

作者:ljhchsh    项目:Recruitment   
/**
  * 登录验证
  * @param $loginArr
  * @return $arr
  */
 public function loginCheck($loginArr)
 {
     $User = new Model('user');
     $array['US_name'] = $loginArr['US_name'];
     //设置用户等级为管理员
     $array['Us_level'] = 2;
     $result = $User->where($array)->select();
     $arr = array();
     $arr['status'] = 0;
     if ($result != null && count($result) == 1) {
         if (strcmp(md5($loginArr['password']), $result[0]['password']) == 0) {
             //登陆成功
             $arr['status'] = 1;
             $arr['content'] = '验证成功!';
             return $arr;
         } else {
             //登陆失败(密码错误)
             $arr['content'] = '密码错误!';
             return $arr;
         }
     } else {
         $arr['content'] = '用户名不存在!';
         return $arr;
     }
 }

作者:magiclak    项目:chaowe   
public function getCitiesByProvince($province)
 {
     $sql = "select a.city as city from t_cities a, t_provinces b\r\n            where b.province like '" . $province . "%' and b.provinceid = a.provinceid";
     $m = new \Think\Model();
     $result = $m->query($sql);
     return $result;
 }

作者:rubylo    项目:lc   
public function detail()
    {
        $Form = new Model();
        $result = $Form->query('select admin_articles.*, admin_nickname from admin_articles 
			inner join admin_personal on admin_articles.admin_id = admin_personal.admin_id
			where article_id="%s"', $_GET['p']);
        if ($result) {
            $result[0]['article_type'] = C('MODULE_CODE')[$result[0]['article_type']];
            //dump($result[0]);
            if ($result[0]['article_about'] == C(PROJECT_CODE)) {
                $object = $Form->query('select project_name as name, project_logo as portrait from project_info
					where project_id = "%s"', $result[0]['article_object']);
                //dump($object);
                $this->obj = $object[0];
            } else {
                if ($result[0]['article_about'] == C(INVESTOR_CODE)) {
                    $object = $Form->query('select name, portrait from investor_personal
					where user_id = "%s"', $result[0]['article_object']);
                    //dump($object);
                    $this->obj = $object[0];
                } else {
                    if ($result[0]['article_about'] == C(INNOVATOR_CODE)) {
                        $object = $Form->query('select name, portrait from entrepreneur_personal
					where user_id = "%s"', $result[0]['article_object']);
                        //dump($object);
                        $this->obj = $object[0];
                    }
                }
            }
            $this->p = $result[0];
        }
        $update = $Form->execute('update admin_articles set article_visits=%d where article_id="%s"', $result[0]['article_visits'] + 1, $_GET['p']);
        $this->display();
    }

作者:snowman82    项目:Attendance-Syste   
public function doLogin()
 {
     // 参数非法,则重新登录
     if (empty($_POST["name"]) || empty($_POST["password"]) || empty($_POST["code"])) {
         $this->ajaxReturn(array("content" => null, "info" => "输入不能为空", "status" => false));
         exit(1);
     }
     //验证码生成
     $code = $_POST['code'];
     $Ver = new CodeController();
     if (!$Ver->check_verify($code)) {
         // 验证码错误
         $this->ajaxReturn(array("content" => null, "info" => "验证码错误", "status" => false));
         $this->error("验证码错误", "index");
         exit(1);
     }
     //获取用户名
     $username = $_POST['name'];
     //获取密码
     $password = $_POST["password"];
     //创建systemmanager 的Model
     $m = new Model("systemmanager");
     //$res = $m->field ( "sys_password,sys_id" )->where ( "sys_username='{$username}'" )->select ();
     $res = $m->field("sys_password,sys_id")->where("sys_username='%s'", $username)->select();
     // 防注入	查找
     if ($res[0]['sys_password'] == md5($password)) {
         //若账号和密码都正确则登录成功,并存入相关session
         $_SESSION['systemmanager'] = $username;
         $_SESSION['sys_id'] = $res[0]['sys_id'];
         $this->ajaxReturn(array("content" => null, "info" => "登录成功!", "status" => true));
     }
     //用户名或者密码错误,则登录失败
     $this->ajaxReturn(array("content" => null, "info" => "用户名或者密码错误!", "status" => false));
 }

作者:Phle    项目:yaowa   
function getCategory()
 {
     /*	$data['slug'] <> 'uncategorized';
        return $this->where($data)->select();*/
     $Model = new Model();
     return $Model->query("select * from wp_terms where wp_terms.slug <> 'uncategorized'");
 }

作者:kaka200    项目:xpla   
function checkVerfiyCode()
 {
     $param = json_decode(file_get_contents('php://input'), true);
     $phone = $param['phone'];
     $verfiycode = $param['verfiycode'];
     if (empty($phone)) {
         err_ret(-205, 'lack of param', '缺少参数');
     }
     if (empty($verfiycode)) {
         err_ret(-205, 'lack of param', '缺少参数');
     }
     //万能验证码
     if ($verfiycode == '0228') {
         http_ret(0, 'verify code is correct', '验证码正确');
     }
     $model = new Model('verify_tmp');
     $condition['phone'] = $phone;
     $condition['verifycode'] = $verfiycode;
     $result = $model->where($condition)->select();
     if (count($result) <= 0) {
         err_ret(-307, 'verfiy code is incorrect', '验证码不正确');
     }
     $time = time() - $result[0]['gen_time'];
     if ($time > 5 * 60) {
         err_ret(-308, 'verify code is invalid', '验证码已过期');
     }
     if ($verfiycode == $result[0]['verifycode']) {
         http_ret(0, 'verify code is correct', '验证码正确');
     } else {
         err_ret(-307, 'verfiy code is incorrect', '验证码不正确');
     }
 }

作者:rubylo    项目:lc   
public function login()
 {
     $Form = new Model();
     $user = $Form->query("select * from admin_personal where admin_id = '%s'", $_POST['loginuser']);
     //echo  json_encode($user[0]);
     if ($user[0]['admin_pwd'] === $_POST['loginpwd']) {
         $_SESSION['userid'] = $user[0]['admin_id'];
         //session(array('name'=>'userid','expire'=>2),$user[0]['admin_id']);
         $_SESSION['usertype'] = $user[0]['admin_type'];
         if ($_SESSION['usertype'] == 1) {
             echo 201;
         } else {
             if ($_SESSION['usertype'] == 2) {
                 echo 202;
             } else {
                 if ($_SESSION['usertype'] == 3) {
                     echo 203;
                 } else {
                     echo 404;
                 }
             }
         }
     } else {
         echo 409;
     }
 }

作者:Telan    项目:b   
public function check($para)
 {
     $user = $para['user'];
     $type = $para['type'];
     $pwd = md5($para['pwd']);
     $vcode = $para['verifycode'];
     //首先验证验证码
     if ($this->check_verify($vcode)) {
         //验证账号密码
         switch ($type) {
             case '3':
                 $tb = 'user_admin';
                 $tb2 = 'user_admin';
                 break;
             case '2':
                 $tb = 'user_teacher_pwd';
                 $tb2 = 'user_teacher';
                 break;
             case '1':
                 $tb = 'user_student_pwd';
                 $tb2 = 'user_student';
         }
         $Model = new \Think\Model();
         $sql = "select  * from {$tb2} B left join {$tb} A on A.user=B.user where A.user='{$user}' and A.pwd='{$pwd}' and B.status=1";
         //var_dump($sql);
         if (count($Model->query($sql))) {
             return 1;
         } else {
             return 0;
         }
     } else {
         return -1;
     }
 }

作者:xialeistudi    项目:thinkphp-inactio   
public function db()
 {
     $m = new Model('Post');
     $list = $m->select();
     dump($list);
     echo $m->getLastSql();
 }

作者:hcpzh    项目:foodorde   
public function myUpdate($data)
 {
     $id = (int) $data['id'];
     if ($id <= 0) {
         $this->error = '请先选择要更新的分类';
         return false;
     }
     unset($data['id']);
     if ($id == $data['parent_id']) {
         $data['parent_id'] = 0;
     }
     //所属分类等于自己时, 更正为顶级分类
     //验证数据
     if (false === $this->create($data, self::MODEL_UPDATE)) {
         return false;
     }
     //验证 parent_id合法性
     if ($this->parent_id > 0) {
         $model = new Model('Category');
         //避免 model 混淆
         $parent = $model->find($this->parent_id);
         if (false === $parent || empty($parent)) {
             $this->error = '父级分类不存在';
             return false;
         }
         $orginfo = $model->find($id);
         if ($orginfo['store_id'] != $parent['store_id']) {
             $this->error = '父级分类不存在当前店铺';
             return false;
         }
     }
     return $this->where('`id`=' . $id)->save();
 }

作者:92580052    项目:itskycm   
/**
  * 列表显示
  */
 public function index()
 {
     if (!IS_AJAX) {
         $this->error(L('_ERROR_ACTION_'));
     }
     $Model = new Model();
     $islang = $Model->query('Describe __' . strtoupper(CONTROLLER_NAME) . '__ lang');
     if ($islang[0]['field'] == 'lang') {
         if (I('get.lang')) {
             $wl = 'lang=\'' . I('get.lang') . '\'';
         } elseif ($this->clang) {
             $wl = 'lang=\'' . $this->clang . '\'';
         } else {
             $wl = 'lang=\'' . LANG_SET . '\'';
         }
     } else {
         $wl = '1';
     }
     $isorder = $Model->query('Describe __' . strtoupper(CONTROLLER_NAME) . '__ listorder');
     $ol = $isorder == 'listorder' ? 'listorder,' : '';
     $name = M(CONTROLLER_NAME);
     $list = $name->where($wl)->order($ol, 'id')->select();
     $this->assign('list', $list);
     $this->display();
 }

作者:xialeistudi    项目:thinkphp-inactio   
public function comment($id)
 {
     $model = new Model('Article');
     $article = $model->find(array('articleId' => $id));
     if (empty($article)) {
         $this->error('文章不存在');
     }
     $key = get_client_ip() . '-view-article-' . $id;
     $cache = S($key);
     if (!empty($cache)) {
         $this->error('评论间隔必须大于1分钟');
     }
     $nickname = I('nickname');
     $content = I('content');
     if (empty($nickname)) {
         $this->error('昵称不能为空');
     }
     if (empty($content)) {
         $this->error('评论内容不能为空');
     }
     $data = array('nickname' => $nickname, 'content' => $content, 'createdAt' => time(), 'createdIp' => get_client_ip(), 'articleId' => $id);
     $commentModel = new Model('Comment');
     if (!$commentModel->data($data)->add()) {
         $this->error('评论失败');
     }
     S($key, 1, 60);
     $data['createdAt'] = date('m-d H:i', $data['createdAt']);
     $this->ajaxReturn($data);
 }

作者:XQ-quadran    项目:gbCM   
public function index($cate)
 {
     $cate_atc = M('cate_atc');
     $count = $cate_atc->where(['status' => 1, 'cate' => $cate])->count();
     $Page = new \Think\Page($count, 16);
     // 实例化分页类 传入总记录数和每页显示的记录数
     $show = $Page->show();
     // 分页显示输出
     $list = $cate_atc->where(['cate' => $cate])->order('createtime')->limit($Page->firstRow . ',' . $Page->listRows)->select();
     $model = new Model();
     foreach ($list as $k => $v) {
         $modelInfo = get_model_info($v['model_id']);
         //获每条数据的模型信息
         $raw = $model->query("select author from {$modelInfo['identity']} where id = {$v['atc_id']}");
         $list[$k]['author'] = $raw[0]['author'];
         $d = strtotime($v['createtime']);
         $list[$k]['createtime'] = '<h6>' . date("m/d", $d) . '</h6>';
         //编辑时间格式
     }
     $this->assign('page', $show);
     $this->assign('list', $list);
     $this->assign('model_list', get_cate_Model($cate));
     $this->assign("cate", $cate);
     $this->display('News/index');
 }

作者:kaka200    项目:xpla   
function checkCoachMaxUsers()
 {
     $param = json_decode(file_get_contents('php://input'), true);
     $token = $param['xtoken'];
     // init_verify_token($token);
     $coachid = $param['coachid'];
     // $coachid = 53;
     if (empty($coachid)) {
         err_ret(-205, 'lack of param', '缺少参数');
     }
     //判断教练的客户是否超过10个
     $model = new Model();
     $sql_user = 'SELECT DISTINCT uid  FROM my_plan WHERE coachid=' . $coachid;
     $result_user = $model->query($sql_user);
     $studentNums = M("user_info")->where("type=1 and id={$coachid}")->getField("studentnums");
     if (count($result_user) >= $studentNums) {
         $model_user = new Model('user_info');
         $save_data['status'] = 1;
         $where_data['id'] = $coachid;
         $where_data['type'] = 1;
         $model_user->where($where_data)->save($save_data);
         $data['errno'] = 0;
         $data['is_max'] = 1;
         $data['coachid'] = $coachid;
         echo json_encode($data);
     } else {
         $data['errno'] = 0;
         $data['is_max'] = 0;
         $data['coachid'] = $coachid;
         echo json_encode($data);
     }
 }

作者:xialeistudi    项目:thinkphp-inactio   
public function edit($id)
 {
     $model = new Model('Link');
     $data = $model->find($id);
     if (empty($data)) {
         $this->error('链接不存在');
     }
     if (IS_POST) {
         $name = I('name');
         $link = I('link');
         $status = I('status', 1);
         $sort = I('sort', 0);
         if (empty($name)) {
             $this->error('网站名称不能为空');
         }
         if (empty($link)) {
             $this->error('网站链接不能为空');
         }
         $data = array('name' => $name, 'link' => $link, 'status' => $status, 'sort' => $sort);
         if (false === $model->where(array('linkId' => $id))->save($data)) {
             $this->error('编辑失败');
         } else {
             $this->success('编辑成功', U('admin/link/index'));
         }
     } else {
         $this->assign('data', $data);
         $this->display('post');
     }
 }

作者:Telan    项目:b   
public function search($para)
 {
     $k = "bs_kt.name like '%" . $para['k'] . "%'";
     //根据实验室分类
     if ($para['d'] == '0') {
         $d = '1=1';
     } else {
         $dep = $para['d'];
         $d = "user_teacher.dep='{$dep}'";
     }
     /**查询sql语句
     		select bs_kt.id,bs_kt.name as bname,bs_kt.snum,user_teacher.name as tname,user_teacher.dep,count(bs_xt.bid) from bs_kt left join user_teacher on user_teacher.user=bs_kt.teacher left join bs_xt on bs_xt.bid=bs_kt.id group by bs_kt.id
     		select bs_kt.id,bs_kt.name as bname,bs_kt.snum,user_teacher.name as tname,user_teacher.dep,count(bs_xt.bid) from bs_kt left join user_teacher on user_teacher.user=bs_kt.teacher left join bs_xt on bs_xt.bid=bs_kt.id where bs_kt.status=1 and bs_kt.name like '%安%' group by bs_kt.id 
     		*/
     $np = 10;
     //每页数
     $cp = (int) $para['p'];
     //当前页
     $sql1 = "select count(*) from bs_kt inner join user_teacher on bs_kt.teacher=user_teacher.user where " . $d . " and " . $k . " and bs_kt.status=3";
     $sql2 = "select bs_kt.id,bs_kt.name as bname,bs_kt.teacher as tuser,user_teacher.name as tname,user_teacher.dep,user_student.user as suser,user_student.name as sname from bs_kt" . " left join user_teacher on bs_kt.teacher=user_teacher.user" . " left join user_student on user_student.user in (select sid from bs_xt where bs_xt.bid = bs_kt.id)" . " where " . $d . " and " . $k . " and bs_kt.status=3 group by bs_kt.id limit " . $np * ($cp - 1) . ',' . $np . '';
     //自定义执行sql语句
     $Model = new \Think\Model();
     $tp = $Model->query($sql1)[0]['count(*)'];
     $rs_kt = $Model->query($sql2);
     $rs = array('page' => array('sql' => $sql2, 'tp' => $tp, 'c_p' => $cp, 't_p' => ceil(1.0 * $tp / $np)), 'r' => $rs_kt ? $rs_kt : array());
     return $rs;
 }

作者:hcpzh    项目:foodorde   
/**
  * 店主信息
  */
 public function onwerInfo()
 {
     $model = new Model('Store');
     $info = $model->find(STID);
     $this->assign('info', $info);
     cookie(C('CURRENT_URL_NAME'), $_SERVER['REQUEST_URI']);
     $this->display();
 }


问题


面经


文章

微信
公众号

扫码关注公众号