ReplaceHtmlController.php 2.8 KB
<?php
/**
 * @remark :
 * @name   :ReplaceHtmlController.php
 * @author :lyh
 * @method :post
 * @time   :2024/5/8 10:02
 */

namespace App\Http\Controllers\Aside\Template;

use App\Enums\Common\Code;
use App\Http\Controllers\Aside\BaseController;
use App\Http\Logic\Aside\Template\ReplaceHtmlLogic;
use App\Models\Template\TemplateReplaceHtml;
use App\Models\Template\TemplateReplaceHtmlLog;
use App\Services\ProjectServer;
use Illuminate\Support\Facades\DB;

class ReplaceHtmlController extends BaseController
{
    /**
     * @remark :替换同一种类型的html代码
     * @name   :replaceTemplateMainHtml
     * @author :lyh
     * @method :post
     * @time   :2024/5/7 14:39
     */
    public function replaceTemplateMainHtml(ReplaceHtmlLogic $logic){
        $this->request->validate([
            'old_html'=>'required',
            'html'=>'required',
            'type'=>'required',
            'is_list'=>'required',
            'is_custom'=>'required',
            'project_id'=>'required',
        ],[
            'old_html.required' => '需替换的html不能为空',
            'html.required' => 'html不能为空',
            'type.required' => '类型type不能为空',
            'is_custom.required' => '类型is_custom不能为空',
            'is_list.required' => '类型is_list不能为空',
            'project_id.required' => 'project_id不能为空',
        ]);
        $logic->replaceHtml();
        $this->response('success');
    }

    /**
     * @remark :替换的记录
     * @name   :replaceTemplateLog
     * @author :lyh
     * @method :post
     * @time   :2024/5/8 10:28
     */
    public function replaceTemplateLog(TemplateReplaceHtml $replaceModel){
        $this->request->validate([
            'project_id'=>'required',
        ],[
            'project_id.required' => 'project_id不能为空',
        ]);
        ProjectServer::useProject($this->param['project_id']);
        $lists = $replaceModel->lists($this->map,$this->page,$this->row,$this->order);
        if(!empty($lists) && !empty($lists['list'])){
            $templateLogModel = new TemplateReplaceHtmlLog();
            foreach ($lists['list'] as $k => $v){
                $v['sub'] = $templateLogModel->list(['replace_id'=>$v['id']]);
                $lists['list'][$k] = $v;
            }
        }
        DB::disconnect('custom_mysql');
        $this->response('success',Code::SUCCESS,$lists);
    }

    /**
     * @remark :还原
     * @name   :reductionHtml
     * @author :lyh
     * @method :post
     * @time   :2024/5/8 10:27
     */
    public function reductionHtml(ReplaceHtmlLogic $logic){
        $this->request->validate([
            'id'=>'required',
        ],[
            'id.required' => 'id不能为空',
        ]);
        $logic->reductionHtml();
        $this->response('success');
    }
}