#视图查询
多个表不同表前缀问题
别名法
~~~
$data_list = self::view(['oxygen_withdraw_change'=>'withdraw_change'])
->view('admin_user', 'username', 'admin_user.id=oxygen_withdraw_change.uid', 'left')
->select();
~~~
table指定法,table前的view里一定要传同样表名
~~~
$data_list = self::view('oxygen_withdraw_change')
->table('oxygen_withdraw_change')
->view('admin_user', 'username', 'admin_user.id=oxygen_withdraw_change.uid', 'left')
->select();
~~~
# 复杂查询
~~~
$post = [
'client_id' => $client_id,
'tab' => $tab,
'name' => $name,
'create_time' => $create_time,
'stage' => $stage,
'status' => $status,
'type' => $type
];
$client_index_status = Cases::$client_index_status;
$client_status = Cases::$client_status + Cases::$status;
$row_list = Cases::where(function($query) use($post, $client_index_status, $client_status){
$query->where('client_id', $post['client_id']);
if($post['tab'] == '待处理'){
$query->where('status', 'in', array_keys($client_index_status));
}
if($post['name']){
$name = $post['name'];
$query->where("(name like '%{$name}%' OR apply_no like '%{$name}%' OR applicant like '%{$name}%')");
}
if ($post['create_time']) {
$query->where('create_time', 'between time', explode(',', $post['create_time']));
}
if($post['stage'] && $post['status']){
$query->where('stage', $post['stage']);
switch ($post['stage']) {
case 0:
$status = array_keys([
"0001"=>"已撤回",
"0002"=>"稿件已确认",
"0003"=>"驳回放弃",
"0004"=>"结束已失效",
"0005"=>"驳回再申请",
"0006"=>"已失效"
], $post['status']);
break;
case 1:
$status = array_keys([
"1001"=>"待支付",
"1002"=>"待审核",
"1003"=>"待修改",
"1004"=>"分配中",
], $post['status']);
break;
case 2:
$status = array_keys([
"2001"=>"起名中",
"2002"=>"起名待确认",
"2003"=>"起名中",
"2004"=>"撰写中",
"2005"=>"撰写中",
"2006"=>"待确认",
"2007"=>"撰写中",
], $post['status']);
break;
case 3:
$status = array_keys([
"3003"=>"已受理",
"3004"=>"补正中",
"3005"=>"补正中",
"3006"=>"补正待确认",
"3007"=>"补正中",
"3008"=>"递交中",
"3009"=>"递交中",
]
, $post['status']);
break;
case 4:
$status = ['4001'];
break;
case 5:
$status = array_keys([
"5001"=>"实审中",
"5002"=>"答复中",
"5003"=>"答复中",
"5004"=>"答复中",
"5005"=>"答复待确认",
"5006"=>"答复待递交",
"5007"=>"答复中",
"5008"=>"驳回待确认",
"5009"=>"待授权"
]
, $post['status']);
break;
case 6:
$status = array_keys([
"6001"=>"生效中",
"6002"=>"待缴纳年费",
], $post['status']);
break;
default:
break;
}
$query->where('status', 'in', $status);
}
if($post['type']){
$query->where('type', $post['type']);
}
})
->order('id DESC')
->paginate($list_rows)
->each(function ($item, $key) {
$item['stage_text'] = $item['stage_text'];
$item['client_status_text'] = $item['client_status_text'];
$item['left_days'] = $item['left_days'];
$item['applicant_text'] = $item['applicant_text'];
return $item;
});
~~~