<?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 -1second'],
'yesterday' => ['yesterday', 'today -1second'],
'week' => ['this week 00:00:00', 'next week 00:00:00 -1second'],
'last week' => ['last week 00:00:00', 'this week 00:00:00 -1second'],
'month' => ['first Day of this month 00:00:00', 'first Day of next month 00:00:00 -1second'],
'last month' => ['first Day of last month 00:00:00', 'first Day of this month 00:00:00 -1second'],
'year' => ['this year 1/1', 'next year 1/1 -1second'],
'last year' => ['last year 1/1', 'this year 1/1 -1second'],
];
/**
* 日期查询快捷定义
* @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()
{
$query = new static($this->connection);
if ($this->model) {
$query->model($this->model);
}
if (isset($this->options['table'])) {
$query->table($this->options['table']);
} else {
$query->name($this->name);
}
if (isset($this->options['json'])) {
$query->json($this->options['json'], $this->options['json_assoc']);
}
if (isset($this->options['field_type'])) {
$query->setJsonFieldType($this->options['field_type']);
}
return $query;
}
/**
* 利用__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;
}
/**
没有合适的资源?快使用搜索试试~ 我知道了~
【源码编号 : MF00643】基于thinkphp的wms进销存源码
共561个文件
php:312个
html:78个
js:56个
需积分: 5 0 下载量 139 浏览量
2024-04-16
22:21:55
上传
评论
收藏 4.77MB RAR 举报
温馨提示
一、基于 ThinkPHP 5.1(LTS版本)开发wms 进销存系统 管理员账号密码:admin 二、实现功能 控制台 权限(用户管理、角色管理、节点) 订单(采购订单、销售订单) 仓库(采购入库,销售出库) 基础资料(产品管理、产品分类、客户管理、品牌管理) 三、技术选型 php mysql html css js
资源推荐
资源详情
资源评论
收起资源包目录
【源码编号 : MF00643】基于thinkphp的wms进销存源码 (561个子文件)
run.bat 13B
bootstrap.min.css 132KB
main.css 105KB
style.css 34KB
style.css 31KB
font-awesome.min.css 30KB
style.min.css 29KB
style.min.css 27KB
theme.css 20KB
layer.css 15KB
layer.css 14KB
layer.css 14KB
bootstrap-table.min.css 12KB
laydate.css 8KB
palette.1.css 7KB
layer.css 6KB
toastr.min.css 6KB
layer.css 5KB
layer.css 5KB
style.css 3KB
style.css 3KB
style.css 3KB
combo.select.css 3KB
bootstrap-table-jumpto.css 148B
phpunit.xml.dist 1KB
iconfont.eot 2KB
hiddeninput.exe 9KB
1.gif 1.13MB
loading-0.gif 6KB
loading-0.gif 6KB
loading-0.gif 6KB
loading-2.gif 2KB
loading-2.gif 2KB
loading-2.gif 2KB
throbber.gif 1KB
throbber.gif 1KB
loading-1.gif 701B
loading-1.gif 701B
loading-1.gif 701B
.gitignore 84B
.gitignore 37B
.gitignore 28B
.gitignore 13B
.htaccess 216B
.htaccess 13B
.htaccess 13B
index.html 9KB
index - 副本.html 9KB
edit.html 7KB
select.html 6KB
edit.html 6KB
edit.html 6KB
edit.html 6KB
create.html 6KB
create.html 6KB
create.html 6KB
create.html 6KB
prints.html 6KB
prints.html 6KB
index.html 6KB
edit.html 6KB
edit.html 5KB
edit.html 5KB
create.html 5KB
index.html 5KB
index.html 5KB
create.html 5KB
create.html 5KB
index.html 5KB
index.html 4KB
base.html 4KB
create.html 4KB
index.html 4KB
bootstrap-table.html 4KB
index.html 4KB
main - 副本 (2).html 4KB
edit.html 4KB
prints.html 4KB
main - 副本.html 4KB
index.html 4KB
index.html 4KB
edit.html 3KB
prints.html 3KB
index.html 3KB
sidebar - 副本.html 3KB
index.html 3KB
index.html 3KB
index.html 3KB
edit.html 3KB
edit.html 3KB
index.html 3KB
edit.html 3KB
create.html 3KB
create.html 3KB
edit.html 3KB
oauth.html 3KB
create.html 3KB
index.html 3KB
index.html 3KB
edit.html 3KB
共 561 条
- 1
- 2
- 3
- 4
- 5
- 6
资源评论
HongYingClub
- 粉丝: 771
- 资源: 100
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功