新版reedaw接口调整

This commit is contained in:
tsf 2025-10-11 18:11:41 +08:00
parent 77e42aa6ea
commit 438ad0f12d
13 changed files with 3274 additions and 4 deletions

17
.vscode/111.json vendored Normal file
View File

@ -0,0 +1,17 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9000, // Xdebug v2使9000
"pathMappings": {
"D:/phpstudy_pro/WWW/reedaw/SchoolPhysicalExamination": "${workspaceFolder}",
"D:/phpstudy_pro/WWW/reedaw/SchoolPhysicalExamination/public": "${workspaceFolder}/public"
},
"log": true,
"stopOnEntry": false
}
]
}

23
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,23 @@
{
// 使 IntelliSense
//
// 访: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000,
"timeout": 30000 //
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000
}
]
}

View File

@ -209,7 +209,6 @@ class Base extends Controller{
}else if($type == 'other'){ }else if($type == 'other'){
} }
} }
// 计算年龄 // 计算年龄
public function calculate_age($data = '1991-04-20'){ public function calculate_age($data = '1991-04-20'){

View File

@ -0,0 +1,742 @@
<?php
namespace app\NewReedaw\controller\app;
use think\Controller;
use think\Db;
use think\Cache;
use think\Log;
use PHPMailer\PHPMailer\PHPMailer;
class Base extends Controller{
protected $base_use_db_name = [
'1'=>'app_data_log',
'2'=>'app_card_data',
'3'=>'app_user_data',
'4'=>'pc_vitalcapacity_standard',
'5'=>'admin_estimate',
'6'=>'app_account_number'
];
public $test_token = ['57bd45e3a963b372ea2d873e4bd8d1f8','e0966788d02cc93290d9d674921d9715'];
protected $base_call_method = ['内部'];
protected $token_time = 30;//30天的秒数
protected $return_data_all = [
// '0' => ['success',[]],
'10001'=>'关键参数缺失',
'10002'=>'操作失败',
'10003'=>'信息核实错误',
'10004'=>'未找到有效数据',
'10005'=>'参数格式错误',
'10006'=>'参数不能为空',
'10007'=>'参数错误',
'10008'=>'',
'10009'=>'',
'10010'=>'自定义信息',
'20001'=>'登录失效',
'99999'=>'网络异常,请稍后重试',
];
// 加 bcadd(,,20)
// 减 bcsub(,,20)
// 乘 bcmul(,,20)
// 除 bcdiv(,,20)
################################################################接口################################################################
################################################################接口################################################################
################################################################接口################################################################
// 接口记录
public function record_api_log($params, $error = null, $response = null){
$logContent = "接口请求参数:" . json_encode($params, JSON_UNESCAPED_UNICODE) . PHP_EOL;
if ($error) {
$logContent .= "错误信息:" . $error['all_content'] . PHP_EOL;
if(!cache($error['flie']."_".$error['line'])){
cache($error['flie']."_".$error['line'],"API错误",3600);
$this->send_email_api_error(["tsf3920322@126.com"],['title'=>'新Reedaw接口报错','from_user_name'=>'Reedaw-API','content'=>$logContent]);
}
}
if ($response) {
$logContent .= "返回信息:" . json_encode($response, JSON_UNESCAPED_UNICODE) . PHP_EOL;
}
// 使用ThinkPHP的日志记录方法
Log::record($logContent, 'api_log');
}
// 检查变量是否是一个只有数字的一维数组
public function is_num_array($array = [1,2,3]) {
if (!is_array($array)) {
return false; // 变量不是数组
}
foreach ($array as $value) {
if (!is_numeric($value)) {
return false; // 数组中包含非数字元素
}
}
$result = Db::table($this->base_use_db_name['2'])->where(['is_del'=>0])->cache(true,600)->select();//查询结果缓存3600秒
if(empty(array_diff($array, array_column($result, 'id')))){
return true;// 数组是一维的且只包含数字,且已经跟数据库比对过,每个数值都是有效
}else{
return false;//跟数据库比对过,存在无效数值
}
}
public function validate_user_identity($data) {
$validate_user = Db::table($this->base_use_db_name['3'])->where(['id'=>$data])->count();
if($validate_user<=0){
return false;
}else{
return true;
}
}
// 判断字符串是手机还是邮箱
public function is_tel_email($str) {
// 手机号码的正则表达式(中国大陆格式)(下面正则实际判断的是是否为11位数字)
$mobilePattern = '/^\d{11}$/';
// 电子邮件地址的正则表达式
$emailPattern = '/^[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/';
// 判断是否为手机号码
if (preg_match($mobilePattern, $str)) {
return 'tel';
}
// 判断是否为电子邮件地址
if (preg_match($emailPattern, $str)) {
return 'email';
}
// 如果都不是,返回其他
return false;
}
// 计算年龄
public function calculate_age($data = '1991-04-20'){
$today = time(); // 获取当前时间的 Unix 时间戳
$birthDate = strtotime($data); // 将出生日期字符串转换为 Unix 时间戳
if ($birthDate !== false) {
$age = date('Y', $today) - date('Y', $birthDate);
// 如果当前年份的月份和日期小于出生年份的月份和日期,那么年龄减一
if (date('m-d', $today) < date('m-d', $birthDate)) {
$age--;
}
return $age;
} else {
return false;
}
}
// 秒转化格式00:00:00
public function handle_hour_branch_second($data = '2000'){
$data = abs($data);
$hours = intval($data / 3600);
$minutes = intval(($data % 3600) / 60);
$remainingSeconds = $data % 60;
return [
'h' => str_pad($hours, 2, '0', STR_PAD_LEFT),
'm' => str_pad($minutes, 2, '0', STR_PAD_LEFT),
's' => str_pad($remainingSeconds, 2, '0', STR_PAD_LEFT)
];
}
// 判断token是否过期
public function token_time_validate($token){
// 591b70e0d80b5fa6d77e6e1384453ab9
if(is_string($token)){
$length = strlen($token);
if ($length < 10 ) {
Log::record('用户尝试更新token时间token' . $token.',但是更新token失败字符串长度小于10', 'token_log');
return ['state'=>false,'language'=>null];
}
}else{
Log::record('用户尝试更新token时间token' . $token.',但是更新token失败不是字符串', 'token_log');
return ['state'=>false,'language'=>null];
}
$user_login = Db::table($this->base_use_db_name['6'])->where(['token'=>$token])->field('id,login_time,language')->find();
if(!$user_login){
Log::record('用户尝试更新token时间token' . $token.',但是更新token失败未找到用户token', 'token_log');
return ['state'=>false,'language'=>null];
}
// 创建 DateTime 对象来表示指定的日期和时间
$specifiedDateTime = new \DateTime($user_login['login_time']);
// 获取当前时间的 DateTime 对象
$currentDateTime = new \DateTime();
// 计算两个日期之间的差异(以秒为单位)
$interval = $currentDateTime->diff($specifiedDateTime);
// 将差异转换为天数(注意:这里的天数可能不是整数,因为差异可能包括小时、分钟等)
$daysDifference = $interval->days;
// 如果需要更精确的计算(包括小时、分钟等转换成的天数),可以使用以下方式:
// $totalSecondsDifference = $interval->format('%a') * 86400 + $interval->format('%h') * 3600 + $interval->format('%i') * 60 + $interval->format('%s');
// $daysDifference = floor($totalSecondsDifference / 86400); // 将总秒数转换为天数并取整
// 判断差异是否超过指定的天数
if ($daysDifference > $this->token_time) {
// echo "超过 {$specifiedDays} 天";
Log::record('用户尝试更新token时间token' . $token.',但是更新token失败原因没有找到该token,或该token已经超过30天', 'token_log');
return ['state'=>false,'language'=>$user_login['language']];
} else {
// echo "未超过 {$specifiedDays} 天";
$user_login = Db::table($this->base_use_db_name['6'])->where(['token'=>$token])->update(['login_time'=>date('Y-m-d H:i:s')]);
if($user_login){
Log::record('用户尝试更新token时间token' . $token.',记录成功,最新的时间为'.date('Y-m-d H:i:s'), 'token_log');
return ['state'=>true,'language'=>$user_login['language']];
}else{
Log::record('用户尝试更新token时间token' . $token.',但是更新token失败数据库更新时间未成功', 'token_log');
return ['state'=>true,'language'=>$user_login['language']];
}
}
}
// 计算天数
public function daysSince($pastDate,$now = false)
{
// 创建一个表示过去日期的 DateTime 对象
$past = new \DateTime($pastDate);
if($now === false){
// 创建一个表示当前日期的 DateTime 对象
$now = new \DateTime();
}else{
$now = new \DateTime($now);
}
// 使用 DateTime::diff() 方法计算两个日期之间的差值
$interval = $past->diff($now);
// 返回相差的天数
return $interval->format('%a');
}
// 计算月龄
public function calculateAgeInMonthsWithPrecision($birthDateStr) {
// 获取当前日期
$now = new \DateTime();
// 将出生日期字符串转换为 DateTime 对象
$birthDate = \DateTime::createFromFormat('Y-m-d', $birthDateStr);
// 计算两者之间的差距(以月为单位,包含部分月份的小数)
$interval = $now->diff($birthDate);
$ageInMonths = $interval->y * 12 + $interval->m; // 年份乘以12加上月份
$remainingDays = $interval->d; // 当前月内的剩余天数
// 将剩余天数转换为小数月份假设一个月为30天进行近似计算
$partialMonth = $remainingDays / 30;
// 结果精确到小数点后两位
// $ageInMonthsPrecise = round($ageInMonths + $partialMonth, 2);
// 整月+剩余月取整
$ageInMonthsPrecise = intval($ageInMonths + $partialMonth);
return $ageInMonthsPrecise;
}
// 曲线页面-底部统计动作
public function base_target_initial_cumulative_weight($data = []){
// 第一种:用户详情(所有数据都有)
// 第二种:手动记录(只有最新体重)
// 第三种:修改原始体重(只有原始体重)
// $result_data['target_weight'] 目标体重
// $result_data['initial_weight'] 最初体重
// $result_data['weight'] 最近一次测量重量
// $result_data['initial_date'] 初始体重日期
if(count($data) > 0){
$result_data['target_weight'] = $data['target_weight'];
$result_data['initial_weight'] = $data['initial_weight'];
$result_data['cumulative_weight'] = bcsub($data['weight'],$data['initial_weight'],2);
$result_data['cumulative_day'] = $data['initial_date'] == 0?0:$this->daysSince($data['initial_date']);
}else{
$result_data['target_weight'] = 0;
$result_data['initial_weight'] = 0;
$result_data['cumulative_weight'] = 0;
$result_data['cumulative_day'] = 0;
}
return $result_data;
}
// 判断一个参数是否为数字且大于等于0
public function isPositiveNumber($value) {
return is_numeric($value) && $value >= 0;
}
// 判断是否为整型,或者字符串类型的整型数字
public function isValidInteger($var) {
// 直接检查是否为整型
if (is_int($var)) {
return true;
}
// 检查是否为字符串且是有效的整数表示
if (is_string($var) && filter_var($var, FILTER_VALIDATE_INT) !== false) {
return true;
}
// 其他情况
return false;
}
// 判断一个字符串是否为两位以内小数
public function isTwoDecimalOrLess($str) {
return preg_match('/^\d*(\.\d{1,2})?$/', $str) === 1;
}
// 获取用户肺活量的标准值
public function get_vitalcapacity_data($id){
$standard_data = [
['min_val'=>'90','max_val'=>'100','text'=>'优秀','color'=>'#6492F6'],
['min_val'=>'80','max_val'=>'89','text'=>'良好','color'=>'#5AD06D'],
['min_val'=>'60','max_val'=>'79','text'=>'及格','color'=>'#FFAB00'],
['min_val'=>'10','max_val'=>'59','text'=>'不及格','color'=>'#FF5656'],
['min_val'=>'0','max_val'=>'9','text'=>'无效','color'=>'#FF5656'],
];
$grade = Db::table($this->base_use_db_name['3'])->where(['id'=>$id])->field('id,grade,gender,birthday')->find();
if(!$grade){
return [];
}
if($grade['grade'] == 'nothing'){
// 计算年龄判断是属于哪个年级
$user_age = $this->calculate_age($grade['birthday']);
if($user_age <= 7){
$grade['grade'] = 'grade_s_1';
}else if($user_age == 8){
$grade['grade'] = 'grade_s_2';
}else if($user_age == 9){
$grade['grade'] = 'grade_s_3';
}else if($user_age == 10){
$grade['grade'] = 'grade_s_4';
}else if($user_age == 11){
$grade['grade'] = 'grade_s_5';
}else if($user_age == 12){
$grade['grade'] = 'grade_s_6';
}else if($user_age == 13){
$grade['grade'] = 'grade_m_1';
}else if($user_age == 14){
$grade['grade'] = 'grade_m_2';
}else if($user_age == 15){
$grade['grade'] = 'grade_m_3';
}else if($user_age == 16){
$grade['grade'] = 'grade_h_1';
}else if($user_age == 17){
$grade['grade'] = 'grade_h_2';
}else if($user_age == 18){
$grade['grade'] = 'grade_h_3';
}else if($user_age == 19 || $user_age == 20){
$grade['grade'] = 'grade_u_12';
}else if($user_age >= 21){
$grade['grade'] = 'grade_u_34';
}
}
$sql_min = "WITH RankedGrades AS (
SELECT
id,
level,
".$grade['grade'].",
ROW_NUMBER() OVER(PARTITION BY level ORDER BY ".$grade['grade']." ASC, id ASC) AS rn
FROM
".$this->base_use_db_name['4']."
WHERE
sex = ".$grade['gender']."
)
SELECT
id,
level,
".$grade['grade']."
FROM
RankedGrades
WHERE
rn = 1";
$result_min = Db::query($sql_min);
foreach ($result_min as $key => $value) {
foreach ($standard_data as $sdk => $sdv) {
if($value['level'] == $sdv['text']){
$standard_data[$sdk]['min_val'] = $value[$grade['grade']];
}
}
}
for ($i=count($standard_data)-1; $i >= 1; $i--) {
$standard_data[$i]['max_val'] = $standard_data[$i-1]['min_val'];
}
$standard_data[0]['max_val'] = '5140';
return $standard_data;
}
// 时间日期转换
public function addCurrentTimeToDateString($dateStr) {
// 将日期字符串转换为DateTime对象
$dateTime = new \DateTime($dateStr);
// 获取当前的时分秒
$currentTime = new \DateTime('now');
$hours = $currentTime->format('H');
$minutes = $currentTime->format('i');
$seconds = $currentTime->format('s');
// 设置DateTime对象的时间部分为当前时间
$dateTime->setTime($hours, $minutes, $seconds);
// 返回格式化为"Y-m-d H:i:s"的字符串
return $dateTime->format('Y-m-d H:i:s');
}
// 处理分秒变秒
public function convertMinutesSecondsToStringSeconds($timeString) {
// 分割字符串获取分钟和秒
list($minutes, $seconds) = explode(':', $timeString);
// 将分钟和秒转换为秒
$totalSeconds = ($minutes * 60) + intval($seconds); // 确保秒是整数
return $totalSeconds;
}
// 转换数字"90.00", "88.11", "66.50", ".00"为正常数字
public function convertStringToNumber($str) {
// 去除字符串两端的空格(如果有的话)
$str = trim($str);
// 检查字符串是否为空或只包含小数点
if ($str === '' || $str === '.') {
return 0;
}
// 尝试将字符串转换为浮点数
$number = (float)$str;
// 格式化浮点数,去掉末尾多余的零
$formattedNumber = rtrim(rtrim(sprintf('%.2f', $number), '0'), '.');
// 如果结果为空字符串(比如,原字符串是“.00”则返回0
if ($formattedNumber === '') {
return '0';
}
// 返回结果,转换为整数如果小数点后没有数字
if (strpos($formattedNumber, '.') === false) {
$formattedNumber = (int)$formattedNumber;
return "$formattedNumber";
}
return $formattedNumber;
}
// 时间加一或者减一
public function adjustDateTime($datetimeStr, $type) {
// 将时间字符串转换为时间戳
$timestamp = strtotime($datetimeStr);
// 检查时间戳是否有效
if ($timestamp === false) {
return "无效的日期时间格式";
}
// 根据$type参数调整时间戳
switch ($type) {
case 'add':
$newTimestamp = strtotime('+1 day', $timestamp);
break;
case 'subtract':
$newTimestamp = strtotime('-1 day', $timestamp);
break;
default:
return false;
}
// 将新的时间戳转换回日期时间字符串
$newDateTimeStr = date('Y-m-d', $newTimestamp);
return $newDateTimeStr;
}
// 对于任意浮点字符串的指定位四舍五入
public function roundToString($numberStr, $numDecimals) {
// 将字符串转换为浮点数
$number = floatval($numberStr);
// 四舍五入到指定的小数位数
$roundedNumber = round($number, $numDecimals);
// 将结果转换回字符串
return strval($roundedNumber);
}
// 发送一个PSOT请求
public function postRequest($url, $data = [], $headers = []) {
$ch = curl_init(); // 初始化cURL会话
if (!$ch) {
return [
'error' => true,
'message' => 'cURL init failed'
];
}
// 设置cURL选项
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 禁用证书验证
curl_setopt($ch, CURLOPT_URL, $url); // 要请求的URL
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // 将curl_exec()获取的信息以文件流的形式返回,而不是直接输出
curl_setopt($ch, CURLOPT_POST, true); // 发送一个常规的POST请求
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); // POST数据
// 设置请求头
if (!empty($headers)) {
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
}else{
// 如果需要发送JSON数据可以使用以下设置
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
}
// 执行cURL会话
$response = curl_exec($ch);
if ($response === false) {
$error = curl_error($ch);
curl_close($ch);
return [
'error' => true,
'message' => "cURL Error: $error"
];
}
$decodedResponse = json_decode($response, true);
$jsonError = json_last_error();
curl_close($ch);
if ($jsonError !== JSON_ERROR_NONE) {
return [
'error' => true,
'message' => 'Invalid JSON Response',
'raw_response' => $response
];
}
return $decodedResponse;
}
public function msg($data,$str='',$result = []){
if(is_array($data)){
if($str != ''){
return json(['code'=>0,'msg'=>$str,'data'=>$data]);
}else{
return json(['code'=>0,'msg'=>'操作成功','data'=>$data]);
}
}else{
if($str != ''){
return json(['code'=>$data,'msg'=>$str,'data'=>$result]);
}
return json(['code'=>$data,'msg'=>$this->return_data_all[$data],'data'=>$result]);
}
}
/* 接口说明(发邮件)
* $address收件人的邮箱地址 数组 格式: ['460834639@qq.com','460834639@qq.com'.......]
* $content邮件的主题数据信息 数组 格式:['title'=>'123','from_user_name'=>'123','content'=>'123']
* $annex附件路径信息 字符串
*/
public function send_email_api_error($address,$content,$annex=''){
// $ad = '460834639@qq.com';
$ad1 = '295155911@qq.com';
$mail = new PHPMailer(); //实例化
$mail->IsSMTP(); // 启用SMTP
$mail->Host = "smtp.126.com"; //SMTP服务器 163邮箱例子
$mail->Port = 465; //邮件发送端口
$mail->SMTPAuth = true; //启用SMTP认证
$mail->SMTPSecure = 'ssl';
$mail->CharSet = "UTF-8"; //字符集
$mail->Encoding = "base64"; //编码方式
$mail->Username = "tsf3920322@126.com"; //你的邮箱
$mail->Password = "HLWXNRPUCTHJFIIX"; //你的密码(邮箱后台的授权密码)
$mail->From = "tsf3920322@126.com"; //发件人地址(也就是你的邮箱)
// $mail->Subject = "微盟测试邮件"; //邮件标题
$mail->Subject = $content['title']; //邮件标题
// $mail->FromName = "微盟体测中心"; //发件人姓名
$mail->FromName = $content['from_user_name']; //发件人姓名
for ($i=0; $i < count($address); $i++) {
$mail->AddAddress($address[$i], ""); //添加收件人(地址,昵称)
}
if($annex != ''){
// $url = ROOT_PATH. 'public' . DS . 'tsf' . DS .'demoooo.jpg';
$mail->AddAttachment($annex,''); // 添加附件,并指定名称
}
$mail->IsHTML(true); //支持html格式内容
$neirong = $content['content'];
$mail->Body = $neirong; //邮件主体内容
//发送
if (!$mail->Send()) {
return ['code' => 10003,'msg'=>$mail->ErrorInfo];
// return $mail->ErrorInfo;
} else {
return ['code' => 0];
// return 'success';
}
}
/**
* 验证数据是否符合指定类型要求
*
* @param mixed $data 要验证的数据
* @param string $type 验证类型 (str, num, intnum, datetime)
* @return bool 验证结果
* @throws InvalidArgumentException 当传入未知类型时抛出异常
*/
public function verify_data_is_ok($data, string $type): bool
{
switch ($type) {
case 'str':
// 字符串验证 - 只要数据类型是字符串即可
return is_string($data);
case 'num':
// 数字验证 - 接受数字、数字字符串、小数和小数字符串
// 注意:布尔值、科学计数法等也会被 is_numeric 认为是数字
return is_numeric($data);
case 'intnum':
// 整数验证 - 必须是整型或纯整数字符串
// 使用 filter_var 同时验证整型和整数字符串
return filter_var($data, FILTER_VALIDATE_INT) !== false;
case 'datetime':
// 日期时间验证 - 保持原有逻辑不变
$formats = ['Y-m-d', 'Y-m-d H:i:s'];
foreach ($formats as $format) {
$dateTime = \DateTime::createFromFormat($format, $data);
if ($dateTime && $dateTime->format($format) === $data) {
return true;
}
}
return false;
default:
throw new \InvalidArgumentException("未知的验证类型: {$type}");
}
}
// 处理身高体重的单位转换它们为cm和kg。
public function convertHeightAndWeight($height, $weight) {
// 加 bcadd(,,20)
// 减 bcsub(,,20)
// 乘 bcmul(,,20)
// 除 bcdiv(,,20)
// 定义单位转换比例
$heightConversion = [
'cm' => 1,
'inch' => 2.54,
'ft-in' => function($value) {
list($ft, $in) = explode('-', $value);
return $ft * 30.48 + $in * 2.54; // 1 foot = 30.48 cm, 1 inch = 2.54 cm
}
];
$weightConversion = [
'kg' => 1,
'斤' => 0.5, // 1斤 = 0.5kg
'st:lb' => function($value) {
list($st, $lb) = explode(':', $value);
return $st * 6.35029318 + $lb * 0.45359237; // 1 stone = 6.35029318 kg, 1 lb = 0.45359237 kg
},
'lb' => 0.45359237 // 1 lb = 0.45359237 kg
];
// 处理 height
if (preg_match('/([\d.]+)(cm|inch|ft-in)/', $height, $matches)) {
// $heightValue = floatval($matches[1]);
$heightValue = $matches[1];
$heightUnit = $matches[2];
if($heightUnit == 'ft-in'){
// 如果单位为st:lb但是数据格式不对
$heightValue = str_replace($heightUnit, "", $height);
if(count(explode('-', $heightValue)) < 2){
$heightValue = str_replace("-", "", $heightValue);
$heightValue = $heightValue."-0";
}
}
if (isset($heightConversion[$heightUnit])) {
if (is_callable($heightConversion[$heightUnit])) {
$heightInCm = $heightConversion[$heightUnit]($heightValue);
} else {
$heightInCm = $heightValue * $heightConversion[$heightUnit];
}
} else {
// 未知单位,返回错误
$heightInCm = false;
}
} else {
// 未找到指定单位判断是否是数字
if (preg_match('/^-?\d+(\.\d+)?$/', $height)) {
$heightInCm = $height;
} else {
$heightInCm = false;
}
}
// 处理 weight
if (preg_match('/([\d.:]+)(kg|斤|st:lb|lb)/', $weight, $matches)) {
$weightValue = $matches[1];
$weightUnit = $matches[2];
if($weightUnit == 'st:lb'){
// 如果单位为st:lb但是数据格式不对
$weightValue = str_replace($weightUnit, "", $weight);
if(count(explode(':', $weightValue)) < 2){
$weightValue = str_replace(":", "", $weightValue);
$weightValue = $weightValue.":0";
}
}
if (isset($weightConversion[$weightUnit])) {
if (is_callable($weightConversion[$weightUnit])) {
$weightInKg = $weightConversion[$weightUnit]($weightValue);
} else {
$weightInKg = $weightValue * $weightConversion[$weightUnit];
}
} else {
// 未知单位,返回错误
$weightInKg = false;
}
} else {
// 未找到指定单位判断是否是数字
if (preg_match('/^-?\d+(\.\d+)?$/', $weight)) {
$weightInKg = $weight;
} else {
$weightInKg = false;
}
}
return [
'height_in_cm' => bcmul($heightInCm,1,2),
'weight_in_kg' => bcmul($weightInKg,1,2)
];
}
public function ceshiyong($aa = 4,$gd = 0.2){
phpinfo();
die;
$token = 'cd3f27cf4c4002170ea7bceeb723ac91';
$data = Db::table('pc_bmistand2')->select();
for ($i=0; $i < count($data); $i++) {
foreach ($data[$i] as $key => $value) {
$data[$i][$key] = str_replace(' ', '',$data[$i][$key]);
}
Db::table('pc_bmistand2')->where(['id'=>$data[$i]['id']])->update([
'month'=>$data[$i]['month'],
'sex'=>$data[$i]['sex'],
// 'f3sd'=>$data[$i]['f3sd'],
// 'f2sd'=>$data[$i]['f2sd'],
'f1sd'=>$data[$i]['f1sd'],
'median'=>$data[$i]['median'],
'z1sd'=>$data[$i]['z1sd'],
'z2sd'=>$data[$i]['z2sd'],
// 'z3sd'=>$data[$i]['z3sd'],
]);
}
die;
// $this->send_email_api_error(["tsf3920322@126.com"],['title'=>'接口报错','from_user_name'=>'青测API','content'=>'123']);
}
}

