正在显示
2 个修改的文件
包含
404 行增加
和
400 行删除
| @@ -76,7 +76,7 @@ class ProductController extends BaseController | @@ -76,7 +76,7 @@ class ProductController extends BaseController | ||
| 76 | } | 76 | } |
| 77 | 77 | ||
| 78 | /** | 78 | /** |
| 79 | - * @remark :列表 | 79 | + * @remark :下载列表 |
| 80 | * @name :index | 80 | * @name :index |
| 81 | * @author :lyh | 81 | * @author :lyh |
| 82 | * @method :post | 82 | * @method :post |
| @@ -108,29 +108,6 @@ class ProductController extends BaseController | @@ -108,29 +108,6 @@ class ProductController extends BaseController | ||
| 108 | } | 108 | } |
| 109 | $this->response('success',Code::SUCCESS,$lists); | 109 | $this->response('success',Code::SUCCESS,$lists); |
| 110 | } | 110 | } |
| 111 | - /** | ||
| 112 | - * @remark :获取当前页的所有关键字名称 | ||
| 113 | - * @name :keywordNameLists | ||
| 114 | - * @author :lyh | ||
| 115 | - * @method :post | ||
| 116 | - * @time :2024/6/3 14:24 | ||
| 117 | - */ | ||
| 118 | - public function keywordNameLists($lists){ | ||
| 119 | - $keywordId = []; | ||
| 120 | - foreach ($lists as $v){ | ||
| 121 | - $keywordId = array_merge($keywordId,$v['keyword_id']); | ||
| 122 | - } | ||
| 123 | - $keywordId = array_values(array_unique($keywordId)); | ||
| 124 | - $keywordModel = new Keyword(); | ||
| 125 | - $data = []; | ||
| 126 | - $cateList = $keywordModel->list(['id' => ['in',$keywordId]], ['id', 'title']); | ||
| 127 | - if (!empty($cateList)) { | ||
| 128 | - foreach ($cateList as $value) { | ||
| 129 | - $data[$value['id']] = $value['title']; | ||
| 130 | - } | ||
| 131 | - } | ||
| 132 | - return $data; | ||
| 133 | - } | ||
| 134 | 111 | ||
| 135 | /** | 112 | /** |
| 136 | * @remark :不分页产品列表 | 113 | * @remark :不分页产品列表 |
| @@ -146,424 +123,119 @@ class ProductController extends BaseController | @@ -146,424 +123,119 @@ class ProductController extends BaseController | ||
| 146 | } | 123 | } |
| 147 | 124 | ||
| 148 | /** | 125 | /** |
| 149 | - * @remark :获取时处理图片和文件 | ||
| 150 | - * @name :getHandleFileImage | 126 | + * @remark :详情 |
| 127 | + * @name :info | ||
| 151 | * @author :lyh | 128 | * @author :lyh |
| 152 | * @method :post | 129 | * @method :post |
| 153 | - * @time :2024/1/23 17:43 | 130 | + * @time :2023/8/21 18:12 |
| 154 | */ | 131 | */ |
| 155 | - public function getHandleFileImage($v){ | ||
| 156 | - //ToDo::处理图片及文件 | ||
| 157 | - if(!empty($v['thumb']) && !empty($v['thumb']['url'])){ | ||
| 158 | - $v['thumb']['url'] = getImageUrl($v['thumb']['url'],$this->user['storage_type'] ?? 0,$this->user['project_location']); | ||
| 159 | - } | ||
| 160 | - if(!empty($v['gallery'])){ | ||
| 161 | - foreach ($v['gallery'] as $gallery_k => $gallery_v){ | ||
| 162 | - $gallery_v['url'] = getImageUrl($gallery_v['url'],$this->user['storage_type'] ?? 0,$this->user['project_location']); | ||
| 163 | - $v['gallery'][$gallery_k] = $gallery_v; | ||
| 164 | - } | ||
| 165 | - } | ||
| 166 | - if(!empty($v['icon'])){ | ||
| 167 | - foreach ($v['icon'] as $icon_k => $icon_v){ | ||
| 168 | - $icon_v = getImageUrl($icon_v,$this->user['storage_type'] ?? 0,$this->user['project_location']); | ||
| 169 | - $v['icon'][$icon_k] = $icon_v; | ||
| 170 | - } | ||
| 171 | - } | ||
| 172 | - if(!empty($v['video'])){ | ||
| 173 | - $v['video']['url'] = getFileUrl($v['video']['url'],$this->user['storage_type'] ?? 0,$this->user['project_location'],$this->user['file_cdn'] ?? 0); | ||
| 174 | - $v['video']['video_image'] = getImageUrl($v['video']['video_image'] ?? '',$this->user['storage_type'] ?? 0,$this->user['project_location']); | ||
| 175 | - } | ||
| 176 | - if(!empty($v['files']) && !empty($v['files']['url'])){ | ||
| 177 | - $v['files']['url'] = getFileUrl($v['files']['url'],$this->user['storage_type'] ?? 0,$this->user['project_location'],$this->user['file_cdn'] ?? 0); | ||
| 178 | - } | ||
| 179 | - return $this->success($v); | 132 | + public function info(Product $product){ |
| 133 | + $this->request->validate([ | ||
| 134 | + 'id'=>'required' | ||
| 135 | + ],[ | ||
| 136 | + 'id.required' => 'ID不能为空' | ||
| 137 | + ]); | ||
| 138 | + $info = $product->read(['id'=>$this->param['id']]); | ||
| 139 | + $info = $this->handleParam($info); | ||
| 140 | + return $this->response('success',Code::SUCCESS,$info); | ||
| 180 | } | 141 | } |
| 181 | 142 | ||
| 182 | /** | 143 | /** |
| 183 | - * @remark :搜索参数处理 | ||
| 184 | - * @name :handleReturnParam | 144 | + * @remark :保存产品数据 |
| 145 | + * @name :save | ||
| 185 | * @author :lyh | 146 | * @author :lyh |
| 186 | * @method :post | 147 | * @method :post |
| 187 | - * @time :2023/9/14 10:01 | 148 | + * @time :2023/8/17 15:01 |
| 188 | */ | 149 | */ |
| 189 | - public function searchParam(&$query){ | ||
| 190 | - $query = $query->where('project_id',$this->user['project_id']); | ||
| 191 | - if (isset($this->map['category_id']) && !empty($this->map['category_id'])) { | ||
| 192 | - $str[] = $this->map['category_id']; | ||
| 193 | - $this->getAllSub($this->map['category_id'],$str); | ||
| 194 | - $categoryRelatedModel = new CategoryRelated(); | ||
| 195 | - $product_id_arr = $categoryRelatedModel->whereIn('cate_id',$str)->pluck('product_id')->toArray(); | ||
| 196 | - $query = $query->whereIn('id',$product_id_arr); | ||
| 197 | - } | ||
| 198 | - if(isset($this->map['title']) && !empty($this->map['title'])){ | ||
| 199 | - $this->map['title'] = str_replace('+',' ',$this->map['title']); | ||
| 200 | - $query = $query->where('title','like','%'.$this->map['title'].'%'); | ||
| 201 | - } | ||
| 202 | - if(isset($this->map['keyword_title']) && !empty($this->map['keyword_title'])){ | ||
| 203 | - $keywordModel = new Keyword(); | ||
| 204 | - $keywordInfo = $keywordModel->read(['title'=>$this->map['keyword_title']],['id']); | ||
| 205 | - if(!empty($keywordInfo)){ | ||
| 206 | - $query = $query->where('keyword_id','like','%,'.$keywordInfo['id'].',%'); | ||
| 207 | - } | ||
| 208 | - } | ||
| 209 | - if(isset($this->map['status'])){ | ||
| 210 | - if($this->map['status'] == 0){ | ||
| 211 | - $query = $query->whereIn('status',[0,3]); | ||
| 212 | - }else{ | ||
| 213 | - $query = $query->where('status',$this->map['status']); | ||
| 214 | - } | ||
| 215 | - } | ||
| 216 | - if(isset($this->map['created_uid'])){ | ||
| 217 | - $query = $query->where('created_uid',$this->map['created_uid']); | ||
| 218 | - } | ||
| 219 | - if(!empty($this->param['start_at']) && !empty($this->param['end_at'])){ | ||
| 220 | - if($this->user['project_id'] == 2059){ | ||
| 221 | - $query->where('send_time', '>=' ,$this->param['start_at'].' 00:00:00')->where('send_time', '<=' ,$this->param['end_at'].' 59:59:59'); | ||
| 222 | - }else{ | ||
| 223 | - $query->where('created_at', '>=' ,$this->param['start_at'].' 00:00:00')->where('created_at', '<=' ,$this->param['end_at'].' 59:59:59'); | ||
| 224 | - } | ||
| 225 | - } | ||
| 226 | - $this->param['featured_status'] = $this->param['featured_status'] ?? 0; | ||
| 227 | - if($this->param['featured_status'] != Category::STATUS_ACTIVE) { | ||
| 228 | - $cateModel = new Category(); | ||
| 229 | - $featured_ids = $cateModel->formatQuery(['title'=>['in',['Featured','featured']]])->pluck('id')->toArray(); | ||
| 230 | - if(!empty($featured_ids)){ | ||
| 231 | - $status = []; | ||
| 232 | - if(isset($this->map['status'])){ | ||
| 233 | - $status = ['status'=>$this->map['status']]; | ||
| 234 | - } | ||
| 235 | - $cateList = $cateModel->list($status,'id',['id','pid']); | ||
| 236 | - //获取当前的子集 | ||
| 237 | - $featured_arr = []; | ||
| 238 | - foreach ($featured_ids as $id){ | ||
| 239 | - $featured_arr = array_merge($featured_arr,array_unique(_get_all_sub($id,$cateList))); | ||
| 240 | - } | ||
| 241 | - if(!empty($featured_arr)){ | ||
| 242 | - $cateRelated = new CategoryRelated(); | ||
| 243 | - $product_ids = $cateRelated->whereIn('cate_id',$featured_arr)->pluck('product_id')->unique()->toArray(); | ||
| 244 | - $query = $query->whereNotIn('id',$product_ids); | ||
| 245 | - } | ||
| 246 | - } | ||
| 247 | - | ||
| 248 | - } | ||
| 249 | - return $query; | 150 | + public function save(ProductRequest $request, ProductLogic $logic) |
| 151 | + { | ||
| 152 | + $request->validated(); | ||
| 153 | + $data = $logic->productSave(); | ||
| 154 | + $this->response('success',Code::SUCCESS,$data); | ||
| 250 | } | 155 | } |
| 251 | 156 | ||
| 252 | /** | 157 | /** |
| 253 | - * @remark :获取当前id下所有子集 | ||
| 254 | - * @name :getAllSub | 158 | + * @remark :直接编辑列表数据 |
| 159 | + * @name :editList | ||
| 255 | * @author :lyh | 160 | * @author :lyh |
| 256 | * @method :post | 161 | * @method :post |
| 257 | - * @time :2023/10/18 15:10 | 162 | + * @time :2023/10/26 9:48 |
| 258 | */ | 163 | */ |
| 259 | - public function getAllSub($id,&$str = []){ | ||
| 260 | - $cateModel = new Category(); | ||
| 261 | - $list = $cateModel->list(['pid'=>$id,'status'=>1],['id','pid']); | ||
| 262 | - if(!empty($list)){ | ||
| 263 | - foreach ($list as $v){ | ||
| 264 | - $str[] = $v['id']; | ||
| 265 | - $this->getAllSub($v['id'],$str); | ||
| 266 | - } | ||
| 267 | - } | ||
| 268 | - return $str; | 164 | + public function editList(ProductLogic $logic){ |
| 165 | + $logic->editList(); | ||
| 166 | + $this->response('success'); | ||
| 269 | } | 167 | } |
| 270 | 168 | ||
| 271 | /** | 169 | /** |
| 272 | - * @remark :获取所有分类 | ||
| 273 | - * @name :getCategoryList | 170 | + * @remark :删除 |
| 171 | + * @name :delete | ||
| 274 | * @author :lyh | 172 | * @author :lyh |
| 275 | * @method :post | 173 | * @method :post |
| 276 | - * @time :2023/9/14 13:56 | 174 | + * @time :2023/8/22 13:45 |
| 277 | */ | 175 | */ |
| 278 | - public function getCategoryList(){ | ||
| 279 | - $data = Common::get_user_cache('product_category',$this->user['project_id']); | ||
| 280 | - if(empty($data)){ | ||
| 281 | - $categoryModel = new Category(); | ||
| 282 | - $data = []; | ||
| 283 | - $cateList = $categoryModel->list(['project_id'=>$this->user['project_id']],['id','title']); | ||
| 284 | - if(!empty($cateList)){ | ||
| 285 | - foreach ($cateList as $value){ | ||
| 286 | - $data[$value['id']] = $value['title']; | ||
| 287 | - } | ||
| 288 | - } | ||
| 289 | - Common::set_user_cache($data,'product_category',$this->user['project_id']); | ||
| 290 | - } | ||
| 291 | - return $data; | 176 | + public function delete(ProductLogic $logic) |
| 177 | + { | ||
| 178 | + $this->request->validate([ | ||
| 179 | + 'ids'=>['required', new Ids()] | ||
| 180 | + ],[ | ||
| 181 | + 'ids.required' => 'ID不能为空' | ||
| 182 | + ]); | ||
| 183 | + $logic->productDelete(); | ||
| 184 | + $this->response('success'); | ||
| 292 | } | 185 | } |
| 293 | 186 | ||
| 187 | + | ||
| 294 | /** | 188 | /** |
| 295 | - * @remark :获取分类名称 | ||
| 296 | - * @name :categoryName | 189 | + * @remark :根据状态获取数量 |
| 190 | + * @name :getStatusNumber | ||
| 297 | * @author :lyh | 191 | * @author :lyh |
| 298 | * @method :post | 192 | * @method :post |
| 299 | - * @time :2023/9/14 13:58 | 193 | + * @time :2023/8/21 18:33 |
| 300 | */ | 194 | */ |
| 301 | - public function categoryName($product_id,$data){ | ||
| 302 | - $cateRelatedModel = new CategoryRelated(); | ||
| 303 | - $category_id = $cateRelatedModel->where('product_id',$product_id)->pluck('cate_id')->toArray(); | ||
| 304 | - $category_name = ''; | ||
| 305 | - if(!empty($category_id) && !empty($data)){ | ||
| 306 | - foreach ($category_id as $v){ | ||
| 307 | - if(isset($data[$v])){ | ||
| 308 | - $category_name .= $data[$v].','; | ||
| 309 | - } | ||
| 310 | - } | ||
| 311 | - $category_name = trim($category_name,','); | ||
| 312 | - } | ||
| 313 | - return $category_name; | 195 | + public function getStatusNumber(ProductLogic $logic){ |
| 196 | + $this->request->validate([ | ||
| 197 | + 'featured_status'=>'numeric', | ||
| 198 | + ],[ | ||
| 199 | + 'featured_status.numeric' => 'numeric为数字', | ||
| 200 | + ]); | ||
| 201 | + $data = $logic->getStatusNumber(); | ||
| 202 | + $this->response('success',Code::SUCCESS,$data); | ||
| 314 | } | 203 | } |
| 315 | 204 | ||
| 316 | /** | 205 | /** |
| 317 | - * @remark :获取关键词名称 | ||
| 318 | - * @name :categoryName | 206 | + * @remark :复制产品 |
| 207 | + * @name :copyProduct | ||
| 319 | * @author :lyh | 208 | * @author :lyh |
| 320 | * @method :post | 209 | * @method :post |
| 321 | - * @time :2023/9/14 13:58 | 210 | + * @time :2023/7/29 14:59 |
| 322 | */ | 211 | */ |
| 323 | - public function keywordName($keyword_id,$data){ | ||
| 324 | - $keyword_name = ''; | ||
| 325 | - if(!empty($keyword_id) && !empty($data)){ | ||
| 326 | - foreach ($keyword_id as $v){ | ||
| 327 | - if(isset($data[$v])){ | ||
| 328 | - $keyword_name .= $data[$v].','; | ||
| 329 | - } | ||
| 330 | - } | ||
| 331 | - $keyword_name = trim($keyword_name,','); | ||
| 332 | - } | ||
| 333 | - return $keyword_name; | 212 | + public function copyProduct(ProductLogic $logic){ |
| 213 | + $this->request->validate([ | ||
| 214 | + 'id'=>'required', | ||
| 215 | + ],[ | ||
| 216 | + 'id.required' => 'id不能为空', | ||
| 217 | + ]); | ||
| 218 | + $data = $logic->setCopyProduct(); | ||
| 219 | + $this->response('success',Code::SUCCESS,$data); | ||
| 334 | } | 220 | } |
| 335 | 221 | ||
| 336 | /** | 222 | /** |
| 337 | - * @remark :详情 | ||
| 338 | - * @name :info | 223 | + * @remark :批量设置产品分类 |
| 224 | + * @name :batchSetCategory | ||
| 339 | * @author :lyh | 225 | * @author :lyh |
| 340 | * @method :post | 226 | * @method :post |
| 341 | - * @time :2023/8/21 18:12 | 227 | + * @time :2023/8/15 17:51 |
| 342 | */ | 228 | */ |
| 343 | - public function info(Product $product){ | 229 | + public function batchSetCategory(ProductLogic $logic){ |
| 344 | $this->request->validate([ | 230 | $this->request->validate([ |
| 345 | - 'id'=>'required' | 231 | + 'id'=>'required', |
| 232 | + 'category_id'=>'required', | ||
| 346 | ],[ | 233 | ],[ |
| 347 | - 'id.required' => 'ID不能为空' | 234 | + 'id.required' => '产品ID不能为空', |
| 235 | + 'category_id.required' => '分类ID不能为空', | ||
| 348 | ]); | 236 | ]); |
| 349 | - $info = $product->read(['id'=>$this->param['id']]); | ||
| 350 | - $info = $this->handleParam($info); | ||
| 351 | - return $this->response('success',Code::SUCCESS,$info); | ||
| 352 | - } | ||
| 353 | - | ||
| 354 | - /** | ||
| 355 | - * @remark :处理列表参数 | ||
| 356 | - * @name :handleParam | ||
| 357 | - * @author :lyh | ||
| 358 | - * @method :post | ||
| 359 | - * @time :2023/8/17 9:15 | ||
| 360 | - */ | ||
| 361 | - public function handleParam($v){ | ||
| 362 | - $v['keyword_id_text'] = ''; | ||
| 363 | - if(!empty($v['keyword_id'])){ | ||
| 364 | - $keywordModel = new Keyword(); | ||
| 365 | - $keyword_data = $keywordModel->list(['id'=>['in',$v['keyword_id']]]); | ||
| 366 | - foreach ($keyword_data as $v1){ | ||
| 367 | - $v['keyword_id_text'] .= $v1['title'].','; | ||
| 368 | - } | ||
| 369 | - $v['keyword_id_text'] = trim($v['keyword_id_text'],','); | ||
| 370 | - } | ||
| 371 | - if(!empty($v['status'])){ | ||
| 372 | - $v['status_text'] = Product::statusMap()[$v['status']] ?? ''; | ||
| 373 | - }else{ | ||
| 374 | - $v['status_text'] = ''; | ||
| 375 | - } | ||
| 376 | - //ToDo::处理图片及文件 | ||
| 377 | - $v = $this->getHandleFileImage($v); | ||
| 378 | - $template_id = $this->getTemplateId(BTemplate::SOURCE_PRODUCT,BTemplate::IS_DETAIL); | ||
| 379 | - $v['is_renovation'] = $this->getIsRenovation(BTemplate::SOURCE_PRODUCT,BTemplate::IS_DETAIL,$template_id,$v['id'] ?? 0); | ||
| 380 | - $v['url'] = $this->user['domain'].($v['route'] ?? ''); | ||
| 381 | - //获取当前数据扩展字段及值 | ||
| 382 | - $v['extend'] = $this->getExtendInfo($v['id']); | ||
| 383 | - return $v; | ||
| 384 | - } | ||
| 385 | - | ||
| 386 | - | ||
| 387 | - /** | ||
| 388 | - * @remark :获取扩展字段详情 | ||
| 389 | - * @name :getExtendInfo | ||
| 390 | - * @author :lyh | ||
| 391 | - * @method :post | ||
| 392 | - * @time :2023/11/14 9:45 | ||
| 393 | - */ | ||
| 394 | - public function getExtendInfo($product_id){ | ||
| 395 | - $extendModel = new Extend(); | ||
| 396 | - $list = $extendModel->list([],'id',['id','type','key','title']); | ||
| 397 | - if(empty($list)){ | ||
| 398 | - return []; | ||
| 399 | - } | ||
| 400 | - $extendInfoModel = new ExtendInfo(); | ||
| 401 | - $infoList = $extendInfoModel->list(['product_id'=>$product_id],'created_at'); | ||
| 402 | - foreach ($list as $k=>$v){ | ||
| 403 | - foreach ($infoList as $values){ | ||
| 404 | - if($v['key'] == $values['key']){ | ||
| 405 | - $v = $this->setTypValues($v,$values); | ||
| 406 | - break; | ||
| 407 | - } | ||
| 408 | - } | ||
| 409 | - $list[$k] = $v; | ||
| 410 | - } | ||
| 411 | - $list = $this->handleExtentList($list); | ||
| 412 | - return $list; | ||
| 413 | - } | ||
| 414 | - | ||
| 415 | - /** | ||
| 416 | - * @remark :处理详情数据(初始化) | ||
| 417 | - * @name :handleList | ||
| 418 | - * @author :lyh | ||
| 419 | - * @method :post | ||
| 420 | - * @time :2024/8/14 18:26 | ||
| 421 | - */ | ||
| 422 | - public function handleExtentList($list){ | ||
| 423 | - foreach ($list as $k => $v){ | ||
| 424 | - if($v['type'] == 3 || $v['type'] == 4){ | ||
| 425 | - if(!isset($v['values'])){ | ||
| 426 | - $v['values'] = []; | ||
| 427 | - } | ||
| 428 | - }else{ | ||
| 429 | - if(!isset($v['values'])){ | ||
| 430 | - $v['values'] = ''; | ||
| 431 | - } | ||
| 432 | - } | ||
| 433 | - $list[$k] = $v; | ||
| 434 | - } | ||
| 435 | - return $this->success($list); | ||
| 436 | - } | ||
| 437 | - /** | ||
| 438 | - * @remark :扩展字段根据type返回类型 | ||
| 439 | - * @name :setTypValues | ||
| 440 | - * @author :lyh | ||
| 441 | - * @method :post | ||
| 442 | - * @time :2023/12/6 14:43 | ||
| 443 | - */ | ||
| 444 | - public function setTypValues($v,$info){ | ||
| 445 | - if($v['type'] == 3){ | ||
| 446 | - $arr = json_decode($info['values']); | ||
| 447 | - foreach ($arr as $k1=>$v1){ | ||
| 448 | - $v1 = (array)$v1; | ||
| 449 | - $v1['url'] = getImageUrl($v1['url'],$this->user['storage_type'],$this->user['project_location']); | ||
| 450 | - $arr[$k1] = $v1; | ||
| 451 | - } | ||
| 452 | - $v['values'] = $arr; | ||
| 453 | - }elseif($v['type'] == 4){ | ||
| 454 | - $arr1 = json_decode($info['values']); | ||
| 455 | - foreach ($arr1 as $k1=>$v1){ | ||
| 456 | - $v1 = (array)$v1; | ||
| 457 | - if(isset($v1['url'])){ | ||
| 458 | - $v1['url'] = getFileUrl($v1['url'],$this->user['storage_type'],$this->user['project_location'],$this->user['file_cdn'] ?? 0); | ||
| 459 | - }else{ | ||
| 460 | - $v1 = getFileUrl($v1,$this->user['storage_type'],$this->user['project_location'],$this->user['file_cdn'] ?? 0); | ||
| 461 | - } | ||
| 462 | - $arr1[$k1] = $v1; | ||
| 463 | - } | ||
| 464 | - $v['values'] = $arr1; | ||
| 465 | - }else{ | ||
| 466 | - $v['values'] = $info['values']; | ||
| 467 | - } | ||
| 468 | - return $v; | ||
| 469 | - } | ||
| 470 | - | ||
| 471 | - /** | ||
| 472 | - * @remark :保存产品数据 | ||
| 473 | - * @name :save | ||
| 474 | - * @author :lyh | ||
| 475 | - * @method :post | ||
| 476 | - * @time :2023/8/17 15:01 | ||
| 477 | - */ | ||
| 478 | - public function save(ProductRequest $request, ProductLogic $logic) | ||
| 479 | - { | ||
| 480 | - $request->validated(); | ||
| 481 | - $data = $logic->productSave(); | ||
| 482 | - $this->response('success',Code::SUCCESS,$data); | ||
| 483 | - } | ||
| 484 | - | ||
| 485 | - /** | ||
| 486 | - * @remark :直接编辑列表数据 | ||
| 487 | - * @name :editList | ||
| 488 | - * @author :lyh | ||
| 489 | - * @method :post | ||
| 490 | - * @time :2023/10/26 9:48 | ||
| 491 | - */ | ||
| 492 | - public function editList(ProductLogic $logic){ | ||
| 493 | - $logic->editList(); | ||
| 494 | - $this->response('success'); | ||
| 495 | - } | ||
| 496 | - | ||
| 497 | - /** | ||
| 498 | - * @remark :删除 | ||
| 499 | - * @name :delete | ||
| 500 | - * @author :lyh | ||
| 501 | - * @method :post | ||
| 502 | - * @time :2023/8/22 13:45 | ||
| 503 | - */ | ||
| 504 | - public function delete(ProductLogic $logic) | ||
| 505 | - { | ||
| 506 | - $this->request->validate([ | ||
| 507 | - 'ids'=>['required', new Ids()] | ||
| 508 | - ],[ | ||
| 509 | - 'ids.required' => 'ID不能为空' | ||
| 510 | - ]); | ||
| 511 | - $logic->productDelete(); | ||
| 512 | - $this->response('success'); | ||
| 513 | - } | ||
| 514 | - | ||
| 515 | - | ||
| 516 | - /** | ||
| 517 | - * @remark :根据状态获取数量 | ||
| 518 | - * @name :getStatusNumber | ||
| 519 | - * @author :lyh | ||
| 520 | - * @method :post | ||
| 521 | - * @time :2023/8/21 18:33 | ||
| 522 | - */ | ||
| 523 | - public function getStatusNumber(ProductLogic $logic){ | ||
| 524 | - $this->request->validate([ | ||
| 525 | - 'featured_status'=>'numeric', | ||
| 526 | - ],[ | ||
| 527 | - 'featured_status.numeric' => 'numeric为数字', | ||
| 528 | - ]); | ||
| 529 | - $data = $logic->getStatusNumber(); | ||
| 530 | - $this->response('success',Code::SUCCESS,$data); | ||
| 531 | - } | ||
| 532 | - | ||
| 533 | - /** | ||
| 534 | - * @remark :复制产品 | ||
| 535 | - * @name :copyProduct | ||
| 536 | - * @author :lyh | ||
| 537 | - * @method :post | ||
| 538 | - * @time :2023/7/29 14:59 | ||
| 539 | - */ | ||
| 540 | - public function copyProduct(ProductLogic $logic){ | ||
| 541 | - $this->request->validate([ | ||
| 542 | - 'id'=>'required', | ||
| 543 | - ],[ | ||
| 544 | - 'id.required' => 'id不能为空', | ||
| 545 | - ]); | ||
| 546 | - $data = $logic->setCopyProduct(); | ||
| 547 | - $this->response('success',Code::SUCCESS,$data); | ||
| 548 | - } | ||
| 549 | - | ||
| 550 | - /** | ||
| 551 | - * @remark :批量设置产品分类 | ||
| 552 | - * @name :batchSetCategory | ||
| 553 | - * @author :lyh | ||
| 554 | - * @method :post | ||
| 555 | - * @time :2023/8/15 17:51 | ||
| 556 | - */ | ||
| 557 | - public function batchSetCategory(ProductLogic $logic){ | ||
| 558 | - $this->request->validate([ | ||
| 559 | - 'id'=>'required', | ||
| 560 | - 'category_id'=>'required', | ||
| 561 | - ],[ | ||
| 562 | - 'id.required' => '产品ID不能为空', | ||
| 563 | - 'category_id.required' => '分类ID不能为空', | ||
| 564 | - ]); | ||
| 565 | - $logic->batchSetCategory(); | ||
| 566 | - $this->response('success'); | 237 | + $logic->batchSetCategory(); |
| 238 | + $this->response('success'); | ||
| 567 | } | 239 | } |
| 568 | 240 | ||
| 569 | /** | 241 | /** |
| @@ -812,4 +484,335 @@ class ProductController extends BaseController | @@ -812,4 +484,335 @@ class ProductController extends BaseController | ||
| 812 | $logic->batchSetKeyword(); | 484 | $logic->batchSetKeyword(); |
| 813 | $this->response('success'); | 485 | $this->response('success'); |
| 814 | } | 486 | } |
| 487 | + | ||
| 488 | + /** | ||
| 489 | + * @remark :获取所有分类 | ||
| 490 | + * @name :getCategoryList | ||
| 491 | + * @author :lyh | ||
| 492 | + * @method :post | ||
| 493 | + * @time :2023/9/14 13:56 | ||
| 494 | + */ | ||
| 495 | + public function getCategoryList(){ | ||
| 496 | + $data = Common::get_user_cache('product_category',$this->user['project_id']); | ||
| 497 | + if(empty($data)){ | ||
| 498 | + $categoryModel = new Category(); | ||
| 499 | + $data = []; | ||
| 500 | + $cateList = $categoryModel->list(['project_id'=>$this->user['project_id']],['id','title']); | ||
| 501 | + if(!empty($cateList)){ | ||
| 502 | + foreach ($cateList as $value){ | ||
| 503 | + $data[$value['id']] = $value['title']; | ||
| 504 | + } | ||
| 505 | + } | ||
| 506 | + Common::set_user_cache($data,'product_category',$this->user['project_id']); | ||
| 507 | + } | ||
| 508 | + return $data; | ||
| 509 | + } | ||
| 510 | + /** | ||
| 511 | + * @remark :获取当前页的所有关键字名称 | ||
| 512 | + * @name :keywordNameLists | ||
| 513 | + * @author :lyh | ||
| 514 | + * @method :post | ||
| 515 | + * @time :2024/6/3 14:24 | ||
| 516 | + */ | ||
| 517 | + public function keywordNameLists($lists){ | ||
| 518 | + $keywordId = []; | ||
| 519 | + foreach ($lists as $v){ | ||
| 520 | + $keywordId = array_merge($keywordId,$v['keyword_id']); | ||
| 521 | + } | ||
| 522 | + $keywordId = array_values(array_unique($keywordId)); | ||
| 523 | + $keywordModel = new Keyword(); | ||
| 524 | + $data = []; | ||
| 525 | + $cateList = $keywordModel->list(['id' => ['in',$keywordId]], ['id', 'title']); | ||
| 526 | + if (!empty($cateList)) { | ||
| 527 | + foreach ($cateList as $value) { | ||
| 528 | + $data[$value['id']] = $value['title']; | ||
| 529 | + } | ||
| 530 | + } | ||
| 531 | + return $data; | ||
| 532 | + } | ||
| 533 | + | ||
| 534 | + /** | ||
| 535 | + * @remark :获取时处理图片和文件 | ||
| 536 | + * @name :getHandleFileImage | ||
| 537 | + * @author :lyh | ||
| 538 | + * @method :post | ||
| 539 | + * @time :2024/1/23 17:43 | ||
| 540 | + */ | ||
| 541 | + public function getHandleFileImage($v){ | ||
| 542 | + //ToDo::处理图片及文件 | ||
| 543 | + if(!empty($v['thumb']) && !empty($v['thumb']['url'])){ | ||
| 544 | + $v['thumb']['url'] = getImageUrl($v['thumb']['url'],$this->user['storage_type'] ?? 0,$this->user['project_location']); | ||
| 545 | + } | ||
| 546 | + if(!empty($v['gallery'])){ | ||
| 547 | + foreach ($v['gallery'] as $gallery_k => $gallery_v){ | ||
| 548 | + $gallery_v['url'] = getImageUrl($gallery_v['url'],$this->user['storage_type'] ?? 0,$this->user['project_location']); | ||
| 549 | + $v['gallery'][$gallery_k] = $gallery_v; | ||
| 550 | + } | ||
| 551 | + } | ||
| 552 | + if(!empty($v['icon'])){ | ||
| 553 | + foreach ($v['icon'] as $icon_k => $icon_v){ | ||
| 554 | + $icon_v = getImageUrl($icon_v,$this->user['storage_type'] ?? 0,$this->user['project_location']); | ||
| 555 | + $v['icon'][$icon_k] = $icon_v; | ||
| 556 | + } | ||
| 557 | + } | ||
| 558 | + if(!empty($v['video'])){ | ||
| 559 | + $v['video']['url'] = getFileUrl($v['video']['url'],$this->user['storage_type'] ?? 0,$this->user['project_location'],$this->user['file_cdn'] ?? 0); | ||
| 560 | + $v['video']['video_image'] = getImageUrl($v['video']['video_image'] ?? '',$this->user['storage_type'] ?? 0,$this->user['project_location']); | ||
| 561 | + } | ||
| 562 | + if(!empty($v['files']) && !empty($v['files']['url'])){ | ||
| 563 | + $v['files']['url'] = getFileUrl($v['files']['url'],$this->user['storage_type'] ?? 0,$this->user['project_location'],$this->user['file_cdn'] ?? 0); | ||
| 564 | + } | ||
| 565 | + return $this->success($v); | ||
| 566 | + } | ||
| 567 | + | ||
| 568 | + /** | ||
| 569 | + * @remark :处理详情数据(初始化) | ||
| 570 | + * @name :handleList | ||
| 571 | + * @author :lyh | ||
| 572 | + * @method :post | ||
| 573 | + * @time :2024/8/14 18:26 | ||
| 574 | + */ | ||
| 575 | + public function handleExtentList($list){ | ||
| 576 | + foreach ($list as $k => $v){ | ||
| 577 | + if($v['type'] == 3 || $v['type'] == 4){ | ||
| 578 | + if(!isset($v['values'])){ | ||
| 579 | + $v['values'] = []; | ||
| 580 | + } | ||
| 581 | + }else{ | ||
| 582 | + if(!isset($v['values'])){ | ||
| 583 | + $v['values'] = ''; | ||
| 584 | + } | ||
| 585 | + } | ||
| 586 | + $list[$k] = $v; | ||
| 587 | + } | ||
| 588 | + return $this->success($list); | ||
| 589 | + } | ||
| 590 | + | ||
| 591 | + /** | ||
| 592 | + * @remark :扩展字段根据type返回类型 | ||
| 593 | + * @name :setTypValues | ||
| 594 | + * @author :lyh | ||
| 595 | + * @method :post | ||
| 596 | + * @time :2023/12/6 14:43 | ||
| 597 | + */ | ||
| 598 | + public function setTypValues($v,$info){ | ||
| 599 | + if($v['type'] == 3){ | ||
| 600 | + $arr = json_decode($info['values']); | ||
| 601 | + foreach ($arr as $k1=>$v1){ | ||
| 602 | + $v1 = (array)$v1; | ||
| 603 | + $v1['url'] = getImageUrl($v1['url'],$this->user['storage_type'],$this->user['project_location']); | ||
| 604 | + $arr[$k1] = $v1; | ||
| 605 | + } | ||
| 606 | + $v['values'] = $arr; | ||
| 607 | + }elseif($v['type'] == 4){ | ||
| 608 | + $arr1 = json_decode($info['values']); | ||
| 609 | + foreach ($arr1 as $k1=>$v1){ | ||
| 610 | + $v1 = (array)$v1; | ||
| 611 | + if(isset($v1['url'])){ | ||
| 612 | + $v1['url'] = getFileUrl($v1['url'],$this->user['storage_type'],$this->user['project_location'],$this->user['file_cdn'] ?? 0); | ||
| 613 | + }else{ | ||
| 614 | + $v1 = getFileUrl($v1,$this->user['storage_type'],$this->user['project_location'],$this->user['file_cdn'] ?? 0); | ||
| 615 | + } | ||
| 616 | + $arr1[$k1] = $v1; | ||
| 617 | + } | ||
| 618 | + $v['values'] = $arr1; | ||
| 619 | + }else{ | ||
| 620 | + $v['values'] = $info['values']; | ||
| 621 | + } | ||
| 622 | + return $this->success($v); | ||
| 623 | + } | ||
| 624 | + | ||
| 625 | + /** | ||
| 626 | + * @remark :搜索参数处理 | ||
| 627 | + * @name :handleReturnParam | ||
| 628 | + * @author :lyh | ||
| 629 | + * @method :post | ||
| 630 | + * @time :2023/9/14 10:01 | ||
| 631 | + */ | ||
| 632 | + public function searchParam(&$query){ | ||
| 633 | + $query = $query->where('project_id',$this->user['project_id']); | ||
| 634 | + if (isset($this->map['category_id']) && !empty($this->map['category_id'])) { | ||
| 635 | + $str[] = $this->map['category_id']; | ||
| 636 | + $this->getAllSub($this->map['category_id'],$str); | ||
| 637 | + $categoryRelatedModel = new CategoryRelated(); | ||
| 638 | + $product_id_arr = $categoryRelatedModel->whereIn('cate_id',$str)->pluck('product_id')->toArray(); | ||
| 639 | + $query = $query->whereIn('id',$product_id_arr); | ||
| 640 | + } | ||
| 641 | + if(isset($this->map['title']) && !empty($this->map['title'])){ | ||
| 642 | + $this->map['title'] = str_replace('+',' ',$this->map['title']); | ||
| 643 | + $query = $query->where('title','like','%'.$this->map['title'].'%'); | ||
| 644 | + } | ||
| 645 | + if(isset($this->map['keyword_title']) && !empty($this->map['keyword_title'])){ | ||
| 646 | + $keywordModel = new Keyword(); | ||
| 647 | + $keywordInfo = $keywordModel->read(['title'=>$this->map['keyword_title']],['id']); | ||
| 648 | + if(!empty($keywordInfo)){ | ||
| 649 | + $query = $query->where('keyword_id','like','%,'.$keywordInfo['id'].',%'); | ||
| 650 | + } | ||
| 651 | + } | ||
| 652 | + if(isset($this->map['status'])){ | ||
| 653 | + if($this->map['status'] == 0){ | ||
| 654 | + $query = $query->whereIn('status',[0,3]); | ||
| 655 | + }else{ | ||
| 656 | + $query = $query->where('status',$this->map['status']); | ||
| 657 | + } | ||
| 658 | + } | ||
| 659 | + if(isset($this->map['created_uid'])){ | ||
| 660 | + $query = $query->where('created_uid',$this->map['created_uid']); | ||
| 661 | + } | ||
| 662 | + if(!empty($this->param['start_at']) && !empty($this->param['end_at'])){ | ||
| 663 | + if($this->user['project_id'] == 2059){ | ||
| 664 | + $query->where('send_time', '>=' ,$this->param['start_at'].' 00:00:00')->where('send_time', '<=' ,$this->param['end_at'].' 59:59:59'); | ||
| 665 | + }else{ | ||
| 666 | + $query->where('created_at', '>=' ,$this->param['start_at'].' 00:00:00')->where('created_at', '<=' ,$this->param['end_at'].' 59:59:59'); | ||
| 667 | + } | ||
| 668 | + } | ||
| 669 | + $this->param['featured_status'] = $this->param['featured_status'] ?? 0; | ||
| 670 | + if($this->param['featured_status'] != Category::STATUS_ACTIVE) { | ||
| 671 | + $cateModel = new Category(); | ||
| 672 | + $featured_ids = $cateModel->formatQuery(['title'=>['in',['Featured','featured']]])->pluck('id')->toArray(); | ||
| 673 | + if(!empty($featured_ids)){ | ||
| 674 | + $status = []; | ||
| 675 | + if(isset($this->map['status'])){ | ||
| 676 | + $status = ['status'=>$this->map['status']]; | ||
| 677 | + } | ||
| 678 | + $cateList = $cateModel->list($status,'id',['id','pid']); | ||
| 679 | + //获取当前的子集 | ||
| 680 | + $featured_arr = []; | ||
| 681 | + foreach ($featured_ids as $id){ | ||
| 682 | + $featured_arr = array_merge($featured_arr,array_unique(_get_all_sub($id,$cateList))); | ||
| 683 | + } | ||
| 684 | + if(!empty($featured_arr)){ | ||
| 685 | + $cateRelated = new CategoryRelated(); | ||
| 686 | + $product_ids = $cateRelated->whereIn('cate_id',$featured_arr)->pluck('product_id')->unique()->toArray(); | ||
| 687 | + $query = $query->whereNotIn('id',$product_ids); | ||
| 688 | + } | ||
| 689 | + } | ||
| 690 | + } | ||
| 691 | + return $query; | ||
| 692 | + } | ||
| 693 | + | ||
| 694 | + | ||
| 695 | + /** | ||
| 696 | + * @remark :处理列表参数 | ||
| 697 | + * @name :handleParam | ||
| 698 | + * @author :lyh | ||
| 699 | + * @method :post | ||
| 700 | + * @time :2023/8/17 9:15 | ||
| 701 | + */ | ||
| 702 | + public function handleParam($v){ | ||
| 703 | + $v['keyword_id_text'] = ''; | ||
| 704 | + if(!empty($v['keyword_id'])){ | ||
| 705 | + $keywordModel = new Keyword(); | ||
| 706 | + $keyword_data = $keywordModel->list(['id'=>['in',$v['keyword_id']]]); | ||
| 707 | + foreach ($keyword_data as $v1){ | ||
| 708 | + $v['keyword_id_text'] .= $v1['title'].','; | ||
| 709 | + } | ||
| 710 | + $v['keyword_id_text'] = trim($v['keyword_id_text'],','); | ||
| 711 | + } | ||
| 712 | + if(!empty($v['status'])){ | ||
| 713 | + $v['status_text'] = Product::statusMap()[$v['status']] ?? ''; | ||
| 714 | + }else{ | ||
| 715 | + $v['status_text'] = ''; | ||
| 716 | + } | ||
| 717 | + //ToDo::处理图片及文件 | ||
| 718 | + $v = $this->getHandleFileImage($v); | ||
| 719 | + $template_id = $this->getTemplateId(BTemplate::SOURCE_PRODUCT,BTemplate::IS_DETAIL); | ||
| 720 | + $v['is_renovation'] = $this->getIsRenovation(BTemplate::SOURCE_PRODUCT,BTemplate::IS_DETAIL,$template_id,$v['id'] ?? 0); | ||
| 721 | + $v['url'] = $this->user['domain'].($v['route'] ?? ''); | ||
| 722 | + //获取当前数据扩展字段及值 | ||
| 723 | + $v['extend'] = $this->getExtendInfo($v['id']); | ||
| 724 | + return $v; | ||
| 725 | + } | ||
| 726 | + | ||
| 727 | + | ||
| 728 | + /** | ||
| 729 | + * @remark :获取扩展字段详情 | ||
| 730 | + * @name :getExtendInfo | ||
| 731 | + * @author :lyh | ||
| 732 | + * @method :post | ||
| 733 | + * @time :2023/11/14 9:45 | ||
| 734 | + */ | ||
| 735 | + public function getExtendInfo($product_id){ | ||
| 736 | + $extendModel = new Extend(); | ||
| 737 | + $list = $extendModel->list([],'id',['id','type','key','title']); | ||
| 738 | + if(empty($list)){ | ||
| 739 | + return []; | ||
| 740 | + } | ||
| 741 | + $extendInfoModel = new ExtendInfo(); | ||
| 742 | + $infoList = $extendInfoModel->list(['product_id'=>$product_id],'created_at'); | ||
| 743 | + foreach ($list as $k=>$v){ | ||
| 744 | + foreach ($infoList as $values){ | ||
| 745 | + if($v['key'] == $values['key']){ | ||
| 746 | + $v = $this->setTypValues($v,$values); | ||
| 747 | + break; | ||
| 748 | + } | ||
| 749 | + } | ||
| 750 | + $list[$k] = $v; | ||
| 751 | + } | ||
| 752 | + $list = $this->handleExtentList($list); | ||
| 753 | + return $list; | ||
| 754 | + } | ||
| 755 | + | ||
| 756 | + /** | ||
| 757 | + * @remark :获取当前id下所有子集 | ||
| 758 | + * @name :getAllSub | ||
| 759 | + * @author :lyh | ||
| 760 | + * @method :post | ||
| 761 | + * @time :2023/10/18 15:10 | ||
| 762 | + */ | ||
| 763 | + public function getAllSub($id,&$str = []){ | ||
| 764 | + $cateModel = new Category(); | ||
| 765 | + $list = $cateModel->list(['pid'=>$id,'status'=>1],['id','pid']); | ||
| 766 | + if(!empty($list)){ | ||
| 767 | + foreach ($list as $v){ | ||
| 768 | + $str[] = $v['id']; | ||
| 769 | + $this->getAllSub($v['id'],$str); | ||
| 770 | + } | ||
| 771 | + } | ||
| 772 | + return $str; | ||
| 773 | + } | ||
| 774 | + | ||
| 775 | + | ||
| 776 | + | ||
| 777 | + /** | ||
| 778 | + * @remark :获取分类名称 | ||
| 779 | + * @name :categoryName | ||
| 780 | + * @author :lyh | ||
| 781 | + * @method :post | ||
| 782 | + * @time :2023/9/14 13:58 | ||
| 783 | + */ | ||
| 784 | + public function categoryName($product_id,$data){ | ||
| 785 | + $cateRelatedModel = new CategoryRelated(); | ||
| 786 | + $category_id = $cateRelatedModel->where('product_id',$product_id)->pluck('cate_id')->toArray(); | ||
| 787 | + $category_name = ''; | ||
| 788 | + if(!empty($category_id) && !empty($data)){ | ||
| 789 | + foreach ($category_id as $v){ | ||
| 790 | + if(isset($data[$v])){ | ||
| 791 | + $category_name .= $data[$v].','; | ||
| 792 | + } | ||
| 793 | + } | ||
| 794 | + $category_name = trim($category_name,','); | ||
| 795 | + } | ||
| 796 | + return $category_name; | ||
| 797 | + } | ||
| 798 | + | ||
| 799 | + /** | ||
| 800 | + * @remark :获取关键词名称 | ||
| 801 | + * @name :categoryName | ||
| 802 | + * @author :lyh | ||
| 803 | + * @method :post | ||
| 804 | + * @time :2023/9/14 13:58 | ||
| 805 | + */ | ||
| 806 | + public function keywordName($keyword_id,$data){ | ||
| 807 | + $keyword_name = ''; | ||
| 808 | + if(!empty($keyword_id) && !empty($data)){ | ||
| 809 | + foreach ($keyword_id as $v){ | ||
| 810 | + if(isset($data[$v])){ | ||
| 811 | + $keyword_name .= $data[$v].','; | ||
| 812 | + } | ||
| 813 | + } | ||
| 814 | + $keyword_name = trim($keyword_name,','); | ||
| 815 | + } | ||
| 816 | + return $keyword_name; | ||
| 817 | + } | ||
| 815 | } | 818 | } |
-
请 注册 或 登录 后发表评论