laravel 中条件查询 function模式
当需要条件查找时,可以使用下面的注入方法:
//我要预约 yudoc_name yudoc_keshi yudoc_jibing yudoc_hospital 这是需要帅选的条件
public function userYuYueDoc(Request $r) {
$data = $r->all();
//获取医生
$res = \DB::table('dxjk_yudoc')
->where('yudoc_status',2)
->where(function($query)use($data){
if($data['yudoc_name'] !== ''){//这一步成立才会查询
$query->where('yudoc_name','like', '%'.$data['yudoc_name'].'%');
}
})
->where(function($query)use($data){
if($data['yudoc_jibing'] !== ''){
//按疾病查找
$jibing_res = \DB::table('dxjk_yudoc')
->select('yudoc_id','yudoc_jibing')
->get();
$doc_id = array();
if(!empty($jibing_res)){
foreach($jibing_res as $key => $val){
$val->yudoc_jibing = json_decode($val->yudoc_jibing,true);
if(in_array($data['yudoc_jibing'],$val->yudoc_jibing)){
array_push($doc_id,$val->yudoc_id);
}
}
}
$doc_id = array_unique($doc_id);
$query->whereIn('yudoc_id', $doc_id);
}
})
->where(function($query)use($data){
if($data['yudoc_keshi'] !== ''){
$query->where('yudoc_keshi', $data['yudoc_keshi']);
}
})
->where(function($query)use($data){
if($data['yudoc_hospital'] !== ''){
//查找该医院所属医生,并去重,组成数组
$doc_res = \DB::table('dxjk_docwork')
->select('docwork_yid')
->where('docwork_hospital',$data['yudoc_hospital'])
->get();
$doc_id = array();
if(!empty($doc_res)){
foreach($doc_res as $key => $val){
array_push($doc_id,$val->docwork_yid);
}
}
$doc_id = array_unique($doc_id);
$query->whereIn('yudoc_id', $doc_id);
}
})
->orderBy('yudoc_tuijian')
->paginate(10)
->toArray();
if (!empty($res['data'])) {
//将查询的时间和图片处理下
$basePath = base_path();
$basePath = $basePath."/public/uploads";
foreach($res['data'] as $key => $val){
//获取医生的出诊医院
$hospital = \DB::table('dxjk_docwork')
->select('docwork_hospital')
->where('docwork_yid',$val->yudoc_id)
->distinct()
->get();
if(!empty($hospital)){
$val->yudoc_hospital = $hospital;
$yudoc_money = \DB::table('dxjk_docwork')
->select('docwork_money')
->where('docwork_yid',$val->yudoc_id)
->where('docwork_hospital',$hospital[0]->docwork_hospital)
->distinct()
->get();
$val->yudoc_money = $yudoc_money[0]->docwork_money;
} $val->yudoc_time = date('Y-m-d',$val->yudoc_time);
$val->yudoc_pic = json_decode($val->yudoc_pic,true);
if(!empty($val->yudoc_pic)){
foreach($val->yudoc_pic as $k => $v){
// $img_file = $basePath.$v;
// $img_info = getimagesize($img_file);
// $val->yudoc_pic[$k] = "data:{$img_info['mime']};base64," . base64_encode(file_get_contents($img_file));
$val->yudoc_pic[$k] = self::urlPic . $v;
}
}
$val->yudoc_jibing = json_decode($val->yudoc_jibing,true);
}
return ['code' => 1000, 'data' => $res];
}else{
return ['code' => 1001, 'data' => ['message' => '未查到医生!']];
} }
laravel 中条件查询 function模式的更多相关文章
- Laravel中服务提供者和门面模式
在laravel中,我们可能需要用到自己添加的类时,可以建立一个文件夹专门存放类文件,也可以使用laravel的服务提供者的方式来使用. 这两者其实区别不大,主要是前者使用的话,会跟业务代码产生依赖, ...
- laravel中通过查询构造器,实现数据的curd
//查询构造器: public function query1(){ //利用查询构造器,插入数据: /*$num=DB::table('student')->insert( ['name'=& ...
- laravel 中数据库查询结果自动转数组
今天在项目中再次碰见laravel中从数据库中查询到的结果是对象,用toArray也不好用,之前改过一次,印象中是在/confing/database.php, 'fetch' => PD ...
- Mysql数据库中条件查询
1.concat(字符串拼接) 作用:将选中的列进行拼接 写法 AS的作用就是属性名 SELECT CONCAT(ename,job) AS 你猜 FROM emp; 2.条件查询 语法: sele ...
- laravel多条件查询,及分页
$res = DtkModel::where('ID','>','1')->select("ID")->get()->paginate(20);//不成立 ...
- Laravel中的查询构造器
public function query(){ //新增数据 //$bool = DB::table('wd_user')->insert(['username'=>'jack']); ...
- laravel 多条件查询
select * from homework where (id between 1 and 10 or id between 50 and 70) and complete = 1 and (tit ...
- laravel多条件查询(and,or嵌套查询)
原生sql select * from homework where (id between 1 and 10 or id between 50 and 70) and complete = 1 an ...
- laravel带条件查询手动分页
后台php代码: //手动分页 $users = $kaoqin; //打算输出的数组,二维 $perPage = 10; if ($request->has('page')) { $curre ...
随机推荐
- docker 使用mysql
mysql 5.7安装成功了,之前5.6一直报错不知道为什么 sudo docker run --name emall_mysql -e MYSQL_ROOT_PASSWORD=jbt1234 -e ...
- Longest Substring Without Repeating Characters,求没有重复字符的最长字串
问题描述: Given a string, find the length of the longest substring without repeating characters. Example ...
- 微信app支付java后台流程、原理分析及nei网穿透
一.流程步骤 本实例是基于springmvc框架编写 1.执行流程 当手机端app(就是你公司开发的app)在支付页面时,调起服务端(后台第1个创建订单接口)接口,后台把需要调起微 ...
- Java条件语句之多重 if
多重 if 语句,在条件 1 不满足的情况下,才会进行条件 2 的判断:当前面的条件均不成立时,才会执行 else 块内的代码.例如,如果考试成绩大于 90 分,则奖励一个 IPHONE 5S ,如果 ...
- gitlab 备份
gitlab 备份 gitlab-rake gitlab:backup:create 执行之后,就会生成一个备份文件 [root@iZuf6dztc469onegfborf5Z backups]# l ...
- DPDK编程指南 2.概述
本章节给出了DPDK架构的一个全局概述. DPDK的主要目的就是为数据面快速报文处理应用程序提供一个简洁完整的框架.用户可以通过代码来理解其中使用的一些技术,构建自己的应用程序或添加自己的协议栈.Al ...
- leetcode 2SUM
; i < numbers.size(); ++i){ ; i < v.size(); i++){ ; j < v.size ...
- Ajax基础(五)--封装库
jQuery ajax请求的基本语法: 一.封装为对象: ajax.txt代码: {"id":"102","username":" ...
- 扫描局域网中Gogs服务器(ruby)
scanGogs.rb #!/usr/bin/env ruby require 'net/http' require 'thread' require 'english' # config CONFI ...
- react-router路由
1.http://blog.csdn.net/sunshine215/article/details/78296404(react-router v4 使用 history 控制路由跳转) 2.htt ...