正在显示
6 个修改的文件
包含
192 行增加
和
9 行删除
| @@ -5,6 +5,7 @@ namespace App\Http\Controllers\Bside\Inquiry; | @@ -5,6 +5,7 @@ namespace App\Http\Controllers\Bside\Inquiry; | ||
| 5 | 5 | ||
| 6 | use App\Http\Controllers\Bside\BaseController; | 6 | use App\Http\Controllers\Bside\BaseController; |
| 7 | use App\Http\Logic\Bside\Inquiry\InquiryLogic; | 7 | use App\Http\Logic\Bside\Inquiry\InquiryLogic; |
| 8 | +use App\Models\Inquiry\InquiryForm; | ||
| 8 | use App\Rules\Ids; | 9 | use App\Rules\Ids; |
| 9 | use App\Services\BatchExportService; | 10 | use App\Services\BatchExportService; |
| 10 | use Illuminate\Http\Request; | 11 | use Illuminate\Http\Request; |
| @@ -20,9 +21,24 @@ use Illuminate\Support\Facades\Storage; | @@ -20,9 +21,24 @@ use Illuminate\Support\Facades\Storage; | ||
| 20 | class InquiryController extends BaseController | 21 | class InquiryController extends BaseController |
| 21 | { | 22 | { |
| 22 | 23 | ||
| 24 | + public function form_list(){ | ||
| 25 | + $list = InquiryForm::where('is_default', 0)->get(); | ||
| 26 | + $data = $list->toArray(); | ||
| 27 | + foreach ($data as &$item){ | ||
| 28 | + $field_text = []; | ||
| 29 | + foreach ($item['field'] as $v){ | ||
| 30 | + $field_text[$v] = InquiryForm::fieldMap($v); | ||
| 31 | + } | ||
| 32 | + $item['field_text'] = $field_text; | ||
| 33 | + } | ||
| 34 | + return $this->success($data); | ||
| 35 | + } | ||
| 36 | + | ||
| 23 | public function index(InquiryLogic $logic) | 37 | public function index(InquiryLogic $logic) |
| 24 | { | 38 | { |
| 25 | - if(($this->param['type']??'') == 'other'){ | 39 | + if(!empty($this->param['form_id'])){ |
| 40 | + $data = $logic->getFormDataList(); | ||
| 41 | + }elseif(($this->param['type']??'') == 'other'){ | ||
| 26 | $data = $logic->getOtherList(); | 42 | $data = $logic->getOtherList(); |
| 27 | }else{ | 43 | }else{ |
| 28 | $data = $logic->getApiList(); | 44 | $data = $logic->getApiList(); |
| @@ -36,7 +52,10 @@ class InquiryController extends BaseController | @@ -36,7 +52,10 @@ class InquiryController extends BaseController | ||
| 36 | ],[ | 52 | ],[ |
| 37 | 'id.required' => 'ID不能为空' | 53 | 'id.required' => 'ID不能为空' |
| 38 | ]); | 54 | ]); |
| 39 | - if(($this->param['type']??'') == 'other'){ | 55 | + |
| 56 | + if(!empty($this->param['form_id'])){ | ||
| 57 | + $data = $logic->getFormDataInfo($this->param['id'], $this->param['form_id']); | ||
| 58 | + }elseif(($this->param['type']??'') == 'other'){ | ||
| 40 | $data = $logic->getOtherInfo($this->param['id']); | 59 | $data = $logic->getOtherInfo($this->param['id']); |
| 41 | }else{ | 60 | }else{ |
| 42 | $data = $logic->getInfo($this->param['id']); | 61 | $data = $logic->getInfo($this->param['id']); |
| @@ -52,7 +71,9 @@ class InquiryController extends BaseController | @@ -52,7 +71,9 @@ class InquiryController extends BaseController | ||
| 52 | ],[ | 71 | ],[ |
| 53 | 'ids.required' => 'ID不能为空' | 72 | 'ids.required' => 'ID不能为空' |
| 54 | ]); | 73 | ]); |
| 55 | - if(($this->param['type']??'') == 'other'){ | 74 | + if(!empty($this->param['form_id'])){ |
| 75 | + $logic->deleteFormData($this->param['ids'], ['form_id' => $this->param['form_id']]); | ||
| 76 | + }elseif(($this->param['type']??'') == 'other'){ | ||
| 56 | $logic->deleteOther($this->param['ids']); | 77 | $logic->deleteOther($this->param['ids']); |
| 57 | }else{ | 78 | }else{ |
| 58 | $logic->delete($this->param['ids']); | 79 | $logic->delete($this->param['ids']); |
| @@ -71,13 +92,24 @@ class InquiryController extends BaseController | @@ -71,13 +92,24 @@ class InquiryController extends BaseController | ||
| 71 | */ | 92 | */ |
| 72 | public function export(InquiryLogic $logic) | 93 | public function export(InquiryLogic $logic) |
| 73 | { | 94 | { |
| 74 | - if(($this->param['type']??'') == 'other'){ | 95 | + if(!empty($this->param['form_id'])){ |
| 96 | + $data = $logic->getFormDataList(true); | ||
| 97 | + $field = InquiryForm::getField($this->param['form_id']); | ||
| 98 | + $map = [ | ||
| 99 | + 'submit_time' => '询盘发送时间', | ||
| 100 | + ]; | ||
| 101 | + foreach ($field as $v) { | ||
| 102 | + $map[$v] = InquiryForm::fieldMap($v); | ||
| 103 | + } | ||
| 104 | + $map['ip_address'] = '访问国家/地区(IP)'; | ||
| 105 | + $map['refer'] = '发送页面'; | ||
| 106 | + }elseif(($this->param['type']??'') == 'other'){ | ||
| 75 | $data = $logic->getOtherList(true); | 107 | $data = $logic->getOtherList(true); |
| 76 | $map = [ | 108 | $map = [ |
| 77 | 'submit_time' => '询盘发送时间', | 109 | 'submit_time' => '询盘发送时间', |
| 78 | 'email' => '邮箱', | 110 | 'email' => '邮箱', |
| 79 | 'ip_address' => '访问国家/地区(IP)', | 111 | 'ip_address' => '访问国家/地区(IP)', |
| 80 | - 'referer' => '发送页面', | 112 | + 'refer' => '发送页面', |
| 81 | ]; | 113 | ]; |
| 82 | }else{ | 114 | }else{ |
| 83 | $data = $logic->getApiList(true); | 115 | $data = $logic->getApiList(true); |
| @@ -95,6 +127,10 @@ class InquiryController extends BaseController | @@ -95,6 +127,10 @@ class InquiryController extends BaseController | ||
| 95 | $data = $data['list'] ?? []; | 127 | $data = $data['list'] ?? []; |
| 96 | foreach ($data as &$item){ | 128 | foreach ($data as &$item){ |
| 97 | $item['ip_address'] = "{$item['country']}({$item['ip']})"; | 129 | $item['ip_address'] = "{$item['country']}({$item['ip']})"; |
| 130 | + | ||
| 131 | + if(!empty($this->param['form_id'])){ | ||
| 132 | + $item = array_merge($item, $item['data']); | ||
| 133 | + } | ||
| 98 | } | 134 | } |
| 99 | 135 | ||
| 100 | //生成文件,发送到客户端 | 136 | //生成文件,发送到客户端 |
| @@ -8,8 +8,9 @@ use App\Helper\Translate; | @@ -8,8 +8,9 @@ use App\Helper\Translate; | ||
| 8 | use App\Http\Logic\Aside\Project\ProjectLogic; | 8 | use App\Http\Logic\Aside\Project\ProjectLogic; |
| 9 | use App\Http\Logic\Bside\BaseLogic; | 9 | use App\Http\Logic\Bside\BaseLogic; |
| 10 | use App\Models\Domain\DomainInfo; | 10 | use App\Models\Domain\DomainInfo; |
| 11 | +use App\Models\Inquiry\InquiryForm; | ||
| 12 | +use App\Models\Inquiry\InquiryFormData; | ||
| 11 | use App\Models\Inquiry\InquiryOther; | 13 | use App\Models\Inquiry\InquiryOther; |
| 12 | -use App\Services\ProjectServer; | ||
| 13 | use Illuminate\Support\Facades\DB; | 14 | use Illuminate\Support\Facades\DB; |
| 14 | 15 | ||
| 15 | /** | 16 | /** |
| @@ -68,7 +69,6 @@ class InquiryLogic extends BaseLogic | @@ -68,7 +69,6 @@ class InquiryLogic extends BaseLogic | ||
| 68 | if($search){ | 69 | if($search){ |
| 69 | $map['email'] = ['like','%'.$search.'%']; | 70 | $map['email'] = ['like','%'.$search.'%']; |
| 70 | } | 71 | } |
| 71 | - ProjectServer::useProject($this->user['project_id']); | ||
| 72 | 72 | ||
| 73 | $data = (new InquiryOther())->lists($map,$page,$page_size,'id', | 73 | $data = (new InquiryOther())->lists($map,$page,$page_size,'id', |
| 74 | ['id', 'email', 'ip', 'country', 'domain', DB::raw('referer as refer'), DB::raw('status as read_status'), 'submit_time'] | 74 | ['id', 'email', 'ip', 'country', 'domain', DB::raw('referer as refer'), DB::raw('status as read_status'), 'submit_time'] |
| @@ -77,6 +77,27 @@ class InquiryLogic extends BaseLogic | @@ -77,6 +77,27 @@ class InquiryLogic extends BaseLogic | ||
| 77 | return $this->success($data); | 77 | return $this->success($data); |
| 78 | } | 78 | } |
| 79 | 79 | ||
| 80 | + public function getFormDataList($export = false){ | ||
| 81 | + $page_size = $export ? 1000 : 20; | ||
| 82 | + $search = $this->request['search'] ?: ''; | ||
| 83 | + $page = $this->request['page'] ?: 1; | ||
| 84 | + $form_id = $this->request['form_id'] ?? ''; | ||
| 85 | + $field = InquiryForm::getField($form_id); | ||
| 86 | + $map = [ | ||
| 87 | + 'form_id' => $form_id | ||
| 88 | + ]; | ||
| 89 | + if($search){ | ||
| 90 | + foreach ($field as $v){ | ||
| 91 | + $map['data->' . $v] = $search; | ||
| 92 | + } | ||
| 93 | + } | ||
| 94 | + $fields = ['id', 'data', 'ip', 'country', 'domain', DB::raw('referer as refer'), DB::raw('status as read_status'), DB::raw('submit_at as submit_time')]; | ||
| 95 | + $lists = InquiryFormData::select($fields)->orderBy('id')->paginate($page_size, ['*'], 'page', $page); | ||
| 96 | + $data = $lists->toArray(); | ||
| 97 | + | ||
| 98 | + return $this->success($data); | ||
| 99 | + } | ||
| 100 | + | ||
| 80 | public function getInfo($id) | 101 | public function getInfo($id) |
| 81 | { | 102 | { |
| 82 | $project = (new ProjectLogic())->getProjectInfo($this->user['project_id']); | 103 | $project = (new ProjectLogic())->getProjectInfo($this->user['project_id']); |
| @@ -93,10 +114,22 @@ class InquiryLogic extends BaseLogic | @@ -93,10 +114,22 @@ class InquiryLogic extends BaseLogic | ||
| 93 | return $this->success(['trans_message' => $trans_message]); | 114 | return $this->success(['trans_message' => $trans_message]); |
| 94 | } | 115 | } |
| 95 | 116 | ||
| 117 | + public function getFormDataInfo($id, $form_id){ | ||
| 118 | + //修改状态为已读 | ||
| 119 | + if($this->request['read_status']){ | ||
| 120 | + (new InquiryFormData())->edit(['status' => 1], ['id' => $id, 'form_id' => $form_id]); | ||
| 121 | + } | ||
| 122 | + //翻译 | ||
| 123 | + $trans_message = ''; | ||
| 124 | + if($this->request['message']){ | ||
| 125 | + $trans_message = Translate::tran($this->request['message'], 'zh'); | ||
| 126 | + } | ||
| 127 | + return $this->success(['trans_message' => $trans_message]); | ||
| 128 | + } | ||
| 129 | + | ||
| 96 | public function getOtherInfo($id){ | 130 | public function getOtherInfo($id){ |
| 97 | //修改状态为已读 | 131 | //修改状态为已读 |
| 98 | if($this->request['read_status']){ | 132 | if($this->request['read_status']){ |
| 99 | - ProjectServer::useProject($this->user['project_id']); | ||
| 100 | (new InquiryOther())->edit(['status' => 1], ['id' => $id]); | 133 | (new InquiryOther())->edit(['status' => 1], ['id' => $id]); |
| 101 | } | 134 | } |
| 102 | return $this->success(['trans_message' => '']); | 135 | return $this->success(['trans_message' => '']); |
| @@ -120,11 +153,21 @@ class InquiryLogic extends BaseLogic | @@ -120,11 +153,21 @@ class InquiryLogic extends BaseLogic | ||
| 120 | if(!$ids){ | 153 | if(!$ids){ |
| 121 | $this->fail('ID不能为空'); | 154 | $this->fail('ID不能为空'); |
| 122 | } | 155 | } |
| 123 | - ProjectServer::useProject($this->user['project_id']); | ||
| 124 | (new InquiryOther())->del(['id'=>['in',$ids]]); | 156 | (new InquiryOther())->del(['id'=>['in',$ids]]); |
| 125 | return $this->success(); | 157 | return $this->success(); |
| 126 | } | 158 | } |
| 127 | 159 | ||
| 160 | + public function deleteFormData($ids, $map = []) | ||
| 161 | + { | ||
| 162 | + $ids = array_filter(Arr::splitFilterToArray($ids), 'intval'); | ||
| 163 | + if(!$ids){ | ||
| 164 | + $this->fail('ID不能为空'); | ||
| 165 | + } | ||
| 166 | + $map['id'] = ['in',$ids]; | ||
| 167 | + (new InquiryFormData())->del($map); | ||
| 168 | + return $this->success(); | ||
| 169 | + } | ||
| 170 | + | ||
| 128 | 171 | ||
| 129 | 172 | ||
| 130 | } | 173 | } |
app/Models/Inquiry/InquiryForm.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace App\Models\Inquiry; | ||
| 4 | + | ||
| 5 | +use App\Models\Base; | ||
| 6 | +use Illuminate\Database\Eloquent\SoftDeletes; | ||
| 7 | +use Illuminate\Support\Facades\Cache; | ||
| 8 | + | ||
| 9 | +/** | ||
| 10 | + * Class InquiryForm | ||
| 11 | + * @package App\Models\Inquiry | ||
| 12 | + * @author zbj | ||
| 13 | + * @date 2023/12/5 | ||
| 14 | + */ | ||
| 15 | +class InquiryForm extends Base | ||
| 16 | +{ | ||
| 17 | + use SoftDeletes; | ||
| 18 | + | ||
| 19 | + //设置关联表名 | ||
| 20 | + /** | ||
| 21 | + * @var mixed | ||
| 22 | + */ | ||
| 23 | + protected $connection = "custom_mysql"; | ||
| 24 | + protected $table = 'gl_inquiry_form'; | ||
| 25 | + | ||
| 26 | + | ||
| 27 | + /** | ||
| 28 | + * 预设字段名称 | ||
| 29 | + * @author zbj | ||
| 30 | + * @date 2023/12/5 | ||
| 31 | + */ | ||
| 32 | + public static function fieldMap($field = ''){ | ||
| 33 | + $map = [ | ||
| 34 | + 'name' => '姓名', | ||
| 35 | + 'email' => '邮箱', | ||
| 36 | + 'phone' => '电话', | ||
| 37 | + 'mobile' => '电话', | ||
| 38 | + 'message' => '询盘内容', | ||
| 39 | + 'company' => '公司名称' | ||
| 40 | + ]; | ||
| 41 | + if($field){ | ||
| 42 | + return $map[$field] ?? $field; | ||
| 43 | + } | ||
| 44 | + return $map; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + | ||
| 48 | + public function getFieldAttribute($value) | ||
| 49 | + { | ||
| 50 | + return json_decode($value, true); | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + /** | ||
| 54 | + * @author zbj | ||
| 55 | + * @date 2023/12/5 | ||
| 56 | + */ | ||
| 57 | + public static function getField($form_id){ | ||
| 58 | + $cache_key = 'inquiry_form_field_' . $form_id; | ||
| 59 | + $field = Cache::get($cache_key); | ||
| 60 | + if(!$field){ | ||
| 61 | + $field = self::where('id', $form_id)->value('field'); | ||
| 62 | + $field && Cache::set($cache_key, $field, 3600); | ||
| 63 | + } | ||
| 64 | + return $field; | ||
| 65 | + } | ||
| 66 | +} |
app/Models/Inquiry/InquiryFormData.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace App\Models\Inquiry; | ||
| 4 | + | ||
| 5 | +use App\Models\Base; | ||
| 6 | +use Illuminate\Database\Eloquent\SoftDeletes; | ||
| 7 | + | ||
| 8 | +/** | ||
| 9 | + * Class InquiryFormData | ||
| 10 | + * @package App\Models\Inquiry | ||
| 11 | + * @author zbj | ||
| 12 | + * @date 2023/12/4 | ||
| 13 | + */ | ||
| 14 | +class InquiryFormData extends Base | ||
| 15 | +{ | ||
| 16 | + use SoftDeletes; | ||
| 17 | + | ||
| 18 | + //设置关联表名 | ||
| 19 | + /** | ||
| 20 | + * @var mixed | ||
| 21 | + */ | ||
| 22 | + protected $connection = "custom_mysql"; | ||
| 23 | + protected $table = 'gl_inquiry_form_data'; | ||
| 24 | + | ||
| 25 | + public function getDataAttribute($value) | ||
| 26 | + { | ||
| 27 | + return json_decode($value, true); | ||
| 28 | + } | ||
| 29 | +} |
| @@ -78,9 +78,17 @@ class RouteMap extends Base | @@ -78,9 +78,17 @@ class RouteMap extends Base | ||
| 78 | if(in_array($route, $fixed)){ | 78 | if(in_array($route, $fixed)){ |
| 79 | return true; | 79 | return true; |
| 80 | } | 80 | } |
| 81 | + $path = ''; | ||
| 82 | + if($source == self::SOURCE_NEWS){ | ||
| 83 | + $path = self::SOURCE_NEWS; | ||
| 84 | + }elseif ($source == self::SOURCE_BLOG){ | ||
| 85 | + $path = self::SOURCE_BLOG.'s'; | ||
| 86 | + } | ||
| 87 | + | ||
| 81 | $where = [ | 88 | $where = [ |
| 82 | 'project_id' => $project_id, | 89 | 'project_id' => $project_id, |
| 83 | 'route' => $route, | 90 | 'route' => $route, |
| 91 | + 'path' => $path, | ||
| 84 | ]; | 92 | ]; |
| 85 | $route = self::where($where)->first(); | 93 | $route = self::where($where)->first(); |
| 86 | if($route){ | 94 | if($route){ |
| @@ -271,6 +271,7 @@ Route::middleware(['bloginauth'])->group(function () { | @@ -271,6 +271,7 @@ Route::middleware(['bloginauth'])->group(function () { | ||
| 271 | //精准询盘 | 271 | //精准询盘 |
| 272 | Route::prefix('inquiry')->group(function () { | 272 | Route::prefix('inquiry')->group(function () { |
| 273 | Route::get('/', [\App\Http\Controllers\Bside\Inquiry\InquiryController::class, 'index'])->name('inquiry'); | 273 | Route::get('/', [\App\Http\Controllers\Bside\Inquiry\InquiryController::class, 'index'])->name('inquiry'); |
| 274 | + Route::get('/form_list', [\App\Http\Controllers\Bside\Inquiry\InquiryController::class, 'form_list'])->name('inquiry_form_list'); | ||
| 274 | Route::get('/info', [\App\Http\Controllers\Bside\Inquiry\InquiryController::class, 'info'])->name('inquiry_info'); | 275 | Route::get('/info', [\App\Http\Controllers\Bside\Inquiry\InquiryController::class, 'info'])->name('inquiry_info'); |
| 275 | Route::any('/delete', [\App\Http\Controllers\Bside\Inquiry\InquiryController::class, 'delete'])->name('inquiry_delete'); | 276 | Route::any('/delete', [\App\Http\Controllers\Bside\Inquiry\InquiryController::class, 'delete'])->name('inquiry_delete'); |
| 276 | Route::any('/export', [\App\Http\Controllers\Bside\Inquiry\InquiryController::class, 'export'])->name('inquiry_export'); | 277 | Route::any('/export', [\App\Http\Controllers\Bside\Inquiry\InquiryController::class, 'export'])->name('inquiry_export'); |
-
请 注册 或 登录 后发表评论