ExtendController.php 2.2 KB
<?php
/**
 * @remark :
 * @name   :ExtendController.php
 * @author :lyh
 * @method :post
 * @time   :2023/11/9 14:22
 */

namespace App\Http\Controllers\Bside\Product;

use App\Enums\Common\Code;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\Product\ExtendLogic;
use App\Models\Product\Extend;

/**
 * @remark :添加扩展字段
 * @name   :ExtendController
 * @author :lyh
 * @method :post
 * @time   :2023/11/9 14:22
 */
class ExtendController extends BaseController
{
    /**
     * @remark :获取所有扩展字段
     * @name   :lists
     * @author :lyh
     * @method :post
     * @time   :2023/11/9 14:23
     */
    public function lists(Extend $extend){
        $lists = $extend->list($this->map);
        $this->response('success',Code::SUCCESS,$lists);
    }

    /**
     * @remark :保存数据
     * @name   :save
     * @author :lyh
     * @method :post
     * @time   :2023/11/9 14:26
     */
    public function save(ExtendLogic $extendLogic){
        $this->request->validate([
            'title'=>'required',
            'type'=>'required',
        ],[
            'title.required' => '字段名称不能为空',
            'type.required' => '字段类型不能为空',
        ]);
        $info = $extendLogic->extendSave();
        $this->response('success',Code::SUCCESS,$info);
    }

    /**
     * @remark :删除扩展字段
     * @name   :del
     * @author :lyh
     * @method :post
     * @time   :2023/11/9 16:00
     */
    public function del(ExtendLogic $extendLogic){
        $this->request->validate([
            'id'=>'required',
        ],[
            'id.required' => '主键不能为空',
        ]);
        $extendLogic->extendDel();
        $this->response('success');
    }


    /**
     * 可搜索的字段列表
     * @author zbj
     * @date 2024/1/22
     */
    public function search_filed(){
        $map = [
            'title' => '产品标题',
            'intro' => '短描述',
        ];
        //文本框类型扩展字段
        $extends = Extend::where('type', 1)->pluck('title', 'key')->toArray();
        $data = array_merge($map, $extends);
        $this->response('success',Code::SUCCESS,$data);
    }
}