部分调整

This commit is contained in:
tsf 2024-04-22 17:29:33 +08:00
parent d194214cc4
commit 276a5c4047
3 changed files with 188 additions and 133 deletions

View File

@ -0,0 +1,117 @@
<?php
namespace app\app\controller;
use think\Controller;
use think\Db;
class Base extends Controller{
protected $base_call_method = ['内部'];
################################################################接口################################################################
################################################################接口################################################################
################################################################接口################################################################
// 操作记录留存
// $data = ['aud_id'=>'xxxxxxxxxxxxxxx','order_list'=>[1,2,3,4,5]]
public function abnormal_data_log_action($dacall_methoda = 0,$content='未记录的内容',$use_database_name='未记录的数据库名'){
$result = Db::table('app_data_log')->insert([
'create_time'=>date('Y-m-d H:i:s'),
'call_method'=>$this->base_call_method[$dacall_methoda],
'content'=>$content,
'use_database_name'=>$use_database_name,
]);
}
// 检查变量是否是一个只有数字的一维数组
function isNumericArray($array = [1,2,3]) {
if (!is_array($array)) {
return false; // 变量不是数组
}
foreach ($array as $value) {
if (!is_numeric($value)) {
return false; // 数组中包含非数字元素
}
}
// $result = Db::table('app_card_data')->where(['is_del'=>1])->cache(true,3600)->column('id');//查询结果缓存3600秒
$result = Db::table('app_card_data')->where(['is_del'=>0])->cache(true,3600)->select();//查询结果缓存3600秒
// dump(array_column($result, 'id'));
// die;
if(empty(array_diff($array, array_column($result, 'id')))){
return true;// 数组是一维的且只包含数字,且已经跟数据库比对过,每个数值都是有效
}else{
return false;//跟数据库比对过,存在无效数值
}
}
// 计算年龄
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;
}
}
// 计算天数
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');
}
// 计算月份
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);
return $ageInMonthsPrecise;
}
// 绑定设备
public function bind_device_action($data = ['serial_number'=>'','machine_code'=>'','account_id'=>0]){
}
public function msg($code,$msg='',$data=[]){
return json(['code'=>$code,'msg'=>$msg,'data'=>$data]);
}
}

View File

@ -9,7 +9,7 @@ use think\Log;
use \think\Validate;
use app\app\controller\Calculatebody;
class Card extends Controller{
class Card extends Base{
protected $color = ['#FF5656','#FFAB00','#5AD06D','#6492F6','#3967D6'];
protected $age_limit = 16;
@ -473,146 +473,16 @@ class Card extends Controller{
return $result_end_data;
}
################################################################跳绳数据卡片接口################################################################
################################################################跳绳数据卡片接口################################################################
################################################################other################################################################
################################################################other################################################################
################################################################other################################################################
// 检查变量是否是一个只有数字的一维数组
function isNumericArray($array = [1,2,3]) {
if (!is_array($array)) {
return false; // 变量不是数组
}
foreach ($array as $value) {
if (!is_numeric($value)) {
return false; // 数组中包含非数字元素
}
}
// $result = Db::table('app_card_data')->where(['is_del'=>1])->cache(true,3600)->column('id');//查询结果缓存3600秒
$result = Db::table('app_card_data')->where(['is_del'=>0])->cache(true,3600)->select();//查询结果缓存3600秒
// dump(array_column($result, 'id'));
// die;
if(empty(array_diff($array, array_column($result, 'id')))){
return true;// 数组是一维的且只包含数字,且已经跟数据库比对过,每个数值都是有效
}else{
return false;//跟数据库比对过,存在无效数值
}
}
// 计算年龄
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;
}
}
// 计算天数
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');
}
// 计算月份
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);
return $ageInMonthsPrecise;
}
// 计算肌肉率 删
function calculate_jiroulv(){
phpinfo();
die;
$result = $result = Db::table('pc_weightstand')->order('Month')->select();
for ($i=0; $i < count($result); $i++) {
$data[$i]['month'] = $result[$i]['Month']*100/100;
$data[$i]['sex'] = $result[$i]['Sex'];
$data[$i]['f3sd'] = $result[$i]['f1sd']*100/100;
$data[$i]['f2sd'] = $result[$i]['f1sd']*100/100;
$data[$i]['f1sd'] = $result[$i]['f1sd']*100/100;
$data[$i]['median'] = $result[$i]['median']*100/100;
$data[$i]['z1sd'] = $result[$i]['z1sd']*100/100;
$data[$i]['z2sd'] = $result[$i]['z2sd']*100/100;
$data[$i]['z3sd'] = $result[$i]['z3sd']*100/100;
$data[$i]['isdel'] = $result[$i]['IsDeleted'];
$data[$i]['create_time'] = date('Y-m-d H:i:s');
}
$result = $result = Db::table('pc_weightstand2')->insertAll($data);
dump($result);
dump($data);
die;
}
// 计算骨重
function calculate_guzhong(){
}
// 计算蛋白率
function calculate_danbailv(){
}
// 计算基础代谢
function calculate_jichudaixie(){
}
// 计算内脏指数
function calculate_neizangzhishu(){
}
// 计算皮下脂肪
function calculate_pixiazhifang(){
}
// 计算肥胖等级
function calculate_feipangdengji(){
}
public function msg($code,$msg='',$data=[]){
return json(['code'=>$code,'msg'=>$msg,'data'=>$data]);
}
}

View File

@ -0,0 +1,68 @@
<?php
namespace app\app\controller;
use think\Controller;
use think\Db;
class Skip extends Base{
protected $color = ['#FF5656','#FFAB00','#5AD06D','#6492F6','#3967D6'];
protected $result_end_data_mould = [
'name'=>'',
'value'=>'',
'unit'=>'',
'standard'=>'',
'color'=>'',
'list'=>[]
];
################################################################接口################################################################
################################################################接口################################################################
################################################################接口################################################################
// 查找设备
// $data = ['device_code'=>'asdkljiouoi']
public function device_check($data = ['device_code'=>'asdkljiouoi']){
$data = input();
$result = Db::query("
select
adcd.id,
adcd.state as activation_state,
add.state as device_state,
from app_device_code_data as adcd
left join app_device_data as add on add.id = adcd.add_id
where
adcd.machine_code = '{$data['device_code']}'
");
if(count($result) == 1){
return $this->msg(0,'success',['device_state'=>$result[0]['device_state'],'activation_state'=>$result[0]['activation_state']]);
}else if(count($result) < 1){
return $this->msg(10001,'未找到设备');
}else{
$this->abnormal_data_log_action(0,'device_check-设备查询出错,结果为'.count($result).'合理值应为1或0','app_device_code_data,app_device_data');
return $this->msg(10002,'未找到设备');
}
}
################################################################跳绳数据卡片接口################################################################
################################################################跳绳数据卡片接口################################################################
################################################################other################################################################
################################################################other################################################################
################################################################other################################################################
}