当需要条件查找时,可以使用下面的注入方法:

//我要预约 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模式的更多相关文章

  1. Laravel中服务提供者和门面模式

    在laravel中,我们可能需要用到自己添加的类时,可以建立一个文件夹专门存放类文件,也可以使用laravel的服务提供者的方式来使用. 这两者其实区别不大,主要是前者使用的话,会跟业务代码产生依赖, ...

  2. laravel中通过查询构造器,实现数据的curd

    //查询构造器: public function query1(){ //利用查询构造器,插入数据: /*$num=DB::table('student')->insert( ['name'=& ...

  3. laravel 中数据库查询结果自动转数组

    今天在项目中再次碰见laravel中从数据库中查询到的结果是对象,用toArray也不好用,之前改过一次,印象中是在/confing/database.php,    'fetch' => PD ...

  4. Mysql数据库中条件查询

    1.concat(字符串拼接) 作用:将选中的列进行拼接  写法 AS的作用就是属性名 SELECT CONCAT(ename,job) AS 你猜 FROM emp; 2.条件查询 语法: sele ...

  5. laravel多条件查询,及分页

    $res = DtkModel::where('ID','>','1')->select("ID")->get()->paginate(20);//不成立 ...

  6. Laravel中的查询构造器

    public function query(){ //新增数据 //$bool = DB::table('wd_user')->insert(['username'=>'jack']); ...

  7. laravel 多条件查询

    select * from homework where (id between 1 and 10 or id between 50 and 70) and complete = 1 and (tit ...

  8. laravel多条件查询(and,or嵌套查询)

    原生sql select * from homework where (id between 1 and 10 or id between 50 and 70) and complete = 1 an ...

  9. laravel带条件查询手动分页

    后台php代码: //手动分页 $users = $kaoqin; //打算输出的数组,二维 $perPage = 10; if ($request->has('page')) { $curre ...

随机推荐

  1. Matlab绘图基础——图形绘制的插值  以及 图像大小的重采样

    使用说明:图形绘制时的插值 interp1   %1-D data interpolation interpft  %使用fft算法插值     %将原数据x转换到频率域,再逆转换回来更密集的数据采样 ...

  2. hadoop 2.7.3 源码编译教程

    1.工具准备,最靠谱的是hadoop说明文档里要求具备的那些工具. 到hadoop官网,点击source下载hadoop-2.7.3-src.tar.gz. 解压之 tar -zxvf hadoop- ...

  3. AJAX基础知识点——思维导图

    如图 思维导图图片链接 http://www.edrawsoft.cn/viewer/public/s/4db2e712070147 有道云笔记链接 http://note.youdao.com/no ...

  4. Web Service简介

    1.1.Web Service基本概念 Web Service也叫XML Web Service WebService是一种可以接收从Internet或者Intranet上的其它系统中传递过来的请求, ...

  5. Android 通过名称获取资源ID

    当我们获取网络数据的时候,解析之后往往都是一个字符串,而不是资源id,所有我们没有办法直接使用,只能通过名称来获取到资源id, package com.example.administrator.de ...

  6. spring3: 内置Resource实现

    4.2  内置Resource实现 4.2.1  ByteArrayResource ByteArrayResource代表byte[]数组资源,对于“getInputStream”操作将返回一个By ...

  7. yii定时任务(linux)

    yii写好了,计划任务,那么需要测试,测试地址大致: 我的测试文件名称:TestControllers.php, windows环境下: 我的项目在f:\www下, CMD: f:/www/ php ...

  8. .Net Core使用jexus配置https

    今天搞了一下怎么从http换成https,写一篇博客记录该过程.关于jexus的安装和使用请看我之前的一篇博客<Jexus部署Asp.Net Core项目>,唯一的不同是,将jexus升级 ...

  9. Android 性能测试小工具 Emmagee

    Emmagee 是一个性能测试小工具 用来监控指定被测应用在使用过程中占用机器的CPU, 内存,流量资源的性能小工具 Emmagee 介绍 Emmagee是网易杭州研究院QA团队开发的一个简单易上手的 ...

  10. Appium 自动化测试(5)-- Appium详细介绍:Appium 手机自动化测试_TesterHome公开版pdf