96 lines
2.8 KiB
PHP
96 lines
2.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace app\adminapi\lists\order;
|
|
|
|
use app\adminapi\lists\BaseAdminDataLists;
|
|
use app\common\lists\ListsSearchInterface;
|
|
use app\common\model\Order;
|
|
|
|
/**
|
|
* 订单列表
|
|
* Class OrderLists
|
|
* @package app\adminapi\lists\order
|
|
*/
|
|
class OrderLists extends BaseAdminDataLists implements ListsSearchInterface
|
|
{
|
|
/**
|
|
* @notes 设置搜索条件
|
|
* @return array
|
|
*/
|
|
public function setSearch(): array
|
|
{
|
|
return [
|
|
'=' => ['order_type', 'status'],
|
|
'like' => ['order_no'],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @notes 获取列表
|
|
* @return array
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
*/
|
|
public function lists(): array
|
|
{
|
|
$where = $this->searchWhere;
|
|
|
|
// 处理患者关键词搜索
|
|
if (!empty($this->params['patient_keyword'])) {
|
|
$where[] = ['patient_id', 'in', function ($query) {
|
|
$query->table('user')
|
|
->where('nickname|mobile', 'like', '%' . $this->params['patient_keyword'] . '%')
|
|
->field('id');
|
|
}];
|
|
}
|
|
|
|
// 处理创建时间范围
|
|
if (!empty($this->params['create_time_start'])) {
|
|
$where[] = ['create_time', '>=', $this->params['create_time_start'] . ' 00:00:00'];
|
|
}
|
|
|
|
if (!empty($this->params['create_time_end'])) {
|
|
$where[] = ['create_time', '<=', $this->params['create_time_end'] . ' 23:59:59'];
|
|
}
|
|
|
|
return Order::where($where)
|
|
->with(['patient', 'creator', 'details'])
|
|
->order(['create_time' => 'desc'])
|
|
->limit($this->limitOffset, $this->pageSize)
|
|
->select()
|
|
->toArray();
|
|
}
|
|
|
|
/**
|
|
* @notes 获取数量
|
|
* @return int
|
|
*/
|
|
public function count(): int
|
|
{
|
|
$where = $this->searchWhere;
|
|
|
|
// 处理患者关键词搜索
|
|
if (!empty($this->params['patient_keyword'])) {
|
|
$where[] = ['patient_id', 'in', function ($query) {
|
|
$query->table('user')
|
|
->where('nickname|mobile', 'like', '%' . $this->params['patient_keyword'] . '%')
|
|
->field('id');
|
|
}];
|
|
}
|
|
|
|
// 处理创建时间范围
|
|
if (!empty($this->params['create_time_start'])) {
|
|
$where[] = ['create_time', '>=', $this->params['create_time_start'] . ' 00:00:00'];
|
|
}
|
|
|
|
if (!empty($this->params['create_time_end'])) {
|
|
$where[] = ['create_time', '<=', $this->params['create_time_end'] . ' 23:59:59'];
|
|
}
|
|
|
|
return Order::where($where)->count();
|
|
}
|
|
}
|