feat: 添加批量采购询盘分页/导出接口
This commit is contained in:
102
app/admin/controller/v1/BulkPurchaseInquiry.php
Normal file
102
app/admin/controller/v1/BulkPurchaseInquiry.php
Normal file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\admin\controller\v1;
|
||||
|
||||
use app\admin\model\v1\BulkPurchaseInquiryModel;
|
||||
|
||||
/**
|
||||
* 批量采购询盘控制器
|
||||
*/
|
||||
class BulkPurchaseInquiry
|
||||
{
|
||||
// 分页
|
||||
public function index()
|
||||
{
|
||||
$param = request()->param([
|
||||
'corp_name',
|
||||
'interested',
|
||||
'created_at',
|
||||
'page/d' => 1,
|
||||
'size/d' => 10
|
||||
]);
|
||||
|
||||
$msgs = BulkPurchaseInquiryModel::field([
|
||||
'id',
|
||||
'ip',
|
||||
'corp_name',
|
||||
'first_name',
|
||||
'last_name',
|
||||
'email',
|
||||
'phone',
|
||||
'interested',
|
||||
'message',
|
||||
'created_at'
|
||||
])
|
||||
->withSearch(['corp_name', 'interested', 'created_at'], [
|
||||
'corp_name' => $param['corp_name'] ?? null,
|
||||
'interested' => $param['interested'] ?? null,
|
||||
'created_at' => !empty($param['created_at']) ? explode(',', $param['created_at']) : null
|
||||
])
|
||||
->language(request()->lang_id)
|
||||
->order(['id' => 'desc'])
|
||||
->paginate([
|
||||
'list_rows' => $param['size'],
|
||||
'page' => $param['page'],
|
||||
]);
|
||||
|
||||
return success('获取成功', $msgs);
|
||||
}
|
||||
|
||||
// 导出
|
||||
public function export()
|
||||
{
|
||||
$schema = [
|
||||
'id' => 'ID',
|
||||
'ip' => 'IP',
|
||||
'corp_name' => '公司名称',
|
||||
'username' => '姓名',
|
||||
'email' => '邮箱',
|
||||
'phone' => '手机号友',
|
||||
'interested' => '想采购的产品',
|
||||
'message' => '询问内容',
|
||||
'created_at' => '提交时间',
|
||||
];
|
||||
|
||||
// 获取要导出的采购询盘数据
|
||||
$data = $this->getExportData();
|
||||
|
||||
// 导出
|
||||
return xlsx_writer($data, $schema);
|
||||
}
|
||||
// 获取要导出的采购询盘数据
|
||||
private function getExportData()
|
||||
{
|
||||
$param = request()->param([
|
||||
'corp_name',
|
||||
'interested',
|
||||
'created_at',
|
||||
]);
|
||||
|
||||
return BulkPurchaseInquiryModel::field([
|
||||
'id',
|
||||
'ip',
|
||||
'corp_name',
|
||||
'CONCAT(first_name, last_name)' => 'username',
|
||||
'last_name',
|
||||
'email',
|
||||
'phone',
|
||||
'interested',
|
||||
'message',
|
||||
'created_at'
|
||||
])
|
||||
->withSearch(['corp_name', 'interested', 'created_at'], [
|
||||
'corp_name' => $param['corp_name'] ?? null,
|
||||
'interested' => $param['interested'] ?? null,
|
||||
'created_at' => !empty($param['created_at']) ? explode(',', $param['created_at']) : null
|
||||
])
|
||||
->language(request()->lang_id)
|
||||
->order(['id' => 'desc'])
|
||||
->select();
|
||||
}
|
||||
}
|
||||
46
app/admin/model/v1/BulkPurchaseInquiryModel.php
Normal file
46
app/admin/model/v1/BulkPurchaseInquiryModel.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\admin\model\v1;
|
||||
|
||||
use app\common\model\BulkPurchaseInquiryBaseModel;
|
||||
|
||||
/**
|
||||
* 批量采购询盘模型
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class BulkPurchaseInquiryModel extends BulkPurchaseInquiryBaseModel
|
||||
{
|
||||
// 按语言查询
|
||||
public function scopeLanguage($query, $value)
|
||||
{
|
||||
$query->where('language_id', '=', $value);
|
||||
}
|
||||
|
||||
// 公司名称搜索
|
||||
public function searchCorpNameAttr($query, $value)
|
||||
{
|
||||
if (is_null($value)) return;
|
||||
$query->where('corp_name', 'like', "%{$value}%");
|
||||
}
|
||||
|
||||
// 兴趣(感兴趣的产品分类)
|
||||
public function searchInterestedAttr($query, $value)
|
||||
{
|
||||
if (is_null($value)) return;
|
||||
$query->where('interested', '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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -528,6 +528,15 @@ Route::group('v1', function () {
|
||||
Route::get('export', 'LeaveMessage/export');
|
||||
});
|
||||
|
||||
// 反馈管理 - 批量采购底盘列表
|
||||
Route::group('bp/inquiry', function() {
|
||||
// 批量采购底盘列表分页
|
||||
Route::get('index', 'BulkPurchaseInquiry/index');
|
||||
|
||||
// 批量采购底盘列表导出
|
||||
Route::get('export', 'BulkPurchaseInquiry/export');
|
||||
});
|
||||
|
||||
// 配置项列表
|
||||
Route::group('config', function() {
|
||||
// 配置分组
|
||||
|
||||
Reference in New Issue
Block a user