ProductController.php 28.3 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 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834
<?php

namespace App\Http\Controllers\Bside\Product;

use App\Enums\Common\Code;
use App\Exceptions\BsideGlobalException;
use App\Helper\Arr;
use App\Helper\Common;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\BTemplate\BTemplateLogic;
use App\Http\Logic\Bside\Product\ProductLogic;
use App\Http\Requests\Bside\Product\ProductRequest;
use App\Models\Product\Category;
use App\Models\Product\CategoryRelated;
use App\Models\Product\Detail;
use App\Models\Product\Extend;
use App\Models\Product\ExtendInfo;
use App\Models\Product\Keyword;
use App\Models\Product\KeywordRelated;
use App\Models\Product\Product;
use App\Models\Product\ProductType;
use App\Models\RouteMap\RouteMap;
use App\Models\Template\Setting;
use App\Models\Template\BTemplate;
use App\Models\User\User;
use App\Models\WebSetting\SettingNum;
use App\Rules\Ids;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;

/**
 * Class ProductController
 * @package App\Http\Controllers\Bside
 * @author zbj
 * @date 2023/4/17
 */
class ProductController extends BaseController
{

    /**
     * @remark :列表
     * @name   :index
     * @author :lyh
     * @method :post
     * @time   :2023/8/28 16:30
     */
    public function index(Product $product)
    {
        $filed = ['id', 'project_id', 'title', 'sort' ,'thumb' ,'product_type' , 'route' ,
            'category_id', 'keyword_id', 'status', 'created_uid', 'is_upgrade' ,'created_at', 'updated_at','six_read'];
        $this->order = $this->param['order'] ?? 'sort';
        $query = $product->orderBy($this->order ,$this->order_type)->orderBy('id','desc');
        $query = $this->searchParam($query);
        $lists = $query->select($filed)->paginate($this->row, ['*'], 'page', $this->page);
        if(!empty($lists)){
            $lists = $lists->toArray();
            $cate_data = $this->getCategoryList();//分类
            $key_data = $this->keywordNameLists($lists['list']);//关键字
            $template_id = $this->getTemplateId(BTemplate::SOURCE_PRODUCT,BTemplate::IS_DETAIL);//获取模版id
            $userModel = new User();
            foreach ($lists['list'] as $k=>$v){
                $route = getRouteMap(RouteMap::SOURCE_PRODUCT,$v['id'], 0, false);
                $v['url'] = $this->user['domain'] . $route['route'] ?? '';
                $v['pv'] = $route['pv'];
                $v['category_id_text'] = $this->categoryName($v['id'],$cate_data);
                $v['keyword_id_text'] = $this->keywordName($v['keyword_id'],$key_data);
                $v['created_uid_text'] = $userModel->getName($v['created_uid']);
                $v['is_renovation']  =  $this->getIsRenovation(BTemplate::SOURCE_PRODUCT,BTemplate::IS_DETAIL,$template_id,$v['id']);
                $v = $this->getHandleFileImage($v);
                $lists['list'][$k] = $v;
            }
            $lists['order_type'] = $this->order_type;
            $lists['order'] = $this->order;
        }
        $this->response('success',Code::SUCCESS,$lists);
    }