View File

@ -0,0 +1,667 @@
<?php
namespace app\NewReedaw\controller\app;
use think\Controller;
use think\Db;
use think\Cache;
use think\Log;
use PHPMailer\PHPMailer\PHPMailer;
use app\NewReedaw\controller\app\Cardparts;
class Body extends Base{
protected $body_db_name = [
'zhanghao'=>'app_account_number',
'juese'=>'app_user_data',
'body_data'=>'app_card_body_data',
'bmi'=>'pc_bmistand',
'heigh'=>'pc_heightstand',
'weigh'=>'pc_weightstand',
'chufang1'=>'pc_childrenprescription',
'chufang2'=>'pc_childprescriptionbyage',
];
protected $result_end_data_mould = [
'name'=>'',
'value'=>'',
'unit'=>'',
'standard'=>'',
'color'=>'',
'list'=>[]
];
protected $age_limit = 16;
protected $unit_name = ['score'=>'身体得分','height'=>'身高','weight'=>'体重','bmi'=>'BMI','fat_r'=>'脂肪率','fat_w'=>'脂肪量','muscle'=>'肌肉率','muscleval'=>'肌肉量','water'=>'水分','bone'=>'骨重','protein'=>'蛋白率','proteinval'=>'蛋白量','kcal'=>'基础代谢','visceral'=>'内脏指数','sfr'=>'皮下脂肪','body_level'=>'肥胖等级','body_type'=>'身体类型'];
protected $unit_symbol = ['score'=>'分','height'=>'CM','weight'=>'公斤','bmi'=>'','fat_r'=>'%','fat_w'=>'kg','muscle'=>'%','muscleval'=>'kg','water'=>'kg','bone'=>'kg','protein'=>'%','proteinval'=>'kg','kcal'=>'kcal','visceral'=>'','sfr'=>'%',];
protected $standard_color = [
'fat_r'=>['偏低'=>'#FCDB67','标准'=>'#58D268','偏高'=>'#FCAA00','高'=>'#FD5752'],
'fat_w'=>['偏低'=>'#FCDB67','标准'=>'#58D268','偏高'=>'#FCAA00','高'=>'#FD5752'],
'muscle'=>['不足'=>'#FFDA68','标准'=>'#59CD6F','优'=>'#3C64D4'],
'muscleval'=>['不足'=>'#FFDA68','标准'=>'#59CD6F','优'=>'#3C64D4'],
'water'=>['不足'=>'#FED966','标准'=>'#58CF6B','优'=>'#3A68D7'],
'proteinval'=>['不足'=>'#FED966','标准'=>'#58CF6B','优'=>'#3A68D7'],
'bone'=>['不足'=>'#FED966','标准'=>'#58CF6B','优'=>'#3A68D7'],
'protein'=>['不足'=>'#FED966','标准'=>'#58CF6B','优'=>'#3A68D7'],
'kcal'=>['偏低'=>'#FF5656','优'=>'#3A68D4'],
'visceral'=>['标准'=>'#55CF6C','警惕'=>'#FEAC00','危险'=>'#FB5A52'],
'sfr'=>['不足'=>'#FCDB68','标准'=>'#59D16F','偏高'=>'#FEAB03'],
];
protected $bhw_list = [
'bmi'=>[
['min_val'=>'0','max_val'=>'','text'=>'消瘦','color'=>'#FDDA6B'],
['min_val'=>'','max_val'=>'','text'=>'正常','color'=>'#59D06A'],
['min_val'=>'','max_val'=>'','text'=>'偏重','color'=>'#FDAA02'],
['min_val'=>'','max_val'=>'50','text'=>'肥胖','color'=>'#FB5755'],
],
'height'=>[
['min_val'=>'0','max_val'=>'','text'=>'矮','color'=>'#FD5759'],
['min_val'=>'','max_val'=>'','text'=>'偏矮','color'=>'#FAAD01'],
['min_val'=>'','max_val'=>'','text'=>'标准','color'=>'#5BD068'],
['min_val'=>'','max_val'=>'','text'=>'偏高','color'=>'#6793F4'],
['min_val'=>'','max_val'=>'','text'=>'高','color'=>'#3D67D3'],
],
'weight'=>[
['min_val'=>'0','max_val'=>'','text'=>'低','color'=>'#F8595D'],
['min_val'=>'','max_val'=>'','text'=>'偏低','color'=>'#FFAF04'],
['min_val'=>'','max_val'=>'','text'=>'标准','color'=>'#59D168'],
['min_val'=>'','max_val'=>'','text'=>'偏高','color'=>'#FFAF04'],
['min_val'=>'','max_val'=>'','text'=>'高','color'=>'#F8595D'],
]
];
protected $card_body_level = [
'height'=>['value'=>1,'list'=>['矮'=>2,'偏矮'=>3,'标准'=>4,'偏高'=>5,'高'=>5]],
'weight'=>['value'=>3,'list'=>['低'=>1,'偏低'=>1,'标准'=>2,'偏高'=>3,'高'=>3]],
'bmi'=>['value'=>2,'list'=>['消瘦'=>1,'正常'=>2,'偏重'=>3,'肥胖'=>4]],
];
// 加 bcadd(,,20)
// 减 bcsub(,,20)
// 乘 bcmul(,,20)
// 除 bcdiv(,,20)
// 测试token=>'caadd1be045a65f30b92aa805f1de54a'
################################################################接口################################################################
################################################################接口################################################################
################################################################接口################################################################
// 获取角色报告
public function body_report(){
// phpinfo();
// die;
// try {
$data = input('post.');
if(!array_key_exists('token', $data) || !array_key_exists('aud_id', $data)){
return $this->msg(10001);
}
if(!$this->verify_data_is_ok($data['token'],'str')){
return $this->msg(10005,'token type error');
}
if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
return $this->msg(10005,'aud_id type error');
}
return $this->body_report_action_detailed($data);
// } catch (\Exception $e) {
// // 捕获异常
// $logContent["flie"] = $e->getFile();
// $logContent["line"] = $e->getLine();
// $logContent['all_content'] = "异常信息:\n";
// $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
// $logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
// $logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
// $logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
// $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
// $this->record_api_log($data, $logContent, null);
// return $this->msg(99999);
// }
}
################################################################action################################################################
################################################################action################################################################
public function body_report_action_detailed($data){
$result_return = [
"score_name"=>"",
"score_value"=>"",
"score_unit"=>"",
"body_type_name"=>"",
"body_type_value"=>"",
"body_type_unit"=>"",
"record_time"=>"",
'top_list'=>[
[
"name"=>"体重",
"value"=>"0",
"unit"=>"公斤",
"standard"=>"",
"color"=>"",
"list"=>[],
"key_name"=>"weight",
"desc"=>"反映和衡量一个人健康状况的重要标志之一",
"offset"=>"0",
"standard_val"=>"",
"difference_val"=>"",
],
[
"name"=>"身高",
"value"=>"0",
"unit"=>"CM",
"standard"=>"",
"color"=>"",
"list"=>[],
"key_name"=>"height",
"desc"=>"人体纵向部分的长度,源于人体的纵向生长,受遗传因素的影响较大",
"offset"=>"0",
"standard_val"=>"",
"difference_val"=>"",
],
[
"name"=>"BMI",
"value"=>"0",
"unit"=>"公斤",
"standard"=>"",
"color"=>"",
"list"=>[],
"key_name"=>"bmi",
"desc"=>"BMI是身体质量指数,是目前国际上常用的衡量人体胖瘦程度以及是否健康的一个标准。",
"offset"=>"0",
"standard_val"=>"",
"difference_val"=>"",
],
],
'bottom_list' => [],
'cplist'=>[
'nutritionlist'=>[],
'sportlist'=>[],
'sleeplist'=>[],
'moodlist'=>[],
],
'target_current'=>[
'target_weight'=>'0',
'initial_weight'=>'0',
'cumulative_weight'=>'0',
'cumulative_day'=>'0'
],
];
$body_last_data = Db::query("
select
Top 1
acbd.id,
acbd.acd_id,
acbd.record_type,
acbd.create_time,
acbd.last_update_time,
acbd.score,
acbd.fat_r,
acbd.fat_w,
acbd.muscle,
acbd.muscleval,
acbd.water,
acbd.proteinval,
acbd.bone,
acbd.protein,
acbd.kcal,
acbd.visceral,
acbd.sfr,
acbd.body_level,
acbd.aud_id,
acbd.record_time,
acbd.body_type,
acbd.age,
acbd.is_del,
acbd.height,
acbd.height_val,
acbd.weight,
acbd.weight_val,
acbd.bmi,
acbd.body_age,
acbd.head_circumference,
aud.birthday,aud.gender,aud.target_weight,aud.initial_weight,aud.initial_date
from ".$this->body_db_name['body_data']." as acbd
left join ".$this->body_db_name['juese']." as aud on acbd.aud_id=aud.id
where acbd.is_del=0 and acbd.aud_id='".$data['aud_id']."'
order by acbd.record_time desc
");
// return $this->msg($body_last_data);
if(count($body_last_data) <= 0){
return $this->msg($result_return);
}
// 暂时存储头围数据
$head_circumference = $body_last_data[0]['head_circumference']?json_decode($body_last_data[0]['head_circumference'],true):false;
unset($body_last_data[0]['head_circumference']);
// 处理返回数据
$result_end = $this->processing_return_data_new($body_last_data[0]);
$cardparts = new Cardparts;
$result_end['gender'] = $body_last_data[0]['gender'];
$result_end['record_time'] = $body_last_data[0]['record_time'];
$result_end['score'] = $result_end['score'];
$result_end['body_type'] = $result_end['body_type'];
$result_end = $cardparts->conversion_interval($result_end);
$result_end['cplist'] = $this->grow_up_recommendation([
'birthday'=>$body_last_data[0]['birthday'],
'body'=>[
'height'=>$body_last_data[0]['height'],
'weight'=>$body_last_data[0]['weight'],
'bmi'=>$body_last_data[0]['bmi']
],
]);
// // 加入曲线板块底部的减肥计划数据start
// $result_end['target_current'] = $this->base_target_initial_cumulative_weight([
// 'weight'=>$body_last_data[0]['weight']>0?$body_last_data[0]['weight']:0,
// 'target_weight'=>$body_last_data[0]['target_weight']>0?$body_last_data[0]['target_weight']:0,
// 'initial_weight'=>$body_last_data[0]['initial_weight']>0?$body_last_data[0]['initial_weight']:0,
// 'initial_date'=>$body_last_data[0]['initial_date']!=null?$body_last_data[0]['initial_date']:0,
// ]);
// // dump($result_end);
// if(count($result_end['top_list'][2]['list']) <= 0){
// // 这是16岁以上人群
// $data = [
// 'height'=>$body_last_data[0]['height_val'],
// 'weight'=>$body_last_data[0]['weight_val'],
// 'birthday'=>$body_last_data[0]['birthday'],
// 'sex'=>$body_last_data[0]['gender']
// ];
// $temporary_arr_bmi_list = $this->card_bmi_evaluation($data,true);
// $temporary_arr_bmi_list = $temporary_arr_bmi_list->getData();
// if($temporary_arr_bmi_list['code'] == 0){
// $result_end['top_list'][2]['standard'] = $temporary_arr_bmi_list['data']['bmilevel'];
// $result_end['top_list'][2]['color'] = $temporary_arr_bmi_list['data']['bmilevelcolor'];
// $result_end['top_list'][2]['list'] = $temporary_arr_bmi_list['data']['bmilevellist'];
// $result_end['top_list'][2]['offset'] = $temporary_arr_bmi_list['data']['offset'];
// }
// // dump($result_end);
// // die;
// }
// 添加头围数据如果有的话start
if($head_circumference !== false && $this->calculate_age($body_last_data[0]['birthday']) < 3){
if($head_circumference['level'] == '异常' || $head_circumference['value'] == 0){
$offset = 0;
}else{
$offset = $cardparts->calculate_landing_point($head_circumference['list2'],$head_circumference['value'],$head_circumference['level']);
}
$touwei_array = [
'name'=>'头围',
'value'=>$head_circumference['value'],
'unit'=>'CM',
'standard'=>$head_circumference['level'],
'color'=>'',
'list'=>$head_circumference['list2'],
'key_name'=>'head_circumference',
'desc'=>'头围是指绕头部一周的最大长度,头围的大小与脑的发育密切相关',
'offset'=>$offset
];
$touwei_data = $this->touwei_temporary_use($body_last_data[0]['birthday'],$body_last_data[0]['gender']);
if(count($touwei_data)){
$touwei_array['standard_val'] = $touwei_data['middle'];
$touwei_array['difference_val'] = bcsub($touwei_array['value'],$touwei_data['middle'],2);
}else{
$touwei_array['standard_val'] = '';
$touwei_array['difference_val'] = '';
}
array_push($result_end['top_list'],$touwei_array);
}
// 添加头围数据如果有的话end
// 这段业务处理可以删除是做的临时的假的start
$biaozhun_val = $this->body_temporary_use($body_last_data[0]['birthday'],$body_last_data[0]['gender']);
// dump($biaozhun_val);
// $biaozhun_val_weight = 50;
// $biaozhun_val_height = 170;
// $biaozhun_val_bmi = 22;
foreach ($result_end['top_list'] as $key => $value) {
if($value['key_name'] == 'weight'){
if($biaozhun_val['weight'] == ''){
$result_end['top_list'][$key]['standard_val'] = '';
$result_end['top_list'][$key]['difference_val'] = '';
}else{
$result_end['top_list'][$key]['standard_val'] = $biaozhun_val['weight'];
$result_end['top_list'][$key]['difference_val'] = bcsub($value['value'],$biaozhun_val['weight'],2);
}
}else if($value['key_name'] == 'height'){
if($biaozhun_val['height'] == ''){
$result_end['top_list'][$key]['standard_val'] = '';
$result_end['top_list'][$key]['difference_val'] = '';
}else{
$result_end['top_list'][$key]['standard_val'] = $biaozhun_val['height'];
$result_end['top_list'][$key]['difference_val'] = bcsub($value['value'],$biaozhun_val['height'],2);
}
}else if($value['key_name'] == 'bmi'){
if($biaozhun_val['bmi'] == ''){
$result_end['top_list'][$key]['standard_val'] = '';
$result_end['top_list'][$key]['difference_val'] = '';
}else{
$result_end['top_list'][$key]['standard_val'] = $biaozhun_val['bmi'];
$result_end['top_list'][$key]['difference_val'] = bcsub($value['value'],$biaozhun_val['bmi'],2);
}
}
}
// 这段业务处理可以删除是做的临时的假的end
return $this->msg($result_end);
// dump($result_end);
}
public function processing_return_data_new($data){
$result_end_data = [];
$month_num = $this->calculateAgeInMonthsWithPrecision($data['birthday']);
$gender_val = $data['gender'];
foreach ($data as $key => $value) {
if($key != 'aud_id' && $key != 'id' && $key != 'create_time' && $key != 'last_update_time' && $key != 'acd_id' && $key != 'ROW_NUMBER' && $key != 'record_time' && $key != 'gender' && $key != 'birthday'){
// 设置单个数据格式
$result_end_data[$key] = $this->result_end_data_mould;
// 该项名
if(array_key_exists($key, $this->unit_name)){
$result_end_data[$key]['name'] = $this->unit_name[$key];
}
// 该项单位
if(array_key_exists($key, $this->unit_symbol)){
$result_end_data[$key]['unit'] = $this->unit_symbol[$key];
}
$result_end_data[$key]['value'] = explode(',',$value)[0];
if(strpos($value, ',')){
$result_end_data[$key]['standard'] = explode(',',$value)[1];
}
if(array_key_exists($key, $this->standard_color)){
if($result_end_data[$key]['standard'] != '异常' && $result_end_data[$key]['standard'] != ''){
$result_end_data[$key]['color'] = $this->standard_color[$key][$result_end_data[$key]['standard']];
}
}
// 如果小于16岁儿童
if($data['age'] < $this->age_limit){
if(array_key_exists($key, $this->bhw_list)){
$result_end_data[$key]['list'] = $this->bhw_list[$key];
if($key == 'bmi'){
$bhw_date = Db::table($this->body_db_name['bmi'])->where("Month <= $month_num and Sex = '$gender_val'")->order('Month desc')->limit(1)->select();
if($bhw_date){
$result_end_data[$key]['list'][0]['max_val'] = $bhw_date[0]['f1sd'];
$result_end_data[$key]['list'][1]['min_val'] = $bhw_date[0]['f1sd'];
$result_end_data[$key]['list'][1]['max_val'] = $bhw_date[0]['z1sd'];
$result_end_data[$key]['list'][2]['min_val'] = $bhw_date[0]['z1sd'];
$result_end_data[$key]['list'][2]['max_val'] = $bhw_date[0]['z2sd'];
$result_end_data[$key]['list'][3]['min_val'] = $bhw_date[0]['z2sd'];
}
}else if($key == 'height'){
$bhw_date = Db::table($this->body_db_name['heigh'])->where("Month <= $month_num and Sex = '$gender_val'")->order('Month desc')->limit(1)->select();
if($bhw_date){
$result_end_data[$key]['list'][0]['max_val'] = $bhw_date[0]['f2sd'];
$result_end_data[$key]['list'][1]['min_val'] = $bhw_date[0]['f2sd'];
$result_end_data[$key]['list'][1]['max_val'] = $bhw_date[0]['f1sd'];
$result_end_data[$key]['list'][2]['min_val'] = $bhw_date[0]['f1sd'];
$result_end_data[$key]['list'][2]['max_val'] = $bhw_date[0]['z1sd'];
$result_end_data[$key]['list'][3]['min_val'] = $bhw_date[0]['z1sd'];
$result_end_data[$key]['list'][3]['max_val'] = $bhw_date[0]['z2sd'];
$result_end_data[$key]['list'][4]['min_val'] = $bhw_date[0]['z2sd'];
$result_end_data[$key]['list'][4]['max_val'] = $bhw_date[0]['z3sd'];
}
}else if($key == 'weight'){
$bhw_date = Db::table($this->body_db_name['weigh'])->where("Month <= $month_num and Sex = '$gender_val'")->order('Month desc')->limit(1)->select();
if($bhw_date){
$result_end_data[$key]['list'][0]['max_val'] = $bhw_date[0]['f2sd'];
$result_end_data[$key]['list'][1]['min_val'] = $bhw_date[0]['f2sd'];
$result_end_data[$key]['list'][1]['max_val'] = $bhw_date[0]['f1sd'];
$result_end_data[$key]['list'][2]['min_val'] = $bhw_date[0]['f1sd'];
$result_end_data[$key]['list'][2]['max_val'] = $bhw_date[0]['z1sd'];
$result_end_data[$key]['list'][3]['min_val'] = $bhw_date[0]['z1sd'];
$result_end_data[$key]['list'][3]['max_val'] = $bhw_date[0]['z2sd'];
$result_end_data[$key]['list'][4]['min_val'] = $bhw_date[0]['z2sd'];
$result_end_data[$key]['list'][4]['max_val'] = $bhw_date[0]['z3sd'];
}
}
}
}
}
}
return $result_end_data;
}
public function grow_up_recommendation($data){
// card_body_level
// die;
// $result = [
// ['name'=>'营养','key'=>'nutrition','content'=>''],
// ['name'=>'睡眠','key'=>'sleep','content'=>''],
// ['name'=>'运动','key'=>'motion','content'=>''],
// ['name'=>'情绪','key'=>'emotion','content'=>'']
// ];
$result = [
'nutritionlist'=>[],//营养
'sportlist'=>[],//运动
'sleeplist'=>[],//睡眠
'moodlist'=>[],//情绪
];
$temporary_arr = [];
foreach ($data['body'] as $key => $value) {
if(explode(',',$value)[1] == '无'){
$result = [
'nutritionlist'=>[],//营养
'sportlist'=>[],//运动
'sleeplist'=>[],//睡眠
'moodlist'=>[],//情绪
];
return $result;
}
$temporary_arr[$key] = $this->card_body_level[$key]['list'][explode(',',$value)[1]];
}
$min_value = min($temporary_arr);
$min_key = array_search($min_value,$temporary_arr);
$type_num = $this->card_body_level[$min_key]['value'];
$temporary_arr2 = Db::table($this->body_db_name['chufang1'])->where(['Type'=>$type_num,'Level'=>$min_value,'IsDeleted'=>0])->field('Nutrition,Sport')->find();
// dump($temporary_arr2);
array_push($result['nutritionlist'],$temporary_arr2['Nutrition']);
array_push($result['sportlist'],$temporary_arr2['Sport']);
// $result['nutritionlist'] = $temporary_arr2['Nutrition'];
// $result['sportlist'] = $temporary_arr2['Sport'];
$month_num = $this->calculateAgeInMonthsWithPrecision($data['birthday']);
$temporary_arr2 = Db::table($this->body_db_name['chufang2'])->where(['IsDeleted'=>0])->field('MinAge,MaxAge,Type,Content')->select();
$default_sleep = '';
$default_emotion = '';
foreach ($temporary_arr2 as $key => $value) {
if($value['MinAge'] == -1 && $value['Type'] == 2){
$default_sleep = $value['Content'];
}
if($value['MinAge'] == -1 && $value['Type'] == 3){
$default_emotion = $value['Content'];
}
if($month_num>=$value['MinAge'] && $month_num<=$value['MaxAge']){
if($value['Type'] == 1){
array_push($result['sportlist'],$value['Content']);
// $result['sportlist'] = $result['sportlist'].$value['Content'];
}else if($value['Type'] == 2){
array_push($result['sleeplist'],$value['Content']);
// $result['sleeplist'] = $result['sleeplist'].$value['Content'];
}else if($value['Type'] == 3){
array_push($result['moodlist'],$value['Content']);
// $result['moodlist'] = $result['moodlist'].$value['Content'];
}
}
}
$result['sleeplist'] = count($result['sleeplist']) <= 0?array_push($result['sportlist'],$default_sleep):$result['sleeplist'];
$result['moodlist'] = count($result['moodlist']) <= 0?array_push($result['moodlist'],$default_sleep):$result['moodlist'];
return $result;
}
public function touwei_temporary_use($age,$gender){
$return_data = [
];
if(!in_array($gender,['1','2'])){
return $return_data;
}
$age_m = $this->calculateAgeInMonthsWithPrecision($age);
if($age_m <= 36){
// $touwei_date = Db::table('ws_touwei')->where("age <= $age_m and gender = '$gender'")->order('age desc')->limit(1)->field('middle')->fetchSql(true)->select();
$touwei_date = Db::query("select * from ws_touwei where age <= $age_m and gender = '$gender' order by age desc");
$return_data = $touwei_date[0];
}
return $return_data;
}
public function body_temporary_use($age,$gender){
$return_data = [
'height'=>'',
'weight'=>'',
'bmi'=>'',
];
if(!in_array($gender,['1','2'])){
return $return_data;
}
$age_m = $this->calculateAgeInMonthsWithPrecision($age);
if($age_m < 228){//月龄小于19岁
// dump($age_m);
// $height_date = Db::table('ws_height')->where("age <= $age_m and gender = '$gender'")->order('age desc')->limit(1)->field('middle')->select();
$height_date = Db::query("select * from ws_height where age <= $age_m and gender = '$gender' order by age desc");
// $weight_date = Db::table('ws_weight')->where("age <= $month_num and Sex = '$gender'")->order('age desc')->limit(1)->field('middle')->select();
$weight_date = Db::query("select * from ws_weight where age <= $age_m and gender = '$gender' order by age desc");
// $bmi_date = Db::table('ws_bmi')->where("age <= $month_num and Sex = '$gender'")->order('age desc')->limit(1)->field('middle')->select();
$bmi_date = Db::query("select * from ws_bmi where age <= $age_m and gender = '$gender' order by age desc");
$return_data = array(
'height' => $height_date[0]['middle'],
'weight' => $weight_date[0]['middle'],
'bmi' => $bmi_date[0]['middle'],
);
}else{
$bmi_data = [
'1' => [ // 男性
[
'age' => ['min' => 216, 'max' => 299], // 18-24岁216-299月龄
'list'=>[
['min_val' => '0', 'max_val' => '18.5', 'text' => '低体重', 'color' => '#8BC8FB'],
['min_val' => '18.5', 'max_val' => '20.4', 'text' => '偏瘦', 'color' => '#B4E3FD'],
['min_val' => '20.5', 'max_val' => '23.9', 'text' => '正常', 'color' => '#6CD86F'],
['min_val' => '24.0', 'max_val' => '27.9', 'text' => '超重', 'color' => '#FFD166'],
['min_val' => '28.0', 'max_val' => '31.9', 'text' => '肥胖', 'color' => '#FF9A5A'],
['min_val' => '32.0', 'max_val' => '99999', 'text' => '重度肥胖', 'color' => '#FF6B6B']
]
],
[
'age' => ['min' => 300, 'max' => 419], // 25-34岁300-419月龄
'list'=>[
['min_val' => '0', 'max_val' => '18.5', 'text' => '低体重', 'color' => '#8BC8FB'],
['min_val' => '18.5', 'max_val' => '20.9', 'text' => '偏瘦', 'color' => '#B4E3FD'],
['min_val' => '21.0', 'max_val' => '24.4', 'text' => '正常', 'color' => '#6CD86F'],
['min_val' => '24.5', 'max_val' => '28.4', 'text' => '超重', 'color' => '#FFD166'],
['min_val' => '28.5', 'max_val' => '32.4', 'text' => '肥胖', 'color' => '#FF9A5A'],
['min_val' => '32.5', 'max_val' => '99999', 'text' => '重度肥胖', 'color' => '#FF6B6B']
]
],
[
'age' => ['min' => 420, 'max' => 539], // 35-44岁420-539月龄
'list'=>[
['min_val' => '0', 'max_val' => '18.5', 'text' => '低体重', 'color' => '#8BC8FB'],
['min_val' => '18.5', 'max_val' => '21.4', 'text' => '偏瘦', 'color' => '#B4E3FD'],
['min_val' => '21.5', 'max_val' => '25.0', 'text' => '正常', 'color' => '#6CD86F'],
['min_val' => '25.1', 'max_val' => '29.0', 'text' => '超重', 'color' => '#FFD166'],
['min_val' => '29.1', 'max_val' => '33.0', 'text' => '肥胖', 'color' => '#FF9A5A'],
['min_val' => '33.1', 'max_val' => '99999', 'text' => '重度肥胖', 'color' => '#FF6B6B']
]
],
[
'age' => ['min' => 540, 'max' => 719], // 45-59岁540-719月龄
'list'=>[
['min_val' => '0', 'max_val' => '18.5', 'text' => '低体重', 'color' => '#8BC8FB'],
['min_val' => '18.5', 'max_val' => '21.9', 'text' => '偏瘦', 'color' => '#B4E3FD'],
['min_val' => '22.0', 'max_val' => '25.5', 'text' => '正常', 'color' => '#6CD86F'],
['min_val' => '25.6', 'max_val' => '29.5', 'text' => '超重', 'color' => '#FFD166'],
['min_val' => '29.6', 'max_val' => '33.5', 'text' => '肥胖', 'color' => '#FF9A5A'],
['min_val' => '33.6', 'max_val' => '99999', 'text' => '重度肥胖', 'color' => '#FF6B6B']
]
],
[
'age' => ['min' => 720, 'max' => '99999'], // ≥60岁720+月龄)
'list'=>[
['min_val' => '0', 'max_val' => '18.5', 'text' => '低体重', 'color' => '#8BC8FB'],
['min_val' => '18.5', 'max_val' => '22.4', 'text' => '偏瘦', 'color' => '#B4E3FD'],
['min_val' => '22.5', 'max_val' => '26.0', 'text' => '正常', 'color' => '#6CD86F'],
['min_val' => '26.1', 'max_val' => '29.0', 'text' => '超重', 'color' => '#FFD166'],
['min_val' => '29.1', 'max_val' => '33.0', 'text' => '肥胖', 'color' => '#FF9A5A'],
['min_val' => '33.1', 'max_val' => '99999', 'text' => '重度肥胖', 'color' => '#FF6B6B']
]
]
],
'2' => [ // 女性
[
'age' => ['min' => 216, 'max' => 299], // 18-24岁
'list'=>[
['min_val' => '0', 'max_val' => '18.0', 'text' => '低体重', 'color' => '#8BC8FB'],
['min_val' => '18.0', 'max_val' => '19.9', 'text' => '偏瘦', 'color' => '#B4E3FD'],
['min_val' => '20.0', 'max_val' => '22.9', 'text' => '正常', 'color' => '#6CD86F'],
['min_val' => '23.0', 'max_val' => '26.9', 'text' => '超重', 'color' => '#FFD166'],
['min_val' => '27.0', 'max_val' => '30.9', 'text' => '肥胖', 'color' => '#FF9A5A'],
['min_val' => '31.0', 'max_val' => '99999', 'text' => '重度肥胖', 'color' => '#FF6B6B']
]
],
[
'age' => ['min' => 300, 'max' => 419], // 25-34岁
'list'=>[
['min_val' => '0', 'max_val' => '18.0', 'text' => '低体重', 'color' => '#8BC8FB'],
['min_val' => '18.0', 'max_val' => '20.4', 'text' => '偏瘦', 'color' => '#B4E3FD'],
['min_val' => '20.5', 'max_val' => '23.4', 'text' => '正常', 'color' => '#6CD86F'],
['min_val' => '23.5', 'max_val' => '27.4', 'text' => '超重', 'color' => '#FFD166'],
['min_val' => '27.5', 'max_val' => '31.4', 'text' => '肥胖', 'color' => '#FF9A5A'],
['min_val' => '31.5', 'max_val' => '99999', 'text' => '重度肥胖', 'color' => '#FF6B6B']
]
],
[
'age' => ['min' => 420, 'max' => 539], // 35-44岁
'list'=>[
['min_val' => '0', 'max_val' => '18.0', 'text' => '低体重', 'color' => '#8BC8FB'],
['min_val' => '18.0', 'max_val' => '20.9', 'text' => '偏瘦', 'color' => '#B4E3FD'],
['min_val' => '21.0', 'max_val' => '24.0', 'text' => '正常', 'color' => '#6CD86F'],
['min_val' => '24.1', 'max_val' => '28.0', 'text' => '超重', 'color' => '#FFD166'],
['min_val' => '28.1', 'max_val' => '32.0', 'text' => '肥胖', 'color' => '#FF9A5A'],
['min_val' => '32.1', 'max_val' => '99999', 'text' => '重度肥胖', 'color' => '#FF6B6B']
]
],
[
'age' => ['min' => 540, 'max' => 719], // 45-59岁
'list'=>[
['min_val' => '0', 'max_val' => '18.0', 'text' => '低体重', 'color' => '#8BC8FB'],
['min_val' => '18.0', 'max_val' => '21.4', 'text' => '偏瘦', 'color' => '#B4E3FD'],
['min_val' => '21.5', 'max_val' => '24.5', 'text' => '正常', 'color' => '#6CD86F'],
['min_val' => '24.6', 'max_val' => '28.5', 'text' => '超重', 'color' => '#FFD166'],
['min_val' => '28.6', 'max_val' => '32.5', 'text' => '肥胖', 'color' => '#FF9A5A'],
['min_val' => '32.6', 'max_val' => '99999', 'text' => '重度肥胖', 'color' => '#FF6B6B']
]
],
[
'age' => ['min' => 720, 'max' => 99999], // ≥60岁
'list'=>[
['min_val' => '0', 'max_val' => '18.0', 'text' => '低体重', 'color' => '#8BC8FB'],
['min_val' => '18.0', 'max_val' => '21.9', 'text' => '偏瘦', 'color' => '#B4E3FD'],
['min_val' => '22.0', 'max_val' => '25.0', 'text' => '正常', 'color' => '#6CD86F'],
['min_val' => '25.1', 'max_val' => '28.0', 'text' => '超重', 'color' => '#FFD166'],
['min_val' => '28.1', 'max_val' => '32.0', 'text' => '肥胖', 'color' => '#FF9A5A'],
['min_val' => '32.1', 'max_val' => '99999', 'text' => '重度肥胖', 'color' => '#FF6B6B']
]
]
]
];
foreach ($bmi_data[$gender] as $group) {
if ($age_m >= $group['age']['min'] && $age_m <= $group['age']['max']) {
$return_data['bmi'] = bcdiv(bcadd($group['list'][2]['min_val'],$group['list'][2]['max_val'],20),2,1);
}
}
}
return $return_data;
}
// public function body_report_action_detailed($data){
// }
}

