IndexController.php
5.4 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<?php
namespace App\Http\Controllers\Aside\Com;
use App\Enums\Common\Code;
use App\Enums\Common\Common;
use App\Http\Controllers\Aside\BaseController;
use App\Http\Logic\Aside\Manage\MenuLogic;
use App\Models\Domain\DomainInfo;
use App\Models\Inquiry\InquiryData;
use App\Models\Manage\Manage;
use App\Models\Product\Keyword;
use App\Models\Product\Product;
use App\Models\Project\Project;
use App\Models\RouteMap\RouteMap;
use App\Services\ProjectServer;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
/**
* Class IndexController
* @package App\Http\Controllers\Aside
* @author zbj
* @date 2023/4/19
*/
class IndexController extends BaseController
{
/**
* 用户菜单
* @param MenuLogic $logic
* @return \Illuminate\Http\JsonResponse
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
* @author zbj
* @date 2023/6/21
*/
public function get_menu(MenuLogic $logic)
{
if($this->manage['gid'] == 0){ //超级管理员
$menus = $logic->getAllMenu();
}else{
$menus = $logic->getMenuByGroupId($this->manage['gid']);
}
$this->response('success',Code::SUCCESS,$menus);
}
/**
* @remark :修改密码
* @name :editPassword
* @author :lyh
* @method :post
* @time :2023/9/11 9:10
*/
public function editPassword(){
$this->request->validate([
// 'oldPassword'=>'required',
'password' => 'required',
'confirm'=>'required',
], [
// 'oldPassword.required' => '请输入原密码',
'password.required' => '请输入新密码',
'confirm.required' => '请再次输入新密码',
]);
//查询员密码是否正确
$managerModel = new Manage();
$info = $managerModel->read(['id'=>$this->manage['id']]);
// if(!Hash::check($this->param['oldPassword'], $info['password'])){
// $this->response('原密码错误',Code::USER_REGISTER_ERROE);
// }
if($this->param['password'] != $this->param['confirm']){
$this->response('两次密码不一致');
}
$rs = $managerModel->edit(['password'=>Hash::make($this->param['password'])],['id'=>$this->manage['id']]);
if($rs === false){
$this->response('系统错误',Code::SYSTEM_ERROR);
}
Cache::pull(Common::MANAGE_TOKEN . $info['token']);
$this->response('success');
}
/**
* @remark :同步询盘记录
* @name :sync_inquiry
* @author :lyh
* @method :post
* @time :2023/11/16 9:51
*/
public function sync_inquiry(){
$this->request->validate([
'data' => 'required|array',
'identifying'=>'required',
], [
'data.required' => '自定义询盘数据不为空',
'data.array' => '必须为数组',
'identifying.required' => '唯一标识不为空',
]);
$inquiryModel = new InquiryData();
$rs = $inquiryModel->add($this->param);
if($rs === false){
$this->response('error',Code::SYSTEM_ERROR);
}
$this->response('success');
}
/**
* @remark :根据关键字获取产品主图
* @name :getKeywordList
* @author :lyh
* @method :post
* @time :2024/2/23 16:28
*/
public function getKeywordImage(){
$arr = explode('/',trim(str_replace('https://', '', $this->param['url']),'/'));
if(empty($arr) || !is_array($arr)){
$this->response('当前项目不存在..',Code::SYSTEM_ERROR);
}
$domainModel = new DomainInfo();
$domainInfo = $domainModel->read(['domain'=>$arr[0]]);
if($domainInfo === false){
$this->response('当前项目不存在.',Code::SYSTEM_ERROR);
}
ProjectServer::useProject($domainInfo['project_id']);
$routeMapModel = new RouteMap();
$routeInfo = $routeMapModel->read(['route'=>$arr[1]]);
if($domainInfo === false){
$this->response('当前路由不存在.',Code::SYSTEM_ERROR);
}
$keywordModel = new Keyword();
$keywordInfo = $keywordModel->read(['id'=>$routeInfo['source_id']]);
$count = Product::where('keyword_id','like' ,'%,'.$keywordInfo['id'].',%')->count();
$productModel = new Product();
if($count < 5){
$productList = $productModel->list([],'sort',['thumb','title']);
//获取7个产品主图
}else{
$productList = $productModel->list(['keyword_id'=>['like','%,'.$keywordInfo['id'].',%']],['thumb','title']);
}
$product_image = [];
foreach ($productList as $k => $v){
$image = [];
if(!empty($v['thumb']) && !empty($v['thumb']['url'])){
$image['image'] = getImageUrl($v['thumb']['url']);
$image['title'] = $v['title'];
$product_image[] = $image;
}
if(count($product_image) > 6){
break;
}
}
$data = [
'title'=>$keywordInfo['title'],
'keyword_title'=>$keywordInfo['keyword_title'],
'keyword_content'=>$keywordInfo['keyword_content'],
'product_list'=>$product_image
];
DB::disconnect('custom_mysql');
$this->response('success',Code::SUCCESS,$data);
}
}