75 lines
2.0 KiB
PHP
75 lines
2.0 KiB
PHP
<?php
|
|
namespace service\models\forms;
|
|
|
|
use common\core\BaseModel;
|
|
use common\models\oldDb\DoctorService;
|
|
use common\models\oldDb\ServiceUser;
|
|
use yii\base\Exception;
|
|
|
|
//医生服务设置
|
|
class DoctorServiceForm extends BaseModel
|
|
{
|
|
public $register_status;
|
|
public $register_price;
|
|
|
|
public function rules()
|
|
{
|
|
return [
|
|
[['register_status','register_price'],'default','value'=>0],
|
|
[['register_price'],'number','min'=>0],
|
|
['register_price','match', 'pattern' => '/^\d+(\.\d{1,2})?$/i','message'=>'挂号费价格最多两位小数']
|
|
];
|
|
}
|
|
public function attributeLabels()
|
|
{
|
|
return [
|
|
'register_status' => '开通挂号',
|
|
'register_price' => '挂号费'
|
|
];
|
|
}
|
|
|
|
public function save()
|
|
{
|
|
if(!$this->validate()){
|
|
throw new Exception($this->getErrorMsg());
|
|
}
|
|
|
|
$serviceUser = ServiceUser::find()->where([
|
|
'id' => \Yii::$app->user->identity->id,
|
|
'is_delete' => 0
|
|
])->with('docInfo','docIdentity','docPracticing')->one();
|
|
|
|
if(!$serviceUser){
|
|
throw new Exception('用户不存在');
|
|
}
|
|
|
|
$t = \Yii::$app->db->beginTransaction();
|
|
try {
|
|
$model = DoctorService::find()->where([
|
|
'su_id' => \Yii::$app->user->identity->id,
|
|
])->one();
|
|
|
|
if(!$model){
|
|
$model = new DoctorService();
|
|
$model->su_id = \Yii::$app->user->identity->id;
|
|
}
|
|
if (!empty($this->register_status?? null)) {
|
|
$model->register_status = $this->register_status;
|
|
}
|
|
$model->attributes = $this->attributes;
|
|
$model->saveOrFail();
|
|
|
|
$user = \Yii::$app->user->identity;
|
|
$user->saveOrFail();
|
|
|
|
$t->commit();
|
|
}catch (Exception $exception){
|
|
$t->rollBack();
|
|
throw $exception;
|
|
}
|
|
return [];
|
|
}
|
|
|
|
|
|
}
|