View File

@ -0,0 +1,487 @@
<?php
namespace app\NewReedaw\controller\app;
class Cardparts extends Base{
protected $color = ['#FF5656','#FFAB00','#5AD06D','#6492F6','#3967D6'];
protected $parameter_aggregate_top = [
'weight'=>'反映和衡量一个人健康状况的重要标志之一',
'height'=>'人体纵向部分的长度,源于人体的纵向生长,受遗传因素的影响较大',
'bmi'=>'BMI是身体质量指数,是目前国际上常用的衡量人体胖瘦程度以及是否健康的一个标准。'
];
protected $parameter_aggregate_bottom = [
'fat_r'=>'体脂率是指身体成分中,脂肪组织所占的比率。测量体脂率比单纯的只测量体重更能反映我们身体的脂肪水平(肥胖程度)。',
'fat_w'=>'人体脂肪的重量',
'muscle'=>'根据人体肌肉总量和人体体重、身高等相结合得到的人体的一个比例值,这个值的范围决定一个人的身体健康状况以及力量的多少。',
'muscleval'=>'肌肉量=实际体重*肌肉率',
'water'=>'指人体内水分比例。',
'proteinval'=>'蛋白量=实际体重*蛋白率',
'bone'=>'单位体积内,骨组织、骨矿物质(钙、磷等)和骨基质(骨胶原、蛋白率、无机盐等等)含量,骨量代表它们骨骼健康的情况。',
'protein'=>'人体内蛋白率含量。',
'kcal'=>'指人体在清醒而又极端安静的状态下,不受肌肉活动、环境温度、食物及精神紧张等影响时的能量代谢率',
'visceral'=>'内脏脂肪指数',
'sfr'=>'皮下脂脂肪就是贮存于皮下的脂肪组织人体的脂肪大约有2/3贮存在皮下组织',
'body_level'=>'肥胖的程度,表现实际体重与理想体重的差距。肥胖等级是判定肥胖症的一个指标。'
];
protected $parameter_aggregate_bottom_out = ['body_level'];
protected $parameter_aggregate_bottom_condition = ['body_level'];
// 脂肪率&脂肪量
protected $fat_r_w = [
'man'=>[
'29'=>[
['min_val'=>'0','max_val'=>'10','text'=>'偏低','color'=>'#FCDB67'],
['min_val'=>'10','max_val'=>'21','text'=>'标准','color'=>'#59D16D'],
['min_val'=>'21','max_val'=>'26','text'=>'偏高','color'=>'#FAB000'],
['min_val'=>'26','max_val'=>'50','text'=>'高','color'=>'#FA5951'],
],
'30'=>[
['min_val'=>'0','max_val'=>'11','text'=>'偏低','color'=>'#FCDB67'],
['min_val'=>'11','max_val'=>'22','text'=>'标准','color'=>'#59D16D'],
['min_val'=>'22','max_val'=>'27','text'=>'偏高','color'=>'#FAB000'],
['min_val'=>'27','max_val'=>'50','text'=>'高','color'=>'#FA5951'],
],
],
'woman'=>[
'29'=>[
['min_val'=>'0','max_val'=>'20','text'=>'偏低','color'=>'#FCDB67'],
['min_val'=>'20','max_val'=>'31','text'=>'标准','color'=>'#59D16D'],
['min_val'=>'31','max_val'=>'38','text'=>'偏高','color'=>'#FAB000'],
['min_val'=>'38','max_val'=>'80','text'=>'高','color'=>'#FA5951'],
],
'30'=>[
['min_val'=>'0','max_val'=>'21','text'=>'偏低','color'=>'#FCDB67'],
['min_val'=>'21','max_val'=>'32','text'=>'标准','color'=>'#59D16D'],
['min_val'=>'32','max_val'=>'39','text'=>'偏高','color'=>'#FAB000'],
['min_val'=>'39','max_val'=>'80','text'=>'高','color'=>'#FA5951'],
]
]
];
// 肌肉率&肌肉量
protected $muscle_muscleval = [
'man'=>[
['min_val'=>'0','max_val'=>'40','text'=>'不足','color'=>'#FCDB67'],
['min_val'=>'40','max_val'=>'60','text'=>'标准','color'=>'#59D16D'],
['min_val'=>'60','max_val'=>'100','text'=>'优','color'=>'#3C66D2'],
],
'woman'=>[
['min_val'=>'0','max_val'=>'30','text'=>'不足','color'=>'#FCDB67'],
['min_val'=>'30','max_val'=>'50','text'=>'标准','color'=>'#59D16D'],
['min_val'=>'50','max_val'=>'100','text'=>'优','color'=>'#3C66D2'],
]
];
// 水分
protected $water = [
'man'=>[
['min_val'=>'0','max_val'=>'55','text'=>'不足','color'=>'#FCDB67'],
['min_val'=>'55','max_val'=>'65','text'=>'标准','color'=>'#59D16D'],
['min_val'=>'65','max_val'=>'100','text'=>'优','color'=>'#3C66D2'],
],
'woman'=>[
['min_val'=>'0','max_val'=>'45','text'=>'不足','color'=>'#FCDB67'],
['min_val'=>'45','max_val'=>'60','text'=>'标准','color'=>'#59D16D'],
['min_val'=>'60','max_val'=>'100','text'=>'优','color'=>'#3C66D2'],
]
];
// 蛋白量&蛋白率
protected $proteinval_protein = [
'man'=>[
['min_val'=>'0','max_val'=>'16','text'=>'不足','color'=>'#FCDB67'],
['min_val'=>'16','max_val'=>'18','text'=>'标准','color'=>'#59D16D'],
['min_val'=>'18','max_val'=>'50','text'=>'优','color'=>'#3C66D2'], //蓝
],
'woman'=>[
['min_val'=>'0','max_val'=>'14','text'=>'不足','color'=>'#FCDB67'],
['min_val'=>'14','max_val'=>'16','text'=>'标准','color'=>'#59D16D'],
['min_val'=>'16','max_val'=>'50','text'=>'优','color'=>'#3C66D2'],
]
];
// 骨重
protected $bone = [
'man'=>[
'60'=>[
['min_val'=>'0','max_val'=>'2.4','text'=>'不足','color'=>'#FCDB67'],
['min_val'=>'2.4','max_val'=>'2.6','text'=>'标准','color'=>'#59D16D'],
['min_val'=>'2.6','max_val'=>'6','text'=>'优','color'=>'#3C66D2'],
],
'60_75'=>[
['min_val'=>'0','max_val'=>'2.8','text'=>'不足','color'=>'#FCDB67'],
['min_val'=>'2.8','max_val'=>'3','text'=>'标准','color'=>'#59D16D'],
['min_val'=>'3','max_val'=>'6','text'=>'优','color'=>'#3C66D2'],
],
'75'=>[
['min_val'=>'0','max_val'=>'3.1','text'=>'不足','color'=>'#FCDB67'],
['min_val'=>'3.1','max_val'=>'3.3','text'=>'标准','color'=>'#59D16D'],
['min_val'=>'3.3','max_val'=>'7','text'=>'优','color'=>'#3C66D2'],
],
],
'woman'=>[
'45'=>[
['min_val'=>'0','max_val'=>'1.7','text'=>'不足','color'=>'#FCDB67'],
['min_val'=>'1.7','max_val'=>'1.9','text'=>'标准','color'=>'#59D16D'],
['min_val'=>'1.9','max_val'=>'5','text'=>'优','color'=>'#3C66D2'],
],
'45_60'=>[
['min_val'=>'0','max_val'=>'2.1','text'=>'不足','color'=>'#FCDB67'],
['min_val'=>'2.1','max_val'=>'2.3','text'=>'标准','color'=>'#59D16D'],
['min_val'=>'2.3','max_val'=>'5','text'=>'优','color'=>'#3C66D2'],
],
'60'=>[
['min_val'=>'0','max_val'=>'2.4','text'=>'不足','color'=>'#FCDB67'],
['min_val'=>'2.4','max_val'=>'2.6','text'=>'标准','color'=>'#59D16D'],
['min_val'=>'2.6','max_val'=>'5','text'=>'优','color'=>'#3C66D2'],
],
]
];
// 基础代谢
protected $kcal = [
['min_val'=>'0','max_val'=>'','text'=>'偏低','color'=>'#ff5656'],
['min_val'=>'','max_val'=>'9999','text'=>'优','color'=>'#3C66D2'],
];
// 内脏指数
protected $visceral = [
'man'=>[
['min_val'=>'0','max_val'=>'9','text'=>'标准','color'=>'#59D16D'],
['min_val'=>'9','max_val'=>'14','text'=>'警惕','color'=>'#FAB000'],
['min_val'=>'14','max_val'=>'50','text'=>'危险','color'=>'#FA5951'], //红
],
'woman'=>[
['min_val'=>'0','max_val'=>'9','text'=>'标准','color'=>'#59D16D'],
['min_val'=>'9','max_val'=>'14','text'=>'警惕','color'=>'#FAB000'],
['min_val'=>'14','max_val'=>'50','text'=>'危险','color'=>'#FA5951'], //红
]
];
// 皮下脂肪
protected $sfr = [
'man'=>[
['min_val'=>'0','max_val'=>'7','text'=>'不足','color'=>'#FCDB67'], //淡黄
['min_val'=>'7','max_val'=>'15','text'=>'标准','color'=>'#59D16D'], //绿
['min_val'=>'15','max_val'=>'50','text'=>'偏高','color'=>'#FAB000'], //橙
],
'woman'=>[
['min_val'=>'0','max_val'=>'11','text'=>'不足','color'=>'#FCDB67'],
['min_val'=>'11','max_val'=>'17','text'=>'标准','color'=>'#59D16D'],
['min_val'=>'17','max_val'=>'50','text'=>'偏高','color'=>'#FAB000'],
]
];
// 加 bcadd(,,20)
// 减 bcsub(,,20)
// 乘 bcmul(,,20)
// 除 bcdiv(,,20)
// 计算部分内容的横线标准以及说明文字
public function conversion_interval($data){
// $data['gender'] = $data['gender']==2?'woman':'man';
$gender = $data['gender']==2?'woman':'man';
$age = $data['age']['value'];
$weight = 0;
$temporary_arr = [
'score_name' =>$data['record_type']['value'] == 'by_device_adc'?$data['score']['name']:'',
'score_value' =>$data['record_type']['value'] == 'by_device_adc'?$data['score']['value']:'',
'score_unit' =>$data['record_type']['value'] == 'by_device_adc'?$data['score']['unit']:'',
'body_type_name' =>$data['record_type']['value'] == 'by_device_adc'?$data['body_type']['name']:'',
'body_type_value' =>$data['record_type']['value'] == 'by_device_adc'?$data['body_type']['value']:'',
'body_type_unit' =>$data['record_type']['value'] == 'by_device_adc'?$data['body_type']['unit']:'',
// 'record_time' =>str_replace('-', '/', $data['record_time']),
'record_time' =>$data['record_time'],
'top_list'=>[],
'bottom_list'=>[],
];
// die;
// $date_temporary = new \DateTime($temporary_arr['record_time']);
// 使用 format 方法来指定新的日期和时间格式
// $temporary_arr['record_time'] = $date_temporary->format('Y年m月d日 H:i:s');
// 处理格式(顶部)
foreach ($this->parameter_aggregate_top as $key => $value) {
$data[$key]['key_name'] = $key;
$data[$key]['desc'] = $value;
if($key == 'weight'){
$weight = $data[$key]['value'];
}
array_push($temporary_arr['top_list'],$data[$key]);
}
// 处理格式(底部)
foreach ($this->parameter_aggregate_bottom as $key => $value) {
$data[$key]['key_name'] = $key;
$data[$key]['desc'] = $value;
array_push($temporary_arr['bottom_list'],$data[$key]);
}
// 处理顶部list
foreach ($temporary_arr['top_list'] as $key => $value) {
if(count($value['list']) > 0){
$temporary_arr['top_list'][$key]['offset'] = $this->calculate_landing_point($value['list'],$value['value'],$value['standard'])[0];
}
}
// 如果是没有阻抗的测试,那么就不要底部的其他数据了
if($data['record_type']['value'] != 'by_device_adc'){
$temporary_arr['bottom_list'] = [];
return $temporary_arr;
}
// 处理底部list
foreach ($temporary_arr['bottom_list'] as $key => $value) {
// dump($value);
// 脂肪率&
if($value['key_name'] == 'fat_r'){
if($age < 30){
$temporary_arr['bottom_list'][$key]['list'] = $this->fat_r_w[$gender]['29'];
}else{
$temporary_arr['bottom_list'][$key]['list'] = $this->fat_r_w[$gender]['30'];
}
// 处理异常
if($temporary_arr['bottom_list'][$key]['standard'] == '异常'){
$temporary_arr['bottom_list'][$key] = $this->handling_exceptions($temporary_arr['bottom_list'][$key]);
}
$temporary_arr['bottom_list'][$key]['offset'] = $this->calculate_landing_point($temporary_arr['bottom_list'][$key]['list'],$temporary_arr['bottom_list'][$key]['value'],$temporary_arr['bottom_list'][$key]['standard']);
}
// 脂肪量
else if($value['key_name'] == 'fat_w'){
if($age < 30){
$temporary_arr['bottom_list'][$key]['list'] = $this->fat_r_w[$gender]['29'];
}else{
$temporary_arr['bottom_list'][$key]['list'] = $this->fat_r_w[$gender]['30'];
}
$temporary_arr['bottom_list'][$key]['list'] = $this->calculate_new_standard($temporary_arr['bottom_list'][$key]['list'],$weight,$value['key_name']);
// 处理异常
if($temporary_arr['bottom_list'][$key]['standard'] == '异常'){
$temporary_arr['bottom_list'][$key] = $this->handling_exceptions($temporary_arr['bottom_list'][$key]);
}
$temporary_arr['bottom_list'][$key]['offset'] = $this->calculate_landing_point($temporary_arr['bottom_list'][$key]['list'],$temporary_arr['bottom_list'][$key]['value'],$temporary_arr['bottom_list'][$key]['standard']);
}
// 肌肉率
else if($value['key_name'] == 'muscle'){
$temporary_arr['bottom_list'][$key]['list'] = $this->muscle_muscleval[$gender];
// 处理异常
if($temporary_arr['bottom_list'][$key]['standard'] == '异常'){
$temporary_arr['bottom_list'][$key] = $this->handling_exceptions($temporary_arr['bottom_list'][$key]);
}
$temporary_arr['bottom_list'][$key]['offset'] = $this->calculate_landing_point($temporary_arr['bottom_list'][$key]['list'],$temporary_arr['bottom_list'][$key]['value'],$temporary_arr['bottom_list'][$key]['standard']);
}
// 肌肉量
else if($value['key_name'] == 'muscleval'){
$temporary_arr['bottom_list'][$key]['list'] = $this->muscle_muscleval[$gender];
$temporary_arr['bottom_list'][$key]['list'] = $this->calculate_new_standard($temporary_arr['bottom_list'][$key]['list'],$weight,$value['key_name']);
// 处理异常
if($temporary_arr['bottom_list'][$key]['standard'] == '异常'){
$temporary_arr['bottom_list'][$key] = $this->handling_exceptions($temporary_arr['bottom_list'][$key]);
}
$temporary_arr['bottom_list'][$key]['offset'] = $this->calculate_landing_point($temporary_arr['bottom_list'][$key]['list'],$temporary_arr['bottom_list'][$key]['value'],$temporary_arr['bottom_list'][$key]['standard']);
}
// 水分
else if($value['key_name'] == 'water'){
$temporary_arr['bottom_list'][$key]['list'] = $this->water[$gender];
// 处理异常
if($temporary_arr['bottom_list'][$key]['standard'] == '异常'){
$temporary_arr['bottom_list'][$key] = $this->handling_exceptions($temporary_arr['bottom_list'][$key]);
}
$temporary_arr['bottom_list'][$key]['offset'] = $this->calculate_landing_point($temporary_arr['bottom_list'][$key]['list'],$temporary_arr['bottom_list'][$key]['value'],$temporary_arr['bottom_list'][$key]['standard']);
}
// 蛋白量
else if($value['key_name'] == 'proteinval'){
$temporary_arr['bottom_list'][$key]['list'] = $this->proteinval_protein[$gender];
$temporary_arr['bottom_list'][$key]['list'] = $this->calculate_new_standard($temporary_arr['bottom_list'][$key]['list'],$weight,$value['key_name']);
// 处理异常
if($temporary_arr['bottom_list'][$key]['standard'] == '异常'){
$temporary_arr['bottom_list'][$key] = $this->handling_exceptions($temporary_arr['bottom_list'][$key]);
}
$temporary_arr['bottom_list'][$key]['offset'] = $this->calculate_landing_point($temporary_arr['bottom_list'][$key]['list'],$temporary_arr['bottom_list'][$key]['value'],$temporary_arr['bottom_list'][$key]['standard']);
}
// 骨重
else if($value['key_name'] == 'bone'){
if($gender == 'man'){
if($weight < 60){
$temporary_arr['bottom_list'][$key]['list'] = $this->bone[$gender]['60'];
}else if($weight >= 60 && $weight < 75){
$temporary_arr['bottom_list'][$key]['list'] = $this->bone[$gender]['60_75'];
}else{
$temporary_arr['bottom_list'][$key]['list'] = $this->bone[$gender]['75'];
}
}else{
if($weight < 45){
$temporary_arr['bottom_list'][$key]['list'] = $this->bone[$gender]['45'];
}else if($weight >= 45 && $weight < 60){
$temporary_arr['bottom_list'][$key]['list'] = $this->bone[$gender]['45_60'];
}else{
$temporary_arr['bottom_list'][$key]['list'] = $this->bone[$gender]['60'];
}
}
// 处理异常
if($temporary_arr['bottom_list'][$key]['standard'] == '异常'){
$temporary_arr['bottom_list'][$key] = $this->handling_exceptions($temporary_arr['bottom_list'][$key]);
}
$temporary_arr['bottom_list'][$key]['offset'] = $this->calculate_landing_point($temporary_arr['bottom_list'][$key]['list'],$temporary_arr['bottom_list'][$key]['value'],$temporary_arr['bottom_list'][$key]['standard']);
}
// 蛋白率
else if($value['key_name'] == 'protein'){
$temporary_arr['bottom_list'][$key]['list'] = $this->proteinval_protein[$gender];
// 处理异常
if($temporary_arr['bottom_list'][$key]['standard'] == '异常'){
$temporary_arr['bottom_list'][$key] = $this->handling_exceptions($temporary_arr['bottom_list'][$key]);
}
$temporary_arr['bottom_list'][$key]['offset'] = $this->calculate_landing_point($temporary_arr['bottom_list'][$key]['list'],$temporary_arr['bottom_list'][$key]['value'],$temporary_arr['bottom_list'][$key]['standard']);
}
// 基础代谢
else if($value['key_name'] == 'kcal'){
$temporary_arr['bottom_list'][$key]['list'] = $this->calculate_new_standard($this->kcal,$weight,$value['key_name'],$age,$gender);
// 处理异常
if($temporary_arr['bottom_list'][$key]['standard'] == '异常'){
$temporary_arr['bottom_list'][$key] = $this->handling_exceptions($temporary_arr['bottom_list'][$key]);
}
$temporary_arr['bottom_list'][$key]['offset'] = $this->calculate_landing_point($temporary_arr['bottom_list'][$key]['list'],$temporary_arr['bottom_list'][$key]['value'],$temporary_arr['bottom_list'][$key]['standard']);
}
// 内脏指数
else if($value['key_name'] == 'visceral'){
$temporary_arr['bottom_list'][$key]['list'] = $this->visceral[$gender];
// 处理异常
if($temporary_arr['bottom_list'][$key]['standard'] == '异常'){
$temporary_arr['bottom_list'][$key] = $this->handling_exceptions($temporary_arr['bottom_list'][$key]);
}
$temporary_arr['bottom_list'][$key]['offset'] = $this->calculate_landing_point($temporary_arr['bottom_list'][$key]['list'],$temporary_arr['bottom_list'][$key]['value'],$temporary_arr['bottom_list'][$key]['standard']);
}
// 皮下脂肪
else if($value['key_name'] == 'sfr'){
$temporary_arr['bottom_list'][$key]['list'] = $this->sfr[$gender];
// 处理异常
if($temporary_arr['bottom_list'][$key]['standard'] == '异常'){
$temporary_arr['bottom_list'][$key] = $this->handling_exceptions($temporary_arr['bottom_list'][$key]);
}
$temporary_arr['bottom_list'][$key]['offset'] = $this->calculate_landing_point($temporary_arr['bottom_list'][$key]['list'],$temporary_arr['bottom_list'][$key]['value'],$temporary_arr['bottom_list'][$key]['standard']);
}
}
return $temporary_arr;
}
// 计算落点百分比(区间字典,值,值描述)
public function calculate_landing_point($data,$val,$t_val){
// 根据字典确认有几个区间
$num = count($data);
if($num <= 0){
return 0;
}
// 没个区间占比
$a_section = bcdiv(100,$num,2);
$temporary_data = [];
$num_0 = 0;
// 看看值是在哪个区间
foreach ($data as $key => $value) {
if($val>=$value['min_val'] && $val<$value['max_val']){
$temporary_data = $value;
$num_0 = $key;
break;
}
}
if(count($temporary_data) <= 0){
return 0;
}
// 加 bcadd(,,20)
// 减 bcsub(,,20)
// 乘 bcmul(,,20)
// 除 bcdiv(,,20)
$max_num = trim($temporary_data['max_val']);
$min_num = trim($temporary_data['min_val']);
if($val < $temporary_data['max_val']){
// 这个值比最小值多出来多少
$num_1 = bcsub($val,$min_num,2);
// 这个区间的值是多少
$num_2 = bcsub($max_num,$min_num,2);
// 算出这个值在这个区间的占比
$num_3 = bcdiv($num_1,$num_2,2);
$num_4 = bcmul($num_3,$a_section,2);
$result = bcadd($num_4,bcmul($a_section,$num_0,2),2);
}else{
// $num_4 = bcdiv(1,$num,4)*100;
$result = bcadd(bcmul($num_0,$a_section,2),$a_section,2);
}
return $result;
}
// 计算新标准
public function calculate_new_standard($data,$w,$k,$age=0,$gender='man'){
$temporary_arr = [];
if($k != 'kcal'){
foreach ($data as $key => $value) {
array_push($temporary_arr,[
'min_val'=>bcmul($w,bcdiv($value['min_val'],100,2),2),
'max_val'=>bcmul($w,bcdiv($value['max_val'],100,2),2),
'text'=>$value['text'],
'color'=>$value['color']
]);
}
}else{
// BMR标准值(男) BMR标准值(女)
// 60.9*体重(kg)-54 61.0*体重(kg)-51
// 22.7*体重(kg)+495 22.5*体重(kg)+499
// 17.5*体重(kg)+651 12.2*体重(kg)+746
// 15.3*体重(kg)+679 14.7*体重(kg)+496
// 11.6*体重(kg)+879 8.7*体重(kg)+820
$vv_val = 0;
if($age < 3){
if($gender == 'man'){
$vv_val = bcsub(bcmul(60.9,$w,2),54,2);
}else{
$vv_val = bcsub(bcmul(61.0,$w,2),51,2);
}
}else if($age >= 3 && $age < 10){
if($gender == 'man'){
$vv_val = bcadd(bcmul(22.7,$w,2),495,2);
}else{
$vv_val = bcadd(bcmul(22.5,$w,2),499,2);
}
}else if($age >= 10 && $age < 18){
if($gender == 'man'){
$vv_val = bcadd(bcmul(17.5,$w,2),651,2);
}else{
$vv_val = bcadd(bcmul(12.2,$w,2),746,2);
}
}else if($age >= 18 && $age < 30){
if($gender == 'man'){
$vv_val = bcadd(bcmul(15.3,$w,2),679,2);
}else{
$vv_val = bcadd(bcmul(14.7,$w,2),496,2);
}
}else{
if($gender == 'man'){
$vv_val = bcadd(bcmul(11.6,$w,2),879,2);
}else{
$vv_val = bcadd(bcmul(8.7,$w,2),820,2);
}
}
$data[0]['max_val'] = $vv_val;
$data[1]['min_val'] = $vv_val;
$temporary_arr = $data;
}
return $temporary_arr;
}
// 处理异常
public function handling_exceptions($data){
for ($i=0; $i < count($data['list']); $i++) {
if($data['value']>=$data['list'][$i]['min_val'] && $data['value']<$data['list'][$i]['max_val']){
$data['standard'] = $data['list'][$i]['text'];
$data['color'] = $data['list'][$i]['color'];
break;
}
}
if($data['standard'] == '异常'){
if($data['value'] <= $data['list'][0]['min_val']){
$data['standard'] = $data['list'][0]['text'];
$data['color'] = $data['list'][0]['color'];
}else if($data['value'] >= $data['list'][count($data['list'])-1]['max_val']){
$data['standard'] = $data['list'][count($data['list'])-1]['text'];
$data['color'] = $data['list'][count($data['list'])-1]['color'];
}
}
return $data;
}
}

