BTemplateModuleRandomLogic.php 1.7 KB
<?php
/**
 * @remark :
 * @name   :BTemplateModuleRandomLogic.php
 * @author :lyh
 * @method :post
 * @time   :2025/5/27 15:36
 */

namespace App\Http\Logic\Bside\BTemplate;

use App\Http\Logic\Bside\BaseLogic;
use App\Models\Template\TemplateModuleRandom;

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

    /**
     * @remark :保存为随机模块
     * @name   :saveRandomModule
     * @author :lyh
     * @method :post
     * @time   :2025/5/27 15:38
     */
    public function saveRandomModule(){
        //查询当前uuid是否已存在
        $info = $this->model->read(['project_id'=>$this->user['project_id'],'uuid'=>$this->param['uuid'],'module_id'=>$this->param['module_id']]);
        try {
            if($info === false){
                //执行新增数据
                $this->model->add($this->param);
            }else{
                //执行编辑
                $this->model->edit(['html'=>$this->param['html']],['id'=>$this->param['id']]);
            }
        }catch (\Exception $e){
            $this->fail('保存失败,请联系管理员');
        }
        return $this->success();
    }

    /**
     * @remark :获取当前模块是否为随机模块
     * @name   :getIsRandomModule
     * @author :lyh
     * @method :post
     * @time   :2025/5/27 15:47
     */
    public function getRandomInfo(){
        $info = $this->model->read(['project_id'=>$this->user['project_id'],'uuid'=>$this->param['uuid'],'module_id'=>$this->param['module_id']]);
        if($info === false){
            $info = [];
        }
        return $this->success($info);
    }
}