作者 刘锟

amp设置

<?php
namespace App\Http\Controllers\Bside\Setting;
use App\Enums\Common\Code;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\Setting\WebSettingAmpLogic;
class WebSettingAmpController extends BaseController
{
/**
* 获取amp设置详情
* @param WebSettingAmpLogic $logic
* @author Akun
* @date 2024/01/25 15:52
*/
public function info(WebSettingAmpLogic $logic)
{
$info = $logic->ampInfo();
$this->response('success', Code::SUCCESS, $info);
}
/**
* 保存amp 设置
* @param WebSettingAmpLogic $logic
* @author Akun
* @date 2024/01/25 15:53
*/
public function save(WebSettingAmpLogic $logic)
{
$logic->ampSave();
$this->response('success');
}
}
... ...
<?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();
}
//banner处理
if (!empty($info['index_banner'])) {
foreach ($info['index_banner'] as &$v) {
$v = getImageUrl($v, $this->user['project_location'] ?? 0, $this->user['storage_type'] ?? 0);
}
}
return $this->success($info);
}
/**
* 保存数据
* @return array
* @author Akun
* @date 2024/01/25 15:33
*/
public function ampSave()
{
try {
//banner处理
foreach ($this->param['index_banner'] ?? [] as &$v) {
$v = str_replace_url($v);
}
$this->param['index_banner'] = Arr::a2s($this->param['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();
}
}
... ...
<?php
namespace App\Models\WebSetting;
use App\Helper\Arr;
use App\Models\Base;
class WebSettingAmp extends Base
{
protected $table = 'gl_web_setting_amp';
//连接数据库
protected $connection = 'custom_mysql';
public function getIndexBannerAttribute($value){
if(!empty($value)){
$value = Arr::s2a($value);
}
return $value;
}
}
... ...
... ... @@ -206,6 +206,12 @@ Route::middleware(['bloginauth'])->group(function () {
Route::any('/info', [\App\Http\Controllers\Bside\Setting\SettingNumController::class, 'info'])->name('num_info');
Route::any('/save',[\App\Http\Controllers\Bside\Setting\SettingNumController::class, 'save'])->name('num_save');
});
//amp设置
Route::prefix('amp')->group(function () {
Route::any('/info', [\App\Http\Controllers\Bside\Setting\WebSettingAmpController::class, 'info'])->name('amp_info');
Route::any('/save',[\App\Http\Controllers\Bside\Setting\WebSettingAmpController::class, 'save'])->name('amp_save');
});
});
//产品
Route::prefix('product')->group(function () {
... ...