更新
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\adminapi\lists\tcm;
|
||||
|
||||
use app\adminapi\lists\BaseAdminDataLists;
|
||||
use app\common\model\tcm\PrescriptionLibrary;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
|
||||
/**
|
||||
* 处方库列表
|
||||
*/
|
||||
class PrescriptionLibraryLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
{
|
||||
/**
|
||||
* @notes 设置搜索条件
|
||||
*/
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'%like%' => ['prescription_name'],
|
||||
'=' => ['is_public', 'creator_id']
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取列表
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
$field = [
|
||||
'id', 'prescription_name', 'herbs', 'is_public',
|
||||
'creator_id', 'creator_name', 'create_time', 'update_time'
|
||||
];
|
||||
|
||||
$lists = PrescriptionLibrary::where($this->searchWhere)
|
||||
->where(function ($query) {
|
||||
// 只显示自己创建的或公开的处方
|
||||
$query->where('creator_id', $this->adminId)
|
||||
->whereOr('is_public', 1);
|
||||
})
|
||||
->field($field)
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order('id', 'desc')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
// 解析药材JSON
|
||||
foreach ($lists as &$item) {
|
||||
if (!empty($item['herbs'])) {
|
||||
$item['herbs'] = json_decode($item['herbs'], true);
|
||||
} else {
|
||||
$item['herbs'] = [];
|
||||
}
|
||||
}
|
||||
|
||||
return $lists;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取数量
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return PrescriptionLibrary::where($this->searchWhere)
|
||||
->where(function ($query) {
|
||||
// 只统计自己创建的或公开的处方
|
||||
$query->where('creator_id', $this->adminId)
|
||||
->whereOr('is_public', 1);
|
||||
})
|
||||
->count();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user