engineering/app/adminapi/lists/custom/CustomLists.php
2024-03-14 15:34:33 +08:00

115 lines
3.4 KiB
PHP

<?php
namespace app\adminapi\lists\custom;
use app\adminapi\lists\BaseAdminDataLists;
use app\common\lists\ListsExcelInterface;
use app\common\lists\ListsSearchInterface;
use app\common\model\auth\Admin;
use app\common\model\custom\Custom;
use app\common\model\custom\CustomFollow;
use app\common\model\GeoCity;
use app\common\model\GeoProvince;
/**
* Custom列表
* Class CustomLists
* @package app\adminapi\listscustom
*/
class CustomLists extends BaseAdminDataLists implements ListsSearchInterface,ListsExcelInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2023/11/11 22:10
*/
public function setSearch(): array
{
return [
'=' => ['custom_type', 'phone', 'province'],
'%like%' => ['name','master_name']
];
}
/**
* @notes 获取列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author likeadmin
* @date 2023/11/11 22:10
*/
public function lists(): array
{
return Custom::field('id,name,custom_type,province,notes,master_name,master_position,master_telephone,master_phone,master_notes,add_user,create_time')
->where($this->searchWhere)->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()->each(function($data){
$admin = Admin::field('id,name')->where('id',$data['add_user'])->findOrEmpty();
$province = GeoProvince::field('province_name')->where('province_code',$data['province'])->findOrEmpty();
$city = GeoCity::field('city_name')->where('city_code',$data['city'])->findOrEmpty();
$customFollow = CustomFollow::field('date,next_follow_date')->where('custom_id', $data['id'])->order('id', 'desc')->limit(1)->findOrEmpty();
$data['next_follow_date'] = $customFollow['next_follow_date'];
$data['last_follow_date'] = $customFollow['date'];
$data['follow_total'] = CustomFollow::where('custom_id', $data['id'])->count();
$data['add_user_name'] = $admin['name'];
$data['province_name'] = $province['province_name'];
$data['city_name'] = $city['city_name'];
$data['custom_type_text'] = $data->custom_type_text;
unset($data['province'],$data['add_user']);
})
->toArray();
}
/**
* @notes 获取数量
* @return int
* @author likeadmin
* @date 2023/11/11 22:10
*/
public function count(): int
{
return Custom::where($this->searchWhere)->count();
}
/**
* @notes 导出文件名
* @return string
* @author 段誉
* @date 2022/11/24 16:17
*/
public function setFileName(): string
{
return '客户列表';
}
/**
* @notes 导出字段
* @return string[]
* @author 段誉
* @date 2022/11/24 16:17
*/
public function setExcelFields(): array
{
return [
'id' => 'id',
'name' => '客户名称',
'custom_type' => '客户属性',
'province_name' => '所在省',
'master_name' => '负责人姓名',
'master_position' => '负责人职务',
'master_telephone' => '负责人电话',
'master_phone' => '负责人手机',
'follow_total' => '跟进记录',
'last_follow_date' => '最后跟进',
'next_follow_date' => '下次回访日期',
'create_time' => '创建时间',
];
}
}