update user login
This commit is contained in:
parent
f083e2ba80
commit
9db9ac7c3c
@ -1 +1 @@
|
||||
APP_DEBUG = true
[APP]
DEFAULT_TIMEZONE = Asia/Shanghai
ADMIN_MULTI_LOGIN = true
[DATABASE]
TYPE = mysql
HOSTNAME = 127.0.0.1
DATABASE = test
USERNAME = username
PASSWORD = password
HOSTPORT = 3306
CHARSET = utf8
DEBUG = true
[LANG]
default_lang = zh-cn
|
||||
APP_DEBUG = true
[APP]
DEFAULT_TIMEZONE = Asia/Shanghai
ADMIN_MULTI_LOGIN = true
[WECHAT]
KEY = wxba6738e3d81f8461
SECRET = wxba6738e3d81f8461
[DATABASE]
TYPE = mysql
HOSTNAME = 127.0.0.1
DATABASE = test
USERNAME = username
PASSWORD = password
HOSTPORT = 3306
CHARSET = utf8
DEBUG = true
[LANG]
default_lang = zh-cn
|
@ -38,16 +38,34 @@ class Evaluation extends ApiController
|
||||
ErrorCode::ERROR_PARAM_REQUIRED, '评估数据缺失'
|
||||
);
|
||||
}
|
||||
// 计算总分
|
||||
$score_keys = array_keys(Config::get('app.evaluation.subject'));
|
||||
$total_score = 0;
|
||||
foreach ($score_keys as $key){
|
||||
$total_score += intval($data[$key]);
|
||||
}
|
||||
$score_keys = array_keys(Config::get('app.evaluation.subject'));//['dizzy','gastrointestinal','headache','tired'];
|
||||
$evaluation = EvaluationHistory::create(array_merge([
|
||||
'uid' => $this->getCurrentUserInfo()->id
|
||||
'uid' => $this->getCurrentUserInfo()->id,
|
||||
'score' => $total_score
|
||||
], $data));
|
||||
if ($evaluation->id > 0) {
|
||||
return SuccessResponse::create();
|
||||
return SuccessResponse::create(['id'=>$evaluation->id]);
|
||||
}
|
||||
return ErrorResponse::createError(
|
||||
ErrorCode::EVALUATION_SAVE_FAIL, '保存评估数据失败'
|
||||
);
|
||||
}
|
||||
public function detail(int $id)
|
||||
{
|
||||
$evaluation = EvaluationService::findById($id);
|
||||
if(empty($evaluation)){
|
||||
return ErrorResponse::createError(
|
||||
ErrorCode::EVALUATION_NOT_EXISTS, '评估数据不存在或已被删除'
|
||||
);
|
||||
}
|
||||
return SuccessResponse::create($evaluation);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户评估的所有项目
|
||||
|
@ -14,6 +14,7 @@ use app\common\ApiController;
|
||||
use app\model\UserInfo;
|
||||
use app\util\ErrorCode;
|
||||
use app\util\ErrorResponse;
|
||||
use app\util\WechatUtil;
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
use PhpOffice\PhpSpreadsheet\Writer\Csv;
|
||||
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
||||
@ -21,10 +22,9 @@ use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
||||
class User extends ApiController
|
||||
{
|
||||
protected $middleware = [
|
||||
'\app\middleware\ApiCheck' => ['except' => ['create']],
|
||||
'\app\middleware\ApiCheck' => ['except' => ['create', 'login']],
|
||||
];
|
||||
|
||||
|
||||
public function search()
|
||||
{
|
||||
list($is_first, $gender, $city, $name) = $this->getParams(
|
||||
@ -39,6 +39,23 @@ class User extends ApiController
|
||||
->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* 小程序login
|
||||
* 通过login获得code到微信服务器换区open_id等数据
|
||||
* 并可以将数据直接保存到数据库
|
||||
* @param string $code
|
||||
*/
|
||||
public function login(string $code)
|
||||
{
|
||||
$wechat = new WechatUtil();
|
||||
return json(
|
||||
[
|
||||
WX_APP_ID,
|
||||
WX_APP_SECRET
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$dataType = $this->request->post('type');
|
||||
|
@ -37,6 +37,11 @@ class EvaluationService
|
||||
['属于重度高反', '联系120,医院急诊留观或进入抢救室'],
|
||||
];
|
||||
|
||||
public static function findById(int $id){
|
||||
$evaluation = EvaluationHistory::find($id);
|
||||
if(empty($evaluation)) return null;
|
||||
return self::parseEvaluationData($evaluation->toArray());
|
||||
}
|
||||
public static function parseEvaluationData($item)
|
||||
{
|
||||
$data = [];
|
||||
@ -62,6 +67,7 @@ class EvaluationService
|
||||
elseif ($data['score'] <= 9) $level = 2;
|
||||
else $level = 3;
|
||||
}
|
||||
$data['level'] = $level;
|
||||
$data['result'] = $results[$level][0];
|
||||
$data['suggest'] = $results[$level][1];
|
||||
}
|
||||
|
@ -50,15 +50,20 @@ class ErrorCode
|
||||
* 评估
|
||||
*/
|
||||
const EVALUATION_SAVE_FAIL = 23005;
|
||||
const EVALUATION_NOT_EXISTS = 23006;
|
||||
}
|
||||
|
||||
class ErrorResponse extends Json
|
||||
{
|
||||
public static function createError($errorCode, $errorMessage = ''): Response
|
||||
public static function createError($errorCode, $errorMessage = '',$extData = null): Response
|
||||
{
|
||||
return parent::create([
|
||||
$ret = [
|
||||
"code" => $errorCode,
|
||||
"message" => $errorMessage
|
||||
]); // TODO: Change the autogenerated stub
|
||||
];
|
||||
if($extData){
|
||||
$ret['data'] = $extData;
|
||||
}
|
||||
return parent::create($ret); // TODO: Change the autogenerated stub
|
||||
}
|
||||
}
|
44
app/util/WechatUtil.php
Normal file
44
app/util/WechatUtil.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: yancheng<cheng@love.xiaoyan.me>
|
||||
* Date: 2019/6/23
|
||||
* Time: 11:29 AM
|
||||
*/
|
||||
|
||||
namespace app\util;
|
||||
use think\facade\Config;
|
||||
|
||||
define('WX_SERVER_URL', 'https://api.weixin.qq.com');
|
||||
define('CODE_2_SESSION', WX_SERVER_URL . '/sns/jscode2session');
|
||||
define('WX_APP_ID',Config::get('wechat.key'));
|
||||
define('WX_APP_SECRET',Config::get('wechat.secret'));
|
||||
class WechatUtil
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public function codeToSession(strign $code): array
|
||||
{
|
||||
return json_decode(
|
||||
$this->request(
|
||||
CODE_2_SESSION, [
|
||||
'js_code' => 'JSCODE',
|
||||
'grant_type' => 'authorization_code'
|
||||
]
|
||||
), true
|
||||
);
|
||||
}
|
||||
|
||||
private function request(string $api, array $params = [], string $method = 'GET')
|
||||
{
|
||||
$params['appid'] = WX_APP_ID;
|
||||
$params['secret'] = WX_APP_SECRET;
|
||||
$url = WX_SERVER_URL . $api;
|
||||
if (strtolower($method) == 'get') {
|
||||
$url .= http_build_query($params);
|
||||
}
|
||||
return file_get_contents($url);
|
||||
}
|
||||
}
|
14
config/wechat.php
Normal file
14
config/wechat.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: yancheng<cheng@love.xiaoyan.me>
|
||||
* Date: 2019/6/23
|
||||
* Time: 11:24 AM
|
||||
*/
|
||||
|
||||
use think\facade\Env;
|
||||
|
||||
return [
|
||||
'key' => Env::get('wechat.key'),
|
||||
'secret' => Env::get('wechat.secret'),
|
||||
];
|
Loading…
x
Reference in New Issue
Block a user