DetailController.php 2.3 KB
<?php
/**
 * @remark :
 * @name   :DetailController.php
 * @author :lyh
 * @method :post
 * @time   :2024/11/12 14:55
 */

namespace App\Http\Controllers\Bside\Product;

use App\Enums\Common\Code;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\Product\DetailLogic;
use App\Models\Product\Column;
use App\Models\Product\Detail;
use Illuminate\Support\Facades\DB;

class DetailController extends BaseController
{
    /**
     * @remark :获取当前产品的描述详情
     * @name   :getDetail
     * @author :lyh
     * @method :post
     * @time   :2024/11/13 9:53
     */
    public function getDetail(Detail $detail,Column $column){
        $data_column = $column->list(['product_id'=>['in',[0,$this->map['product_id']]]],'id',['*'],'asc');
        $data = $detail->list($this->map,'sort',['*'],'asc');
        if(!empty($data_column) && !empty($data)){
            foreach ($data_column as $k => $v){
                $column_data = [];
                foreach ($data as $v1){
                    if($v['id'] == $v1['column_id']){
                        $column_data[] = $v1;
                    }
                }
                $v['data'] = $column_data;
                $data_column[$k] = $v;
            }
        }
        $this->response('success',Code::SUCCESS,$data_column);
    }

    /**
     * @remark :获取产品描述页所有详情
     * @name   :getType
     * @author :lyh
     * @method :post
     * @time   :2024/11/12 14:57
     */
    public function getType(Detail $detail){
        $data = [
            'text_type' => $detail->text_type(),
            'line_two_type' => $detail->line_two_type(),
            'image_two_type' => $detail->image_two_type(),
            'three_type' => $detail->three_type(),
            'image_three_type' => $detail->image_three_type(),
        ];
        $this->response('success',Code::SUCCESS,$data);
    }

    /**
     * @remark :获取产品描述栏目
     * @name   :getColumn
     * @author :lyh
     * @method :post
     * @time   :2024/11/12 15:07
     */
    public function getColumn(Column $column){
        $this->map['product_id'] = ['in',[0,$this->map['product_id'] ?? 0]];
        $data = $column->list($this->map,'id',['*'],'asc');
        $this->response('success',Code::SUCCESS,$data);
    }
}