92 lines
2.5 KiB
PHP
92 lines
2.5 KiB
PHP
<?php
|
||
|
||
/**
|
||
* @author Any
|
||
* @description KISS
|
||
* @date 2021年7月2日
|
||
* @version 1.0.0
|
||
*
|
||
* _____LOG_____
|
||
*
|
||
*/
|
||
namespace app\models\common\cms;
|
||
|
||
use app\models\cms\Notice;
|
||
use app\models\cms\RichText;
|
||
use app\models\Model;
|
||
use yii\data\Pagination;
|
||
use app\components\SiteHelper;
|
||
|
||
|
||
class CommonNoticeEditForm extends Model
|
||
{
|
||
public $cx_mch_id;
|
||
public $title;
|
||
public $content;
|
||
public $status;
|
||
public $sort;
|
||
public $is_top;
|
||
public $is_index;
|
||
|
||
public $model;
|
||
|
||
|
||
|
||
public function rules()
|
||
{
|
||
return [
|
||
[['title', 'content',], 'trim'],
|
||
[['title', 'content',], 'string'],
|
||
[['cx_mch_id', 'status', 'sort', 'is_top', 'is_index'], 'integer'],
|
||
[['is_top', 'is_index'], 'in', 'range' => [0, 1]],
|
||
[['status'], 'in', 'range' => [0, 1, 2]],
|
||
[['model',], 'safe'],
|
||
[['sort'], 'default', 'value' => 100],
|
||
[['title', 'content', 'cx_mch_id', 'status', 'is_top', 'model', 'is_index'], 'required'],
|
||
];
|
||
}
|
||
|
||
public function attributeLabels()
|
||
{
|
||
return [
|
||
'cx_mch_id' => '平台商户ID',
|
||
'title' => '标题',
|
||
'content' => '内容',
|
||
'status' => '状态:0=草稿,1=已发布,2=回收站',
|
||
'sort' => '排序:默认100,升序',
|
||
'is_top' => '是否置顶:0=否,1=是',
|
||
];
|
||
}
|
||
|
||
public function save()
|
||
{
|
||
if(!$this->validate()){
|
||
return $this->getModelError();
|
||
}
|
||
$t = \Yii::$app->db->beginTransaction();
|
||
if($this->model->isNewRecord){
|
||
$this->model->cx_mch_id = $this->cx_mch_id;
|
||
$this->model->is_delete = 0;
|
||
$this->model->rich_text_id = 0;
|
||
}
|
||
$res = RichText::saveRichText($this->model->rich_text_id, $this->title, $this->content, null, null, null, $this->cx_mch_id);
|
||
if($res['code'] != 0)
|
||
return $res;
|
||
$this->model->rich_text_id = $res['data']['rich_text_id'];
|
||
$this->model->status = $this->status;
|
||
$this->model->sort = $this->sort;
|
||
$this->model->is_top = $this->is_top;
|
||
$this->model->is_index = $this->is_index;
|
||
if($this->status == Notice::STATUS_PUBLISHED && empty($this->model->published_at)){
|
||
$this->model->published_at = time();
|
||
}
|
||
if(!$this->model->save()){
|
||
$t->rollBack();
|
||
return $this->getModelError($this->model);
|
||
}
|
||
$t->commit();
|
||
return $this->apiReturnSuccess("保存成功");
|
||
}
|
||
}
|
||
|