    /**
     * @remark :下载列表
     * @name   :index
     * @author :lyh
     * @method :post
     * @time   :2023/8/28 16:30
     */
    public function downloadProduct(Product $product)
    {
        $filed = ['id', 'project_id', 'title', 'sort' ,'thumb' ,'product_type' , 'route' ,'intro','content',
            'category_id', 'keyword_id', 'status', 'created_uid', 'is_upgrade' ,'created_at', 'updated_at','six_read'];
        $this->order = 'sort';
        $query = $product->orderBy($this->order ,'desc')->orderBy('id','desc');
        $query = $this->searchParam($query);
        $lists = $query->select($filed)->paginate($this->row, ['*'], 'page', $this->page);
        if(!empty($lists)){
            $lists = $lists->toArray();
            $cate_data = $this->getCategoryList();//分类
            $key_data = $this->keywordNameLists($lists['list']);//关键字
            $template_id = $this->getTemplateId(BTemplate::SOURCE_PRODUCT,BTemplate::IS_DETAIL);//获取模版id
            $userModel = new User();
            foreach ($lists['list'] as $k=>$v){
                $route = getRouteMap(RouteMap::SOURCE_PRODUCT,$v['id'], 0, true);
                $v['url'] = $this->user['domain'] . $route['route'];
                $v['pv'] = $route['pv'];
                $v['category_id_text'] = $this->categoryName($v['id'],$cate_data);
                $v['keyword_id_text'] = $this->keywordName($v['keyword_id'],$key_data);
                $v['created_uid_text'] = $userModel->getName($v['created_uid']);
                $v['is_renovation']  =  $this->getIsRenovation(BTemplate::SOURCE_PRODUCT,BTemplate::IS_DETAIL,$template_id,$v['id']);
                $v = $this->getHandleFileImage($v);
                $lists['list'][$k] = $v;
            }
        }
        $this->response('success',Code::SUCCESS,$lists);
    }

    /**
     * @remark :不分页产品列表
     * @name   :productNoPage
     * @author :lyh
     * @method :post
     * @time   :2024/3/20 11:02
     */
    public function productNoPage(Product $product){
        $this->map['status'] = $product::STATUS_ON;
        $lists = $product->list($this->map,'id',['id','title']);
        $this->response('success',Code::SUCCESS,$lists);
    }

    /**
     * @remark :详情
     * @name   :info
     * @author :lyh
     * @method :post
     * @time   :2023/8/21 18:12
     */
    public function info(Product $product){
        $this->request->validate([
            'id'=>'required'
        ],[
            'id.required' => 'ID不能为空'
        ]);
        $info = $product->read(['id'=>$this->param['id']]);
        if($info === false){
            $this->fail('当前数据不存在,或已被删除');
        }
        $info = $this->handleParam($info);
        return $this->response('success',Code::SUCCESS,$info);
    }

    /**
     * @remark :保存产品数据
     * @name   :save
     * @author :lyh
     * @method :post
     * @time   :2023/8/17 15:01
     */
    public function save(ProductRequest $request, ProductLogic $logic)
    {
        $request->validated();
        $data = $logic->productSave();
        $this->response('success',Code::SUCCESS,$data);
    }

    /**
     * @remark :直接编辑列表数据
     * @name   :editList
     * @author :lyh
     * @method :post
     * @time   :2023/10/26 9:48
     */
    public function editList(ProductLogic $logic){
        $logic->editList();
        $this->response('success');
    }

    /**
     * @remark :删除
     * @name   :delete
     * @author :lyh
     * @method :post
     * @time   :2023/8/22 13:45
     */
    public function delete(ProductLogic $logic)
    {
        $this->request->validate([
            'ids'=>['required', new Ids()]
        ],[
            'ids.required' => 'ID不能为空'
        ]);
        $logic->productDelete();
        $this->response('success');
    }


    /**
     * @remark :根据状态获取数量
     * @name   :getStatusNumber
     * @author :lyh
     * @method :post
     * @time   :2023/8/21 18:33
     */
    public function getStatusNumber(ProductLogic $logic){
        $this->request->validate([
            'featured_status'=>'numeric',
        ],[
            'featured_status.numeric' => 'numeric为数字',
        ]);
        $data = $logic->getStatusNumber();
        $this->response('success',Code::SUCCESS,$data);
    }

    /**
     * @remark :复制产品
     * @name   :copyProduct
     * @author :lyh
     * @method :post
     * @time   :2023/7/29 14:59
     */
    public function copyProduct(ProductLogic $logic){
        $this->request->validate([
            'id'=>'required',
        ],[
            'id.required' => 'id不能为空',
        ]);
        $data = $logic->setCopyProduct();
        $this->response('success',Code::SUCCESS,$data);
    }

