本文整理汇总了PHP中think\Model::where方法的典型用法代码示例。如果您正苦于以下问题:PHP Model::where方法的具体用法?PHP Model::where怎么用?PHP Model::where使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类think\Model
的用法示例。
在下文中一共展示了Model::where方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: edit
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');
}
}
示例2: checkVerfiyCode
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', '验证码不正确');
}
}
示例3: send
/**
* 发送验证码
* @param string $mobile 手机号
* @return boolean 是否成功
*/
public function send($mobile)
{
//验证码每天手机号最大数量
if (parent::where(array('mobile' => $mobile, 'create_time' => array('gt', time())))->count() > (int) C('sms.mobile_day_max')) {
$this->error = '手机号 ' . $mobile . ' 已超过每天发送验证码最大数量';
return false;
}
//验证码每天ip最大数量
if (parent::where(array('ip' => get_client_ip(), 'create_time' => array('gt', time())))->count() > (int) C('sms.ip_day_max')) {
$this->error = 'ip ' . get_client_ip() . ' 已超过每天发送验证码最大数量';
return false;
}
//验证码每天ip最大数量
if (time() - parent::where(array('mobile' => $mobile))->order('id desc')->getField('create_time') < (int) C('sms.send_wait_time')) {
$this->error = '发送间隔过于频繁';
return false;
}
if (!($data = $this->create((new Sms())->send($mobile)))) {
return false;
}
if ($data['status'] != '0') {
$this->error = (new Sms())->getError($data['code']);
return false;
}
return parent::add($data);
}
示例4: read
public function read($id)
{
$map['id'] = (int) $id;
if ($map['id'] <= 0) {
$this->error('请选择商品');
}
$model = new Model('Goods');
$info = $model->where($map)->find();
$store_M = new Model('Store');
$store_info = $store_M->find($info['store_id']);
$this->assign('store_info', $store_info);
//所属店铺
$cate_M = new CategoryModel();
if ($info['cate_id'] > 0) {
$info['cate_name'] = $cate_M->where('id=' . $info['cate_id'])->getField('cate_name');
} else {
$info['cate_name'] = '无分类';
}
$map = array('store_id' => $info['store_id'], 'status' => 1);
$cate_tree = $cate_M->ztreeArr($map);
//ztree json
$tmp = array(array('id' => null, 'pId' => 0, 'name' => '无分类'));
$cate_tree = array_merge(array(array('id' => 0, 'pId' => 0, 'name' => '无分类', 'open' => true)), $cate_tree);
//$tmp + $cate_tree;
$cate_tree = json_encode($cate_tree);
$this->assign('tree_json', $cate_tree);
//ztree json
$this->assign('info', $info);
//商品信息
cookie(C('CURRENT_URL_NAME'), $_SERVER['REQUEST_URI']);
$this->display();
}
示例5: getPlanDetail
function getPlanDetail()
{
$param = json_decode(file_get_contents('php://input'), true);
$token = $param['xtoken'];
init_verify_token($token);
$pid = $param['pid'];
//$pid = 1;
if (empty($pid)) {
err_ret(-205, 'lack of param', '缺少参数');
}
//获取计划的基本信息
$plan_model = new Model('plan');
$condition['id'] = $pid;
$result = $plan_model->where($condition)->select();
//获取计划的介绍信息
$plan_intro_model = new Model('plan_intro');
unset($condition);
$condition['pid'] = $pid;
$result_intro = $plan_intro_model->where($condition)->select();
//查询计划对应的教练的信息(未排序)
// $sql_coach = "SELECT coachid,name,duration,header,type,price FROM user_info,(
// SELECT coachid FROM plan,plan_coach WHERE plan.id=$pid AND plan.id=plan_coach.pid
// ) AS t WHERE t.coachid=user_info.id";
//查询计划对应的教练的信息(已排序)
$sql_coach = "SELECT coachid,name,duration,header,type,price ,score FROM user_info,(\n SELECT coachid FROM plan,plan_coach WHERE plan.id={$pid} AND plan.id=plan_coach.pid AND plan_coach.status=0\n ) AS t WHERE t.coachid=user_info.id ORDER BY score DESC";
$model_coach = new Model();
$result_coach = $model_coach->query($sql_coach);
$data['errno'] = 0;
$data['coverimg'] = $result[0]['coverimg'];
$data['title'] = $result[0]['title'];
$data['peoplenumber'] = $result[0]['peoplenumber'];
$data['coach_list'] = $result_coach;
$data['intro_list'] = $result_intro;
echo json_encode($data);
}
示例6: loginCheck
/**
* 登录验证
* @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;
}
}
示例7: checkCoachMaxUsers
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);
}
}
示例8: where
public function where($map, $parse = null)
{
if (!$this->not_belongs_to_company && !$map['id']) {
$map["company_id"] = get_current_company_id();
}
return parent::where($map, $parse);
}
示例9: updateDeviceToken
function updateDeviceToken()
{
$param = json_decode(file_get_contents('php://input'), true);
$xtoken = $param['xtoken'];
init_verify_token($xtoken);
$uid = $param['uid'];
if (empty($uid)) {
err_ret(-205, 'lack of param', '缺少参数');
}
$device_token = $param['device_token'];
if (empty($device_token)) {
err_ret(-205, 'lack of param', '缺少参数');
}
//设备类型 1安卓手机 2苹果手机
$type = $param['type'];
if ($type != 1 && $type != 2) {
err_ret(-205, 'param is error', '参数错误');
}
$model = new Model('apns_user');
$where_data['uid'] = $uid;
$result = $model->where($where_data)->select();
if (count($result) > 0) {
//如果已经有了deviceToken
$old_type = $param[0]['type'];
$old_device_token = $param[0]['device_token'];
if ($old_device_token != $device_token) {
$type = $old_type == 1 ? 2 : 1;
$condition['uid'] = $uid;
$save_data['device_token'] = $device_token;
$save_data['type'] = $type;
$model->where($condition)->save($save_data);
}
} else {
$add_data['device_token'] = $device_token;
$add_data['uid'] = $uid;
$add_data['type'] = $type;
$result = $model->add($add_data);
}
$data['errno'] = 0;
$data['uid'] = $uid;
$data['type'] = $type;
$data['device_token'] = $device_token;
echo json_encode($data);
}
示例10: checkAccount
public function checkAccount($account)
{
$model = new Model('Admin');
$status = $model->where('account="' . trim($account) . '"')->getField('id');
if (intval($status) > 0) {
return false;
} else {
return true;
}
}
示例11: checkQq
/**
* 检查该QQ是否已被注册
* @param string qq 用户提交的qq字段
* @access protected
* */
protected function checkQq($qq)
{
$mo = new Model();
$mo->table('__USERS__');
if (empty($mo->where(array('qq' => $qq))->find())) {
return true;
} else {
return false;
}
}
示例12: get_num_odr
function get_num_odr($oid)
{
$model = new Model('OrderGoods');
$list = $model->where('order_id=' . $oid)->select();
$num = 0;
foreach ($list as $row) {
$num += $row['quantity'];
}
return $num;
}
示例13: init_verify_token
function init_verify_token($token)
{
if ($token == '') {
err_ret(-205, 'lack of param xtoken', '缺少xtoken参数');
}
$model = new Model('user_info');
$condition['xtoken'] = $token;
$result = $model->where($condition)->select();
if (count($result) <= 0) {
err_ret(-505, 'tokan is invalid', 'token 失效');
}
}
示例14: lists
/**
* 列表
*/
public function lists($status = null)
{
$model = new GoodsModel();
$map = array();
$status_view = array('default' => '所有', 'del' => '已删除', 'forbid' => '禁用', 'allow' => '正常');
//查询条件 处理
$map['store_id'] = STID;
$store_M = new Model('Store');
$store_info = $store_M->find(STID);
if (empty($store_info)) {
$this->error('店铺不存在');
}
$this->assign('store_info', $store_info);
//店铺信息
if (isset($status) && key_exists($status, GoodsModel::$mystat)) {
//指定查询状态
$map['status'] = GoodsModel::$mystat[$status];
$now_status = $status_view[$status];
} else {
$map['status'] = array('EGT', 0);
//默认查询状态为未删除的数据
$now_status = $status_view['default'];
}
/******************/
$list = $this->_lists($model, $map);
$this->assign('list', $list);
//列表
$this->assign('now_status', $now_status);
//当前页面筛选的状态
if (!empty($list)) {
$cate_M = new Model('Category');
$cate_ids = field_unique($list, 'cate_id');
//列表中用到的会员ID
$map = array('id' => array('in', $cate_ids));
$catelist = $cate_M->where($map)->getField('id,cate_name');
$this->assign('catelist', $catelist);
//列表用到的分类, ID为key索引
}
/*****用于添加商品的商品分类树**/
$catetreemap = array('store_id' => STID, 'status' => '1');
//只要状态正常商品分类
$cate_M = new CategoryModel();
$cate_tree = $cate_M->ztreeArr($catetreemap);
$cate_tree = array_merge(array(array('id' => 0, 'pId' => 0, 'name' => '无分类', 'open' => true)), $cate_tree);
$cate_tree = json_encode($cate_tree);
$this->assign('tree_json', $cate_tree);
//category ztree json
// 记录当前列表页的cookie
cookie(C('CURRENT_URL_NAME'), $_SERVER['REQUEST_URI']);
$this->display();
}
示例15: delete
public function delete()
{
$id = I('id');
if (empty($id)) {
$this->error('缺少参数');
}
$this->checkLogin();
$model = new Model('Message');
$result = $model->where(array('message_id' => $id, 'user_id' => session('user.userId')))->find();
if (!$result) {
$this->error('删除失败');
}
$this->success('删除成功', U('index'));
}