View File

@ -0,0 +1,141 @@
<?php
namespace app\NewReedaw\controller\app;
use think\Controller;
use think\Db;
use think\Cache;
use think\Log;
use PHPMailer\PHPMailer\PHPMailer;
use app\NewReedaw\controller\app\Role;
class Index extends Base{
protected $index_db_name = [
'zhanghao'=>'app_account_number',
'juese'=>'app_user_data',
'body_data'=>'app_card_body_data',
];
// 加 bcadd(,,20)
// 减 bcsub(,,20)
// 乘 bcmul(,,20)
// 除 bcdiv(,,20)
// 测试token=>'caadd1be045a65f30b92aa805f1de54a'
################################################################接口################################################################
################################################################接口################################################################
################################################################接口################################################################
// 配置信息
public function config($data = ['token'=>'caadd1be045a65f30b92aa805f1de54a']){
try {
// 你的业务逻辑
if(count(input('post.')) > 0){
$data = input('post.');
}
if(!array_key_exists('token', $data)){
return $this->msg(10001);
}
if(!$this->verify_data_is_ok($data['token'],'str')){
return $this->msg(10005);
}
return $this->config_action($data);
} catch (\Exception $e) {
// 捕获异常
$logContent["flie"] = $e->getFile();
$logContent["line"] = $e->getLine();
$logContent['all_content'] = "异常信息:\n";
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
$this->record_api_log($data, $logContent, null);
return $this->msg(99999);
}
}
// 获取首页角色信息
public function get_user_data_information(){
try {
$data = input('post.');
if(!array_key_exists('token', $data) || !array_key_exists('aud_id', $data)){
return $this->msg(10001);
}
if(!$this->verify_data_is_ok($data['token'],'str')){
return $this->msg(10005,'token type error');
}
if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
return $this->msg(10005,'aud_id type error');
}
return $this->get_user_data_information_action($data);
} catch (\Exception $e) {
// 捕获异常
$logContent["flie"] = $e->getFile();
$logContent["line"] = $e->getLine();
$logContent['all_content'] = "异常信息:\n";
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
$this->record_api_log($data, $logContent, null);
return $this->msg(99999);
}
}
################################################################action################################################################
################################################################action################################################################
public function config_action($data){
$return_data = [
'literature'=>[
'index'=>[
'*数据参考:',
'《中华人民共和国卫生行业标准WS/T 423-2022》',
'《中华人民共和国卫生行业标准WS/T 612-2018》',
'《中华人民共和国卫生行业标准WS/T 586-2018》',
'《WHO 5~19岁身高/体重判定标准》',
],
'bmi_evaluation'=>[
'*数据参考:',
'《WHO 5~19岁身高/体重判定标准》'
],
'height_prediction'=>[
'*数据参考:',
'Khamis-Roche方法',
'北京积水潭医院儿科临床参考公式',
'《中国妇幼保健》等相关学术期刊文献',
],
'warning'=>[
'此测量数据仅供参考,不可替代医学专业测试!'
]
],
'king_kong_region'=>[
['title'=>'增量对比','icon'=>'','jump'=>''],
['title'=>'中招估分','icon'=>'','jump'=>''],
['title'=>'遗传身高','icon'=>'','jump'=>''],
['title'=>'BMI测评','icon'=>'','jump'=>''],
],
'role_list'=>[
]
];
$role = new Role;
$return_data['role_list'] = $role->role_list_action(['token'=>$data['token'],'type'=>2])->getData()['data'];
return $this->msg($return_data);
}
public function get_user_data_information_action($data){
$return_result = [
'body_data'=>[],
'kcal_data'=>[],
'card_data'=>[]
];
$aud_data = Db::table($this->index_db_name['juese'])->where(['id'=>$data['aud_id']])->find();
$body_data = Db::table($this->index_db_name['body_data'])->where(['id'=>$data['aud_id']])->find();
}
}

