InquiryController.php
3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
namespace App\Http\Controllers\Api;
use App\Enums\Common\Code;
use App\Exceptions\InquiryFilterException;
use App\Models\Domain\DomainInfo;
use App\Models\Project\Project;
use App\Models\SyncSubmitTask\SyncSubmitTask;
use App\Models\Visit\Visit;
use App\Services\CosService;
use App\Services\ProjectServer;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
/**
* Class InquiryController
* @package App\Http\Controllers\Api
* @author zbj
* @date 2024/2/2
*/
class InquiryController extends BaseController
{
/**
* 提交询盘
* C端部署自己服务器的
* @param Request $request
* @return false|string
* @author zbj
* @date 2024/2/2
*/
public function submit(Request $request){
$data = $request->post();
@file_put_contents(storage_path('logs/form_submit_' . date('Y-m-d') . '.log'), var_export(date('Y-m-d H:i:s') . "-询盘表单提交数据:" . json_encode($data), true) . PHP_EOL, FILE_APPEND);
try {
$files = $request->allFiles()['data'] ?? [];
foreach ($files as $key => $file) {
$cos = new CosService();
$fileinfo = $cos->checkInquiryFile($file);
$fileName = uniqid().rand(10000,99999).'.'.$file->getClientOriginalExtension();
$path = $cos->uploadFile($file, '/inquiry/'. date('Ymd'), $fileName);
$data['data'][$key] = [
'path' => $path,
'original_name' => $fileinfo['name'],
];
}
}catch (InquiryFilterException $e){
return $this->error($e->getMessage());
}catch (\Exception $e){
return $this->error('File upload fail');
}
//异步处理
if(!SyncSubmitTask::addTask(SyncSubmitTask::TYPE_INQUIRY, $data)){
return $this->error();
}
return $this->success();
}
/**
* @remark :修改路由状态
* @name :editInquiryStatus
* @author :lyh
* @method :post
* @time :2024/3/22 15:41
*/
public function editInquiryStatus(){
$this->request->validate([
'domain'=>'required',
'ip'=>'required',
'updated_date'=>'required',
],[
'domain.required' => 'domain不能为空',
'ip.required' => 'ip不能为空',
'updated_date.required' => '日期不能为空',
]);
$project = Project::getProjectByDomain($this->param['domain']);
if(!$project){
$this->response('域名不存在',Code::SYSTEM_ERROR);
}
ProjectServer::useProject($project->id);
$customerVisitModel = new Visit();
$info = $customerVisitModel->read([
'ip'=>$this->param['ip'],
'updated_date'=>$this->param['updated_date']
]);
if($info === false){
$this->response('当前记录不存在',Code::SYSTEM_ERROR);
}
try {
$customerVisitModel->edit(['is_inquiry'=>1],['id'=>$info['id']]);
}catch (\Exception $e){
$this->response('操作失败',Code::SYSTEM_ERROR);
}
DB::disconnect('custom_mysql');
$this->response('success');
}
}