67 lines
1.5 KiB
PHP
67 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace member\models\forms;
|
|
|
|
use common\core\BaseModel;
|
|
use common\models\oldDb\FollowDoctor;
|
|
use yii\db\Exception;
|
|
|
|
|
|
//关注form
|
|
class FollowForm extends BaseModel
|
|
{
|
|
public $su_id;
|
|
|
|
public function rules()
|
|
{
|
|
return [
|
|
[['su_id'],'required'],
|
|
];
|
|
}
|
|
|
|
|
|
public function save()
|
|
{
|
|
if (!$this->validate()){
|
|
throw new Exception($this->getErrorMsg());
|
|
}
|
|
$su_ids = FollowDoctor::find()->where([
|
|
'user_id' => \Yii::$app->user->identity->id,
|
|
])->select('su_id')->column();
|
|
|
|
if (in_array($this->su_id ,$su_ids)) {
|
|
throw new Exception('已关注该医生');
|
|
}
|
|
|
|
$FollowDoctor=new FollowDoctor();
|
|
$FollowDoctor->attributes=$this->attributes;
|
|
$FollowDoctor->user_id=\Yii::$app->user->identity->id;
|
|
$FollowDoctor->saveOrFail();
|
|
}
|
|
|
|
public function cancel()
|
|
{
|
|
if (!$this->validate()){
|
|
throw new Exception($this->getErrorMsg());
|
|
}
|
|
$su_ids = FollowDoctor::find()->where([
|
|
'user_id' => \Yii::$app->user->identity->id,
|
|
])->select('su_id')->column();
|
|
|
|
if (!in_array($this->su_id ,$su_ids)) {
|
|
throw new Exception('你还没有关注该医生');
|
|
}
|
|
|
|
\Yii::$app->db->createCommand()->delete('yii_follow_doctor', ['user_id' => \Yii::$app->user->identity->id, 'su_id' => $this->su_id])->execute();
|
|
|
|
}
|
|
|
|
|
|
public function attributeLabels()
|
|
{
|
|
return [
|
|
'su_id' => '医生id',
|
|
];
|
|
}
|
|
|
|
} |