View File

@ -0,0 +1,716 @@
<?php
namespace app\NewReedaw\controller\app;
use think\Db;
use PHPMailer\PHPMailer\PHPMailer;
use app\app\controller\Wechat;// 引入Wechat服务类
class Login extends Base{
protected $code_time = 50;
// protected $token_time = 2592000;//30天的秒数
protected $default_head_pic = 'https://tc.pcxbc.com/tsf/head_pic.png';
protected $login_use_db_name = [
'zhanghao'=>'app_account_number',
];
################################################################接口################################################################
################################################################接口################################################################
################################################################接口################################################################
// 注册
public function register(){
try {
$data = input('post.');
// 验证数据项是否完整
if(!array_key_exists('data', $data) || !array_key_exists('password', $data) || !array_key_exists('code', $data)){
return $this->msg(10001);
}
// 验证数据值是否合规
if(!$data['data'] || !$data['password'] || !$data['code']){
return $this->msg(10006);
}
if(!$this->verify_data_is_ok($data['password'],'str')){
return $this->msg(10005);
}
if(!$this->verify_data_is_ok($data['code'],'num')){
return $this->msg(10005);
}
return $this->register_action($data);
} catch (\Exception $e) {
// 捕获异常
$logContent["flie"] = $e->getFile();
$logContent["line"] = $e->getLine();
$logContent['all_content'] = "异常信息:\n";
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
$logContent['all_content'] .= "方法: " . __METHOD__ . "\n";
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
$this->record_api_log($data, $logContent, null);
return $this->msg(99999);
}
}
// 登录
public function login(){
try {
$data = input('post.');
if(!array_key_exists('data', $data) || !array_key_exists('validate_data', $data) || !array_key_exists('validate_type', $data)){
return $this->msg(10001);
}
// 验证数据值是否合规
if(!$this->verify_data_is_ok($data['data'],'str')){
return $this->msg(10005);
}
if(!$this->verify_data_is_ok($data['validate_data'],'str')){
return $this->msg(10005);
}
if(!$this->verify_data_is_ok($data['validate_type'],'str')){
return $this->msg(10005);
}
return $this->login_action($data);
} catch (\Exception $e) {
// 捕获异常
$logContent["flie"] = $e->getFile();
$logContent["line"] = $e->getLine();
$logContent['all_content'] = "异常信息:\n";
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
$logContent['all_content'] .= "方法: " . __METHOD__ . "\n";
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
$this->record_api_log($data, $logContent, null);
return $this->msg(99999);
}
}
###############################################################action################################################################
###############################################################action################################################################
###############################################################action################################################################
public function register_action($data){
// 验证是手机还是邮箱
$montage_data = $this->is_tel_email($data['data']);
if($montage_data == false){
return $this->msg(10005);
}
// 查询账号是否已经注册
$inspect_repeat = Db::table($this->login_use_db_name['zhanghao'])->where([$montage_data=>$data['data'],'is_del'=>0])->count();
if($inspect_repeat > 0){
return $this->msg(10002,'注册失败,账号已存在');
}
// 检查验证码
$code_result = $this->check_code($data['data'],$data['code']);
if($code_result !== true){
return $this->msg(10002,$code_result);
}
// 验证完之后
$set_data = [];
if($montage_data == 'tel'){
$set_data['tel'] = $data['data'];
}else{
$set_data['email'] = $data['data'];
}
$set_data['password'] = $data['password'];
$set_data['head_pic'] = $this->default_head_pic;
$set_data['nickname'] = '用户'.time();
$set_data['create_time'] = date('Y-m-d H:i:s');
$set_data['login_time'] = date('Y-m-d H:i:s');
$set_data['token'] = md5($data['data'].$this->create_random_string(12).time());
$result = Db::table($this->login_use_db_name['zhanghao'])->insertGetId($set_data);
if($result){
$return_data = $this->msg(['token'=>$set_data['token'],'aan_id'=>$result]);
}else{
$return_data = $this->msg(10002);
}
return $return_data;
}
public function login_action($data){
// 检测是否为手机
$montage_data = $this->is_tel_email($data['data']);
if($montage_data == false){
return $this->msg(10005);
}
$verify_result[$montage_data] = $data['data'];
$verify_result['is_del'] = 0;
// 检测校验途径
if($data['validate_type'] == 'code'){
$code_name = $data['data'];
if($this->check_code($code_name,$data['validate_data']) === true){
$result = Db::table($this->login_use_db_name['zhanghao'])->where($verify_result)->field('id,token')->find();
if($result){
Db::table($this->login_use_db_name['zhanghao'])->where($verify_result)->update(['login_time'=>date('Y-m-d H:i:s')]);
$return_data = $this->msg(['token'=>$result['token'],'aan_id'=>$result['id']]);
}else{
$set_data['password'] = '';
$set_data[$montage_data] = $data['data'];
$set_data['head_pic'] = $this->default_head_pic;
$set_data['nickname'] = '用户'.$data['data'];
$set_data['create_time'] = date('Y-m-d H:i:s');
$set_data['login_time'] = date('Y-m-d H:i:s');
$set_data['token'] = md5($data['data'].$this->create_random_string(12).time());
$result = Db::table($this->login_use_db_name['zhanghao'])->insertGetId($set_data);
if($result){
$return_data = $this->msg(['token'=>$set_data['token'],'aan_id'=>$result],'登录成功');
}else{
$return_data = $this->msg(10002);
}
}
}else{
$return_data = $this->msg(10003,'登录失败,验证码错误或失效');
}
}else if($data['validate_type'] == 'password'){
// $verify_result['password'] = $data['validate_data'];
$result = Db::table($this->login_use_db_name['zhanghao'])->where($verify_result)->field('id,token,password')->find();
if($result){
if($result['password'] == ''){
$return_data = $this->msg(10003,'该账户未设密码,请用验证码登录');
}
if($data['validate_data'] != $result['password']){
$return_data = $this->msg(10003,'账号密码错误');
}else{
Db::table($this->login_use_db_name['zhanghao'])->where($verify_result)->update(['login_time'=>date('Y-m-d H:i:s')]);
$return_data = $this->msg(['token'=>$result['token'],'aan_id'=>$result['id']],'登录成功');
}
}else{
$return_data = $this->msg(10003,'账号未注册,请先注册');
}
}else{
$return_data = $this->msg(10003,'校验参数错误');
}
return $return_data;
}
// 重置密码
public function reset_password($data = ['data'=>'18530934717','password'=>'ceshi1','c_password'=>'ceshi1','code'=>'491661']){
try {
// 你的业务逻辑
// 验证是否前段发送过来的数据
if(count(input('post.')) > 0){
$data = input('post.');
}
// 验证数据项是否完整
if(!array_key_exists('data', $data) || !array_key_exists('password', $data) || !array_key_exists('c_password', $data) || !array_key_exists('code', $data)){
return $this->msg(10001);
}
// 验证数据值是否合规
if($data['password'] != $data['c_password']){
return $this->msg(10003,'两次密码不一致');
}
if($data['password'] == ''){
return $this->msg(10003,'密码不能为空');
}
if(!$this->verify_data_is_ok($data['password'],'str')){
return $this->msg(10005);
}
if(!$this->verify_data_is_ok($data['code'],'num')){
return $this->msg(10005);
}
// 检查验证码
$code_result = $this->check_code($data['data'],$data['code']);
if($code_result !== true){
return $this->msg(10003,$code_result);
}
$t_y = $this->is_tel_email($data['data']);
if($t_y === false){
return $this->msg(10003,'账号格式错误');
}
// 检查账号是否存在
$find_data = Db::table($this->login_use_db_name['zhanghao'])->where([$t_y=>$data['data'],'is_del'=>0])->field('id,token')->find();
if(!$find_data){
return $this->msg(10003);
}
$result = Db::table($this->login_use_db_name['zhanghao'])->where([$t_y=>$data['data']])->update(['password'=>$data['password']]);
if($result){
$return_data = $this->msg(['token'=>$find_data['token'],'aan_id'=>$find_data['id']]);
}else{
$return_data = $this->msg(10002);
}
// 成功
$this->record_api_log($data, null, $return_data);
return $return_data;
} catch (\Exception $e) {
// 捕获异常
$logContent["flie"] = $e->getFile();
$logContent["line"] = $e->getLine();
$logContent['all_content'] = "异常信息:\n";
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
$logContent['all_content'] .= "方法: " . __METHOD__ . "\n";
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
$this->record_api_log($data, $logContent, null);
return $this->msg(99999);
}
}
// 微信手机号快捷登录
public function wechat_quick_login(){
try {
// 你的业务逻辑
if(count(input('post.')) > 0){
$data = input('post.');
}
if(!array_key_exists('code', $data)){
// return $this->msg(10001,'');
return $this->msg(10001,'code is miss');
}
if(!array_key_exists('encryptedData', $data)){
return $this->msg(10001,'encryptedData is miss');
}
if(!array_key_exists('iv', $data)){
return $this->msg(10001,'iv is miss');
}
// 校验参数
if (empty($data['code'])) {
return $this->msg(10001,'code is miss.');
}
if (empty($data['encryptedData'])) {
return $this->msg(10001,'encryptedData is miss.');
}
if (empty($data['iv'])) {
return $this->msg(10001,'iv is miss.');
}
// 调用Wechat服务类处理微信登录逻辑
$wechatService = new Wechat();
$result = $wechatService->handleWechatLogin($data['code'], $data['encryptedData'], $data['iv']);
// die;
if($result['code'] == 0){
// return $this->msg($result['code'],$result['msg']);
$user_data = Db::table($this->login_use_db_name['zhanghao'])->where(['tel'=>$result['data']['phoneNumber'],'is_del'=>0])->find();
if($user_data){
Db::table($this->login_use_db_name['zhanghao'])->where(['token'=>$user_data['token']])->update(['login_time'=>date('Y-m-d H:i:s')]);
$return_data = $this->msg(['token'=>$user_data['token'],'aan_id'=>$user_data['id']]);
}else{
$set_data['password'] = '';
$set_data['tel'] = $result['data']['phoneNumber'];
$set_data['head_pic'] = $this->default_head_pic;
$set_data['nickname'] = '用户'.$result['data']['phoneNumber'];
$set_data['create_time'] = date('Y-m-d H:i:s');
$set_data['login_time'] = date('Y-m-d H:i:s');
$set_data['token'] = md5($result['data']['phoneNumber'].$this->create_random_string(12).time());
$set_user_result = Db::table($this->login_use_db_name['zhanghao'])->insertGetId($set_data);
if($set_user_result){
$return_data = $this->msg(['token'=>$set_data['token'],'aan_id'=>$set_user_result],'登录成功');
}else{
$return_data = $this->msg(10002);
}
}
return $return_data;
}else{
return $this->msg($result['code'],$result['msg']);
}
} catch (\Exception $e) {
// 捕获异常
$logContent["flie"] = $e->getFile();
$logContent["line"] = $e->getLine();
$logContent['all_content'] = "异常信息:\n";
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
$logContent['all_content'] .= "方法: " . __METHOD__ . "\n";
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
$this->record_api_log($data, $logContent, null);
return $this->msg(99999);
}
}
// 退出登录操作
public function user_quit_account($data=['token'=>'0dafb98a10995c98b5a33b7d59d986ca']){
try {
// 你的业务逻辑
if(count(input('post.')) > 0){
$data = input('post.');
}
if(!array_key_exists('token', $data)){
$return_data = $this->msg(10001);
}
if($this->token_time_validate($data['token']) === false){
$return_data = $this->msg(20001);
}
$result = Db::table($this->login_use_db_name['zhanghao'])->where(['token'=>$data['token']])->update(['login_time'=>'2024-09-01 00:00:00']);
if($result){
$return_data = $this->msg([]);
}else{
$return_data = $this->msg(10002);
}
// 成功
$this->record_api_log($data, null, $return_data);
return $return_data;
} catch (\Exception $e) {
// 捕获异常
$logContent["flie"] = $e->getFile();
$logContent["line"] = $e->getLine();
$logContent['all_content'] = "异常信息:\n";
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
$logContent['all_content'] .= "方法: " . __METHOD__ . "\n";
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
$this->record_api_log($data, $logContent, null);
return $this->msg(99999);
}
}
// 删除账号
public function delete_account($data=['token'=>'0dafb98a10995c98b5a33b7d59d986ca']){
try {
// 你的业务逻辑
if(count(input('post.')) > 0){
$data = input('post.');
}
if(!array_key_exists('token', $data)){
$return_data = $this->msg(10001);
}
$result = Db::table($this->login_use_db_name['zhanghao'])->where(['token'=>$data['token']])->update(['is_del'=>1,'login_time'=>'2024-09-01 00:00:00']);
if($result){
$return_data = $this->msg([]);
}else{
$return_data = $this->msg(10002);
}
// 成功
$this->record_api_log($data, null, $return_data);
return $return_data;
} catch (\Exception $e) {
// 捕获异常
$logContent["flie"] = $e->getFile();
$logContent["line"] = $e->getLine();
$logContent['all_content'] = "异常信息:\n";
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
$logContent['all_content'] .= "方法: " . __METHOD__ . "\n";
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
$this->record_api_log($data, $logContent, null);
return $this->msg(99999);
}
}
################################################################接口################################################################
################################################################接口################################################################
################################################################接口################################################################
// 发送验证码 手机/邮箱
/* 接口说明(发邮件)
* $data手机或者邮箱信息 字符串
* $type验证类型是注册用还是其他用途 字符串 默认register注册register、login、reset_password
* $road是手机还是邮箱还是其他 字符串 默认tel或email
*/
//18736019909
public function send_phone_email_code($data = ['data'=>'18736019909']){
if(count(input('post.')) > 0){
$data = input('post.');
}
if(!array_key_exists('data', $data)){
return $this->msg(10001);
}
if(cache($data['data'])){
return $this->msg(10002,'60秒仅可发送一次验证码');
}
$num = mt_rand(100000,999999);
if (preg_match('/^\d{11}$/', $data['data'])) {
// 本公司短信
// $result = $this->send_tel_code($data['data'],$num);
// 阿里云短信
$sms_all = new Smsaliyun;
$result = $sms_all->send_sms($data['data'],$num);
// dump($result);
$road = 'tel';
}else{
$result = $this->send_email_code([$data['data']],['title'=>'Reedaw验证码','from_user_name'=>'Reedaw验证码','content'=>$num]);
$road = 'email';
}
if(is_array($result) && $result['code'] == 0){
cache($data['data'], $num, $this->code_time);
// return $this->msg(['code'=>$num]);
return $this->msg([]);
// return true;
}else{
return $this->msg(10010,'验证码发送失败');
// return false;
}
}
################################内部调用################################
/* 接口说明(发手机短信)
*/
public function send_tel_code($tel,$code){
// 初始化cURL会话
$ch = curl_init();
$headers = [
'Accept: application/json',
'Content-Type: application/json',
];
// 设置头部信息
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// 设置请求的URL
$url = "http://sms.ybhdmob.com/Message/Send?token=ybhdmob";
curl_setopt($ch, CURLOPT_URL, $url);
// 设置为POST请求
curl_setopt($ch, CURLOPT_POST, 1);
// 设置POST数据
$postData = array(
'phone' => $tel,
// 'content' => '【巨天】您好欢迎使用Reedaw您的手机验证码是'.$code.',验证码一分钟内有效,若非本人操作,请忽略本短信'
// 'content' => '【郑州品传科技】您好欢迎使用Reedaw您的手机验证码是'.$code.',验证码一分钟内有效,若非本人操作,请忽略本短信'
// 'content' => '【每日一称】您好欢迎使用Reedaw您的手机验证码是'.$code.',验证码一分钟内有效,若非本人操作,请忽略本短信'
'content' => '【小白健康】您好欢迎使用Reedaw您的手机验证码是'.$code.',验证码一分钟内有效,若非本人操作,请忽略本短信'
);
$postData = json_encode($postData);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
// 设置返回结果不直接输出,而是返回到变量中
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// 发送请求并获取响应
$response = curl_exec($ch);
// dump($response);
// 检查是否有错误发生
if (curl_errno($ch)) {
$error_message = curl_error($ch);
return "请求错误: " . $error_message;
}
// 关闭cURL会话
curl_close($ch);
// 处理响应
// dump(json_decode($response,true));
if ($response) {
return json_decode($response,true);
} else {
echo "未收到响应";
}
}
// 手机号区分
function getCarrierByPhone($phone) {
// 验证手机号格式11位数字且以1开头
if (!preg_match('/^1[3-9]\d{9}$/', $phone)) {
return '无效手机号';
}
$prefix3 = substr($phone, 0, 3);
// 2025年最新3位号段排除4位号段
$carriers = [
'中国移动' => ['134', '135', '136', '137', '138', '139', '150', '151', '152', '157', '158', '159', '178', '182', '183', '184', '187', '188', '195', '197', '198'],
'中国联通' => ['130', '131', '132', '155', '156', '166', '175', '176', '185', '186', '196'],
'中国电信' => ['133', '153', '173', '177', '180', '181', '189', '190', '191', '193', '199'],
'中国广电' => ['192']
];
foreach ($carriers as $carrier => $segments) {
if (in_array($prefix3, $segments)) {
return $carrier;
}
}
return '未知运营商';
}
/* 接口说明(发邮件)
* $address收件人的邮箱地址 数组 格式: ['460834639@qq.com','460834639@qq.com'.......]
* $content邮件的主题数据信息 数组 格式:['title'=>'123','from_user_name'=>'123','content'=>'123']
* $annex附件路径信息 字符串
*/
public function send_email_code($address,$content,$annex=''){
// $ad = '460834639@qq.com';
$ad1 = '295155911@qq.com';
$mail = new PHPMailer(); //实例化
$mail->IsSMTP(); // 启用SMTP
$mail->Host = "smtp.126.com"; //SMTP服务器 163邮箱例子
$mail->Port = 465; //邮件发送端口
$mail->SMTPAuth = true; //启用SMTP认证
$mail->SMTPSecure = 'ssl';
$mail->CharSet = "UTF-8"; //字符集
$mail->Encoding = "base64"; //编码方式
$mail->Username = "tsf3920322@126.com"; //你的邮箱
$mail->Password = "HLWXNRPUCTHJFIIX"; //你的密码(邮箱后台的授权密码)
$mail->From = "tsf3920322@126.com"; //发件人地址(也就是你的邮箱)
// $mail->Subject = "微盟测试邮件"; //邮件标题
$mail->Subject = $content['title']; //邮件标题
// $mail->FromName = "微盟体测中心"; //发件人姓名
$mail->FromName = $content['from_user_name']; //发件人姓名
for ($i=0; $i < count($address); $i++) {
$mail->AddAddress($address[$i], ""); //添加收件人(地址,昵称)
}
if($annex != ''){
// $url = ROOT_PATH. 'public' . DS . 'tsf' . DS .'demoooo.jpg';
$mail->AddAttachment($annex,''); // 添加附件,并指定名称
}
$mail->IsHTML(true); //支持html格式内容
$neirong = '<div style="margin: 0; padding: 0;">
<table cellpadding="0" cellspacing="0" border="0" width="100%" style="background: #f3f3f3; min-width: 350px; font-size: 1px; line-height: normal;">
<tbody><tr>
<td align="center" valign="top">
<table cellpadding="0" cellspacing="0" border="0" width="750" class="table750" style="width: 100%; max-width: 750px; min-width: 350px; background: #f3f3f3;">
<tbody><tr>
<td class="mob_pad" width="25" style="width: 25px; max-width: 25px; min-width: 25px;">&nbsp;</td>
<td align="center" valign="top" style="background: #ffffff;">
<table cellpadding="0" cellspacing="0" border="0" width="100%" style="width: 100% !important; min-width: 100%; max-width: 100%; background: #f3f3f3;">
<tbody><tr>
<td align="right" valign="top">
<div class="top_pad" style="height: 25px; line-height: 25px; font-size: 23px;">&nbsp;</div>
</td>
</tr>
</tbody></table>
<table cellpadding="0" cellspacing="0" border="0" width="88%" style="width: 88% !important; min-width: 88%; max-width: 88%;">
<tbody><tr>
<td align="left" valign="top">
<div style="height: 39px; line-height: 39px; font-size: 37px;">&nbsp;</div>
<font class="mob_title1" face="\'Source Sans Pro\', sans-serif" color="#1a1a1a" style="font-size: 52px; line-height: 55px; font-weight: 300; letter-spacing: -1.5px;">
<span class="mob_title1" style="font-family: \'Nunito\', Arial, Tahoma, Geneva, sans-serif; color: #fb966e; font-size: 48px; line-height: 55px; font-weight: 700; letter-spacing: -1.5px;">Reedaw!</span>
</font>
<div style="height: 73px; line-height: 73px; font-size: 71px;">&nbsp;</div>
</td>
</tr>
</tbody></table>
<table cellpadding="0" cellspacing="0" border="0" width="88%" style="width: 88% !important; min-width: 88%; max-width: 88%;">
<tbody><tr>
<td align="left" valign="top">
<div style="height: 33px; line-height: 33px; font-size: 31px;">&nbsp;</div>
<font face="\'Nunito\', sans-serif" color="#585858" style="font-size: 24px; line-height: 32px;">
<span style="font-family: \'Nunito\', Arial, Tahoma, Geneva, sans-serif; color: #585858; font-size: 24px; line-height: 32px;">感谢您选择锐动产品!</span>
</font>
<div style="height: 33px; line-height: 33px; font-size: 31px;">&nbsp;</div>
<font face="\'Nunito\', sans-serif" color="#585858" style="font-size: 24px; line-height: 32px;">
<span style="font-family: \'Nunito\', Arial, Tahoma, Geneva, sans-serif; color: #585858; font-size: 24px; line-height: 32px;">以下6位数字是邮箱验证码请在需要的位置填写以通过验证</span>
</font>
<div style="height: 18px; line-height: 33px; font-size: 31px;">&nbsp;</div>
<font face="\'Nunito\', sans-serif" color="#585858" style="font-size: 24px; line-height: 32px;">
<span style="font-family: \'Nunito\', Arial, Tahoma, Geneva, sans-serif; color: #aaaaaa; font-size: 16px; line-height: 32px;">(如果您从未请求发送邮箱验证码,请忽略此邮件)</span>
</font>
<div style="height: 33px; line-height: 33px; font-size: 31px;">&nbsp;</div>
<table class="mob_btn" cellpadding="0" cellspacing="0" border="0" style="background: #fb966e; border-radius: 4px;">
<tbody><tr>
<td align="center" valign="top">
<span style="display: block; border: 1px solid #fb966e; border-radius: 0px; padding: 6px 12px; font-family: \'Nunito\', Arial, Verdana, Tahoma, Geneva, sans-serif; color: #ffffff; font-size: 20px; line-height: 30px; text-decoration: none; white-space: nowrap; font-weight: 600;">
<font face="\'Nunito\', sans-serif" color="#ffffff" style="font-size: 20px; line-height: 30px; text-decoration: none; white-space: nowrap; font-weight: 600;">
<span style="font-family: \'Nunito\', Arial, Verdana, Tahoma, Geneva, sans-serif; color: #ffffff; font-size: 20px; line-height: 30px; text-decoration: none; white-space: nowrap; font-weight: 600;">'.$content['content'].'</span>
</font>
</span>
</td>
</tr>
</tbody></table>
<div style="height: 75px; line-height: 75px; font-size: 73px;">&nbsp;</div>
</td>
</tr>
</tbody></table>
<table cellpadding="0" cellspacing="0" border="0" width="100%" style="width: 100% !important; min-width: 100%; max-width: 100%; background: #f3f3f3;">
<tbody><tr>
<td align="center" valign="top">
<div style="height: 34px; line-height: 34px; font-size: 32px;">&nbsp;</div>
<table cellpadding="0" cellspacing="0" border="0" width="88%" style="width: 88% !important; min-width: 88%; max-width: 88%;">
<tbody><tr>
<td align="center" valign="top">
<div style="height:12px; line-height: 34px; font-size: 32px;">&nbsp;</div>
<font face="\'Nunito\', sans-serif" color="#868686" style="font-size: 17px; line-height: 20px;">
<span style="font-family: \'Nunito\', Arial, Tahoma, Geneva, sans-serif; color: #868686; font-size: 17px; line-height: 20px;">© Zhengzhou Pinchuan Technology Co., Ltd. </span>
</font>
<div style="height: 3px; line-height: 3px; font-size: 1px;">&nbsp;</div>
<font face="\'Nunito\', sans-serif" color="#1a1a1a" style="font-size: 17px; line-height: 20px;">
<span style="font-family: \'Nunito\', Arial, Tahoma, Geneva, sans-serif; color: #1a1a1a; font-size: 17px; line-height: 20px;"><a target="_blank" style="font-family: \'Nunito\', Arial, Tahoma, Geneva, sans-serif; color: #1a1a1a; font-size: 17px; line-height: 20px; text-decoration: none;" href="https://paoluz.link/"></a></span>
</font>
<div style="height: 35px; line-height: 35px; font-size: 33px;">&nbsp;</div>
</td>
</tr>
</tbody></table>
</td>
</tr>
</tbody></table>
</td>
<td class="mob_pad" width="25" style="width: 25px; max-width: 25px; min-width: 25px;">&nbsp;</td>
</tr>
</tbody></table>
</td>
</tr>
</tbody></table>
</div>';
$mail->Body = $neirong; //邮件主体内容
//发送
if (!$mail->Send()) {
return ['code' => 10003,'msg'=>$mail->ErrorInfo];
// return $mail->ErrorInfo;
} else {
return ['code' => 0];
// return 'success';
}
}
public function check_code($data = 18530934717 , $code = 123456){
// 默认验证码正确start
if($code == 88888888){
return true;
}
// 默认验证码正确end
if(cache($data) == false){
return '验证码过期';
}else{
if($code != cache($data)){
return '验证码错误';
}
}
return true;
}
################################################################other################################################################
################################################################other################################################################
################################################################other################################################################
public function create_random_string($length = 12)
{
//创建随机字符
$chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
$str = "";
for ($i = 0; $i < $length; $i++) {
$str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
}
return $str;
}
}

