初始化仓库
This commit is contained in:
71
service/models/forms/DoctorServiceForm.php
Normal file
71
service/models/forms/DoctorServiceForm.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
namespace service\models\forms;
|
||||
|
||||
use common\core\BaseModel;
|
||||
use common\models\DoctorService;
|
||||
use common\models\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;
|
||||
}
|
||||
$model->attributes = $this->attributes;
|
||||
$model->saveOrFail();
|
||||
|
||||
$user = \Yii::$app->user->identity;
|
||||
$user->saveOrFail();
|
||||
|
||||
$t->commit();
|
||||
}catch (Exception $exception){
|
||||
$t->rollBack();
|
||||
throw $exception;
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user