<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
namespace think\db;
use PDO;
use think\Collection;
use think\Container;
use think\Db;
use think\db\exception\BindParamException;
use think\db\exception\DataNotFoundException;
use think\db\exception\ModelNotFoundException;
use think\Exception;
use think\exception\DbException;
use think\exception\PDOException;
use think\Loader;
use think\Model;
use think\model\Collection as ModelCollection;
use think\model\Relation;
use think\model\relation\OneToOne;
use think\Paginator;
class Query
{
/**
* 当前数据库连接对象
* @var Connection
*/
protected $connection;
/**
* 当前模型对象
* @var Model
*/
protected $model;
/**
* 当前数据表名称(不含前缀)
* @var string
*/
protected $name = '';
/**
* 当前数据表主键
* @var string|array
*/
protected $pk;
/**
* 当前数据表前缀
* @var string
*/
protected $prefix = '';
/**
* 当前查询参数
* @var array
*/
protected $options = [];
/**
* 当前参数绑定
* @var array
*/
protected $bind = [];
/**
* 事件回调
* @var array
*/
private static $event = [];
/**
* 扩展查询方法
* @var array
*/
private static $extend = [];
/**
* 读取主库的表
* @var array
*/
protected static $readMaster = [];
/**
* 日期查询表达式
* @var array
*/
protected $timeRule = [
'today' => ['today', 'tomorrow'],
'yesterday' => ['yesterday', 'today'],
'week' => ['this week 00:00:00', 'next week 00:00:00'],
'last week' => ['last week 00:00:00', 'this week 00:00:00'],
'month' => ['first Day of this month 00:00:00', 'first Day of next month 00:00:00'],
'last month' => ['first Day of last month 00:00:00', 'first Day of this month 00:00:00'],
'year' => ['this year 1/1', 'next year 1/1'],
'last year' => ['last year 1/1', 'this year 1/1'],
];
/**
* 日期查询快捷定义
* @var array
*/
protected $timeExp = ['d' => 'today', 'w' => 'week', 'm' => 'month', 'y' => 'year'];
/**
* 架构函数
* @access public
*/
public function __construct(Connection $connection = null)
{
if (is_null($connection)) {
$this->connection = Db::connect();
} else {
$this->connection = $connection;
}
$this->prefix = $this->connection->getConfig('prefix');
}
/**
* 创建一个新的查询对象
* @access public
* @return Query
*/
public function newQuery()
{
return new static($this->connection);
}
/**
* 利用__call方法实现一些特殊的Model方法
* @access public
* @param string $method 方法名称
* @param array $args 调用参数
* @return mixed
* @throws DbException
* @throws Exception
*/
public function __call($method, $args)
{
if (isset(self::$extend[strtolower($method)])) {
// 调用扩展查询方法
array_unshift($args, $this);
return Container::getInstance()
->invoke(self::$extend[strtolower($method)], $args);
} elseif (strtolower(substr($method, 0, 5)) == 'getby') {
// 根据某个字段获取记录
$field = Loader::parseName(substr($method, 5));
return $this->where($field, '=', $args[0])->find();
} elseif (strtolower(substr($method, 0, 10)) == 'getfieldby') {
// 根据某个字段获取记录的某个值
$name = Loader::parseName(substr($method, 10));
return $this->where($name, '=', $args[0])->value($args[1]);
} elseif (strtolower(substr($method, 0, 7)) == 'whereor') {
$name = Loader::parseName(substr($method, 7));
array_unshift($args, $name);
return call_user_func_array([$this, 'whereOr'], $args);
} elseif (strtolower(substr($method, 0, 5)) == 'where') {
$name = Loader::parseName(substr($method, 5));
array_unshift($args, $name);
return call_user_func_array([$this, 'where'], $args);
} elseif ($this->model && method_exists($this->model, 'scope' . $method)) {
// 动态调用命名范围
$method = 'scope' . $method;
array_unshift($args, $this);
call_user_func_array([$this->model, $method], $args);
return $this;
} else {
throw new Exception('method not exist:' . ($this->model ? get_class($this->model) : static::class) . '->' . $method);
}
}
/**
* 扩展查询方法
* @access public
* @param string|array $method 查询方法名
* @param callable $callback
* @return void
*/
public static function extend($method, $callback = null)
{
if (is_array($method)) {
foreach ($method as $key => $val) {
self::$extend[strtolower($key)] = $val;
}
} else {
self::$extend[strtolower($method)] = $callback;
}
}
/**
* 设置当前的数据库Connection对象
* @access public
* @param Connection $connection
* @return $this
*/
public function setConnection(Connection $connection)
{
$this->connection = $connection;
$this->prefix = $this->connection->getConfig('prefix');
return $this;
}
/**
* 获取当前的数据库Connection对象
* @access public
* @return Connection
*/
public function getConnection()
{
return $this->connection;
}
/**
* 指定模型
* @access public
* @param Model $model 模型对象实例
* @return $this
*/
public function model(Model $model)
{
$this->model = $model;
return $this;
}
/**
* 获取当前的模型对象
* @access public
* @return Model|null
*/
public function getModel()
{
return $this->model ? $this->model->setQuery($this) : null;
}
/**
* 设置从主库读取数据
* @access public
* @param bool $all 是否所有表有效
* @return $this
*/
public function readMaster($all = false)
{
$table = $all ? '*' : $this->getTable();
static::$readMaster[$table] = true;
return $this;
}
/**
* 指定当前数据表名(不含前缀)
* @access public
* @param string $name
* @return $this
*/
public function name($name)
{
$this->name = $name;
return $this;
}
/**
* 获取当前的数据表名称
* @access public
* @return string
*/
public function getName()
{
return $this->name ?: $this->model->getName();
}
/**
* 得到当前或者指定名称的数据表
* @access public
* @param string $name
* @return string
*/
public function getTable($name = '')
{
if (empty($name) && isset($this->options['table'])) {
return $this->options['table'];
}
$name = $name ?: $this->name;
return $this->prefix . Loader::parseName($name);
}
/**
* �
没有合适的资源?快使用搜索试试~ 我知道了~
基于PHP的LetuCRMPHP乐兔客户关系管理系统源码.zip
共688个文件
php:326个
js:120个
html:60个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 176 浏览量
2023-08-27
23:43:21
上传
评论
收藏 7.04MB ZIP 举报
温馨提示
基于PHP的LetuCRMPHP乐兔客户关系管理系统源码.zip
资源推荐
资源详情
资源评论
收起资源包目录
基于PHP的LetuCRMPHP乐兔客户关系管理系统源码.zip (688个子文件)
test.bmp 0B
weui.css 359KB
weui.css 359KB
jquery-weui.css 66KB
jquery-weui.css 66KB
jquery-weui.min.css 55KB
jquery-weui.min.css 55KB
weui.min.css 50KB
weui.min.css 50KB
summernote-lite.css 27KB
font-awesome.min.css 26KB
font-awesome.min.css 26KB
summernote.css 17KB
summernote-bs4.css 17KB
glyphicons.min.css 12KB
glyphicons.min.css 12KB
houtai.css 9KB
login.css 1KB
login.css 1KB
home.css 1KB
ajaxfileupload.css 468B
phpunit.xml.dist 1KB
fontawesome-webfont.eot 67KB
fontawesome-webfont.eot 67KB
glyphicons-halflings-regular.eot 20KB
glyphicons-halflings-regular.eot 20KB
ratchicons.eot 11KB
ratchicons.eot 11KB
summernote.eot 9KB
hiddeninput.exe 9KB
test.gif 233KB
loading.gif 4KB
.gitignore 84B
.gitignore 42B
.gitignore 29B
.gitignore 28B
.gitignore 16B
.gitignore 13B
.gitignore 13B
.gitignore 6B
.htaccess 216B
.htaccess 13B
.htaccess 13B
edit.html 27KB
add.html 25KB
flow_step_edit.html 15KB
view.html 14KB
member.html 14KB
view.html 12KB
flow_step.html 11KB
index.html 11KB
insurance_edit.html 10KB
index.html 10KB
index.html 10KB
insurance_add.html 10KB
index.html 8KB
member_view.html 8KB
index.html 8KB
index.html 7KB
insurance_view.html 7KB
index.html 7KB
aim_list.html 7KB
member_edit.html 7KB
member_add.html 7KB
my_insurance.html 6KB
customer_insurance.html 6KB
talk_script.html 6KB
index.html 6KB
edit.html 6KB
view.html 5KB
add.html 5KB
edit.html 5KB
view.html 5KB
view.html 5KB
add.html 5KB
edit.html 5KB
view.html 5KB
edit.html 5KB
add.html 5KB
add.html 5KB
edit.html 4KB
add.html 4KB
view.html 4KB
view.html 4KB
index.html 4KB
talk_script_view.html 4KB
letu_picker.html 4KB
talk_script_edit.html 3KB
talk_script_add.html 3KB
letu_picker_user.html 3KB
index.html 3KB
set_password.html 3KB
letu_picker_city.html 3KB
index.html 2KB
add_batch.html 2KB
index.html 2KB
bottom_nav.html 1KB
common_js.html 726B
login_js.html 505B
common_js.html 499B
共 688 条
- 1
- 2
- 3
- 4
- 5
- 6
- 7
资源评论
易小侠
- 粉丝: 6453
- 资源: 9万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功