View File

@ -0,0 +1,328 @@
<?php
namespace app\NewReedaw\controller\app;
use think\Controller;
use think\Db;
use think\Cache;
use think\Log;
use PHPMailer\PHPMailer\PHPMailer;
class Role extends Base{
protected $role_db_name = [
'zhanghao'=>'app_account_number',
'juese'=>'app_user_data',
'quyu_card'=>'admin_estimate'
];
protected $identity_list = ['P0'=>'陌生人','P1'=>'爸爸','P2'=>'妈妈','P3'=>'大宝','P4'=>'二宝','P5'=>'三宝','P6'=>'四宝','P7'=>'爷爷','P8'=>'奶奶'];
protected $grade_list = [
['id'=>'nothing','name'=>'无'],
['id'=>'grade_s_1','name'=>'小学一年级'],
['id'=>'grade_s_2','name'=>'小学二年级'],
['id'=>'grade_s_3','name'=>'小学三年级'],
['id'=>'grade_s_4','name'=>'小学四年级'],
['id'=>'grade_s_5','name'=>'小学五年级'],
['id'=>'grade_s_6','name'=>'小学六年级'],
['id'=>'grade_m_1','name'=>'初中一年级'],
['id'=>'grade_m_2','name'=>'初中二年级'],
['id'=>'grade_m_3','name'=>'初中三年级'],
['id'=>'grade_h_1','name'=>'高中一年级'],
['id'=>'grade_h_2','name'=>'高中二年级'],
['id'=>'grade_h_3','name'=>'高中三年级'],
['id'=>'grade_u_12','name'=>'大学一、二年级'],
['id'=>'grade_u_34','name'=>'大学三、四年级']
];
protected $grade_list2 = [
'nothing' => '无',
'grade_s_1' => '小学一年级',
'grade_s_2' => '小学二年级',
'grade_s_3' => '小学三年级',
'grade_s_4' => '小学四年级',
'grade_s_5' => '小学五年级',
'grade_s_6' => '小学六年级',
'grade_m_1' => '初中一年级',
'grade_m_2' => '初中二年级',
'grade_m_3' => '初中三年级',
'grade_h_1' => '高中一年级',
'grade_h_2' => '高中二年级',
'grade_h_3' => '高中三年级',
'grade_u_12' => '大学一、二年级',
'grade_u_34' => '大学三、四年级'
];
// 阶段性称谓
protected $stage_appellation = [
['min'=>'0','max'=>'3','value'=>'婴儿'],
['min'=>'3','max'=>'16','value'=>'儿童'],
['min'=>'16','max'=>'500','value'=>'成人']
];
// 加 bcadd(,,20)
// 减 bcsub(,,20)
// 乘 bcmul(,,20)
// 除 bcdiv(,,20)
// 测试token=>'caadd1be045a65f30b92aa805f1de54a'
################################################################接口################################################################
################################################################接口################################################################
################################################################接口################################################################
// 添加角色
public function add_member(){
try {
// 你的业务逻辑
$data = input('post.');
if(!array_key_exists('token', $data) || !array_key_exists('nickname', $data) || !array_key_exists('birthday', $data) || !array_key_exists('gender', $data) || !array_key_exists('height', $data) || !array_key_exists('weight', $data) || !array_key_exists('measure_model', $data)){
return $this->msg(10001);
}
if($data['measure_model'] != '1' && $data['measure_model'] != '2'){
return $this->msg(10001);
}
if(!$this->verify_data_is_ok($data['token'],'str')){
return $this->msg(10005,'token type error');
}
if(!$this->verify_data_is_ok($data['birthday'],'datetime')){
return $this->msg(10005,'birthday type error');
}
if(!$this->verify_data_is_ok($data['gender'],'intnum')){
return $this->msg(10005,'gender type error');
}
if(!$this->verify_data_is_ok($data['height'],'num')){
return $this->msg(10005,'height type error');
}
if(!$this->verify_data_is_ok($data['weight'],'num')){
return $this->msg(10005,'weight type error');
}
return $this->add_member_action($data);
} catch (\Exception $e) {
// 捕获异常
$logContent["flie"] = $e->getFile();
$logContent["line"] = $e->getLine();
$logContent['all_content'] = "异常信息:\n";
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
$this->record_api_log($data, $logContent, null);
return $this->msg(99999);
}
}
// 添加角色
public function update_member(){
try {
// 你的业务逻辑
$data = input('post.');
if(!array_key_exists('token', $data) || !array_key_exists('aud_id', $data) || !array_key_exists('nickname', $data) || !array_key_exists('birthday', $data) || !array_key_exists('gender', $data) || !array_key_exists('height', $data) || !array_key_exists('weight', $data) || !array_key_exists('measure_model', $data)){
return $this->msg(10001);
}
if($data['measure_model'] != '1' && $data['measure_model'] != '2'){
return $this->msg(10001);
}
if(!$this->verify_data_is_ok($data['token'],'str')){
return $this->msg(10005,'token type error');
}
if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
return $this->msg(10005,'aud_id type error');
}
if(!$this->verify_data_is_ok($data['birthday'],'datetime')){
return $this->msg(10005,'birthday type error');
}
if(!$this->verify_data_is_ok($data['gender'],'intnum')){
return $this->msg(10005,'gender type error');
}
if(!$this->verify_data_is_ok($data['height'],'num')){
return $this->msg(10005,'height type error');
}
if(!$this->verify_data_is_ok($data['weight'],'num')){
return $this->msg(10005,'weight type error');
}
return $this->update_member_action($data);
} catch (\Exception $e) {
// 捕获异常
$logContent["flie"] = $e->getFile();
$logContent["line"] = $e->getLine();
$logContent['all_content'] = "异常信息:\n";
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
$this->record_api_log($data, $logContent, null);
return $this->msg(99999);
}
}
// 添加角色
public function role_list(){
try {
// 你的业务逻辑
$data = input('post.');
if(!array_key_exists('token', $data)){
return $this->msg(10001);
}
if(!$this->verify_data_is_ok($data['token'],'str')){
return $this->msg(10005,'token type error');
}
return $this->role_list_action($data);
} catch (\Exception $e) {
// 捕获异常
$logContent["flie"] = $e->getFile();
$logContent["line"] = $e->getLine();
$logContent['all_content'] = "异常信息:\n";
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
$this->record_api_log($data, $logContent, null);
return $this->msg(99999);
}
}
################################################################action################################################################
################################################################action################################################################
public function add_member_action($data){
$aan_id = Db::table($this->role_db_name['zhanghao'])->where(['token'=>$data['token']])->field('id,token')->find();
if(!$aan_id){
return $this->msg(10002,'账号信息错误');
}
$parameter['aan_id'] = $aan_id['id'];
$parameter['nickname'] = $data['nickname'];
$parameter['birthday'] = $data['birthday'];
$parameter['gender'] = $data['gender'];
$parameter['height'] = $data['height'];
$parameter['weight'] = $data['weight'];
$parameter['head_pic'] = $data['gender'] == 2?'http://tc.pcxbc.com/tsf/2.png':'http://tc.pcxbc.com/tsf/1.png';
$parameter['card_order'] = '';
$parameter['create_time'] = date('Y-m-d H:i:s');
$parameter['last_update_time'] = $parameter['create_time'];
$parameter['measure_model'] = $data['measure_model'];
$is_nickname_ok = Db::table($this->role_db_name['juese'])->where(['nickname'=>$parameter['nickname'],'aan_id'=>$parameter['aan_id'],'is_del'=>0])->count();
if($is_nickname_ok>0){
return $this->msg(10002,'该角色已存在');
}
if($parameter['measure_model'] == 1){
if(!array_key_exists('grade',$data) || !array_key_exists('identity_id',$data) || !array_key_exists('address',$data)){
return $this->msg(10001);
}
if(!array_key_exists($data['identity_id'],$this->identity_list)){
return $this->msg(10005,'身份信息错误');
}
if(!array_key_exists($data['grade'],$this->grade_list2)){
return $this->msg(10005,'年级信息错误');
}
$parameter['grade'] = $data['grade'];
$parameter['identity_id'] = $data['identity_id'];
$parameter['identity_name'] = $this->identity_list[$data['identity_id']];
$parameter['address'] = $data['address'];
$address_data = Db::table($this->role_db_name['quyu_card'])->where(['province'=>explode(',',$parameter['address'])[0],'is_del'=>0])->field('id,recommend_cards')->find();
$parameter['card_order'] = $address_data['recommend_cards'];
}else{
$parameter['grade'] = 'nothing';
$parameter['identity_id'] = 'P0';
$parameter['identity_name'] = '陌生人';
$parameter['address'] = '';
}
if($parameter['identity_id'] != 'P0'){
$result = Db::table($this->role_db_name['juese'])->where(['identity_id'=>$parameter['identity_id'],'aan_id'=>$parameter['aan_id'],'is_del'=>0])->count();
if($result>0){
return $this->msg(10005,'该身份已存在');
}
}
$return_result = Db::table($this->role_db_name['juese'])->insert($parameter);
if($return_result){
return $this->msg([]);
}else{
return $this->msg(10002);
}
}
public function update_member_action($data){
$aan_id = Db::table($this->role_db_name['zhanghao'])->where(['token'=>$data['token']])->field('id,token')->find();
if(!$aan_id){
return $this->msg(10002,'账号信息错误');
}
// $parameter['aan_id'] = $aan_id['id'];
$parameter['nickname'] = $data['nickname'];
$parameter['birthday'] = $data['birthday'];
$parameter['gender'] = $data['gender'];
$parameter['height'] = $data['height'];
$parameter['weight'] = $data['weight'];
$parameter['head_pic'] = $data['gender'] == 2?'http://tc.pcxbc.com/tsf/2.png':'http://tc.pcxbc.com/tsf/1.png';
$parameter['last_update_time'] = date('Y-m-d H:i:s');
$parameter['measure_model'] = $data['measure_model'];
if($parameter['measure_model'] == 1){
if(!array_key_exists('grade',$data) || !array_key_exists('identity_id',$data) || !array_key_exists('address',$data)){
return $this->msg(10001);
}
if(!array_key_exists($data['identity_id'],$this->identity_list)){
return $this->msg(10005,'身份信息错误');
}
if(!array_key_exists($data['grade'],$this->grade_list2)){
return $this->msg(10005,'年级信息错误');
}
$parameter['grade'] = $data['grade'];
$parameter['identity_id'] = $data['identity_id'];
$parameter['identity_name'] = $this->identity_list[$data['identity_id']];
$parameter['address'] = $data['address'];
if($parameter['identity_id'] != 'P0'){
$result = Db::table($this->role_db_name['juese'])->where(['identity_id'=>$parameter['identity_id'],'aan_id'=>$aan_id['id'],'is_del'=>0])->count();
if($result>0){
return $this->msg(10005,'该身份已存在');
}
}
$address_data = Db::table($this->role_db_name['quyu_card'])->where(['province'=>explode(',',$parameter['address'])[0],'is_del'=>0])->field('id,recommend_cards')->find();
$parameter['card_order'] = $address_data['recommend_cards'];
}
$return_result = Db::table($this->role_db_name['juese'])->where(['id'=>$data['aud_id']])->update($parameter);
if($return_result){
return $this->msg([]);
}else{
return $this->msg(10002);
}
}
public function role_list_action($data){
if(array_key_exists('type', $data)){
if(!$this->verify_data_is_ok($data['type'],'intnum')){
return $this->msg(10005,'type type error');
}
}else{
$data['type'] = 1;
}
$user = Db::table($this->role_db_name['zhanghao'])->where(['token'=>$data['token']])->field('id,token')->find();
if(!$user){
return $this->msg(10002,'账号信息错误');
}
$result = Db::table($this->role_db_name['juese'])
->where(['aan_id'=>$user['id'],'is_del'=>0])
->field('id,aan_id,nickname,birthday,gender,card_order,target_weight,initial_weight,initial_date,grade,head_pic,weight,height,identity_name,address,identity_id,measure_model')
->select();
$temporary_data = [];
if($data['type'] == 1){
for ($i=0; $i < count($result); $i++) {
array_push($temporary_data,[
'id'=>$result[$i]['id'],
'nickname'=>$result[$i]['nickname'],
'identity_name'=>$result[$i]['identity_name'],
'identity_id'=>$result[$i]['identity_id'],
]);
}
}else{
for ($i=0; $i < count($result); $i++) {
$result[$i]['age'] = $this->calculate_age($result[$i]['birthday']);
// 添加阶段称谓、婴儿、儿童、成人
foreach ($this->stage_appellation as $key => $value) {
if($result[$i]['age'] >= $value['min'] && $result[$i]['age'] < $value['max']){
$result[$i]['stage'] = $value['value'];
}
}
}
$temporary_data = $result;
}
return $this->msg($temporary_data);
}
}