    /**
     * @remark :批量设置产品分类
     * @name   :batchSetCategory
     * @author :lyh
     * @method :post
     * @time   :2023/8/15 17:51
     */
    public function batchSetCategory(ProductLogic $logic){
        $this->request->validate([
            'id'=>'required',
            'category_id'=>'required',
        ],[
            'id.required' => '产品ID不能为空',
            'category_id.required' => '分类ID不能为空',
        ]);
        $logic->batchSetCategory();
        $this->response('success');
    }

    /**
     * @remark :修改排序
     * @name   :sort
     * @author :lyh
     * @method :post
     * @time   :2023/8/19 11:13
     */
    public function sort(ProductLogic $logic){
        $this->request->validate([
            'id'=>'required',
            'sort'=>'required'
        ],[
            'id.required' => '产品ID不能为空',
            'sort.required'=>'排序字段不能为空'
        ]);
        $logic->setSort();
        $this->response('success');
    }

    /**
     * @remark :批量更新排序
     * @name   :allSort
     * @author :lyh
     * @method :post
     * @time   :2024/1/10 15:34
     */
    public function allSort(ProductLogic $logic){
        $logic->setAllSort();
        $this->response('success');
    }

    /**
     * @remark :设置产品排序
     * @name   :setProductSort
     * @author :lyh
     * @method :post
     * @time   :2024/1/31 10:14
     */
    public function setProductSort(){
        $setNumModel = new SettingNum();
        try {
            if(isset($this->param['id']) && !empty($this->param['id'])){
                //执行编辑
                $param = [
                    'data'=>json_encode($this->param['data']),
                ];
                $setNumModel->edit($param,['id'=>$this->param['id']]);
            }else{
                //执行新增
                $param = [
                    'type'=>$setNumModel::TYPE_PRODUCT_SORT,
                    'project_id'=>$this->user['project_id'],
                    'data'=>json_encode($this->param['data']),
                ];
                $setNumModel->add($param);
            }
        }catch (\Exception $e){
            Log::info('error file: ' . __CLASS__ . __FUNCTION__ . $e->getMessage());
            $this->response('设置排序失败,请稍后重试',Code::SYSTEM_ERROR);
        }
        $this->response('success');
    }

    /**
     * @remark :获取产品排序
     * @name   :getProductSort
     * @author :lyh
     * @method :post
     * @time   :2024/1/31 10:24
     */
    public function getProductSort(){
        $setNumModel = new SettingNum();
        $info = $setNumModel->read(['type'=>$setNumModel::TYPE_PRODUCT_SORT]);
        if($info === false){
            $this->response('success');
        }
        $info['data'] = json_decode($info['data']);
        $this->response('success',Code::SUCCESS,$info);
    }

    /**
     * @remark :Ai发布
     * @name   :sendAiProduct
     * @author :lyh
     * @method :post
     * @time   :2024/1/26 15:33
     */
    public function sendAiProduct(Product $product){
        $this->request->validate([
            'keyword'=>'required',
            'product_id'=>'required'
        ],[
            'keyword.required' => 'keyword不能为空',
            'product_id.required' => 'product_id不能为空',
        ]);
        $productInfo = $product->read(['id' => $this->param['product_id']]);
        if ($productInfo == false) {
            $this->fail('请选择有效产品信息!');
        }
        $productInfo = $this->handleParam($productInfo);
        $keyword = generateRoute($this->param['keyword']);
        $pre_suf = file_get_contents("http://www.quanqiusou.cn/get_prefix_suffix_api.php");
        $pre_suf_array = json_decode($pre_suf,JSON_OBJECT_AS_ARRAY);
        $search_info = file_get_contents("http://title.globalso.com/ajax_data_for_web.php?keyword=".$keyword);
        if ($search_info) {
            $new_info = explode(" - ",trim($search_info));
            $new_title = str_replace('  ',' ',$pre_suf_array['prefix_title'][0].' '.$new_info[0]);
            $tm_ky = explode(',',$new_info[1]);
            $contents = $pre_suf_array['prefix'][0].' '.$new_title.', '.$pre_suf_array['suffix_s'][0]."\r\n";
            $contents .= $pre_suf_array['prefix_title'][0].' '.implode(', ',$tm_ky).', '.$pre_suf_array['suffix_l'][0]."\r\n";
            $new_content = htmlentities($contents);
        }
        if (!empty($new_content)){
            $detailModel = new Detail();
            $detailInfo = $detailModel->read(['column_id'=>1]);
            if($detailInfo !== false && !empty($detailInfo['content'])){
                $productInfo['content'] = $new_content . $detailInfo['content']['content'];
            }
        }
        $this->response('success',Code::SUCCESS,$productInfo);
    }

