WebSettingAmpLogic.php 5.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'] = Arr::s2a($info['top_logo']);
        if (!empty($info['top_logo'])) {
            $info['top_logo']['url'] = getImageUrl($info['top_logo']['url'], $this->user['storage_type'], $this->user['project_location']);
        }
        //banner处理
        $info['index_banner'] = Arr::s2a($info['index_banner']);
        if (!empty($info['index_banner'])) {
            foreach ($info['index_banner'] as &$v) {
                $v['url'] = getImageUrl($v['url'], $this->user['storage_type'], $this->user['project_location']);
            }
        }
        //首页video处理
        $info['index_video'] = Arr::s2a($info['index_video']);
        if (!empty($info['index_video'])) {
            $info['index_video']['url'] = getImageUrl($info['index_video']['url'], $this->user['storage_type'], $this->user['project_location']);
        }
        //公司主图处理
        $info['company_image'] = Arr::s2a($info['company_image']);
        if (!empty($info['company_image'])) {
            $info['company_image']['url'] = getImageUrl($info['company_image']['url'], $this->user['storage_type'], $this->user['project_location']);
        }
        //contact主图处理
        $info['contact_image'] = Arr::s2a($info['contact_image']);
        if (!empty($info['contact_image'])) {
            $info['contact_image']['url'] = getImageUrl($info['contact_image']['url'], $this->user['storage_type'], $this->user['project_location']);
        }
        //icon处理
        $info['web_icon'] = getImageUrl($info['web_icon']);
        return $this->success($info);
    }

    /**
     * 保存数据
     * @return array
     * @author Akun
     * @date 2024/01/25 15:33
     */
    public function ampSave()
    {
        try {
            //log图处理
            if (isset($this->param['top_logo']) && $this->param['top_logo']) {
                $this->param['top_logo']['url'] = str_replace_url($this->param['top_logo']['url'] ?? '');
            }
            $this->param['top_logo'] = Arr::a2s($this->param['top_logo'] ?? []);
            //banner处理
            $index_banner = [];
            if (isset($this->param['index_banner']) && $this->param['index_banner']) {
                foreach ($this->param['index_banner'] as $v) {
                    $v['url'] = str_replace_url($v['url'] ?? '');
                    $index_banner[] = $v;
                }
            }
            $this->param['index_banner'] = Arr::a2s($index_banner);
            //首页video处理
            if (isset($this->param['index_video']) && $this->param['index_video']) {
                $this->param['index_video']['url'] = str_replace_url($this->param['index_video']['url'] ?? '');
            }
            $this->param['index_video'] = Arr::a2s($this->param['index_video'] ?? []);
            //公司主图处理
            if (isset($this->param['company_image']) && $this->param['company_image']) {
                $this->param['company_image']['url'] = str_replace_url($this->param['company_image']['url'] ?? '');
            }
            $this->param['company_image'] = Arr::a2s($this->param['company_image'] ?? []);
            //contact主图处理
            if (isset($this->param['contact_image']) && $this->param['contact_image']) {
                $this->param['contact_image']['url'] = str_replace_url($this->param['contact_image']['url'] ?? '');
            }
            $this->param['contact_image'] = Arr::a2s($this->param['contact_image'] ?? []);
            //icon处理
            $this->param['web_icon'] = str_replace_url($this->param['web_icon'] ?? '');
            //其余参数默认值
            $this->param['top_backgroundcolor'] =  $this->param['top_backgroundcolor'] ?? '';
            $this->param['company_email'] =  $this->param['company_email'] ?? '';
            $this->param['company_address'] =  $this->param['company_address'] ?? '';
            $this->param['company_tel'] =  $this->param['company_tel'] ?? '';
            $this->param['company_skype'] =  $this->param['company_skype'] ?? '';
            $this->param['company_whatsapp'] =  $this->param['company_whatsapp'] ?? '';

            $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();
    }
}