feat: 添加代理商分页/导出/企业规模列表接口

This commit is contained in:
2025-03-13 18:01:36 +08:00
parent b9d4a7b27e
commit 3705434150
11 changed files with 350 additions and 12 deletions

View File

@@ -0,0 +1,139 @@
<?php
declare (strict_types = 1);
namespace app\admin\controller\v1;
use app\admin\model\v1\AgentEnterpriseSizeTypeModel;
use app\admin\model\v1\AgentModel;
/**
* 代理商数据控制器
*/
class Agent
{
// 企业规模列表
public function enterpriseSizeTypes()
{
$types = AgentEnterpriseSizeTypeModel::field([
'name',
'value'
])
->language(request()->lang_id)
->order(['sort' => 'asc', 'id' => 'desc'])
->select();
return success('获取成功', $types);
}
// 分页
public function index()
{
$param = request()->param([
'corp_name',
'size_type',
'created_at',
'page/d' => 1,
'size/d' => 10
]);
$agents = AgentModel::field([
'id',
'ip',
'corp_name',
'email',
'phone',
'business_type',
'enterprise_size',
'address',
'message',
'created_at'
])
->with([
'businessType' => function ($query) {
$query->field(['name' => 'business_type_name', 'value']);
},
'enterpriseSizeType' => function ($query) {
$query->field(['name' => 'enterprise_size_name', 'value']);
}
])
->withSearch(['corp_name', 'created_at'], [
'corp_name' => $param['corp_name'] ?? null,
'created_at' => !empty($param['created_at']) ? explode(',', $param['created_at']) : null
])
->language(request()->lang_id)
->enterpriseSize($param['size_type'] ?? null)
->order(['id' => 'desc'])
->paginate([
'list_rows' => $param['size'],
'page' => $param['page'],
])
->bindAttr('businessType', ['business_type_name'])
->bindAttr('enterpriseSizeType', ['enterprise_size_name'])
->hidden(['business_type', 'businessType', 'enterprise_size', 'enterpriseSizeType']);
return success('获取成功', $agents);
}
// 导出
public function export()
{
$schema = [
'id' => 'ID',
'ip' => 'IP',
'corp_name' => '公司名称',
'email' => '邮箱',
'phone' => '手机号',
'business_type_name' => '业务类型',
'enterprise_size_name' => '企业规模',
'address' => '地址',
'message' => '留言内容',
'created_at' => '提交时间'
];
// 获取要导出的代理商数据
$agents = $this->getAgentExportData();
// 导出
return xlsx_writer($agents, $schema);
}
// 获取要导出的代理商数据
private function getAgentExportData()
{
$param = request()->param([
'corp_name',
'size_type',
'created_at'
]);
return AgentModel::field([
'id',
'ip',
'corp_name',
'email',
'phone',
'business_type',
'enterprise_size',
'address',
'message',
'created_at'
])
->with([
'businessType' => function ($query) {
$query->field(['name' => 'business_type_name', 'value']);
},
'enterpriseSizeType' => function ($query) {
$query->field(['name' => 'enterprise_size_name', 'value']);
}
])
->withSearch(['corp_name', 'created_at'], [
'corp_name' => $param['corp_name'] ?? null,
'created_at' => !empty($param['created_at']) ? explode(',', $param['created_at']) : null
])
->language(request()->lang_id)
->enterpriseSize($param['size_type'] ?? null)
->order(['id' => 'desc'])
->select()
->bindAttr('businessType', ['business_type_name'])
->bindAttr('enterpriseSizeType', ['enterprise_size_name'])
->hidden(['business_type', 'businessType', 'enterprise_size', 'enterpriseSizeType']);
}
}

View File

@@ -0,0 +1,19 @@
<?php
declare (strict_types = 1);
namespace app\admin\model\v1;
use app\common\model\AgentBusinessTypeBaseModel;
/**
* 代理商业务类型模型
* @mixin \think\Model
*/
class AgentBusinessTypeModel extends AgentBusinessTypeBaseModel
{
// 按语言查询
public function scopeLanguage($query, $value)
{
$query->where('language_id', '=', $value);
}
}

View File

@@ -0,0 +1,19 @@
<?php
declare (strict_types = 1);
namespace app\admin\model\v1;
use app\common\model\AgentEnterpriseSizeTypeBaseModel;
/**
* 代理商企业规模类型模型
* @mixin \think\Model
*/
class AgentEnterpriseSizeTypeModel extends AgentEnterpriseSizeTypeBaseModel
{
// 按语言查询
public function scopeLanguage($query, $value)
{
$query->where('language_id', '=', $value);
}
}

View File

