BTemplateModuleProjectLogic.php 2.5 KB
<?php
/**
 * @remark :
 * @name   :BTemplateModuleProjectLogic.php
 * @author :lyh
 * @method :post
 * @time   :2023/11/14 14:41
 */

namespace App\Http\Logic\Bside\BTemplate;

use App\Http\Logic\Bside\BaseLogic;
use App\Models\Template\TemplateLabel;
use App\Models\Template\TemplateModule;

class BTemplateModuleProjectLogic extends BaseLogic
{
    public function __construct()
    {
        parent::__construct();
        $this->model = new TemplateModule();
        $this->param = $this->requestAll;
    }

    /**
     * @remark :获取左侧模块列表
     * @name   :ModuleList
     * @author :lyh
     * @method :post
     * @time   :2023/6/29 13:35
     */
    public function ModuleList($map,$order = 'created_at',$filed = ['id','name','status','image','html','project_id']){
        $map['deleted_status'] = 0;
        $list = $this->model::whereRaw("FIND_IN_SET(?, project_id)", [$this->user['project_id']])->orderBy($order,'desc')->select($filed)->get()->toArray();
        $templateLabel = new TemplateLabel();
        $label = [];
        foreach ($list as  $v){
            $label[] = $v['id'];
        }
        $label_arr = $templateLabel->list(['template_id'=>['in',$label],'type'=>2],'id',['id','template_id','name'],'desc');
        foreach ($list as $k1 => $v1){
            foreach ($label_arr as $v2){
                if($v2['template_id'] == $v1['id']){
                    $v1['label'][] = $v2;
                }
            }
            $list[$k1] = $v1;
        }
        return $this->success($list);
    }

    /**
     * @remark :保存私有化左侧模块
     * @name   :moduleProjectSave
     * @author :lyh
     * @method :post
     * @time   :2023/11/14 14:46
     */
    public function moduleProjectSave(){
        try {
            $this->param['operator_id'] = $this->user['id'];
            $this->param['project_id'] = isset($this->param['project_id']) ? $this->param['project_id'] : $this->user['project_id'];
            $this->model->add($this->param);
        }catch (\Exception $e){
            $this->fail('系统错误,请联系管理员');
        }
        return $this->success();
    }

    /**
     * @remark :
     * @name   :delModule
     * @author :lyh
     * @method :post
     * @time   :2023/11/28 17:42
     */
    public function delModule(){
        try {
            $this->model->del($this->param);
        }catch (\Exception $e){
            $this->fail('系统错误,请联系管理员');
        }
        return $this->success();
    }
}