512], [['author'], 'string', 'max' => 128], [['summary', 'cover_url'], 'string', 'max' => 2048], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'cx_mch_id' => '平台商户ID', 'title' => '标题', 'author' => '作者', 'summary' => '摘要', 'cover_url' => '封面', 'content' => '内容', 'created_at' => '添加时间', 'updated_at' => '更新时间', 'is_delete' => '是否删除:0=否,1=是', 'deleted_at' => '删除时间', ]; } public function beforeSave($insert) { if(parent::beforeSave($insert)){ if($this->isNewRecord){ $this->created_at = time(); } $this->updated_at = time(); if($this->is_delete == 1) $this->deleted_at = time(); $this->htmlTagFilter(); return true; } else { return false; } } public function htmlTagFilter() { $this->title = Model::htmlTagFilter($this->title); $this->author = Model::htmlTagFilter($this->author); $this->summary = Model::htmlTagFilter($this->summary); $this->cover_url = Model::htmlTagFilter($this->cover_url); $this->content = Model::htmlTagFilter($this->content); } public static function saveRichText($rich_text_id, $title, $content, $cover_url = null, $author = null, $summary = null, $cx_mch_id = 0) { $model = RichText::findOne([ 'id' => $rich_text_id, 'cx_mch_id' => $cx_mch_id, ]); if($model == null){ $model = new RichText(); $model->cx_mch_id = $cx_mch_id; $model->is_delete = 0; } $model->title = $title; $model->content = $content; $model->author = $author; $model->summary = $summary; $model->cover_url = $cover_url; if(!$model->save()){ return (new Model())->getModelError($model); } return Model::asReturnSuccess("ok", ['rich_text_id' => $model->id]); } public static function deleteRichText($rich_text_id, $cx_mch_id = 0) { $model = RichText::findOne([ 'id' => $rich_text_id, 'cx_mch_id' => $cx_mch_id, 'is_delete' => 0 ]); if($model == null){ return Model::asReturnError("内容不存在或已经删"); } $model->is_delete = 1; if(!$model->save()){ return (new Model())->getModelError($model); } return Model::asReturnSuccess(); } }