@@ -0,0 +1,58 @@
<?php
declare (strict_types = 1);
namespace app\admin\model\v1;
use app\common\model\AgentBaseModel;
/**
* 代理商数据模型
* @mixin \think\Model
*/
class AgentModel extends AgentBaseModel
{
// 关联业务类型
public function businessType()
{
return $this->belongsTo(AgentBusinessTypeModel::class, 'business_type', 'value');
}
// 关联企业规模类型
public function enterpriseSizeType()
{
return $this->belongsTo(AgentEnterpriseSizeTypeModel::class, 'enterprise_size', 'value');
}
// 按放言查询
public function scopeLanguage($query, $value)
{
$query->where('language_id', '=', $value);
}
// 按企业规模查询
public function scopeEnterpriseSize($query, $value)
{
if (is_null($value)) return;
$query->where('enterprise_size', '=', $value);
}
// 根据公司名称搜索
public function searchCorpNameAttr($query, $value)
{
if (is_null($value)) return;
$query->where('corp_name', 'like', "%{$value}%");
}
// 根据提交时间搜索
public function searchCreatedAtAttr($query, $value)
{
if (is_null($value)) return;
if (is_array($value)) {
if (count($value) > 1) {
$query->whereBetweenTime('created_at', $value[0], $value[1]);
} else {
$query->whereTime('created_at', '>=', $value[0]);
}
}
}
}

View File