    /**
     * @remark :搜索分类参数
     * @name   :searchCategory
     * @author :lyh
     * @method :post
     * @time   :2024/7/9 14:48
     */
    public function getSearchCategoryList(ProductLogic $logic){
        $this->request->validate([
            'featured_status'=>'numeric',
        ],[
            'featured_status.numeric' => 'numeric为数字',
        ]);
        $data = $logic->getSearchCategoryList();
        $this->response('success',Code::SUCCESS,$data);
    }

    /**
     * @remark :清空所有的产品+关键词关联
     * @name   :delProductKeyword
     * @author :lyh
     * @method :post
     * @time   :2024/8/5 15:47
     */
    public function delProductKeyword(ProductLogic $logic){
        $this->request->validate([
            'id'=>'required',
        ],[
            'id.required' => 'id不为空',
        ]);
        $logic->delProductKeyword();
        $this->response('success');
    }

    /**
     * @remark :获取产品类型
     * @name   :getProductType
     * @author :lyh
     * @method :post
     * @time   :2024/8/21 17:18
     */
    public function getProductType(){
        $typeModel = new ProductType();
        $data = $typeModel->list(['project_id'=>['in',[0,$this->user['project_id']]]]);
        $this->response('success',Code::SUCCESS,$data);
    }

    /**
     * @remark :保存数据
     * @name   :saveType
     * @author :lyh
     * @method :post
     * @time   :2024/8/21 17:52
     */
    public function saveType(){
        $this->request->validate([
            'name'=>'required',
        ],[
            'name.required' => 'id不为空',
        ]);
        $typeModel = new ProductType();
        if(isset($this->param['id']) && !empty($this->param['id'])){
            $id = $this->param['id'];
            $typeModel->edit($this->param,['id'=>$this->param['id']]);
        }else{
            $this->param['project_id'] = $this->user['project_id'];
            $id = $typeModel->addReturnId($this->param);
        }
        $this->response('success',Code::SUCCESS,['id'=>$id]);
    }

    /**
     * @remark :删除
     * @name   :delProductType
     * @author :lyh
     * @method :post
     * @time   :2024/8/27 9:44
     */
    public function delProductType(){
        $this->request->validate([
            'name'=>'required',
        ],[
            'name.required' => 'id不为空',
        ]);
        $typeModel = new ProductType();
        $typeModel->del(['project_id'=>$this->user['project_id'],'name'=>$this->param['name']]);
        $this->response('success');
    }

    /**
     * @remark :获取按钮
     * @name   :getButton
     * @author :lyh
     * @method :post
     * @time   :2024/8/30 16:29
     */
    public function getButton(){
        $data = [
            '0'=>'草稿',
            '1'=>'发布',
            '2'=>'回收站',
            '3'=>'待发布'
        ];
        $this->response('success',Code::SUCCESS,$data);
    }

    /**
     * @remark :批量设置产品
     * @name   :batchSetKeyword
     * @author :lyh
     * @method :post
     * @time   :2024/9/20 16:46
     */
    public function batchSetKeyword(ProductLogic $logic){
        $this->request->validate([
            'id'=>'required|array',
            'keyword_id'=>'required|array',
        ],[
            'id.required' => '产品ID不能为空',
            'keyword_id.required' => '关键词ID不能为空',
        ]);
        $logic->batchSetKeyword();
        $this->response('success');
    }

