初始化仓库
This commit is contained in:
97
service/models/forms/DrugCompleteOne.php
Normal file
97
service/models/forms/DrugCompleteOne.php
Normal file
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
namespace service\models\forms;
|
||||
|
||||
use common\core\BaseModel;
|
||||
use common\models\DoctorInfo;
|
||||
use common\models\PharmacistrInfo;
|
||||
use common\models\StoreDoctor;
|
||||
use common\validators\MobileValidator;
|
||||
use GuzzleHttp\Client;
|
||||
use yii\base\Exception;
|
||||
use yii\helpers\Json;
|
||||
|
||||
//药师完善信息第一步
|
||||
class DrugCompleteOne extends BaseModel
|
||||
{
|
||||
public $name;
|
||||
public $avatar;
|
||||
public $mobile;
|
||||
public $idcard;
|
||||
public $store_id;
|
||||
public $depart_id;
|
||||
public $title_id;
|
||||
public $id_card;
|
||||
public $type;
|
||||
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['name','avatar','mobile','idcard','store_id','title_id','type'],'required'],
|
||||
['mobile',MobileValidator::class],
|
||||
['id_card', 'match', 'pattern' => '/^[1-9]\d{5}(18|19|20|(3\d))\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/i'],
|
||||
['idcard', 'checkCard'],
|
||||
];
|
||||
}
|
||||
|
||||
public function checkCard($attribute, $params)
|
||||
{
|
||||
$response = (new Client(['http_errors' => false]))->post("https://eid.shumaidata.com/eid/check", [
|
||||
'headers' => ['Authorization' =>"APPCODE f98bba3251714c759f5bd29d00e1c46e"],
|
||||
'query' => [
|
||||
'idcard' => $this->idcard,
|
||||
'name' => $this->name
|
||||
],
|
||||
]);
|
||||
$result = json_decode($response->getBody(),true);
|
||||
if(!($result['code']==0 && $result['result']['res']==1)){
|
||||
$this->addError($attribute, '身份证名字不匹配');
|
||||
}
|
||||
}
|
||||
|
||||
public function attributeLabels()
|
||||
{
|
||||
return [
|
||||
'name' => '姓名',
|
||||
'avatar' => '头像',
|
||||
'mobile' => '手机号',
|
||||
'idcard' => '身份证号',
|
||||
'store_id' => '门店id',
|
||||
'title_id' => '职称',
|
||||
'type' => '身份类型1中医药师 2西医药师',
|
||||
];
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
if(!$this->validate()){
|
||||
throw new Exception($this->getErrorMsg());
|
||||
}
|
||||
$model = PharmacistrInfo::find()->where([
|
||||
'su_id' => \Yii::$app->user->identity->id,
|
||||
])->one();
|
||||
$t=\Yii::$app->db->beginTransaction();
|
||||
if(!$model){
|
||||
$model = new PharmacistrInfo();
|
||||
$model->su_id = \Yii::$app->user->identity->id;
|
||||
|
||||
$docinfo=DoctorInfo::find()->where(['idcard'=>$this->idcard,'is_delete'=>0])->one();
|
||||
$pharmacistrInfo=PharmacistrInfo::find()->where(['idcard'=>$this->idcard])->one();
|
||||
if ($pharmacistrInfo){
|
||||
throw new \yii\db\Exception('您已经注册过药师了');
|
||||
}
|
||||
if ($docinfo){
|
||||
throw new \yii\db\Exception('您的身份证不能同时注册医生和药师');
|
||||
}
|
||||
}
|
||||
|
||||
$model->attributes = $this->attributes;
|
||||
if (!$model->saveOrFail()){
|
||||
$t->rollBack();
|
||||
}
|
||||
|
||||
$t->commit();
|
||||
return ['已完善基础信息'];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user