@@ -537,6 +537,18 @@ Route::group('v1', function () {
Route::get('export', 'BulkPurchaseInquiry/export'); Route::get('export', 'BulkPurchaseInquiry/export');
}); });
// 反馈管理 - 代理商申请列表
Route::group('agent', function() {
// 代理商企业规模类型
Route::get('enterprise_size_types', 'Agent/enterpriseSizeTypes');
// 代理商申请列表分页
Route::get('index', 'Agent/index');
// 代理商申请列表导出
Route::get('export', 'Agent/export');
});
// 配置项列表 // 配置项列表
Route::group('config', function() { Route::group('config', function() {
// 配置分组 // 配置分组

View File

@@ -0,0 +1,34 @@
<?php
declare (strict_types = 1);
namespace app\common\model;
/**
* 代理商数据模型
* @mixin \think\Model
*/
class AgentBaseModel extends BaseModel
{
// 表名
protected $name = 'agent';
// 主键
protected $pk = 'id';
// 字段信息
protected $schema = [
'id' => 'int',
'language_id' => 'int',
'corp_name' => 'string',
'email' => 'string',
'phone' => 'string',
'referer_url' => 'string',
'website_url' => 'string',
'business_type' => 'string',
'enterprise_size' => 'string',
'address' => 'string',
'message' => 'string',
'ip' => 'string',
'created_at' => 'datetime'
];
}

View File

@@ -0,0 +1,28 @@
<?php
declare (strict_types = 1);
namespace app\common\model;
/**
* 代理商业务类型模型
* @mixin \think\Model
*/
class AgentBusinessTypeBaseModel extends BaseModel
{
// 表名
protected $name = 'agent_business_type';
// 主键
protected $pk = 'id';
// 字段信息
protected $schema = [
'id' => 'int',
'language_id' => 'int',
'name' => 'string',
'value' => 'string',
'desc' => 'string',
'sort' => 'int',
'created_at' => 'datetime',
];
}

View File

@@ -0,0 +1,28 @@
<?php
declare (strict_types = 1);
namespace app\common\model;
/**
* 代理商企业规模类型模型
* @mixin \think\Model
*/
class AgentEnterpriseSizeTypeBaseModel extends BaseModel
{
// 表名
protected $name = 'agent_enterprise_size_type';
// 主键
protected $pk = 'id';
// 字段信息
protected $schema = [
'id' => 'int',
'language_id' => 'int',
'name' => 'string',
'value' => 'string',
'desc' => 'string',
'sort' => 'int',
'created_at' => 'datetime',
];
}

View File

@@ -32,14 +32,13 @@ class CreateAgent extends Migrator
->addColumn('corp_name', 'string', ['limit' => 64, 'null' => false, 'comment' => '公司名称']) ->addColumn('corp_name', 'string', ['limit' => 64, 'null' => false, 'comment' => '公司名称'])
->addColumn('email', 'string', ['limit' => 64, 'null' => false, 'comment' => '邮箱']) ->addColumn('email', 'string', ['limit' => 64, 'null' => false, 'comment' => '邮箱'])
->addColumn('phone', 'string', ['limit' => 64, 'null' => false, 'comment' => '电话']) ->addColumn('phone', 'string', ['limit' => 64, 'null' => false, 'comment' => '电话'])
->addColumn('website_url', 'string', ['limit' => 128, 'null' => false, 'comment' => '网站地址']) ->addColumn('referer_url', 'string', ['limit' => 255, 'null' => false, 'comment' => '来源URL'])
->addColumn('business_type', 'integer', ['null' => false, 'comment' => '业务类型']) ->addColumn('website_url', 'string', ['limit' => 255, 'null' => false, 'comment' => '网站URL'])
->addColumn('enterprise_size', 'integer', ['null' => false, 'comment' => '企业规模']) ->addColumn('business_type', 'string', ['limit' => 128, 'null' => false, 'comment' => '业务类型'])
->addColumn('province', 'string', ['limit' => 64, 'null' => true, 'default' => null, 'comment' => '']) ->addColumn('enterprise_size', 'string', ['limit' => 128, 'null' => false, 'comment' => '企业规模'])
->addColumn('city', 'string', ['limit' => 64, 'null' => true, 'default' => null, 'comment' => '市'])
->addColumn('district', 'string', ['limit' => 64, 'null' => true, 'default' => null, 'comment' => '区/县'])
->addColumn('address', 'string', ['limit' => 255, 'null' => true, 'default' => null, 'comment' => '地址']) ->addColumn('address', 'string', ['limit' => 255, 'null' => true, 'default' => null, 'comment' => '地址'])
->addColumn('message', 'text', ['null' => true, 'default' => null, 'comment' => '留言']) ->addColumn('message', 'text', ['null' => true, 'default' => null, 'comment' => '留言'])
->addColumn('ip', 'string', ['limit' => 64, 'null' => false, 'comment' => 'IP'])
->addColumn('created_at', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP', 'comment' => '创建时间']) ->addColumn('created_at', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP', 'comment' => '创建时间'])
->create(); ->create();
} }

View File

@@ -28,9 +28,10 @@ class CreateAgentBusinessType extends Migrator
public function change() public function change()
{ {
$table = $this->table('agent_business_type', ['engine' => 'MyISAM', 'comment' => '代理商业务类型表']); $table = $this->table('agent_business_type', ['engine' => 'MyISAM', 'comment' => '代理商业务类型表']);
$table->addColumn('cn_name', 'string', ['limit' => 64, 'null' => false, 'comment' => '业务类型名称']) $table->addColumn('language_id', 'integer', ['null' => false, 'default' => 0, 'comment' => '语言ID'])
->addColumn('en_name', 'string', ['limit' => 128, 'null' => false, 'comment' => '英文名称']) ->addColumn('name', 'string', ['limit' => 64, 'null' => false, 'comment' => '类型名'])
->addColumn('desc', 'string', ['limit' => 255, 'null' => true, 'default' => null, 'comment' => '业务类型描述']) ->addColumn('value', 'string', ['limit' => 64, 'null' => false, 'comment' => '类型值'])
->addColumn('desc', 'string', ['limit' => 255, 'null' => true, 'default' => null, 'comment' => '描述'])
->addColumn('sort', 'integer', ['null' => false, 'default' => 0, 'comment' => '排序']) ->addColumn('sort', 'integer', ['null' => false, 'default' => 0, 'comment' => '排序'])
->addColumn('created_at', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP', 'comment' => '创建时间']) ->addColumn('created_at', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP', 'comment' => '创建时间'])
->create(); ->create();

View File

@@ -28,9 +28,10 @@ class CreateAgentEntrypriceSizeType extends Migrator
public function change() public function change()
{ {
$table = $this->table('agent_entryprice_size_type', ['engine' => 'MyISAM', 'comment' => '代理商企业规模类型表']); $table = $this->table('agent_entryprice_size_type', ['engine' => 'MyISAM', 'comment' => '代理商企业规模类型表']);
$table->addColumn('cn_name', 'integer', ['signed' => false, 'null' => false, 'comment' => '中文类型名']) $table->addColumn('language_id', 'integer', ['null' => false, 'default' => 0, 'comment' => '语言ID'])
->addColumn('en_name', 'integer', ['signed' => false, 'null' => false, 'comment' => '英文类型名']) ->addColumn('name', 'string', ['limit' => 64, 'null' => false, 'comment' => '类型名'])
->addColumn('desc', 'string', ['limit' => 255, 'null' => true, 'default' => null, 'comment' => '描述信息']) ->addColumn('value', 'string', ['limit' => 64, 'null' => false, 'comment' => '类型值'])
->addColumn('desc', 'string', ['limit' => 255, 'null' => true, 'default' => null, 'comment' => '描述'])
->addColumn('sort', 'integer', ['null' => false, 'default' => 0, 'comment' => '排序']) ->addColumn('sort', 'integer', ['null' => false, 'default' => 0, 'comment' => '排序'])
->addColumn('created_at', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP', 'comment' => '创建时间']) ->addColumn('created_at', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP', 'comment' => '创建时间'])
->create(); ->create();