View File

@ -0,0 +1,124 @@
<?php
namespace app\app\controller;
use think\Db;
use PHPMailer\PHPMailer\PHPMailer;
class Wechat extends Base{
// reedaw的小程序信息
private $app_id = 'wx9c0b7a436ada6d1e'; // 微信小程序的AppID
private $app_secret = 'ed7cda5874f0eef3360e782a3db73c80'; // 微信小程序的AppSecret
// ed7cda5874f0eef3360e782a3db73c80
################################################################接口################################################################
################################################################接口################################################################
################################################################接口################################################################
/**
* 处理微信登录
*
* @param string $code 微信登录凭证
* @param string $encryptedData 加密的用户信息
* @param string $iv 解密算法的初始向量
* @return array
*/
public function handleWechatLogin($code, $encryptedData, $iv)
{
// try {
// 1. 通过code获取openid和session_key
$sessionData = $this->getSessionKey($code);
if (empty($sessionData['openid']) || empty($sessionData['session_key'])) {
// throw new Exception('获取openid或session_key失败');
// return false;
// return $this->msg(10001);
return ['code'=>10002,'msg'=>'获取openid或session_key失败'];
}
// 2. 解密用户信息
$userInfo = $this->decryptData($encryptedData, $iv, $sessionData['session_key']);
if(array_key_exists('phoneNumber',$userInfo)){
return ['code'=>0,'msg'=>'seccess','data'=>$userInfo];
}else{
return ['code'=>10002,'msg'=>'解密用户信息失败'];
}
// if (empty($userInfo['phoneNumber'])) {
// // throw new Exception('获取手机号失败');
// }else{
// }
// // 3. 保存或更新用户信息
// $user = User::where('openid', $sessionData['openid'])->find();
// if (!$user) {
// $user = new User();
// $user->openid = $sessionData['openid'];
// }
// $user->phone = $userInfo['phoneNumber'];
// $user->save();
// 返回成功信息
// return ['code' => 0, 'msg' => '登录成功', 'data' => $user];
// } catch (Exception $e) {
// // 返回错误信息
// return ['code' => 500, 'msg' => $e->getMessage()];
// }
}
/**
* 通过code获取openid和session_key
*
* @param string $code
* @return array
* @throws Exception
*/
private function getSessionKey($code)
{
$url = "https://api.weixin.qq.com/sns/jscode2session?appid={$this->app_id}&secret={$this->app_secret}&js_code={$code}&grant_type=authorization_code";
$result = file_get_contents($url);
$data = json_decode($result, true);
if (isset($data['openid']) && isset($data['session_key'])) {
return $data;
} else {
return ['code'=>10002,'msg'=>'获取openid或session_key失败'];
}
}
/**
* 解密用户信息
*
* @param string $encryptedData
* @param string $iv
* @param string $sessionKey
* @return array
* @throws Exception
*/
private function decryptData($encryptedData, $iv, $sessionKey)
{
// require_once 'wx_crypt/WXBizDataCrypt.php'; // 引入微信解密类
// require_once env('root_path') . 'extend/wx_crypt/WXBizDataCrypt.php';
// dump(ROOT_PATH . 'extend\wx_crypt\wxBizDataCrypt.php');
require_once ROOT_PATH . 'extend\wx_crypt\wxBizDataCrypt.php';
$pc = new \WXBizDataCrypt($this->app_id, $sessionKey);
$errCode = $pc->decryptData($encryptedData, $iv, $data);
if ($errCode == 0) {
return json_decode($data, true);
} else {
return ['code'=>10002,'msg'=>'解密用户信息失败('.$errCode.')'];
// throw new Exception('解密失败: ' . $errCode);
}
}
// 注册
}