    /**
     * @remark :获取所有分类
     * @name   :getCategoryList
     * @author :lyh
     * @method :post
     * @time   :2023/9/14 13:56
     */
    public function getCategoryList(){
        $data = Common::get_user_cache('product_category',$this->user['project_id']);
        if(empty($data)){
            $categoryModel = new Category();
            $data = [];
            $cateList = $categoryModel->list(['project_id'=>$this->user['project_id']],['id','title']);
            if(!empty($cateList)){
                foreach ($cateList as $value){
                    $data[$value['id']] = $value['title'];
                }
            }
            Common::set_user_cache($data,'product_category',$this->user['project_id']);
        }
        return $data;
    }
    /**
     * @remark :获取当前页的所有关键字名称
     * @name   :keywordNameLists
     * @author :lyh
     * @method :post
     * @time   :2024/6/3 14:24
     */
    public function keywordNameLists($lists){
        $keywordId = [];
        foreach ($lists as $v){
            $keywordId = array_merge($keywordId,$v['keyword_id']);
        }
        $keywordId = array_values(array_unique($keywordId));
        $keywordModel = new Keyword();
        $data = [];
        $cateList = $keywordModel->list(['id' => ['in',$keywordId]], ['id', 'title']);
        if (!empty($cateList)) {
            foreach ($cateList as $value) {
                $data[$value['id']] = $value['title'];
            }
        }
        return $data;
    }

    /**
     * @remark :获取时处理图片和文件
     * @name   :getHandleFileImage
     * @author :lyh
     * @method :post
     * @time   :2024/1/23 17:43
     */
    public function getHandleFileImage($v){
        //ToDo::处理图片及文件
        if(!empty($v['thumb']) && !empty($v['thumb']['url'])){
            $v['thumb']['url'] = getImageUrl($v['thumb']['url'],$this->user['storage_type'] ?? 0,$this->user['project_location']);
        }
        if(!empty($v['gallery'])){
            foreach ($v['gallery'] as $gallery_k => $gallery_v){
                $gallery_v['url'] = getImageUrl($gallery_v['url'],$this->user['storage_type'] ?? 0,$this->user['project_location']);
                $v['gallery'][$gallery_k] = $gallery_v;
            }
        }
        if(!empty($v['og_image'])){
            $v['og_image'] = getImageUrl($v['og_image'] ?? '',$this->user['storage_type'],$this->user['project_location']);
        }else{
            $v['og_image'] = $v['thumb']['url'] ?? '';
        }
        if(!empty($v['icon'])){
            foreach ($v['icon'] as $icon_k => $icon_v){
                $icon_v = getImageUrl($icon_v,$this->user['storage_type'] ?? 0,$this->user['project_location']);
                $v['icon'][$icon_k] = $icon_v;
            }
        }
        if(!empty($v['video'])){
            $v['video']['url'] = getFileUrl($v['video']['url'],$this->user['storage_type'] ?? 0,$this->user['project_location'],$this->user['file_cdn'] ?? 0);
            $v['video']['video_image'] = getImageUrl($v['video']['video_image'] ?? '',$this->user['storage_type'] ?? 0,$this->user['project_location']);
        }
        if(!empty($v['files']) && !empty($v['files']['url'])){
            $v['files']['url'] = getFileUrl($v['files']['url'],$this->user['storage_type'] ?? 0,$this->user['project_location'],$this->user['file_cdn'] ?? 0);
        }
        return $this->success($v);
    }

    /**
     * @remark :处理详情数据(初始化)
     * @name   :handleList
     * @author :lyh
     * @method :post
     * @time   :2024/8/14 18:26
     */
    public function handleExtentList($list){
        foreach ($list  as $k => $v){
            if($v['type'] == 3 || $v['type'] == 4){
                if(!isset($v['values'])){
                    $v['values'] = [];
                }
            }else{
                if(!isset($v['values'])){
                    $v['values'] = '';
                }
            }
            $list[$k] = $v;
        }
        return $this->success($list);
    }

