更新
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace app\adminapi\lists\doctor;
|
||||
|
||||
use app\adminapi\lists\BaseAdminDataLists;
|
||||
use app\common\model\doctor\Medicine;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
|
||||
/**
|
||||
* 药品库列表
|
||||
*/
|
||||
class MedicineLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
{
|
||||
/**
|
||||
* 设置搜索条件
|
||||
*/
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'%like%' => ['supplier'],
|
||||
'=' => ['status'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* name 参数:中文等按名称模糊;纯英文字母按拼音首字母字段 + 名称模糊(OR)
|
||||
*/
|
||||
private function appendMedicineNameSearch($query): void
|
||||
{
|
||||
$keyword = trim((string) ($this->params['name'] ?? ''));
|
||||
if ($keyword === '') {
|
||||
return;
|
||||
}
|
||||
if (preg_match('/^[a-zA-Z]+$/', $keyword)) {
|
||||
$kw = strtolower($keyword);
|
||||
$query->where(function ($q) use ($kw, $keyword) {
|
||||
$q->where('name_pinyin_abbr', 'like', '%' . $kw . '%')
|
||||
->whereOr('name', 'like', '%' . $keyword . '%');
|
||||
});
|
||||
} else {
|
||||
$query->where('name', 'like', '%' . $keyword . '%');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表字段
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
$query = Medicine::where($this->searchWhere);
|
||||
$this->appendMedicineNameSearch($query);
|
||||
|
||||
return $query
|
||||
->field([
|
||||
'id', 'name', 'name_pinyin_abbr', 'supplier', 'unit',
|
||||
'settlement_price', 'retail_price', 'stock',
|
||||
'image', 'status', 'remark',
|
||||
'create_time', 'update_time',
|
||||
])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()
|
||||
->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表数量
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
$query = Medicine::where($this->searchWhere);
|
||||
$this->appendMedicineNameSearch($query);
|
||||
|
||||
return $query->count();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user