2024-09-19 11:32:39 +08:00
|
|
|
<?php
|
|
|
|
|
namespace platform\modules\v1\controllers;
|
|
|
|
|
|
|
|
|
|
use common\core\BasePlatformController;
|
2024-12-19 19:20:27 +08:00
|
|
|
use common\models\oldDb\ServiceUser;
|
|
|
|
|
use common\models\oldDb\ServiceUserToken;
|
2024-09-19 11:32:39 +08:00
|
|
|
use yii\base\Exception;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @doc-module 互医医生相关接口
|
|
|
|
|
*/
|
|
|
|
|
class DoctorController extends BasePlatformController
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @doc-name 获取平台医生的token
|
|
|
|
|
* @doc-param integer service_user_id service_user的id
|
|
|
|
|
* @doc-return mixed ServiceUser{*} 医生详情
|
|
|
|
|
*/
|
|
|
|
|
public function actionToken()
|
|
|
|
|
{
|
|
|
|
|
$post = \Yii::$app->request->post();
|
|
|
|
|
$service_user_id = $post['service_user_id'];
|
|
|
|
|
|
|
|
|
|
$user = ServiceUser::findOne(['id'=>$service_user_id]);
|
|
|
|
|
|
|
|
|
|
if(!$user){
|
|
|
|
|
throw new Exception('用户不存在');
|
|
|
|
|
}
|
|
|
|
|
$lastToken = ServiceUserToken::find()->where(['su_id' => $service_user_id])->orderBy('id DESC')->one();
|
|
|
|
|
if(!ServiceUserToken::checkToken($lastToken->token)){
|
|
|
|
|
$ServiceUserToken = new ServiceUserToken();
|
|
|
|
|
$ServiceUserToken->su_id = $service_user_id;
|
|
|
|
|
$token = \Yii::$app->security->generateRandomString() . '_' . time();
|
|
|
|
|
$ServiceUserToken->token = $token;
|
|
|
|
|
$ServiceUserToken->saveOrFail();
|
|
|
|
|
}else{
|
|
|
|
|
$token = $lastToken->token;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ['token' => $token];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|