初始化仓库
This commit is contained in:
67
member/models/forms/FollowForm.php
Normal file
67
member/models/forms/FollowForm.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace member\models\forms;
|
||||
|
||||
use common\core\BaseModel;
|
||||
use common\models\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',
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user