初始化仓库
This commit is contained in:
90
admin/models/forms/drug/ArticleForm.php
Normal file
90
admin/models/forms/drug/ArticleForm.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace admin\models\forms\drug;
|
||||
|
||||
use common\core\BaseModel;
|
||||
use common\models\DoctorArticle;
|
||||
use yii\db\Exception;
|
||||
|
||||
//文章Form
|
||||
class ArticleForm extends BaseModel
|
||||
{
|
||||
|
||||
public $id;
|
||||
public $type;
|
||||
public $cid;
|
||||
public $su_id;
|
||||
public $cover;
|
||||
public $title;
|
||||
public $intro;
|
||||
public $content;
|
||||
public $video_url;
|
||||
public $read_num;
|
||||
public $collection;
|
||||
public $is_draft;
|
||||
|
||||
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['su_id','read_num','collection','is_draft','id'],'integer'],
|
||||
[['cover','content','title','cid','type'],'required'],
|
||||
[['video_url','content','cover','title','intro'],'string'],
|
||||
['su_id','default','value'=>'0'],
|
||||
['read_num','default','value'=>'0'],
|
||||
['collection','default','value'=>'0'],
|
||||
['is_draft','default','value'=>'0'],
|
||||
];
|
||||
}
|
||||
|
||||
public function attributeLabels()
|
||||
{
|
||||
return [
|
||||
'type'=>'文章类型',
|
||||
'cid'=>'分类id',
|
||||
'cover'=>'封面',
|
||||
'intro'=>'简介',
|
||||
'content'=>'内容',
|
||||
'title'=>'文章标题',
|
||||
'video_url'=>'视频链接',
|
||||
'is_draft'=>'是否是草稿0否1是',
|
||||
'su_id'=>'医生id 0为后台发布',
|
||||
];
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
|
||||
if (!$this->validate()){
|
||||
throw new Exception($this->getErrorMsg());
|
||||
}
|
||||
|
||||
if (!$this->id){
|
||||
$DoctorArticle= new DoctorArticle();
|
||||
}else{
|
||||
$DoctorArticle= DoctorArticle::find()->where(['id'=>$this->id])->one();
|
||||
if (!$DoctorArticle) throw new Exception('文章不存在');
|
||||
}
|
||||
|
||||
$DoctorArticle->attributes=$this->attributes;
|
||||
|
||||
if (!$DoctorArticle->saveOrFail()){
|
||||
throw new Exception('error');
|
||||
};
|
||||
return ['success'];
|
||||
|
||||
}
|
||||
public function del()
|
||||
{
|
||||
$article= DoctorArticle::find()->where([
|
||||
'id' => $this->id,
|
||||
'is_delete'=>0
|
||||
])->one();
|
||||
if (!$article) throw new Exception('文章不存在');
|
||||
|
||||
$article->is_delete=1;
|
||||
$article->saveOrFail();
|
||||
|
||||
return ['删除成功'];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user