WebSettingAmpLogic.php 2.2 KB
<?php

namespace App\Http\Logic\Bside\Setting;

use App\Helper\Arr;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\WebSetting\WebSettingAmp;

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

    /**
     * 获取详情
     * @return array
     * @author Akun
     * @date 2024/01/25 15:32
     */
    public function ampInfo()
    {
        $info = $this->model->read(['project_id' => $this->user['project_id']]);
        if ($info === false) {
            return $this->success();
        }
        //log图处理
        $info['top_logo'] = getImageUrl($info['top_logo'],$this->user['storage_type'],$this->user['project_location']);
        //banner处理
        if (!empty($info['index_banner'])) {
            foreach ($info['index_banner'] as &$v) {
                $v = getImageUrl($v,$this->user['storage_type'],$this->user['project_location']);
            }
        }
        return $this->success($info);
    }

    /**
     * 保存数据
     * @return array
     * @author Akun
     * @date 2024/01/25 15:33
     */
    public function ampSave()
    {
        try {
            //log图处理
            $this->param['top_logo'] = str_replace_url($this->param['top_logo'] ?? '');
            //banner处理
            $index_banner = [];
            if (isset($this->param['index_banner']) && $this->param['index_banner']) {
                foreach ($this->param['index_banner'] as $v) {
                    $index_banner[] = str_replace_url($v);
                }
            }
            $this->param['index_banner'] = Arr::a2s($index_banner);

            $info = $this->model->read(['project_id' => $this->user['project_id']]);
            if ($info === false) {
                $this->param['project_id'] = $this->user['project_id'];
                $this->model->add($this->param);
            } else {
                $this->model->edit($this->param, ['project_id' => $this->user['project_id']]);
            }
        } catch (\Exception $e) {
            $this->fail('error');
        }
        return $this->success();
    }
}