102 lines
2.3 KiB
PHP
102 lines
2.3 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @author Any
|
|
* @description KISS
|
|
* @date 2021-4-19
|
|
* @version 1.0.0
|
|
*
|
|
* _____LOG_____
|
|
*
|
|
*/
|
|
namespace app\models;
|
|
|
|
|
|
use app\models\Option;
|
|
use app\models\Model;
|
|
|
|
|
|
class PageForm extends Model
|
|
{
|
|
public $content;
|
|
public $key;
|
|
public $video_open;
|
|
|
|
public $cx_mch_id;
|
|
|
|
public function rules()
|
|
{
|
|
return [
|
|
[['content', 'key'], 'trim'],
|
|
[['content', 'key','video_open'], 'string'],
|
|
[['cx_mch_id'], 'integer'],
|
|
[['key', 'cx_mch_id'], 'required',],
|
|
[['content'], 'required', 'on' => 'edit'],
|
|
];
|
|
}
|
|
|
|
public function beforeSave($insert) {
|
|
if(parent::beforeSave($insert)){
|
|
if($this->isNewRecord){
|
|
}
|
|
$this->_htmlTagFilter();
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public function _htmlTagFilter()
|
|
{
|
|
$this->content = Model::htmlTagFilter($this->content);
|
|
}
|
|
|
|
|
|
public function save()
|
|
{
|
|
if(!$this->validate()){
|
|
return $this->getModelError();
|
|
}
|
|
$this->content = base64_encode($this->content);
|
|
$r = Option::setOption($this->key, $this->content, $this->cx_mch_id);
|
|
if (!$r){
|
|
return [
|
|
'code' => 1,
|
|
'msg' => '保存失败'
|
|
];
|
|
}
|
|
if(!empty($this->video_open)){
|
|
// 视频开关
|
|
$redis_name = "cxaibc:api:actionHandleVideo_v1";
|
|
if($this->video_open == 'on'){
|
|
\Yii::$app->redis->set($redis_name,1);
|
|
}else{
|
|
\Yii::$app->redis->set($redis_name,0);
|
|
}
|
|
}
|
|
return [
|
|
'code' => 0,
|
|
'msg' => '保存成功'
|
|
];
|
|
}
|
|
|
|
public function search()
|
|
{
|
|
$content = Option::getOption($this->key, $this->cx_mch_id);
|
|
if($this->is_base64_encode($content))
|
|
$content = base64_decode($content);
|
|
return [
|
|
'content' => $content,
|
|
];
|
|
}
|
|
|
|
private function is_base64_encode($content)
|
|
{
|
|
try{
|
|
if($content == base64_encode(base64_decode($content)))
|
|
return true;
|
|
} catch (\Exception $ex){
|
|
}
|
|
return false;
|
|
}
|
|
} |