    /**
     * @remark :扩展字段根据type返回类型
     * @name   :setTypValues
     * @author :lyh
     * @method :post
     * @time   :2023/12/6 14:43
     */
    public function setTypValues($v,$info){
        if($v['type'] == 3){
            $arr = json_decode($info['values']);
            foreach ($arr as $k1=>$v1){
                $v1 = (array)$v1;
                $v1['url'] = getImageUrl($v1['url'],$this->user['storage_type'],$this->user['project_location']);
                $arr[$k1] = $v1;
            }
            $v['values'] = $arr;
        }elseif($v['type'] == 4){
            $arr1 = json_decode($info['values']);
            foreach ($arr1 as $k1=>$v1){
                $v1 = (array)$v1;
                if(isset($v1['url'])){
                    $v1['url'] = getFileUrl($v1['url'],$this->user['storage_type'],$this->user['project_location'],$this->user['file_cdn'] ?? 0);
                }else{
                    $v1 = getFileUrl($v1,$this->user['storage_type'],$this->user['project_location'],$this->user['file_cdn'] ?? 0);
                }
                $arr1[$k1] = $v1;
            }
            $v['values'] = $arr1;
        }else{
            $v['values'] = $info['values'];
        }
        return $this->success($v);
    }

    /**
     * @remark :搜索参数处理
     * @name   :handleReturnParam
     * @author :lyh
     * @method :post
     * @time   :2023/9/14 10:01
     */
    public function searchParam(&$query){
        $query = $query->where('project_id',$this->user['project_id']);
        if (isset($this->map['category_id']) && !empty($this->map['category_id'])) {
            $str[] = $this->map['category_id'];
            $this->getAllSub($this->map['category_id'],$str);
            $categoryRelatedModel = new CategoryRelated();
            $product_id_arr = $categoryRelatedModel->whereIn('cate_id',$str)->pluck('product_id')->toArray();
            $query = $query->whereIn('id',$product_id_arr);
        }
        if(isset($this->map['title']) && !empty($this->map['title'])){
            $this->map['title'] = str_replace('+',' ',$this->map['title']);
            $query = $query->where('title','like','%'.$this->map['title'].'%');
        }
        if(isset($this->map['keyword_title']) && !empty($this->map['keyword_title'])){
            $keywordModel = new Keyword();
            $keywordInfo = $keywordModel->read(['title'=>$this->map['keyword_title']],['id']);
            if(!empty($keywordInfo)){
                $query = $query->where('keyword_id','like','%,'.$keywordInfo['id'].',%');
            }
        }
        if(isset($this->map['status'])){
            if($this->map['status'] == 0){
                $query = $query->whereIn('status',[0,3]);
            }else{
                $query = $query->where('status',$this->map['status']);
            }
        }
        if(isset($this->map['created_uid'])){
            $query = $query->where('created_uid',$this->map['created_uid']);
        }
        if(isset($this->map['six_read'])){
            $query = $query->where('six_read',$this->map['six_read']);
        }
        if(!empty($this->param['start_at']) && !empty($this->param['end_at'])){
            if($this->user['project_id'] == 2059){
                $query->where('send_time', '>=' ,$this->param['start_at'].' 00:00:00')->where('send_time', '<=' ,$this->param['end_at'].' 59:59:59');
            }else{
                $query->where('created_at', '>=' ,$this->param['start_at'].' 00:00:00')->where('created_at', '<=' ,$this->param['end_at'].' 59:59:59');
            }
        }
        $this->param['featured_status']  = $this->param['featured_status'] ?? 0;
        if($this->param['featured_status'] != Category::STATUS_ACTIVE) {
            $cateModel = new Category();
            $featured_ids = $cateModel->formatQuery(['title'=>['in',['Featured','featured']]])->pluck('id')->toArray();
            if(!empty($featured_ids)){
                $status = [];
                if(isset($this->map['status'])){
                    $status = ['status'=>$this->map['status']];
                }
                $cateList = $cateModel->list($status,'id',['id','pid']);
                //获取当前的子集
                $featured_arr = [];
                foreach ($featured_ids as $id){
                    $featured_arr = array_merge($featured_arr,array_unique(_get_all_sub($id,$cateList)));
                }
                if(!empty($featured_arr)){
                    $cateRelated = new CategoryRelated();
                    $product_ids = $cateRelated->whereIn('cate_id',$featured_arr)->pluck('product_id')->unique()->toArray();
                    $query = $query->whereNotIn('id',$product_ids);
                }
            }
        }
        return $query;
    }


