From b9d4a7b27eb838bbe0cb8168cd95979ad559bf25 Mon Sep 17 00:00:00 2001 From: jsasg <735273025@qq.com> Date: Thu, 13 Mar 2025 16:23:37 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E9=87=87=E8=B4=AD=E8=AF=A2=E7=9B=98=E5=88=86=E9=A1=B5/?= =?UTF-8?q?=E5=AF=BC=E5=87=BA=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/v1/BulkPurchaseInquiry.php | 102 ++++++++++++++++++ .../model/v1/BulkPurchaseInquiryModel.php | 46 ++++++++ app/admin/route/v1.php | 9 ++ .../model/BulkPurchaseInquiryBaseModel.php | 38 +++++++ ...224032339_create_bulk_purchase_inquiry.php | 12 ++- 5 files changed, 202 insertions(+), 5 deletions(-) create mode 100644 app/admin/controller/v1/BulkPurchaseInquiry.php create mode 100644 app/admin/model/v1/BulkPurchaseInquiryModel.php create mode 100644 app/common/model/BulkPurchaseInquiryBaseModel.php diff --git a/app/admin/controller/v1/BulkPurchaseInquiry.php b/app/admin/controller/v1/BulkPurchaseInquiry.php new file mode 100644 index 00000000..f3ce21b8 --- /dev/null +++ b/app/admin/controller/v1/BulkPurchaseInquiry.php @@ -0,0 +1,102 @@ +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(); + } +} diff --git a/app/admin/model/v1/BulkPurchaseInquiryModel.php b/app/admin/model/v1/BulkPurchaseInquiryModel.php new file mode 100644 index 00000000..3763f476 --- /dev/null +++ b/app/admin/model/v1/BulkPurchaseInquiryModel.php @@ -0,0 +1,46 @@ +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]); + } + } + } +} diff --git a/app/admin/route/v1.php b/app/admin/route/v1.php index e249bcac..55f559e0 100644 --- a/app/admin/route/v1.php +++ b/app/admin/route/v1.php @@ -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() { // 配置分组 diff --git a/app/common/model/BulkPurchaseInquiryBaseModel.php b/app/common/model/BulkPurchaseInquiryBaseModel.php new file mode 100644 index 00000000..715eec10 --- /dev/null +++ b/app/common/model/BulkPurchaseInquiryBaseModel.php @@ -0,0 +1,38 @@ + 'int', + 'language_id' => 'int', + 'corp_name' => 'string', + 'first_name' => 'string', + 'last_name' => 'string', + 'email' => 'string', + 'phone' => 'string', + 'province' => 'string', + 'city' => 'string', + 'district' => 'string', + 'street' => 'string', + 'interested' => 'string', + 'url' => 'string', + 'referer_url' => 'string', + 'message' => 'string', + 'ip' => 'string', + 'created_at' => 'datetime' + ]; +} diff --git a/database/migrations/20241224032339_create_bulk_purchase_inquiry.php b/database/migrations/20241224032339_create_bulk_purchase_inquiry.php index e62bcf43..b672be34 100644 --- a/database/migrations/20241224032339_create_bulk_purchase_inquiry.php +++ b/database/migrations/20241224032339_create_bulk_purchase_inquiry.php @@ -34,11 +34,13 @@ class CreateBulkPurchaseInquiry extends Migrator ->addColumn('last_name', 'string', ['limit' => 64, 'null' => false, 'comment' => '名']) ->addColumn('email', 'string', ['limit' => 128, 'null' => false, 'comment' => '邮箱']) ->addColumn('phone', 'string', ['limit' => 32, 'null' => false, 'comment' => '电话']) - ->addColumn('province', 'string', ['limit' => 64, 'null' => false, 'comment' => '省']) - ->addColumn('city', 'string', ['limit' => 64, 'null' => false, 'comment' => '市']) - ->addColumn('district', 'string', ['limit' => 64, 'null' => false, 'comment' => '区']) - ->addColumn('address', 'string', ['limit' => 255, 'null' => false, 'comment' => '地址']) - ->addColumn('interest', 'string', ['limit' => 255, 'null' => false, 'comment' => '兴趣(感兴趣的产品品类)']) + ->addColumn('province', 'string', ['limit' => 64, 'null' => true, 'comment' => '省']) + ->addColumn('city', 'string', ['limit' => 64, 'null' => true, 'comment' => '市']) + ->addColumn('district', 'string', ['limit' => 64, 'null' => true, 'comment' => '区']) + ->addColumn('address', 'string', ['limit' => 255, 'null' => true, 'comment' => '地址']) + ->addColumn('interested', 'string', ['limit' => 255, 'null' => false, 'comment' => '兴趣(感兴趣的产品品类)']) + ->addColumn('url', 'string', ['limit' => 255, 'null' => true, 'comment' => '感兴趣产品所在官网URL']) + ->addColumn('referer_url', 'string', ['limit' => 255, 'null' => true, 'comment' => '来源URL']) ->addColumn('message', 'text', ['null' => false, 'comment' => '留言内容']) ->addColumn('ip', 'string', ['limit' => 64, 'null' => false, 'comment' => 'IP']) ->addColumn('created_at', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP', 'comment' => '创建时间'])