View File

@ -437,7 +437,7 @@ class Login extends Base{
// dump($result); // dump($result);
$road = 'tel'; $road = 'tel';
}else{ }else{
$result = $this->send_email_code([$data['data']],['title'=>'体测APP验证码','from_user_name'=>'体测APP','content'=>$num]); $result = $this->send_email_code([$data['data']],['title'=>'Reedaw验证码','from_user_name'=>'Reedaw验证码','content'=>$num]);
$road = 'email'; $road = 'email';
} }
if(is_array($result) && $result['code'] == 0){ if(is_array($result) && $result['code'] == 0){

View File

@ -28,7 +28,10 @@ class Msginformation extends Base{
// 获取板块,及板块下类型标签 // 获取板块,及板块下类型标签
public function get_sector_label_msg($data = ['token'=>'6441bf7dabea7b3360a30240d3b19fc5']){ public function get_sector_label_msg($data = ['token'=>'6441bf7dabea7b3360a30240d3b19fc5']){
try { try {
// 你的业务逻辑
if(count(input('post.')) > 0){
$data = input('post.'); $data = input('post.');
}
if(!array_key_exists('token', $data)){ if(!array_key_exists('token', $data)){
return $this->msg(10001); return $this->msg(10001);
} }
@ -148,7 +151,7 @@ class Msginformation extends Base{
return $this->msg(10005); return $this->msg(10005);
} }
$return_result = $this->get_recommend_information_action($data); $return_result = $this->get_recommend_information_action($data);
$this->record_api_log($data, null, $return_result); // $this->record_api_log($data, null, $return_result);
return $return_result; return $return_result;
} catch (\Exception $e) { } catch (\Exception $e) {
// 捕获异常 // 捕获异常

View File

@ -651,6 +651,29 @@ Route::any('/de/admin/device/index', 'app/DeviceEnter/admin.device/index');
Route::any('/de/admin/device/device_list', 'app/DeviceEnter/admin.device/device_list'); Route::any('/de/admin/device/device_list', 'app/DeviceEnter/admin.device/device_list');
Route::any('/de/admin/device/device_all', 'app/DeviceEnter/admin.device/device_all'); Route::any('/de/admin/device/device_all', 'app/DeviceEnter/admin.device/device_all');
################################################################下面是新版reedaw体侧+厨房秤)################################################################
#############################################################################################################################################################
################################################################接口(管理后台)
################################################################接口API
// 默认配置
Route::any('/reedaw/config', 'app/NewReedaw/app.index/config');
################################################################登录注册部分
// 注册账号
Route::any('/reedaw/register', 'app/NewReedaw/app.login/register');
// 登录账号
Route::any('/reedaw/login', 'app/NewReedaw/app.login/login');
################################################################角色部分
// 创建角色
Route::any('/reedaw/add_member', 'app/NewReedaw/app.role/add_member');
// 更新角色
Route::any('/reedaw/update_member', 'app/NewReedaw/app.role/update_member');
// 获取角色列表
Route::any('/reedaw/role_list', 'app/NewReedaw/app.role/role_list');
################################################################身体报告部分
// 获取角色报告
Route::any('/reedaw/body_report', 'app/NewReedaw/app.body/body_report');