    /**
     * @remark :处理列表参数
     * @name   :handleParam
     * @author :lyh
     * @method :post
     * @time   :2023/8/17 9:15
     */
    public function handleParam($v){
        $v['keyword_id_text'] = '';
        if(!empty($v['keyword_id'])){
            $keywordModel = new Keyword();
            $keyword_data = $keywordModel->list(['id'=>['in',$v['keyword_id']]]);
            foreach ($keyword_data as $v1){
                $v['keyword_id_text'] .= $v1['title'].',';
            }
            $v['keyword_id_text'] = trim($v['keyword_id_text'],',');
        }
        if(!empty($v['status'])){
            $v['status_text'] = Product::statusMap()[$v['status']] ?? '';
        }else{
            $v['status_text'] = '';
        }
        //ToDo::处理图片及文件
        $v = $this->getHandleFileImage($v);
        $template_id = $this->getTemplateId(BTemplate::SOURCE_PRODUCT,BTemplate::IS_DETAIL);
        $v['is_renovation']  =  $this->getIsRenovation(BTemplate::SOURCE_PRODUCT,BTemplate::IS_DETAIL,$template_id,$v['id'] ?? 0);
        $v['url'] = $this->user['domain'].($v['route'] ?? '');
        //获取当前数据扩展字段及值
        $v['extend'] = $this->getExtendInfo($v['id']);
        return $v;
    }


    /**
     * @remark :获取扩展字段详情
     * @name   :getExtendInfo
     * @author :lyh
     * @method :post
     * @time   :2023/11/14 9:45
     */
    public function getExtendInfo($product_id){
        $extendModel = new Extend();
        $list = $extendModel->list([],'id',['id','type','key','title']);
        if(empty($list)){
            return [];
        }
        $extendInfoModel = new ExtendInfo();
        $infoList = $extendInfoModel->list(['product_id'=>$product_id],'created_at');
        foreach ($list as $k=>$v){
            foreach ($infoList as $values){
                if($v['key'] == $values['key']){
                    $v = $this->setTypValues($v,$values);
                    break;
                }
            }
            $list[$k] = $v;
        }
        $list = $this->handleExtentList($list);
        return $list;
    }

    /**
     * @remark :获取当前id下所有子集
     * @name   :getAllSub
     * @author :lyh
     * @method :post
     * @time   :2023/10/18 15:10
     */
    public function getAllSub($id,&$str = []){
        $cateModel = new Category();
        $list = $cateModel->list(['pid'=>$id,'status'=>1],['id','pid']);
        if(!empty($list)){
            foreach ($list as $v){
                $str[] = $v['id'];
                $this->getAllSub($v['id'],$str);
            }
        }
        return $str;
    }



    /**
     * @remark :获取分类名称
     * @name   :categoryName
     * @author :lyh
     * @method :post
     * @time   :2023/9/14 13:58
     */
    public function categoryName($product_id,$data){
        $cateRelatedModel = new CategoryRelated();
        $category_id = $cateRelatedModel->where('product_id',$product_id)->pluck('cate_id')->toArray();
        $category_name = '';
        if(!empty($category_id) && !empty($data)){
            foreach ($category_id as $v){
                if(isset($data[$v])){
                    $category_name .= $data[$v].',';
                }
            }
            $category_name = trim($category_name,',');
        }
        return $category_name;
    }

    /**
     * @remark :获取关键词名称
     * @name   :categoryName
     * @author :lyh
     * @method :post
     * @time   :2023/9/14 13:58
     */
    public function keywordName($keyword_id,$data){
        $keyword_name = '';
        if(!empty($keyword_id) && !empty($data)){
            foreach ($keyword_id as $v){
                if(isset($data[$v])){
                    $keyword_name .= $data[$v].',';
                }
            }
            $keyword_name = trim($keyword_name,',');
        }
        return $keyword_name;
    }

}