Files
zyt/server/app/adminapi/lists/qywx/CustomerLists.php
T

66 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
namespace app\adminapi\lists\qywx;
use app\common\lists\BaseDataLists;
use app\common\lists\ListsSearchInterface;
use app\common\model\QywxExternalContact;
/**
* 企业微信客户列表
*/
class CustomerLists extends BaseDataLists implements ListsSearchInterface
{
/**
* @notes 搜索条件
*/
public function setSearch(): array
{
return [
'%like%' => ['name', 'follow_user'],
];
}
/**
* @notes 获取列表
*/
public function lists(): array
{
try {
$lists = QywxExternalContact::where($this->searchWhere)
->order('id', 'desc')
->limit($this->limitOffset, $this->limitLength)
->select()
->toArray();
foreach ($lists as &$item) {
// 解析跟进人JSON(如果字段存在)
if (isset($item['follow_users'])) {
$followUsers = json_decode($item['follow_users'] ?? '[]', true);
$item['follow_users'] = is_array($followUsers) ? $followUsers : [];
} else {
$item['follow_users'] = [];
}
}
return $lists;
} catch (\Throwable $e) {
return [];
}
}
/**
* @notes 获取总数
*/
public function count(): int
{
try {
return QywxExternalContact::where($this->searchWhere)->count();
} catch (\Throwable $e) {
return 0;
}
}
}