WebSettingTextLogic.php 2.6 KB
<?php

namespace App\Http\Logic\Bside\Setting;

use App\Http\Logic\Bside\BaseLogic;
use App\Models\WebSetting\WebSetting;
use App\Models\WebSetting\WebSettingText;
use Illuminate\Support\Facades\DB;

class WebSettingTextLogic extends BaseLogic
{
    public function __construct()
    {
        parent::__construct();

        $this->model = new WebSettingText();
        $this->param = $this->requestAll;
    }

    /**
     * @name   :(查询设置详情)setting_read
     * @author :lyh
     * @method :post
     * @time   :2023/5/8 15:56
     */
    public function setting_read(){
        $web_setting = new WebSetting();
        $setting_info = $web_setting->read(['project_id'=>$this->user['project_id']],['anchor_setting','anchor_is_enable','anchor_num']);
        return $setting_info;
    }

    /**
     * @name   :(描文本详情)setting_text_lists
     * @author :lyh
     * @method :post
     * @time   :2023/5/8 14:18
     */
    public function setting_text_lists(){
        $lists['data'] = $this->model->list(['project_id'=>$this->user['project_id']],'created_at',['key_words','url']);
        $lists['anchor_info'] =  $this->setting_read();
        $anchor_text = $this->model->anchor_text;
        $lists['anchor_text'] = $anchor_text;
        return $this->success($lists);
    }

    /**
     * @name   :(设置描文本)setting_text_save
     * @author :lyh
     * @method :post
     * @time   :2023/5/8 14:39
     */
    public function setting_text_save(){
        $web_setting = new WebSetting();
        $setting_info = $this->setting_read();
        if(count($this->param['data']) > $setting_info['anchor_num']){
            $this->fail('超过最大设置限制');
        }
        DB::beginTransaction();
        try {
            //更新描文本设置
            $data = [
                'anchor_setting'=>$this->param['anchor_setting'],
                'anchor_is_enable'=>$this->param['anchor_is_enable'],
                'anchor_num'=>$this->param['anchor_num']
            ];
            $web_setting->edit($data,['project_id'=>$this->user['project_id']]);
            $this->model->del(['project_id'=>$this->user['project_id']]);
            foreach ($this->param['data'] as $k => $v){
                $v['created_at'] = date('Y-m-d H:i:s');
                $v['updated_at'] = date('Y-m-d H:i:s');
                $v['project_id'] = $this->user['project_id'];
                $this->param['data'][$k] = $v;
            }
            $this->model->insert($this->param['data']);
            DB::commit();
        }catch (\Exception $e){
            DB::rollBack();
            $this->fail('更新失败');
        }
        $this->success();
    }
}