diff --git a/application/KitchenScale2/controller/admin/Base.php b/application/KitchenScale2/controller/admin/Base.php
new file mode 100644
index 0000000..38be76b
--- /dev/null
+++ b/application/KitchenScale2/controller/admin/Base.php
@@ -0,0 +1,172 @@
+'test_app_data_log',
+ ];
+ protected $return_data_all = [
+ '10001'=>'关键参数缺失',
+ '10002'=>'操作失败',
+ '10003'=>'信息核实错误',
+ '10004'=>'未找到有效数据',
+ '10005'=>'参数格式错误',
+ '10006'=>'参数不能为空',
+ '10007'=>'参数错误',
+ '10008'=>'',
+ '10009'=>'',
+ '10010'=>'自定义信息',
+ '20001'=>'登录失效',
+ '99999'=>'网络异常,请稍后重试',
+ ];
+ protected $file_max = 1024*1024*2;//xxxMB
+ // 加 bcadd(,,20)
+ // 减 bcsub(,,20)
+ // 乘 bcmul(,,20)
+ // 除 bcdiv(,,20)
+ ################################################################接口################################################################
+ ################################################################接口################################################################
+ ################################################################接口################################################################
+
+
+
+ // 验证
+ public function verify_data_is_ok($data = 2,$type){
+ if($type == 'str'){
+ if (is_string($data)) {
+ return true;
+ } else {
+ $this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为字符串',[]]);
+ return false;
+ }
+ }else if($type == 'num'){
+ if (is_numeric($data)) {
+ return true;
+ } else {
+ $this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为数字',[]]);
+ return false;
+ }
+ }else if($type == 'intnum'){
+ $pattern = '/^\d+$/';
+ if (preg_match($pattern, $data)) {
+ return true; // 匹配成功,返回 true
+ } else {
+ $this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为整数数字',[]]);
+ return false; // 匹配失败,返回 false
+ }
+ }else if($type == '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;
+ }
+ }
+ // 如果所有格式都解析失败,则返回 false
+ $this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为日期格式',[]]);
+ return false;
+ }else if($type == 'other'){
+
+ }
+ }
+
+ ####################################################图片选择上传start##############################################################
+ public function pic_index($page = 1) {
+ $data = input();
+ $pd = true;
+ if(array_key_exists('page',$data)){
+ $page = $data['page'];
+ $pd = false;
+ }
+ $cfc = Db::connect('cfc_db');
+ $num = $cfc->table('app_user_upload_img')->where(['special_record_str'=>'admin'])->count();
+ $result = $cfc->table('app_user_upload_img')->where(['special_record_str'=>'admin'])->order('id desc')->page($page,20)->field('id,pic_url')->select();
+ if(!$pd){
+ $return_result['num'] = $num;
+ $return_result['result'] = $result;
+ return $this->msg(0,'success',$return_result);
+ }
+ $this->assign([
+ 'result' => $result,
+ 'num' => $num,
+ ]);
+ return $this->fetch();
+ }
+ public function pic_upload_action(){
+
+ $save_data = [];
+ $error_data = [];
+ // 获取表单上传文件
+ $files = request()->file('image');
+ foreach($files as $file){
+ $name = $file->getInfo()['name'];
+ // 使用 pathinfo() 函数获取文件名的扩展名
+ $pathinfo = pathinfo($name);
+ $extension = strtolower($pathinfo['extension']); // 转换为小写以进行不区分大小写的比较
+ $file_name = $pathinfo['filename'];
+ // 判断扩展名是否不是 .png 或 .gif
+ if ($extension !== 'png' && $extension !== 'gif') {
+ // 修改文件名,将扩展名改为 .jpg
+ $new_filename = date('YmdHis').$file_name . '.jpg';
+ } else {
+ $new_filename = date('YmdHis').$name;
+ }
+ $info = $file->validate(['size'=>$this->file_max,'ext'=>'jpg,png,gif'])->move(ROOT_PATH . 'public' . DS . 'kitchenscale_all' . DS . 'user_upload',$new_filename);
+ if($info){
+ array_push($save_data,[
+ 'user_token'=>'caadd1be045a65f30b92aa805f1de54a',
+ 'pic_name'=>$new_filename,
+ 'pic_url'=>'https://tc.pcxbc.com/kitchenscale_all/user_upload/'.$new_filename,
+ 'create_time'=>date('Y-m-d H:i:s'),
+ 'special_record_str'=>'admin',
+ 'operate_log'=>1
+ ]);
+ }else{
+ array_push($error_data,[
+ 'pic_name'=>$name,
+ 'error_msg'=>$file->getError(),
+ ]);
+ }
+ }
+ $cfc = Db::connect('cfc_db');
+ $pic_result = $cfc->table('app_user_upload_img')->insertAll ($save_data);
+ if($pic_result){
+ return $this->msg(['success'=>count($save_data),'error_data'=>$error_data]);
+ }else{
+ for ($i=0; $i < count($save_data); $i++) {
+ unlink(ROOT_PATH . 'public' . DS . 'kitchenscale_all' . DS . 'user_upload' . DS . $new_filename);
+ }
+ return $this->msg(10002,'图片数据保存失败');
+ }
+ }
+
+ ####################################################图片选择上传end##############################################################
+
+
+ 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]);
+ }
+ }
+
+
+
+}
\ No newline at end of file
diff --git a/application/KitchenScale2/controller/admin/Cookbook.php b/application/KitchenScale2/controller/admin/Cookbook.php
new file mode 100644
index 0000000..48589cd
--- /dev/null
+++ b/application/KitchenScale2/controller/admin/Cookbook.php
@@ -0,0 +1,178 @@
+=',$data['s_time']];
+ // }
+ // if($data['e_time']){
+ // $parameter['create_time'] = ['<=',$data['e_time']];
+ // }
+ }
+ $where = '1=1';
+ $cfc = Db::connect('cfc_db');
+ $num = $cfc->table('app_user_cookbook')->where($parameter)->count();
+ $sql = "
+ SELECT
+ a.id,
+ a.title,
+ a.create_user_nickname,
+ a.likes_num,
+ a.read_it,
+ a.is_del,
+ a.create_time,
+ b.pic_url
+ FROM
+ app_user_cookbook a
+ LEFT JOIN
+ app_user_upload_img b ON a.cover = b.id
+ WHERE
+ $where
+ ORDER BY
+ a.id DESC
+ OFFSET (".($page - 1)." * ".$this->page_num.") ROWS
+ FETCH NEXT ".$this->page_num." ROWS ONLY;
+ ";
+ $result = $cfc->query($sql);
+
+ if(!$pd){
+ $return_data['num'] = $num;
+ $return_data['data'] = $result;
+ return $this->msg($return_data);
+ }
+ $this->assign([
+ 'result' => $result,
+ 'num' => $num,
+ ]);
+ return $this->fetch();
+
+ }
+
+ public function add_cookbook(){
+ $cfc = Db::connect('cfc_db');
+ $result = $cfc->table('app_user_cookbook_label')->where(['is_del'=>0])->select();
+ $this->assign([
+ 'result' => $result,
+ ]);
+ return $this->fetch();
+ }
+
+ public function add_cookbook_action(){
+ $data = input();
+ $cfc = Db::connect('cfc_db');
+ // dump($data);
+ // 处理食谱数据
+ $id_list = [];
+ $food_cookbook_relationship = [];
+ foreach ($data['foodList'] as $key => $value) {
+ if(!in_array($value['id'],$id_list)){
+ array_push($id_list,$value['id']);
+ array_push($food_cookbook_relationship,[
+ 'cookbook_id' => '',
+ 'food_id' => $value['id']
+ ]);
+ }
+ }
+ $kcal_data = $cfc->table('app_z_national_standard_food_type_3')->where("id in (".implode(',',$id_list).")")->field('id,Calorie_val')->select();
+ for ($i=0; $i < count($kcal_data); $i++) {
+ $id_list[$kcal_data[$i]['id']] = $kcal_data[$i]['Calorie_val'];
+ }
+ foreach ($data['foodList'] as $key => $value) {
+ $data['foodList'][$key]['kcal'] = bcmul(bcdiv($value['weight'],100,20),$id_list[$value['id']],2);
+ $data['foodList'][$key]['unit'] = 'g';
+ }
+
+ // 设置食谱信息
+ $cookbook_data = [
+ 'title'=>$data['title'],
+ 'cover'=>$data['cover'],
+ 'create_user_token'=>'caadd1be045a65f30b92aa805f1de54a',
+ 'create_user_head_pic'=>'https://tc.pcxbc.com/tsf/head_pic.png',
+ 'create_user_nickname'=>'clown',
+ 'describe_data'=>$data['description'],
+ 'food_data'=>json_encode($data['foodList']),
+ 'step_data'=>json_encode($data['stepList']),
+ 'create_time'=>date('Y-m-d H:i:s'),
+ 'original_cookbook_id'=>'admin',
+ 'cook_label'=>$data['cook_label'],
+ 'is_del'=>1,
+
+ ];
+
+ $cfc->startTrans();
+ try {
+
+ $cookbook_id = $cfc->table('app_user_cookbook')->insertGetId($cookbook_data);
+ for ($i=0; $i < count($food_cookbook_relationship); $i++) {
+ $food_cookbook_relationship[$i]['cookbook_id'] = $cookbook_id;
+ }
+ $cfc->table('app_user_cookbook_food_relation')->insertAll($food_cookbook_relationship);
+ $cfc->commit();
+ return $this->msg([]);
+ } catch (\Exception $e) {
+ $cfc->rollback();
+ return $this->msg(10002,'数据保存失败,'.$e->getMessage());
+ }
+
+ }
+
+ public function stop_and_run(){
+ $data = input();
+ $cfc = Db::connect('cfc_db');
+ $result = $cfc->table('app_user_cookbook')->where(['id'=>$data['id']])->update(['is_del'=>$data['status']]);
+ if($result){
+ return $this->msg([]);
+ }else{
+ return $this->msg(10002);
+ }
+ }
+
+
+
+
+ public function find_food_list(){
+ $data = input();
+ $cfc = Db::connect('cfc_db');
+ $result = $cfc->table('app_z_national_standard_food_type_3')->where("food_name like '%". $data['search_data'] ."%'")->field('id,food_name,Calorie_val')->select();
+ return $this->msg(0,'success',$result);
+ }
+
+
+}
\ No newline at end of file
diff --git a/application/KitchenScale2/controller/admin/Index.php b/application/KitchenScale2/controller/admin/Index.php
new file mode 100644
index 0000000..f06f5e1
--- /dev/null
+++ b/application/KitchenScale2/controller/admin/Index.php
@@ -0,0 +1,30 @@
+assign('domain',$a);
+ return $this->fetch();
+ }
+
+ public function welcome(){
+ // $this->assign('domain',$a);
+ return $this->fetch();
+ }
+
+}
\ No newline at end of file
diff --git a/application/KitchenScale2/controller/admin/Login.php b/application/KitchenScale2/controller/admin/Login.php
new file mode 100644
index 0000000..2f0eddf
--- /dev/null
+++ b/application/KitchenScale2/controller/admin/Login.php
@@ -0,0 +1,40 @@
+fetch();
+
+ }
+ // 检测登录信息是否超时
+ public function login_action(){
+ $data = input();
+ // 验证数据项是否完整
+ if(!array_key_exists('username', $data) || !array_key_exists('password', $data)){
+ return $this->msg(10001);
+ }
+ $cfc = Db::connect('cfc_db');
+ $account = $cfc->table('admin_user_account_number')->where(['account_num'=>$data['username'],'password'=>$data['password']])->count();
+ if($account>0){
+ return $this->msg([]);
+ }else{
+ return $this->msg(10003);
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/application/KitchenScale2/controller/app/Aipart.php b/application/KitchenScale2/controller/app/Aipart.php
new file mode 100644
index 0000000..5af96e3
--- /dev/null
+++ b/application/KitchenScale2/controller/app/Aipart.php
@@ -0,0 +1,144 @@
+'app_user_cookbook',//菜谱表
+ 'foodlist3'=>'app_z_national_standard_food_type_3',//食材列表3
+ 'user'=>'app_user_data',//banner
+ ];
+
+ // 百度接口参数
+ protected $baidu_api_key = "3WRiEJgo0P0Zz3bmV3V1kJsS";
+ protected $baidu_secret_key = "yUNCE4QpuO8Ht7kmZm7IRFwr1kECCFv4";
+ protected $baidu_accesstoken_expire_time = 432000;//5天
+
+ // 加 bcadd(,,20)
+ // 减 bcsub(,,20)
+ // 乘 bcmul(,,20)
+ // 除 bcdiv(,,20)
+ ################################################################百度接口################################################################
+ ################################################################百度接口################################################################
+ ################################################################百度接口################################################################
+
+
+ // 百度图片识别食材
+ public function baidu_identify_food(){
+
+ try {
+ // 你的业务逻辑
+ if(count(input('post.')) > 0){
+ $data = input('post.');
+ }
+ if(!array_key_exists('token', $data)){
+ return $this->msg(10001);
+ }
+ if(!array_key_exists('img_str', $data)){
+ return $this->msg(10001);
+ }
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005);
+ }
+ if(!$this->verify_data_is_ok($data['img_str'],'str')){
+ return $this->msg(10005);
+ }
+ $result = $this->baidu_identify_food_action($data['img_str']);
+ return $result;
+ } 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";
+ // dump($data);
+ // die;
+ $this->record_api_log($data, $logContent, null);
+ return $this->msg(99999);
+ }
+
+ }
+
+
+ // 识别食材
+ private function baidu_identify_food_action($img_str){
+ // dump($str);
+ $access_token = $this->baidu_get_accesstoken();
+ if($access_token == false){
+ return $this->msg(10002,'识别失败01');
+ }
+ // dump($access_token);
+ // die;
+ $curl = curl_init();
+ curl_setopt_array($curl, array(
+ CURLOPT_URL => "https://aip.baidubce.com/rest/2.0/image-classify/v1/classify/ingredient?access_token=".$access_token,
+ CURLOPT_TIMEOUT => 30,
+ CURLOPT_RETURNTRANSFER => true,
+ CURLOPT_SSL_VERIFYPEER => false,
+ CURLOPT_SSL_VERIFYHOST => false,
+ CURLOPT_CUSTOMREQUEST => 'POST',
+ CURLOPT_POSTFIELDS => http_build_query(array(
+ 'image' => $img_str,
+ 'top_num'=>10
+ )),
+ CURLOPT_HTTPHEADER => array(
+ 'Content-Type: application/x-www-form-urlencoded',
+ 'Accept: application/json'
+ ),
+ ));
+ $response = curl_exec($curl);
+ curl_close($curl);
+ $result = json_decode($response,true);
+ if(array_key_exists('result',$result)){
+ // return ['code'=>0,'data'=>$result['result']];
+ return $this->msg(['name'=>$result['result'][0]['name']]);
+ }else{
+ return $this->msg(10002,'识别失败02');
+ }
+ }
+
+ // 获取AccessToken
+ private function baidu_get_accesstoken(){
+ $baidu_cache = cache('baidu_accesstoken');
+ if($baidu_cache != false){
+ // dump($baidu_cache);
+ // die;
+ return $baidu_cache;
+ }
+ $baidu_cache = cache('baidu_accesstoken');
+ $curl = curl_init();
+ $postData = array(
+ 'grant_type' => 'client_credentials',
+ 'client_id' => $this->baidu_api_key,
+ 'client_secret' => $this->baidu_secret_key
+ );
+ curl_setopt_array($curl, array(
+ CURLOPT_URL => 'https://aip.baidubce.com/oauth/2.0/token',
+ CURLOPT_CUSTOMREQUEST => 'POST',
+ CURLOPT_SSL_VERIFYPEER => false,
+ CURLOPT_SSL_VERIFYHOST => false,
+ CURLOPT_RETURNTRANSFER => true,
+ CURLOPT_POSTFIELDS => http_build_query($postData)
+ ));
+ $response = curl_exec($curl);
+ curl_close($curl);
+ $rtn = json_decode($response,true);
+ // dump($rtn);
+ if(array_key_exists('access_token',$rtn)){
+ cache('baidu_accesstoken', $rtn['access_token'], ($rtn['expires_in']-$this->baidu_accesstoken_expire_time));
+ return $rtn['access_token'];
+ }else{
+ return false;
+ }
+ }
+
+
+}
\ No newline at end of file
diff --git a/application/KitchenScale2/controller/app/Base.php b/application/KitchenScale2/controller/app/Base.php
new file mode 100644
index 0000000..1ad5e86
--- /dev/null
+++ b/application/KitchenScale2/controller/app/Base.php
@@ -0,0 +1,561 @@
+'app_account_number',
+ 'search_history'=>'app_user_search_history',
+ 'foodlist4'=>'app_z_national_standard_food_type_4'
+ ];
+ protected $token_time = 30;//30天的秒数
+ protected $file_size = 5*1024*1024;
+ protected $return_data_all = [
+ '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){
+ // dump($params);
+ // dump($error);
+ // die;
+ $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'=>'接口报错','from_user_name'=>'厨房秤(后台)','content'=>$logContent]);
+ }
+ }
+ if ($response) {
+ $logContent .= "返回信息:" . json_encode($response, JSON_UNESCAPED_UNICODE) . PHP_EOL;
+ }
+ // 使用ThinkPHP的日志记录方法
+ Log::record($logContent, 'api_log');
+ }
+
+
+
+ /* 接口说明(发邮件)
+ * $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';
+ }
+ }
+
+ ################################################################通用工具################################################################
+ ################################################################通用工具################################################################
+ ################################################################通用工具################################################################
+ // 判断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 false;
+ }
+ }else{
+ Log::record('用户尝试更新token时间,token:' . $token.',但是更新token失败,不是字符串', 'token_log');
+ return false;
+ }
+
+ $user_login = Db::table($this->base_use_db_name['6'])->where(['token'=>$token])->field('id,login_time')->find();
+ if(!$user_login){
+ Log::record('用户尝试更新token时间,token:' . $token.',但是更新token失败,未找到用户token', 'token_log');
+ return false;
+ }
+
+ // 创建 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 false;
+ } 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 true;
+ }else{
+ Log::record('用户尝试更新token时间,token:' . $token.',但是更新token失败,数据库更新时间未成功', 'token_log');
+ return true;
+ }
+
+ }
+ }
+ // 验证数据类型
+ public function verify_data_is_ok($data = 2,$type){
+ if($type == 'str'){
+ if (is_string($data)) {
+ return true;
+ } else {
+ $this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为字符串',[]]);
+ return false;
+ }
+ }else if($type == 'num'){
+ if (is_numeric($data)) {
+ return true;
+ } else {
+ $this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为数字',[]]);
+ return false;
+ }
+ }else if($type == 'intnum'){
+ $pattern = '/^\d+$/';
+ // dump($data);
+ if (preg_match($pattern, $data)) {
+ return true; // 匹配成功,返回 true
+ } else {
+ $this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为整数数字',[]]);
+ return false; // 匹配失败,返回 false
+ }
+ }else if($type == '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;
+ }
+ }
+ // 如果所有格式都解析失败,则返回 false
+ $this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为日期格式',[]]);
+ return false;
+ }else if($type == 'other'){
+
+ }
+ }
+ // 计算年龄
+ 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;
+ }
+ }
+ // 计算常规卡路里
+ public function count_user_nutrition_all($data){
+ // 计算基础代谢率(BMR)
+ if($data['gender'] == 1){
+ // 男性:BMR = 10 × 体重(kg) + 6.25 × 身高(cm) - 5 × 年龄(岁) + 5
+ $bmr = bcmul(10,$data['weight'],20);
+ $bmr = bcadd($bmr,bcmul(6.25,$data['height'],20),20);
+ $bmr = bcsub($bmr,bcmul(5,$data['age_num'],20),20);
+ $bmr = bcadd($bmr,5,2);
+ }else if($data['gender'] == 2){
+ // 女性:BMR = 10 × 体重(kg) + 6.25 × 身高(cm) - 5 × 年龄(岁) - 161
+ $bmr = bcmul(10,$data['weight'],20);
+ $bmr = bcadd($bmr,bcmul(6.25,$data['height'],20),20);
+ $bmr = bcsub($bmr,bcmul(5,$data['age_num'],20),20);
+ $bmr = bcsub($bmr,161,2);
+ }else{
+ return $this->msg(10003,'性别未知');
+ }
+
+ // 每日总能量消耗(TDEE)
+ // 久坐(很少或没有运动):BMR × 1.2
+ // 轻度活动(每周1-3天轻度运动):BMR × 1.375
+ // 中度活动(每周3-5天中度运动):BMR × 1.55
+ // 高度活动(每周6-7天高强度运动):BMR × 1.725
+ // 极高活动(体力劳动或每天高强度训练):BMR × 1.9
+ $tdee = bcmul($bmr,1.55,2);
+
+ // 碳水化合物:通常占总热量的45-65%
+ // 蛋白质:通常占总热量的10-35%
+ // 脂肪:通常占总热量的20-35%
+ // 孩子&成年人:碳水化合物50%,蛋白质20%,脂肪30%。
+ // 老人:碳水化合物50%,蛋白质25%,脂肪25%。
+ // 建议每日摄入量计算:
+ // 1.碳水化合物(克): (TDEE × 碳水化合物比例) / 4
+ // 2.蛋白质(克):(TDEE × 蛋白质比例) / 4
+ // 3.脂肪(克): (TDEE × 脂肪比例) / 9
+ $carbohydrate = bcdiv(bcmul($tdee,0.5,20),4,2);
+ if($data['age_num'] < 65){
+ $protein = bcdiv(bcmul($tdee,0.2,20),4,2);
+ $fat = bcdiv(bcmul($tdee,0.3,20),9,2);
+ }else{
+ $protein = bcdiv(bcmul($tdee,0.25,20),4,2);
+ $fat =bcdiv(bcmul($tdee,0.25,20),9,2);
+ }
+ return ['kcal'=>$tdee,'carbohydrate'=>$carbohydrate,'protein'=>$protein,'fat'=>$fat,'bmr'=>$bmr];
+ }
+
+ // 计算营养物质
+ public function calculate_nutrients($data){
+ // dump($data);
+ $food_id_arr = [];
+ for ($i=0; $i < count($data); $i++) {
+ $food_id_arr[] = $data[$i]['food_id'];
+ }
+
+ $cfc = Db::connect('cfc_db');
+ $nutrients_list = $cfc->table($this->base_use_db_name['foodlist4'])
+ ->where("father_id in ('".implode("','",$food_id_arr)."')")
+ // ->field()
+ ->select();
+
+ $nutrients_arr = ['VitaminA','VitaminB1','VitaminB2','VitaminB6','VitaminB12','VitaminD','VitaminK','Niacin','VitaminC','VitaminE','FolicAcid','Biotin','PantothenicAcid','TotalCholine','Ca','Phosphorus','Kalium','Mg','Na','Fe','Zn','Se','Cu','Mn','Iodine'];
+ // dump($nutrients_list);
+ // 加 bcadd(,,20)
+ // 减 bcsub(,,20)
+ // 乘 bcmul(,,20)
+ // 除 bcdiv(,,20)
+ for ($i=0; $i < count($data); $i++) {
+ $data[$i]['nutrients_four'][] = [
+ 'name' => '卡路里',
+ 'unit' => 'kcal',
+ 'color' => '',
+ 'value' => $data[$i]['kcal_val'],
+ 'proportion' => 0,
+ ];
+ $data[$i]['nutrients_four'][] = [
+ 'name' => '蛋白质',
+ 'unit' => 'g',
+ 'color' => '#5180D8',
+ 'value' => $data[$i]['protein_val'],
+ 'proportion' => bcmul(bcdiv($data[$i]['protein_val'],bcadd($data[$i]['protein_val'],bcadd($data[$i]['fat_val'],$data[$i]['carbohydrate_val'],20),20),2),100,0),
+ ];
+ $data[$i]['nutrients_four'][] = [
+ 'name' => '脂肪',
+ 'unit' => 'g',
+ 'color' => '#ED7886',
+ 'value' => $data[$i]['fat_val'],
+ 'proportion' => bcmul(bcdiv($data[$i]['fat_val'],bcadd($data[$i]['protein_val'],bcadd($data[$i]['fat_val'],$data[$i]['carbohydrate_val'],20),20),2),100,0),
+ ];
+ $data[$i]['nutrients_four'][] = [
+ 'name' => '碳水化合物',
+ 'unit' => 'g',
+ 'color' => '#FFB169',
+ 'value' => $data[$i]['carbohydrate_val'],
+ 'proportion' => bcmul(bcdiv($data[$i]['carbohydrate_val'],bcadd($data[$i]['protein_val'],bcadd($data[$i]['fat_val'],$data[$i]['carbohydrate_val'],20),20),2),100,0),
+ ];
+ $data[$i]['nutrients_list'][] = [
+ 'name' => 'Calorie',
+ 'name_ch' => '卡路里',
+ 'unit' => 'kcal',
+ 'value' => $data[$i]['kcal_val'],
+ 'type' => 1,
+ 'type_name' => '能量及宏量营养素',
+ 'color' => '#C4FFE0',
+ ];
+ $data[$i]['nutrients_list'][] = [
+ 'name' => 'Protein',
+ 'name_ch' => '蛋白质',
+ 'unit' => 'g',
+ 'value' => $data[$i]['protein_val'],
+ 'type' => 1,
+ 'type_name' => '能量及宏量营养素',
+ 'color' => '#C4FFE0',
+ ];
+ $data[$i]['nutrients_list'][] = [
+ 'name' => 'Fat',
+ 'name_ch' => '脂肪',
+ 'unit' => 'g',
+ 'value' => $data[$i]['fat_val'],
+ 'type' => 1,
+ 'type_name' => '能量及宏量营养素',
+ 'color' => '#C4FFE0',
+ ];
+ $data[$i]['nutrients_list'][] = [
+ 'name' => 'Carbohydrate',
+ 'name_ch' => '碳水化合物',
+ 'unit' => 'g',
+ 'value' => $data[$i]['carbohydrate_val'],
+ 'type' => 1,
+ 'type_name' => '能量及宏量营养素',
+ 'color' => '#C4FFE0',
+ ];
+ foreach ($nutrients_list as $key => $value) {
+ if($value['father_id'] == $data[$i]['food_id']){
+ if(in_array($value['name'],$nutrients_arr)){
+ $data[$i]['nutrients_list'][] = [
+ 'name' => $value['name'],
+ 'name_ch' => $value['name_ch'],
+ 'unit' => $value['unit'],
+ 'value' => bcmul($value['value'],bcdiv($data[$i]['weight'],100,20),2),
+ 'type' => $value['type'],
+ 'type_name' => $value['type'] == 1?'能量及宏量营养素':($value['type'] == 2?'维生素':($value['type'] == 3?'矿物质':'')),
+ 'color' => $value['type'] == 1?'#C4FFE0':($value['type'] == 2?'#FFEFB7':($value['type'] == 3?'#7DA8E0':'')),
+ ];
+ }
+
+ }
+ }
+ }
+ return $data;
+ }
+
+
+
+ public function add_search_history_action($data){
+ // 添加一条搜索记录start
+ $cfc = Db::connect('cfc_db');
+ $insert_search_log = $cfc->table($this->base_use_db_name['search_history'])->where(['user_id'=>$data['id'],'keyword'=>$data['search_data'],'type'=>$data['type']])->field('id,search_count')->find();
+ if($insert_search_log){
+ $cfc->table($this->base_use_db_name['search_history'])->where(['id'=>$insert_search_log['id']])->update([
+ 'search_count'=>$insert_search_log['search_count']+1,
+ 'last_searched_at'=>date('Y-m-d H:i:s'),
+ ]);
+ }else{
+ $cfc->table($this->base_use_db_name['search_history'])->insert([
+ 'user_id'=>$data['id'],
+ 'keyword'=>$data['search_data'],
+ 'type'=>$data['type'],
+ ]);
+ }
+ // 添加一条搜索记录end
+ }
+ ####################################################图片选择上传start##############################################################
+ ####################################################图片选择上传start##############################################################
+ ####################################################图片选择上传start##############################################################
+ public function pic_chose_list($page = 1) {
+ $data = input();
+ $page_num = 20;
+ if(!array_key_exists('token',$data)){
+ return $this->msg(10001,'token is miss');
+ }
+ if(array_key_exists('page',$data)){
+ $page = $data['page'];
+ }
+ $parameter_data = [
+ 'user_token'=>$data['token'],
+ 'is_del'=>0
+ ];
+
+ $cfc = Db::connect('cfc_db');
+
+ $num = $cfc->table('app_user_upload_img')->where($parameter_data)->count();
+ $result = $cfc->table('app_user_upload_img')->where($parameter_data)->order('id desc')->page($page,$page_num)->field('id,pic_name,pic_url')->select();
+ $return_result['page_total'] = $page_total = ceil($num/$page_num);
+ $return_result['page_now'] = $page;
+ $return_result['result'] = $result;
+ return $this->msg($return_result);
+ }
+ public function pic_upload_one_action(){
+ $temporary_data = [];
+ $cfc = Db::connect('cfc_db');
+ $file = request()->file('image');
+ $token = request()->param('token');
+ if(!$token){
+ return $this->msg(10001,'token is miss');
+ }
+ if($file){
+ $name = $file->getInfo()['name'];
+ // 使用 pathinfo() 函数获取文件名的扩展名
+ $pathinfo = pathinfo($name);
+ $extension = strtolower($pathinfo['extension']); // 转换为小写以进行不区分大小写的比较
+ $new_filename = time().$this->generateRandomString(). '.' . $extension;
+ $info = $file->validate(['size'=>$this->file_size,'ext'=>'jpg,png,gif'])->move(ROOT_PATH . 'public' . DS . 'kitchenscale_all' . DS . 'user_upload',$new_filename);
+ if($info){
+ $temporary_data = [
+ 'user_token'=>$token,
+ 'pic_name'=>$new_filename,
+ 'pic_url'=>"https://tc.pcxbc.com/kitchenscale_all/user_upload/".$new_filename,
+ 'create_time'=>date('Y-m-d H:i:s'),
+ ];
+ $pic_id = $cfc->table('app_user_upload_img')->insertGetId($temporary_data);
+ if($pic_id){
+ $temporary_data['id'] = $pic_id;
+ unset($temporary_data['create_time']);
+ unset($temporary_data['user_token']);
+ return $this->msg($temporary_data);
+ }else{
+ return $this->msg(10002);
+ }
+ }else{
+ // 上传失败获取错误信息
+ return $this->msg(10010,$file->getError());
+ }
+ }else{
+ return $this->msg(10001,'未选择图片');
+ }
+ }
+ public function pic_upload_action(){
+ $insert_data = [];
+ $temporary_data = [];
+ $miss_data = 0;
+ $cfc = Db::connect('cfc_db');
+ $files = request()->file('images');
+ $token = request()->param('token');
+ if(!$token){
+ return $this->msg(10001,'token is miss');
+ }
+ if($files){
+ if(count($files)>5){
+ return $this->msg(10001,'单次最多上传5张图片');
+ }
+ foreach($files as $file){
+ $name = $file->getInfo()['name'];
+ // 使用 pathinfo() 函数获取文件名的扩展名
+ $pathinfo = pathinfo($name);
+ $extension = strtolower($pathinfo['extension']); // 转换为小写以进行不区分大小写的比较
+ $file_name = $pathinfo['filename'];
+ // 判断扩展名是否不是 .png 或 .gif
+ if ($extension !== 'png' && $extension !== 'gif') {
+ // 修改文件名,将扩展名改为 .jpg
+ $new_filename = time().$this->generateRandomString(). '.jpg';
+ } else {
+ $new_filename = time().$this->generateRandomString(). '.' . $extension;
+ }
+ $info = $file->validate(['size'=>$this->file_size,'ext'=>'jpg,png,gif'])->move(ROOT_PATH . 'public' . DS . 'kitchenscale_all' . DS . 'user_upload',$new_filename);
+ if($info){
+ $temporary_data = [
+ 'user_token'=>$token,
+ 'pic_name'=>$new_filename,
+ 'pic_url'=>"https://tc.pcxbc.com/kitchenscale_all/user_upload/".$new_filename,
+ 'create_time'=>date('Y-m-d H:i:s'),
+ ];
+ $pic_id = $cfc->table('app_user_upload_img')->insertGetId($temporary_data);
+ if($pic_id){
+ $temporary_data['id'] = $pic_id;
+ unset($temporary_data['create_time']);
+ unset($temporary_data['user_token']);
+ array_push($insert_data,$temporary_data);
+ }else{
+ $miss_data = $miss_data+1;
+ }
+ }else{
+ $miss_data = $miss_data+1;
+ }
+ }
+
+ return $this->msg(['error_num'=>$miss_data,'insert_data'=>$insert_data]);
+
+ }else{
+ return $this->msg(10001,'未选择图片');
+ }
+ }
+ ####################################################图片选择上传end##############################################################
+ ####################################################图片选择上传end##############################################################
+ ####################################################图片选择上传end##############################################################
+
+
+ ########################################################其他工具########################################################
+ ########################################################其他工具########################################################
+ ########################################################其他工具########################################################
+ 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]);
+ }
+ }
+
+ public function generateRandomString($length = 10) {
+ $characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
+ $charactersLength = strlen($characters);
+ $randomString = '';
+ for ($i = 0; $i < $length; $i++) {
+ $randomString .= $characters[rand(0, $charactersLength - 1)];
+ }
+ return $randomString;
+ }
+
+
+ public function ceshi(){
+ echo 'hello';
+ }
+
+
+
+
+}
\ No newline at end of file
diff --git a/application/KitchenScale2/controller/app/Cookbook.php b/application/KitchenScale2/controller/app/Cookbook.php
new file mode 100644
index 0000000..b4e893f
--- /dev/null
+++ b/application/KitchenScale2/controller/app/Cookbook.php
@@ -0,0 +1,1612 @@
+'app_account_number',//账号表
+ 'juese'=>'app_user_data',//角色表
+ ];
+ protected $kitchenscale_db_msg = [
+ 'cookbook'=>'app_user_cookbook',//菜谱表
+ 'cookbook_food_relation'=>'app_user_cookbook_food_relation',//菜谱表
+ 'cookbook_label'=>'app_user_cookbook_label',//菜谱标签表
+ 'uploadimg'=>'app_user_upload_img',//素材表
+ 'followlist'=>'app_user_follow_list',//关注列表
+ 'collect_list'=>'app_user_collect_list',//收藏列表
+ 'foodlist1'=>'app_z_national_standard_food_type_1',//食材列表3
+ 'foodlist2'=>'app_z_national_standard_food_type_2',//食材列表3
+ 'foodlist3'=>'app_z_national_standard_food_type_3',//食材列表3
+ 'foodlist4'=>'app_z_national_standard_food_type_4',//食材列表3
+ 'nutrition'=>'app_user_cookbook_nutrition',//能量
+ 'vitamin'=>'app_user_cookbook_vitamin',//维生素
+ 'mineral'=>'app_user_cookbook_mineral',//矿物质
+ 'user_kcal_log'=>'app_user_kcal_log',//食材列表3
+ 'user'=>'app_user_data',//用户表
+ ];
+
+ // 加 bcadd(,,20)
+ // 减 bcsub(,,20)
+ // 乘 bcmul(,,20)
+ // 除 bcdiv(,,20)
+ ################################################################接口################################################################
+ ################################################################接口################################################################
+ ################################################################接口################################################################
+
+ // 添加菜谱(OK)
+ public function add_cookbook(){
+ // 尝试捕获异常
+ try {
+ if(count(input('post.')) > 0){
+ $data = input('post.');
+ }
+ if(!array_key_exists('token', $data)){
+ return $this->msg(10001,'token is miss');
+ }
+ if(!array_key_exists('cover', $data)){
+ return $this->msg(10001,'cover is miss');
+ }
+ if(!array_key_exists('description', $data)){
+ return $this->msg(10001,'description is miss');
+ }
+ if(!array_key_exists('cook_label', $data)){
+ return $this->msg(10001,'cook_label is miss');
+ }
+ if(!array_key_exists('food_list', $data)){
+ $data['food_list'] = [];
+ }
+ if(!array_key_exists('step_list', $data)){
+ $data['step_list'] = [];
+ }
+
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005,'token type is error');
+ }
+ if(!$this->verify_data_is_ok($data['cover'],'intnum')){
+ return $this->msg(10005,'cover type is error');
+ }
+ if(!$this->verify_data_is_ok($data['description'],'str')){
+ return $this->msg(10005,'description type is error');
+ }
+ if(!$this->verify_data_is_ok($data['cook_label'],'intnum')){
+ return $this->msg(10005,'cook_label type is error');
+ }
+ if (!is_array($data['food_list'])) {
+ return $this->msg(10005,'food_list type is error');
+ }
+ if (!is_array($data['step_list'])) {
+ return $this->msg(10005,'step_list type is error');
+ }
+
+
+ $return_data = $this->add_cookbook_action($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'] .= "行号: " . $e->getLine() . "\n";
+ $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
+ // 记录日志
+ $this->record_api_log($data, $logContent, null);
+ return json(['status' => 'error', 'message' => '系统错误']);
+ }
+ }
+ // 修改菜谱(OK)
+ public function update_cookbook(){
+ // 尝试捕获异常
+ try {
+ if(count(input('post.')) > 0){
+ $data = input('post.');
+ }
+ if(!array_key_exists('token', $data)){
+ return $this->msg(10001,'token is miss');
+ }
+ if(!array_key_exists('cover', $data)){
+ return $this->msg(10001,'cover is miss');
+ }
+ if(!array_key_exists('description', $data)){
+ return $this->msg(10001,'description is miss');
+ }
+ if(!array_key_exists('cook_label', $data)){
+ return $this->msg(10001,'cook_label is miss');
+ }
+ if(!array_key_exists('food_list', $data)){
+ $data['food_list'] = [];
+ }
+ if(!array_key_exists('step_list', $data)){
+ $data['step_list'] = [];
+ }
+ if(!array_key_exists('cookbook_id', $data)){
+ return $this->msg(10001,'cookbook_id is miss');
+ }
+
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005,'token type is error');
+ }
+ if(!$this->verify_data_is_ok($data['cover'],'intnum')){
+ return $this->msg(10005,'cover type is error');
+ }
+ if(!$this->verify_data_is_ok($data['description'],'str')){
+ return $this->msg(10005,'description type is error');
+ }
+ if(!$this->verify_data_is_ok($data['cook_label'],'intnum')){
+ return $this->msg(10005,'cook_label type is error');
+ }
+ if (!is_array($data['food_list'])) {
+ return $this->msg(10005,'food_list type is error');
+ }
+ if (!is_array($data['step_list'])) {
+ return $this->msg(10005,'step_list type is error');
+ }
+ if(!$this->verify_data_is_ok($data['cookbook_id'],'intnum')){
+ return $this->msg(10005,'cookbook_id type is error');
+ }
+
+
+
+ $return_data = $this->update_cookbook_action($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'] .= "行号: " . $e->getLine() . "\n";
+ $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
+ // 记录日志
+ $this->record_api_log($data, $logContent, null);
+ return json(['status' => 'error', 'message' => '系统错误']);
+ }
+ }
+ // 根据菜谱标签查询列表(首页用)(OK)
+ public function find_by_cook_label($data=['token'=>'','cook_label'=>4,'page'=>'1']){
+ // 尝试捕获异常
+ try {
+ if(count(input('post.')) > 0){
+ $data = input('post.');
+ }
+
+ if(!array_key_exists('cook_label', $data)){
+ return $this->msg(10001,'cook_label is miss');
+ }
+ // if(!array_key_exists('page', $data)){
+ // return $this->msg(10001,'page is miss');
+ // }
+
+ if(!$this->verify_data_is_ok($data['cook_label'],'intnum')){
+ return $this->msg(10005,'cook_label type is error');
+ }
+ // if(!$this->verify_data_is_ok($data['page'],'intnum')){
+ // return $this->msg(10005,'page type is error');
+ // }
+ $return_data = $this->find_by_cook_label_action($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'] .= "行号: " . $e->getLine() . "\n";
+ $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
+ // 记录日志
+ $this->record_api_log($data, $logContent, null);
+ return json(['status' => 'error', 'message' => '系统错误']);
+ }
+ }
+ // 根据食材详细查找列表(OK)
+ public function find_by_food($data=['token'=>'caadd1be045a65f30b92aa805f1de54a','food_name'=>"2724,2670",'page'=>'1']){
+ // 尝试捕获异常
+ try {
+ if(count(input('post.')) > 0){
+ $data = input('post.');
+ }
+ if(!array_key_exists('token', $data)){
+ return $this->msg(10001,'token is miss');
+ }
+ if(!array_key_exists('food_name', $data)){
+ return $this->msg(10001,'food_name is miss');
+ }
+ // if(!array_key_exists('page', $data)){
+ // return $this->msg(10001,'page is miss');
+ // }
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005,'token type is error');
+ }
+ if(!$this->verify_data_is_ok($data['food_name'],'str')){
+ return $this->msg(10005,'tofood_nameken type is error');
+ }
+ // if(!$this->verify_data_is_ok($data['page'],'intnum')){
+ // return $this->msg(10005,'page type is error');
+ // }
+ $return_data = $this->find_by_food_action($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'] .= "行号: " . $e->getLine() . "\n";
+ $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
+ // 记录日志
+ $this->record_api_log($data, $logContent, null);
+ return json(['status' => 'error', 'message' => '系统错误']);
+ }
+ }
+ // 查询食谱的详情(OK)
+ public function cookbook_details($data=['token'=>'','cookbook_id'=>'3594']){
+ // 尝试捕获异常
+ try {
+ if(count(input('post.')) > 0){
+ $data = input('post.');
+ }
+ if(!array_key_exists('cookbook_id', $data)){
+ return $this->msg(10001,'cookbook_id is miss');
+ }
+ if(!$this->verify_data_is_ok($data['cookbook_id'],'intnum')){
+ return $this->msg(10005,'cookbook_id type is error');
+ }
+ $return_data = $this->cookbook_details_action($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'] .= "行号: " . $e->getLine() . "\n";
+ $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
+ // 记录日志
+ $this->record_api_log($data, $logContent, null);
+ return json(['status' => 'error', 'message' => '系统错误']);
+ }
+ }
+ // 关注行为(OK)
+ public function cookbook_follow($data=['token'=>'caadd1be045a65f3','being_followed'=>'caadd1be045a65f30b92aa805f1de54a']){
+ // 尝试捕获异常
+ try {
+ if(count(input('post.')) > 0){
+ $data = input('post.');
+ }
+ if(!array_key_exists('token', $data)){
+ return $this->msg(10001,'token is miss');
+ }
+ if(!array_key_exists('being_followed', $data)){
+ return $this->msg(10001,'cookbook_id is miss');
+ }
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005,'token type is error');
+ }
+ if(!$this->verify_data_is_ok($data['being_followed'],'str')){
+ return $this->msg(10005,'cookbook_id type is error');
+ }
+ $return_data = $this->cookbook_follow_action($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'] .= "行号: " . $e->getLine() . "\n";
+ $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
+ // 记录日志
+ $this->record_api_log($data, $logContent, null);
+ return json(['status' => 'error', 'message' => '系统错误']);
+ }
+ }
+ // 点赞收藏菜谱(OK)
+ public function cookbook_like($data=['token'=>'caadd1be045a65f30b92aa805f1de54a','cookbook_id'=>'12']){
+ // 尝试捕获异常
+ try {
+ if(count(input('post.')) > 0){
+ $data = input('post.');
+ }
+ if(!array_key_exists('token', $data)){
+ return $this->msg(10001,'token is miss');
+ }
+ if(!array_key_exists('cookbook_id', $data)){
+ return $this->msg(10001,'cookbook_id is miss');
+ }
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005,'token type is error');
+ }
+ if(!$this->verify_data_is_ok($data['cookbook_id'],'intnum')){
+ return $this->msg(10005,'cookbook_id type is error');
+ }
+ $return_data = $this->cookbook_like_action($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'] .= "行号: " . $e->getLine() . "\n";
+ $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
+ // 记录日志
+ $this->record_api_log($data, $logContent, null);
+ return json(['status' => 'error', 'message' => '系统错误']);
+ }
+ }
+ // 计算当前食材重量的卡路里(OK)
+ public function food_count_kcal($data=['food_name'=>'鸡肉','food_weight'=>456.37]){
+ // 尝试捕获异常
+ try {
+ if(count(input('post.')) > 0){
+ $data = input('post.');
+ }
+ if(!array_key_exists('food_name', $data)){
+ return $this->msg(10001,'food_name is miss');
+ }
+ if(!array_key_exists('food_weight', $data)){
+ return $this->msg(10001,'food_weight is miss');
+ }
+ if(!$this->verify_data_is_ok($data['food_name'],'str')){
+ return $this->msg(10005,'food_name type is error');
+ }
+ if(!$this->verify_data_is_ok($data['food_weight'],'num')){
+ return $this->msg(10005,'food_weight type is error');
+ }
+
+ $return_data = $this->food_count_kcal_action($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'] .= "行号: " . $e->getLine() . "\n";
+ $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
+ // 记录日志
+ $this->record_api_log($data, $logContent, null);
+ return json(['status' => 'error', 'message' => '系统错误']);
+ }
+ }
+ // 食材列表查询接口(OK)
+ public function find_food($data=['food_name'=>'鸡肉']){
+ // 尝试捕获异常
+ try {
+ if(count(input('post.')) > 0){
+ $data = input('post.');
+ }
+ if(!array_key_exists('food_name', $data)){
+ return $this->msg(10001,'food_name is miss');
+ }
+ if(!$this->verify_data_is_ok($data['food_name'],'str')){
+ return $this->msg(10005,'food_name type is error');
+ }
+
+ $return_data = $this->find_food_action($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'] .= "行号: " . $e->getLine() . "\n";
+ $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
+ // 记录日志
+ $this->record_api_log($data, $logContent, null);
+ return json(['status' => 'error', 'message' => '系统错误']);
+ }
+ }
+ // 获取所有食材列表
+ public function get_food_list(){
+ // 尝试捕获异常
+ // try {
+ if(count(input('post.')) > 0){
+ $data = input('post.');
+ }
+ // if(!array_key_exists('food_level2_id', $data)){
+ // return $this->msg(10001,'food_level2_id is miss');
+ // }
+ // if(!array_key_exists('page', $data)){
+ // return $this->msg(10001,'page is miss');
+ // }
+ // if(!$this->verify_data_is_ok($data['food_level2_id'],'intnum')){
+ // return $this->msg(10005,'food_level2_id type is error');
+ // }
+ // if(!$this->verify_data_is_ok($data['page'],'intnum')){
+ // return $this->msg(10005,'page type is error');
+ // }
+
+ $return_data = $this->get_food_list_action($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'] .= "行号: " . $e->getLine() . "\n";
+ // $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
+ // // 记录日志
+ // $this->record_api_log($data, $logContent, null);
+ // return json(['status' => 'error', 'message' => '系统错误']);
+ // }
+ }
+ // 获取所有食谱label
+ public function get_cookbook_label_list($data=['token'=>'caadd1be045a65f30b92aa805f1de54a']){
+ // 尝试捕获异常
+ try {
+ if(count(input('post.')) > 0){
+ $data = input('post.');
+ }
+ if(!array_key_exists('token', $data)){
+ return $this->msg(10001,'token is miss');
+ }
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005,'token type is error');
+ }
+
+ $return_data = $this->get_cookbook_label_list_action($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'] .= "行号: " . $e->getLine() . "\n";
+ $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
+ // 记录日志
+ $this->record_api_log($data, $logContent, null);
+ return json(['status' => 'error', 'message' => '系统错误']);
+ }
+ }
+
+ // 获取查询页页面导航食材列表
+ public function get_search_food_page_list($data=['token'=>'caadd1be045a65f30b92aa805f1de54a']){
+ // 尝试捕获异常
+ try {
+ if(count(input('post.')) > 0){
+ $data = input('post.');
+ }
+ if(!array_key_exists('token', $data)){
+ return $this->msg(10001,'token is miss');
+ }
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005,'token type is error');
+ }
+
+ $return_data = $this->get_search_food_page_list_action($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'] .= "行号: " . $e->getLine() . "\n";
+ $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
+ // 记录日志
+ $this->record_api_log($data, $logContent, null);
+ return json(['status' => 'error', 'message' => '系统错误']);
+ }
+ }
+
+
+
+
+
+ #######################################################################action#######################################################################
+ #######################################################################action#######################################################################
+ #######################################################################action#######################################################################
+
+ public function add_cookbook_action($data){
+
+ // 获取账号下信息以及用户信息
+ $user_data = Db::table($this->reedaw_db_msg['zhanghao'])->where(['token'=>$data['token']])->field('id,token,nickname,head_pic')->find();
+ if(!$user_data){
+ return $this->msg(20001,'账号信息错误');
+ }
+
+ if(count($data['food_list']) < 1){
+ return $this->msg(10001,'至少添加一个食物');
+ }
+ if(count($data['step_list']) < 1){
+ return $this->msg(10001,'至少添加一个步骤');
+ }
+ $food_type = [];
+ // 检验一下food_list是否合规(食材列表)
+ foreach ($data['food_list'] as $key => $value) {
+ if (!array_key_exists('id', $value) || !array_key_exists('weight', $value)) {
+ return $this->msg(10001,'食材缺少id或者重量');
+ }
+ if(!$this->verify_data_is_ok($value['name'],'str')){
+ return $this->msg(10005,'食材名称格式错误');
+ }
+ if(!$this->verify_data_is_ok($value['weight'],'intnum')){
+ return $this->msg(10005,'食材重量格式错误,需整数数字');
+ }
+ if(!in_array($value['id'], $food_type)){
+ array_push($food_type, $value['id']);
+ }
+ }
+ // 检验一下step_list是否合规(步骤列表)
+ foreach ($data['step_list'] as $key => $value) {
+ if (!array_key_exists('description', $value) || !array_key_exists('pic_list', $value)) {
+ return $this->msg(10001,'步骤缺少描述或者图片');
+ }
+ if(!$this->verify_data_is_ok($value['description'],'str')){
+ return $this->msg(10005,'步骤描述格式错误,需要正常字符');
+ }
+ foreach ($value['pic_list'] as $k => $v) {
+ if(!$this->verify_data_is_ok($v,'intnum')){
+ return $this->msg(10005,'步骤中图片ID错误,需整数数字');
+ }
+ }
+ }
+
+ $cfc = Db::connect('cfc_db');
+ // 获取账号下信息以及用户信息
+ $user_data = Db::table($this->reedaw_db_msg['zhanghao'])->where(['token'=>$data['token']])->field('id,token,nickname,head_pic')->find();
+
+
+ // 处理食材卡路里start
+ $kcal_data = $this->count_calorie($data['food_list'],$data['step_list']);
+ $data['food_list'] =$kcal_data;
+ // 处理食材卡路里end
+
+ // dump($data['food_list']);
+ // die;
+ $insert_data = [
+ 'title'=>$data['title'],
+ 'cover'=>$data['cover'],
+ 'create_user_token'=>$user_data['token'],
+ 'create_user_head_pic'=>$user_data['head_pic'],
+ 'create_user_nickname'=>$user_data['nickname'],
+ 'describe_data'=>$data['description'],
+ 'food_data'=>json_encode($data['food_list']),
+ 'step_data'=>json_encode($data['step_list']),
+ // 'food_type'=>implode(',', $food_type),
+ 'cook_label'=>$data['cook_label'],
+ 'create_time'=>date('Y-m-d H:i:s')
+ ];
+ // dump($insert_data);
+ // die;
+ // 启动事务
+ Db::startTrans();
+ try{
+ $cook_book_result = $cfc->table($this->kitchenscale_db_msg['cookbook'])->insertGetId($insert_data);
+ $food_type_insert = [];
+ foreach ($food_type as $key => $value) {
+ array_push($food_type_insert,['cookbook_id'=>$cook_book_result,'food_id'=>$value]);
+ }
+ $cfc->table($this->kitchenscale_db_msg['cookbook_food_relation'])->insertAll($food_type_insert);
+ // 提交事务
+ Db::commit();
+ return $this->msg([]);
+ } catch (\Exception $e) {
+ // 回滚事务
+ Db::rollback();
+ return $this->msg(10002);
+ }
+
+
+ // if($cook_book_result){
+ // return $this->msg([]);
+ // }else{
+ // return $this->msg(10002);
+ // }
+ }
+ public function update_cookbook_action($data){
+ // 获取账号下信息以及用户信息
+ $user_data = Db::table($this->reedaw_db_msg['zhanghao'])->where(['token'=>$data['token']])->field('id,token,nickname,head_pic')->find();
+ if(!$user_data){
+ return $this->msg(20001,'账号信息错误');
+ }
+
+ if(count($data['food_list']) < 1){
+ return $this->msg(10001,'至少添加一个食物');
+ }
+ if(count($data['step_list']) < 1){
+ return $this->msg(10001,'至少添加一个步骤');
+ }
+ $food_type = [];
+ // 检验一下food_list是否合规(食材列表)
+ foreach ($data['food_list'] as $key => $value) {
+ if (!array_key_exists('id', $value) || !array_key_exists('weight', $value)) {
+ return $this->msg(10001,'食材缺少id或者重量');
+ }
+ if(!$this->verify_data_is_ok($value['name'],'str')){
+ return $this->msg(10005,'食材名称格式错误');
+ }
+ if(!$this->verify_data_is_ok($value['weight'],'intnum')){
+ return $this->msg(10005,'食材重量格式错误,需整数数字');
+ }
+ if(!in_array($value['id'], $food_type)){
+ array_push($food_type, $value['id']);
+ }
+ }
+ // 检验一下step_list是否合规(步骤列表)
+ foreach ($data['step_list'] as $key => $value) {
+ if (!array_key_exists('description', $value) || !array_key_exists('pic_list', $value)) {
+ return $this->msg(10001,'步骤缺少描述或者图片');
+ }
+ if(!$this->verify_data_is_ok($value['description'],'str')){
+ return $this->msg(10005,'步骤描述格式错误,需要正常字符');
+ }
+ foreach ($value['pic_list'] as $k => $v) {
+ if(!$this->verify_data_is_ok($v,'intnum')){
+ return $this->msg(10005,'步骤中图片ID错误,需整数数字');
+ }
+ }
+ }
+ $cfc = Db::connect('cfc_db');
+ // 获取账号下信息以及用户信息
+ // $user_data = Db::table($this->reedaw_db_msg['zhanghao'])->where(['token'=>$data['token']])->field('id,token,nickname,head_pic')->find();
+ // if(!$user_data){
+
+ // }
+
+ // 处理食材卡路里start
+ $kcal_data = $this->count_calorie($data['food_list'],$data['step_list']);
+ $data['food_list'] =$kcal_data;
+ // 处理食材卡路里end
+
+ // dump($data['food_list']);
+ // die;
+ $insert_data = [
+ 'title'=>$data['title'],
+ 'cover'=>$data['cover'],
+ 'create_user_token'=>$user_data['token'],
+ 'create_user_head_pic'=>$user_data['head_pic'],
+ 'create_user_nickname'=>$user_data['nickname'],
+ 'describe_data'=>$data['description'],
+ 'food_data'=>json_encode($data['food_list']),
+ 'step_data'=>json_encode($data['step_list']),
+ // 'food_type'=>implode(',', $food_type),
+ 'cook_label'=>$data['cook_label'],
+ ];
+
+
+
+ // 启动事务
+ Db::startTrans();
+ try{
+ $cook_book_result = $cfc->table($this->kitchenscale_db_msg['cookbook'])->where(['id'=>$data['cookbook_id']])->update($insert_data);
+ $food_type_insert = [];
+ foreach ($food_type as $key => $value) {
+ array_push($food_type_insert,['cookbook_id'=>$data['cookbook_id'],'food_id'=>$value]);
+ }
+ $cfc->table($this->kitchenscale_db_msg['cookbook_food_relation'])->where('cookbook_id',$data['cookbook_id'])->delete();
+ $cfc->table($this->kitchenscale_db_msg['cookbook_food_relation'])->insertAll($food_type_insert);
+ // 提交事务
+ Db::commit();
+ return $this->msg([]);
+ } catch (\Exception $e) {
+ // 回滚事务
+ Db::rollback();
+ return $this->msg(10002);
+ }
+ // dump($cook_book_result);
+ // die;
+ if($cook_book_result){
+ return $this->msg([]);
+ }else{
+ return $this->msg(10002);
+ }
+ }
+
+ public function find_by_cook_label_action($data){
+
+ $page_now = array_key_exists('page',$data)?$data['page']:1;
+ $page_total = $page_now;
+ $page_num = 20;
+ $cook_label = $data['cook_label'];
+
+ $cfc = Db::connect('cfc_db');
+ $content_num = $cfc->table($this->kitchenscale_db_msg['cookbook'])
+ ->where(['cook_label'=>$cook_label,'is_del'=>0])
+ ->count();
+
+ $page_total = ceil($content_num/$page_num);
+ $content_list = $cfc->table($this->kitchenscale_db_msg['cookbook'])
+ ->alias('a')
+ ->join($this->kitchenscale_db_msg['uploadimg'].' b','a.cover = b.id','LEFT')
+ ->where(['a.cook_label'=>$cook_label,'a.is_del'=>0])
+ ->field('a.id,a.title,b.pic_url as cover,a.create_user_head_pic,a.create_user_nickname,a.likes_num')
+ // ->order('id DESC')
+ ->page("$page_now,$page_num")
+ ->select();
+
+ if(array_key_exists('token',$data)){
+ if($data['token'] != ''){
+ // 获取账号下信息以及用户信息
+ $user_data = Db::table($this->reedaw_db_msg['zhanghao'])->where(['token'=>$data['token']])->field('id,token,nickname,head_pic')->find();
+ if(!$user_data){
+ return $this->msg(20001,'账号信息错误');
+ }
+ // 获取用户收藏列表
+ $my_collect_list = $cfc->table($this->kitchenscale_db_msg['collect_list'])
+ ->where(['token'=>$data['token'],'is_del'=>0])
+ ->column('cookbook_id');
+ // dump($my_collect_list);
+ // 处理菜谱收藏信息
+ foreach ($content_list as $key => $value) {
+ // if(in_array($value['id'],$my_collect_list)){
+ if(array_key_exists($value['id'],$my_collect_list)){
+ $content_list[$key]['is_me_like_it'] = 'yes';
+ }else{
+ $content_list[$key]['is_me_like_it'] = 'no';
+ }
+ if($value['cover'] == null){
+ $content_list[$key]['cover'] = 'https://tc.pcxbc.com/kitchenscale_all/diule.jpg';
+ }
+ unset($content_list[$key]['ROW_NUMBER']);
+ }
+ }else{
+ foreach ($content_list as $key => $value) {
+ $content_list[$key]['is_me_like_it'] = 'no';
+ if($value['cover'] == null){
+ $content_list[$key]['cover'] = 'https://tc.pcxbc.com/kitchenscale_all/diule.jpg';
+ }
+ unset($content_list[$key]['ROW_NUMBER']);
+ }
+ }
+ }else{
+ foreach ($content_list as $key => $value) {
+ $content_list[$key]['is_me_like_it'] = 'no';
+ if($value['cover'] == null){
+ $content_list[$key]['cover'] = 'https://tc.pcxbc.com/kitchenscale_all/diule.jpg';
+ }
+ unset($content_list[$key]['ROW_NUMBER']);
+ }
+ }
+ // dump($content_list);
+ // die;
+ return $this->msg([
+ 'page_now'=>$page_now,
+ 'page_total'=>$page_total,
+ 'content_list'=>$content_list
+ ]);
+ }
+ public function find_by_food_action($data){
+
+
+ // 获取账号下信息以及用户信息
+ $user_data = Db::table($this->reedaw_db_msg['zhanghao'])->where(['token'=>$data['token']])->field('id,token,nickname,head_pic')->find();
+ if(!$user_data){
+ return $this->msg(20001,'账号信息错误');
+ }
+
+ $page_now = array_key_exists('page',$data)?$data['page']:1;
+ $page_total = $page_now;
+ $page_num = 20;
+ $food_name = $data['food_name'];
+
+ $cfc = Db::connect('cfc_db');
+
+ // $food_name = implode(',',$food_name);
+ // dump($food_name);
+ // die;
+
+ $content_num = $cfc->table($this->kitchenscale_db_msg['cookbook_food_relation'])
+ ->where("food_id in ($food_name)")
+ ->group('cookbook_id')
+ ->field('count(distinct cookbook_id) as count') // 显式指定列名
+ ->select(); // 然后获取结果
+ // dump($content_num);
+ $page_total = ceil(count($content_num)/$page_num);
+
+ $content_list = $cfc->table($this->kitchenscale_db_msg['cookbook_food_relation'])
+ ->alias('a')
+ ->join($this->kitchenscale_db_msg['cookbook'].' b','a.cookbook_id = b.id','LEFT')
+ ->join($this->kitchenscale_db_msg['uploadimg'].' c','b.cover = c.id','LEFT')
+ ->where("a.food_id in ($food_name)")
+ ->field('b.id,b.title,c.pic_url as cover,b.create_user_head_pic,b.create_user_nickname,b.likes_num')
+ ->group('b.id,b.title,c.pic_url,b.create_user_head_pic,b.create_user_nickname,b.likes_num')
+ ->page("$page_now,$page_num")
+ ->select();
+
+ // dump($food_name);
+ // dump($content_num);
+ // dump($page_total);
+ // dump($content_list);
+ // die;
+
+ // $content_num = $cfc->table($this->kitchenscale_db_msg['cookbook'])
+ // ->where("food_type like '%$food_name%'")
+ // ->count();
+ // $page_total = ceil($content_num/$page_num);
+
+ // $content_list = $cfc->table($this->kitchenscale_db_msg['cookbook'])
+ // ->alias('cookbook')
+ // ->join($this->kitchenscale_db_msg['uploadimg'].' uploadimg','cookbook.cover = uploadimg.id','LEFT')
+ // ->where("cookbook.food_type like '%$food_name%'")
+ // ->field('cookbook.id,cookbook.title,uploadimg.pic_url as cover,cookbook.create_user_head_pic,cookbook.create_user_nickname,cookbook.likes_num')
+ // ->page("$page_now,$page_num")
+ // ->select();
+
+ // 获取用户收藏列表
+ $my_collect_list = $cfc->table($this->kitchenscale_db_msg['collect_list'])
+ ->where(['token'=>$data['token']])
+ ->column('cookbook_id');
+ // dump($my_collect_list);
+ // 处理菜谱收藏信息
+ foreach ($content_list as $key => $value) {
+ // if(in_array($value['id'],$my_collect_list)){
+ if(array_key_exists($value['id'],$my_collect_list)){
+ $content_list[$key]['is_me_like_it'] = 'yes';
+ }else{
+ $content_list[$key]['is_me_like_it'] = 'no';
+ }
+ if($value['cover'] == null){
+ $content_list[$key]['cover'] = 'https://tc.pcxbc.com/kitchenscale_all/diule.jpg';
+ }
+ unset($content_list[$key]['ROW_NUMBER']);
+ }
+
+ return $this->msg([
+ 'page_now'=>$page_now,
+ 'page_total'=>$page_total,
+ 'content_list'=>$content_list
+ ]);
+ }
+ public function cookbook_details_action($data){
+
+ $cfc = Db::connect('cfc_db');
+ $img_arr = [];
+ // 查询菜谱详情
+ $cookbook_data = $cfc->table($this->kitchenscale_db_msg['cookbook'])->where(['id'=>$data['cookbook_id']])->find();
+ if(!$cookbook_data){
+ return $this->msg(10004,'菜谱不存在');
+ }
+ $cookbook_data['food_data'] = json_decode($cookbook_data['food_data'],true);
+ $cookbook_data['step_data'] = json_decode($cookbook_data['step_data'],true);
+ // $cookbook_data['food_type'] = explode(',',$cookbook_data['food_type']);
+ $cookbook_data_step_data_count = count($cookbook_data['step_data']);
+ // 设置需要的图片id
+ array_push($img_arr, $cookbook_data['cover']);
+
+ foreach ($cookbook_data['step_data'] as $key => $value) {
+ if(count($value['pic_list']) > 0){
+ foreach ($value['pic_list'] as $k => $v) {
+ if(!in_array($v, $img_arr)){
+ array_push($img_arr, $v);
+ }
+ }
+ }
+ }
+ // dump($cookbook_data);
+ // die;
+ $img_arr = implode(',',$img_arr);
+ // 查找需要的图片
+ $img_arr_data = $cfc->table($this->kitchenscale_db_msg['uploadimg'])->where("id in ($img_arr) AND is_del = 0")->field('id,pic_name,pic_url')->select();
+ $cookbook_img_data = [];
+ // 处理菜谱图片
+ foreach ($img_arr_data as $key => $value) {
+ $cookbook_img_data[$value['id']] = $value['pic_url'];
+ }
+
+ // 设置菜谱图片
+ foreach ($cookbook_data['step_data'] as $key => $value) {
+ $cookbook_data['step_data'][$key]['step_num'] = "步骤".($key+1).'/'.$cookbook_data_step_data_count;
+ $cookbook_data['step_data'][$key]['pic_url_list'] = [];
+ foreach ($value['pic_list'] as $k => $v) {
+ if(array_key_exists($v, $cookbook_img_data)){
+ array_push($cookbook_data['step_data'][$key]['pic_url_list'],$cookbook_img_data[$v]);
+ }else{
+ array_push($cookbook_data['step_data'][$key]['pic_url_list'],'https://tc.pcxbc.com/kitchenscale_all/diule.jpg');
+ }
+ }
+ }
+
+ // $cookbook_data['cover_id'] = $cookbook_data['cover'];
+ if(array_key_exists($cookbook_data['cover'], $cookbook_img_data)){
+ $cookbook_data['cover_pic_url'] = $cookbook_img_data[$cookbook_data['cover']];
+
+ }else{
+ $cookbook_data['cover_pic_url'] = 'https://tc.pcxbc.com/kitchenscale_all/diule.jpg';
+ }
+
+
+ if(array_key_exists($cookbook_data['cover'], $cookbook_img_data)){
+ if($data['token'] != ''){
+ // 获取账号下信息以及用户信息
+ $user_data = Db::table($this->reedaw_db_msg['zhanghao'])->where(['token'=>$data['token']])->field('id,token,nickname,head_pic')->find();
+ if(!$user_data){
+ return $this->msg(20001,'账号信息错误');
+ }
+ $collect_data = $cfc->table($this->kitchenscale_db_msg['collect_list'])
+ ->where([
+ 'token'=>$data['token'],
+ 'cookbook_id'=>$data['cookbook_id'],
+ ])
+ ->find();
+ if($collect_data){
+ if($collect_data['is_del'] == 0){
+ // 如果有结果并且没被删过
+ $cookbook_data['collect_status'] = 'yes';
+ }else{
+ // 如果有结果被删过
+ $cookbook_data['collect_status'] = 'no';
+ }
+ }else{
+ // 如果没结果
+ $cookbook_data['collect_status'] = 'no';
+ }
+ }else{
+ $cookbook_data['collect_status'] = 'no';
+ }
+ }else{
+ $cookbook_data['collect_status'] = 'no';
+ }
+
+ // 处理营养物质
+ $nutrition = $cfc->table($this->kitchenscale_db_msg['nutrition'])->where(['cookbook_id'=>$data['cookbook_id']])->field('name_en,name_ch as name,unit,value as weight,nrv')->select();
+ $vitamin = $cfc->table($this->kitchenscale_db_msg['vitamin'])->where(['cookbook_id'=>$data['cookbook_id']])->field('name_en,name_ch as name,unit,value as weight,nrv')->select();
+ $mineral = $cfc->table($this->kitchenscale_db_msg['mineral'])->where(['cookbook_id'=>$data['cookbook_id']])->field('name_en,name_ch as name,unit,value as weight,nrv')->select();
+
+
+ $cookbook_data['tags'] = [];
+
+ array_push($cookbook_data['tags'],[
+ 'title'=>'所需食材',
+ 'desc'=>'重量',
+ 'list'=>$cookbook_data['food_data'],
+ ]);
+ if(count($nutrition)>0){
+ array_push($cookbook_data['tags'],[
+ 'title'=>'能量',
+ 'desc'=>'含量',
+ 'list'=>$nutrition,
+ ]);
+ }else{
+ array_push($cookbook_data['tags'],[
+ 'title'=>'',
+ 'desc'=>'',
+ 'list'=>[],
+ ]);
+ }
+ if(count($vitamin)>0){
+ array_push($cookbook_data['tags'],[
+ 'title'=>'维生素',
+ 'desc'=>'含量',
+ 'list'=>$vitamin,
+ ]);
+ }else{
+ array_push($cookbook_data['tags'],[
+ 'title'=>'',
+ 'desc'=>'',
+ 'list'=>[],
+ ]);
+ }
+ if(count($mineral)>0){
+ array_push($cookbook_data['tags'],[
+ 'title'=>'矿物质',
+ 'desc'=>'含量',
+ 'list'=>$mineral,
+ ]);
+ }else{
+ array_push($cookbook_data['tags'],[
+ 'title'=>'',
+ 'desc'=>'',
+ 'list'=>[],
+ ]);
+ }
+
+ $cookbook_data['token'] = $cookbook_data['create_user_token'];
+ $cookbook_data['description'] = $cookbook_data['describe_data'];
+ // $cookbook_data['food_list'] = $cookbook_data['food_data'];
+ $cookbook_data['step_list'] = $cookbook_data['step_data'];
+ unset($cookbook_data['create_user_token']);
+ unset($cookbook_data['describe_data']);
+ unset($cookbook_data['food_data']);
+ unset($cookbook_data['step_data']);
+ unset($cookbook_data['create_time']);
+ unset($cookbook_data['food_type']);
+ unset($cookbook_data['ROW_NUMBER']);
+ unset($cookbook_data['is_del']);
+ return $this->msg($cookbook_data);
+ }
+
+ public function cookbook_follow_action($data){
+ // 获取账号下信息以及用户信息
+ $user_data = Db::table($this->reedaw_db_msg['zhanghao'])->where(['token'=>$data['token']])->field('id,token,nickname,head_pic')->find();
+ if(!$user_data){
+ return $this->msg(20001,'账号信息错误');
+ }
+ // dump($data);
+ $cfc = Db::connect('cfc_db');
+ // $cookbook_data = $cfc->table($this->kitchenscale_db_msg['cookbook'])->where(['id'=>$data['cookbook_id']])->field('id,create_user_token')->find();
+ // if(!$cookbook_data){
+ // return $this->msg(10002,'未找到菜谱');
+ // }
+ if($data['token'] == $data['being_followed']){
+ // 如果查询跟作者一致
+ return $this->msg(10003,'不能关注自己');
+ }
+ $follow_data = $cfc->table($this->kitchenscale_db_msg['followlist'])
+ ->where([
+ 'follow_user_token'=>$data['token'],
+ 'being_follow_user_token'=>$data['being_followed'],
+ ])
+ ->find();
+ $follow_data_state = 0;
+ if($follow_data){
+ if($follow_data['is_del'] == 0){
+ // 如果当前是关注状态
+ $follow_data_state = 1;
+ }else{
+ $follow_data_state = 0;
+ }
+ $follow_result= $cfc->table($this->kitchenscale_db_msg['followlist'])
+ ->where(['id'=>$follow_data['id']])
+ ->update(['is_del'=>$follow_data_state]);
+ }else{
+ $follow_result = $cfc->table($this->kitchenscale_db_msg['followlist'])
+ ->insert([
+ 'follow_user_token'=>$data['token'],
+ 'being_follow_user_token'=>$data['being_followed'],
+ 'create_time'=>date('Y-m-d H:i:s')
+ ]);
+ }
+ if($follow_result){
+ return $this->msg([]);
+ }else{
+ return $this->msg(10002,'操作失败');
+ }
+ }
+ public function cookbook_like_action($data){
+
+ // 获取账号下信息以及用户信息
+ $user_data = Db::table($this->reedaw_db_msg['zhanghao'])->where(['token'=>$data['token']])->field('id,token,nickname,head_pic')->find();
+ if(!$user_data){
+ return $this->msg(20001,'账号信息错误');
+ }
+
+
+ $cfc = Db::connect('cfc_db');
+ $cookbook_data = $cfc->table($this->kitchenscale_db_msg['cookbook'])->where(['id'=>$data['cookbook_id']])->field('id,create_user_token,likes_num')->find();
+ if(!$cookbook_data){
+ return $this->msg(10004,'未找到菜谱');
+ }
+ // return $this->msg(10002,'是这里');
+ // if($data['token'] == $cookbook_data['create_user_token']){
+ // // 如果查询跟作者一致
+ // return $this->msg(10002,'不能收藏自己');
+ // }
+ $like_data = $cfc->table($this->kitchenscale_db_msg['collect_list'])->where(['token'=>$data['token'],'cookbook_id'=>$data['cookbook_id']])->find();
+
+ $like_data_state = 0;
+ if($like_data){
+ if($like_data['is_del'] == 0){
+ // 如果当前是关注状态
+ $like_data_state = 1;
+ }else{
+ $like_data_state = 0;
+ }
+ // 启动事务
+ Db::startTrans();
+ try{
+ $cfc->table($this->kitchenscale_db_msg['collect_list'])
+ ->where(['id'=>$like_data['id']])
+ ->update(['is_del'=>$like_data_state]);
+ if($like_data_state == 0){
+ $cfc->table($this->kitchenscale_db_msg['cookbook'])->where(['id'=>$data['cookbook_id']])->setInc('likes_num');
+ }else{
+ $cfc->table($this->kitchenscale_db_msg['cookbook'])->where(['id'=>$data['cookbook_id']])->setDec('likes_num');
+ }
+ // 提交事务
+ Db::commit();
+ if($like_data_state==0){
+ $likes_num = $cookbook_data['likes_num']+1;
+ }else{
+ $likes_num = $cookbook_data['likes_num']-1;
+ if($likes_num <= 0){
+ $likes_num = 0;
+ }
+ }
+ return $this->msg([
+ 'collect_status'=>$like_data_state==0?'yes':'no',
+ 'likes_num'=>$likes_num
+ ]);
+ } catch (\Exception $e) {
+ // 回滚事务
+ Db::rollback();
+ return $this->msg(10002,'操作失败.');
+ }
+ }else{
+ // 启动事务
+ Db::startTrans();
+ try{
+ $cfc->table($this->kitchenscale_db_msg['collect_list'])
+ ->insert([
+ 'token'=>$data['token'],
+ 'cookbook_id'=>$data['cookbook_id'],
+ 'create_time'=>date('Y-m-d H:i:s')
+ ]);
+ $cfc->table($this->kitchenscale_db_msg['cookbook'])->where(['id'=>$data['cookbook_id']])->setInc('likes_num');
+ // 提交事务
+ Db::commit();
+ return $this->msg([
+ 'collect_status'=>"yes",
+ 'likes_num'=>$cookbook_data['likes_num']+1
+ ]);
+ } catch (\Exception $e) {
+ // 回滚事务
+ Db::rollback();
+ return $this->msg(10002,'操作失败');
+ }
+ }
+ }
+ public function food_count_kcal_action($data){
+ $cfc = Db::connect('cfc_db');
+ $food_data = $cfc->table($this->kitchenscale_db_msg['foodlist3'])->where(['name'=>$data['food_name']])->field("kcal")->find();
+ if(!$food_data){
+ return $this->msg(10004,'未登记的食材');
+ }
+ $weight = bcdiv($data['food_weight'],100,2);
+ $kcal = bcmul($weight,$food_data['kcal'],2);
+ return $this->msg(['value'=>$kcal,'unit'=>'kcal']);
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+ public function find_food_action($data){
+ $cfc = Db::connect('cfc_db');
+ $food_data = $cfc->query("select f3.id,f3.food_name as name,f3.pic_url,f3.Calorie_val as kcal,f3.weight_unit as unit,f2.id as up_one_level_id,f1.id as up_two_level_id
+ from ".$this->kitchenscale_db_msg['foodlist3']." as f3
+ LEFT JOIN ".$this->kitchenscale_db_msg['foodlist2']." as f2
+ on f3.two_id = f2.id
+ LEFT JOIN ".$this->kitchenscale_db_msg['foodlist1']." as f1
+ on f2.one_id = f1.id
+ where f3.is_del=0 AND f3.food_name like '%".$data['food_name']."%'
+ ");
+
+ if(count($food_data)>0){
+ for ($i=0; $i < count($food_data); $i++) {
+ if($food_data[$i]['pic_url'] != ''){
+ $food_data[$i]['pic_url'] = 'https://tc.pcxbc.com/kitchenscale_all'.$food_data[$i]['pic_url'];
+ }
+ }
+ return $this->msg($food_data);
+ }else{
+ return $this->msg(10004,'未找到该食材');
+ }
+ }
+
+
+ public function get_food_list_action($data){
+
+ if(!array_key_exists('page',$data)){
+ $data['page'] = 1;
+ }else{
+ if(!$this->verify_data_is_ok($data['page'],'intnum')){
+ $data['page'] = 1;
+ }
+ }
+
+ // $cp_page_num = 15;
+ // $cfc = Db::connect('cfc_db');
+ // $search_sql_str = "is_del = 0";
+ // if(!array_key_exists('search_data', $data)){
+ // $data['search_data'] = "";
+ // $ss = "";
+ // }else{
+ // if($data['search_data'] === ""){
+ // $data['search_data'] = "";
+ // $ss = "";
+ // }else{
+ // $ss = $data['search_data'];
+ // $data['search_data'] = " AND food_name LIKE '%".str_replace('[', '[[]', $ss)."%'";
+
+ // }
+ // }
+ // $search_sql_str = $search_sql_str.$data['search_data'];
+
+ // $content_num = $cfc->table($this->kitchenscale_db_msg['foodlist3'])
+ // ->where($search_sql_str)
+ // ->count();
+ // $page_total = ceil($content_num/$cp_page_num);
+
+ // $collect_list = $cfc->table($this->kitchenscale_db_msg['foodlist3'])
+ // ->where($search_sql_str)
+ // ->field('id,record_id,food_name as name,pic_url,Calorie_val as kcal,weight_unit as unit')
+ // ->page($data['page'],$cp_page_num)
+ // ->select();
+ $cp_page_num = 15;
+ $cfc = Db::connect('cfc_db');
+ $search_sql_str = "is_del = 0";
+ if(!array_key_exists('search_data', $data)){
+ $data['search_data'] = "";
+ $ss = "";
+ }else{
+ if($data['search_data'] === ""){
+ $data['search_data'] = "";
+ $ss = "";
+ }else{
+ $ss = $data['search_data'];
+ $data['search_data'] = " AND food_name LIKE '%".str_replace('[', '[[]', $ss)."%'";
+
+ }
+ }
+ $search_sql_str = $search_sql_str.$data['search_data'];
+
+ // 计算总数
+ $count_sql = "SELECT COUNT(*) as total FROM {$this->kitchenscale_db_msg['foodlist3']} WHERE {$search_sql_str}";
+ $count_result = $cfc->query($count_sql);
+ $content_num = $count_result[0]['total'] ?? 0;
+ $page_total = ceil($content_num/$cp_page_num);
+
+ // 计算分页偏移量
+ $page = max(1, intval($data['page']));
+ $offset = ($page - 1) * $cp_page_num;
+
+ // SQL Server分页查询 - 使用OFFSET FETCH语法(SQL Server 2012及以上版本)
+ $sql = "SELECT id, record_id, food_name as name, pic_url, Calorie_val as kcal, weight_unit as unit
+ FROM {$this->kitchenscale_db_msg['foodlist3']}
+ WHERE {$search_sql_str}
+ ORDER BY id
+ OFFSET {$offset} ROWS
+ FETCH NEXT {$cp_page_num} ROWS ONLY";
+
+ // dump($count_sql);
+
+ $collect_list = $cfc->query($sql);
+
+
+ if(count($collect_list) > 0){
+ $nutrients_list_id = [];
+ $nutrients_list_temporary = [];
+ foreach ($collect_list as $key => $value) {
+ $collect_list[$key]['pic_url'] = "https://tc.pcxbc.com/kitchenscale_all".$collect_list[$key]['pic_url'];
+ array_push($nutrients_list_id,$collect_list[$key]['record_id']);
+ $nutrients_list_temporary[$collect_list[$key]['record_id']] = [];
+ if (!is_numeric($collect_list[$key]['kcal'])) {
+ $collect_list[$key]['kcal'] = 0;
+ }
+ }
+
+ // 处理营养物质
+ $nutrients_list_data = $cfc->table($this->kitchenscale_db_msg['foodlist4'])
+ ->where("father_id in (". implode(',',$nutrients_list_id) .")")
+ ->field("father_id,name,name_ch,unit,value,type")
+ ->select();
+
+ for ($i=0; $i < count($nutrients_list_data); $i++) {
+ if(!is_numeric($nutrients_list_data[$i]['value']) || $nutrients_list_data[$i]['value'] == 0){
+ continue;
+ }else{
+ array_push($nutrients_list_temporary[$nutrients_list_data[$i]['father_id']],[
+ 'name'=>$nutrients_list_data[$i]['name'],
+ 'name_ch'=>$nutrients_list_data[$i]['name_ch'],
+ 'unit'=>$nutrients_list_data[$i]['unit'],
+ 'value'=>$nutrients_list_data[$i]['value'],
+ 'type'=>$nutrients_list_data[$i]['type'],
+ 'type_name'=>$nutrients_list_data[$i]['type'] == 1?'能量及宏量营养素':($nutrients_list_data[$i]['type'] == 2?'维生素':'矿物质'),
+ 'color'=>$nutrients_list_data[$i]['type'] == 1?'#C4FFE0':($nutrients_list_data[$i]['type'] == 2?'#FFEFB7':'#7DA8E0')
+ ]);
+ }
+ }
+
+ for ($i=0; $i < count($collect_list); $i++) {
+ $collect_list[$i]['nutrients_four'] = [];
+ $collect_list[$i]['nutrients_list'] = [];
+ $temporary_calculate = 0;
+ if(array_key_exists($collect_list[$i]['record_id'],$nutrients_list_temporary)){
+ $collect_list[$i]['nutrients_list'] = $nutrients_list_temporary[$collect_list[$i]['record_id']];
+ foreach ($nutrients_list_temporary[$collect_list[$i]['record_id']] as $key => $value) {
+ if($value['type'] == 1){
+ array_push($collect_list[$i]['nutrients_four'],[
+ 'name'=>$value['name'] == 'Carbohydrate'?'碳水':$value['name_ch'],
+ 'unit'=>$value['unit'],
+ 'color'=>$value['name'] == 'Carbohydrate'?'#FFB169':($value['name'] == 'Fat'?'#ED7886':($value['name'] == 'Protein'?'#5180D8':'')),
+ 'value'=>!is_numeric($value['value'])?0:$value['value'],
+ ]);
+ // 如果不为卡路里
+ if($value['name'] != 'Calorie'){
+ $temporary_calculate = $temporary_calculate+$value['value'];
+ }
+ }
+ }
+ // 处理详情当中的环数据占比
+ foreach ($collect_list[$i]['nutrients_four'] as $k => $v) {
+ if($v['name'] != '卡路里'){
+ $collect_list[$i]['nutrients_four'][$k]['proportion'] = bcmul(bcdiv($v['value'],$temporary_calculate,2),100,0);
+ }else{
+ $collect_list[$i]['nutrients_four'][$k]['proportion'] = 0;
+ }
+ }
+ }
+ }
+ }
+
+
+ // 记录搜索历史
+ if(array_key_exists('token',$data) && $data['token'] != '' && $ss != ''){
+ $user_data = $cfc->table($this->kitchenscale_db_msg['user'])->where(['token'=>$data['token']])->field('id,token')->find();
+ if($user_data){
+ $this->add_search_history_action(['id'=>$user_data['id'],'search_data'=>$ss,'type'=>'food']);
+ }
+ }
+
+ return $this->msg([
+ 'page_now'=>$data['page'],
+ 'page_total'=>$page_total,
+ 'content_list'=>$collect_list
+ ]);
+ }
+ public function get_cookbook_label_list_action(){
+ $cfc = Db::connect('cfc_db');
+ // 获取菜谱分类标签start
+ $cook_label = $cfc->table($this->kitchenscale_db_msg['cookbook_label'])
+ ->where("is_del = 0")
+ ->field('id,name')
+ ->select();
+ $temporary_label = [];
+ foreach ($cook_label as $key => $value) {
+ unset($cook_label[$key]['ROW_NUMBER']);
+ $cook_label[$key]['list'] = [];
+ $temporary_label[$value['id']] = $key;
+ }
+ $content_list = $cfc->table($this->kitchenscale_db_msg['cookbook'])
+ ->alias('a')
+ ->join($this->kitchenscale_db_msg['uploadimg'].' b','a.cover = b.id','LEFT')
+ ->where(['a.is_del'=>0])
+ ->field('a.id,a.cook_label,a.title,b.pic_url as cover')
+ ->select();
+ foreach ($content_list as $key => $value) {
+ unset($content_list[$key]['ROW_NUMBER']);
+ array_push($cook_label[$temporary_label[$value['cook_label']]]['list'],$content_list[$key]);
+ }
+ return $this->msg($cook_label);
+ // 获取菜谱分类标签end
+ }
+
+ public function get_search_food_page_list_action($data){
+ $cfc = Db::connect('cfc_db');
+ // 获取菜谱分类标签start
+ // 蔬菜类id:4 6 7
+ // 肉类id:10 11 14
+ $data_list = $cfc->table($this->kitchenscale_db_msg['foodlist3'])
+ ->where('two_id in (4,6,7,10,11,14) and is_popular = 1')
+ ->field('id,food_name,two_id')
+ ->select();
+ $result = [
+ 'food'=>[
+ 'title'=>'流行食材',
+ 'list'=>[
+ [
+ 'title'=>'蔬菜',
+ 'list'=>[]
+ ],
+ [
+ 'title'=>'肉类',
+ 'list'=>[]
+ ],
+ ]
+ ],
+ 'log'=>[],
+ ];
+ foreach ($data_list as $key => $value) {
+ if($value['two_id'] == 4 || $value['two_id'] == 6 || $value['two_id'] == 7){
+ array_push($result['food']['list'][0]['list'],['id'=>$value['id'],'name'=>$value['food_name']]);
+ }else if($value['two_id'] == 10 || $value['two_id'] == 11 || $value['two_id'] == 14){
+ array_push($result['food']['list'][1]['list'],['id'=>$value['id'],'name'=>$value['food_name']]);
+ }
+ }
+
+ return $this->msg($result);
+ // 获取菜谱分类标签end
+ }
+
+
+
+
+
+
+
+
+
+ #######################################################################小工具#######################################################################
+ #######################################################################小工具#######################################################################
+ #######################################################################小工具#######################################################################
+
+ // 处理食材的卡路里
+ public function count_calorie($data,$step){
+
+ $foot_name = array_column($data, 'id');
+ $foot_name = array_unique($foot_name);
+ $cfc = Db::connect('cfc_db');
+ $foot_kcal = $cfc->table($this->kitchenscale_db_msg['foodlist3'])->where("id in ('".implode("','", $foot_name)."')")->field("id,food_name as name,Calorie_val as kcal")->select();
+ $foot_kcal2 = [];
+ foreach ($foot_kcal as $key => $value) {
+ $foot_kcal2[$value['name']] = [$value['id'],$value['kcal']];
+ }
+ // dump($data);
+ // dump($foot_kcal2);
+ // die;
+ foreach ($data as $key => $value) {
+ if(array_key_exists($value['name'], $foot_kcal2)){
+ $data[$key]['id'] = $foot_kcal2[$value['name']][0];
+ $data[$key]['kcal'] = $foot_kcal2[$value['name']][1];
+ }else{
+ $data[$key]['kcal'] = '0';
+ $data[$key]['id'] = 0;
+ }
+ $data[$key]['unit'] = 'g';
+ }
+
+
+ return $data;
+ }
+
+
+ // 加 bcadd(,,20)
+ // 减 bcsub(,,20)
+ // 乘 bcmul(,,20)
+ // 除 bcdiv(,,20)
+ // 计算卡路里
+ public function count_calorie_action($weight,$kcal){
+ $weight = bcdiv($weight,100,2);
+ return bcmul($weight,$kcal,2);
+ }
+
+
+
+ public function chuli_shuju(){
+ $cfc = Db::connect('cfc_db');
+ // $foot_kcal = $cfc->table('app_user_cookbook')->field("food_data,id")->select();
+ // $foot_name = [];
+ // // dump($foot_kcal);
+ // foreach ($foot_kcal as $key => $value) {
+ // unset($foot_kcal[$key]['ROW_NUMBER']);
+ // $foot_kcal[$key]['food_data'] = json_decode($foot_kcal[$key]['food_data'],true);
+ // foreach ($foot_kcal[$key]['food_data'] as $k => $v) {
+ // $linshi_data = $v;
+ // // dump($linshi_data);
+ // $foot_kcal[$key]['food_data'][$k] = [];
+ // $foot_kcal[$key]['food_data'][$k]['name'] = $linshi_data['name'];
+ // $foot_kcal[$key]['food_data'][$k]['weight'] = $linshi_data['weight'];
+ // $foot_kcal[$key]['food_data'][$k]['unit'] = 'g';
+ // $foot_kcal[$key]['food_data'][$k]['kcal'] = rtrim($linshi_data['kcal'], "kcal");
+ // if(!in_array($linshi_data['name'], $foot_name)){
+ // array_push($foot_name,$linshi_data['name']);
+ // }
+ // }
+ // // $foot_kcal[$key]['food_data'] = $foot_kcal[$key]['food_data'][0];
+
+ // // $foot_kcal[$key]['food_data'] = json_encode($foot_kcal[$key]['food_data']);
+ // }
+
+ // $shicai = $cfc->table($this->kitchenscale_db_msg['foodlist3'])->where("name in ('".implode("','", $foot_name)."')")->field("id,name,kcal")->select();
+ // $shicai2 = [];
+ // foreach ($shicai as $key => $value) {
+ // $shicai2[$value['name']] = [$value['id'],$value['kcal']];
+ // }
+ // // dump($shicai2);
+ // foreach ($foot_kcal as $key => $value) {
+ // foreach ($foot_kcal[$key]['food_data'] as $k => $v) {
+ // $foot_kcal[$key]['food_data'][$k]['kcal'] = $shicai2[$v['name']][1];
+ // $foot_kcal[$key]['food_data'][$k]['id'] = $shicai2[$v['name']][0];
+ // }
+ // // $foot_kcal[$key]['food_data'] = $foot_kcal[$key]['food_data'][0];
+
+ // $foot_kcal[$key]['food_data'] = json_encode($foot_kcal[$key]['food_data']);
+ // }
+
+ // // dump($foot_kcal);
+ // // die;
+ // foreach ($foot_kcal as $key => $value) {
+ // $cfc->table('app_user_cookbook')->where(['id'=>$value['id']])->update(['food_data'=>$value['food_data']]);
+ // }
+ // dump($foot_kcal);
+ // die;
+
+
+ $sql = "SELECT father_id,count(*) as num FROM app_z_national_standard_food_type_4 GROUP BY father_id ORDER BY num DESC";
+
+ $result = $cfc->query($sql);
+ $aa = [];
+ foreach ($result as $key => $value) {
+ if($value['num'] >= 30){
+ $aa[] = $value['father_id'];
+ }
+ }
+ $bb = implode("','",$aa);
+
+ $sql2 = "SELECT id,father_id FROM app_z_national_standard_food_type_4 WHERE father_id IN ('".$bb."')";
+ $result2 = $cfc->query($sql2);
+
+ $cc = [];
+ foreach ($result2 as $key => $value) {
+ if (array_key_exists($value['father_id'], $cc)) {
+ // 基本用法
+ if (!in_array($value['id'], $cc[$value['father_id']])) {
+ $cc[$value['father_id']][] = $value['id'];
+ }
+ } else {
+ $cc[$value['father_id']] = [$value['id']];
+ }
+ }
+
+ $toDeleteStructured = [];
+
+ foreach ($cc as $key => $value) {
+ // 每个数组有58个元素,后29个是需要删除的
+ $deletePart = array_slice($value, 29, 29);
+ $toDeleteStructured[$key] = $deletePart;
+ // $toDeleteStructured[$key] = count($deletePart);
+ }
+
+ foreach ($toDeleteStructured as $key => $value) {
+ $zz = implode("','",$value);
+
+ $result3 = $cfc->table('app_z_national_standard_food_type_4')
+ ->where("id in ('".$zz."')")
+ ->update(['is_del'=>1]);
+ dump($key);
+ dump($result3);
+ // $sql3 = "UPDATE app_z_national_standard_food_type_4 SET is_del = 1 WHERE id IN (".$zz.")";
+ // $result3 = $cfc->query($sql3);
+ }
+
+ // foreach ($toDeleteStructured as $key => $value) {
+
+ // foreach ($value as $k => $v) {
+ // $dd[] = $v;
+ // }
+ // }
+ // $zz = implode(",",$dd);
+ // $sql3 = "UPDATE app_z_national_standard_food_type_4 SET is_del = 1 WHERE id IN (".$zz.")";
+ // $result3 = $cfc->query($sql3);
+ // dump($result3);
+ // dump($toDeleteStructured);
+ }
+
+
+
+
+}
\ No newline at end of file
diff --git a/application/KitchenScale2/controller/app/Countfood.php b/application/KitchenScale2/controller/app/Countfood.php
new file mode 100644
index 0000000..d6fdee1
--- /dev/null
+++ b/application/KitchenScale2/controller/app/Countfood.php
@@ -0,0 +1,1486 @@
+'app_account_number',//账号表
+ 'juese'=>'app_user_data',//角色表
+ ];
+ protected $kitchenscale_db_msg = [
+ 'cookbook'=>'app_user_cookbook',//菜谱表
+ 'uploadimg'=>'app_user_upload_img',//素材表
+ 'followlist'=>'app_user_follow_list',//关注列表
+ 'collect_list'=>'app_user_collect_list',//收藏列表
+ 'foodlist3'=>'app_z_national_standard_food_type_3',//食材列表3
+ 'foodlist4'=>'app_z_national_standard_food_type_4',//食材列表3
+ 'eat_log'=>'app_user_kcal_log',//食材列表3
+ 'user'=>'app_user_data',//banner
+ ];
+
+ // 加 bcadd(,,20)
+ // 减 bcsub(,,20)
+ // 乘 bcmul(,,20)
+ // 除 bcdiv(,,20)
+ ################################################################接口################################################################
+ ################################################################接口################################################################
+ ################################################################接口################################################################
+
+ // 添加每日摄入记录
+ public function add_intake_food($data=['token'=>'3e5876042361c8cb42bd48c46918f737','aud_id'=>6,'meals_type'=>'早餐','food_list'=>[['id'=>2778,'name'=>"啤酒(X)",'weight'=>'150','unit'=>'g']]]){
+ // 尝试捕获异常
+ try {
+ if(count(input('post.')) > 0){
+ $data = input('post.');
+ }
+ if(!array_key_exists('token', $data)){
+ return $this->msg(10001,'token is miss');
+ }
+ if(!array_key_exists('aud_id', $data)){
+ return $this->msg(10001,'aud_id is miss');
+ }
+ if(!array_key_exists('food_list', $data)){
+ return $this->msg(10001,'food_list is miss');
+ }
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005,'token type is error');
+ }
+ if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
+ return $this->msg(10005,'aud_id type is error');
+ }
+ $return_data = $this->add_intake_food_action($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'] .= "行号: " . $e->getLine() . "\n";
+ $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
+ // 记录日志
+ $this->record_api_log($data, $logContent, null);
+ return json(['status' => 'error', 'message' => '系统错误']);
+ }
+ }
+ // 获取记食器板块内容
+ public function get_countfoot_content(){
+ // 尝试捕获异常
+ // try {
+ if(count(input('post.')) > 0){
+ $data = input('post.');
+ }
+ if(!array_key_exists('token', $data)){
+ return $this->msg(10001,'token is miss');
+ }
+ if(!array_key_exists('aud_id', $data)){
+ return $this->msg(10001,'aud_id is miss');
+ }
+ if(!array_key_exists('time', $data)){
+ return $this->msg(10001,'time is miss');
+ }
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005,'token type is error');
+ }
+ if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
+ return $this->msg(10005,'aud_id type is error');
+ }
+ if(!$this->verify_data_is_ok($data['time'],'datetime')){
+ return $this->msg(10005,'time type is error');
+ }
+
+ $return_data = $this->get_countfoot_content_action($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'] .= "行号: " . $e->getLine() . "\n";
+ // $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
+ // // 记录日志
+ // $this->record_api_log($data, $logContent, null);
+ // return json(['status' => 'error', 'message' => '系统错误']);
+ // }
+ }
+ // 获取记食器记录
+ public function get_log_list($data=['token'=>'caadd1be045a65f30b92aa805f1de54a','aud_id'=>1,'page'=>1]){
+ // 尝试捕获异常
+ // try {
+ if(count(input('post.')) > 0){
+ $data = input('post.');
+ }
+ if(!array_key_exists('token', $data)){
+ return $this->msg(10001,'token is miss');
+ }
+ if(!array_key_exists('aud_id', $data)){
+ return $this->msg(10001,'aud_id is miss');
+ }
+ if(!array_key_exists('page', $data)){
+ return $this->msg(10001,'page is miss');
+ }
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005,'token type is error');
+ }
+ if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
+ return $this->msg(10005,'aud_id type is error');
+ }
+ if(!$this->verify_data_is_ok($data['page'],'intnum')){
+ return $this->msg(10005,'page type is error');
+ }
+
+ $return_data = $this->get_log_list_action($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'] .= "行号: " . $e->getLine() . "\n";
+ // $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
+ // // 记录日志
+ // $this->record_api_log($data, $logContent, null);
+ // return json(['status' => 'error', 'message' => '系统错误']);
+ // }
+ }
+ // 计食器板块-设置内容
+ public function set_up_content($data=['token'=>'caadd1be045a65f30b92aa805f1de54a','aud_id'=>61]){
+ // 尝试捕获异常
+ try {
+ if(count(input('post.')) > 0){
+ $data = input('post.');
+ }
+ if(!array_key_exists('token', $data)){
+ return $this->msg(10001,'token is miss');
+ }
+ if(!array_key_exists('aud_id', $data)){
+ return $this->msg(10001,'aud_id is miss');
+ }
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005,'token type is error');
+ }
+ if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
+ return $this->msg(10005,'aud_id type is error');
+ }
+
+ $return_data = $this->set_up_content_action($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'] .= "行号: " . $e->getLine() . "\n";
+ $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
+ // 记录日志
+ $this->record_api_log($data, $logContent, null);
+ return json(['status' => 'error', 'message' => '系统错误']);
+ }
+ }
+ // 设置用户的卡路里
+ public function set_user_kcal($data=['token'=>'caadd1be045a65f30b92aa805f1de54a','aud_id'=>61,'set_kcal'=>2000]){
+ // 尝试捕获异常
+ try {
+ if(count(input('post.')) > 0){
+ $data = input('post.');
+ }
+ if(!array_key_exists('token', $data)){
+ return $this->msg(10001,'token is miss');
+ }
+ if(!array_key_exists('aud_id', $data)){
+ return $this->msg(10001,'aud_id is miss');
+ }
+ if(!array_key_exists('set_kcal', $data)){
+ return $this->msg(10001,'set_kcal is miss');
+ }
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005,'token type is error');
+ }
+ if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
+ return $this->msg(10005,'aud_id type is error');
+ }
+ if(!$this->verify_data_is_ok($data['set_kcal'],'num')){
+ return $this->msg(10005,'set_kcal type is error');
+ }
+
+ $return_data = $this->set_user_kcal_action($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'] .= "行号: " . $e->getLine() . "\n";
+ $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
+ // 记录日志
+ $this->record_api_log($data, $logContent, null);
+ return json(['status' => 'error', 'message' => '系统错误']);
+ }
+ }
+ public function del_user_eat_log($data=['token'=>'caadd1be045a65f30b92aa805f1de54a','aud_id'=>6,'eat_log_id'=>160]){
+ // 尝试捕获异常
+ try {
+ if(count(input('post.')) > 0){
+ $data = input('post.');
+ }
+ if(!array_key_exists('token', $data)){
+ return $this->msg(10001,'token is miss');
+ }
+ if(!array_key_exists('aud_id', $data)){
+ return $this->msg(10001,'aud_id is miss');
+ }
+ if(!array_key_exists('eat_log_id', $data)){
+ return $this->msg(10001,'eat_log_id is miss');
+ }
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005,'token type is error');
+ }
+ if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
+ return $this->msg(10005,'aud_id type is error');
+ }
+ if(!$this->verify_data_is_ok($data['eat_log_id'],'num')){
+ return $this->msg(10005,'eat_log_id type is error');
+ }
+
+ $return_data = $this->del_user_eat_log_action($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'] .= "行号: " . $e->getLine() . "\n";
+ $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
+ // 记录日志
+ $this->record_api_log($data, $logContent, null);
+ return json(['status' => 'error', 'message' => '系统错误']);
+ }
+ }
+ public function del_user_eat_list_log(){
+ // 尝试捕获异常
+ try {
+ if(count(input('post.')) > 0){
+ $data = input('post.');
+ }
+ if(!array_key_exists('token', $data)){
+ return $this->msg(10001,'token is miss');
+ }
+ if(!array_key_exists('time', $data)){
+ return $this->msg(10001,'time is miss');
+ }
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005,'token type is error');
+ }
+ if(!$this->verify_data_is_ok($data['time'],'datetime')){
+ return $this->msg(10005,'time type is error');
+ }
+
+ $return_data = $this->del_user_eat_list_log_action($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'] .= "行号: " . $e->getLine() . "\n";
+ $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
+ // 记录日志
+ $this->record_api_log($data, $logContent, null);
+ return json(['status' => 'error', 'message' => '系统错误']);
+ }
+ }
+ #######################################################################action#######################################################################
+ #######################################################################action#######################################################################
+ #######################################################################action#######################################################################
+ // 加 bcadd(,,20)
+ // 减 bcsub(,,20)
+ // 乘 bcmul(,,20)
+ // 除 bcdiv(,,20)
+
+ public function add_intake_food_action($data){
+
+
+ $cfc = Db::connect('cfc_db');
+ $user_data = $cfc->table($this->kitchenscale_db_msg['user'])
+ ->where(["id"=>$data['aud_id']])
+ ->field('weight,height,gender,age,is_use_set_kcal,set_kcal')
+ ->find();
+ if(!$user_data){
+ return $this->msg(10003);
+ }
+
+ // 统计食物的id
+ $food_id_arr = [];
+
+ foreach ($data['food_list'] as $key => $value) {
+ if(!array_key_exists('id', $value)){
+ return $this->msg(10001,'id is miss');
+ }
+ if(!array_key_exists('weight', $value)){
+ return $this->msg(10001,'weight is miss');
+ }
+ if(!array_key_exists('meals_type', $value)){
+ return $this->msg(10001,'meals_type is miss');
+ }
+ if(!$this->verify_data_is_ok($value['id'],'intnum')){
+ return $this->msg(10005,'id type is error');
+ }
+ if(!$this->verify_data_is_ok($value['weight'],'num')){
+ return $this->msg(10005,'weight type is error');
+ }
+ if(!in_array($value['meals_type'],['早餐','午餐','晚餐','加餐'])){
+ return $this->msg(10005,'meals_type type is error');
+ }
+
+ foreach ($data['food_list'][$key] as $k => $v) {
+ if(!in_array($k,['id','weight','meals_type'])){
+ unset($data['food_list'][$key][$k]);
+ }
+ }
+ array_push($food_id_arr,$value['id']);
+ }
+
+ $food_content = $cfc->table($this->kitchenscale_db_msg['foodlist3'])
+ ->where("id in (".implode(',',$food_id_arr).")")
+ ->field('id,food_name as name,Calorie_val as kcal,Carbohydrate_val as carbohydrate,Protein_val as protein,Fat_val as fat')
+ ->select();
+
+ if(count($food_content) <= 0){
+ return $this->msg(10004,'未找到对应食材');
+ }
+
+ // 整理食物信息
+ $food_content_arr = [];
+ foreach ($food_content as $key => $value) {
+ $food_content_arr[$value['id']] = $value;
+ }
+ $create_time = date('Y-m-d H:i:s');
+ foreach ($data['food_list'] as $key => $value) {
+ //获取每100g食物的比例
+ $proportion_num = bcdiv($value['weight'],100,2);
+ if(array_key_exists($value['id'], $food_content_arr)){
+ $data['food_list'][$key]['kcal_val'] = bcmul($food_content_arr[$value['id']]['kcal'],$proportion_num,2);
+ $data['food_list'][$key]['carbohydrate_val'] = bcmul($food_content_arr[$value['id']]['carbohydrate'],$proportion_num,2);
+ $data['food_list'][$key]['protein_val'] = bcmul($food_content_arr[$value['id']]['protein'],$proportion_num,2);
+ $data['food_list'][$key]['fat_val'] = bcmul($food_content_arr[$value['id']]['fat'],$proportion_num,2);
+ $data['food_list'][$key]['food_name'] = $food_content_arr[$value['id']]['name'];
+ $data['food_list'][$key]['aud_id'] = $data['aud_id'];
+ $data['food_list'][$key]['meals_type'] = $value['meals_type'];
+ $data['food_list'][$key]['create_time'] = $create_time;
+ $data['food_list'][$key]['food_id'] = $value['id'];
+ unset($data['food_list'][$key]['id']);
+
+ }else{
+ unset($data['food_list'][$key]);
+ }
+ }
+ // dump($data['food_list']);
+ // die;
+ // 数据库数据字段:id,aud_id,meals_type,food_id,food_name,weight,kcal_val,carbohydrate_val,protein_val,fat_val,create_time
+ // 启动事务
+
+ Db::startTrans();
+ try{
+ $result = $cfc->table($this->kitchenscale_db_msg['eat_log'])->insertAll($data['food_list']);
+ if ($result !== count($data['food_list'])) {
+ Db::rollback();
+ return $this->msg(10002,'添加数据错误');
+ } else {
+ Db::commit();
+ return $this->msg([]);
+ }
+ } catch (\Exception $e) {
+ // 回滚事务
+ Db::rollback();
+ return $this->msg(10002);
+ }
+
+ // dump($data);
+ // dump($food_id_arr);
+ // dump($food_content);
+ // die;
+ }
+ public function get_countfoot_content_action($data){
+ $cfc = Db::connect('cfc_db');
+
+ $user_data = $cfc->table($this->kitchenscale_db_msg['user'])
+ ->where(["id"=>$data['aud_id']])
+ ->field('weight,height,gender,age,birthday,is_use_set_kcal,set_kcal')
+ ->find();
+ if(!$user_data){
+ return $this->msg(10003);
+ }
+ if($user_data['birthday']){
+ $user_data['age_num'] = $this->calculate_age($user_data['birthday']);
+ }else{
+ $user_data['age_num'] = $user_data['age'];
+ }
+ $nutrition_data = $this->count_user_nutrition_all($user_data);
+ if($user_data['is_use_set_kcal'] == 1){
+ $proportion = bcdiv($user_data['set_kcal'],$nutrition_data['kcal'],20);
+ $nutrition_data['kcal'] = $user_data['set_kcal'];
+ $nutrition_data['carbohydrate'] = bcmul($nutrition_data['carbohydrate'],$proportion,2);
+ $nutrition_data['protein'] = bcmul($nutrition_data['protein'],$proportion,2);
+ $nutrition_data['fat'] = bcmul($nutrition_data['fat'],$proportion,2);
+
+ }
+ $return_data = [
+ 'date'=>$data['time'], //时间
+ 'suggestion'=>[ //建议
+ 'kcal'=>$nutrition_data['kcal'], //建议摄入卡路里量
+ 'carbohydrate'=>$nutrition_data['carbohydrate'], //建议摄入碳水量
+ 'protein'=>$nutrition_data['protein'], //建议摄入蛋白质量
+ 'fat'=>$nutrition_data['fat'], //建议摄入脂肪量
+ ],
+ 'today_intake'=>[ //今日已摄入
+ 'kcal'=>0, //今日已摄入卡路里量
+ 'carbohydrate'=>0, //今日已摄入碳水量
+ 'protein'=>0, //今日已摄入蛋白质量
+ 'fat'=>0, //今日已摄入脂肪量
+ ],
+ 'remaining_kcal'=>$nutrition_data['kcal'], //剩下可摄入卡路里量
+ 'details'=>[ //当天营养元素能量占比
+ 'carbohydrate'=>['name'=>'碳水','icon'=>'https://tc.pcxbc.com/kitchenscale_all/icon_carbohydrate.png','color'=>'#ED7886','val'=>0,'unit'=>'g','proportion'=>'0.00','rank_list'=>[['icon'=>'https://tc.pcxbc.com/kitchenscale_all/rank1.png','name'=>'','pic_url'=>'','weight'=>''],['icon'=>'https://tc.pcxbc.com/kitchenscale_all/rank2.png','name'=>'','pic_url'=>'','weight'=>''],['icon'=>'https://tc.pcxbc.com/kitchenscale_all/rank3.png','name'=>'','pic_url'=>'','weight'=>'']]],
+ 'protein'=>['name'=>'蛋白质','icon'=>'https://tc.pcxbc.com/kitchenscale_all/icon_protein.png','color'=>'#FFB169','val'=>0,'unit'=>'g','proportion'=>'0.00','rank_list'=>[['icon'=>'https://tc.pcxbc.com/kitchenscale_all/rank1.png','name'=>'','pic_url'=>'','weight'=>''],['icon'=>'https://tc.pcxbc.com/kitchenscale_all/rank2.png','name'=>'','pic_url'=>'','weight'=>''],['icon'=>'https://tc.pcxbc.com/kitchenscale_all/rank3.png','name'=>'','pic_url'=>'','weight'=>'']]],
+ 'fat'=>['name'=>'脂肪','icon'=>'https://tc.pcxbc.com/kitchenscale_all/icon_fat.png','color'=>'#3CB383','val'=>0,'unit'=>'g','proportion'=>'0.00','rank_list'=>[['icon'=>'https://tc.pcxbc.com/kitchenscale_all/rank1.png','name'=>'','pic_url'=>'','weight'=>''],['icon'=>'https://tc.pcxbc.com/kitchenscale_all/rank2.png','name'=>'','pic_url'=>'','weight'=>''],['icon'=>'https://tc.pcxbc.com/kitchenscale_all/rank3.png','name'=>'','pic_url'=>'','weight'=>'']]],
+ ],
+ 'trace_elements_all_day' => [
+ [
+ 'name' => 'VitaminA',
+ 'name_ch' => '维生素A',
+ 'unit' => 'μg RAE',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'VitaminB1',
+ 'name_ch' => '硫胺素',
+ 'unit' => 'mg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'VitaminB2',
+ 'name_ch' => '核黄素',
+ 'unit' => 'mg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'VitaminB6',
+ 'name_ch' => '维生素B6',
+ 'unit' => 'mg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'VitaminB12',
+ 'name_ch' => '维生素B12',
+ 'unit' => 'μg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'VitaminD',
+ 'name_ch' => '维生素D',
+ 'unit' => 'μg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'VitaminK',
+ 'name_ch' => '维生素K',
+ 'unit' => 'μg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'Niacin',
+ 'name_ch' => '烟酸',
+ 'unit' => 'mg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'VitaminC',
+ 'name_ch' => '维生素C',
+ 'unit' => 'mg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'VitaminE',
+ 'name_ch' => '维生素E',
+ 'unit' => 'mg α-TE',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'FolicAcid',
+ 'name_ch' => '叶酸',
+ 'unit' => 'μg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'Biotin',
+ 'name_ch' => '生物素',
+ 'unit' => 'μg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'PantothenicAcid',
+ 'name_ch' => '泛酸',
+ 'unit' => 'mg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'TotalCholine',
+ 'name_ch' => '总胆碱',
+ 'unit' => 'mg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'Ca',
+ 'name_ch' => '钙',
+ 'unit' => 'mg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'Phosphorus',
+ 'name_ch' => '磷',
+ 'unit' => 'mg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'Kalium',
+ 'name_ch' => '钾',
+ 'unit' => 'mg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'Mg',
+ 'name_ch' => '镁',
+ 'unit' => 'mg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'Na',
+ 'name_ch' => '钠',
+ 'unit' => 'mg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'Fe',
+ 'name_ch' => '铁',
+ 'unit' => 'mg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'Zn',
+ 'name_ch' => '锌',
+ 'unit' => 'mg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'Se',
+ 'name_ch' => '硒',
+ 'unit' => 'μg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'Cu',
+ 'name_ch' => '铜',
+ 'unit' => 'mg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'Mn',
+ 'name_ch' => '锰',
+ 'unit' => 'mg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'Iodine',
+ 'name_ch' => '碘',
+ 'unit' => 'μg',
+ 'value' => 0
+ ]
+ ],
+ 'list'=>[
+ [
+ 'name'=>'早餐',
+ 'val'=>0,
+ 'unit'=>'kcal',
+ 'color'=>'#0992B4',
+ 'icon'=>'https://tc.pcxbc.com/kitchenscale_all/meal_1.png',
+ 'icon_home'=>'/static/1.png',
+ 'bgimg_home'=>'/static/2.png',
+ 'kcal_proportion'=>0,
+ "nutrients_four"=> [
+ [
+ 'name'=>'卡路里',
+ 'unit'=>'kcal',
+ 'color'=>'',
+ 'value'=>0,
+ 'proportion'=>0,
+ ],
+ [
+ 'name'=>'碳水化合物',
+ 'unit'=>'g',
+ 'color'=>'#FFB169',
+ 'value'=>0,
+ 'proportion'=>0,
+ ],
+ [
+ 'name'=>'蛋白质',
+ 'unit'=>'g',
+ 'color'=>'#5180D8',
+ 'value'=>0,
+ 'proportion'=>0,
+ ],
+ [
+ 'name'=>'脂肪',
+ 'unit'=>'g',
+ 'color'=>'#ED7886',
+ 'value'=>0,
+ 'proportion'=>0,
+ ],
+
+ ],
+ 'list'=>[],
+ ],
+ [
+ 'name'=>'午餐',
+ 'val'=>0,
+ 'unit'=>'kcal',
+ 'color'=>'#4F9211',
+ 'icon'=>'https://tc.pcxbc.com/kitchenscale_all/meal_2.png',
+ 'icon_home'=>'/static/3.png',
+ 'bgimg_home'=>'/static/4.png',
+ 'kcal_proportion'=>0,
+ "nutrients_four"=> [
+ [
+ 'name'=>'卡路里',
+ 'unit'=>'kcal',
+ 'color'=>'',
+ 'value'=>0,
+ 'proportion'=>0,
+ ],
+ [
+ 'name'=>'蛋白质',
+ 'unit'=>'g',
+ 'color'=>'#5180D8',
+ 'value'=>0,
+ 'proportion'=>0,
+ ],
+ [
+ 'name'=>'脂肪',
+ 'unit'=>'g',
+ 'color'=>'#ED7886',
+ 'value'=>0,
+ 'proportion'=>0,
+ ],
+ [
+ 'name'=>'碳水化合物',
+ 'unit'=>'g',
+ 'color'=>'#FFB169',
+ 'value'=>0,
+ 'proportion'=>0,
+ ],
+ ],
+ 'list'=>[],
+ ],
+ [
+ 'name'=>'晚餐',
+ 'val'=>0,
+ 'unit'=>'kcal',
+ 'color'=>'#B354B0',
+ 'icon'=>'https://tc.pcxbc.com/kitchenscale_all/meal_3.png',
+ 'icon_home'=>'/static/5.png',
+ 'bgimg_home'=>'/static/6.png',
+ 'kcal_proportion'=>0,
+ "nutrients_four"=> [
+ [
+ 'name'=>'卡路里',
+ 'unit'=>'kcal',
+ 'color'=>'',
+ 'value'=>0,
+ 'proportion'=>0,
+ ],
+ [
+ 'name'=>'蛋白质',
+ 'unit'=>'g',
+ 'color'=>'#5180D8',
+ 'value'=>0,
+ 'proportion'=>0,
+ ],
+ [
+ 'name'=>'脂肪',
+ 'unit'=>'g',
+ 'color'=>'#ED7886',
+ 'value'=>0,
+ 'proportion'=>0,
+ ],
+ [
+ 'name'=>'碳水化合物',
+ 'unit'=>'g',
+ 'color'=>'#FFB169',
+ 'value'=>0,
+ 'proportion'=>0,
+ ],
+ ],
+ 'list'=>[],
+ ],
+ [
+ 'name'=>'加餐',
+ 'val'=>0,
+ 'unit'=>'kcal',
+ 'color'=>'#C08433',
+ 'icon'=>'https://tc.pcxbc.com/kitchenscale_all/meal_4.png',
+ 'icon_home'=>'/static/7.png',
+ 'bgimg_home'=>'/static/8.png',
+ 'kcal_proportion'=>0,
+ "nutrients_four"=> [
+ [
+ 'name'=>'卡路里',
+ 'unit'=>'kcal',
+ 'color'=>'',
+ 'value'=>0,
+ 'proportion'=>0,
+ ],
+ [
+ 'name'=>'蛋白质',
+ 'unit'=>'g',
+ 'color'=>'#5180D8',
+ 'value'=>0,
+ 'proportion'=>0,
+ ],
+ [
+ 'name'=>'脂肪',
+ 'unit'=>'g',
+ 'color'=>'#ED7886',
+ 'value'=>0,
+ 'proportion'=>0,
+ ],
+ [
+ 'name'=>'碳水化合物',
+ 'unit'=>'g',
+ 'color'=>'#FFB169',
+ 'value'=>0,
+ 'proportion'=>0,
+ ],
+ ],
+ 'list'=>[],
+ ],
+ ],
+ ];
+ // 查询用户今日摄入食物
+ $food_content = $cfc->table($this->kitchenscale_db_msg['eat_log'])
+ ->alias('a')
+ ->join('app_z_national_standard_food_type_3 b','a.food_id = b.id','LEFT')
+ ->where("a.is_del = 0 AND a.aud_id = " . $data['aud_id'] . " AND CAST(a.create_time AS DATE) = CAST('" . $data['time'] . "' AS DATE)")
+ ->field('a.meals_type,a.food_name,a.weight,a.kcal_val,a.carbohydrate_val,a.protein_val,a.fat_val,a.id,\'https://tc.pcxbc.com\' + b.pic_url as pic_url,a.food_id')
+ ->select();
+
+ if(count($food_content) > 0){ //计算营养物质
+ $food_content = $this->calculate_nutrients($food_content);
+ // return $this->msg($food_content);
+ foreach ($food_content as $key => $value) {
+ // dump($value['nutrients_four']);
+ $return_data['today_intake']['kcal'] = bcadd($return_data['today_intake']['kcal'],$value['kcal_val'],2);
+ $return_data['today_intake']['carbohydrate'] = bcadd($return_data['today_intake']['carbohydrate'],$value['carbohydrate_val'],2);
+ $return_data['today_intake']['protein'] = bcadd($return_data['today_intake']['protein'],$value['protein_val'],2);
+ $return_data['today_intake']['fat'] = bcadd($return_data['today_intake']['fat'],$value['fat_val'],2);
+ // 处理各餐
+ if($value['meals_type'] == '早餐'){
+ $return_data['list'][0]['val'] = bcadd($return_data['list'][0]['val'],$value['kcal_val'],2);
+ $return_data['list'][0]['nutrients_four'][0]['value'] = bcadd($return_data['list'][0]['nutrients_four'][0]['value'],$value['kcal_val'],2);
+ $return_data['list'][0]['nutrients_four'][1]['value'] = bcadd($return_data['list'][0]['nutrients_four'][1]['value'],$value['carbohydrate_val'],2);
+ $return_data['list'][0]['nutrients_four'][2]['value'] = bcadd($return_data['list'][0]['nutrients_four'][2]['value'],$value['protein_val'],2);
+ $return_data['list'][0]['nutrients_four'][3]['value'] = bcadd($return_data['list'][0]['nutrients_four'][3]['value'],$value['fat_val'],2);
+ array_push($return_data['list'][0]['list'],[
+ 'name'=>$value['food_name'],
+ 'weight'=>$value['weight'].'克',
+ 'id'=>$value['id'],
+ 'pic_url'=>$value['pic_url'],
+ 'val'=>$value['kcal_val'],
+ 'nutrients_four' => $value['nutrients_four'],
+ 'nutrients_list' => $value['nutrients_list']
+ ]);
+ }else if($value['meals_type'] == '午餐'){
+ $return_data['list'][1]['val'] = bcadd($return_data['list'][1]['val'],$value['kcal_val'],2);
+ $return_data['list'][1]['nutrients_four'][0]['value'] = bcadd($return_data['list'][1]['nutrients_four'][0]['value'],$value['kcal_val'],2);
+ $return_data['list'][1]['nutrients_four'][1]['value'] = bcadd($return_data['list'][1]['nutrients_four'][1]['value'],$value['carbohydrate_val'],2);
+ $return_data['list'][1]['nutrients_four'][2]['value'] = bcadd($return_data['list'][1]['nutrients_four'][2]['value'],$value['protein_val'],2);
+ $return_data['list'][1]['nutrients_four'][3]['value'] = bcadd($return_data['list'][1]['nutrients_four'][3]['value'],$value['fat_val'],2);
+ array_push($return_data['list'][1]['list'],[
+ 'name'=>$value['food_name'],
+ 'weight'=>$value['weight'].'克',
+ 'id'=>$value['id'],
+ 'pic_url'=>$value['pic_url'],
+ 'val'=>$value['kcal_val'],
+ 'nutrients_four' => $value['nutrients_four'],
+ 'nutrients_list' => $value['nutrients_list']
+ ]);
+ }else if($value['meals_type'] == '晚餐'){
+ $return_data['list'][2]['val'] = bcadd($return_data['list'][2]['val'],$value['kcal_val'],2);
+ $return_data['list'][2]['nutrients_four'][0]['value'] = bcadd($return_data['list'][2]['nutrients_four'][0]['value'],$value['kcal_val'],2);
+ $return_data['list'][2]['nutrients_four'][1]['value'] = bcadd($return_data['list'][2]['nutrients_four'][1]['value'],$value['carbohydrate_val'],2);
+ $return_data['list'][2]['nutrients_four'][2]['value'] = bcadd($return_data['list'][2]['nutrients_four'][2]['value'],$value['protein_val'],2);
+ $return_data['list'][2]['nutrients_four'][3]['value'] = bcadd($return_data['list'][2]['nutrients_four'][3]['value'],$value['fat_val'],2);
+ array_push($return_data['list'][2]['list'],[
+ 'name'=>$value['food_name'],
+ 'weight'=>$value['weight'].'克',
+ 'id'=>$value['id'],
+ 'pic_url'=>$value['pic_url'],
+ 'val'=>$value['kcal_val'],
+ 'nutrients_four' => $value['nutrients_four'],
+ 'nutrients_list' => $value['nutrients_list']
+ ]);
+ }else{
+ $return_data['list'][3]['val'] = bcadd($return_data['list'][3]['val'],$value['kcal_val'],2);
+ $return_data['list'][3]['nutrients_four'][0]['value'] = bcadd($return_data['list'][3]['nutrients_four'][0]['value'],$value['kcal_val'],2);
+ $return_data['list'][3]['nutrients_four'][1]['value'] = bcadd($return_data['list'][3]['nutrients_four'][1]['value'],$value['carbohydrate_val'],2);
+ $return_data['list'][3]['nutrients_four'][2]['value'] = bcadd($return_data['list'][3]['nutrients_four'][2]['value'],$value['protein_val'],2);
+ $return_data['list'][3]['nutrients_four'][3]['value'] = bcadd($return_data['list'][3]['nutrients_four'][3]['value'],$value['fat_val'],2);
+ array_push($return_data['list'][3]['list'],[
+ 'name'=>$value['food_name'],
+ 'weight'=>$value['weight'].'克',
+ 'id'=>$value['id'],
+ 'pic_url'=>$value['pic_url'],
+ 'val'=>$value['kcal_val'],
+ 'nutrients_four' => $value['nutrients_four'],
+ 'nutrients_list' => $value['nutrients_list']
+ ]);
+ }
+ }
+ // dump($return_data['list']);
+ // die;
+ $return_data['list'] = array_values($return_data['list']);
+ // 处理剩下可吃
+ $return_data['remaining_kcal'] = bcsub($return_data['suggestion']['kcal'],$return_data['today_intake']['kcal'],2)>=0?bcsub($return_data['suggestion']['kcal'],$return_data['today_intake']['kcal'],2):0;
+
+
+
+ // 处理各餐卡路里占比
+ $return_data = $this->calculate_kcal_proportion($return_data);
+ // 计算营养物质能量占比
+ $return_data = $this->calculate_energy_proportion($return_data);
+ // 排序营养元素食物排行榜
+ $return_data = $this->energy_food_rank($return_data);
+ // 微量元素处理全天
+ $return_data = $this->calculate_trace_elements($return_data);
+ // 处理单餐营养占比
+ foreach ($return_data['list'] as $key => $value) {
+ $all_yy_data_0 = bcadd($value['nutrients_four'][3]['value'],bcadd($value['nutrients_four'][1]['value'],$value['nutrients_four'][2]['value'],20),2);
+ foreach ($value['nutrients_four'] as $k => $v) {
+ if($k != 0){
+ if($all_yy_data_0 == 0){
+ $return_data['list'][$key]['nutrients_four'][$k]['proportion'] = 0;
+ }else{
+ $return_data['list'][$key]['nutrients_four'][$k]['proportion'] = bcdiv($value['nutrients_four'][$k]['value'],$all_yy_data_0,2) >= 1?'100':(bcdiv($value['nutrients_four'][$k]['value'],$all_yy_data_0,2))*100;
+ }
+ }
+ }
+ }
+ }
+
+
+
+ $nameMap = [
+ 'kcal' => ['卡路里','kcal','https://tc.pcxbc.com/kitchenscale_all/icon_kcal.png','#5180D8'],
+ 'carbohydrate' => ['碳水','g','https://tc.pcxbc.com/kitchenscale_all/icon_carbohydrate.png','#ED7886'],
+ 'protein' => ['蛋白质','g','https://tc.pcxbc.com/kitchenscale_all/icon_protein.png','#FFB169'],
+ 'fat' => ['脂肪','g','https://tc.pcxbc.com/kitchenscale_all/icon_fat.png','#3CB383'],
+ ];
+ $all_yy_data = bcadd($return_data['suggestion']['fat'],bcadd($return_data['suggestion']['carbohydrate'],$return_data['suggestion']['protein'],20),20);
+ foreach ($return_data['suggestion'] as $key => $value) {
+ $return_data['nutrients_four'][] = [
+ 'name'=>$nameMap[$key][0],
+ 'unit'=>$nameMap[$key][1],
+ 'suggestion'=>$value,
+ 'today_intake'=>$return_data['today_intake'][$key],
+ 'icon'=>$nameMap[$key][2],
+ 'color'=>$nameMap[$key][3],
+ 'proportion'=>bcdiv($return_data['today_intake'][$key],$value,2) >= 1?'100':(bcdiv($return_data['today_intake'][$key],$value,2))*100,
+ 'proportion_fp'=>$key == 'kcal'?0:(bcdiv($return_data['suggestion'][$key],$all_yy_data,2))*100,
+ ];
+ }
+ unset($return_data['suggestion']);
+ unset($return_data['today_intake']);
+ // $return_data = $this->calculate_kcal_proportion($return_data);
+
+
+ return $this->msg($return_data);
+
+ }
+ public function get_log_list_action($data){
+ $cfc = Db::connect('cfc_db');
+ $user_data = $cfc->table($this->kitchenscale_db_msg['user'])
+ ->where(["id"=>$data['aud_id']])
+ ->field('weight,height,gender,age,is_use_set_kcal,set_kcal')
+ ->find();
+ if(!$user_data){
+ return $this->msg(10003);
+ }
+ // 计算年龄
+ $user_data['age_num'] = $user_data['age'];
+ // 计算推荐营养
+ $nutrition_data = $this->count_user_nutrition_all($user_data);
+ if($user_data['is_use_set_kcal'] == 1){
+ $nutrition_data['kcal'] = $user_data['set_kcal'];
+ }
+
+
+ $content_num = $cfc->query("SELECT COUNT(DISTINCT CONVERT(varchar, create_time, 23)) as total
+ FROM ".$this->kitchenscale_db_msg['eat_log']."
+ WHERE aud_id = ".$data['aud_id']." and is_del = 0");
+ $page_total = ceil($content_num[0]['total']/$this->page_num);
+
+ $food_content = $cfc->table($this->kitchenscale_db_msg['eat_log'])
+ ->where(['aud_id'=>$data['aud_id'],'is_del'=>0])
+ ->group('CONVERT(varchar, create_time, 23)')
+ ->page($data['page'],$this->page_num)
+ ->order('create_time DESC')
+ ->field("CONVERT(varchar, create_time, 23) as create_time, SUM(kcal_val) as kcal_val")
+ ->select();
+
+ $return_data = [];
+ foreach ($food_content as $key => $value) {
+ if(bcdiv($value['kcal_val'],$nutrition_data['kcal'],2) < 0.9){
+ $bz['text'] = '不达标';
+ $bz['color'] = '#F0AD4E';
+ }else if(bcdiv($value['kcal_val'],$nutrition_data['kcal'],2) >= 0.9 && bcdiv($value['kcal_val'],$nutrition_data['kcal'],2) < 1.1){
+ $bz['text'] = '达标';
+ $bz['color'] = '#4CD964';
+ }else{
+ $bz['text'] = '超标';
+ $bz['color'] = '#FF0000';
+ }
+ array_push($return_data,['time'=>$value['create_time'],'title'=>'摄入卡路里','val'=>$value['kcal_val'],'unit'=>'kcal','describe'=>$bz['text'],'color'=>$bz['color']]);
+ }
+ return $this->msg([
+ 'page_now'=>$data['page'],
+ 'page_total'=>$page_total,
+ 'content_list'=>$return_data
+ ]);
+ }
+ public function set_up_content_action($data){
+ $cfc = Db::connect('cfc_db');
+ $user_data = $cfc->table($this->kitchenscale_db_msg['user'])
+ ->where(["id"=>$data['aud_id']])
+ ->field('weight,height,gender,age,is_use_set_kcal,set_kcal')
+ ->find();
+ if(!$user_data){
+ return $this->msg(10003);
+ }
+ // 计算年龄
+ $user_data['age_num'] = $user_data['age'];
+ // 计算推荐营养
+ $nutrition_data = $this->count_user_nutrition_all($user_data);
+ if($user_data['is_use_set_kcal'] == 1){
+ $nutrition_data['kcal'] = $user_data['set_kcal'];
+ }
+ $nutrition_describe = [
+ [
+ '对于一个孩子(2-18岁)(没有特殊健康问题),身体处于快速生长发育阶段,需要充足的营养支持,尤其是蛋白质和健康脂肪。通常建议的三大营养素比例为:',
+ '1、碳水化合物:45%-65% 的总热量',
+ '提供能量,支持孩子的日常活动和生长发育。',
+ '优先选择复合碳水化合物(如全谷物、蔬菜、水果),避免精制糖和高糖零食。',
+ '2、蛋白质:10%-30% 的总热量',
+ '支持肌肉、骨骼和器官的发育。',
+ '建议摄入优质蛋白质来源,如瘦肉、鱼类、鸡蛋、豆类和乳制品。',
+ '蛋白质需求较高,尤其是青春期孩子。',
+ '3、脂肪:25%-35% 的总热量',
+ '提供能量,并支持大脑发育(尤其是Omega-3脂肪酸)。',
+ '优先选择健康脂肪,如鱼类、坚果、种子、橄榄油和牛油果。',
+ '避免反式脂肪和过多的饱和脂肪。',
+ '注意事项',
+ '如果你有特定的健康目标(如增高,减重),可以进一步调整比例,并咨询营养师或医生以获得个性化建议。',
+ ],
+ [
+ '对于一个正常成年人(没有特殊健康问题或特定健身目标),通常建议的三大营养素比例为:',
+ '1、碳水化合物:45%-65% 的总热量',
+ '主要功能是提供能量',
+ '建议选择复合碳水化合物(如全谷物、蔬菜、豆类),而不是精制糖。',
+ '对于普通人,碳水化合物占总热量的 50%-55% 是一个常见的推荐值。',
+ '2、蛋白质:10%-35% 的总热量',
+ '用于维持肌肉、修复组织和支持免疫功能。',
+ '普通人每日蛋白质摄入量建议为 0.8-1.2克/公斤体重。',
+ '对于活动量较大或健身人群,蛋白质比例可以提高到 20%-30%。',
+ '3、脂肪:20%-35% 的总热量',
+ '提供能量、支持细胞功能并帮助吸收脂溶性维生素。',
+ '建议以 不饱和脂肪(如橄榄油、坚果、鱼类)为主,减少饱和脂肪和反式脂肪的摄入。',
+ '脂肪占总热量的 20%-30% 是常见的推荐值。',
+ '以上是根据世界卫生组织(WHO)和其他健康机构的建议制定的。具体比例可以根据个人的活动水平、健康状况和目标进行微调。',
+ '注意事项',
+ '活动水平:活动量大的人可能需要更多的碳水化合物来提供能量,而健身人群可能需要更多的蛋白质。',
+ '健康状况:例如,糖尿病患者可能需要控制碳水化合物比例,而心血管疾病患者可能需要减少脂肪摄入。',
+ '个体差异:每个人的代谢和需求不同,建议根据个人情况调整。',
+ '如果你有特定的健康目标(如减脂、增肌或控制慢性病),可以进一步调整比例,并咨询营养师或医生以获得个性化建议。',
+ ],
+ [
+ '对于一个老人(65岁以上)(没有特殊健康问题),身体的代谢率下降,肌肉量减少,可能面临营养不良或慢性病风险,因此需要调整营养比例。通常建议的三大营养素比例为:',
+ '1、碳水化合物:45%-65% 的总热量',
+ '提供能量,但应选择低血糖指数(GI)的食物,如全谷物、蔬菜和豆类,以控制血糖水平。',
+ '避免精制糖和高糖食物,尤其是糖尿病患者。',
+ '帮助维持肌肉质量,预防肌肉流失(少肌症)。',
+ '建议摄入优质蛋白质,如鱼类、瘦肉、鸡蛋、豆类和乳制品。',
+ '蛋白质需求较高,尤其是活动量较大的老人。',
+ '3、脂肪:20%-35% 的总热量',
+ '提供能量,并支持细胞功能和脂溶性维生素的吸收。',
+ '优先选择不饱和脂肪,如橄榄油、坚果、种子和鱼类。',
+ '减少饱和脂肪和反式脂肪的摄入,以降低心血管疾病风险。',
+ '注意事项',
+ '如果你有特定的健康目标(控制慢性病),可以进一步调整比例,并咨询营养师或医生以获得个性化建议。',
+ ]
+ ];
+ $return_data = [
+ 'kcal'=>[
+ 'title'=>"建议摄入卡路里",
+ 'suggestion_kcal_val'=>$nutrition_data['kcal'],
+ 'suggestion_kcal_unit'=>"千卡",
+ 'suggestion_kcal_range_val'=>"建议您在:".bcmul($nutrition_data['bmr'],1.2,2)."~".bcmul($nutrition_data['bmr'],1.9,2)."千卡范围内调整,修改时请以医生建议为准!",
+ 'describe'=>[
+ '基础代谢率(BMR):是指人体在清醒而又极端安静的状态下,不受肌肉活动、环境温度、食物及精神紧张等影响时的能量代谢率。',
+ '每日总能量消耗(TDEE):',
+ 'TDEE是BMR乘以活动系数,活动系数根据日常活动水平确定',
+ '久坐(很少或没有运动):BMR × 1.2',
+ '轻度活动(每周1-3天轻度运动):BMR × 1.375',
+ '中度活动(每周3-5天中度运动):BMR × 1.55',
+ '高度活动(每周6-7天高强度运动):BMR × 1.725',
+ '极高活动(体力劳动或每天高强度训练):BMR × 1.9',
+ '您的BMR为'.$nutrition_data['bmr'].',建议根据您的日常生活水平,调整合适的TDEE',
+ ],
+ ],
+ 'nutrition'=>[
+ 'title'=>"建议三大营养比例",
+ 'list'=>[
+ [
+ 'name'=>'碳水化合物',
+ 'icon'=>'icon-tanshuihuahewu',
+ 'proportion'=>'50%',
+ 'val'=>$nutrition_data['carbohydrate'],
+ 'unit'=>'克'
+ ],
+ [
+ 'name'=>'蛋白质',
+ 'icon'=>'icon-Sm-danbaizhi',
+ 'proportion'=>'20%',
+ 'val'=>$nutrition_data['protein'],
+ 'unit'=>'克'
+ ],
+ [
+ 'name'=>'脂肪',
+ 'icon'=>'icon-w_fat_normal',
+ 'proportion'=>'30%',
+ 'val'=>$nutrition_data['fat'],
+ 'unit'=>'克'
+ ]
+ ],
+ 'describe'=>[]
+ ]
+ ];
+ if($user_data['age_num'] >= 2 && $user_data['age_num'] <= 18){
+ $return_data['nutrition']['describe'] = $nutrition_describe[0];
+ }else if($user_data['age_num'] > 18 && $user_data['age_num'] < 65){
+ $return_data['nutrition']['describe'] = $nutrition_describe[1];
+ }else if($user_data['age_num'] >= 65){
+ $return_data['nutrition']['describe'] = $nutrition_describe[2];
+ }else{
+
+ }
+ return $this->msg($return_data);
+
+ }
+ public function set_user_kcal_action($data){
+ $cfc = Db::connect('cfc_db');
+ $user_data = $cfc->table($this->kitchenscale_db_msg['user'])
+ ->where(["id"=>$data['aud_id']])
+ ->field('weight,height,gender,age,is_use_set_kcal,set_kcal')
+ ->find();
+ if(!$user_data){
+ return $this->msg(10003);
+ }
+ $result = $cfc->table($this->kitchenscale_db_msg['user'])
+ ->where(["id"=>$data['aud_id']])
+ ->update([
+ 'is_use_set_kcal'=>1,
+ 'set_kcal'=>$data['set_kcal']
+ ]);
+
+ if($result){
+ return $this->msg([]);
+ }else{
+ return $this->msg(10002);
+ }
+ }
+ public function del_user_eat_log_action($data){
+ $cfc = Db::connect('cfc_db');
+ $user_data = $cfc->table($this->kitchenscale_db_msg['eat_log'])
+ ->where(["id"=>$data['eat_log_id']])
+ ->update(['is_del'=>1]);
+ if($user_data){
+ return $this->msg([]);
+ }else{
+ return $this->msg(10002);
+ }
+ }
+ public function del_user_eat_list_log_action($data){
+ $cfc = Db::connect('cfc_db');
+ $user_data = $cfc->table($this->kitchenscale_db_msg['user'])->where(['token'=>$data['token']])->field('id,token')->find();
+ // dump($user_data);
+ if(!$user_data){
+ return $this->msg(10003);
+ }
+ $result = $cfc->table($this->kitchenscale_db_msg['eat_log'])
+ ->where("aud_id = ".$user_data['id']." AND LEFT(create_time,10) = '" .$data['time']. "'")
+ ->update(['is_del'=>1]);
+ if($result){
+ return $this->msg([]);
+ }else{
+ return $this->msg(10002);
+ }
+ }
+
+
+
+ #######################################################################工具#######################################################################
+ #######################################################################工具#######################################################################
+ #######################################################################工具#######################################################################
+
+ // public function count_user_nutrition_all($data){
+ // // 计算基础代谢率(BMR)
+ // if($data['gender'] == 1){
+ // // 男性:BMR = 10 × 体重(kg) + 6.25 × 身高(cm) - 5 × 年龄(岁) + 5
+ // $bmr = bcmul(10,$data['weight'],20);
+ // $bmr = bcadd($bmr,bcmul(6.25,$data['height'],20),20);
+ // $bmr = bcsub($bmr,bcmul(5,$data['age_num'],20),20);
+ // $bmr = bcadd($bmr,5,2);
+ // }else if($data['gender'] == 2){
+ // // 女性:BMR = 10 × 体重(kg) + 6.25 × 身高(cm) - 5 × 年龄(岁) - 161
+ // $bmr = bcmul(10,$data['weight'],20);
+ // $bmr = bcadd($bmr,bcmul(6.25,$data['height'],20),20);
+ // $bmr = bcsub($bmr,bcmul(5,$data['age_num'],20),20);
+ // $bmr = bcsub($bmr,161,2);
+ // }else{
+ // return $this->msg(10003,'性别未知');
+ // }
+
+ // // 每日总能量消耗(TDEE)
+ // // 久坐(很少或没有运动):BMR × 1.2
+ // // 轻度活动(每周1-3天轻度运动):BMR × 1.375
+ // // 中度活动(每周3-5天中度运动):BMR × 1.55
+ // // 高度活动(每周6-7天高强度运动):BMR × 1.725
+ // // 极高活动(体力劳动或每天高强度训练):BMR × 1.9
+ // $tdee = bcmul($bmr,1.55,2);
+
+ // // 碳水化合物:通常占总热量的45-65%
+ // // 蛋白质:通常占总热量的10-35%
+ // // 脂肪:通常占总热量的20-35%
+ // // 孩子&成年人:碳水化合物50%,蛋白质20%,脂肪30%。
+ // // 老人:碳水化合物50%,蛋白质25%,脂肪25%。
+ // // 建议每日摄入量计算:
+ // // 1.碳水化合物(克): (TDEE × 碳水化合物比例) / 4
+ // // 2.蛋白质(克):(TDEE × 蛋白质比例) / 4
+ // // 3.脂肪(克): (TDEE × 脂肪比例) / 9
+ // $carbohydrate = bcdiv(bcmul($tdee,0.5,20),4,2);
+ // if($data['age_num'] < 65){
+ // $protein = bcdiv(bcmul($tdee,0.2,20),4,2);
+ // $fat = bcdiv(bcmul($tdee,0.3,20),9,2);
+ // }else{
+ // $protein = bcdiv(bcmul($tdee,0.25,20),4,2);
+ // $fat =bcdiv(bcmul($tdee,0.25,20),9,2);
+ // }
+ // return ['kcal'=>$tdee,'carbohydrate'=>$carbohydrate,'protein'=>$protein,'fat'=>$fat,'bmr'=>$bmr];
+ // }
+ // public function calculateDateRange($n) {
+ // // 获取当前日期和时间
+ // $today = new \DateTime();
+ // // dump($today);
+ // // 计算结束时间:往前推 (10 * (n - 1)) 天,时间设为 23:59:59
+ // $endInterval = new \DateInterval('P' . (10 * ($n - 1)) . 'D');
+ // $endTime = clone $today;
+ // $endTime->sub($endInterval)->setTime(23, 59, 59);
+
+ // // 计算开始时间:往前推 (10 * n) 天,时间设为 00:00:00
+ // $startInterval = new \DateInterval('P' . (10 * $n) . 'D');
+ // $startTime = clone $today;
+ // $startTime->sub($startInterval)->setTime(0, 0, 0);
+
+ // return [
+ // 's_time' => $startTime->format('Y-m-d H:i:s'),
+ // 'e_time' => $endTime->format('Y-m-d H:i:s'),
+ // ];
+ // }
+
+ // 计算每日每餐kcal占比
+ public function calculate_kcal_proportion($data){
+
+ $all_kcal = $data['today_intake']['kcal'];
+ $arr_kcal = [];
+ foreach ($data['list'] as $key => $value) {
+ $arr_kcal[] = $value['val'];
+ }
+ // 计算占比
+ $percentages = [];
+ if (bccomp($all_kcal, "0", 20) > 0) {
+ $sum = "0";
+ // 计算前n-1个元素的占比
+ for ($i = 0; $i < count($arr_kcal) - 1; $i++) {
+ $percentage = bcmul(bcdiv($arr_kcal[$i], $all_kcal, 20), "100", 20);
+ $percentage = bcdiv($percentage, "1", 2); // 保留两位小数
+ $percentages[] = $percentage;
+ $sum = bcadd($sum, $percentage, 2);
+ }
+
+ // 最后一个元素用100%减去前面总和,确保100%
+ if($arr_kcal[count($arr_kcal)-1] != 0){
+ $lastPercentage = bcsub("100.00", $sum, 2);
+ }else{
+ $lastPercentage = '0.00';
+ }
+ $percentages[] = $lastPercentage;
+ } else {
+ // 如果总热量为0,所有占比都为0
+ $percentages = array_fill(0, count($arr_kcal), "0.00");
+ }
+
+ // 将占比结果添加回原数据
+ foreach ($data['list'] as $key => &$value) {
+ $value['kcal_proportion'] = $percentages[$key];
+ }
+ return $data;
+ }
+ // 计算营养物质能量占比
+ public function calculate_energy_proportion($data){
+ // 获取今日摄入数据
+ $today_intake = $data['today_intake'];
+ // dump($today_intake);
+ // 总热量摄入
+ $total_kcal = $today_intake['kcal'];
+
+ // 各营养素摄入量(克)
+ $carb_intake = $today_intake['carbohydrate']; // 碳水
+ $protein_intake = $today_intake['protein']; // 蛋白质
+ $fat_intake = $today_intake['fat']; // 脂肪
+
+ // 供能系数
+ $carb_energy_coef = "4"; // 碳水:4 kcal/g
+ $protein_energy_coef = "4"; // 蛋白质:4 kcal/g
+ $fat_energy_coef = "9"; // 脂肪:9 kcal/g
+
+ // 计算各营养素的能量贡献(kcal)
+ $carb_energy = bcmul($carb_intake, $carb_energy_coef, 20);
+ $protein_energy = bcmul($protein_intake, $protein_energy_coef, 20);
+ $fat_energy = bcmul($fat_intake, $fat_energy_coef, 20);
+
+ // 计算各营养素的能量占比(%)
+ if (bccomp($total_kcal, "0", 20) > 0) {
+ // 碳水能量占比
+ $carb_proportion = bcmul(bcdiv($carb_energy, $total_kcal, 20), "100", 20);
+ $carb_proportion = bcdiv($carb_proportion, "1", 2); // 保留两位小数
+
+ // 蛋白质能量占比
+ $protein_proportion = bcmul(bcdiv($protein_energy, $total_kcal, 20), "100", 20);
+ $protein_proportion = bcdiv($protein_proportion, "1", 2);
+
+ // 脂肪能量占比
+ $fat_proportion = bcmul(bcdiv($fat_energy, $total_kcal, 20), "100", 20);
+ $fat_proportion = bcdiv($fat_proportion, "1", 2);
+ } else {
+ $carb_proportion = $protein_proportion = $fat_proportion = "0.00";
+ }
+
+ // 填充details数据
+ $data['details']['carbohydrate']['val'] = $carb_intake;
+ $data['details']['carbohydrate']['proportion'] = $carb_proportion;
+
+ $data['details']['protein']['val'] = $protein_intake;
+ $data['details']['protein']['proportion'] = $protein_proportion;
+
+ $data['details']['fat']['val'] = $fat_intake;
+ $data['details']['fat']['proportion'] = $fat_proportion;
+
+ return $data;
+ }
+ // 排序营养元素食物排行榜
+ public function energy_food_rank($data){
+ // 获取所有食物数据
+ $allFoods = [];
+
+ // 遍历每餐数据,收集所有食物信息
+ foreach ($data['list'] as $meal) {
+ if (!empty($meal['list'])) {
+ foreach ($meal['list'] as $food) {
+ // 获取食物的营养素数据
+ $nutrients_four = $food['nutrients_four'];
+ $nutrientValues = [];
+
+ // 将营养素数据转换为键值对,便于查询
+ foreach ($nutrients_four as $nutrient) {
+ $nutrientValues[$nutrient['name']] = $nutrient['value'];
+ }
+
+ $allFoods[] = [
+ 'name' => $food['name'],
+ 'pic_url' => $food['pic_url'],
+ 'weight' => $food['weight'],
+ 'carbohydrate' => isset($nutrientValues['碳水化合物']) ? $nutrientValues['碳水化合物'] : '0',
+ 'protein' => isset($nutrientValues['蛋白质']) ? $nutrientValues['蛋白质'] : '0',
+ 'fat' => isset($nutrientValues['脂肪']) ? $nutrientValues['脂肪'] : '0'
+ ];
+ }
+ }
+ }
+
+ // 如果没有食物数据,直接返回
+ if (empty($allFoods)) {
+ return $data;
+ }
+
+ // 对每种营养素进行排序并取前三
+ $nutrientTypes = [
+ 'carbohydrate' => '碳水化合物',
+ 'protein' => '蛋白质',
+ 'fat' => '脂肪'
+ ];
+
+ foreach ($nutrientTypes as $nutrientKey => $nutrientName) {
+ // 使用BC函数进行精确比较排序
+ usort($allFoods, function($a, $b) use ($nutrientKey) {
+ $valueA = $a[$nutrientKey];
+ $valueB = $b[$nutrientKey];
+
+ // 使用bccomp进行比较
+ $comparison = bccomp($valueA, $valueB, 20);
+
+ if ($comparison == 0) {
+ return 0;
+ }
+ // 返回-1表示a应该在b前面(降序排序)
+ return ($comparison > 0) ? -1 : 1;
+ });
+
+ // 取前三名
+ $topThree = array_slice($allFoods, 0, 3);
+
+ // 填充rank_list
+ $rankList = [];
+ foreach ($topThree as $index => $food) {
+ $rankList[] = [
+ 'icon' => 'https://tc.pcxbc.com/kitchenscale_all/rank'.($index+1).'.png',
+ 'name' => $food['name'],
+ 'pic_url' => $food['pic_url'],
+ 'weight' => bcdiv($food[$nutrientKey], '1', 2) // 使用BC函数保留两位小数
+ ];
+ }
+
+ // 如果不足三个,用空数据补全
+ $currentCount = count($rankList);
+ for ($i = $currentCount; $i < 3; $i++) {
+ $rankList[] = [
+ 'icon' => 'https://tc.pcxbc.com/kitchenscale_all/rank' . ($i + 1) . '.png',
+ 'name' => '',
+ 'pic_url' => '',
+ 'weight' => ''
+ ];
+ }
+
+ // 更新到details中对应的营养素
+ $data['details'][$nutrientKey]['rank_list'] = $rankList;
+ }
+
+ return $data;
+ }
+
+ // 微量元素处理全天
+ public function calculate_trace_elements($data){
+ $traceElements = [];
+
+ // 遍历所有餐次数据
+ foreach ($data['list'] as $meal) {
+ if (!empty($meal['list'])) {
+ foreach ($meal['list'] as $food) {
+ if (!empty($food['nutrients_list'])) {
+ foreach ($food['nutrients_list'] as $nutrient) {
+ // 只处理维生素(type=2)和矿物质(type=3)
+ if (in_array($nutrient['type'], [2, 3])) {
+ $name = $nutrient['name'];
+ $value = $nutrient['value'];
+
+ // 初始化微量元素数据
+ if (!isset($traceElements[$name])) {
+ $traceElements[$name] = [
+ 'name' => $nutrient['name'],
+ 'name_ch' => isset($nutrient['name_ch']) ? $nutrient['name_ch'] : $nutrient['name'],
+ 'unit' => $nutrient['unit'],
+ 'value' => '0'
+ ];
+ }
+
+ // 使用BC数学函数精确累加
+ $traceElements[$name]['value'] = bcadd(
+ $traceElements[$name]['value'],
+ $value,
+ 20
+ );
+ }
+ }
+ }
+ }
+ }
+ }
+
+ // 处理结果,保留两位小数
+ $formattedElements = [];
+ foreach ($traceElements as $element) {
+ // 使用BC函数格式化值为两位小数
+ $formattedValue = bcdiv($element['value'], '1', 2);
+
+ // 如果值为0,跳过(可选,根据需求决定是否显示0值)
+ if (bccomp($formattedValue, '0', 2) > 0) {
+ $formattedElements[] = [
+ 'name' => $element['name'],
+ 'name_ch' => $element['name_ch'],
+ 'unit' => $element['unit'],
+ 'value' => $formattedValue
+ ];
+ }
+ }
+
+
+ // 按中文名称排序
+ usort($formattedElements, function($a, $b) {
+ return strcmp($a['name_ch'], $b['name_ch']);
+ });
+
+ $data['trace_elements_all_day'] = $formattedElements;
+
+ return $data;
+
+
+
+ }
+
+
+
+
+
+}
\ No newline at end of file
diff --git a/application/KitchenScale2/controller/app/Guessyoulike.php b/application/KitchenScale2/controller/app/Guessyoulike.php
new file mode 100644
index 0000000..34d8fb8
--- /dev/null
+++ b/application/KitchenScale2/controller/app/Guessyoulike.php
@@ -0,0 +1,418 @@
+ 'app_user_cookbook', //食谱表
+ 'cookbook_label' => 'app_user_cookbook_label', //食谱标签表
+ 'cookbook_food_relation' => 'app_user_cookbook_food_relation', //食谱跟食材关系表
+ 'foodlist2' => 'app_z_national_standard_food_type_2', //食材标签表2
+ 'foodlist3' => 'app_z_national_standard_food_type_3', //食材表
+ 'kcal_log' => 'app_user_kcal_log', //用户饮食记录表记录用户吃了什么食材
+ 'search_history' => 'app_user_search_history', //用户搜索记录表,记录用户搜索过什么内容
+ 'tag_preference' => 'app_user_tag_preference', //用户标签偏好表
+ 'recommend_cache' => 'app_recommend_cache' //智能推荐缓存表
+ ];
+
+ protected $config = [
+ 'tag_limit' => 2,
+ 'item_limit' => 12,
+ 'cache_time' => 3600
+ ];
+
+ /**
+ * 猜你喜欢主接口
+ */
+ public function getGuessYouLike($user_id = 1, $type = 'food', $limit = null) {
+ try {
+ $cfc = Db::connect('cfc_db');
+ // dump(1);
+ // 设置限制数量
+ $tag_limit = $limit ? intval($limit) : $this->config['tag_limit'];
+ $item_limit = $this->config['item_limit'];
+
+ // 检查缓存
+ // $cache_key = $user_id . ':' . $type;
+ // $cache_result = $this->getCache($cfc, $cache_key);
+ // // die;
+ // if ($cache_result !== null) {
+ // return $cache_result;
+ // }
+
+ // 判断用户是否有历史数据
+ $has_history = $this->checkUserHistory($cfc, $user_id);
+ if (!$has_history) {
+ // 新用户,返回最火信息(仅一个标签)
+ $result = $this->getPopularRecommendations($cfc, $type, 1, $item_limit);
+ } else {
+ // 老用户,根据类型返回个性化推荐
+ if ($type === 'cookbook') {
+ $result = $this->getCookbookRecommendations($cfc, $user_id, $tag_limit, $item_limit);
+
+ } else {
+ $result = $this->getFoodRecommendations($cfc, $user_id, $tag_limit, $item_limit);
+ }
+ }
+
+ // 确保返回格式正确
+ if (!is_array($result)) {
+ $result = [];
+ }
+
+ // 更新缓存
+ // $this->updateCache($cfc, $cache_key, $user_id, $type, $result);
+
+ return $result;
+
+ } catch (\Exception $e) {
+ // 记录错误日志
+ \think\Log::error('猜你喜欢功能错误: ' . $e->getMessage());
+ return [];
+ }
+ }
+
+ /**
+ * 检查用户是否有历史数据
+ */
+ private function checkUserHistory($db, $user_id) {
+ try {
+ // 检查饮食记录
+ $kcal_result = $db->query("
+ SELECT COUNT(*) as count
+ FROM {$this->kitchenscale_db_msg['kcal_log']}
+ WHERE aud_id = ? AND is_del = 0
+ ", [$user_id]);
+ $kcal_count = $kcal_result[0]['count'] ?? 0;
+
+ // 检查搜索记录
+ $search_result = $db->query("
+ SELECT COUNT(*) as count
+ FROM {$this->kitchenscale_db_msg['search_history']}
+ WHERE user_id = ? AND is_del = 0
+ ", [$user_id]);
+ $search_count = $search_result[0]['count'] ?? 0;
+
+ return ($kcal_count > 0 || $search_count > 0);
+ } catch (\Exception $e) {
+ return false;
+ }
+ }
+
+ /**
+ * 获取缓存数据
+ */
+ private function getCache($db, $cache_key) {
+ try {
+ $cache_result = $db->query("
+ SELECT id, cache_key, user_id, keyword, recommend_data, hit_count, last_hit, is_del, create_time
+ FROM {$this->kitchenscale_db_msg['recommend_cache']}
+ WHERE cache_key = ? AND is_del = 0
+ ", [$cache_key]);
+
+ if (!empty($cache_result)) {
+ $cache = $cache_result[0];
+ $last_hit_timestamp = strtotime($cache['last_hit']);
+
+ if (time() - $last_hit_timestamp < $this->config['cache_time']) {
+ // 更新命中次数和时间
+ $db->execute("
+ UPDATE {$this->kitchenscale_db_msg['recommend_cache']}
+ SET hit_count = hit_count + 1, last_hit = GETDATE()
+ WHERE id = ?
+ ", [$cache['id']]);
+
+ $data = json_decode($cache['recommend_data'], true);
+ return is_array($data) ? $data : null;
+ }
+ }
+ } catch (\Exception $e) {
+ // 忽略缓存错误,继续执行
+ }
+
+ return null;
+ }
+
+ /**
+ * 更新缓存
+ */
+ private function updateCache($db, $cache_key, $user_id, $keyword, $data) {
+ try {
+ $current_time = date('Y-m-d H:i:s');
+ $recommend_data = json_encode($data, JSON_UNESCAPED_UNICODE);
+
+ // 检查是否存在缓存
+ $existing_result = $db->query("
+ SELECT id FROM {$this->kitchenscale_db_msg['recommend_cache']}
+ WHERE cache_key = ? AND is_del = 0
+ ", [$cache_key]);
+
+ if (!empty($existing_result)) {
+ // 更新现有缓存
+ $db->execute("
+ UPDATE {$this->kitchenscale_db_msg['recommend_cache']}
+ SET user_id = ?, keyword = ?, recommend_data = ?, hit_count = 1,
+ last_hit = ?, create_time = ?
+ WHERE cache_key = ? AND is_del = 0
+ ", [$user_id, $keyword, $recommend_data, $current_time, $current_time, $cache_key]);
+ } else {
+ // 插入新缓存
+ $db->execute("
+ INSERT INTO {$this->kitchenscale_db_msg['recommend_cache']}
+ (cache_key, user_id, keyword, recommend_data, hit_count, last_hit, create_time, is_del)
+ VALUES (?, ?, ?, ?, 1, ?, ?, 0)
+ ", [$cache_key, $user_id, $keyword, $recommend_data, $current_time, $current_time]);
+ }
+ } catch (\Exception $e) {
+ // 忽略缓存更新错误
+ }
+ }
+
+ /**
+ * 获取热门推荐(新用户)
+ */
+ private function getPopularRecommendations($db, $type, $tag_limit, $item_limit) {
+ // dump($type);
+ if ($type === 'cookbook') {
+ return $this->getPopularCookbooks($db, $tag_limit, $item_limit);
+ } else {
+ // dump(111);
+ return $this->getPopularFoods($db, $tag_limit, $item_limit);
+ }
+ }
+
+ /**
+ * 获取热门食谱(新用户)
+ */
+ private function getPopularCookbooks($db, $tag_limit, $item_limit) {
+ try {
+ // 简化查询,避免复杂关联导致的错误
+ $popular_cookbooks = $db->query("
+ SELECT TOP {$item_limit}
+ id,
+ title as name
+ FROM {$this->kitchenscale_db_msg['cookbook']}
+ WHERE is_del = 0
+ ORDER BY likes_num DESC, read_it DESC, create_time DESC
+ ");
+ // dump('sp');
+ // dump($popular_cookbooks);
+ $result = [];
+ $label_data = [];
+
+ foreach ($popular_cookbooks as $cookbook) {
+ $label_data[] = [
+ 'name' => $cookbook['name'] ?? '未知食谱',
+ 'id' => $cookbook['id'] ?? 0,
+ 'type' => 'cookbook'
+ ];
+ }
+
+ if (!empty($label_data)) {
+ $result['最火食谱搜索'] = $label_data;
+ }
+
+ return $result;
+ } catch (\Exception $e) {
+ return [];
+ }
+ }
+
+ /**
+ * 获取热门食材(新用户)
+ */
+ private function getPopularFoods($db, $tag_limit, $item_limit) {
+ try {
+ // dump(2222);
+ // // 简化查询,避免复杂关联导致的错误
+ $popular_foods = $db->query("
+ SELECT TOP {$item_limit}
+ id,
+ keyword as name,
+ COUNT(*) as num
+ FROM {$this->kitchenscale_db_msg['search_history']}
+ WHERE is_del = 0 AND type = 'food'
+ GROUP BY id, keyword
+ ORDER BY num DESC
+ ");
+ // dump('sc');
+ // dump($popular_foods);
+
+ $popular_foods_2 = [];
+ if(count($popular_foods) < $item_limit){
+ $num = $item_limit - count($popular_foods);
+ $popular_foods_2 = $db->query("
+ SELECT TOP {$num}
+ id,
+ food_name as name
+ FROM {$this->kitchenscale_db_msg['foodlist3']}
+ WHERE is_del = 0
+ ORDER BY is_popular DESC, food_name ASC
+ ");
+ }
+
+ foreach ($popular_foods_2 as $key => $value) {
+ $popular_foods[] = $value;
+ }
+
+
+ $result = [];
+ $label_data = [];
+
+ foreach ($popular_foods as $food) {
+ $label_data[] = [
+ 'name' => $food['name'] ?? '未知食材',
+ 'id' => $food['id'] ?? 0,
+ 'type' => 'food'
+ ];
+ }
+
+ if (!empty($label_data)) {
+ $result['最火食材搜索'] = $label_data;
+ }
+
+ return $result;
+ } catch (\Exception $e) {
+ return [];
+ }
+ }
+
+ /**
+ * 获取个性化食谱推荐(老用户)
+ */
+ private function getCookbookRecommendations($db, $user_id, $tag_limit, $item_limit) {
+ try {
+ // 获取用户最常吃的食材
+ $user_top_foods = $db->query("
+ SELECT TOP 10 food_id, COUNT(*) as eat_count
+ FROM {$this->kitchenscale_db_msg['kcal_log']}
+ WHERE aud_id = ? AND is_del = 0
+ GROUP BY food_id
+ ORDER BY eat_count DESC
+ ", [$user_id]);
+
+ if (empty($user_top_foods)) {
+ return $this->getPopularCookbooks($db, $tag_limit, $item_limit);
+ }
+
+ $food_ids = array_column($user_top_foods, 'food_id');
+ if (empty($food_ids)) {
+ return $this->getPopularCookbooks($db, $tag_limit, $item_limit);
+ }
+ $food_ids_str = implode(',', $food_ids);
+
+ // 获取包含这些食材的食谱标签
+ $preferred_labels = $db->query("
+ SELECT TOP {$tag_limit} lbl.id, lbl.name, COUNT(DISTINCT cb.id) as match_count
+ FROM {$this->kitchenscale_db_msg['cookbook_label']} lbl
+ INNER JOIN {$this->kitchenscale_db_msg['cookbook']} cb ON lbl.id = cb.cook_label AND cb.is_del = 0
+ INNER JOIN {$this->kitchenscale_db_msg['cookbook_food_relation']} cfr ON cb.id = cfr.cookbook_id
+ WHERE lbl.is_del = 0 AND cfr.food_id IN ({$food_ids_str})
+ GROUP BY lbl.id, lbl.name
+ ORDER BY match_count DESC
+ ");
+
+ $result = [];
+ foreach ($preferred_labels as $label) {
+ // 使用子查询避免GROUP BY复杂性问题
+ $cookbooks = $db->query("
+ SELECT TOP {$item_limit} cb.id, cb.title as name
+ FROM {$this->kitchenscale_db_msg['cookbook']} cb
+ WHERE cb.id IN (
+ SELECT DISTINCT cfr.cookbook_id
+ FROM {$this->kitchenscale_db_msg['cookbook_food_relation']} cfr
+ WHERE cfr.food_id IN ({$food_ids_str})
+ )
+ AND cb.cook_label = ?
+ AND cb.is_del = 0
+ ORDER BY cb.likes_num DESC, cb.read_it DESC
+ ", [$label['id']]);
+
+ $label_data = [];
+ foreach ($cookbooks as $cookbook) {
+ $label_data[] = [
+ 'name' => $cookbook['name'] ?? '未知食谱',
+ 'id' => $cookbook['id'] ?? 0,
+ 'type' => 'cookbook'
+ ];
+ }
+
+ if (!empty($label_data)) {
+ $result[$label['name'] ?? '未知标签'] = $label_data;
+ }
+ }
+
+ return $result;
+ } catch (\Exception $e) {
+ return $this->getPopularCookbooks($db, $tag_limit, $item_limit);
+ }
+ }
+
+ /**
+ * 获取个性化食材推荐(老用户)
+ */
+ private function getFoodRecommendations($db, $user_id, $tag_limit, $item_limit) {
+ try {
+ // 获取用户最常吃的食材
+ $user_top_foods = $db->query("
+ SELECT TOP 10 food_id, COUNT(*) as eat_count
+ FROM {$this->kitchenscale_db_msg['kcal_log']}
+ WHERE aud_id = ? AND is_del = 0
+ GROUP BY food_id
+ ORDER BY eat_count DESC
+ ", [$user_id]);
+
+ if (empty($user_top_foods)) {
+ return $this->getPopularFoods($db, $tag_limit, $item_limit);
+ }
+
+ $food_ids = array_column($user_top_foods, 'food_id');
+ if (empty($food_ids)) {
+ return $this->getPopularFoods($db, $tag_limit, $item_limit);
+ }
+ $food_ids_str = implode(',', $food_ids);
+
+ // 获取用户偏好食材的分类
+ $preferred_categories = $db->query("
+ SELECT TOP {$tag_limit} f2.id, f2.name, COUNT(DISTINCT f3.id) as food_count
+ FROM {$this->kitchenscale_db_msg['foodlist2']} f2
+ INNER JOIN {$this->kitchenscale_db_msg['foodlist3']} f3 ON f2.id = f3.two_id
+ WHERE f3.id IN ({$food_ids_str}) AND f2.is_del = 0 AND f3.is_del = 0
+ GROUP BY f2.id, f2.name
+ ORDER BY food_count DESC
+ ");
+
+ $result = [];
+ foreach ($preferred_categories as $category) {
+ // 获取该分类下的其他食材
+ $foods = $db->query("
+ SELECT TOP {$item_limit} id, food_name as name
+ FROM {$this->kitchenscale_db_msg['foodlist3']}
+ WHERE two_id = ? AND is_del = 0 AND id NOT IN ({$food_ids_str})
+ ORDER BY is_popular DESC, food_name ASC
+ ", [$category['id']]);
+
+ $category_data = [];
+ foreach ($foods as $food) {
+ $category_data[] = [
+ 'name' => $food['name'] ?? '未知食材',
+ 'id' => $food['id'] ?? 0,
+ 'type' => 'food'
+ ];
+ }
+
+ if (!empty($category_data)) {
+ $result[$category['name'] ?? '未知分类'] = $category_data;
+ }
+ }
+
+ return $result;
+ } catch (\Exception $e) {
+ return $this->getPopularFoods($db, $tag_limit, $item_limit);
+ }
+ }
+}
\ No newline at end of file
diff --git a/application/KitchenScale2/controller/app/Index.php b/application/KitchenScale2/controller/app/Index.php
new file mode 100644
index 0000000..6137ac1
--- /dev/null
+++ b/application/KitchenScale2/controller/app/Index.php
@@ -0,0 +1,890 @@
+'app_account_number',//账号表
+ 'juese'=>'app_user_data',//角色表
+ ];
+ protected $kitchenscale_db_msg = [
+ 'cookbook'=>'app_user_cookbook',//菜谱表
+ 'cookbook_label'=>'app_user_cookbook_label',//菜谱标签表
+ 'uploadimg'=>'app_user_upload_img',//图片素材表
+ 'foodlist1'=>'app_z_national_standard_food_type_1',//食材列表1
+ 'foodlist2'=>'app_z_national_standard_food_type_2',//食材列表2
+ 'foodlist3'=>'app_z_national_standard_food_type_3',//食材列表3
+ 'foodlist4'=>'app_z_national_standard_food_type_4',//食材列表3
+ 'collect_list'=>'app_user_collect_list',//点赞表
+ 'banner'=>'app_banner_data',//banner
+ 'version'=>'app_version_log',//版本表
+ 'user'=>'app_user_data',//用户表
+ 'kcal_log'=>'app_user_kcal_log',//饮食记录表
+ 'search_history'=>'app_user_search_history',//搜索历史表
+ 'business_cooperation'=>'app_business_cooperation',//搜索历史表
+
+ ];
+
+ protected $reedaw_db_name = [
+ 'banner'=>'admin_notice_banner',//菜谱表
+
+ ];
+
+
+ // 加 bcadd(,,20)
+ // 减 bcsub(,,20)
+ // 乘 bcmul(,,20)
+ // 除 bcdiv(,,20)
+ ################################################################接口################################################################
+ ################################################################接口################################################################
+ ################################################################接口################################################################
+
+ // 检测版本及判断是否登录失效
+ public function login_invalid_version($data = ['token'=>'']){
+ try {
+ // 你的业务逻辑
+ if(count(input('post.')) > 0){
+ $data = input('post.');
+ }
+ // if(!array_key_exists('token', $data)){
+ // return $this->msg(10001);
+ // }
+ $cfc = Db::connect('cfc_db');
+ $result = $cfc->table($this->kitchenscale_db_msg['version'])->order('is_del,id desc')->find();
+ if($result){
+ $version = $result['version_num_original'];
+ $url = $result['download_url'];
+ }else{
+ $version = '';
+ $url = '';
+ }
+
+ if($this->token_time_validate($data['token']) === false){
+ $this->record_api_log($data, null, ['code'=>-1,'msg'=>'未登录',['version'=>$version,'url'=>$url]]);
+ return $this->msg(-1,'未登录',['version'=>$version,'url'=>$url]);
+ }else{
+ $this->record_api_log($data, null, ['code'=>0,'msg'=>'success',['version'=>$version,'url'=>$url]]);
+ return $this->msg(['version'=>$version,'url'=>$url]);
+ }
+
+ } 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 wechat_quick_login($data = ['code'=>'asdasdasd','encryptedData'=>'adsadasdasd','iv'=>'asdasdasdasd']){
+ 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();
+ // die;
+ $result = $wechatService->handleWechatLogin($data['code'], $data['encryptedData'], $data['iv']);
+ // dump($result);
+ // die;
+ if($result['code'] == 0){
+ // return $this->msg($result['code'],$result['msg']);
+
+ $user_data = Db::table($this->reedaw_db_msg['zhanghao'])->where(['tel'=>$result['data']['phoneNumber'],'is_del'=>0])->find();
+
+ if($user_data){
+ Db::table($this->reedaw_db_msg['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->reedaw_db_msg['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'] .= "方法: (wechat_quick_login)" . "\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);
+ }
+ }
+
+ // 获取默认配置信息(包含:食材的分类列表,用户角色信息)(OK)
+ public function get_default_config(){
+ try {
+ $data = input('post.');
+ $return_data = $this->get_default_config_action($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'] .= "接口: (get_default_config)\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);
+ }
+ }
+
+ // 首页搜索接口(OK)
+ public function search_column($data = ['search_data'=>'鱼','token'=>'caadd1be045a65f30b92aa805f1de54a','page'=>1]){
+ try {
+ // 你的业务逻辑
+ if(count(input('post.')) > 0){
+ $data = input('post.');
+ }
+ if(!array_key_exists('search_data', $data)){
+ return $this->msg(10001);
+ }
+ if(!array_key_exists('page', $data)){
+ return $this->msg(10001,'page is miss');
+ }
+ if(!$this->verify_data_is_ok($data['search_data'],'str')){
+ return $this->msg(10005);
+ }
+ if(!$this->verify_data_is_ok($data['page'],'intnum')){
+ return $this->msg(10005,'page type is error');
+ }
+ $return_data = $this->search_column_action($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'] .= "接口: (search_column)\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#######################################################################
+ #######################################################################action#######################################################################
+
+ // 新版
+ public function get_default_config_action($data){
+ $return_data = [
+ // 'user_data'=>[],
+ // 'kcal_data'=>[
+ // 'title'=>'今日已摄入热量',
+ // 'time'=>date('Y-m-d H:i:s'),
+ // 'kcal'=>['value'=>0,'unit'=>'kcal','standard'=>'不达标','color'=>'#F0AD4E'],
+ // 'other_elements'=>[
+ // 'carbohydrate'=>['value'=>0,'unit'=>'g'],
+ // 'protein'=>['value'=>0,'unit'=>'g'],
+ // 'fat'=>['value'=>0,'unit'=>'g'],
+ // ],
+ // 'list'=>[
+ // ['title'=>'早餐(千卡)','icon'=>'','value'=>0,'unit'=>'kcal'],
+ // ['title'=>'午餐(千卡)','icon'=>'','value'=>0,'unit'=>'kcal'],
+ // ['title'=>'晚餐(千卡)','icon'=>'','value'=>0,'unit'=>'kcal'],
+ // ['title'=>'加餐(千卡)','icon'=>'','value'=>0,'unit'=>'kcal'],
+ // ],
+ // ],
+ 'business_cooperation'=>[],
+ 'banner_data'=>[],
+ 'search_history'=>['cookbook'=>[],'food'=>[]],
+ 'search_guess'=>[],
+ 'default_count_foot'=>[
+ 'date'=>'', //时间
+ "nutrients_four"=>[
+ [
+ "name"=>"卡路里",
+ "unit"=>"kcal",
+ "suggestion"=>0,
+ "today_intake"=>0,
+ "icon"=>"https://tc.pcxbc.com/kitchenscale_all/icon_kcal.png",
+ "color"=>"#5180D8",
+ "proportion"=>0,
+ "proportion_fp"=>0
+ ],
+ [
+ "name"=>"碳水",
+ "unit"=>"g",
+ "suggestion"=>0,
+ "today_intake"=>0,
+ "icon"=>"https://tc.pcxbc.com/kitchenscale_all/icon_carbohydrate.png",
+ "color"=>"#ED7886",
+ "proportion"=>0,
+ "proportion_fp"=>0
+ ],
+ [
+ "name"=>"蛋白质",
+ "unit"=>"g",
+ "suggestion"=>0,
+ "today_intake"=>0,
+ "icon"=>"https://tc.pcxbc.com/kitchenscale_all/icon_protein.png",
+ "color"=>"#FFB169",
+ "proportion"=>0,
+ "proportion_fp"=>0
+ ],
+ [
+ "name"=>"脂肪",
+ "unit"=>"g",
+ "suggestion"=>0,
+ "today_intake"=>0,
+ "icon"=>"https://tc.pcxbc.com/kitchenscale_all/icon_fat.png",
+ "color"=>"#3CB383",
+ "proportion"=>0,
+ "proportion_fp"=>0
+ ]
+ ],
+ 'remaining_kcal'=>0, //剩下可摄入卡路里量
+ 'details'=>[ //当天营养元素能量占比
+ 'carbohydrate'=>['name'=>'碳水','icon'=>'https://tc.pcxbc.com/kitchenscale_all/icon_carbohydrate.png','color'=>'#ED7886','val'=>0,'unit'=>'g','proportion'=>'0.00','rank_list'=>[['icon'=>'https://tc.pcxbc.com/kitchenscale_all/rank1.png','name'=>'','pic_url'=>'','weight'=>''],['icon'=>'https://tc.pcxbc.com/kitchenscale_all/rank2.png','name'=>'','pic_url'=>'','weight'=>''],['icon'=>'https://tc.pcxbc.com/kitchenscale_all/rank3.png','name'=>'','pic_url'=>'','weight'=>'']]],
+ 'protein'=>['name'=>'蛋白质','icon'=>'https://tc.pcxbc.com/kitchenscale_all/icon_protein.png','color'=>'#FFB169','val'=>0,'unit'=>'g','proportion'=>'0.00','rank_list'=>[['icon'=>'https://tc.pcxbc.com/kitchenscale_all/rank1.png','name'=>'','pic_url'=>'','weight'=>''],['icon'=>'https://tc.pcxbc.com/kitchenscale_all/rank2.png','name'=>'','pic_url'=>'','weight'=>''],['icon'=>'https://tc.pcxbc.com/kitchenscale_all/rank3.png','name'=>'','pic_url'=>'','weight'=>'']]],
+ 'fat'=>['name'=>'脂肪','icon'=>'https://tc.pcxbc.com/kitchenscale_all/icon_fat.png','color'=>'#3CB383','val'=>0,'unit'=>'g','proportion'=>'0.00','rank_list'=>[['icon'=>'https://tc.pcxbc.com/kitchenscale_all/rank1.png','name'=>'','pic_url'=>'','weight'=>''],['icon'=>'https://tc.pcxbc.com/kitchenscale_all/rank2.png','name'=>'','pic_url'=>'','weight'=>''],['icon'=>'https://tc.pcxbc.com/kitchenscale_all/rank3.png','name'=>'','pic_url'=>'','weight'=>'']]],
+ ],
+ 'trace_elements_all_day' => [
+ [
+ 'name' => 'VitaminA',
+ 'name_ch' => '维生素A',
+ 'unit' => 'μg RAE',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'VitaminB1',
+ 'name_ch' => '硫胺素',
+ 'unit' => 'mg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'VitaminB2',
+ 'name_ch' => '核黄素',
+ 'unit' => 'mg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'VitaminB6',
+ 'name_ch' => '维生素B6',
+ 'unit' => 'mg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'VitaminB12',
+ 'name_ch' => '维生素B12',
+ 'unit' => 'μg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'VitaminD',
+ 'name_ch' => '维生素D',
+ 'unit' => 'μg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'VitaminK',
+ 'name_ch' => '维生素K',
+ 'unit' => 'μg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'Niacin',
+ 'name_ch' => '烟酸',
+ 'unit' => 'mg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'VitaminC',
+ 'name_ch' => '维生素C',
+ 'unit' => 'mg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'VitaminE',
+ 'name_ch' => '维生素E',
+ 'unit' => 'mg α-TE',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'FolicAcid',
+ 'name_ch' => '叶酸',
+ 'unit' => 'μg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'Biotin',
+ 'name_ch' => '生物素',
+ 'unit' => 'μg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'PantothenicAcid',
+ 'name_ch' => '泛酸',
+ 'unit' => 'mg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'TotalCholine',
+ 'name_ch' => '总胆碱',
+ 'unit' => 'mg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'Ca',
+ 'name_ch' => '钙',
+ 'unit' => 'mg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'Phosphorus',
+ 'name_ch' => '磷',
+ 'unit' => 'mg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'Kalium',
+ 'name_ch' => '钾',
+ 'unit' => 'mg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'Mg',
+ 'name_ch' => '镁',
+ 'unit' => 'mg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'Na',
+ 'name_ch' => '钠',
+ 'unit' => 'mg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'Fe',
+ 'name_ch' => '铁',
+ 'unit' => 'mg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'Zn',
+ 'name_ch' => '锌',
+ 'unit' => 'mg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'Se',
+ 'name_ch' => '硒',
+ 'unit' => 'μg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'Cu',
+ 'name_ch' => '铜',
+ 'unit' => 'mg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'Mn',
+ 'name_ch' => '锰',
+ 'unit' => 'mg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'Iodine',
+ 'name_ch' => '碘',
+ 'unit' => 'μg',
+ 'value' => 0
+ ]
+ ],
+ 'list'=>[
+ [
+ 'name'=>'早餐',
+ 'val'=>0,
+ 'unit'=>'kcal',
+ 'color'=>'#0992B4',
+ 'icon'=>'https://tc.pcxbc.com/kitchenscale_all/meal_1.png',
+ 'icon_home'=>'/static/1.png',
+ 'bgimg_home'=>'/static/2.png',
+ 'kcal_proportion'=>0,
+ "nutrients_four"=> [
+ [
+ 'name'=>'卡路里',
+ 'unit'=>'kcal',
+ 'color'=>'',
+ 'value'=>0,
+ 'proportion'=>0,
+ ],
+ [
+ 'name'=>'碳水化合物',
+ 'unit'=>'g',
+ 'color'=>'#FFB169',
+ 'value'=>0,
+ 'proportion'=>0,
+ ],
+ [
+ 'name'=>'蛋白质',
+ 'unit'=>'g',
+ 'color'=>'#5180D8',
+ 'value'=>0,
+ 'proportion'=>0,
+ ],
+ [
+ 'name'=>'脂肪',
+ 'unit'=>'g',
+ 'color'=>'#ED7886',
+ 'value'=>0,
+ 'proportion'=>0,
+ ],
+
+ ],
+ 'list'=>[],
+ ],
+ [
+ 'name'=>'午餐',
+ 'val'=>0,
+ 'unit'=>'kcal',
+ 'color'=>'#4F9211',
+ 'icon'=>'https://tc.pcxbc.com/kitchenscale_all/meal_2.png',
+ 'icon_home'=>'/static/3.png',
+ 'bgimg_home'=>'/static/4.png',
+ 'kcal_proportion'=>0,
+ "nutrients_four"=> [
+ [
+ 'name'=>'卡路里',
+ 'unit'=>'kcal',
+ 'color'=>'',
+ 'value'=>0,
+ 'proportion'=>0,
+ ],
+ [
+ 'name'=>'蛋白质',
+ 'unit'=>'g',
+ 'color'=>'#5180D8',
+ 'value'=>0,
+ 'proportion'=>0,
+ ],
+ [
+ 'name'=>'脂肪',
+ 'unit'=>'g',
+ 'color'=>'#ED7886',
+ 'value'=>0,
+ 'proportion'=>0,
+ ],
+ [
+ 'name'=>'碳水化合物',
+ 'unit'=>'g',
+ 'color'=>'#FFB169',
+ 'value'=>0,
+ 'proportion'=>0,
+ ],
+ ],
+ 'list'=>[],
+ ],
+ [
+ 'name'=>'晚餐',
+ 'val'=>0,
+ 'unit'=>'kcal',
+ 'color'=>'#B354B0',
+ 'icon'=>'https://tc.pcxbc.com/kitchenscale_all/meal_3.png',
+ 'icon_home'=>'/static/5.png',
+ 'bgimg_home'=>'/static/6.png',
+ 'kcal_proportion'=>0,
+ "nutrients_four"=> [
+ [
+ 'name'=>'卡路里',
+ 'unit'=>'kcal',
+ 'color'=>'',
+ 'value'=>0,
+ 'proportion'=>0,
+ ],
+ [
+ 'name'=>'蛋白质',
+ 'unit'=>'g',
+ 'color'=>'#5180D8',
+ 'value'=>0,
+ 'proportion'=>0,
+ ],
+ [
+ 'name'=>'脂肪',
+ 'unit'=>'g',
+ 'color'=>'#ED7886',
+ 'value'=>0,
+ 'proportion'=>0,
+ ],
+ [
+ 'name'=>'碳水化合物',
+ 'unit'=>'g',
+ 'color'=>'#FFB169',
+ 'value'=>0,
+ 'proportion'=>0,
+ ],
+ ],
+ 'list'=>[],
+ ],
+ [
+ 'name'=>'加餐',
+ 'val'=>0,
+ 'unit'=>'kcal',
+ 'color'=>'#C08433',
+ 'icon'=>'https://tc.pcxbc.com/kitchenscale_all/meal_4.png',
+ 'icon_home'=>'/static/7.png',
+ 'bgimg_home'=>'/static/8.png',
+ 'kcal_proportion'=>0,
+ "nutrients_four"=> [
+ [
+ 'name'=>'卡路里',
+ 'unit'=>'kcal',
+ 'color'=>'',
+ 'value'=>0,
+ 'proportion'=>0,
+ ],
+ [
+ 'name'=>'蛋白质',
+ 'unit'=>'g',
+ 'color'=>'#5180D8',
+ 'value'=>0,
+ 'proportion'=>0,
+ ],
+ [
+ 'name'=>'脂肪',
+ 'unit'=>'g',
+ 'color'=>'#ED7886',
+ 'value'=>0,
+ 'proportion'=>0,
+ ],
+ [
+ 'name'=>'碳水化合物',
+ 'unit'=>'g',
+ 'color'=>'#FFB169',
+ 'value'=>0,
+ 'proportion'=>0,
+ ],
+ ],
+ 'list'=>[],
+ ],
+ ],
+ ]
+ // 'cookbook_label'=>[],
+ ];
+ $cfc = Db::connect('cfc_db');
+
+ // 如果有账号信息
+ if(array_key_exists('token', $data)){
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005);
+ }
+ // 获取账号下信息以及用户信息 start
+ $user = $cfc->table($this->kitchenscale_db_msg['user'])->where(["token"=>$data['token']])->find();
+
+ if($user){
+ // return $this->msg(20001,'账号信息错误');
+ // 处理搜索历史 start
+ $search_history_cookbook = $cfc->table($this->kitchenscale_db_msg['search_history'])
+ ->where(["user_id"=>$user['id'],'is_del'=>0,'type'=>'cookbook'])
+ ->field('id,keyword,last_searched_at,type')
+ ->order('last_searched_at desc')
+ ->limit(30)
+ ->select();
+ $search_history_food = $cfc->table($this->kitchenscale_db_msg['search_history'])
+ ->where(["user_id"=>$user['id'],'is_del'=>0,'type'=>'food'])
+ ->field('id,keyword,last_searched_at,type')
+ ->order('last_searched_at desc')
+ ->limit(30)
+ ->select();
+ // 去重
+ foreach ($search_history_cookbook as $key => $value) {
+ unset($search_history_cookbook[$key]['type']);
+ unset($search_history_cookbook[$key]['ROW_NUMBER']);
+ }
+ foreach ($search_history_food as $key => $value) {
+ unset($search_history_food[$key]['type']);
+ unset($search_history_food[$key]['ROW_NUMBER']);
+ }
+
+ $return_data['search_history']['cookbook'] = $search_history_cookbook;
+ $return_data['search_history']['food'] = $search_history_food;
+ // 处理搜索历史 end
+ }
+ // $return_data['user_data'] = $user;
+ // if($return_data['user_data']['birthday']){
+ // $return_data['user_data']['age'] = $this->calculate_age($return_data['user_data']['birthday']);
+ // }
+ // unset($return_data['user_data']['id']);
+ // unset($return_data['user_data']['token']);
+ // unset($return_data['user_data']['update_time']);
+ // unset($return_data['user_data']['ROW_NUMBER']);
+ // 获取账号下信息以及用户信息 end
+ // // 处理计食器信息 start
+ // $kcal = $cfc->table($this->kitchenscale_db_msg['kcal_log'])->where(["aud_id"=>$user['id'],'is_del'=>0])->whereTime('create_time', 'today')->order('id desc')->select();
+ // if(count($kcal)>0){
+ // $return_data['kcal_data']['title'] = '今日已摄入热量(千卡)'.$kcal[0]['create_time'];
+ // $return_data['kcal_data']['time'] = $kcal[0]['create_time'];
+ // foreach ($kcal as $key => $value) {
+
+ // $return_data['kcal_data']['kcal']['value'] = bcadd($return_data['kcal_data']['kcal']['value'],$value['kcal_val'],2);
+ // $return_data['kcal_data']['other_elements']['carbohydrate']['value'] = bcadd($return_data['kcal_data']['other_elements']['carbohydrate']['value'],$value['carbohydrate_val'],2);
+ // $return_data['kcal_data']['other_elements']['protein']['value'] = bcadd($return_data['kcal_data']['other_elements']['protein']['value'],$value['protein_val'],2);
+ // $return_data['kcal_data']['other_elements']['fat']['value'] = bcadd($return_data['kcal_data']['other_elements']['fat']['value'],$value['fat_val'],2);
+ // if($value['meals_type'] == '早餐'){
+ // $return_data['kcal_data']['list'][0]['value'] = bcadd($return_data['kcal_data']['list'][0]['value'],$value['kcal_val'],2);
+ // }else if($value['meals_type'] == '午餐'){
+ // $return_data['kcal_data']['list'][1]['value'] = bcadd($return_data['kcal_data']['list'][1]['value'],$value['kcal_val'],2);
+ // }else if($value['meals_type'] == '晚餐'){
+ // $return_data['kcal_data']['list'][2]['value'] = bcadd($return_data['kcal_data']['list'][2]['value'],$value['kcal_val'],2);
+ // }else{
+ // $return_data['kcal_data']['list'][3]['value'] = bcadd($return_data['kcal_data']['list'][3]['value'],$value['kcal_val'],2);
+ // }
+ // }
+ // foreach ($return_data['kcal_data']['list'] as $key => $value) {
+ // if($value['value'] <= 0){
+ // $return_data['kcal_data']['list'][$key]['value'] = '-';
+ // }
+ // }
+ // }
+
+ // if($user['is_use_set_kcal'] == 1){
+ // $nutrition_data['kcal'] = $user['set_kcal'];
+ // }else{
+ // $user['age_num'] = $return_data['user_data']['age'];
+ // $nutrition_data = $this->count_user_nutrition_all($user);
+ // }
+
+ // if(bcdiv($return_data['kcal_data']['kcal']['value'],$nutrition_data['kcal'],2) < 0.9){
+ // $return_data['kcal_data']['kcal']['standard'] = '不达标';
+ // $return_data['kcal_data']['kcal']['color'] = '#F0AD4E';
+ // }else if(bcdiv($return_data['kcal_data']['kcal']['value'],$nutrition_data['kcal'],2) >= 0.9 && bcdiv($return_data['kcal_data']['kcal']['value'],$nutrition_data['kcal'],2) < 1.1){
+ // $return_data['kcal_data']['kcal']['standard'] = '达标';
+ // $return_data['kcal_data']['kcal']['color'] = '#4CD964';
+ // }else{
+ // $return_data['kcal_data']['kcal']['standard'] = '超标';
+ // $return_data['kcal_data']['kcal']['color'] = '#FF0000';
+ // }
+ // // 处理计食器信息 end
+
+
+ // dump($return_data);
+
+ }else{
+
+ }
+ $banner_list = Db::table($this->reedaw_db_name['banner'])->where(['scene_data' => '3','is_del'=>0])->cache(43200)->order('sort_num desc')->field('id,type,pic,jump_url,parameter_data,sort_num')->select();
+ for ($i=0; $i < count($banner_list); $i++) {
+ if($banner_list[$i]['type'] != 1){
+ $banner_list[$i]['parameter_data'] = '';
+ }
+ unset($banner_list[$i]['sort_num']);
+ unset($banner_list[$i]['ROW_NUMBER']);
+ }
+ $return_data['banner_data'] = $banner_list;
+ // 处理banner信息 end
+
+ // 处理猜你喜欢信息start
+ // 使用三元运算符判断$user是否存在
+ $user_id = isset($user) ? $user['id'] : 9999999;
+ $cnxh = new Guessyoulike;
+ $cookbook_data = $cnxh->getGuessYouLike($user_id,'cookbook');
+ $food_data = $cnxh->getGuessYouLike($user_id,'food');
+ foreach ($cookbook_data as $key => $value) {
+ $return_data['search_guess']['cookbook'][] = ['title'=>$key,'list'=>$value];
+ }
+ foreach ($food_data as $key => $value) {
+ $return_data['search_guess']['food_data'][] = ['title'=>$key,'list'=>$value];
+ }
+ // 处理猜你喜欢信息end
+
+ // 添加商务合作信息start
+ $business_cooperation = $cfc->table($this->kitchenscale_db_msg['business_cooperation'])->where(["is_del"=>0])->field('id,title,data_url as jump_url')->find();
+ $return_data['business_cooperation'] = $business_cooperation;
+ // 添加商务合作信息start
+
+ // 添加菜谱label start
+
+ // $cookbook_label = $cfc->table($this->kitchenscale_db_msg['cookbook_label'])->where(["is_del"=>0])->field('id,name')->select();
+ // $return_data['cookbook_label'] = $cookbook_label;
+ // 添加菜谱label end
+
+ // 添加每餐背景图start
+ $return_data['meal_list'] = [
+ ['icon'=>'https://tc.pcxbc.com/kitchenscale_all/meal_1.png','name'=>'早餐','icon_bg'=>'https://tc.pcxbc.com/kitchenscale_all/meal_1_bg.jpg'],
+ ['icon'=>'https://tc.pcxbc.com/kitchenscale_all/meal_2.png','name'=>'午餐','icon_bg'=>'https://tc.pcxbc.com/kitchenscale_all/meal_2_bg.jpg'],
+ ['icon'=>'https://tc.pcxbc.com/kitchenscale_all/meal_3.png','name'=>'晚餐','icon_bg'=>'https://tc.pcxbc.com/kitchenscale_all/meal_3_bg.jpg'],
+ ['icon'=>'https://tc.pcxbc.com/kitchenscale_all/meal_4.png','name'=>'加餐','icon_bg'=>'https://tc.pcxbc.com/kitchenscale_all/meal_4_bg.jpg'],
+ ];
+ // 添加每餐背景图start
+
+
+
+
+
+ return $this->msg($return_data);
+ }
+
+ public function search_column_action($data){
+
+ // $cookbook = new Cookbook();
+ $cfc = Db::connect('cfc_db');
+ $page_now = array_key_exists('page',$data)?$data['page']:1;
+ $page_total = $page_now;
+ $page_num = 20;
+ // 获取菜谱信息
+ $content_num = $cfc->table($this->kitchenscale_db_msg['cookbook'])
+ ->where("title LIKE '%".$data['search_data']."%' OR describe_data LIKE '%".$data['search_data']."%'")
+ ->count();
+ $page_total = ceil($content_num/$page_num);
+
+ $content_list = $cfc->table($this->kitchenscale_db_msg['cookbook'])
+ ->alias('cookbook')
+ ->join($this->kitchenscale_db_msg['uploadimg'].' uploadimg','cookbook.cover = uploadimg.id','LEFT')
+ ->where("cookbook.title LIKE '%".$data['search_data']."%' OR cookbook.describe_data LIKE '%".$data['search_data']."%'")
+ ->field("cookbook.id,cookbook.title,cookbook.create_user_head_pic,cookbook.create_user_nickname,cookbook.likes_num,uploadimg.pic_url as cover")
+ ->page("$page_now,$page_num")
+ ->select();
+
+
+ if(count($content_list)<=0){
+ return $this->msg([]);
+ }
+ if(array_key_exists('token',$data)){
+ if($data['token'] != ''){
+ // 获取账号下信息以及用户信息
+ $user_data = $cfc->table($this->kitchenscale_db_msg['user'])->where(['token'=>$data['token']])->field('id,token,nickname,head_pic')->find();
+ if($user_data){
+ // 获取用户收藏列表
+ $my_collect_list = $cfc->table($this->kitchenscale_db_msg['collect_list'])
+ ->where(['token'=>$data['token']])
+ ->column('cookbook_id');
+ // dump();
+ // 处理菜谱收藏信息
+ foreach ($content_list as $key => $value) {
+ if(array_key_exists($value['id'],$my_collect_list)){
+ $content_list[$key]['is_me_like_it'] = 'yes';
+ }else{
+ $content_list[$key]['is_me_like_it'] = 'no';
+ }
+ if($value['cover'] == null){
+ $content_list[$key]['cover'] = 'https://tc.pcxbc.com/kitchenscale_all/diule.jpg';
+ }
+ unset($content_list[$key]['ROW_NUMBER']);
+ }
+ if($data['search_data'] != ''){
+ $this->add_search_history_action(['id'=>$user_data['id'],'search_data'=>$data['search_data'],'type'=>'cookbook']);
+ }
+
+ }else{
+ foreach ($content_list as $key => $value) {
+ $content_list[$key]['is_me_like_it'] = 'no';
+ if($value['cover'] == null){
+ $content_list[$key]['cover'] = 'https://tc.pcxbc.com/kitchenscale_all/diule.jpg';
+ }
+ unset($content_list[$key]['ROW_NUMBER']);
+ }
+ }
+ }else{
+ foreach ($content_list as $key => $value) {
+ $content_list[$key]['is_me_like_it'] = 'no';
+ if($value['cover'] == null){
+ $content_list[$key]['cover'] = 'https://tc.pcxbc.com/kitchenscale_all/diule.jpg';
+ }
+ unset($content_list[$key]['ROW_NUMBER']);
+ }
+ }
+ }else{
+ foreach ($content_list as $key => $value) {
+ $content_list[$key]['is_me_like_it'] = 'no';
+ if($value['cover'] == null){
+ $content_list[$key]['cover'] = 'https://tc.pcxbc.com/kitchenscale_all/diule.jpg';
+ }
+ unset($content_list[$key]['ROW_NUMBER']);
+ }
+ }
+
+
+ return $this->msg([
+ 'page_now'=>$page_now,
+ 'page_total'=>$page_total,
+ 'content_list'=>$content_list
+ ]);
+ }
+
+
+
+
+ ########################################################################################################################################################################
+ ########################################################################################################################################################################
+ ########################################################################################################################################################################
+
+
+
+
+ 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;
+ }
+
+}
\ No newline at end of file
diff --git a/application/KitchenScale2/controller/app/Login.php b/application/KitchenScale2/controller/app/Login.php
new file mode 100644
index 0000000..3284708
--- /dev/null
+++ b/application/KitchenScale2/controller/app/Login.php
@@ -0,0 +1,705 @@
+'app_account_number',
+ ];
+
+ ################################################################接口################################################################
+ ################################################################接口################################################################
+ ################################################################接口################################################################
+
+ // 注册
+ public function register_action($data = ['data'=>13408173311,'password'=>'123','code'=>'746119']){
+ try {
+ // 你的业务逻辑
+ // 验证是否前段发送过来的数据
+ if(count(input('post.')) > 0){
+ $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);
+ }
+ // 验证是手机还是邮箱
+ $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['1'])->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['1'])->insertGetId($set_data);
+ if($result){
+ $return_data = $this->msg(['token'=>$set_data['token'],'aan_id'=>$result]);
+ }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 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['1'])->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['1'])->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 login_action($data = ['data'=>'18530934717','validate_data'=>'0932','type'=>'login','validate_type'=>'password']){
+ try {
+ // 你的业务逻辑
+ if(count(input('post.')) > 0){
+ $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);
+ }
+ // 检测是否为手机
+ $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['1'])->where($verify_result)->field('id,token')->find();
+ if($result){
+ Db::table($this->login_use_db_name['1'])->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['1'])->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['1'])->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['1'])->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,'校验参数错误');
+ }
+
+ // 成功
+ $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['1'])->where(['tel'=>$result['data']['phoneNumber'],'is_del'=>0])->find();
+
+ if($user_data){
+ Db::table($this->login_use_db_name['1'])->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['1'])->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['1'])->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['1'])->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'=>'体测APP验证码','from_user_name'=>'体测APP','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 = '
+
+
+
+
+
+
+
+ | |
+
+
+
+
+
+
+ |
+
+
+ Reedaw!
+
+
+ |
+
+
+
+
+
+ |
+
+
+ 感谢您选择锐动产品!
+
+
+
+ 以下6位数字是邮箱验证码,请在需要的位置填写以通过验证
+
+
+
+ (如果您从未请求发送邮箱验证码,请忽略此邮件)
+
+
+
+
+ |
+
+
+ '.$content['content'].'
+
+
+ |
+
+
+
+ |
+
+
+
+
+
+ |
+
+
+
+ |
+
+
+ © Zhengzhou Pinchuan Technology Co., Ltd.
+
+
+
+
+
+
+ |
+
+
+ |
+
+
+
+ |
+ |
+
+
+
+ |
+
+
+
';
+
+ $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){
+ // // 默认验证码正确
+
+ 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;
+ }
+
+
+
+}
\ No newline at end of file
diff --git a/application/KitchenScale2/controller/app/Product.php b/application/KitchenScale2/controller/app/Product.php
new file mode 100644
index 0000000..d2d4191
--- /dev/null
+++ b/application/KitchenScale2/controller/app/Product.php
@@ -0,0 +1,75 @@
+table("ceshi3_option")
+ ->alias('xuanxiang')
+ ->join('ceshi2_configuration peizhi','xuanxiang.parent_id = peizhi.id','LEFT')
+ ->where(['peizhi.is_default'=>$this->is_default])
+ ->field("xuanxiang.*,peizhi.name")
+ ->select();
+ $temporary = [];
+ foreach ($content_num as $key => $value) {
+ $temporary[$value['name']]['id'] = $value['parent_id'];
+ $temporary[$value['name']]['name'] = $value['name'];
+ $temporary[$value['name']]['type'] = "configuration";
+ $temporary[$value['name']]['list'][$value['value']] = [];
+ $temporary[$value['name']]['list'][$value['value']]['id'] = $value['id'];
+ $temporary[$value['name']]['list'][$value['value']]['name'] = $value['value'];
+ $temporary[$value['name']]['list'][$value['value']]['type'] = "parameter";
+ $temporary[$value['name']]['list'][$value['value']]['list'] = [];
+ }
+ // dump($temporary);
+ // die;
+ return $this->msg($temporary);
+ }
+
+ // 获取所点击选项的所有直属上级配置项
+ private function getAncestorConfigurations($cfc, $optionId)
+ {
+ $ancestors = [];
+
+ // 获取当前选项的配置项
+ $currentConfig = $cfc->query("
+ SELECT c.id, c.name, c.parent_id
+ FROM configurations c
+ JOIN options o ON c.id = o.config_id
+ WHERE o.id = ?
+ ", [$optionId]);
+
+ if (!empty($currentConfig)) {
+ $currentConfig = $currentConfig[0];
+
+ // 获取直属上级配置项
+ if ($currentConfig['parent_id']) {
+ $parentConfig = $cfc->query("
+ SELECT c.id, c.name
+ FROM configurations c
+ WHERE c.id = ?
+ ", [$currentConfig['parent_id']]);
+
+ if (!empty($parentConfig)) {
+ $parentConfig = $parentConfig[0];
+ $ancestors[] = $parentConfig;
+ }
+ }
+ }
+
+ return $ancestors;
+ }
+}
\ No newline at end of file
diff --git a/application/KitchenScale2/controller/app/Usercenter.php b/application/KitchenScale2/controller/app/Usercenter.php
new file mode 100644
index 0000000..3b34b4f
--- /dev/null
+++ b/application/KitchenScale2/controller/app/Usercenter.php
@@ -0,0 +1,811 @@
+'app_account_number',//账号表
+ 'juese'=>'app_user_data',//角色表
+ ];
+ protected $kitchenscale_db_msg = [
+ 'cookbook'=>'app_user_cookbook',//菜谱表
+ 'cookbook_label'=>'app_user_cookbook_label',//菜谱标签表
+ 'uploadimg'=>'app_user_upload_img',//图片素材表
+ 'foodlist1'=>'app_z_national_standard_food_type_1',//食材列表1
+ 'foodlist2'=>'app_z_national_standard_food_type_2',//食材列表2
+ 'foodlist3'=>'app_z_national_standard_food_type_3',//食材列表3
+ 'collect_list'=>'app_user_collect_list',//点赞表
+ 'banner'=>'app_banner_data',//banner
+ 'user'=>'app_user_data',//用户表
+ 'search_history'=>'app_user_search_history',//用户搜索表
+ 'business_cooperation'=>'app_business_cooperation_log',//商务合作
+ 'eat_log'=>'app_user_kcal_log',//食材列表3
+ ];
+
+
+ // 加 bcadd(,,20)
+ // 减 bcsub(,,20)
+ // 乘 bcmul(,,20)
+ // 除 bcdiv(,,20)
+ ################################################################接口################################################################
+ ################################################################接口################################################################
+ ################################################################接口################################################################
+
+ // 获取角色信息
+ public function get_user_msg($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_data = $this->get_user_msg_action($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'] .= "接口: (get_default_config)\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_user_msg(){
+ try {
+ if(count(input('post.')) > 0){
+ $data = input('post.');
+ }
+ if(!array_key_exists('token', $data)){
+ return $this->msg(10001,'token is miss');
+ }
+ if(!array_key_exists('nickname', $data)){
+ return $this->msg(10001,'nickname is miss');
+ }
+ if(!array_key_exists('gender', $data)){
+ return $this->msg(10001,'gender is miss');
+ }
+ if(!array_key_exists('birthday', $data)){
+ return $this->msg(10001,'birthday is miss');
+ }
+ if(!array_key_exists('height', $data)){
+ return $this->msg(10001,'height is miss');
+ }
+ if(!array_key_exists('weight', $data)){
+ return $this->msg(10001,'weight is miss');
+ }
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005,'token type is error');
+ }
+ if(!$this->verify_data_is_ok($data['nickname'],'str')){
+ return $this->msg(10005,'nickname type is error');
+ }
+ if(!$this->verify_data_is_ok($data['gender'],'intnum')){
+ return $this->msg(10005,'gender type is error');
+ }
+ if(!$this->verify_data_is_ok($data['birthday'],'datetime')){
+ return $this->msg(10005,'birthday type is error');
+ }
+ if(!$this->verify_data_is_ok($data['height'],'num')){
+ return $this->msg(10005,'height type is error');
+ }
+ if(!$this->verify_data_is_ok($data['weight'],'num')){
+ return $this->msg(10005,'weight type is error');
+ }
+ $return_data = $this->update_user_msg_action($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'] .= "接口: (get_default_config)\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);
+ }
+ }
+
+ // 获取用户收藏点赞列表(OK)
+ public function get_user_collect_list($data = ['token'=>'caadd1be045a65f30b92aa805f1de54a','page'=>1,'search_data'=>'']){
+ try {
+ if(count(input('post.')) > 0){
+ $data = input('post.');
+ }
+ if(!array_key_exists('token', $data)){
+ return $this->msg(10001,'token is miss');
+ }
+ if(!array_key_exists('page', $data)){
+ return $this->msg(10001,'page is miss');
+ }
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005,'token type is error');
+ }
+ if(!$this->verify_data_is_ok($data['page'],'intnum')){
+ return $this->msg(10005,'page type is error');
+ }
+ $return_data = $this->get_user_collect_list_action($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'] .= "接口: (get_default_config)\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_my_cookbook($data = ['token'=>'caadd1be045a65f30b92aa805f1de54a','page'=>1,'search_data'=>'']){
+ try {
+ if(count(input('post.')) > 0){
+ $data = input('post.');
+ }
+ if(!array_key_exists('token', $data)){
+ return $this->msg(10001,'token is miss');
+ }
+ if(!array_key_exists('page', $data)){
+ return $this->msg(10001,'page is miss');
+ }
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005,'token type is error');
+ }
+ if(!$this->verify_data_is_ok($data['page'],'intnum')){
+ return $this->msg(10005,'page type is error');
+ }
+ $return_data = $this->get_my_cookbook_action($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'] .= "接口: (get_default_config)\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 del_my_cookbook($data = ['token'=>'caadd1be045a65f30b92aa805f1de54a','aud_id'=>1,'cookbook_id'=>'33']){
+ try {
+ if(count(input('post.')) > 0){
+ $data = input('post.');
+ }
+ if(!array_key_exists('token', $data)){
+ return $this->msg(10001,'token is miss');
+ }
+ if(!array_key_exists('aud_id', $data)){
+ return $this->msg(10001,'aud_id is miss');
+ }
+ if(!array_key_exists('cookbook_id', $data)){
+ return $this->msg(10001,'cookbook_id is miss');
+ }
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005,'token type is error');
+ }
+ if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
+ return $this->msg(10005,'aud_id type is error');
+ }
+ if(!$this->verify_data_is_ok($data['cookbook_id'],'intnum')){
+ return $this->msg(10005,'cookbook_id type is error');
+ }
+ $return_data = $this->del_my_cookbook_action($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'] .= "接口: (get_default_config)\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 del_search_history(){
+ // 尝试捕获异常
+ try {
+ if(count(input('post.')) > 0){
+ $data = input('post.');
+ }
+ if(!array_key_exists('token', $data)){
+ return $this->msg(10001,'token is miss');
+ }
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005,'token type is error');
+ }
+ if(!array_key_exists('del_arr', $data)){
+ return $this->msg(10001,'del_arr is miss');
+ }
+ if(!$this->verify_data_is_ok($data['del_arr'],'str')){
+ return $this->msg(10005,'del_arr type is error');
+ }
+ $data['del_arr'] = strval($data['del_arr']);
+ $data['del_arr'] = trim($data['del_arr']);
+ // 判断是否是 "all"(不区分大小写)
+ if (strtolower($data['del_arr']) !== 'all' && preg_match('/^\d+(,\d+)*$/', $data['del_arr']) !== 1) {
+ return $this->msg(10005,'del_arr type is error');
+ }
+
+ $return_data = $this->del_search_history_action($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'] .= "行号: " . $e->getLine() . "\n";
+ $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
+ // 记录日志
+ $this->record_api_log($data, $logContent, null);
+ return json(['status' => 'error', 'message' => '系统错误']);
+ }
+ }
+
+ // 商务合作
+ public function business_cooperation(){
+ return $this->fetch();
+ }
+
+
+
+ #######################################################################action#######################################################################
+ #######################################################################action#######################################################################
+ #######################################################################action#######################################################################
+
+ public function get_user_msg_action($data){
+ // 获取账号下信息以及用户信息
+ $user_data = Db::table($this->reedaw_db_msg['zhanghao'])->where(['token'=>$data['token']])->field('id,token,nickname,head_pic,tel,email')->find();
+ if(!$user_data){
+ return $this->msg(10004);
+ }
+ // $return_data = [];
+ // 获取账号下信息以及用户信息start
+ $user_all_data['aud_id'] = '';
+ $user_all_data['token'] = $user_data['token'];
+ $user_all_data['nickname'] = $user_data['nickname'];
+ $user_all_data['head_pic'] = $user_data['head_pic'];
+ $user_all_data['gender'] = '';
+ $user_all_data['age'] = '';
+ $user_all_data['height'] = '';
+ $user_all_data['weight'] = '';
+ $user_all_data['set_kcal'] = '';
+ $user_all_data['is_use_set_kcal'] = '';
+ $user_all_data['tel'] = $user_data['tel'];
+ $user_all_data['email'] = $user_data['email'];
+ $cfc = Db::connect('cfc_db');
+ $user_account = $cfc->table($this->kitchenscale_db_msg['user'])
+ ->where(["token"=>$data['token']])
+ ->field('id as aud_id,token,nickname,head_pic,gender,age,height,weight,set_kcal,is_use_set_kcal,birthday')
+ ->find();
+ if($user_account){
+ if($user_account['set_kcal'] == '.00'){
+ $user_account['set_kcal'] = 0;
+ }
+ $user_all_data['aud_id'] = $user_account['aud_id'];
+ $user_all_data['gender'] = $user_account['gender'];
+ $user_all_data['age'] = $user_account['age']?$user_account['age']:$this->calculate_age($user_account['birthday']);
+ $user_all_data['height'] = $user_account['height'];
+ $user_all_data['weight'] = $user_account['weight'];
+ $user_all_data['set_kcal'] = $user_account['set_kcal'];
+ $user_all_data['is_use_set_kcal'] = $user_account['is_use_set_kcal'];
+ $user_all_data['birthday'] = $user_account['birthday'];
+ $user_all_data['food_count'] = $this->user_that_day_food_count($user_account);
+ }else{
+ return $this->msg(10004);
+ }
+
+
+ // $return_data = $user_all_data;
+ return $this->msg($user_all_data);
+ // 获取账号下信息以及用户信息end
+ }
+ public function update_user_msg_action($data){
+ if($data['gender'] == 0){
+ return $this->msg(10005,'性别信息错误');
+ }
+ // 获取账号下信息以及用户信息
+ $user_data = Db::table($this->reedaw_db_msg['zhanghao'])->where(['token'=>$data['token']])->count();
+ if($user_data<=0){
+ return $this->msg(10005,'账号信息错误');
+ }
+
+ $cfc = Db::connect('cfc_db');
+
+ $is_user_true = $cfc->table($this->kitchenscale_db_msg['user'])->where(['token'=>$data['token']])->count();
+
+ $user_msg['nickname'] = $data['nickname'];
+ $user_msg['head_pic'] = $data['gender'] == 1?'https://tc.pcxbc.com/tsf/1.png':'https://tc.pcxbc.com/tsf/2.png';
+ $user_msg['gender'] = $data['gender'];
+ $user_msg['birthday'] = $data['birthday'];
+ $user_msg['height'] = $data['height'];
+ $user_msg['weight'] = $data['weight'];
+
+ if($is_user_true>0){
+ $user_msg['update_time'] = date('Y-m-d H:i:s');
+ $result = $cfc->table($this->kitchenscale_db_msg['user'])
+ ->where(['token'=>$data['token']])
+ ->update($user_msg);
+ }else{
+ $user_msg['token'] = $data['token'];
+ $result = $cfc->table($this->kitchenscale_db_msg['user'])
+ ->insert($user_msg);
+ }
+ Db::table($this->reedaw_db_msg['zhanghao'])->where(['token'=>$data['token']])->update(['nickname'=>$user_msg['nickname']]);
+ if($result){
+ return $this->msg([]);
+ }else{
+ return $this->msg(10002);
+ }
+ }
+ public function get_user_collect_list_action($data){
+ // 获取账号下信息以及用户信息
+ $user_data = Db::table($this->reedaw_db_msg['zhanghao'])->where(['token'=>$data['token']])->count();
+ if($user_data<=0){
+ return $this->msg(10005,'账号信息错误');
+ }
+
+ $search_sql_str = "a.token = '".$data['token']."' AND a.is_del = 0 AND b.is_del = 0";
+ if(!array_key_exists('search_data', $data)){
+ $data['search_data'] = "";
+ }else{
+ if($data['search_data'] === ""){
+ $data['search_data'] = "";
+ }else{
+ $data['search_data'] = " AND (b.title LIKE '%".$data['search_data']."%' OR b.describe_data LIKE '%".$data['search_data']."%')";
+ }
+ }
+ $search_sql_str = $search_sql_str.$data['search_data'];
+ // "a.token = 'asdasdasdasda' AND a.is_del = 0 AND b.title LIKE '%鱼%' OR b.describe_data LIKE '%鱼%'";
+
+ $cfc = Db::connect('cfc_db');
+
+ $content_num = $cfc->table($this->kitchenscale_db_msg['collect_list'])
+ ->alias('a')
+ ->join($this->kitchenscale_db_msg['cookbook'].' b','a.cookbook_id = b.id','LEFT')
+ ->join($this->kitchenscale_db_msg['uploadimg'].' c','b.cover = c.id','LEFT')
+ ->where($search_sql_str)
+ ->count();
+ $page_total = ceil($content_num/$this->page_num);;
+ $collect_list = $cfc->table($this->kitchenscale_db_msg['collect_list'])
+ ->alias('a')
+ ->join($this->kitchenscale_db_msg['cookbook'].' b','a.cookbook_id = b.id','LEFT')
+ ->join($this->kitchenscale_db_msg['uploadimg'].' c','b.cover = c.id','LEFT')
+ ->where($search_sql_str)
+ ->field("b.id,b.title,b.cover as cover_id,c.pic_url as cover_url,b.likes_num,b.create_user_token,b.create_user_head_pic,b.create_user_nickname")
+ ->page($data['page'],$this->page_num)
+ ->select();
+
+ foreach ($collect_list as $key => $value) {
+ $collect_list[$key]['is_me_like_it'] = 'yes';
+
+ }
+
+ return $this->msg([
+ 'page_now'=>$data['page'],
+ 'page_total'=>$page_total,
+ 'content_list'=>$collect_list
+ ]);
+ }
+
+ public function get_my_cookbook_action($data){
+ // 获取账号下信息以及用户信息
+ $user_data = Db::table($this->reedaw_db_msg['zhanghao'])->where(['token'=>$data['token']])->count();
+ if($user_data<=0){
+ return $this->msg(10005,'账号信息错误');
+ }
+
+ $search_sql_str = "b.create_user_token = '".$data['token']."' AND b.is_del = 0";
+ if(!array_key_exists('search_data', $data)){
+ $data['search_data'] = "";
+ }else{
+ if($data['search_data'] === ""){
+ $data['search_data'] = "";
+ }else{
+ $data['search_data'] = " AND (b.title LIKE '%".$data['search_data']."%' OR b.describe_data LIKE '%".$data['search_data']."%')";
+ }
+ }
+ $search_sql_str = $search_sql_str.$data['search_data'];
+
+ $cfc = Db::connect('cfc_db');
+ $content_num = $cfc->table($this->kitchenscale_db_msg['cookbook'])
+ ->alias('b')
+ ->join($this->kitchenscale_db_msg['uploadimg'].' c','b.cover = c.id','LEFT')
+ ->where($search_sql_str)
+ ->count();
+ $page_total = ceil($content_num/$this->page_num);;
+ $content_list = $cfc->table($this->kitchenscale_db_msg['cookbook'])
+ ->alias('b')
+ ->join($this->kitchenscale_db_msg['uploadimg'].' c','b.cover = c.id','LEFT')
+ ->where($search_sql_str)
+ ->field("b.id,b.title,b.cover as cover_id,c.pic_url as cover_url,b.likes_num,b.create_user_token,b.create_user_head_pic,b.create_user_nickname")
+ ->page($data['page'],$this->page_num)
+ ->select();
+
+ // 获取用户收藏列表
+ $my_collect_list = $cfc->table($this->kitchenscale_db_msg['collect_list'])
+ ->where(['token'=>$data['token'],'is_del'=>0])
+ ->column('cookbook_id');
+ // dump($my_collect_list);
+ // 处理菜谱收藏信息
+ foreach ($content_list as $key => $value) {
+ // if(in_array($value['id'],$my_collect_list)){
+ if(array_key_exists($value['id'],$my_collect_list)){
+ $content_list[$key]['is_me_like_it'] = 'yes';
+ }else{
+ $content_list[$key]['is_me_like_it'] = 'no';
+ }
+ // if($value['cover'] == null){
+ // $content_list[$key]['cover'] = 'https://tc.pcxbc.com/kitchenscale_all/diule.jpg';
+ // }
+ unset($content_list[$key]['ROW_NUMBER']);
+ }
+
+ // foreach ($collect_list as $key => $value) {
+ // $collect_list[$key]['is_me_like_it'] = 'yes';
+
+ // }
+
+ return $this->msg([
+ 'page_now'=>$data['page'],
+ 'page_total'=>$page_total,
+ 'content_list'=>$content_list
+ ]);
+ }
+
+ public function del_my_cookbook_action($data){
+ // 获取账号下信息以及用户信息
+ $user_data = Db::table($this->reedaw_db_msg['zhanghao'])->where(['token'=>$data['token']])->count();
+ if($user_data<=0){
+ return $this->msg(10005,'账号信息错误');
+ }
+
+ $cfc = Db::connect('cfc_db');
+
+ $cookbook_data = $cfc->table($this->kitchenscale_db_msg['cookbook'])->where(['id'=>$data['cookbook_id'],'create_user_token'=>$data['token']])->find();
+
+ if($cookbook_data){
+
+ // 启动事务
+ $cfc->startTrans();
+ try{
+ $cfc->table($this->kitchenscale_db_msg['cookbook'])->where(['id'=>$data['cookbook_id']])->update(['is_del'=>1]);
+ $result_banner = $cfc->table($this->kitchenscale_db_msg['banner'])->where(['cookbook_id'=>$cookbook_data['id']])->count();
+ if($result_banner > 0){
+ $cfc->table($this->kitchenscale_db_msg['banner'])->where(['cookbook_id'=>$cookbook_data['id']])->update(['is_del'=>1]);
+ }
+ // 提交事务
+ $cfc->commit();
+ return $this->msg([]);
+ } catch (\Exception $e) {
+ // 回滚事务
+ $cfc->rollback();
+ return $this->msg(10002);
+ }
+ }else{
+ return $this->msg(10003);
+ }
+
+ }
+
+
+ public function del_search_history_action($data){
+
+ // $data['del_arr'] = strval($data['del_arr']);
+ // $data['del_arr'] = trim($data['del_arr']);
+
+ // // 正确的判断逻辑:如果不是all 并且 不是ID列表,就报错
+ // if (strtolower($data['del_arr']) !== 'all' && preg_match('/^\d+(,\d+)*$/', $data['del_arr']) !== 1) {
+ // return $this->msg(10005, 'del_arr type is error');
+ // }
+
+
+
+ $cfc = Db::connect('cfc_db');
+ $user = $cfc->table($this->kitchenscale_db_msg['user'])->where(['token'=>$data['token']])->field('id,token')->find();
+ if(!$user){
+ return $this->msg(20001,'账号信息错误');
+ }
+ if($data['del_arr'] == 'all'){
+ $result = $cfc->table($this->kitchenscale_db_msg['search_history'])
+ ->where(['user_id'=>$user['id']])
+ ->update(['is_del'=>1]);
+ }else{
+ $result = $cfc->table($this->kitchenscale_db_msg['search_history'])
+ ->where("user_id = ".$user['id']." AND id IN (".$data['del_arr'].")")
+ ->update(['is_del'=>1]);
+ }
+ if($result){
+ return $this->msg([]);
+ }else{
+ return $this->msg(10002);
+ }
+
+
+ // 获取菜谱分类标签end
+ }
+
+ public function business_cooperation_action(){
+ $data = input();
+
+ $cfc = Db::connect('cfc_db');
+ $result = $cfc->table($this->kitchenscale_db_msg['business_cooperation'])
+ ->insert([
+ 'name'=>$data['name'],
+ 'tel'=>$data['phone'],
+ 'company'=>$data['company'],
+ 'intention_data'=> implode(',',$data['selectedValues']),
+ 'notes_data'=>$data['remark'],
+ 'create_time'=>date('Y-m-s H:i:s'),
+ ]);
+ if($result){
+ return $this->msg([]);
+ }else{
+ return $this->msg(10002);
+ }
+ }
+
+
+ public function user_that_day_food_count($user_data){
+ $cfc = Db::connect('cfc_db');
+ if($user_data['birthday']){
+ $user_data['age_num'] = $this->calculate_age($user_data['birthday']);
+ }else{
+ $user_data['age_num'] = $user_data['age'];
+ }
+ $nutrition_data = $this->count_user_nutrition_all($user_data);
+ if($user_data['is_use_set_kcal'] == 1){
+ $proportion = bcdiv($user_data['set_kcal'],$nutrition_data['kcal'],20);
+ $nutrition_data['kcal'] = $user_data['set_kcal'];
+ $nutrition_data['carbohydrate'] = bcmul($nutrition_data['carbohydrate'],$proportion,2);
+ $nutrition_data['protein'] = bcmul($nutrition_data['protein'],$proportion,2);
+ $nutrition_data['fat'] = bcmul($nutrition_data['fat'],$proportion,2);
+
+ }
+ $day_time = date('Y-m-d');
+ $return_data = [
+ 'date'=>$day_time, //时间
+ 'suggestion'=>[ //建议
+ 'kcal'=>$nutrition_data['kcal'], //建议摄入卡路里量
+ 'carbohydrate'=>$nutrition_data['carbohydrate'], //建议摄入碳水量
+ 'protein'=>$nutrition_data['protein'], //建议摄入蛋白质量
+ 'fat'=>$nutrition_data['fat'], //建议摄入脂肪量
+ ],
+ 'today_intake'=>[ //今日已摄入
+ 'kcal'=>0, //今日已摄入卡路里量
+ 'carbohydrate'=>0, //今日已摄入碳水量
+ 'protein'=>0, //今日已摄入蛋白质量
+ 'fat'=>0, //今日已摄入脂肪量
+ ],
+ 'remaining_kcal'=>$nutrition_data['kcal'], //剩下可摄入卡路里量
+ 'list'=>[
+ [
+ 'name'=>'早餐',
+ 'val'=>0,
+ 'unit'=>'kcal',
+ 'color'=>'#0992B4',
+ 'icon'=>'https://tc.pcxbc.com/kitchenscale_all/meal_1.png',
+ 'icon_home'=>'/static/1.png',
+ 'bgimg_home'=>'/static/2.png',
+ 'kcal_proportion'=>0,
+ 'list'=>[],
+ ],
+ [
+ 'name'=>'午餐',
+ 'val'=>0,
+ 'unit'=>'kcal',
+ 'color'=>'#4F9211',
+ 'icon'=>'https://tc.pcxbc.com/kitchenscale_all/meal_2.png',
+ 'icon_home'=>'/static/3.png',
+ 'bgimg_home'=>'/static/4.png',
+ 'kcal_proportion'=>0,
+ 'list'=>[],
+ ],
+ [
+ 'name'=>'晚餐',
+ 'val'=>0,
+ 'unit'=>'kcal',
+ 'color'=>'#B354B0',
+ 'icon'=>'https://tc.pcxbc.com/kitchenscale_all/meal_3.png',
+ 'icon_home'=>'/static/5.png',
+ 'bgimg_home'=>'/static/6.png',
+ 'kcal_proportion'=>0,
+ 'list'=>[],
+ ],
+ [
+ 'name'=>'加餐',
+ 'val'=>0,
+ 'unit'=>'kcal',
+ 'color'=>'#C08433',
+ 'icon'=>'https://tc.pcxbc.com/kitchenscale_all/meal_4.png',
+ 'icon_home'=>'/static/7.png',
+ 'bgimg_home'=>'/static/8.png',
+ 'kcal_proportion'=>0,
+ 'list'=>[],
+ ],
+ ],
+ ];
+
+ // 查询用户今日摄入食物
+ $food_content = $cfc->table($this->kitchenscale_db_msg['eat_log'])
+ ->alias('a')
+ ->join('app_z_national_standard_food_type_3 b','a.food_id = b.id','LEFT')
+ ->where("a.is_del = 0 AND a.aud_id = " . $user_data['aud_id'] . " AND CAST(a.create_time AS DATE) = CAST('" . $day_time . "' AS DATE)")
+ ->field('a.meals_type,a.food_name,a.weight,a.kcal_val,a.carbohydrate_val,a.protein_val,a.fat_val,a.id,\'https://tc.pcxbc.com\' + b.pic_url as pic_url,a.food_id')
+ ->select();
+
+ if(count($food_content) > 0){ //计算营养物质
+ $food_content = $this->calculate_nutrients($food_content);
+ // return $this->msg($food_content);
+ foreach ($food_content as $key => $value) {
+ // dump($value['nutrients_four']);
+ $return_data['today_intake']['kcal'] = bcadd($return_data['today_intake']['kcal'],$value['kcal_val'],2);
+ $return_data['today_intake']['carbohydrate'] = bcadd($return_data['today_intake']['carbohydrate'],$value['carbohydrate_val'],2);
+ $return_data['today_intake']['protein'] = bcadd($return_data['today_intake']['protein'],$value['protein_val'],2);
+ $return_data['today_intake']['fat'] = bcadd($return_data['today_intake']['fat'],$value['fat_val'],2);
+ // 处理各餐
+ if($value['meals_type'] == '早餐'){
+ $return_data['list'][0]['val'] = bcadd($return_data['list'][0]['val'],$value['kcal_val'],2);
+ // $return_data['list'][0]['nutrients_four'][0]['value'] = bcadd($return_data['list'][0]['nutrients_four'][0]['value'],$value['kcal_val'],2);
+ // $return_data['list'][0]['nutrients_four'][1]['value'] = bcadd($return_data['list'][0]['nutrients_four'][1]['value'],$value['carbohydrate_val'],2);
+ // $return_data['list'][0]['nutrients_four'][2]['value'] = bcadd($return_data['list'][0]['nutrients_four'][2]['value'],$value['protein_val'],2);
+ // $return_data['list'][0]['nutrients_four'][3]['value'] = bcadd($return_data['list'][0]['nutrients_four'][3]['value'],$value['fat_val'],2);
+ array_push($return_data['list'][0]['list'],[
+ 'name'=>$value['food_name'],
+ 'weight'=>$value['weight'].'克',
+ 'id'=>$value['id'],
+ 'pic_url'=>$value['pic_url'],
+ 'val'=>$value['kcal_val'],
+ // 'nutrients_four' => $value['nutrients_four'],
+ // 'nutrients_list' => $value['nutrients_list']
+ ]);
+ }else if($value['meals_type'] == '午餐'){
+ $return_data['list'][1]['val'] = bcadd($return_data['list'][1]['val'],$value['kcal_val'],2);
+ // $return_data['list'][1]['nutrients_four'][0]['value'] = bcadd($return_data['list'][1]['nutrients_four'][0]['value'],$value['kcal_val'],2);
+ // $return_data['list'][1]['nutrients_four'][1]['value'] = bcadd($return_data['list'][1]['nutrients_four'][1]['value'],$value['carbohydrate_val'],2);
+ // $return_data['list'][1]['nutrients_four'][2]['value'] = bcadd($return_data['list'][1]['nutrients_four'][2]['value'],$value['protein_val'],2);
+ // $return_data['list'][1]['nutrients_four'][3]['value'] = bcadd($return_data['list'][1]['nutrients_four'][3]['value'],$value['fat_val'],2);
+ array_push($return_data['list'][1]['list'],[
+ 'name'=>$value['food_name'],
+ 'weight'=>$value['weight'].'克',
+ 'id'=>$value['id'],
+ 'pic_url'=>$value['pic_url'],
+ 'val'=>$value['kcal_val'],
+ // 'nutrients_four' => $value['nutrients_four'],
+ // 'nutrients_list' => $value['nutrients_list']
+ ]);
+ }else if($value['meals_type'] == '晚餐'){
+ $return_data['list'][2]['val'] = bcadd($return_data['list'][2]['val'],$value['kcal_val'],2);
+ // $return_data['list'][2]['nutrients_four'][0]['value'] = bcadd($return_data['list'][2]['nutrients_four'][0]['value'],$value['kcal_val'],2);
+ // $return_data['list'][2]['nutrients_four'][1]['value'] = bcadd($return_data['list'][2]['nutrients_four'][1]['value'],$value['carbohydrate_val'],2);
+ // $return_data['list'][2]['nutrients_four'][2]['value'] = bcadd($return_data['list'][2]['nutrients_four'][2]['value'],$value['protein_val'],2);
+ // $return_data['list'][2]['nutrients_four'][3]['value'] = bcadd($return_data['list'][2]['nutrients_four'][3]['value'],$value['fat_val'],2);
+ array_push($return_data['list'][2]['list'],[
+ 'name'=>$value['food_name'],
+ 'weight'=>$value['weight'].'克',
+ 'id'=>$value['id'],
+ 'pic_url'=>$value['pic_url'],
+ 'val'=>$value['kcal_val'],
+ // 'nutrients_four' => $value['nutrients_four'],
+ // 'nutrients_list' => $value['nutrients_list']
+ ]);
+ }else{
+ $return_data['list'][3]['val'] = bcadd($return_data['list'][3]['val'],$value['kcal_val'],2);
+ // $return_data['list'][3]['nutrients_four'][0]['value'] = bcadd($return_data['list'][3]['nutrients_four'][0]['value'],$value['kcal_val'],2);
+ // $return_data['list'][3]['nutrients_four'][1]['value'] = bcadd($return_data['list'][3]['nutrients_four'][1]['value'],$value['carbohydrate_val'],2);
+ // $return_data['list'][3]['nutrients_four'][2]['value'] = bcadd($return_data['list'][3]['nutrients_four'][2]['value'],$value['protein_val'],2);
+ // $return_data['list'][3]['nutrients_four'][3]['value'] = bcadd($return_data['list'][3]['nutrients_four'][3]['value'],$value['fat_val'],2);
+ array_push($return_data['list'][3]['list'],[
+ 'name'=>$value['food_name'],
+ 'weight'=>$value['weight'].'克',
+ 'id'=>$value['id'],
+ 'pic_url'=>$value['pic_url'],
+ 'val'=>$value['kcal_val'],
+ // 'nutrients_four' => $value['nutrients_four'],
+ // 'nutrients_list' => $value['nutrients_list']
+ ]);
+ }
+ }
+ // dump($return_data['list']);
+ // die;
+ $return_data['list'] = array_values($return_data['list']);
+ // 处理剩下可吃
+ $return_data['remaining_kcal'] = bcsub($return_data['suggestion']['kcal'],$return_data['today_intake']['kcal'],2)>=0?bcsub($return_data['suggestion']['kcal'],$return_data['today_intake']['kcal'],2):0;
+
+ $nameMap = [
+ 'kcal' => ['卡路里','kcal','https://tc.pcxbc.com/kitchenscale_all/icon_kcal.png','#5180D8'],
+ 'carbohydrate' => ['碳水','g','https://tc.pcxbc.com/kitchenscale_all/icon_carbohydrate.png','#ED7886'],
+ 'protein' => ['蛋白质','g','https://tc.pcxbc.com/kitchenscale_all/icon_protein.png','#FFB169'],
+ 'fat' => ['脂肪','g','https://tc.pcxbc.com/kitchenscale_all/icon_fat.png','#3CB383'],
+ ];
+ $all_yy_data = bcadd($return_data['suggestion']['fat'],bcadd($return_data['suggestion']['carbohydrate'],$return_data['suggestion']['protein'],20),20);
+ foreach ($return_data['suggestion'] as $key => $value) {
+ $return_data['nutrients_four'][] = [
+ 'name'=>$nameMap[$key][0],
+ 'unit'=>$nameMap[$key][1],
+ 'suggestion'=>$value,
+ 'today_intake'=>$return_data['today_intake'][$key],
+ 'icon'=>$nameMap[$key][2],
+ 'color'=>$nameMap[$key][3],
+ 'proportion'=>bcdiv($return_data['today_intake'][$key],$value,2) >= 1?'100':(bcdiv($return_data['today_intake'][$key],$value,2))*100,
+ 'proportion_fp'=>$key == 'kcal'?0:(bcdiv($return_data['suggestion'][$key],$all_yy_data,2))*100,
+ ];
+ }
+ unset($return_data['suggestion']);
+ unset($return_data['today_intake']);
+
+
+ // // 处理各餐卡路里占比
+ // $return_data = $this->calculate_kcal_proportion($return_data);
+ // // 计算营养物质能量占比
+ // $return_data = $this->calculate_energy_proportion($return_data);
+ // // 排序营养元素食物排行榜
+ // $return_data = $this->energy_food_rank($return_data);
+ // // 微量元素处理全天
+ // $return_data = $this->calculate_trace_elements($return_data);
+ // 处理单餐营养占比
+ // foreach ($return_data['list'] as $key => $value) {
+ // $all_yy_data_0 = bcadd($value['nutrients_four'][3]['value'],bcadd($value['nutrients_four'][1]['value'],$value['nutrients_four'][2]['value'],20),2);
+ // foreach ($value['nutrients_four'] as $k => $v) {
+ // if($k != 0){
+ // if($all_yy_data_0 == 0){
+ // $return_data['list'][$key]['nutrients_four'][$k]['proportion'] = 0;
+ // }else{
+ // $return_data['list'][$key]['nutrients_four'][$k]['proportion'] = bcdiv($value['nutrients_four'][$k]['value'],$all_yy_data_0,2) >= 1?'100':(bcdiv($value['nutrients_four'][$k]['value'],$all_yy_data_0,2))*100;
+ // }
+ // }
+ // }
+ // }
+ }
+
+ return $return_data;
+ }
+
+
+
+
+
+}
\ No newline at end of file
diff --git a/application/KitchenScale2/controller/app/Wechat.php b/application/KitchenScale2/controller/app/Wechat.php
new file mode 100644
index 0000000..93e3013
--- /dev/null
+++ b/application/KitchenScale2/controller/app/Wechat.php
@@ -0,0 +1,121 @@
+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);
+ }
+ }
+
+
+ // 注册
+
+
+
+}
\ No newline at end of file
diff --git a/application/KitchenScale2/view/admin/base/pic_index.html b/application/KitchenScale2/view/admin/base/pic_index.html
new file mode 100644
index 0000000..ae123b5
--- /dev/null
+++ b/application/KitchenScale2/view/admin/base/pic_index.html
@@ -0,0 +1,209 @@
+
+
+
+
+ 图片管理
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {volist name="result" id="vo"}
+
+ {/volist}
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/application/KitchenScale2/view/admin/cookbook/add_cookbook.html b/application/KitchenScale2/view/admin/cookbook/add_cookbook.html
new file mode 100644
index 0000000..9480e45
--- /dev/null
+++ b/application/KitchenScale2/view/admin/cookbook/add_cookbook.html
@@ -0,0 +1,420 @@
+
+
+
+
+
+ 菜谱管理
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/application/KitchenScale2/view/admin/cookbook/card_edit.html b/application/KitchenScale2/view/admin/cookbook/card_edit.html
new file mode 100644
index 0000000..d448a5c
--- /dev/null
+++ b/application/KitchenScale2/view/admin/cookbook/card_edit.html
@@ -0,0 +1,232 @@
+
+
+
+
+
+ app版本管理
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/application/KitchenScale2/view/admin/cookbook/index.html b/application/KitchenScale2/view/admin/cookbook/index.html
new file mode 100644
index 0000000..1e7f477
--- /dev/null
+++ b/application/KitchenScale2/view/admin/cookbook/index.html
@@ -0,0 +1,288 @@
+
+
+
+
+ 所有卡片管理
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/application/KitchenScale2/view/admin/index/index.html b/application/KitchenScale2/view/admin/index/index.html
new file mode 100644
index 0000000..2e3e1f9
--- /dev/null
+++ b/application/KitchenScale2/view/admin/index/index.html
@@ -0,0 +1,230 @@
+
+
+
+
+ 后台登录-X-admin2.2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/application/KitchenScale2/view/admin/index/welcome.html b/application/KitchenScale2/view/admin/index/welcome.html
new file mode 100644
index 0000000..f362ddd
--- /dev/null
+++ b/application/KitchenScale2/view/admin/index/welcome.html
@@ -0,0 +1,219 @@
+
+
+
+
+ 欢迎页面-X-admin2.2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/application/KitchenScale2/view/admin/login/login.html b/application/KitchenScale2/view/admin/login/login.html
new file mode 100644
index 0000000..56b9866
--- /dev/null
+++ b/application/KitchenScale2/view/admin/login/login.html
@@ -0,0 +1,77 @@
+
+
+
+
+ 后台登录-X-admin2.2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/application/KitchenScale2/view/app/usercenter/business_cooperation.html b/application/KitchenScale2/view/app/usercenter/business_cooperation.html
new file mode 100644
index 0000000..7b0a490
--- /dev/null
+++ b/application/KitchenScale2/view/app/usercenter/business_cooperation.html
@@ -0,0 +1,398 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 商务合作
+
+
+
+
+
+
+
+
+
+

+
+
商务合作意向登记表
+
+
+
+
+
+
+
+
+
+ 商务合作电话/微信:13590959084
+
+
+
+
提交
+
+
+
+
+
+
\ No newline at end of file
diff --git a/application/NewReedaw/controller/app/Base.php b/application/NewReedaw/controller/app/Base.php
index 4d491a6..b192f9f 100644
--- a/application/NewReedaw/controller/app/Base.php
+++ b/application/NewReedaw/controller/app/Base.php
@@ -593,7 +593,9 @@ class Base extends Controller{
case 'intnum':
// 整数验证 - 必须是整型或纯整数字符串
// 使用 filter_var 同时验证整型和整数字符串
- return filter_var($data, FILTER_VALIDATE_INT) !== false;
+ // 必须是 >0 的整数或字符串整数
+ $filtered = filter_var($data, FILTER_VALIDATE_INT);
+ return $filtered !== false && $filtered > 0;
case 'datetime':
// 日期时间验证 - 保持原有逻辑不变
diff --git a/application/NewReedaw/controller/app/Body.php b/application/NewReedaw/controller/app/Body.php
index eb4f3e1..6510857 100644
--- a/application/NewReedaw/controller/app/Body.php
+++ b/application/NewReedaw/controller/app/Body.php
@@ -2,12 +2,9 @@
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;
+use app\NewReedaw\controller\app\Calculatebody;
class Body extends Base{
@@ -30,6 +27,7 @@ class Body extends Base{
'list'=>[]
];
protected $age_limit = 16;
+ protected $pagesize = 15;
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 = [
@@ -85,7 +83,7 @@ class Body extends Base{
public function body_report(){
// phpinfo();
// die;
- // try {
+ try {
$data = input('post.');
if(!array_key_exists('token', $data) || !array_key_exists('aud_id', $data)){
return $this->msg(10001);
@@ -97,20 +95,243 @@ class Body extends Base{
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);
- // }
+ } 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 manual_record(){
+ try {
+
+ $data = input('post.');
+ if(!array_key_exists('aud_id', $data) || !array_key_exists('time', $data) || !array_key_exists('height', $data) || !array_key_exists('weight', $data) || !array_key_exists('token', $data)){
+ return $this->msg(10001);
+ }
+ unset($data['token']);
+ 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['time'],'datetime')){
+ return $this->msg(10005,'time type error');
+ }
+ $temporary_data = $this->convertHeightAndWeight($data['height'],$data['weight']);
+ if($temporary_data['height_in_cm'] == false){
+ return $this->msg(10005,'身高单位错误');
+ }
+ if($temporary_data['weight_in_kg'] == false){
+ return $this->msg(10005,'体重单位错误');
+ }
+ $data['height'] = $temporary_data['height_in_cm'];
+ $data['weight'] = $temporary_data['weight_in_kg'];
+ if(strlen($data['time']) <= 12){
+ // 时间日期转换,把'Y-m-d'转换成'Y-m-d H:i:s'格式
+ $data['time'] = $this->addCurrentTimeToDateString($data['time']);
+ }
+ // $data['acd_id'] = '2';
+ return $this->set_user_body_data($data,'by_hand_means');
+ } 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 device_record(){
+ try {
+ // 你的业务逻辑
+ $data = input('post.');
+ if(!array_key_exists('aud_id', $data) || !array_key_exists('height', $data) || !array_key_exists('weight', $data) || !array_key_exists('adc', $data) || !array_key_exists('token', $data)){
+ return $this->msg(10001);
+ }
+ 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['adc'],'num')){
+ return $this->msg(10005,'adc type error');
+ }
+ $temporary_data = $this->convertHeightAndWeight($data['height'],$data['weight']);
+ if($temporary_data['height_in_cm'] == false){
+ return $this->msg(10005,'身高单位错误');
+ }
+ if($temporary_data['weight_in_kg'] == false){
+ return $this->msg(10005,'体重单位错误');
+ }
+ // 检测设备传过来的info信息
+ if(array_key_exists('info', $data)){
+ if (!is_array($data['info'])) {
+ return $this->msg(10005,'info参数格式错误');
+ }else{
+ $info_data_arr =['bodyage','fat_r','muscle','kcal','visceral','sfr','water','bone','fatlevlval','protein','bmi'];
+ foreach ($data['info'] as $key => $value) {
+ if (!in_array($key, $info_data_arr)) {
+ return $this->msg(10005,'info参数格式错误-2');
+ }
+ }
+ }
+ }
+ $data['height'] = $temporary_data['height_in_cm'];
+ $data['weight'] = $temporary_data['weight_in_kg'];
+ $data['time'] = date('Y-m-d H:i:s');
+ return $this->set_user_body_data($data,'by_device');
+ } 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 record_list_page(){
+ try {
+ $data = input('post.');
+ if(!array_key_exists('token', $data) || !array_key_exists('aud_id', $data) || !array_key_exists('page', $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');
+ }
+ if(!$this->verify_data_is_ok($data['page'],'intnum')){
+ return $this->msg(10005,'page type error');
+ }
+ return $this->record_list_page_or_group_action($data,'page');
+ } 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 record_list_group(){
+ try {
+ $data = input('post.');
+ if(!array_key_exists('token', $data) || !array_key_exists('aud_id', $data) || !array_key_exists('s_time', $data) || !array_key_exists('e_time', $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');
+ }
+ if(!$this->verify_data_is_ok($data['s_time'],'datetime')){
+ return $this->msg(10005,'page type error');
+ }
+ if(!$this->verify_data_is_ok($data['e_time'],'datetime')){
+ return $this->msg(10005,'page type error');
+ }
+ return $this->record_list_page_or_group_action($data,'group');
+ } 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 detailed_record(){
+ try {
+ $data = input('post.');
+ if(!array_key_exists('token', $data) || !array_key_exists('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['id'],'intnum')){
+ return $this->msg(10005,'id type error');
+ }
+ return $this->get_all_detaile_data_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 del_record(){
+ try {
+ $data = input('post.');
+ if(!array_key_exists('id', $data) || !array_key_exists('token', $data)){
+ return $this->msg(10001);
+ }
+ if(!$this->verify_data_is_ok($data['id'],'intnum')){
+ return $this->msg(10005);
+ }
+ unset($data['token']);
+ $user_data = Db::table($this->body_db_name['body_data'])->where(['id'=>$data['id']])->update(['is_del'=>1]);
+ if($user_data){
+ return $this->msg([]);
+ }else{
+ return $this->msg(10002);
+ }
+ } 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################################################################
@@ -344,7 +565,318 @@ class Body extends Base{
// dump($result_end);
}
+ // 用户身体数据卡片记录
+ public function set_user_body_data($data,$type){
+ // 加 bcadd(,,20)
+ // 减 bcsub(,,20)
+ // 乘 bcmul(,,20)
+ // 除 bcdiv(,,20)
+
+ // 判断头围数据是否存在是否合理
+ if(array_key_exists('head_data', $data)){
+ if(!$this->verify_data_is_ok($data['head_data'],'num')){
+ return $this->msg(10005);
+ }
+ $data['head_circumference'] = $data['head_data'];
+ }else{
+ $data['head_circumference'] = 0;
+ }
+
+ // 查询用户信息
+ $user_data = Db::table($this->body_db_name['juese'])->where(['id'=>$data['aud_id']])->field('birthday,gender,target_weight,initial_weight,initial_date')->find();
+
+ if(!$user_data){
+ return $this->msg(10003);
+ }
+ // 如果最初体重设置为null
+ if($user_data['initial_date'] == null){
+ Db::table($this->body_db_name['juese'])->where(['id'=>$data['aud_id']])->update(['initial_weight'=>$data['weight'],'initial_date'=>$data['time']]);
+ $target_current = $this->base_target_initial_cumulative_weight([
+ 'weight'=>$data['weight'],
+ 'target_weight'=>$user_data['target_weight'],
+ 'initial_weight'=>$data['weight'],
+ 'initial_date'=>$data['time'],
+ ]);
+ }else{
+ $target_current = $this->base_target_initial_cumulative_weight([
+ 'weight'=>$data['weight'],
+ 'target_weight'=>$user_data['target_weight'],
+ 'initial_weight'=>$user_data['initial_weight'],
+ 'initial_date'=>$user_data['initial_date'],
+ ]);
+ }
+ // 设置身高、体重、年龄、性别、阶段称谓、头围、生日、阻抗
+ $result_data['height'] = $data['height'];
+ $result_data['weight'] = $data['weight'];
+ $result_data['age'] = $this->calculate_age($user_data['birthday']);
+ $result_data['gender'] = $user_data['gender'];
+ $result_data['head_circumference'] = $data['head_circumference'];
+ $result_data['birthday'] = $user_data['birthday'];
+ if(array_key_exists('adc', $data)){
+ if($data['adc'] > 0){
+ $result_data['adc'] = $data['adc'];
+ $type = "by_device_adc";
+ }else{
+ $result_data['adc'] = 550;
+ $type = "by_device";
+ }
+ }
+ $calculate_body_formula = new Calculatebody();
+
+ // 计算身体数据
+ $get_body_value = $calculate_body_formula->calculate_body_data_result($result_data);
+
+ if($get_body_value === false){
+ return $this->msg(10005);
+ }
+
+ // 如果年纪小于三岁,处理头围数据star
+ $standardlist = [];
+ if($result_data['age'] < 3){
+ if(array_key_exists('standardlist',$get_body_value)){
+ $standardlist = $get_body_value['standardlist'];
+ foreach ($standardlist as $key => $value) {
+ if($value['name'] == 'head' && count($value['list'] ) > 0){
+ $standardlist = $value;
+ }
+ }
+ $standardlist['list2'] = [];
+ foreach ($standardlist['list'] as $key => $value) {
+ array_push($standardlist['list2'],[
+ 'min_val'=>$value['minvalue'],
+ 'max_val'=>$value['maxvalue'],
+ 'text'=>$value['text'],
+ 'color'=>$value['color']
+ ]);
+ }
+ unset($standardlist['list']);
+ unset($get_body_value['standardlist']);
+ }
+ }else{
+ if(array_key_exists('standardlist',$get_body_value)){
+ unset($get_body_value['standardlist']);
+ }
+ }
+ // 如果年纪小于三岁,处理头围数据end
+ $get_body_value['gender'] = $user_data['gender'];
+ $get_body_value['birthday'] = $user_data['birthday'];
+ // 添加身高、体重、bmi、头围(如果有)的标尺标准
+ $get_body_value = $this->hwb_standard($get_body_value);
+
+ $enumeration_data = [
+ 'fat_r'=>'脂肪率',
+ 'muscle'=>'肌肉率',
+ 'kcal'=>'基础代谢',
+ 'visceral'=>'内脏指数',
+ 'sfr'=>'皮下脂肪',
+ 'water'=>'水分',
+ 'bone'=>'骨重',
+ 'protein'=>'蛋白率',
+ 'bodyage'=>'身体年龄'
+ ];
+
+ // return $this->msg($get_body_value);
+ // 根据秤传过来的数据,去处理要存的结果
+ if(array_key_exists('info', $data)){
+
+
+ foreach ($data['info'] as $key => $value) {
+ if($key == 'bmi'){
+ if($value > 0){
+ $get_body_value['BMI'] = $value;
+ $get_body_value['BMI2'] = explode(',',$get_body_value['BMI2']);
+ $get_body_value['BMI2'][0] = $value;
+ $get_body_value['BMI2'] = implode(',',$get_body_value['BMI2']);
+ }
+ }else if($key == 'bodyage'){
+ $get_body_value[$enumeration_data[$key]] = $value;
+ }else if($key == 'fatlevlval'){
+ continue;
+ }else{
+ if($value > 0){
+ $get_body_value[$enumeration_data[$key]][0] = $value;
+ }
+ }
+ }
+ }
+
+ $set_data = [
+ 'acd_id'=>2,
+ 'aud_id'=>$data['aud_id'],
+ 'record_time'=>array_key_exists('time', $data)?$data['time']:date('Y-m-d H:i:s'),
+ 'create_time'=>date('Y-m-d H:i:s'),
+ 'last_update_time'=>date('Y-m-d H:i:s'),
+ 'age'=>$get_body_value['age'],
+ 'height'=>$get_body_value['身高2'],
+ 'height_val'=>$get_body_value['身高'],
+ 'weight'=>$get_body_value['体重2'],
+ 'weight_val'=>$get_body_value['体重'],
+ 'bmi'=>$get_body_value['BMI2'],
+ 'bmi_val'=>$get_body_value['BMI'],
+ 'score'=>$get_body_value['身体得分'],
+ 'fat_r'=> implode(',',$get_body_value['脂肪率']),
+ 'fat_w'=>implode(',',$get_body_value['脂肪量']),
+ 'muscle'=>implode(',',$get_body_value['肌肉率']),
+ 'muscleval'=>implode(',',$get_body_value['肌肉量']),
+ 'water'=>implode(',',$get_body_value['水分']),
+ 'proteinval'=>implode(',',$get_body_value['蛋白量']),
+ 'bone'=>implode(',',$get_body_value['骨重']),
+ 'protein'=>implode(',',$get_body_value['蛋白率']),
+ 'kcal'=>implode(',',$get_body_value['基础代谢']),
+ 'visceral'=>implode(',',$get_body_value['内脏指数']),
+ 'sfr'=>implode(',',$get_body_value['皮下脂肪']),
+ 'body_level'=>$get_body_value['肥胖等级'],
+ 'body_type'=>$get_body_value['身体类型'],
+ 'body_age'=>$get_body_value['身体年龄'],
+ 'record_type' => $type,
+ 'head_circumference' => $result_data['age'] < 3?json_encode($standardlist):"",
+ ];
+ if(strlen($set_data['record_time']) <= 12){
+ // 时间日期转换,把'Y-m-d'转换成'Y-m-d H:i:s'格式
+ $set_data['record_time'] = $this->addCurrentTimeToDateString($set_data['record_time']);
+ }
+
+ // 启动事务
+ Db::startTrans();
+ try{
+ $set_user_data = Db::table($this->body_db_name['body_data'])->insert($set_data);
+ $update_arr = [
+ 'height'=>$get_body_value['身高'],
+ 'weight'=>$get_body_value['体重']
+ ];
+ if($data['head_circumference']>0){
+ $update_arr['head_data'] = $data['head_circumference'];
+ }
+ $update_user_data = Db::table($this->body_db_name['juese'])->where(['id'=>$data['aud_id']])->update($update_arr);
+ // 提交事务
+ Db::commit();
+ return $this->msg([
+ 'acd_id'=>2,
+ 'height'=>$get_body_value['身高'].',CM',
+ 'weight'=>$get_body_value['体重'].',公斤',
+ 'bmi'=>$get_body_value['BMI'],
+ 'target_current'=>$target_current,
+ ]);
+ } catch (\Exception $e) {
+ // 回滚事务
+ Db::rollback();
+ return $this->msg(10002);
+ }
+ }
+ public function record_list_page_or_group_action($data,$type){
+ $return_result = [];
+
+ if($type == 'group'){
+ $data['s_time'] = $data['s_time'].' 00:00:00';
+ $data['e_time'] = $data['e_time'].' 23:59:59';
+ $result = Db::query("
+ select
+ id,
+ CONVERT(varchar(10), record_time, 120) AS r_t,
+ CONVERT(varchar(19), record_time, 120) AS record_time,
+ height_val as v1,
+ weight_val as v2,
+ bmi_val as v3
+ from ".$this->body_db_name['body_data']."
+ where aud_id='".$data['aud_id']."'
+ and record_time between '".$data['s_time']."' and '".$data['e_time']."'
+ and is_del = 0
+ order by record_time desc");
+ foreach ($result as $key => $value) {
+ array_push($return_result, [
+ 'id'=>$value['id'],
+ 'v1'=>floatval(sprintf("%.2f", $value['v1'])),
+ 'v2'=>floatval(sprintf("%.2f", $value['v2'])),
+ 'v3'=>floatval(sprintf("%.2f", $value['v3'])),
+ 'v1_name'=>'身高',
+ 'v2_name'=>'体重',
+ 'v3_name'=>'BMI',
+ // 'r_t'=>str_replace('-', '/', $value['r_t'])
+ 'r_t'=>$value['r_t']
+ ]);
+ }
+ }else{
+ $result = Db::table($this->body_db_name['body_data'])->where(['aud_id'=>$data['aud_id'],'is_del'=>0])->field("id,record_time,REPLACE(record_time, '-', '-') AS b_time,height_val,weight_val,bmi_val")->order('record_time desc')->page($data['page'],$this->pagesize)->select();
+ $return_result['totalrows'] = Db::table($this->body_db_name['body_data'])->where(['aud_id'=>$data['aud_id']])->count();
+ $return_result['rows'] = [];
+ $return_result['pageno'] = $data['page'];
+ $return_result['pagesize'] = $this->pagesize;
+ $return_result['totalpage'] = ceil($return_result['totalrows']/$this->pagesize);
+ foreach ($result as $key => $value) {
+ array_push($return_result['rows'],[
+ 'id'=>$value['id'],
+ 'v1'=>floatval(sprintf("%.2f", $value['height_val'])),
+ 'v2'=>floatval(sprintf("%.2f", $value['weight_val'])),
+ 'v3'=>floatval(sprintf("%.2f", $value['bmi_val'])),
+ 'v1_name'=>'身高',
+ 'v2_name'=>'体重',
+ 'v3_name'=>'BMI',
+ 'record_time'=>$value['b_time'],
+ ]);
+ }
+ }
+ return $this->msg($return_result);
+ }
+ // 获取详细历史数据信息
+ public function get_all_detaile_data_action($data){
+ // 加 bcadd(,,20)
+ // 减 bcsub(,,20)
+ // 乘 bcmul(,,20)
+ // 除 bcdiv(,,20)
+ // 设置排除在外的数据类型start
+ $exclude_data_arr = ['height','weight','age','bmi'];
+ // 设置排除在外的数据类型end
+ $result = Db::table($this->body_db_name['body_data'])->where(['id'=>$data['id']])->find();
+ $for_data_arr = ['height'=>['身高','cm'],'weight'=>['体重','kg'],'age'=>['年龄','岁'],'bmi'=>['BMI',''],'head'=>['头围',''],'fat_w'=>['脂肪量','kg'],'fat_r'=>['脂肪率','%'],'muscleval'=>['肌肉量','kg'],'muscle'=>['肌肉率','%'],'proteinval'=>['蛋白量','kg'],'protein'=>['蛋白率','%'],'water'=>['水分',''],'bone'=>['骨重','kg'],'visceral'=>['内脏指数',''],'sfr'=>['皮下脂肪','%'],'kcal'=>['基础代谢','kcal'],'un_fat_w_weight'=>['去脂体重','kg'],'body_age'=>['体龄',''],'body_level'=>['肥胖等级',''],'body_type'=>['体型','']];
+ if($result){
+ $result_data = [];
+ foreach ($for_data_arr as $key => $value) {
+ $temporary_arr['key_name'] = $key;
+ $temporary_arr['name'] = $value[0];
+ // 身体数据处理,如果没有阻抗,则只显示四项$exclude_data_arr
+ if($result['record_type'] != 'by_device_adc'){
+ if(!in_array($key, $exclude_data_arr)){
+ continue;
+ }else{
+ $temporary_arr['value'] = explode(',',$result[$key])[0];
+ }
+ }else{
+
+ if($key == 'un_fat_w_weight'){
+ $temporary_arr['value'] = bcsub(explode(',',$result['weight'])[0],explode(',',$result['fat_w'])[0],2);
+ }else{
+ if(array_key_exists($key,$result)){
+ $temporary_arr['value'] = explode(',',$result[$key])[0];
+ }
+
+ }
+ }
+ $temporary_arr['unit'] = $value[1];
+ array_push($result_data,$temporary_arr);
+ }
+ //
+ // 添加头围详细start
+ if($result['head_circumference'] != null){
+ array_unshift($result_data,[
+ 'key_name'=>'head_circumference',
+ 'name'=>'头围',
+ 'value'=>json_decode($result['head_circumference'],true)['value'] == 0?"0":json_decode($result['head_circumference'],true)['value'],
+ 'unit'=>'cm',
+ ]);
+ }
+ // 添加头围详细end
+ return $this->msg($result_data);
+ }else{
+ return $this->msg(10004);
+ }
+
+ }
+
+
+
+ ################################################################内部调用################################################################
+ ################################################################内部调用################################################################
public function processing_return_data_new($data){
$result_end_data = [];
$month_num = $this->calculateAgeInMonthsWithPrecision($data['birthday']);
@@ -655,9 +1187,86 @@ class Body extends Base{
}
return $return_data;
}
- // public function body_report_action_detailed($data){
- // }
+ // 添加身高体重bmi的标准
+ public function hwb_standard($data){
+ $linshi_data = [];
+ $month_num = $this->calculateAgeInMonthsWithPrecision($data['birthday']);
+ $gender_val = $data['gender'];
+ if($data['age'] < $this->age_limit){
+ foreach ($data as $key => $value) {
+ if($key =='身高'){
+ $linshi_data['身高'] = $this->bhw_list['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){
+ $linshi_data['身高'][0]['max_val'] = $bhw_date[0]['f2sd'];
+ $linshi_data['身高'][1]['min_val'] = $bhw_date[0]['f2sd'];
+ $linshi_data['身高'][1]['max_val'] = $bhw_date[0]['f1sd'];
+ $linshi_data['身高'][2]['min_val'] = $bhw_date[0]['f1sd'];
+ $linshi_data['身高'][2]['max_val'] = $bhw_date[0]['z1sd'];
+ $linshi_data['身高'][3]['min_val'] = $bhw_date[0]['z1sd'];
+ $linshi_data['身高'][3]['max_val'] = $bhw_date[0]['z2sd'];
+ $linshi_data['身高'][4]['min_val'] = $bhw_date[0]['z2sd'];
+ $linshi_data['身高'][4]['max_val'] = $bhw_date[0]['z3sd'];
+ }
+
+ }else if($key =='体重'){
+ $linshi_data['体重'] = $this->bhw_list['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){
+ $linshi_data['体重'][0]['max_val'] = $bhw_date[0]['f2sd'];
+ $linshi_data['体重'][1]['min_val'] = $bhw_date[0]['f2sd'];
+ $linshi_data['体重'][1]['max_val'] = $bhw_date[0]['f1sd'];
+ $linshi_data['体重'][2]['min_val'] = $bhw_date[0]['f1sd'];
+ $linshi_data['体重'][2]['max_val'] = $bhw_date[0]['z1sd'];
+ $linshi_data['体重'][3]['min_val'] = $bhw_date[0]['z1sd'];
+ $linshi_data['体重'][3]['max_val'] = $bhw_date[0]['z2sd'];
+ $linshi_data['体重'][4]['min_val'] = $bhw_date[0]['z2sd'];
+ $linshi_data['体重'][4]['max_val'] = $bhw_date[0]['z3sd'];
+ }
+ }else if($key =='BMI'){
+ $linshi_data['BMI'] = $this->bhw_list['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){
+ $linshi_data['BMI'][0]['max_val'] = $bhw_date[0]['f1sd'];
+ $linshi_data['BMI'][1]['min_val'] = $bhw_date[0]['f1sd'];
+ $linshi_data['BMI'][1]['max_val'] = $bhw_date[0]['z1sd'];
+ $linshi_data['BMI'][2]['min_val'] = $bhw_date[0]['z1sd'];
+ $linshi_data['BMI'][2]['max_val'] = $bhw_date[0]['z2sd'];
+ $linshi_data['BMI'][3]['min_val'] = $bhw_date[0]['z2sd'];
+ }
+ }
+ }
+ foreach ($linshi_data as $key => $value) {
+ foreach ($value as $k => $v) {
+ if($data[$key] >= $v['min_val'] && $data[$key] < $v['max_val']){
+ // 如果落在区间内
+ $data[$key.'2'] = $data[$key].','.$v['text'].','.$v['color'];
+ break;
+ }
+ }
+ // 如果$key.'2'没有被设置
+ if(!array_key_exists($key.'2', $data)){
+ if($data[$key] < $value[0]['min_val']){
+ // 如果小于最小值
+ $data[$key.'2'] = $data[$key].','.$value[0]['text'].','.$value[0]['color'];
+ }else if($data[$key] >= $value[count($value)-1]['max_val']){
+ // 如果大于最大值
+ $data[$key.'2'] = $data[$key].','.$value[count($value)-1]['text'].','.$value[count($value)-1]['color'];
+ }
+ }
+ }
+ // die;
+ }else{
+ $data['身高2'] = $data['身高'].',无,无';
+ $data['体重2'] = $data['体重'].',无,无';
+ $data['BMI2'] = $data['BMI'].',无,无';
+ }
+ return $data;
+ }
+
+
diff --git a/application/NewReedaw/controller/app/Calculatebody.php b/application/NewReedaw/controller/app/Calculatebody.php
new file mode 100644
index 0000000..4288274
--- /dev/null
+++ b/application/NewReedaw/controller/app/Calculatebody.php
@@ -0,0 +1,641 @@
+52.5,'height'=>165,'age'=>30,'gender'=>1]){
+ $data['gender'] = $data['gender'] == 0 ? 1 : $data['gender'];
+
+ $data['adc'] = array_key_exists('adc', $data)?$data['adc']:$this->default_adc;
+ // 加 bcadd(,,20)
+ // 减 bcsub(,,20)
+ // 乘 bcmul(,,20)
+ // 除 bcdiv(,,20)
+
+ // 青测自己写的计算start
+ // $result = $this->calculate_body_data($data['height'],$data['weight'],$data['age'],$data['gender'],$data['adc']);
+ // // $result['fat_w'] = $result['fat_r'] / 100 * $data['weight'];
+ // $result['fat_w'] = bcmul(bcdiv($result['fat_r'],'100',20),$data['weight'],2);
+ // // $result['proteinval'] = $result['protein'] / 100 * $data['weight'];
+ // $result['proteinval'] = bcmul(bcdiv($result['protein'],'100',20),$data['weight'],2);
+ // //肌肉量=体重-脂肪量-骨量
+ // // $result['muscleval'] = $result['weight'] - $result['fat_w'] - $result['bone'];
+ // $result['muscleval'] = bcsub(bcsub($result['weight'],$result['fat_w'],20),$result['bone'],2);
+ // // $result['muscle'] = $result['muscleval'] / $data['weight'] * 100.0;
+ // $result['muscle'] = bcmul(bcdiv($result['muscleval'],$data['weight'],20),'100.0',2);
+ // // 水份=肌肉量-蛋白量
+ // // $result['water'] = $result['muscleval'] - $result['proteinval'];
+ // $result['water'] = bcsub($result['muscleval'],$result['proteinval'],2);
+ // // $result['lbm'] = (1 - $result['fat_r'] / 100) * $data['weight'];
+ // $result['lbm'] = bcmul(bcsub('1',bcdiv($result['fat_r'],'100',20),20),$data['weight'],2);
+ // 青测自己写的计算end
+
+ // 使用接口调用之前的进行计算start
+ $url = 'https://klcz.pcxbc.com/open-api/calc/healthcalc/bodyfat3';
+ if($data['age'] < '3'){
+ $temporary_parameter = [
+ 'weight'=>$data['weight'],
+ 'height'=>$data['height'],
+ 'age'=>round($data['age']),//四舍五入取整
+ 'adc'=>round($data['adc']),//四舍五入取整
+ 'gender'=>$data['gender'],
+ 'head'=>$data['head_circumference'],
+ 'hasStandardList'=>true,
+ 'birthDay'=>$data['birthday'],
+ ];
+ }else{
+ $temporary_parameter = [
+ 'weight'=>$data['weight'],
+ 'height'=>$data['height'],
+ 'age'=>round($data['age']),//四舍五入取整
+ 'adc'=>round($data['adc']),//四舍五入取整
+ 'gender'=>$data['gender'],
+ ];
+ }
+ $request_result = $this->postRequest($url,$temporary_parameter);
+ if($request_result['code'] != 0){
+ return false;
+ }
+
+ $result['weight'] = $request_result['data']['weight'];
+ $result['height'] = $request_result['data']['height'];
+ $result['bmi'] = $request_result['data']['bmi'];
+ $result['age'] = $request_result['data']['age'];
+ $result['cmi'] = $request_result['data']['cmi'];
+ $result['fat_w'] = $request_result['data']['bfrval'];
+ $result['fat_r'] = $request_result['data']['bfr'];
+ $result['muscleval'] = $request_result['data']['romval'];
+ $result['muscle'] = $request_result['data']['rom'];
+ $result['water'] = $request_result['data']['vwc'];
+ $result['proteinval'] = $request_result['data']['ppval'];
+ $result['protein'] = $request_result['data']['pp'];
+ $result['bone'] = $request_result['data']['bm'];
+ $result['kcal'] = $request_result['data']['bmr'];
+ $result['visceral'] = $request_result['data']['uvi'];
+ $result['sfr'] = $request_result['data']['sfr'];
+ $result['standard_level'] = $request_result['data']['fatlevelname'];
+ $result['bodyage'] = $request_result['data']['bodyage'];
+ $result['lbm'] = $request_result['data']['lbm'];
+ $result['body'] = $request_result['data']['body'];
+ // 使用接口调用之前的进行计算end
+
+ $return_data['standardlist'] = $request_result['data']['standardlist'];
+ $return_data['体重'] = $data['weight'];
+ $return_data['身高'] = $data['height'];
+ $return_data['BMI'] = $result['bmi'];
+ $return_data['age'] = $result['age'];
+
+ // 身体得分修改start
+ // if($result['bmi']<21.6){
+ // $return_data['身体得分'] = bcmul(bcdiv($result['bmi'],'21.6',20),'100',0);
+ // }else{
+ // $return_data['身体得分'] = bcmul(bcdiv('21.6',$result['bmi'],20),'100',0);
+ // }
+ $return_data['身体得分'] = $result['cmi'];
+ // 身体得分修改end
+
+ $return_data['脂肪量'][0] = $result['fat_w'];
+ $return_data['脂肪率'][0] = $result['fat_r'];
+ if(
+ ($data['gender']==1 && $data['age']<30 && $result['fat_r']<10) ||
+ ($data['gender']==1 && $data['age']>=30 && $result['fat_r']<11) ||
+ ($data['gender']==2 && $data['age']<30 && $result['fat_r']<20) ||
+ ($data['gender']==2 && $data['age']>=30 && $result['fat_r']<21)){
+ $return_data['脂肪率'][1] = '偏低';
+ $return_data['脂肪量'][1] = '偏低';
+ }else if(
+ ($data['gender']==1 && $data['age']<30 && $result['fat_r']>=10 && $result['fat_r']<21) ||
+ ($data['gender']==1 && $data['age']>=30 && $result['fat_r']>=11 && $result['fat_r']<22) ||
+ ($data['gender']==2 && $data['age']<30 && $result['fat_r']>=20 && $result['fat_r']<31) ||
+ ($data['gender']==2 && $data['age']>=30 && $result['fat_r']>=21 && $result['fat_r']<32)){
+ $return_data['脂肪率'][1] = '标准';
+ $return_data['脂肪量'][1] = '标准';
+ }else if(
+ ($data['gender']==1 && $data['age']<30 && $result['fat_r']>=21 && $result['fat_r']<26) ||
+ ($data['gender']==1 && $data['age']>=30 && $result['fat_r']>=22 && $result['fat_r']<27) ||
+ ($data['gender']==2 && $data['age']<30 && $result['fat_r']>=31 && $result['fat_r']<38) ||
+ ($data['gender']==2 && $data['age']>=30 && $result['fat_r']>=32 && $result['fat_r']<39)){
+ $return_data['脂肪率'][1] = '偏高';
+ $return_data['脂肪量'][1] = '偏高';
+ }else if(
+ ($data['gender']==1 && $data['age']<30 && $result['fat_r']>=26) ||
+ ($data['gender']==1 && $data['age']>=30 && $result['fat_r']>=27) ||
+ ($data['gender']==2 && $data['age']<30 && $result['fat_r']<38) ||
+ ($data['gender']==2 && $data['age']>=30 && $result['fat_r']<39)){
+ $return_data['脂肪率'][1] = '高';
+ $return_data['脂肪量'][1] = '高';
+ }else{
+ $return_data['脂肪率'][1] = '异常';
+ $return_data['脂肪量'][1] = '异常';
+ }
+
+ $return_data['肌肉量'][0] = $result['muscleval'];
+ $return_data['肌肉率'][0] = $result['muscle'];
+ if(
+ ($data['gender']==1 && $result['muscle']<40) ||
+ ($data['gender']==2 && $result['muscle']<30)){
+ $return_data['肌肉量'][1] = '不足';
+ $return_data['肌肉率'][1] = '不足';
+ }else if(
+ ($data['gender']==1 && $result['muscle']>=40 && $result['muscle']<60) ||
+ ($data['gender']==2 && $result['muscle']>=30 && $result['muscle']<50)){
+ $return_data['肌肉量'][1] = '标准';
+ $return_data['肌肉率'][1] = '标准';
+ }else if(
+ ($data['gender']==1 && $result['muscle']>=60) ||
+ ($data['gender']==2 && $result['muscle']>=50)){
+ $return_data['肌肉量'][1] = '优';
+ $return_data['肌肉率'][1] = '优';
+ }else{
+ $return_data['肌肉量'][1] = '异常';
+ $return_data['肌肉率'][1] = '异常';
+ }
+
+ $return_data['水分'][0] = $result['water'];
+ if(
+ ($data['gender']==1 && $result['water']<55) ||
+ ($data['gender']==2 && $result['water']<45)){
+ $return_data['水分'][1] = '不足';
+ }else if(
+ ($data['gender']==1 && $result['water']>=55 && $result['water']<65) ||
+ ($data['gender']==2 && $result['water']>=45 && $result['water']<60)){
+ $return_data['水分'][1] = '标准';
+ }else if(
+ ($data['gender']==1 && $result['water']>65) ||
+ ($data['gender']==2 && $result['water']>60)){
+ $return_data['水分'][1] = '优';
+ }else{
+ $return_data['水分'][1] = '异常';
+ }
+
+ $return_data['蛋白量'][0] = $result['proteinval'];
+ $return_data['蛋白率'][0] = $result['protein'];
+ if(
+ ($data['gender']==1 && $result['protein']<16) ||
+ ($data['gender']==2 && $result['protein']<14)){
+ $return_data['蛋白量'][1] = '不足';
+ $return_data['蛋白率'][1] = '不足';
+ }else if(
+ ($data['gender']==1 && $result['protein']>=16 && $result['protein']<18) ||
+ ($data['gender']==2 && $result['protein']>=14 && $result['protein']<16)){
+ $return_data['蛋白量'][1] = '标准';
+ $return_data['蛋白率'][1] = '标准';
+ }else if(
+ ($data['gender']==1 && $result['protein']>18) ||
+ ($data['gender']==2 && $result['protein']>16)){
+ $return_data['蛋白量'][1] = '优';
+ $return_data['蛋白率'][1] = '优';
+ }else{
+ $return_data['蛋白量'][1] = '异常';
+ $return_data['蛋白率'][1] = '异常';
+ }
+
+ $return_data['骨重'][0] = $result['bone'];
+ if(
+ ($data['gender']==1 && $data['weight']<60 && $result['bone']<2.4) ||
+ ($data['gender']==1 && $data['weight']>=60 && $data['weight']<75 && $result['bone']<2.8) ||
+ ($data['gender']==1 && $data['weight']>=75 && $result['bone']<3.1) ||
+ ($data['gender']==2 && $data['weight']<45 && $result['bone']<1.7) ||
+ ($data['gender']==2 && $data['weight']>=45 && $data['weight']<60 && $result['bone']<2.1) ||
+ ($data['gender']==2 && $data['weight']>=60 && $result['bone']<2.4)){
+ $return_data['骨重'][1] = '不足';
+ }else if(
+ ($data['gender']==1 && $data['weight']<60 && $result['bone']>=2.4 && $result['bone']<=2.6) ||
+ ($data['gender']==1 && $data['weight']>=60 && $data['weight']<75 && $result['bone']>=2.8 && $result['bone']<=3) ||
+ ($data['gender']==1 && $data['weight']>=75 && $result['bone']>=3.1 && $result['bone']<=3.3) ||
+ ($data['gender']==2 && $data['weight']<45 && $result['bone']>=1.7 && $result['bone']<=1.9) ||
+ ($data['gender']==2 && $data['weight']>=45 && $data['weight']<60 && $result['bone']>=2.1 && $result['bone']<=2.3) ||
+ ($data['gender']==2 && $data['weight']>=60 && $result['bone']>=2.4 && $result['bone']<=2.6)){
+ $return_data['骨重'][1] = '标准';
+ }else if(
+ ($data['gender']==1 && $data['weight']<60 && $result['bone']>2.6) ||
+ ($data['gender']==1 && $data['weight']>=60 && $data['weight']<75 && $result['bone']>3) ||
+ ($data['gender']==1 && $data['weight']>=75 && $result['bone']<3.3) ||
+ ($data['gender']==2 && $data['weight']<45 && $result['bone']>1.9) ||
+ ($data['gender']==2 && $data['weight']>=45 && $data['weight']<60 && $result['bone']>2.3) ||
+ ($data['gender']==2 && $data['weight']>=60 && $result['bone']>2.6)){
+ $return_data['骨重'][1] = '优';
+ }else{
+ $return_data['骨重'][1] = '异常';
+ }
+
+ $return_data['基础代谢'][0] = $result['kcal'];
+ if(
+ ($data['gender']==1 && $data['age']>0 && $data['age']<3 && (60.9*$data['weight']-54)>$result['kcal']) ||
+ ($data['gender']==1 && $data['age']>=3 && $data['age']<10 && (22.7*$data['weight']+495)>$result['kcal']) ||
+ ($data['gender']==1 && $data['age']>=10 && $data['age']<18 && (17.5*$data['weight']+651)>$result['kcal']) ||
+ ($data['gender']==1 && $data['age']>=18 && $data['age']<30 && (15.3*$data['weight']+679)>$result['kcal']) ||
+ ($data['gender']==1 && $data['age']>=30 && (11.6*$data['weight']+879)>$result['kcal']) ||
+ ($data['gender']==2 && $data['age']>0 && $data['age']<3 && (61*$data['weight']-51)>$result['kcal']) ||
+ ($data['gender']==2 && $data['age']>=3 && $data['age']<10 && (22.5*$data['weight']+499)>$result['kcal']) ||
+ ($data['gender']==2 && $data['age']>=10 && $data['age']<18 && (12.2*$data['weight']+746)>$result['kcal']) ||
+ ($data['gender']==2 && $data['age']>=18 && $data['age']<30 && (14.7*$data['weight']+496)>$result['kcal']) ||
+ ($data['gender']==2 && $data['age']>=30 && (8.7*$data['weight']+820)>$result['kcal'])){
+ $return_data['基础代谢'][1] = '偏低';
+ }else if(
+ ($data['gender']==1 && $data['age']>0 && $data['age']<3 && (60.9*$data['weight']-54)<=$result['kcal']) ||
+ ($data['gender']==1 && $data['age']>=3 && $data['age']<10 && (22.7*$data['weight']+495)<=$result['kcal']) ||
+ ($data['gender']==1 && $data['age']>=10 && $data['age']<18 && (17.5*$data['weight']+651)<=$result['kcal']) ||
+ ($data['gender']==1 && $data['age']>=18 && $data['age']<30 && (15.3*$data['weight']+679)<=$result['kcal']) ||
+ ($data['gender']==1 && $data['age']>=30 && (11.6*$data['weight']+879)<=$result['kcal']) ||
+ ($data['gender']==2 && $data['age']>0 && $data['age']<3 && (61*$data['weight']-51)<=$result['kcal']) ||
+ ($data['gender']==2 && $data['age']>=3 && $data['age']<10 && (22.5*$data['weight']+499)<=$result['kcal']) ||
+ ($data['gender']==2 && $data['age']>=10 && $data['age']<18 && (12.2*$data['weight']+746)<=$result['kcal']) ||
+ ($data['gender']==2 && $data['age']>=18 && $data['age']<30 && (14.7*$data['weight']+496)<=$result['kcal']) ||
+ ($data['gender']==2 && $data['age']>=30 && (8.7*$data['weight']+820)<=$result['kcal'])){
+ $return_data['基础代谢'][1] = '优';
+ }else{
+ $return_data['基础代谢'][1] = '异常';
+ }
+
+ $return_data['内脏指数'][0] = $result['visceral'];
+ if($result['visceral']<9){
+ $return_data['内脏指数'][1] = '标准';
+ }else if($result['visceral']>=9 && $result['visceral']<14){
+ $return_data['内脏指数'][1] = '警惕';
+ }else if($result['visceral']>=14){
+ $return_data['内脏指数'][1] = '危险';
+ }else{
+ $return_data['内脏指数'][1] = '异常';
+ }
+
+ $return_data['皮下脂肪'][0] = $result['sfr'];
+ if(
+ ($data['gender']==1 && $result['sfr']<7) ||
+ ($data['gender']==2 && $result['sfr']<11)){
+ $return_data['皮下脂肪'][1] = '不足';
+ }else if(
+ ($data['gender']==1 && $result['sfr']>=7 && $result['sfr']<15) ||
+ ($data['gender']==2 && $result['sfr']>=11 && $result['sfr']<17)){
+ $return_data['皮下脂肪'][1] = '标准';
+ }else if(
+ ($data['gender']==1 && $result['sfr']>=15) ||
+ ($data['gender']==2 && $result['sfr']>=17)){
+ $return_data['皮下脂肪'][1] = '偏高';
+ }else{
+ $return_data['皮下脂肪'][1] = '异常';
+ }
+ // 脂肪率:偏低 标准 偏高 高
+ // 肌肉率:不足 标准 优
+
+ // 肥胖等级修改start
+ // // if($data['age']>=16){
+ // if($result['standard_level']<-0.2){
+ // $return_data['肥胖等级'] = '体重不足';
+ // }else if($result['standard_level']>=-0.2 && $result['standard_level']<-0.1){
+ // $return_data['肥胖等级'] = '偏瘦';
+ // }else if($result['standard_level']>=-0.1 && $result['standard_level']<=0.1){
+ // $return_data['肥胖等级'] = '标准';
+ // }else if($result['standard_level']>0.1 && $result['standard_level']<=0.2){
+ // $return_data['肥胖等级'] = '偏重';
+ // }else if($result['standard_level']>0.2){
+ // $return_data['肥胖等级'] = '超重';
+ // }else{
+ // $return_data['肥胖等级'] = '暂无数据';
+ // }
+ // // }else{
+ // // $return_data['肥胖等级'] = '儿童';
+ // // }
+ $return_data['肥胖等级'] = $result['standard_level'];
+ // 肥胖等级修改end
+
+
+ // 身体类型修改start
+ // // if($data['age']>=16){
+ // if(($return_data['脂肪率'][1] == '高' || $return_data['脂肪率'][1] == '偏高') && $return_data['肌肉率'][1] == '不足'){
+ // $return_data['身体类型'] = '隐形肥胖';
+ // }else if(($return_data['脂肪率'][1] == '高' || $return_data['脂肪率'][1] == '偏高') && $return_data['肌肉率'][1] == '标准'){
+ // $return_data['身体类型'] = '偏胖';
+ // }else if(($return_data['脂肪率'][1] == '高' || $return_data['脂肪率'][1] == '偏高') && $return_data['肌肉率'][1] == '优'){
+ // $return_data['身体类型'] = '结实型偏胖';
+ // }else if($return_data['脂肪率'][1] == '标准' && $return_data['肌肉率'][1] == '不足'){
+ // $return_data['身体类型'] = '缺乏肌肉型';
+ // }else if($return_data['脂肪率'][1] == '标准' && $return_data['肌肉率'][1] == '标准'){
+ // $return_data['身体类型'] = '标准型';
+ // }else if($return_data['脂肪率'][1] == '标准' && $return_data['肌肉率'][1] == '优'){
+ // $return_data['身体类型'] = '标准肌肉型';
+ // }else if($return_data['脂肪率'][1] == '偏低' && $return_data['肌肉率'][1] == '不足'){
+ // $return_data['身体类型'] = '偏瘦';
+ // }else if($return_data['脂肪率'][1] == '偏低' && $return_data['肌肉率'][1] == '标准'){
+ // $return_data['身体类型'] = '偏瘦肌肉型';
+ // }else if($return_data['脂肪率'][1] == '偏低' && $return_data['肌肉率'][1] == '优'){
+ // $return_data['身体类型'] = '健美肌肉型';
+ // }else{
+ // $return_data['身体类型'] = '暂无数据';
+ // }
+ // // }else{
+ // // $return_data['身体类型'] = '儿童';
+ // // }
+ $return_data['身体类型'] = $result['body'];
+ // 身体类型修改end
+
+ $return_data['身体年龄'] = $result['bodyage'];
+
+ // $result_end['fat_r'] = $result['fat_r'];
+ // $result_end['muscle'] = $result['muscle'];
+ // $result_end['water'] = $result['water'];
+ // $result_end['bone'] = $result['bone'];
+ // $result_end['kcal'] = $result['kcal'];
+ // $result_end['fat_w'] = $result['fat_w'];
+ // $result_end['visceral'] = $result['visceral'];
+ // $result_end['protein'] = $result['protein'];
+ // $result_end['bodyage'] = $result['bodyage'];
+ // $result_end['bmi'] = $result['bmi'];
+ // // $result_end['cmi'] = $result['cmi'];
+ // $result_end['sfr'] = $result['sfr'];
+ // // $result_end['sfrval'] = $result['sfrval'];
+ // $result_end['skeletalmuscle'] = $result['skeletalmuscle'];
+ // $result_end['muscleval'] = $result['muscleval'];
+ // $result_end['proteinval'] = $result['proteinval'];
+ // $result_end['lbm'] = $result['lbm'];
+ // $result_end['weight'] = $result['weight'];
+ // $result_end['height'] = $result['height'];
+ return $return_data;
+ }
+
+ // 加 bcadd(,,20)
+ // 减 bcsub(,,20)
+ // 乘 bcmul(,,20)
+ // 除 bcdiv(,,20)
+
+ // 计算身体数据,BMI、脂肪率、脂肪量、肌肉率、肌肉量....
+ public function calculate_body_data($height,$weight,$age,$gender,$impedance){
+
+ $result_data = [];
+ $mheight = bcdiv($height, '100', 20); // 假设我们保留20位小数
+ $gender = $gender == 0 ? 1 : $gender;
+
+ if (($weight <= 0) || ($weight > 220) || ($height <= 0) || ($height > 270) || ($age <= 0) || ($age > 120) || ($impedance <= 0) || ($impedance > 1000) || !in_array($gender, [1, 2])) {
+ if ($weight != 0 && $height != 0) {
+ // 计算BMI
+ $bmi = bcdiv($weight, bcmul($mheight, $mheight,20), 2);
+ $result_data['bmi'] = $bmi;
+ $result_data['bone'] = 0;
+ $result_data['muscle'] = 0;
+ $result_data['water'] = 0;
+ $result_data['fat_r'] = 0;
+ $result_data['sfr'] = 0;
+ $result_data['skeletalmuscle'] = 0;
+ $result_data['protein'] = 0;
+ $result_data['visceral'] = 0;
+ $result_data['kcal'] = 0;
+ $result_data['bodyage'] = 0;
+ $result_data['weight'] = $weight;
+ $result_data['height'] = $height;
+ $result_data['age'] = $age;
+ $result_data['adc'] = $impedance;
+ $result_data['gender'] = $gender;
+ $result_data['standard_level'] = 0.0;
+ return $result_data;
+ }
+ }
+ $num = intval(bcmul(bcdiv($weight,bcmul($mheight,$mheight,20),20),'10',20))/10;
+ $num2 = 0.0;
+ $num3 = 0.0;
+ $num4 = 0.0;
+ $num5 = 0.0;
+ $num6 = 0.0;
+ $num7 = 0.0;
+ $num8 = 0.0;
+ $num9 = 0.0;
+ $num10 = 0.0;
+ $num11 = 0.0;
+ // 根据男女计算脂肪率、脂肪量、肌肉率、肌肉量等等....
+ $standard_weight = 0.0;
+ $standard_level = 0.0;
+ if ($gender == 1){
+ // $num2 = 0.015 * $weight + (2.0 - 0.00055 * $impedance) * $height / 100 - 1.15;
+ $num2 = bcsub(bcadd(bcmul('0.015',$weight,20),bcdiv(bcmul(bcsub('2.0',bcmul('0.00055',$impedance,20),20),$height,20),'100.0',20),20),'1.15',2);
+ // $num3 = (0.0 - (0.00115 * $impedance + 0.01)) * $weight + (49.64 - 0.031 * $impedance) * $height / 100.0 + $impedance * 0.08 + $age * 0.04 + 15.4;
+ $num3 = bcsub(bcsub(bcsub(bcsub(bcmul(bcsub('0.0',bcadd(bcmul('0.00115',$impedance,20),'0.01',20),20),$weight,20),bcdiv(bcmul(bcsub('49.64',bcmul('0.031',$impedance,20)),$height,20),'100.0',20),20),bcmul($impedance,'0.08'),20),bcmul($age,'0.04'),20),'15.4',2);
+ // $num4 = 1000000.0/($num*(2.688*$impedance-78.28))-(10058/$impedance)-0.22*$age+52.6;
+ $num4 = bcadd(bcsub(bcsub(bcdiv('1000000.0',bcmul($num,bcsub(bcmul('2.688',$impedance,20),'78.28',20),20),20),bcdiv('10058',$impedance,20),20),bcmul('0.22',$age,20),20),'52.6',20);
+ // $num5 = -930000.0 / $num / (1.966 * $impedance - 58.46) + (13176 / $impedance) - 0.06 * $age + 40.0;
+ $num5 = bcadd(bcsub(bcadd(bcdiv(bcdiv('-930000.0',$num,20),bcsub(bcmul('1.966',$impedance,20),'58.46',20),20),bcdiv('13176',$impedance,0),20),bcmul('0.06',$age,20),20),'40.0',20);
+ // $num6 = 0.898 * $num5;
+ $num6 = bcmul('0.898',$num5,1);
+ // $num7 = 0.895 * $num4;
+ $num7 = bcmul('0.895',$num4,20);
+ // $num8 = 0.8 * (100.0 - $num5 - $num4 - $num2 / $weight);
+ $num8 = bcmul('0.8',bcsub(bcsub(bcsub('100.0',$num5,20),$num4,20),bcdiv($num2,$weight,20),20),2);
+ // $num9 = 0.304 * $weight - 25.58 * $height / 100.0 + 0.131 * $age + 0.005 * $impedance + 22.0;
+ $num9 = bcadd(bcadd(bcadd(bcsub(bcmul('0.304',$weight,20),bcdiv(bcmul('25.58',$height,20),'100.0',20),20),bcmul('0.131',$age,20),20),bcmul('0.005',$impedance,20),20),'22.0',0);
+ // $num10 = (9.0 + 0.0015 * $impedance) * $weight + (1350.0 - 0.88 * $impedance) * $height / 100.0 + (188 / $age) + 0.748 * $impedance - 1053.0;
+ $num10 = bcsub(bcadd(bcadd(bcadd(bcmul(bcadd('9.0',bcmul('0.0015',$impedance,20),20),$weight,20),bcdiv(bcmul(bcsub('1350.0',bcmul('0.88',$impedance,20),20),$height,20),'100.0',20),20),bcdiv('188',$age,20),20),bcmul('0.748',$impedance,20),20),'1053.0',0);
+ // $num11 = $age * (1.0 + 0.012 * ($num - 1.0)) - 21.0 + (30 - $age) * 0.35 + ($impedance - 450) * 0.02 + 11.0;
+ $num11 = bcadd(bcadd(bcadd(bcsub(bcmul($age,bcadd('1.0',bcmul('0.012',bcsub($num,'1.0',20),20),20),20),'21.0',20),bcmul(bcsub('30',$age,20),'0.35',20),20),bcmul(bcsub($impedance,'450',20),'0.02',20),20),'11.0',0);
+
+ // $standard_weight = ($height-80)*0.7;
+ $standard_weight = bcmul(bcsub($height,'80',20),'0.7',20);
+
+ }else{
+ // $num2 = 2.2E-05 * $impedance * $weight + (4.99 - 0.00284 * $impedance) * $height / 100.0 + 0.0012 * $impedance - 4.45;
+ $num2 = bcsub(bcadd(bcadd(bcmul(bcmul('0.000022',$impedance,20),$weight,20),bcdiv(bcmul(bcsub('4.99',bcmul('0.00284',$impedance,20),20),$height,20),'100.0',20),20),bcmul('0.0012',$impedance,20),20),'4.45',2);
+ // $num3 = (0.0 - (0.00115 * $impedance + 0.01)) * $weight + (49.64 - 0.031 * $impedance) * $height / 100.0 + $impedance * 0.08 + $age * 0.04 + 6.0;
+ $num3 = bcadd(bcadd(bcadd(bcadd(bcmul(bcsub('0.0',bcadd(bcmul('0.00115',$impedance,20),'0.01',20),20),$weight,20),bcdiv(bcmul(bcsub('49.64',bcmul('0.031',$impedance,20),20),$height,20),'100.0',20),20),bcmul($impedance,'0.08',20),20),bcmul($age,'0.04',20),20),'6.0',2);
+ // $num4 = 1000000.0 / ($num * (2.467 * $impedance - 75.37)) - (14215 / $impedance) - 0.034 * $age + 43.2;
+ $num4 = bcadd(bcsub(bcsub(bcdiv('1000000.0',bcmul($num,bcsub(bcmul('2.467',$impedance,20),'75.37',20),20),20),bcdiv('14215',$impedance,20),20),bcmul('0.034',$age,20),20),'43.2',20);
+ // $num5 = -3030000.0 / ($num + 20.0) / (1.966 * $impedance - 58.46) + (28176 / $impedance) - 0.06 * $age + 51.0;
+ $num5 = bcadd(bcsub(bcadd(bcdiv(bcdiv('-3030000.0',bcadd($num,'20.0',20),20),bcsub(bcmul('1.966',$impedance,20),'58.46',20),20),bcdiv('28176',$impedance,20),20),bcmul('0.06',$age,20),20),'51.0',20);
+ // $num6 = 0.876 * $num5 + 1.66;
+ $num6 = bcadd(bcmul('0.876',$num5,20),'1.66',1);
+ // $num7 = 0.857 * $num4 - 0.36;
+ $num7 = bcsub(bcmul('0.857',$num4,20),'0.36',20);
+ // $num8 = 0.75 * (100.0 - $num5 - $num4 - $num2 / $weight);
+ $num8 = bcmul('0.75',bcsub('100.0',bcsub($num5,bcsub($num4,bcdiv($num2,$weight,20),20),20),20),2);
+ // $num9 = 0.304 * $weight - 25.58 * $height / 100.0 + 0.131 * $age + 0.005 * $impedance + 22.0;
+ $num9 = bcadd(bcadd(bcadd(bcsub(bcmul(0.304,$weight,20),bcdiv(bcmul(25.58,$height,20),'100.0',20),20),bcmul('0.131',$age,20),20),bcmul('0.005',$impedance,20),20),'22.0',0);
+ // $num10 = (0.00307 * $impedance + 1.5) * $weight + (1459.0 - 0.989 * $impedance) * $height / 100.0 + $age * 0.9 + 0.923 * $impedance - 950.0;
+ $num10 = bcsub(bcadd(bcadd(bcadd(bcmul(bcadd(bcmul('0.00307',$impedance,20),'1.5',20),$weight,20),bcdiv(bcmul(bcsub('1459.0',bcmul('0.989',$impedance,20),20),$height,20),'100.0',20),20),bcmul($age,'0.9',20),20),bcmul('0.923',$impedance,20),20),'950.0',0);
+ // $num11 = $age * (0.95 + 0.02 * ($num - 21.2)) + ($impedance - 500) * 0.02;
+ $num11 = bcadd(bcmul($age,bcadd(0.95,bcmul('0.02',bcsub($num,'21.2',20),20),20),20),bcmul(bcsub($impedance,'500',20),'0.02',20),0);
+
+ // $standard_weight = ($height-80)*0.7;
+ $standard_weight = bcmul(bcsub($height,'80',20),'0.6',20);
+ }
+
+ $result_data['bmi'] = $num;
+ // $num2 = (($num2 > $weight * 0.15) ? ($weight * 0.15) : $num2);
+ if(bccomp($num2, bcmul($weight,'0.15',20), 20) === 1){
+ $num2 = bcmul($weight,'0.15',2);
+ }
+ // $result_data['bone'] = ($num2 < $weight * 0.02) ? ($weight * 0.02) : $num2;
+ if(bccomp($num2, bcmul($weight,'0.02',20), 20) === -1){
+ $result_data['bone'] = bcmul($weight,'0.02',2);
+ }else{
+ $result_data['bone'] = $num2;
+ }
+ // $num3 = (($num3 > 75.0) ? 75.0 : $num3);
+ if(bccomp($num3, '75.0', 20) === 1){
+ $num3 = '75.0';
+ }
+ // $result_data['muscle'] = ($num3 < 15.0) ? 15.0 : $num3;
+ if(bccomp($num3, '15.0', 20) === -1){
+ $result_data['muscle'] = '15.00';
+ }else{
+ $result_data['muscle'] = $num3;
+ }
+ // $num4 = (($num4 > 70.0) ? 70.0 : $num4);
+ if(bccomp($num4, '70.0', 20) === 1){
+ $num4 = '70.0';
+ }
+ // $result_data['water'] = ($num4 < 20.0) ? 20.0 : $num4;
+ if(bccomp($num4, '20.0', 20) === -1){
+ $result_data['water'] = '20.00';
+ }else{
+ $result_data['water'] = $num4;
+ }
+ // $num5 = (($num5 > 50.0) ? 50.0 : $num5);
+ if(bccomp($num5, '50.0', 20) === 1){
+ $num5 = '50.0';
+ }
+ // $result_data['fat_r'] = ($num5 < 5.0) ? 5.0 : $num5;
+
+ if(bccomp($num5, '5.0', 20) === -1){
+ $result_data['fat_r'] = '5.00';
+ }else{
+ // $result_data['fat_r'] = $num5;
+ $result_data['fat_r'] = substr($num5, 0, strpos($num5, ".") + 3);
+ }
+ // $result_data['sfr'] = $num6 <= 0 ? "0" : $num6;
+ if(bccomp($num6, '0.0', 20) === -1){
+ $result_data['sfr'] = '0.00';
+ }else{
+ $result_data['sfr'] = $num6;
+ }
+ // $result_data['skeletalmuscle'] = $num7;
+ $result_data['skeletalmuscle'] = substr($num7, 0, strpos($num7, ".") + 3);
+ // $num8 = (($num8 > 50.0) ? 50.0 : $num8);
+ if(bccomp($num8, '50.0', 20) === 1){
+ $num8 = '50.00';
+ }
+ // $result_data['protein'] = ($num8 < 10.0) ? 10.0 : $num8;
+ if(bccomp($num8, '10.0', 20) === -1){
+ $result_data['protein'] = '10.00';
+ }else{
+ $result_data['protein'] = $num8;
+ }
+ // $num9 = (($num9 > 20.0) ? 20.0 : $num9);
+ if(bccomp($num9, '20.0', 20) === 1){
+ $num9 = '20.0';
+ }
+ // $result_data['visceral'] = ($num9 < 1.0) ? 1.0 : $num9;
+ if(bccomp($num9, '1.0', 20) === -1){
+ $result_data['visceral'] = '1.0';
+ }else{
+ $result_data['visceral'] = $num9;
+ }
+ // $result_data['kcal'] = $num10 <= 0 ? "0" : $num10;
+ if(bccomp($num10, '0', 20) !== 1){
+ $result_data['kcal'] = '0';
+ }else{
+ $result_data['kcal'] = $num10;
+ }
+
+ // $standard_level = ($weight-$standard_weight)/$standard_weight;
+ $standard_level = bcdiv(bcsub($weight,$standard_weight,20),$standard_weight,2);
+ // 加 bcadd(,,20)
+ // 减 bcsub(,,20)
+ if ($age < 18){
+ $num11 = $age;
+ }else{
+ // $num11 = (($num11 > ($age + 10)) ? (($age + 10)) : $num11);
+ if(bccomp($num11, $age + 10, 20) === 1){
+ $num11 = $age + 10;
+ }
+ // $num11 = (($num11 < ($age - 10)) ? (($age - 10)) : $num11);
+ if(bccomp($num11, $age - 10, 20) === -1){
+ $num11 = $age - 10;
+ }
+ }
+
+ $result_data['bodyage'] = $num11;
+ $result_data['weight'] = $weight;
+ $result_data['height'] = $height;
+ $result_data['age'] = $age;
+ $result_data['adc'] = $impedance;
+ $result_data['gender'] = $gender;
+ $result_data['standard_level'] = $standard_level;
+ return $result_data;
+ }
+ // 计算脂肪率
+ function calculate_fat_r(){
+ }
+ // 计算脂肪量
+ function calculate_zhifangliang(){
+
+ }
+ // 计算肌肉率
+ function calculate_jiroulv(){
+
+ }
+ // 计算肌肉量
+ function calculate_jirouliang(){
+
+ }
+ // 计算水分
+ function calculate_shuifen(){
+
+ }
+ // 计算蛋白量
+ function calculate_danbailiang(){
+
+ }
+ // 计算骨重
+ 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]);
+ }
+
+}
\ No newline at end of file
diff --git a/application/NewReedaw/controller/app/Card.php b/application/NewReedaw/controller/app/Card.php
new file mode 100644
index 0000000..a954c3d
--- /dev/null
+++ b/application/NewReedaw/controller/app/Card.php
@@ -0,0 +1,144 @@
+'app_account_number',
+ 'juese'=>'app_user_data',
+ 'card'=>'app_card_data'
+ ];
+ // 加 bcadd(,,20)
+ // 减 bcsub(,,20)
+ // 乘 bcmul(,,20)
+ // 除 bcdiv(,,20)
+ // 测试token=>'caadd1be045a65f30b92aa805f1de54a'
+
+ ################################################################接口################################################################
+ ################################################################接口################################################################
+ ################################################################接口################################################################
+
+ // 卡片列表信息
+ public function card_list_msg(){
+ 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->card_list_msg_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 card_user_order(){
+ try {
+ // 你的业务逻辑
+ $data = input('post.');
+ if(!array_key_exists('token', $data) || !array_key_exists('aud_id', $data) || !array_key_exists('card_data', $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->card_user_order_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 card_list_msg_action($data){
+ // 检查角色
+ $user_data = Db::table($this->card_db_name['juese'])->where(['id'=>$data['aud_id'],'is_del'=>0])->field('id,card_order')->find();
+ if(!$user_data){
+ return $this->msg(10003,'未核实到角色信息');
+ }
+ // 获取卡片信息
+ $card_data = Db::table($this->card_db_name['card'])->where(['is_del'=>0])->field('id,name,content,page_url_report,is_sub_item,background_color,background_pic,key_word')->cache(86400)->select();
+ // 根据用户处理卡片信息
+ $return_data = [
+ 'chosen_yes'=>[],
+ 'chosen_no'=>[],
+ ];
+ if($user_data['card_order'] != ''){
+ $user_data['card_order'] = explode(',',$user_data['card_order']);
+ }else{
+ $user_data['card_order'] = [];
+ }
+ for ($i=0; $i < count($card_data); $i++) {
+ if(!in_array($card_data[$i]['id'],$user_data['card_order'])){
+ $return_data['chosen_no'][] = $card_data[$i];
+ }else{
+ $key = array_search($card_data[$i]['id'], $user_data['card_order']);
+ $return_data['chosen_yes'][$key] = $card_data[$i];
+ }
+ }
+ ksort($return_data['chosen_yes']);
+ return $this->msg($return_data);
+ }
+ public function card_user_order_action($data){
+
+ if($data['card_data'] != ''){
+ $data['card_data2'] = explode(',',$data['card_data']);
+ }else{
+ $data['card_data2'] = [];
+ }
+
+ foreach ($data['card_data2'] as $key => $value) {
+ if(!$this->verify_data_is_ok($value,'intnum')){
+ return $this->msg(10005,'卡片id错误');
+ }
+ }
+ $user_data = Db::table($this->card_db_name['juese'])->where(['id'=>$data['aud_id'],'is_del'=>0])->count();
+ if($user_data <= 0){
+ return $this->msg(10003,'未核实到角色信息');
+ }
+ $result = Db::table($this->card_db_name['juese'])->where(['id'=>$data['aud_id']])->update(['card_order' => $data['card_data']]);
+ if($result){
+ return $this->msg([]);
+ }else{
+ return $this->msg(10002);
+ }
+
+ }
+
+
+
+}
\ No newline at end of file
diff --git a/application/NewReedaw/controller/app/Countfood.php b/application/NewReedaw/controller/app/Countfood.php
new file mode 100644
index 0000000..c5ad963
--- /dev/null
+++ b/application/NewReedaw/controller/app/Countfood.php
@@ -0,0 +1,89 @@
+'app_account_number',
+ ];
+ // 加 bcadd(,,20)
+ // 减 bcsub(,,20)
+ // 乘 bcmul(,,20)
+ // 除 bcdiv(,,20)
+ // 测试token=>'caadd1be045a65f30b92aa805f1de54a'
+
+ ################################################################接口################################################################
+ ################################################################接口################################################################
+ ################################################################接口################################################################
+
+ // 卡片列表信息
+ public function card_list_msg(){
+ 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->card_list_msg_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 card_list_msg_action($data){
+ // 检查角色
+ $user_data = Db::table($this->card_db_name['juese'])->where(['id'=>$data['aud_id'],'is_del'=>0])->field('id,card_order')->find();
+ if(!$user_data){
+ return $this->msg(10003,'未核实到角色信息');
+ }
+ // 获取卡片信息
+ $card_data = Db::table($this->card_db_name['card'])->where(['is_del'=>0])->field('id,name,content,page_url_report,is_sub_item,background_color,background_pic,key_word')->cache(86400)->select();
+ // 根据用户处理卡片信息
+ $return_data = [
+ 'chosen_yes'=>[],
+ 'chosen_no'=>[],
+ ];
+ if($user_data['card_order'] != ''){
+ $user_data['card_order'] = explode(',',$user_data['card_order']);
+ }else{
+ $user_data['card_order'] = [];
+ }
+ for ($i=0; $i < count($card_data); $i++) {
+ if(!in_array($card_data[$i]['id'],$user_data['card_order'])){
+ $return_data['chosen_no'][] = $card_data[$i];
+ }else{
+ $key = array_search($card_data[$i]['id'], $user_data['card_order']);
+ $return_data['chosen_yes'][$key] = $card_data[$i];
+ }
+ }
+ ksort($return_data['chosen_yes']);
+ return $this->msg($return_data);
+ }
+
+
+
+}
\ No newline at end of file
diff --git a/application/NewReedaw/controller/app/Gufen.php b/application/NewReedaw/controller/app/Gufen.php
new file mode 100644
index 0000000..727d8e9
--- /dev/null
+++ b/application/NewReedaw/controller/app/Gufen.php
@@ -0,0 +1,93 @@
+'app_account_number',
+ 'guize'=>'admin_estimate',
+
+ ];
+ // 加 bcadd(,,20)
+ // 减 bcsub(,,20)
+ // 乘 bcmul(,,20)
+ // 除 bcdiv(,,20)
+ // 测试token=>'caadd1be045a65f30b92aa805f1de54a'
+
+ ################################################################接口################################################################
+ ################################################################接口################################################################
+ ################################################################接口################################################################
+
+ // 获取单个类型列表
+ public function get_single_data($data = ['address'=>'上海','gender'=>'1','token'=>'caadd1be045a65f30b92aa805f1de54a']){
+ try {
+ // 你的业务逻辑
+ if(count(input('post.')) > 0){
+ $data = input('post.');
+ }
+ if(!array_key_exists('address', $data) || !array_key_exists('gender', $data) || !array_key_exists('token', $data)){
+ $return_data = $this->msg(10001);
+ }
+ if(!$this->verify_data_is_ok($data['address'],'str')){
+ return $this->msg(10005);
+ }
+ if(!$this->verify_data_is_ok($data['gender'],'intnum')){
+ return $this->msg(10005);
+ }
+ unset($data['token']);
+ $return_data = $this->sportstesting_get_type_list_action($data);
+
+ // 成功
+ $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'] .= "行号: " . $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 sportstesting_get_type_list_action($data){
+
+ $parameter_data = explode(',',$data['address']);
+ $gender = $data['gender'];
+ // 精准查询地市规则start
+ // if(count($parameter_data) == 1){
+ // $db_condition = "province = '".$parameter_data[0]."'";
+ // }else if(count($parameter_data) == 2){
+ // $db_condition = "province = '".$parameter_data[0]."' and city = '".$parameter_data[1]."'";
+ // }else if(count($parameter_data) == 3){
+ // $db_condition = "province = ".$parameter_data[0]."' and city = '".$parameter_data[1]."' and area = '".$parameter_data[2]."'";
+ // }else{
+ // return $this->msg(10005);
+ // }
+ // 精准查询地市规则end
+ // 全省地市一个规则start
+ $db_condition = "province = '".$parameter_data[0]."'";
+ // 全省地市一个规则end
+ $data = Db::table($this->card_db_name['guize'])->where($db_condition)->find();
+ $data = json_decode($data['content'],true);
+ $result = $this->handle_default_rule_list_content($data,$gender);
+ return $this->msg($result);
+ }
+
+
+
+}
\ No newline at end of file
diff --git a/application/NewReedaw/controller/app/Index.php b/application/NewReedaw/controller/app/Index.php
index 68adcb9..bb386f2 100644
--- a/application/NewReedaw/controller/app/Index.php
+++ b/application/NewReedaw/controller/app/Index.php
@@ -2,12 +2,13 @@
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;
+use app\app\controller\Language;
class Index extends Base{
@@ -15,7 +16,67 @@ class Index extends Base{
'zhanghao'=>'app_account_number',
'juese'=>'app_user_data',
'body_data'=>'app_card_body_data',
-
+ 'banben'=>'app_version_log',
+ 'shangwuhezuo'=>'admin_business_cooperation',
+ 'diqu'=>'admin_estimate',
+ 'banner'=>'admin_notice_banner',
+ 'skip'=>'app_card_skip_data',
+ 'vitalcapacity'=>'app_card_vitalcapacity_data',
+ ];
+ protected $request_result = [
+ '2'=>['height'=>['身高','cm'],'weight'=>['体重','kg'],'age'=>['年龄','岁'],'bmi'=>['BMI',''],'head'=>['头围',''],'fat_w'=>['脂肪量','kg'],'fat_r'=>['脂肪率','%'],'muscleval'=>['肌肉量','kg'],'muscle'=>['肌肉率','%'],'proteinval'=>['蛋白量','kg'],'protein'=>['蛋白率','%'],'water'=>['水分',''],'bone'=>['骨重','kg'],'visceral'=>['内脏指数',''],'sfr'=>['皮下脂肪','%'],'kcal'=>['基础代谢','kcal'],'un_fat_w_weight'=>['去脂体重','kg'],'body_age'=>['体龄',''],'body_level'=>['肥胖等级',''],'body_type'=>['体型','']],
+ '6'=>['jump_num'=>['个数',''],'jump_time'=>['时长',''],'jump_kcal'=>['卡路里','kcal']],
+ '8'=>['one_val'=>['第一次','ml'],'two_val'=>['第二次','ml'],'three_val'=>['第三次','ml'],'average_val'=>['三次平均','ml'],'score'=>['最后成绩','分']]
+ ];
+ 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 $language_country = [
+ 'en' => 'English', // 英语(通用)★
+ 'zh-Hans' => '中文', // 中文(简体)★
+ // 'es' => 'Español', // 西班牙语(西班牙)★
+ // 'fr' => 'Français', // 法语(法国)★
+ // 'pt' => 'Português', // 葡萄牙语(巴西)★
+ // 'ar' => 'العربية', // 阿拉伯语(标准)★
+ // 'ru' => 'Русский', // 俄语(俄罗斯)★
+ // 'de' => 'Deutsch', // 德语(德国)★
+ // 'ja' => '日本語', // 日语
+ // 'ko' => '한국어', // 韩语
+ // 'it' => 'Italiano', // 意大利语
+ // 'nl' => 'Nederlands', // 荷兰语
+ // 'hi' => 'हिन्दी', // 印地语
+ // 'tr' => 'Türkçe', // 土耳其语
+ // 'vi' => 'Tiếng Việt', // 越南语
+ // 'th' => 'ไทย', // 泰语
+ // 'pl' => 'Polski', // 波兰语
+ // 'sv' => 'Svenska', // 瑞典语
+ // 'fi' => 'Suomi', // 芬兰语
+ // 'da' => 'Dansk', // 丹麦语
+ // 'no' => 'Norsk', // 挪威语
+ // 'he' => 'עברית', // 希伯来语
+ // 'id' => 'Bahasa Indonesia', // 印尼语
+ // 'ms' => 'Bahasa Melayu', // 马来语
+ // 'cs' => 'Čeština', // 捷克语
+ // 'hu' => 'Magyar', // 匈牙利语
+ // 'el' => 'Ελληνικά', // 希腊语
+ // 'ro' => 'Română', // 罗马尼亚语
+ // 'sk' => 'Slovenčina', // 斯洛伐克语
+ // 'uk' => 'Українська', // 乌克兰语
];
// 加 bcadd(,,20)
// 减 bcsub(,,20)
@@ -30,16 +91,7 @@ class Index extends Base{
// 配置信息
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);
- }
+ $data = input('post.');
return $this->config_action($data);
} catch (\Exception $e) {
// 捕获异常
@@ -55,25 +107,29 @@ class Index extends Base{
return $this->msg(99999);
}
}
- // 遗传身高
+
+ // 身高预测
public function genetic_height(){
try {
$data = input('post.');
+ if(!is_array($data)){
+ return $this->msg(10005);
+ }
if(!array_key_exists('dadHeight', $data) || !array_key_exists('momHeight', $data) || !array_key_exists('birthday', $data) || !array_key_exists('sex', $data)){
return $this->msg(10001);
}
unset($data['token']);
if(!$this->verify_data_is_ok($data['birthday'],'datetime')){
- return $this->msg(10005);
+ return $this->msg(10005,'birthday type error');
}
if(!$this->verify_data_is_ok($data['dadHeight'],'num')){
- return $this->msg(10005);
+ return $this->msg(10005,'dadHeight type error');
}
if(!$this->verify_data_is_ok($data['momHeight'],'num')){
- return $this->msg(10005);
+ return $this->msg(10005,'momHeight type error');
}
if(!$this->verify_data_is_ok($data['sex'],'intnum')){
- return $this->msg(10005);
+ return $this->msg(10005,'sex type error');
}
// 直接开始业务,请求外部接口start
@@ -85,7 +141,6 @@ class Index extends Base{
'sex'=>$data['sex'],
];
$request_result = $this->postRequest($url,$temporary_parameter,array('Content-Type:application/json','Origin:http://ybdevice.pcxbc.com'));
- // 直接开始业务,请求外部接口end
return json($request_result);
} catch (\Exception $e) {
// 捕获异常
@@ -101,41 +156,45 @@ class Index extends Base{
return $this->msg(99999);
}
}
+
// BMI测评
public function bmi_evaluation(){
try {
- $data = input('post.');
- if(!array_key_exists('height', $data) || !array_key_exists('weight', $data) || !array_key_exists('birthday', $data) || !array_key_exists('sex', $data)){
+ $cbe_data = input('post.');
+ if(!is_array($cbe_data)){
+ return $this->msg(10005);
+ }
+ if(!array_key_exists('height', $cbe_data) || !array_key_exists('weight', $cbe_data) || !array_key_exists('birthday', $cbe_data) || !array_key_exists('sex', $cbe_data)){
return $this->msg(10001);
}
- unset($data['token']);
- if(!$this->verify_data_is_ok($data['birthday'],'datetime')){
- return $this->msg(10005);
+ unset($cbe_data['token']);
+ if(!$this->verify_data_is_ok($cbe_data['birthday'],'datetime')){
+ return $this->msg(10005,'birthday type error');
}
- if(!$this->verify_data_is_ok($data['height'],'num')){
- return $this->msg(10005);
+ if(!$this->verify_data_is_ok($cbe_data['height'],'num')){
+ return $this->msg(10005,'height type error');
}
- if(!$this->verify_data_is_ok($data['weight'],'num')){
- return $this->msg(10005);
+ if(!$this->verify_data_is_ok($cbe_data['weight'],'num')){
+ return $this->msg(10005,'weight type error');
}
- if(!$this->verify_data_is_ok($data['sex'],'intnum')){
- return $this->msg(10005);
+ if(!$this->verify_data_is_ok($cbe_data['sex'],'intnum')){
+ return $this->msg(10005,'sex type error');
}
// 直接开始业务,请求外部接口start
$url = 'http://ybdevice.pcxbc.com/api/result/calcbmi';
$temporary_parameter = [
- 'height'=>$data['height'],
- 'weight'=>$data['weight'],
- 'birthday'=>$data['birthday'],
- 'sex'=>$data['sex'],
+ 'height'=>$cbe_data['height'],
+ 'weight'=>$cbe_data['weight'],
+ 'birthday'=>$cbe_data['birthday'],
+ 'sex'=>$cbe_data['sex'],
];
$request_result = $this->postRequest($url,$temporary_parameter,array('Content-Type:application/json','Origin:http://ybdevice.pcxbc.com'));
// 直接开始业务,请求外部接口end
// 处理进度点
- $return_result =$this->bmi_evaluation_action($request_result);
- return $return_result;
+ $request_result =$this->bmi_evaluation_action($request_result);
+ return $request_result;
} catch (\Exception $e) {
// 捕获异常
$logContent["flie"] = $e->getFile();
@@ -146,24 +205,35 @@ class Index extends Base{
$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);
+ $this->record_api_log($cbe_data, $logContent, null);
return $this->msg(99999);
}
}
- // 获取首页角色信息
- public function get_user_data_information(){
+
+ // 数据对比(包含身体、跳绳、肺活量)
+ public function all_data_contrast($data = ['before_id'=>'171','after_id'=>'174','type'=>'2','token'=>'caadd1be045a65f30b92aa805f1de54a']){
try {
$data = input('post.');
- if(!array_key_exists('token', $data) || !array_key_exists('aud_id', $data)){
+ if(!array_key_exists('before_id', $data) || !array_key_exists('after_id', $data) || !array_key_exists('type', $data) || !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');
+ if(!$this->verify_data_is_ok($data['before_id'],'intnum')){
+ return $this->msg(10005);
}
- 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['after_id'],'intnum')){
+ return $this->msg(10005);
+ }
+ if(!$this->verify_data_is_ok($data['type'],'intnum')){
+ return $this->msg(10005);
+ }
+ unset($data['token']);
+ if($data['type'] == '2'){
+ return $this->get_body_data_contrast($data);
+ }else if($data['type'] == '6'){
+ return $this->get_skip_data_contrast($data);
+ }else if($data['type'] == '8'){
+ return $this->get_vitalcapacity_data_contrast($data);
}
- return $this->get_user_data_information_action($data);
} catch (\Exception $e) {
// 捕获异常
$logContent["flie"] = $e->getFile();
@@ -177,7 +247,37 @@ class Index extends Base{
$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################################################################
@@ -207,16 +307,44 @@ class Index extends Base{
]
],
'king_kong_region'=>[
- ['title'=>'增量对比','icon'=>'','jump'=>''],
- ['title'=>'中招估分','icon'=>'','jump'=>''],
- ['title'=>'遗传身高','icon'=>'','jump'=>''],
- ['title'=>'BMI测评','icon'=>'','jump'=>''],
+ ['title'=>'减值对比','icon'=>'https://tc.pcxbc.com/new_reedaw/icon/contrast.png','jump'=>'/pageTwo/compk/contrast'],
+ ['title'=>'中招估分','icon'=>'https://tc.pcxbc.com/new_reedaw/icon/report.png','jump'=>'/pageTwo/score/report'],
+ ['title'=>'遗传身高','icon'=>'https://tc.pcxbc.com/new_reedaw/icon/inheritHeighet.png','jump'=>'/pageTwo/home/inheritHeighet'],
+ ['title'=>'BMI测评','icon'=>'https://tc.pcxbc.com/new_reedaw/icon/bmi.png','jump'=>'/pageTwo/home/bmi'],
],
- 'role_list'=>[
- ]
+ 'version_msg'=>[],
+ 'login_status'=>[],
+ 'business_cooperation_url'=>[],
+ 'area_list'=>[],
+ 'identity_list'=>[],
+ 'grade_list'=>[],
+ 'banner'=>[],
+
];
- $role = new Role;
- $return_data['role_list'] = $role->role_list_action(['token'=>$data['token'],'type'=>2])->getData()['data'];
+
+ $temporary = $this->login_invalid_version($data);
+ $return_data['version_msg'] = $temporary[1];
+ $return_data['login_status'] = $temporary[0];
+
+ $return_data['business_cooperation_url'] = Db::table($this->index_db_name['shangwuhezuo'])->where(['is_del'=>0])->field('title,data_url as url')->select();
+
+ $address_data = Db::table($this->index_db_name['diqu'])->where(['type' => '2'])->cache(86400)->field('id,content,city,area')->find();
+ $return_data['area_list'] = json_decode($address_data['content'],true);
+ $return_data['identity_list'] = [];
+ foreach ($this->identity_list as $key => $value) {
+ array_push($return_data['identity_list'],['id'=>$key,'name'=>$value]);
+ }
+ $return_data['grade_list'] = $this->grade_list;
+
+ $return_data['banner'] = Db::table($this->index_db_name['banner'])->where(['scene_data' => '3','is_del'=>0])->cache(3600)->order('sort_num desc')->field('id,type,pic,jump_url,parameter_data,sort_num')->select();
+
+ for ($i=0; $i < count($return_data['banner']); $i++) {
+ if($return_data['banner'][$i]['type'] != 1){
+ $return_data['banner'][$i]['parameter_data'] = '';
+ }
+ unset($return_data['banner'][$i]['sort_num']);
+ unset($return_data['banner'][$i]['ROW_NUMBER']);
+ }
return $this->msg($return_data);
}
public function bmi_evaluation_action($data){
@@ -281,18 +409,396 @@ class Index extends Base{
// 处理key名称一致end
return $this->msg($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();
+ // 数据对比(身体)
+ public function get_body_data_contrast($data){
+ $data2 = [$data['before_id'],$data['after_id']];
+ $data3 = implode(',',$data2);
+ $calculate_arr = [];
+ $result = Db::query("
+ select
+ acbd.id,
+ acbd.height,
+ acbd.weight,
+ acbd.bmi,
+ 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.record_time,
+ acbd.record_type,
+ acbd.head_circumference,
+ REPLACE(CONVERT(varchar(10), acbd.record_time, 23), '-', '-') AS b_time,
+ aud.nickname,
+ aud.gender,
+ aud.birthday,
+ aud.head_pic
+ from ".$this->index_db_name['body_data']." as acbd
+ left join ".$this->index_db_name['juese']." as aud on acbd.aud_id=aud.id
+ where acbd.id in ($data3)
+ and acbd.is_del = 0
+ ");
+ if(!$result || count($result)<2){
+ return $this->msg(10004);
+ }
+ // 调整顺序
+ foreach ($result as $key => $value) {
+ if($value['id'] == $data2[0]){
+ $calculate_arr['before'] = $value;
+ }else{
+ $calculate_arr['after'] = $value;
+ }
+ }
+ $return_data['time'] = $calculate_arr['before']['b_time'].'与'.$calculate_arr['after']['b_time'];
+ $return_data['headimg'] = $calculate_arr['before']['head_pic'];
+ $return_data['name'] = $calculate_arr['before']['nickname'];
+ $return_data['gender'] = $calculate_arr['before']['gender'];
+ $return_data['age'] = $this->calculate_age($calculate_arr['before']['birthday']);
+ $return_data['day'] = abs($this->daysSince($calculate_arr['before']['record_time'],$calculate_arr['after']['record_time']));
+ $return_data['list'] = [];
+ // 处理如果没有阻抗的数据为0,显示异常start;同步处理,如果两个对比数据,都没有阻抗数据,则只显示基础信息
+ if($calculate_arr['before']['record_type'] != 'by_device_adc' && $calculate_arr['after']['record_type'] != 'by_device_adc'){
+ foreach ($calculate_arr['before'] as $key => $value) {
+ if(!in_array($key, ['height','weight','bmi','head_circumference'])){
+ unset($calculate_arr['before'][$key]);
+ unset($calculate_arr['after'][$key]);
+ }
+ }
+ if($return_data['age']>=3){
+ unset($calculate_arr['before']['head_circumference']);
+ unset($calculate_arr['after']['head_circumference']);
+ }else{
+ $calculate_arr['before']['head_circumference'] = json_decode($calculate_arr['before']['head_circumference'],true);
+ $calculate_arr['after']['head_circumference'] = json_decode($calculate_arr['after']['head_circumference'],true);
+ foreach ($calculate_arr as $key => $value) {
+ if(array_key_exists('value',$value['head_circumference'])){
+ $calculate_arr[$key]['head'][0] = $value['head_circumference']['value'];
+ }else{
+ $calculate_arr[$key]['head'][0] = 0;
+ }
+ if(array_key_exists('level',$value['head_circumference'])){
+ $calculate_arr[$key]['head'][1] = $value['head_circumference']['level'];
+ }else{
+ $calculate_arr[$key]['head'][1] = '异常';
+ }
+ if(array_key_exists('color',$value['head_circumference'])){
+ $calculate_arr[$key]['head'][2] = $value['head_circumference']['color'];
+ }else{
+ $calculate_arr[$key]['head'][2] = '';
+ }
+ $calculate_arr[$key]['head'] = implode(',',$calculate_arr[$key]['head']);
+ unset($calculate_arr['before']['head_circumference']);
+ unset($calculate_arr['after']['head_circumference']);
+ }
+ }
+ }else{
+ foreach ($calculate_arr as $key => $value) {
+ if($value['record_type'] != 'by_device_adc'){
+ $calculate_arr[$key]['fat_r'] = "0,异常";
+ $calculate_arr[$key]['fat_w'] = "0,异常";
+ $calculate_arr[$key]['muscle'] = "0,异常";
+ $calculate_arr[$key]['muscleval'] = "0,异常";
+ $calculate_arr[$key]['water'] = "0,异常";
+ $calculate_arr[$key]['proteinval'] = "0,异常";
+ $calculate_arr[$key]['bone'] = "0,异常";
+ $calculate_arr[$key]['protein'] = "0,异常";
+ $calculate_arr[$key]['kcal'] = "0,异常";
+ $calculate_arr[$key]['visceral'] = "0,异常";
+ $calculate_arr[$key]['sfr'] = "0,异常";
+ }
+ }
+ }
+ // 处理如果没有阻抗的数据为0,显示异常end;同步处理,如果两个对比数据,都没有阻抗数据,则只显示基础信息
+ foreach ($calculate_arr['before'] as $key => $value) {
+ if(in_array($key, ['height','weight','bmi','head','fat_r','fat_w','muscle','muscleval','water','proteinval','bone','protein','kcal','visceral','sfr'])){
+ $before_arr = explode(',', $value);
+ $after_arr = explode(',', $calculate_arr['after'][$key]);
+ array_push($return_data['list'], [
+ 'firstresult'=>[
+ 'color'=>'',
+ 'level'=>$before_arr[1],
+ 'value'=>$before_arr[0],
+ 'title'=>$this->request_result['2'][$key][0],
+ 'unit'=>$this->request_result['2'][$key][1],
+ 'name'=>$key,
+ ],
+ 'secondresult'=>[
+ 'color'=>'',
+ 'level'=>$after_arr[1],
+ 'value'=>$after_arr[0],
+ 'title'=>$this->request_result['2'][$key][0],
+ 'unit'=>$this->request_result['2'][$key][1],
+ 'name'=>$key,
+ ],
+ 'diffval'=>bcsub($after_arr[0],$before_arr[0],2),
+ ]);
+ }
+ }
+ // 添加头围数据(如果需要的话)end
+ return $this->msg($return_data);
}
+ // 数据对比(跳绳)
+ public function get_skip_data_contrast($data){
+ $data2 = [$data['before_id'],$data['after_id']];
+ $data3 = implode(',',$data2);
+ $calculate_arr = [];
+ $result = Db::query("
+ select
+ acsd.id,
+ acsd.jump_num,
+ acsd.jump_time,
+ acsd.jump_kcal,
+ acsd.record_time,
+ REPLACE(CONVERT(varchar(10), acsd.record_time, 23), '-', '-') AS b_time,
+ aud.nickname,
+ aud.gender,
+ aud.birthday,
+ aud.head_pic
+ from ".$this->index_db_name['skip']." as acsd
+ left join ".$this->index_db_name['juese']." as aud on acsd.aud_id=aud.id
+ where acsd.id in ($data3)
+ and acsd.is_del = 0
+ ");
+
+ if(!$result || count($result)<2){
+ return $this->msg(10004);
+ }
+ // 调整顺序
+ foreach ($result as $key => $value) {
+ if($value['id'] == $data2[0]){
+ $calculate_arr['before'] = $value;
+ }else{
+ $calculate_arr['after'] = $value;
+ }
+ }
+ $return_data['time'] = $calculate_arr['before']['b_time'].'-'.$calculate_arr['after']['b_time'];
+ $return_data['headimg'] = $calculate_arr['before']['head_pic'];
+ $return_data['name'] = $calculate_arr['before']['nickname'];
+ $return_data['gender'] = $calculate_arr['before']['gender'];
+ $return_data['age'] = $this->calculate_age($calculate_arr['before']['birthday']);
+ $return_data['day'] = abs($this->daysSince($calculate_arr['before']['record_time'],$calculate_arr['after']['record_time']));
+
+ $return_data['list'] = [];
+ foreach ($calculate_arr['before'] as $key => $value) {
+ if(in_array($key, ['jump_num','jump_time','jump_kcal'])){
+ $before_arr = $value;
+ $after_arr = $calculate_arr['after'][$key];
+ $temporary_arr = [
+ 'firstresult'=>[
+ 'color'=>'',
+ 'level'=>'',
+ 'value'=>$key=='jump_time'?implode(':',$this->handle_hour_branch_second($before_arr)):$before_arr,
+ 'title'=>$this->request_result['6'][$key][0],
+ 'unit'=>$this->request_result['6'][$key][1],
+ 'name'=>$key,
+ ],
+ 'secondresult'=>[
+ 'color'=>'',
+ 'level'=>'',
+ 'value'=>$key=='jump_time'?implode(':',$this->handle_hour_branch_second($after_arr)):$after_arr,
+ 'title'=>$this->request_result['6'][$key][0],
+ 'unit'=>$this->request_result['6'][$key][1],
+ 'name'=>$key,
+ ],
+ 'diffval'=>bcsub($after_arr,$before_arr,2)
+ ];
+ if($key=='jump_time'){
+ $temporary_arr['diffval'] = $temporary_arr['diffval'] >= 0?implode(':',$this->handle_hour_branch_second($temporary_arr['diffval'])):'-'.implode(':',$this->handle_hour_branch_second($temporary_arr['diffval']));
+ }
+ array_push($return_data['list'], $temporary_arr);
+
+ }
+
+ }
+ return $this->msg($return_data);
+ }
+ // 数据对比(肺活)
+ public function get_vitalcapacity_data_contrast($data){
+ $data2 = [$data['before_id'],$data['after_id']];
+ $data3 = implode(',',$data2);
+ $calculate_arr = [];
+ $result = Db::query("
+ select
+ acsd.id,
+ acsd.one_val,
+ acsd.two_val,
+ acsd.three_val,
+ acsd.average_val,
+ acsd.score_val as score,
+ acsd.record_time,
+ REPLACE(CONVERT(varchar(10), acsd.record_time, 23), '-', '-') AS b_time,
+ aud.nickname,
+ aud.gender,
+ aud.birthday,
+ aud.head_pic
+ from ".$this->index_db_name['vitalcapacity']." as acsd
+ left join ".$this->index_db_name['juese']." as aud on acsd.aud_id=aud.id
+ where acsd.id in ($data3)
+ and acsd.is_del = 0
+ ");
+
+ if(!$result || count($result)<2){
+ return $this->msg(10004);
+ }
+ // 调整顺序
+ foreach ($result as $key => $value) {
+ if($value['id'] == $data2[0]){
+ $calculate_arr['before'] = $value;
+ }else{
+ $calculate_arr['after'] = $value;
+ }
+ }
+ $return_data['time'] = $calculate_arr['before']['b_time'].'-'.$calculate_arr['after']['b_time'];
+ $return_data['headimg'] = $calculate_arr['before']['head_pic'];
+ $return_data['name'] = $calculate_arr['before']['nickname'];
+ $return_data['gender'] = $calculate_arr['before']['gender'];
+ $return_data['age'] = $this->calculate_age($calculate_arr['before']['birthday']);
+ $return_data['day'] = abs($this->daysSince($calculate_arr['before']['record_time'],$calculate_arr['after']['record_time']));
+
+ $return_data['list'] = [];
+ foreach ($calculate_arr['before'] as $key => $value) {
+ if(in_array($key, ['one_val','two_val','three_val','average_val','score_val'])){
+ $before_arr = $value;
+ $after_arr = $calculate_arr['after'][$key];
+ $temporary_arr = [
+ 'firstresult'=>[
+ 'color'=>'',
+ 'level'=>'',
+ 'value'=>$before_arr,
+ 'title'=>$this->request_result['8'][$key][0],
+ 'unit'=>$this->request_result['8'][$key][1],
+ 'name'=>$key,
+ ],
+ 'secondresult'=>[
+ 'color'=>'',
+ 'level'=>'',
+ 'value'=>$after_arr,
+ 'title'=>$this->request_result['8'][$key][0],
+ 'unit'=>$this->request_result['8'][$key][1],
+ 'name'=>$key,
+ ],
+ 'diffval'=>bcsub($after_arr,$before_arr,2)
+ ];
+ array_push($return_data['list'], $temporary_arr);
+
+ }
+
+ }
+ return $this->msg($return_data);
+ }
+
+
+ ################################################################内部调用################################################################
+ ################################################################内部调用################################################################
+ // 检测版本及判断是否登录失效
+ public function login_invalid_version($data){
+ // 获取客户端IP
+ $ip = request()->ip();
+ // 调用IP识别方法
+ $region = $this->getIpInfo($ip);
+ // 解析地区信息
+ $regionParts = explode('|', $region);
+ $country = $regionParts[0] ?? '';
+ // 判断国家是否在支持的语言列表中
+ $language = '';
+ if ($country && $country !== '0') {
+ $languageMap = [
+ '中国' => 'zh-Hans',
+ '美国' => 'en',
+ '英国' => 'en',
+ '西班牙' => 'es',
+ '法国' => 'fr',
+ '葡萄牙' => 'pt',
+ '阿拉伯联合酋长国' => 'ar',
+ '俄罗斯' => 'ru',
+ '德国' => 'de'
+ ];
+ $language = $languageMap[$country] ?? '';
+ }
+ // 检查语言是否在支持列表中
+ $language_all = new Language();
+ $isSupportedLanguage = array_key_exists($language, $language_all->getSupportedLanguages());
+
+ $result = Db::table($this->index_db_name['banben'])->order('is_del,id desc')->find();
+ if($result){
+ $version = $result['version_num_original'];
+ $url = $result['download_url'];
+ }else{
+ $version = '';
+ $url = '';
+ }
+ if(!array_key_exists('token', $data)){
+ return [['code'=>-1,'description'=>'已过期'],['version'=>$version,'url'=>$url,'language'=>'zh-Hans','language_arr'=>$this->process_Language()]];
+ }else{
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005);
+ }
+ $user_token_state = $this->token_time_validate($data['token']);
+ $language_data = $this->pd_language($user_token_state['language'],$isSupportedLanguage,$language);
+ if($user_token_state['state'] === false){
+ return [['code'=>-1,'description'=>'已过期'],['version'=>$version,'url'=>$url,'language'=>$language_data,'language_arr'=>$this->process_Language()]];
+ }else{
+ return [['code'=>0,'description'=>'未过期'],['version'=>$version,'url'=>$url,'language'=>$language_data,'language_arr'=>$this->process_Language()]];
+ }
+ }
+ }
+ // 添加IP信息获取方法
+ protected function getIpInfo($ip) {
+ // 默认IP
+ $ip = $ip ?: request()->ip();
+ try {
+ $ip2region = new \Ip2Region();
+ $info = $ip2region->memorySearch($ip);
+ // 返回国家信息
+ return $info['region'] ?: '未知';
+ } catch (\Exception $e) {
+ return '未知';
+ }
+ }
+ public function pd_language($user_language,$isSupportedLanguage,$language){
+ if(!$user_language){
+ if($isSupportedLanguage){
+ $result = $language;
+ }else{
+ $result = 'zh-Hans'; // 默认语言为中文
+ }
+ }else{
+ $result = $user_language;
+ }
+ return $result;
+ }
+ // 处理返回的语言数组
+ protected function process_Language(){
+ $temporary_arr = [];
+ foreach ($this->language_country as $key => $value) {
+ array_push($temporary_arr,['key'=>$key,'value'=>$value]);
+ }
+ return $temporary_arr;
+ }
+
+
+
+ // 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();
+
+
+ // }
+
}
\ No newline at end of file
diff --git a/application/NewReedaw/controller/app/Language.php b/application/NewReedaw/controller/app/Language.php
new file mode 100644
index 0000000..141bcac
--- /dev/null
+++ b/application/NewReedaw/controller/app/Language.php
@@ -0,0 +1,211 @@
+ 'English',
+ 'zh-Hans' => 'Chinese',
+ 'es' => 'Spanish',
+ 'fr' => 'French',
+ 'pt' => 'Portuguese',
+ 'ar' => 'Arabic',
+ 'ru' => 'Russian',
+ 'de' => 'German'
+ ];
+
+ // 语言映射表
+ protected $languageMap = [
+ 'en' => [
+ '操作成功' => 'Success',
+ '体重' => 'Weight',
+ '身高' => 'Height',
+ '消瘦' => 'Slim',
+ '正常' => 'Normal',
+ '偏重' => 'Overweight',
+ '肥胖' => 'Obesity',
+ '反映和衡量一个人健康状况的重要标志之一' => "One of the important indicators reflecting and measuring a person's health status",
+ '人体纵向部分的长度,源于人体的纵向生长,受遗传因素的影响较大' => "The length of the longitudinal part of the human body is derived from its longitudinal growth and is greatly influenced by genetic factors",
+ 'BMI是身体质量指数,是目前国际上常用的衡量人体胖瘦程度以及是否健康的一个标准。' => "BMI is the body mass index, which is currently a commonly used international standard for measuring the degree of body fat, thinness, and health.",
+ '公斤' => "kg",
+ 'CM' => "cm",
+ '年' => "-",
+ '月' => "-",
+ '日' => "",
+ '身体得分' => "Physical score",
+ '分' => "score",
+ '身体类型' => "body type",
+ '健美肌肉型' => "Bodybuilding muscle type",
+ '低' => "Low",
+ '偏低' => "Slightly low",
+ '标准' => "Standard",
+ '偏高' => "Slightly high",
+ '高' => "High",
+ '矮' => "Short",
+ '偏矮' => "Slightly short",
+ '脂肪率' => "Body Fat Percentage",
+ '体脂率是指身体成分中,脂肪组织所占的比率。测量体脂率比单纯的只测量体重更能反映我们身体的脂肪水平(肥胖程度)。' => "Body fat percentage refers to the proportion of fat tissue in body composition. Measuring it provides a more accurate reflection of body fat levels (degree of obesity) than weight measurement alone.",
+ '脂肪量' => "Fat Mass",
+ '人体脂肪的重量' => "Body Fat Weight",
+ '肌肉率' => "Muscle Percentage",
+ '优' => "Excellent",
+ '根据人体肌肉总量和人体体重、身高等相结合得到的人体的一个比例值,这个值的范围决定一个人的身体健康状况以及力量的多少。' => "Muscle percentage is a ratio derived from total muscle mass, body weight, height, etc. Its range determines a person's health status and strength level.",
+ '肌肉量' => "Muscle Mass",
+ '不足' => "Insufficient",
+ '肌肉量=实际体重*肌肉率' => "Muscle Mass = Actual Weight × Muscle Percentage",
+ '水分' => "Body Water",
+ '指人体内水分比例。' => "Refers to the proportion of water in the human body.",
+ '蛋白量' => "Protein Mass",
+ '蛋白量=实际体重*蛋白率' => "Protein Mass = Actual Weight × Protein Percentage",
+ '骨重' => "Bone Mass",
+ '单位体积内,骨组织、骨矿物质(钙、磷等)和骨基质(骨胶原、蛋白率、无机盐等等)含量,骨量代表它们骨骼健康的情况。' => "Bone mass refers to the content of bone tissue, minerals (calcium, phosphorus, etc.), and bone matrix (collagen, proteins, inorganic salts, etc.) per unit volume, reflecting skeletal health.",
+ '蛋白率' => "Protein Percentage",
+ '人体内蛋白率含量。' => "The proportion of protein in the human body.",
+ '基础代谢' => "Basal Metabolic Rate (BMR)",
+ '指人体在清醒而又极端安静的状态下,不受肌肉活动、环境温度、食物及精神紧张等影响时的能量代谢率' => "The energy expenditure rate when the body is awake, completely at rest, and unaffected by muscle activity, ambient temperature, food intake, or mental stress.",
+ '内脏指数' => "Visceral Fat Index",
+ '警惕' => "Caution",
+ '危险' => "Danger",
+ '内脏脂肪指数' => "Visceral Fat Level",
+ '皮下脂肪' => "Subcutaneous Fat",
+ '皮下脂脂肪就是贮存于皮下的脂肪组织,人体的脂肪大约有2/3贮存在皮下组织' => "Subcutaneous fat refers to adipose tissue stored under the skin. About two-thirds of body fat is stored subcutaneously.",
+ '肥胖等级' => "Obesity Level",
+ '体重不足' => "Underweight",
+ '肥胖的程度,表现实际体重与理想体重的差距。肥胖等级是判定肥胖症的一个指标。' => "Obesity level indicates the disparity between actual and ideal weight, serving as a diagnostic criterion for obesity.",
+ '孩子可能存在营养不良:对于处在生长发育期的孩子而言,蛋白质、碳水化合物、维生素和矿物质这四类营养素非常重要。建议补充足够的蛋白质、锌、钙、铁、维生素D、赖氨酸等营养。建议补充含鸡内金山楂膏健脾开胃类药食同源食物。' => "The child may be malnourished: For growing children, protein, carbohydrates, vitamins, and minerals are critical. Ensure adequate intake of protein, zinc, calcium, iron, vitamin D, lysine, etc. Consider herbal foods like chicken gizzard-hawthorn paste to improve digestion and appetite.",
+ '孩子可能存在营养不良:对于处在生长发育期的孩子而言,最有利于长高的营养素是蛋白质、碳水化合物、维生素和矿物质四类。建议补充足够的蛋白质、锌、铁、钙、维生素D、赖氨酸等营养。' => "The child may be malnourished: For children in their growth and development stage, the most beneficial nutrients for height growth are proteins, carbohydrates, vitamins, and minerals. It is recommended to ensure adequate intake of nutrients such as protein, zinc, iron, calcium, vitamin D, and lysine.",
+ '坚持适当、科学的跳跃运动能够科学地增加学生体重,能够改善学 生体重过低的情况;同时运动会消耗能量并加速胃肠蠕动,这会使孩子的食欲大开,再配合均衡的营养有利于孩子增重。' => "Moderate, scientifically designed jumping exercises can help underweight students gain weight by boosting energy expenditure and gastrointestinal motility, thereby increasing appetite. Combined with balanced nutrition, this supports healthy weight gain.",
+ '3-7岁的孩子:骑两轮车、拍踢球、打篮球、游泳、爬山,每天高强度运动不超过30分钟。' => "Ages 3–7: Bicycling, ball games, basketball, swimming, hiking. Limit high-intensity exercise to 30 minutes daily.",
+ '该年龄段睡眠时间建议:9-11小时' => "Recommended sleep duration for this age group: 9–11 hours.",
+ '孩子开始对于赞赏、鼓励、认同和肯定有需求,而且此阶段父亲在孩子的性格塑造、情绪控制以及责任感培养方面扮演着重要的角色,必须告诉孩子什么事应该做、什么事不应该做,并经常性地给孩子一些积极地暗示。例如,可以时常向孩子表达“我会一直在你身边,不要害怕””我对你的进步都看在眼里等类似的话语。' => "Children begin to crave praise, encouragement, and validation. Fathers play a key role in shaping character, emotional regulation, and responsibility during this phase. Clearly define boundaries while offering positive affirmations (e.g., 'I’m always here for you,' 'I see your progress').",
+ '《中华人民共和国卫生行业标准WS 423-2013》' => "《Chinese Health Industry Standard WS 423-2013》",
+ '《中华人民共和国卫生行业标准WS/T 612-2018》' => "《Chinese Health Industry Standard WS/T 612-2018》",
+ '《中华人民共和国卫生行业标准WS/T1586-2018》' => "《Chinese Health Industry Standard WS/T 1586-2018》",
+ '《WHO 5~19岁身高/体重判定标准》' => "《WHO Growth Reference for Children and Adolescents (5–19 Years)》",
+ '头围' => "Head Circumference",
+ '头围是指绕头部一周的最大长度,头围的大小与脑的发育密切相关' => "Head circumference refers to the maximum length around the head. Its measurement is closely related to brain development.",
+
+ ],
+ // 可以添加更多语言映射
+ ];
+
+ /**
+ * 处理多国语言翻译
+ *
+ * @param string $language 目标语言代码
+ * @param mixed $data 要翻译的数据(字符串或数组)
+ * @return mixed 翻译后的数据
+ */
+ public function handling_languages_from_multiple_countries($language, $data)
+ {
+
+ // dump($data);
+ // 验证语言是否支持
+ if (!$this->isLanguageSupported($language)) {
+ return $this->msg($data['data']);
+ }
+
+ // 如果是数组,递归处理每个元素
+ if (is_array($data)) {
+ // dump(2);
+ $data = $this->translateArray($language, $data);
+ return $this->msg($data['data']);
+ }
+
+ // 如果是字符串,直接翻译
+ if (is_string($data)) {
+ // dump(3);
+ return $this->translateString($language, $data);
+ }
+
+ // dump($data);
+ // 其他类型直接返回
+ return $this->msg($data['data']);
+ }
+
+ /**
+ * 检查语言是否支持
+ *
+ * @param string $language 语言代码
+ * @return bool
+ */
+ protected function isLanguageSupported($language)
+ {
+ return isset($this->supportedLanguages[$language]);
+ }
+
+ /**
+ * 翻译数组
+ *
+ * @param string $language 目标语言
+ * @param array $array 要翻译的数组
+ * @return array 翻译后的数组
+ */
+ protected function translateArray($language, array $array)
+ {
+ $result = [];
+ foreach ($array as $key => $value) {
+ // 保持键不变,只翻译值
+ $result[$key] = is_array($value)
+ ? $this->translateArray($language, $value)
+ : $this->translateString($language, $value);
+ }
+ return $result;
+ }
+
+ /**
+ * 翻译字符串
+ *
+ * @param string $language 目标语言
+ * @param string $string 要翻译的字符串
+ * @return string 翻译后的字符串
+ */
+ protected function translateString($language, $string)
+ {
+ // dump($string);
+ // 检查是否有该语言的映射表
+ if (!isset($this->languageMap[$language])) {
+ return $string;
+ }
+
+ // 检查是否有对应的翻译
+ return $this->languageMap[$language][$string] ?? $string;
+ }
+
+ /**
+ * 获取支持的语言列表
+ *
+ * @return array
+ */
+ public function getSupportedLanguages()
+ {
+ return $this->supportedLanguages;
+ }
+
+ /**
+ * 添加新的语言翻译
+ *
+ * @param string $language 语言代码
+ * @param array $translations 翻译映射数组
+ * @return bool
+ */
+ public function addTranslations($language, array $translations)
+ {
+ if (!$this->isLanguageSupported($language)) {
+ return false;
+ }
+
+ if (!isset($this->languageMap[$language])) {
+ $this->languageMap[$language] = [];
+ }
+
+ $this->languageMap[$language] = array_merge(
+ $this->languageMap[$language],
+ $translations
+ );
+
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/application/NewReedaw/controller/app/Role.php b/application/NewReedaw/controller/app/Role.php
index 90bf494..2548d7c 100644
--- a/application/NewReedaw/controller/app/Role.php
+++ b/application/NewReedaw/controller/app/Role.php
@@ -112,7 +112,7 @@ class Role extends Base{
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)){
+ if(!array_key_exists('token', $data) || !array_key_exists('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'){
@@ -121,8 +121,8 @@ class Role extends Base{
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['id'],'intnum')){
+ return $this->msg(10005,'id type error');
}
if(!$this->verify_data_is_ok($data['birthday'],'datetime')){
return $this->msg(10005,'birthday type error');
@@ -273,7 +273,7 @@ class Role extends Base{
$parameter['card_order'] = $address_data['recommend_cards'];
}
- $return_result = Db::table($this->role_db_name['juese'])->where(['id'=>$data['aud_id']])->update($parameter);
+ $return_result = Db::table($this->role_db_name['juese'])->where(['id'=>$data['id']])->update($parameter);
if($return_result){
return $this->msg([]);
}else{
diff --git a/application/NewReedaw/controller/app/Skip.php b/application/NewReedaw/controller/app/Skip.php
new file mode 100644
index 0000000..90d39c2
--- /dev/null
+++ b/application/NewReedaw/controller/app/Skip.php
@@ -0,0 +1,582 @@
+'app_account_number',
+ 'juese'=>'app_user_data',
+ 'body'=>'app_card_body_data',
+ 'skip'=>'app_card_skip_data',
+
+ ];
+ protected $curve_data_format = ['jump_num'=>['跳绳个数','个','#009DFF'],'jump_time'=>['跳绳时长','分钟','#009DFF'],'jump_kcal'=>['消耗卡路里','kcal','#009DFF']];
+ // protected $skip_use_db_name = [
+ // '1'=>'app_card_skip_data',
+ // '2'=>'app_user_data',
+ // '3'=>'app_card_body_data',
+ // ];
+ protected $pagesize = 15;
+ // 加 bcadd(,,20)
+ // 减 bcsub(,,20)
+ // 乘 bcmul(,,20)
+ // 除 bcdiv(,,20)
+ // 测试token=>'caadd1be045a65f30b92aa805f1de54a'
+
+ ################################################################接口################################################################
+ ################################################################接口################################################################
+ ################################################################接口################################################################
+
+ // 手动记录
+ public function manual_record(){
+ try {
+ $data = input('post.');
+ if(!array_key_exists('aud_id', $data) || !array_key_exists('r_time', $data) || !array_key_exists('num', $data) || !array_key_exists('time_m', $data) || !array_key_exists('time_s', $data) || !array_key_exists('type', $data) || !array_key_exists('token', $data)){
+ $return_data = $this->msg(10001);
+ }
+ 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['r_time'],'datetime')){
+ return $this->msg(10005,'r_time type error');
+ }
+ if(!$this->verify_data_is_ok($data['type'],'str')){
+ return $this->msg(10005,'type type error');
+ }
+ if(!$this->verify_data_is_ok($data['num'],'intnum') || !$this->verify_data_is_ok($data['time_m'],'intnum') || !$this->verify_data_is_ok($data['time_s'],'intnum')){
+ return $this->msg(10005,'跳绳数量或者分钟、秒钟值必须为整数');
+ }
+ if($data['num'] <= 0){
+ return $this->msg(10005,'跳绳数不能小于等于0');
+ }
+ if(abs($data['time_s']) >= 60){
+ return $this->msg(10005,'秒钟值不能大于60');
+ }
+ unset($data['token']);
+ if($this->validate_user_identity($data['aud_id']) === false){
+ return $this->msg(10003);
+ }
+ return $this->manual_record_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 device_record(){
+ try {
+ $data = input('post.');
+ if(!array_key_exists('aud_id', $data) || !array_key_exists('kcal', $data) || !array_key_exists('num', $data) || !array_key_exists('time_m', $data) || !array_key_exists('time_s', $data) || !array_key_exists('type', $data) || !array_key_exists('token', $data)){
+ $return_data = $this->msg(10001);
+ }
+ if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
+ return $this->msg(10005);
+ }
+ if(!$this->verify_data_is_ok($data['kcal'],'num')){
+ return $this->msg(10005);
+ }
+ if(!$this->verify_data_is_ok($data['type'],'str')){
+ return $this->msg(10005);
+ }
+ if(!$this->isValidInteger($data['num']+0) || !$this->isValidInteger($data['time_m']+0) || !$this->isValidInteger($data['time_s']+0)){
+ $return_data = $this->msg(10005,'跳绳数量或者分钟、秒钟值必须为整数');
+ }
+ if($data['num'] <= 0){
+ $return_data = $this->msg(10005,'跳绳数不能小于等于0');
+ }
+ if(abs($data['time_s']) >= 60){
+ $return_data = $this->msg(10005,'秒钟值不能大于60');
+ }
+ unset($data['token']);
+ if($this->validate_user_identity($data['aud_id']) === false){
+ $return_data = $this->msg(10003);
+ }
+ $return_data = $this->manual_record_action($data);
+
+ // 成功
+ $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'] .= "行号: " . $e->getLine() . "\n";
+ $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
+ $this->record_api_log($data, $logContent, null);
+ return $this->msg(99999);
+ }
+ }
+ // 数据报告
+ public function data_report(){
+ try {
+ $data = input('post.');
+ if(!array_key_exists('aud_id', $data) || !array_key_exists('token', $data)){
+ return $this->msg(10001);
+ }
+ if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
+ return $this->msg(10005);
+ }
+ unset($data['token']);
+ return $this->data_report_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 curve_chart(){
+ try {
+ $data = input('post.');
+ if(!array_key_exists('aud_id', $data) || !array_key_exists('time', $data) || !array_key_exists('token', $data)){
+ return $this->msg(10001);
+ }
+ if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
+ return $this->msg(10005);
+ }
+ unset($data['token']);
+ return $this->curve_chart_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 record_list_page(){
+ try {
+ $data = input('post.');
+ if(!array_key_exists('token', $data) || !array_key_exists('aud_id', $data) || !array_key_exists('page', $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');
+ }
+ if(!$this->verify_data_is_ok($data['page'],'intnum')){
+ return $this->msg(10005,'page type error');
+ }
+ return $this->record_list_page_or_group_action($data,'page');
+ } 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 record_list_group(){
+ try {
+ $data = input('post.');
+ if(!array_key_exists('token', $data) || !array_key_exists('aud_id', $data) || !array_key_exists('s_time', $data) || !array_key_exists('e_time', $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');
+ }
+ if(!$this->verify_data_is_ok($data['s_time'],'datetime')){
+ return $this->msg(10005,'page type error');
+ }
+ if(!$this->verify_data_is_ok($data['e_time'],'datetime')){
+ return $this->msg(10005,'page type error');
+ }
+ return $this->record_list_page_or_group_action($data,'group');
+ } 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 detailed_record(){
+ try {
+ $data = input('post.');
+ if(!array_key_exists('token', $data) || !array_key_exists('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['id'],'intnum')){
+ return $this->msg(10005,'id type error');
+ }
+ return $this->get_all_detaile_data_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 del_record(){
+ try {
+ $data = input('post.');
+ if(!array_key_exists('id', $data) || !array_key_exists('token', $data)){
+ return $this->msg(10001);
+ }
+ if(!$this->verify_data_is_ok($data['id'],'intnum')){
+ return $this->msg(10005);
+ }
+ unset($data['token']);
+ $user_data = Db::table($this->skip_db_name['skip'])->where(['id'=>$data['id']])->update(['is_del'=>1]);
+ if($user_data){
+ return $this->msg([]);
+ }else{
+ return $this->msg(10002);
+ }
+ } 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 manual_record_action($data){
+ // 分秒转换为秒
+ $data['time'] = abs($data['time_m'])*60+abs($data['time_s']);
+ $user_msg_content = Db::table($this->skip_db_name['juese'])->where(['id'=>$data['aud_id']])->count();
+ if($user_msg_content<=0){
+ return $this->msg(10004);
+ }
+ if(!array_key_exists('kcal', $data)){
+ $last_data_body = Db::table($this->skip_db_name['body'])->where(['aud_id'=>$data['aud_id'],'is_del'=>0])->order('record_time desc,id desc')->field('id,weight_val,record_time')->find();
+ if(!$last_data_body){
+ $last_data_body = Db::table($this->skip_db_name['juese'])->where(['id'=>$data['aud_id']])->field('id,weight as weight_val')->find();
+ if(!$last_data_body){
+ return $this->msg(10004);
+ }
+ }
+ $kcal_data = $this->skip_kcal_calculate($data['num'],$data['time'],$last_data_body['weight_val']);
+ }else{
+ // 将时间从秒转换为分钟
+ $minutes = bcdiv($data['time'],60,20);
+ // 计算每分钟的跳绳次数
+ $jumpsPerMinute = bcdiv($data['num'],$minutes,2);
+ $kcal_data['totalCalories'] = $data['kcal'];
+ $kcal_data['averageAchievement'] = $jumpsPerMinute;
+ $kcal_data['caloriesPerMinute'] = bcdiv($kcal_data['totalCalories'],$minutes,2);
+ }
+
+
+ $data_set = [
+ 'create_time'=>date('Y-m-d H:i:s'),
+ 'last_update_time'=>date('Y-m-d H:i:s'),
+ 'jump_num'=>$data['num'],
+
+ 'jump_time'=>$data['time'],
+ 'jump_kcal'=>$kcal_data['totalCalories'],
+ 'average_num'=>$kcal_data['averageAchievement'],
+ 'average_kcal'=>$kcal_data['caloriesPerMinute'],
+ 'aud_id'=>$data['aud_id'],
+ 'record_time'=>array_key_exists('r_time', $data)?$data['r_time']:date('Y-m-d H:i:s'),
+ 'jump_type'=>$data['type']
+ ];
+ if(strlen($data_set['record_time']) <= 12){
+ $data_set['record_time'] = $this->addCurrentTimeToDateString($data_set['record_time']);
+ }
+ $last_data_body = Db::table($this->skip_db_name['skip'])->insert($data_set);
+ $result = [
+ 'today_jump_num'=>0,
+ 'today_jump_time'=>0,
+ 'today_jump_kcal'=>0,
+ ];
+ $all_data = Db::table($this->skip_db_name['skip'])->where(['aud_id'=>$data['aud_id']])->whereTime('record_time','today')->field('jump_num,jump_time,jump_kcal')->select();
+ foreach ($all_data as $key => $value) {
+ $result['today_jump_num'] = $result['today_jump_num']+$value['jump_num'];
+ $result['today_jump_time'] = $result['today_jump_time']+$value['jump_time'];
+ $result['today_jump_kcal'] = bcadd($result['today_jump_kcal'],$value['jump_kcal'],2);
+ }
+ $result['last_jump_num'] = $data['num'];
+ $result['last_jump_time'] = $data['time'];
+ $result['last_jump_kcal'] = $data_set['jump_kcal'];
+ // $result['last_record_time'] = str_replace('-', '/', $data_set['record_time']);
+ $result['last_record_time'] = $data_set['record_time'];
+ $time_conversion = $this->handle_hour_branch_second($result['today_jump_time']);
+ $result['today_jump_time'] = $time_conversion['h'].':'.$time_conversion['m'].':'.$time_conversion['s'];
+ $time_conversion = $this->handle_hour_branch_second($result['last_jump_time']);
+ $result['last_jump_time'] = $time_conversion['h'].':'.$time_conversion['m'].':'.$time_conversion['s'];
+ return $this->msg($result);
+ }
+ public function data_report_action($data){
+ $all_data = Db::table($this->skip_db_name['skip'])->where(['aud_id'=>$data['aud_id']])->whereTime('record_time','today')->field('jump_num,jump_time,jump_kcal')->select();
+ $last_data = Db::table($this->skip_db_name['skip'])->where(['aud_id'=>$data['aud_id']])->order('record_time desc,id desc')->field('id,jump_num,jump_time,jump_kcal,record_time')->find();
+ $result = [
+ 'today_jump_num'=>0,
+ 'today_jump_time'=>0,
+ 'today_jump_kcal'=>0,
+ ];
+ foreach ($all_data as $key => $value) {
+ $result['today_jump_num'] = $result['today_jump_num']+$value['jump_num'];
+ $result['today_jump_time'] = $result['today_jump_time']+$value['jump_time'];
+ $result['today_jump_kcal'] = bcadd($result['today_jump_kcal'],$value['jump_kcal'],2);
+ }
+ if($last_data){
+ $result['last_jump_num'] = $last_data['jump_num'];
+ $result['last_jump_time'] = $last_data['jump_time'];
+ $result['last_jump_kcal'] = $last_data['jump_kcal'];
+ $result['last_record_time'] = $last_data['record_time'];
+ }else{
+ $result['last_jump_num'] = 0;
+ $result['last_jump_time'] = 0;
+ $result['last_jump_kcal'] = 0;
+ $result['last_record_time'] = '';
+ }
+ $time_conversion = $this->handle_hour_branch_second($result['today_jump_time']);
+ $result['today_jump_time'] = $time_conversion['h'].':'.$time_conversion['m'].':'.$time_conversion['s'];
+ $time_conversion = $this->handle_hour_branch_second($result['last_jump_time']);
+ $result['last_jump_time'] = $time_conversion['h'].':'.$time_conversion['m'].':'.$time_conversion['s'];
+ return $this->msg($result);
+ }
+ public function curve_chart_action($data){
+ $audid = $data['aud_id'];
+ $timeData = explode('-', $data['time']);
+ // 根据$timeData的长度构建不同的查询条件
+ $map = ['aud_id' => $audid,'is_del'=>0];
+ switch (count($timeData)) {
+ case 3: // 年月日
+ $map['record_time'] = ['between', [date('Y-m-d 00:00:00', strtotime($timeData[0] . '-' . $timeData[1] . '-' . $timeData[2])), date('Y-m-d 23:59:59', strtotime($timeData[0] . '-' . $timeData[1] . '-' . $timeData[2]))]];
+ break;
+ case 2: // 年月
+ $map['record_time'] = ['between', [date('Y-m-01 00:00:00', strtotime($timeData[0] . '-' . $timeData[1])), date('Y-m-t 23:59:59', strtotime($timeData[0] . '-' . $timeData[1]))]];
+ break;
+ case 1: // 年
+ $map['record_time'] = ['between', [date('Y-01-01 00:00:00', strtotime($timeData[0])), date('Y-12-31 23:59:59', strtotime($timeData[0]))]];
+ break;
+ default:
+ return $this->msg(10005); // 无效的时间数据格式
+ }
+
+ // 使用查询构造器进行查询
+ $result = Db::name($this->skip_db_name['skip'])->where($map)->field('jump_num,jump_time,jump_kcal,aud_id,record_time,jump_type,DATEPART(hour, record_time) AS hour,DATEPART(minute, record_time) AS minute,DATEPART(day, record_time) AS day,DATEPART(month, record_time) AS month')->order('record_time')->select();
+ $return_data = [];
+ if(count($timeData) == 3){
+ $key_condition = 'hour';
+ }else if(count($timeData) == 2){
+ $key_condition = 'day';
+ }else if(count($timeData) == 1){
+ $key_condition = 'month';
+ }
+ foreach ($this->curve_data_format as $key => $value) {
+ $temporary_arr['title'] = $value[0].'('.$value[1].')';
+ $temporary_arr['key'] = $key;
+ $temporary_arr['line']['categories'] = [];
+ $temporary_arr['line']['series'][0]['color'] = $value[2];
+ $temporary_arr['line']['series'][0]['name'] = $value[0].'('.$value[1].')';
+ $temporary_arr['line']['series'][0]['data'] = [];
+ foreach ($result as $k => $v) {
+ if($key_condition == 'hour'){
+ // 每一次的记录都添加进去
+ array_push($temporary_arr['line']['categories'],$result[$k]['hour'].':'.$result[$k]['minute']);
+ array_push($temporary_arr['line']['series'][0]['data'],$result[$k][$key]);
+ }else if($key_condition == 'day'){
+ // 根据天分组
+ if(in_array($result[$k]['month'].'/'.$result[$k][$key_condition],$temporary_arr['line']['categories'])){
+ $num = array_search($result[$k]['month'].'/'.$result[$k][$key_condition], $temporary_arr['line']['categories']);
+ $temporary_arr['line']['series'][0]['data'][$num] = bcadd($temporary_arr['line']['series'][0]['data'][$num],$result[$k][$key],2);
+ }else{
+ array_push($temporary_arr['line']['categories'],$result[$k]['month'].'/'.$result[$k][$key_condition]);
+ array_push($temporary_arr['line']['series'][0]['data'],$result[$k][$key]);
+ }
+
+ }else{
+ // 根据年分组
+ if(in_array($result[$k]['month'].'月',$temporary_arr['line']['categories'])){
+ $num = array_search($result[$k]['month'].'月', $temporary_arr['line']['categories']);
+ $temporary_arr['line']['series'][0]['data'][$num] = bcadd($temporary_arr['line']['series'][0]['data'][$num],$result[$k][$key],2);
+ }else{
+ array_push($temporary_arr['line']['categories'],$result[$k]['month'].'月');
+ array_push($temporary_arr['line']['series'][0]['data'],$result[$k][$key]);
+ }
+ }
+ }
+ array_push($return_data,$temporary_arr);
+ }
+ foreach ($return_data[1]['line']['series'][0]['data'] as $key => $value) {
+ $return_data[1]['line']['series'][0]['data'][$key] = bcdiv($return_data[1]['line']['series'][0]['data'][$key],60,2);
+ }
+ return $this->msg($return_data);
+ }
+ public function record_list_page_or_group_action($data,$type){
+ $return_result = [];
+
+ if($type == 'group'){
+ $data['s_time'] = $data['s_time'].' 00:00:00';
+ $data['e_time'] = $data['e_time'].' 23:59:59';
+ $result = Db::query("
+ select
+ id,
+ CONVERT(varchar(10), record_time, 120) AS r_t,
+ CONVERT(varchar(19), record_time, 120) AS record_time,
+ jump_num as v1,
+ jump_time as v2,
+ jump_kcal as v3
+ from ".$this->skip_db_name['skip']."
+ where aud_id='".$data['aud_id']."'
+ and record_time between '".$data['s_time']."' and '".$data['e_time']."'
+ and is_del = 0
+ order by record_time desc");
+ foreach ($result as $key => $value) {
+ $time_t = $this->handle_hour_branch_second($value['v2']);
+ array_push($return_result, [
+ 'id'=>$value['id'],
+ 'v1'=>$value['v1'],
+ 'v2'=>$time_t['h'].':'.$time_t['m'].':'.$time_t['s'],
+ 'v3'=>$value['v3'],
+ 'v1_name'=>'个数',
+ 'v2_name'=>'时长',
+ 'v3_name'=>'卡路里',
+ // 'r_t'=>str_replace('-', '/', $value['r_t'])
+ 'r_t'=>$value['r_t']
+ ]);
+ }
+ }else{
+ $result = Db::table($this->skip_db_name['skip'])->where(['aud_id'=>$data['aud_id'],'is_del'=>0])->field("id,record_time,REPLACE(record_time, '-', '-') AS b_time,jump_num,jump_time,jump_kcal")->order('record_time desc')->page($data['page'],$this->pagesize)->select();
+ $return_result['totalrows'] = Db::table($this->skip_db_name['skip'])->where(['aud_id'=>$data['aud_id']])->count();
+ $return_result['rows'] = [];
+ $return_result['pageno'] = $data['page'];
+ $return_result['pagesize'] = $this->pagesize;
+ $return_result['totalpage'] = ceil($return_result['totalrows']/$this->pagesize);
+ foreach ($result as $key => $value) {
+ $time_t = $this->handle_hour_branch_second($value['jump_time']);
+ array_push($return_result['rows'],[
+ 'id'=>$value['id'],
+ 'v1'=>$value['jump_num'],
+ 'v2'=>$time_t['h'].':'.$time_t['m'].':'.$time_t['s'],
+ 'v3'=>$value['jump_kcal'],
+ 'v1_name'=>'个数',
+ 'v2_name'=>'时长',
+ 'v3_name'=>'卡路里',
+ 'record_time'=>$value['b_time'],
+ ]);
+ }
+ }
+ return $this->msg($return_result);
+ }
+ public function get_all_detaile_data_action($data){
+
+ $result = $result = Db::table($this->skip_db_name['skip'])->where(['id'=>$data['id'],'is_del'=>0])->find();
+ $for_data_arr = ['jump_num'=>['个数',''],'jump_time'=>['时长',''],'jump_kcal'=>['卡路里','kcal']];
+ if($result){
+ $result_data = [];
+ foreach ($for_data_arr as $key => $value) {
+ $temporary_arr['key_name'] = $key;
+ $temporary_arr['name'] = $value[0];
+ $temporary_arr['value'] = explode(',',$result[$key])[0];
+ $temporary_arr['unit'] = $value[1];
+ array_push($result_data,$temporary_arr);
+ }
+ return $this->msg($result_data);
+ }else{
+ return $this->msg(10002);
+ }
+
+ }
+
+ ################################################################内部调用################################################################
+ ################################################################内部调用################################################################
+ // 跳绳卡路里计算
+ public function skip_kcal_calculate($num=143, $time=222, $weight=70) {
+ // 加 bcadd(,,20)
+ // 减 bcsub(,,20)
+ // 乘 bcmul(,,20)
+ // 除 bcdiv(,,20)
+ // 将时间从秒转换为分钟
+ $minutes = bcdiv($time,60,20);
+ // 计算每分钟的跳绳次数
+ $jumpsPerMinute = bcdiv($num,$minutes,2);
+ // 根据跳绳次数确定MET值
+ // $met = 11.8;
+ if ($jumpsPerMinute < 100) {
+ $met = 8.8;
+ } else if ($jumpsPerMinute >= 100 && $jumpsPerMinute < 120) {
+ $met = 11.8;
+ } else {
+ $met = 12.3;
+ }
+ // 计算每分钟燃烧的卡路里
+ $caloriesPerMinute = bcdiv(bcmul(bcmul($met,$weight,20),3.5,20),200,2);
+ // 计算总卡路里消耗
+ $totalCalories = bcmul($caloriesPerMinute,$minutes,2);
+ // 返回结果
+ return [
+ 'averageAchievement' => $jumpsPerMinute,
+ 'caloriesPerMinute' => $caloriesPerMinute,
+ 'totalCalories' => $totalCalories
+ ];
+ }
+
+
+}
\ No newline at end of file
diff --git a/application/NewReedaw/controller/app/Vitalcapacity.php b/application/NewReedaw/controller/app/Vitalcapacity.php
new file mode 100644
index 0000000..ff600f6
--- /dev/null
+++ b/application/NewReedaw/controller/app/Vitalcapacity.php
@@ -0,0 +1,639 @@
+'app_account_number',
+ 'juese'=>'app_user_data',
+ 'vitalcapacity'=>'app_card_vitalcapacity_data',
+ 'biaozhun'=>'pc_vitalcapacity_standard',
+
+ ];
+ protected $color = ['无效'=>'#FF5656','不及格'=>'#FF5656','及格'=>'#FFAB00','良好'=>'#5AD06D','优秀'=>'#6492F6','牛逼'=>'#3967D6'];
+ protected $curve_data_format = ['one_val'=>['第一次','容积/ml','#009DFF'],'two_val'=>['第二次','容积/ml','#009DFF'],'three_val'=>['第三次','容积/ml','#009DFF'],'average_val'=>['平均','容积/ml','#009DFF']];
+ protected $pagesize = 15;
+ // 加 bcadd(,,20)
+ // 减 bcsub(,,20)
+ // 乘 bcmul(,,20)
+ // 除 bcdiv(,,20)
+ // 测试token=>'caadd1be045a65f30b92aa805f1de54a'
+
+ ################################################################接口################################################################
+ ################################################################接口################################################################
+ ################################################################接口################################################################
+
+ // 手动记录
+ public function manual_record(){
+ try {
+
+ $data = input('post.');
+ if(!array_key_exists('aud_id', $data) || !array_key_exists('one', $data) || !array_key_exists('two', $data) || !array_key_exists('three', $data) || !array_key_exists('time', $data) || !array_key_exists('token', $data)){
+ return $this->msg(10001);
+ }
+ unset($data['token']);
+ 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['one'],'intnum')){
+ return $this->msg(10005,'one type error');
+ }
+ if(!$this->verify_data_is_ok($data['two'],'intnum')){
+ return $this->msg(10005,'two type error');
+ }
+ if(!$this->verify_data_is_ok($data['three'],'intnum')){
+ return $this->msg(10005,'three type error');
+ }
+ if(!$this->verify_data_is_ok($data['time'],'datetime')){
+ return $this->msg(10005,'time type error');
+ }
+ if(strlen($data['time']) <= 12){
+ // 时间日期转换,把'Y-m-d'转换成'Y-m-d H:i:s'格式
+ $data['time'] = $this->addCurrentTimeToDateString($data['time']);
+ }
+ return $this->manual_record_action($data,'by_hand_means');
+ } 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 device_record(){
+ try {
+ $data = input('post.');
+ if(!array_key_exists('aud_id', $data) || !array_key_exists('one', $data) || !array_key_exists('two', $data) || !array_key_exists('three', $data) || !array_key_exists('token', $data)){
+ return $this->msg(10001);
+ }
+ unset($data['token']);
+ 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['one'],'intnum')){
+ return $this->msg(10005,'one type error');
+ }
+ if(!$this->verify_data_is_ok($data['two'],'intnum')){
+ return $this->msg(10005,'two type error');
+ }
+ if(!$this->verify_data_is_ok($data['three'],'intnum')){
+ return $this->msg(10005,'three type error');
+ }
+ $data['time'] = date('Y-m-d H:i:s');
+ return $this->manual_record_action($data,'by_device');
+ } 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 data_report(){
+ try {
+ $data = input('post.');
+ if(!array_key_exists('aud_id', $data) || !array_key_exists('token', $data)){
+ $return_data = $this->msg(10001);
+ }
+ unset($data['token']);
+ if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
+ return $this->msg(10005,'aud_id type error');
+ }
+ return $this->data_report_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 curve_chart(){
+ try {
+ // 你的业务逻辑
+ if(count(input('post.')) > 0){
+ $data = input('post.');
+ }
+ if(!array_key_exists('aud_id', $data) || !array_key_exists('time', $data) || !array_key_exists('token', $data)){
+ $return_data = $this->msg(10001);
+ }
+ unset($data['token']);
+ 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['time'],'datetime')){
+ return $this->msg(10005,'time type error');
+ }
+ return $this->curve_chart_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 record_list_page(){
+ try {
+ $data = input('post.');
+ if(!array_key_exists('token', $data) || !array_key_exists('aud_id', $data) || !array_key_exists('page', $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');
+ }
+ if(!$this->verify_data_is_ok($data['page'],'intnum')){
+ return $this->msg(10005,'page type error');
+ }
+ return $this->record_list_page_or_group_action($data,'page');
+ } 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 record_list_group(){
+ try {
+ $data = input('post.');
+ if(!array_key_exists('token', $data) || !array_key_exists('aud_id', $data) || !array_key_exists('s_time', $data) || !array_key_exists('e_time', $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');
+ }
+ if(!$this->verify_data_is_ok($data['s_time'],'datetime')){
+ return $this->msg(10005,'page type error');
+ }
+ if(!$this->verify_data_is_ok($data['e_time'],'datetime')){
+ return $this->msg(10005,'page type error');
+ }
+ return $this->record_list_page_or_group_action($data,'group');
+ } 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 detailed_record(){
+ try {
+ $data = input('post.');
+ if(!array_key_exists('token', $data) || !array_key_exists('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['id'],'intnum')){
+ return $this->msg(10005,'id type error');
+ }
+ return $this->get_all_detaile_data_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 del_record(){
+ try {
+ $data = input('post.');
+ if(!array_key_exists('id', $data) || !array_key_exists('token', $data)){
+ return $this->msg(10001);
+ }
+ if(!$this->verify_data_is_ok($data['id'],'intnum')){
+ return $this->msg(10005);
+ }
+ unset($data['token']);
+ $user_data = Db::table($this->vitalcapacity_db_name['vitalcapacity'])->where(['id'=>$data['id']])->update(['is_del'=>1]);
+ if($user_data){
+ return $this->msg([]);
+ }else{
+ return $this->msg(10002);
+ }
+ } 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 manual_record_action($data,$type){
+ $temporary_arr['aud_id'] = $data['aud_id'];
+ $temporary_arr['record_time'] = $data['time'];
+ $temporary_arr['one'] = $data['one'];
+ $temporary_arr['two'] = $data['two'];
+ $temporary_arr['three'] = $data['three'];
+ $temporary_arr['average'] = bcdiv(bcadd(bcadd($data['one'],$data['two'],2),$data['three'],2),3,2);
+ $temporary_arr['create_time'] = date('Y-m-d H:i:s');
+ $temporary_arr['one_val'] = $data['one'];
+ $temporary_arr['two_val'] = $data['two'];
+ $temporary_arr['three_val'] = $data['three'];
+ $temporary_arr['average_val'] = $temporary_arr['average'];
+ $temporary_arr['flow_val'] = array_key_exists('flow', $data)?$data['flow']:'0.00';//流速
+ $temporary_arr['record_type'] = $type;//流速
+ // die;
+ // 处理记录时间
+
+ $user_msg = Db::name($this->vitalcapacity_db_name['juese'])->where(['id'=>$data['aud_id']])->field('id,grade,gender,birthday')->find();
+ // die;
+ if($user_msg){
+ // 根据性别&年级&年龄查规则
+ if($user_msg['grade'] == 'nothing'){
+ // 计算年龄判断是属于哪个年级
+ $user_age = $this->calculate_age($user_msg['birthday']);
+ if($user_age <= 7){
+ $user_msg['grade'] = 'grade_s_1';
+ }else if($user_age == 8){
+ $user_msg['grade'] = 'grade_s_2';
+ }else if($user_age == 9){
+ $user_msg['grade'] = 'grade_s_3';
+ }else if($user_age == 10){
+ $user_msg['grade'] = 'grade_s_4';
+ }else if($user_age == 11){
+ $user_msg['grade'] = 'grade_s_5';
+ }else if($user_age == 12){
+ $user_msg['grade'] = 'grade_s_6';
+ }else if($user_age == 13){
+ $user_msg['grade'] = 'grade_m_1';
+ }else if($user_age == 14){
+ $user_msg['grade'] = 'grade_m_2';
+ }else if($user_age == 15){
+ $user_msg['grade'] = 'grade_m_3';
+ }else if($user_age == 16){
+ $user_msg['grade'] = 'grade_h_1';
+ }else if($user_age == 17){
+ $user_msg['grade'] = 'grade_h_2';
+ }else if($user_age == 18){
+ $user_msg['grade'] = 'grade_h_3';
+ }else if($user_age == 19 || $user_age == 20){
+ $user_msg['grade'] = 'grade_u_12';
+ }else if($user_age >= 21){
+ $user_msg['grade'] = 'grade_u_34';
+ }
+ }
+ $sql_str = "sex = ".$user_msg['gender']." and ".$user_msg['grade']." <= ".$temporary_arr['average_val'];
+ $user_achievement = Db::name($this->vitalcapacity_db_name['biaozhun'])->where($sql_str)->order($user_msg['grade'] .' desc')->field('level,score,'.$user_msg['grade'])->limit(1)->cache(86400)->select();
+ if(count($user_achievement)<=0){
+ $user_achievement[0] = ['level'=>'无效','score'=>'0'];
+ }
+ $temporary_arr['score'] = $user_achievement[0]['score'].','.$user_achievement[0]['level'].','.$this->color[$user_achievement[0]['level']];
+ $temporary_arr['score_val'] = $user_achievement[0]['score'];
+
+ }else{
+ return $this->msg(10004,'未找到有效数据');
+ }
+ $standard_data = $this->get_vitalcapacity_data($data['aud_id']);
+ $temporary_arr['standard_data'] = json_encode($standard_data);
+ $result = Db::table($this->vitalcapacity_db_name['vitalcapacity'])->insert($temporary_arr);
+
+ if($result){
+ $time = $result[0]['record_time'];
+ $time = strtotime($time);
+ $time = date('Y年m月d日 H:i:s', $time);
+ return $this->msg([
+ 'average'=>$temporary_arr['average'].'ml',
+ 'level'=>$user_achievement[0]['level'],
+ 'time'=>$time,
+ 'flow_val'=>$temporary_arr['flow_val'],
+ 'list'=>$standard_data,
+ 'offset'=>$this->vitalcapacity_standard_interval($temporary_arr['average'],$standard_data)
+ ]);
+ }else{
+ return $this->msg(10002);
+ }
+ }
+ public function data_report_action($data){
+ $result = Db::table($this->vitalcapacity_db_name['vitalcapacity'])->where(['aud_id'=>$data['aud_id']])->order('record_time desc')->field('record_time,score,average,flow_val,standard_data')->limit(1)->select();
+
+ if(count($result) <= 0){
+ // return $this->msg(10004);
+ return $this->msg([
+ 'average'=>'',
+ 'level'=>'',
+ 'time'=>'',
+ 'flow_val'=>'',
+ 'list'=>'',
+ 'offset'=>''
+ ]);
+
+ }else{
+
+ $time = $result[0]['record_time'];
+ $time = strtotime($time);
+ $time = date('Y年m月d日 H:i:s', $time);
+ $o_l = explode(',',$result[0]['score']);
+ // $standard_data = $this->get_vitalcapacity_data($data['aud_id']);
+ $standard_data = json_decode($result[0]['standard_data'],true);
+
+ return $this->msg([
+ 'average'=>$result[0]['average'].'ml',
+ 'level'=>$o_l[1],
+ 'time'=>$time,
+ 'flow_val'=>$result[0]['flow_val'] == '.00'?'0.00':$result[0]['flow_val'],
+ 'list'=>$standard_data,
+ 'offset'=>$this->vitalcapacity_standard_interval($result[0]['average'],$standard_data)
+ ]);
+ }
+ }
+ public function curve_chart_action($data){
+ $audid = $data['aud_id'];
+ $timeData = explode('-', $data['time']);
+
+ // 根据$timeData的长度构建不同的查询条件
+ $map = ['aud_id' => $audid];
+ switch (count($timeData)) {
+ case 3: // 年月日
+ $map['record_time'] = ['between', [date('Y-m-d 00:00:00', strtotime($timeData[0] . '-' . $timeData[1] . '-' . $timeData[2])), date('Y-m-d 23:59:59', strtotime($timeData[0] . '-' . $timeData[1] . '-' . $timeData[2]))]];
+ break;
+ case 2: // 年月
+ $map['record_time'] = ['between', [date('Y-m-01 00:00:00', strtotime($timeData[0] . '-' . $timeData[1])), date('Y-m-t 23:59:59', strtotime($timeData[0] . '-' . $timeData[1]))]];
+ break;
+ case 1: // 年
+ $map['record_time'] = ['between', [date('Y-01-01 00:00:00', strtotime($timeData[0])), date('Y-12-31 23:59:59', strtotime($timeData[0]))]];
+ break;
+ default:
+ return $this->msg(10005); // 无效的时间数据格式
+ }
+ // 使用查询构造器进行查询
+ $result = Db::name($this->vitalcapacity_db_name['vitalcapacity'])->where($map)->field('id,one_val,two_val,three_val,average_val,score_val,aud_id,record_time,DATEPART(hour, record_time) AS hour,DATEPART(day, record_time) AS day,DATEPART(month, record_time) AS month')->order('record_time')->select();
+ $return_data = [];
+ if(count($timeData) == 3){
+ $key_condition = 'hour';
+ }else if(count($timeData) == 2){
+ $key_condition = 'day';
+ }else if(count($timeData) == 1){
+ $key_condition = 'month';
+ }
+ foreach ($this->curve_data_format as $key => $value) {
+ $temporary_arr['title'] = $value[0].'('.$value[1].')';
+ $temporary_arr['key'] = $key;
+ $temporary_arr['line']['categories'] = [];
+ $temporary_arr['line']['series'][0]['color'] = $value[2];
+ $temporary_arr['line']['series'][0]['name'] = $value[0].'('.$value[1].')';
+ $temporary_arr['line']['series'][0]['data'] = [];
+ foreach ($result as $k => $v) {
+ if($key_condition == 'hour'){
+ if(in_array($result[$k][$key_condition].'时',$temporary_arr['line']['categories'])){
+
+ $num = array_search($result[$k][$key_condition].'时', $temporary_arr['line']['categories']);
+ // $temporary_arr['line']['series'][0]['data'][$num] = bcadd($temporary_arr['line']['series'][0]['data'][$num],$result[$k][$key],2);
+ $temporary_arr['line']['series'][0]['data'][$num] = $temporary_arr['line']['series'][0]['data'][$num] >= $result[$k][$key]?$temporary_arr['line']['series'][0]['data'][$num]:$result[$k][$key];
+
+ }else{
+ array_push($temporary_arr['line']['categories'],$result[$k][$key_condition].'时');
+ array_push($temporary_arr['line']['series'][0]['data'],$result[$k][$key]);
+ }
+ }else if($key_condition == 'day'){
+ if(in_array($result[$k]['month'].'-'.$result[$k][$key_condition],$temporary_arr['line']['categories'])){
+ $num = array_search($result[$k]['month'].'-'.$result[$k][$key_condition], $temporary_arr['line']['categories']);
+ // $temporary_arr['line']['series'][0]['data'][$num] = bcadd($temporary_arr['line']['series'][0]['data'][$num],$result[$k][$key],2);
+ $temporary_arr['line']['series'][0]['data'][$num] = $temporary_arr['line']['series'][0]['data'][$num] >= $result[$k][$key]?$temporary_arr['line']['series'][0]['data'][$num]:$result[$k][$key];
+ }else{
+ array_push($temporary_arr['line']['categories'],$result[$k]['month'].'-'.$result[$k][$key_condition]);
+ array_push($temporary_arr['line']['series'][0]['data'],$result[$k][$key]);
+ }
+ }else{
+ if(in_array($result[$k]['month'].'月',$temporary_arr['line']['categories'])){
+ $num = array_search($result[$k]['month'].'月', $temporary_arr['line']['categories']);
+ // $temporary_arr['line']['series'][0]['data'][$num] = bcadd($temporary_arr['line']['series'][0]['data'][$num],$result[$k][$key],2);
+ $temporary_arr['line']['series'][0]['data'][$num] = $temporary_arr['line']['series'][0]['data'][$num] >= $result[$k][$key]?$temporary_arr['line']['series'][0]['data'][$num]:$result[$k][$key];
+ }else{
+ array_push($temporary_arr['line']['categories'],$result[$k]['month'].'月');
+ array_push($temporary_arr['line']['series'][0]['data'],$result[$k][$key]);
+ }
+ }
+ }
+ array_push($return_data,$temporary_arr);
+ }
+ return $this->msg($return_data);
+ }
+ public function record_list_page_or_group_action($data,$type){
+ $return_result = [];
+
+ if($type == 'group'){
+ $data['s_time'] = $data['s_time'].' 00:00:00';
+ $data['e_time'] = $data['e_time'].' 23:59:59';
+ $result = Db::query("
+ select
+ id,
+ CONVERT(varchar(10), record_time, 120) AS r_t,
+ CONVERT(varchar(19), record_time, 120) AS record_time,
+ one_val as v1,
+ two_val as v2,
+ three_val as v3,
+ average_val as v4,
+ score as v5
+ from ".$this->vitalcapacity_db_name['vitalcapacity']."
+ where aud_id='".$data['aud_id']."'
+ and record_time between '".$data['s_time']."' and '".$data['e_time']."'
+ and is_del = 0
+ order by record_time desc");
+ foreach ($result as $key => $value) {
+ // $time_t = $this->handle_hour_branch_second($value['v2']);
+ array_push($return_result, [
+ 'id'=>$value['id'],
+ 'v1'=>$value['v1'] == '.00'?'0':$value['v1'],
+ 'v2'=>$value['v2'] == '.00'?'0':$value['v2'],
+ 'v3'=>$value['v3'] == '.00'?'0':$value['v3'],
+ 'v4'=>$value['v4'] == '.00'?'0':$value['v4'],
+ 'v5'=>explode(',',$value['v5'])[0],
+ 'v1_name'=>'第一次',
+ 'v2_name'=>'第二次',
+ 'v3_name'=>'第三次',
+ 'v4_name'=>'平均',
+ 'v5_name'=>'成绩',
+ // 'r_t'=>str_replace('-', '/', $value['r_t'])
+ 'r_t'=>$value['r_t']
+ ]);
+ }
+ }else{
+ $result = Db::table($this->vitalcapacity_db_name['vitalcapacity'])->where(['aud_id'=>$data['aud_id'],'is_del'=>0])->field("id,record_time,REPLACE(record_time, '-', '-') AS b_time,one_val,two_val,three_val,average_val,score")->order('record_time desc')->page($data['page'],$this->pagesize)->select();
+ $return_result['totalrows'] = Db::table($this->vitalcapacity_db_name['vitalcapacity'])->where(['aud_id'=>$data['aud_id']])->count();
+ $return_result['rows'] = [];
+ $return_result['pageno'] = $data['page'];
+ $return_result['pagesize'] = $this->pagesize;
+ $return_result['totalpage'] = ceil($return_result['totalrows']/$this->pagesize);
+ foreach ($result as $key => $value) {
+ // $time_t = $this->handle_hour_branch_second($value['jump_time']);
+ array_push($return_result['rows'],[
+ 'id'=>$value['id'],
+ 'v1'=>$value['one_val'] == '.00'?'0':$value['one_val'],
+ 'v2'=>$value['two_val'] == '.00'?'0':$value['two_val'],
+ 'v3'=>$value['three_val'] == '.00'?'0':$value['three_val'],
+ 'v4'=>$value['average_val'] == '.00'?'0':$value['average_val'],
+ 'v5'=>explode(',',$value['score'])[0],
+ 'v1_name'=>'第一次',
+ 'v2_name'=>'第二次',
+ 'v3_name'=>'第三次',
+ 'v4_name'=>'平均',
+ 'v5_name'=>'成绩',
+ 'record_time'=>$value['b_time']
+ ]);
+ }
+ }
+ return $this->msg($return_result);
+ }
+ public function get_all_detaile_data_action($data){
+
+ $result = $result = Db::table($this->vitalcapacity_db_name['vitalcapacity'])->where(['id'=>$data['id'],'is_del'=>0])->find();
+ $for_data_arr = ['one_val'=>['第一次','ml'],'two_val'=>['第二次','ml'],'three_val'=>['第三次','ml'],'average_val'=>['三次平均','ml'],'score'=>['最后成绩','分']];
+ if($result){
+ $result_data = [];
+ foreach ($for_data_arr as $key => $value) {
+ $temporary_arr['key_name'] = $key;
+ $temporary_arr['name'] = $value[0];
+ $temporary_arr['value'] = explode(',',$result[$key])[0];
+ $temporary_arr['unit'] = $value[1];
+ array_push($result_data,$temporary_arr);
+ }
+ return $this->msg($result_data);
+ }else{
+ return $this->msg(10002);
+ }
+
+ }
+
+ ################################################################内部调用################################################################
+ ################################################################内部调用################################################################
+ // 肺活量判断区间
+ public function vitalcapacity_standard_interval($val,$data){
+ // 缓存一周
+ $result = '';
+ if(!$data || count($data) <= 0){
+ return $result;
+ }
+ $temporary_qj = $data;
+ $max = 0;
+ $min = 0;
+ $num = 0;
+ foreach ($temporary_qj as $key => $value) {
+ if($val >= $value['min_val'] && $val <= $value['max_val']){
+ $max = $value['max_val'];
+ $min = $value['min_val'];
+ $num = $key;
+ break;
+ }
+ }
+
+ $num = count($temporary_qj)-1-$num;
+
+ if($max == 0){
+ if($val >= $temporary_qj[0]['max_val']){
+ $result = 100;
+ }
+ }else{
+ $temporary_num = bcmul(bcdiv(bcsub($val,$min,20),bcsub($max,$min,20),2),bcdiv(100,count($temporary_qj),2),2);
+ $result = bcadd(bcmul(bcdiv(100,count($temporary_qj),2),$num,2),$temporary_num,2);
+ }
+ return $result;
+ }
+ // 肺活量判断区间(根据得分)
+ public function vitalcapacity_standard_interval2($val,$data){
+ // 缓存一周
+ $result = '';
+ if(count($data) <= 0){
+ return $result;
+ }
+ $temporary_qj = $data;
+ $max = 0;
+ $min = 0;
+ $num = 0;
+ foreach ($temporary_qj as $key => $value) {
+ if($val >= $value['min_val'] && $val <= $value['max_val']){
+ $max = $value['max_val'];
+ $min = $value['min_val'];
+ $num = $key;
+ break;
+ }
+ }
+ // 计算每份占比
+ $share_value = bcdiv($temporary_qj[0]['max_val'],count($temporary_qj),1);
+ // 计算在这一段中占多少
+ $result = bcsub($val,$min,1);
+ $result = bcdiv($result,bcsub($max,$min,1),1);
+ $num = count($temporary_qj)-1-$num;
+ $num = bcmul($num,$share_value,1);
+ $result = bcadd($num,$result,1);
+ // $num = count($temporary_qj)-1-$num;
+ // $temporary_num = bcmul(bcdiv(bcsub($val,$min,20),bcsub($max,$min,20),2),bcdiv(100,count($temporary_qj),2),2);
+ // $result = bcadd(bcmul(bcdiv(100,count($temporary_qj),2),$num,2),$temporary_num,2);
+
+ return $result;
+ }
+
+
+}
\ No newline at end of file
diff --git a/application/NewReedaw2/controller/app/Base.php b/application/NewReedaw2/controller/app/Base.php
new file mode 100644
index 0000000..4d491a6
--- /dev/null
+++ b/application/NewReedaw2/controller/app/Base.php
@@ -0,0 +1,742 @@
+'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']);
+ }
+
+
+}
\ No newline at end of file
diff --git a/application/NewReedaw2/controller/app/Body.php b/application/NewReedaw2/controller/app/Body.php
new file mode 100644
index 0000000..eb4f3e1
--- /dev/null
+++ b/application/NewReedaw2/controller/app/Body.php
@@ -0,0 +1,667 @@
+'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){
+
+ // }
+
+
+
+
+
+
+}
\ No newline at end of file
diff --git a/application/NewReedaw2/controller/app/Cardparts.php b/application/NewReedaw2/controller/app/Cardparts.php
new file mode 100644
index 0000000..b062caf
--- /dev/null
+++ b/application/NewReedaw2/controller/app/Cardparts.php
@@ -0,0 +1,487 @@
+'反映和衡量一个人健康状况的重要标志之一',
+ '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;
+ }
+
+}
\ No newline at end of file
diff --git a/application/NewReedaw2/controller/app/Index.php b/application/NewReedaw2/controller/app/Index.php
new file mode 100644
index 0000000..68adcb9
--- /dev/null
+++ b/application/NewReedaw2/controller/app/Index.php
@@ -0,0 +1,298 @@
+'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 genetic_height(){
+ try {
+ $data = input('post.');
+ if(!array_key_exists('dadHeight', $data) || !array_key_exists('momHeight', $data) || !array_key_exists('birthday', $data) || !array_key_exists('sex', $data)){
+ return $this->msg(10001);
+ }
+ unset($data['token']);
+ if(!$this->verify_data_is_ok($data['birthday'],'datetime')){
+ return $this->msg(10005);
+ }
+ if(!$this->verify_data_is_ok($data['dadHeight'],'num')){
+ return $this->msg(10005);
+ }
+ if(!$this->verify_data_is_ok($data['momHeight'],'num')){
+ return $this->msg(10005);
+ }
+ if(!$this->verify_data_is_ok($data['sex'],'intnum')){
+ return $this->msg(10005);
+ }
+
+ // 直接开始业务,请求外部接口start
+ $url = 'https://ybapi.pcxbc.com/api/child/predictheight';
+ $temporary_parameter = [
+ 'dadHeight'=>$data['dadHeight'],
+ 'momHeight'=>$data['momHeight'],
+ 'birthday'=>$data['birthday'],
+ 'sex'=>$data['sex'],
+ ];
+ $request_result = $this->postRequest($url,$temporary_parameter,array('Content-Type:application/json','Origin:http://ybdevice.pcxbc.com'));
+ // 直接开始业务,请求外部接口end
+ return json($request_result);
+ } 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);
+ }
+ }
+ // BMI测评
+ public function bmi_evaluation(){
+ try {
+ $data = input('post.');
+ if(!array_key_exists('height', $data) || !array_key_exists('weight', $data) || !array_key_exists('birthday', $data) || !array_key_exists('sex', $data)){
+ return $this->msg(10001);
+ }
+ unset($data['token']);
+ if(!$this->verify_data_is_ok($data['birthday'],'datetime')){
+ return $this->msg(10005);
+ }
+ if(!$this->verify_data_is_ok($data['height'],'num')){
+ return $this->msg(10005);
+ }
+ if(!$this->verify_data_is_ok($data['weight'],'num')){
+ return $this->msg(10005);
+ }
+ if(!$this->verify_data_is_ok($data['sex'],'intnum')){
+ return $this->msg(10005);
+ }
+
+ // 直接开始业务,请求外部接口start
+ $url = 'http://ybdevice.pcxbc.com/api/result/calcbmi';
+ $temporary_parameter = [
+ 'height'=>$data['height'],
+ 'weight'=>$data['weight'],
+ 'birthday'=>$data['birthday'],
+ 'sex'=>$data['sex'],
+ ];
+ $request_result = $this->postRequest($url,$temporary_parameter,array('Content-Type:application/json','Origin:http://ybdevice.pcxbc.com'));
+ // 直接开始业务,请求外部接口end
+
+ // 处理进度点
+ $return_result =$this->bmi_evaluation_action($request_result);
+ return $return_result;
+ } 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 bmi_evaluation_action($data){
+ // 加 bcadd(,,20)
+ // 减 bcsub(,,20)
+ // 乘 bcmul(,,20)
+ // 除 bcdiv(,,20)
+ if(!array_key_exists('code',$data) || !array_key_exists('data',$data)){
+ return $this->msg(99999,'网络异常,请稍后重试1');
+ }
+ if($data['code'] != 0){
+ return $this->msg(99999,'网络异常,请稍后重试2');
+ }
+ if(!is_array($data['data'])){
+ return $this->msg(99999,'网络异常,请稍后重试3');
+ }
+ if(!array_key_exists('bmi',$data['data']) || !array_key_exists('bmilevel',$data['data']) || !array_key_exists('bmilevelcolor',$data['data']) || !array_key_exists('bmilevellist',$data['data'])){
+ return $this->msg(99999,'网络异常,请稍后重试4');
+ }
+ if(!is_array($data['data']['bmilevellist'])){
+ return $this->msg(99999,'网络异常,请稍后重试5');
+ }
+ $num = 0;
+ $subsection_val = 0;
+ $temporary_subsection_val = null;
+ foreach ($data['data']['bmilevellist'] as $key => $value) {
+ if(!array_key_exists('maxvalue',$value) || !array_key_exists('minvalue',$value)){
+ return $this->msg(99999,'网络异常,请稍后重试6');
+ }
+ // 判断是否可以进行比较,规则是否正确
+ if(is_numeric($value['maxvalue']) && is_numeric($value['minvalue'])){
+ if($data['data']['bmi'] >= $value['minvalue'] && $data['data']['bmi'] < $value['maxvalue']){
+ // 在落点内
+ $subsection_val = bcsub($value['maxvalue'],$value['minvalue'],1);//获取最大最小值差
+ $temporary_subsection_val = bcsub($data['data']['bmi'],$value['minvalue'],1);//获取当前值与最小值差
+ $temporary_subsection_val = bcdiv($temporary_subsection_val,$subsection_val,1);//获取当前值与最小值差与最大最小值差之比
+ $subsection_val = bcdiv(100,count($data['data']['bmilevellist']),1);//每段应该的百分比
+ $temporary_subsection_val = bcmul($subsection_val,$temporary_subsection_val,1);//获取当前值与最小值差与最大最小值差之比与总段数之比
+ $temporary_subsection_val = bcadd($temporary_subsection_val,bcmul($subsection_val,$num,1),1);
+ }else{
+ $num = $num + 1;
+ }
+ }
+ }
+
+ if($temporary_subsection_val === null){
+ if($data['data']['bmi'] >= $data['data']['bmilevellist'][count($data['data']['bmilevellist'])-1]['maxvalue']){
+ $temporary_subsection_val = 100;
+ }else{
+ return $this->msg(99999,'网络异常,请稍后重试7');
+ }
+ }
+ $data['data']['offset'] = $temporary_subsection_val;
+ $data = $data['data'];
+ // 处理key名称一致start
+ foreach ($data['bmilevellist'] as $key => $value) {
+ $data['bmilevellist'][$key]['max_val'] = $value['maxvalue'];
+ $data['bmilevellist'][$key]['min_val'] = $value['minvalue'];
+ unset($data['bmilevellist'][$key]['minvalue']);
+ unset($data['bmilevellist'][$key]['maxvalue']);
+ }
+ // 处理key名称一致end
+ return $this->msg($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();
+
+
+ }
+
+
+}
\ No newline at end of file
diff --git a/application/NewReedaw2/controller/app/Login.php b/application/NewReedaw2/controller/app/Login.php
new file mode 100644
index 0000000..a518d58
--- /dev/null
+++ b/application/NewReedaw2/controller/app/Login.php
@@ -0,0 +1,686 @@
+'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);
+ }
+ }
+ // 重置密码
+ public function reset_password(){
+ try {
+ $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);
+ }
+ return $this->reset_password_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 wechat_quick_login(){
+ try {
+ $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']);
+ if($result['code'] == 0){
+ $user_data = Db::table($this->login_use_db_name['zhanghao'])->where(['tel'=>$result['data']['phoneNumber']])->fidle('token,id,is_del')->find();
+ if($user_data){
+ if($user_data['is_del'] == 1){
+ return $this->msg(10002,'该账号已注销');
+ }
+ 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 $this->msg(['token'=>$set_data['token'],'aan_id'=>$set_user_result],'登录成功');
+ }else{
+ return $this->msg(10002);
+ }
+ }
+ }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 quit_account(){
+ 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);
+ }
+ $result = Db::table($this->login_use_db_name['zhanghao'])->where(['token'=>$data['token']])->count();
+ if($result <= 0){
+ return $this->msg(10003,'账号不存在');
+ }
+ $quit_result = Db::table($this->login_use_db_name['zhanghao'])->where(['token'=>$data['token']])->update(['login_time'=>'2024-09-01 00:00:00']);
+ if($quit_result){
+ return $this->msg([]);
+ }else{
+ return $this->msg(10002);
+ }
+ } 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(){
+ 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);
+ }
+ $result = Db::table($this->login_use_db_name['zhanghao'])->where(['token'=>$data['token']])->count();
+ if($result <= 0){
+ return $this->msg(10003,'账号不存在');
+ }
+ $quit_result = Db::table($this->login_use_db_name['zhanghao'])->where(['token'=>$data['token']])->update(['is_del'=>1,'login_time'=>'2024-08-08 00:00:00']);
+ if($quit_result){
+ return $this->msg([]);
+ }else{
+ return $this->msg(10002);
+ }
+ } 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);
+ // 验证是手机还是邮箱
+ $montage_data = $this->is_tel_email($data['data']);
+ if($montage_data == false){
+ return $this->msg(10005,'账号格式错误,不是手机号或者邮箱');
+ }
+ if($montage_data == 'tel'){
+ // 本公司短信
+ // $result = $this->send_tel_code($data['data'],$num);
+ // 阿里云短信
+ $sms_all = new Smsaliyun;
+ $result = $sms_all->send_sms($data['data'],$num);
+ }else{
+ $result = $this->send_email_code([$data['data']],['title'=>'Reedaw验证码','from_user_name'=>'Reedaw验证码','content'=>$num]);
+ }
+ if(is_array($result) && $result['code'] == 0){
+ cache($data['data'], $num, $this->code_time);
+ // return $this->msg(['code'=>$num]);
+ return $this->msg([]);
+ }else{
+ return $this->msg(10010,'验证码发送失败');
+ }
+ }
+ ###############################################################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']])->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,is_del')->find();
+ if($result){
+ if($result['is_del'] == 1){
+ return $this->msg(10002,'该账号已注销');
+ }
+ 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(10002,'登录失败,验证码错误或失效');
+ }
+ }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,is_del')->find();
+ if($result){
+ if($result['is_del'] == 1){
+ return $this->msg(10002,'该账号已注销');
+ }
+ if($result['password'] == ''){
+ $return_data = $this->msg(10002,'该账户未设密码,请用验证码登录');
+ }
+ if($data['validate_data'] != $result['password']){
+ $return_data = $this->msg(10002,'账号或密码错误');
+ }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_action($data){
+ // 检查验证码
+ $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']])->field('id,token,password')->find();
+ if(!$find_data){
+ return $this->msg(10003,'未核实到账号信息');
+ }
+ if($find_data['password'] == $data['password']){
+ return $this->msg(10002,'新密码不可与旧密码相同');
+ }
+ $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);
+ }
+ return $return_data;
+ }
+ // 发送手机短信(本公司接口)
+ 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 "未收到响应";
+ }
+ }
+ // 手机号区分
+ public 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 = '
+
+
+
+
+
+
+
+ | |
+
+
+
+
+
+
+ |
+
+
+ Reedaw!
+
+
+ |
+
+
+
+
+
+ |
+
+
+ 感谢您选择锐动产品!
+
+
+
+ 以下6位数字是邮箱验证码,请在需要的位置填写以通过验证
+
+
+
+ (如果您从未请求发送邮箱验证码,请忽略此邮件)
+
+
+
+
+ |
+
+
+ '.$content['content'].'
+
+
+ |
+
+
+
+ |
+
+
+
+
+
+ |
+
+
+
+ |
+
+
+ © Zhengzhou Pinchuan Technology Co., Ltd.
+
+
+
+
+
+
+ |
+
+
+ |
+
+
+
+ |
+ |
+
+
+
+ |
+
+
+
';
+
+ $mail->Body = $neirong; //邮件主体内容
+ //发送
+ if (!$mail->Send()) {
+
+ return ['code' => 10003,'msg'=>$mail->ErrorInfo];
+ // return $mail->ErrorInfo;
+ } else {
+ return ['code' => 0];
+ // return 'success';
+ }
+ }
+
+
+ ################################################################other################################################################
+ ################################################################other################################################################
+ ################################################################other################################################################
+ // 检查验证码
+ 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;
+ }
+
+ 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;
+ }
+
+
+
+}
\ No newline at end of file
diff --git a/application/NewReedaw2/controller/app/Role.php b/application/NewReedaw2/controller/app/Role.php
new file mode 100644
index 0000000..90bf494
--- /dev/null
+++ b/application/NewReedaw2/controller/app/Role.php
@@ -0,0 +1,328 @@
+'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);
+ }
+
+
+
+
+
+}
\ No newline at end of file
diff --git a/application/NewReedaw2/controller/app/Smsaliyun.php b/application/NewReedaw2/controller/app/Smsaliyun.php
new file mode 100644
index 0000000..99ea6c9
--- /dev/null
+++ b/application/NewReedaw2/controller/app/Smsaliyun.php
@@ -0,0 +1,135 @@
+ 'LTAI5tQCdWe9Epir3ydXWbzp',
+ 'accessKeySecret' => 'JKLzF0b5AXw2ajhwtem2fhPSUZVOZ5',
+ 'signName' => '郑州巨天信息',
+ // 'signName' => '郑州品传科技',
+ // 'templateCode' => 'SMS_484085215',//reedaw模板 :您好,欢迎使用Reedaw,您的手机验证码是: ${code},验证码一分钟内有效,若非本人操作,请忽略本短信
+ 'templateCode' => 'SMS_491550200',//巨天通用模板 :您好,您的手机验证码是: ${code},请尽快输入避免验证码失效,若非本人操作,请忽略本短信
+ // 'templateCode' => 'SMS_491320295',//品传通用模板 :您好,您的手机验证码是: ${code},请尽快输入避免验证码失效,若非本人操作,请忽略本短信
+ 'regionId' => 'cn-hangzhou'
+ ];
+
+
+ public function send_sms_api(){
+ $data = input();
+ if(!array_key_exists('tel',$data)){
+ return json([
+ 'code'=>10001,
+ 'msg'=>'缺少手机号码',
+ 'data'=>[],
+ ]);
+ }
+ if(!array_key_exists('code',$data)){
+ return json([
+ 'code'=>10002,
+ 'msg'=>'缺少验证码',
+ 'data'=>[],
+ ]);
+ }
+ if(!$this->validatePhoneNumber($data['tel'])){
+ return json([
+ 'code'=>10001,
+ 'msg'=>'手机号码格式错误',
+ 'data'=>[],
+ ]);
+ }
+ if(!$this->validateSixDigitCode($data['code'])){
+ return json([
+ 'code'=>10002,
+ 'msg'=>'验证码格式错误',
+ 'data'=>[],
+ ]);
+ }
+
+ $result = $this->send_sms($data['tel'],$data['code']);
+
+ return json($result);
+ }
+ // 验证函数定义(可以放在单独的文件中)
+ public function validatePhoneNumber($phone) {
+ $pattern = '/^1[3-9]\d{9}$/';
+ return preg_match($pattern, $phone) === 1;
+ }
+
+ public function validateSixDigitCode($code) {
+ $pattern = '/^\d{6}$/';
+ return preg_match($pattern, $code) === 1;
+ }
+
+
+ /**
+ * 发送短信接口
+ * @param string $phone 手机号
+ * @param string $code 验证码
+ */
+ public function send_sms($phone, $code)
+ {
+ try {
+ // 初始化阿里云客户端
+ AlibabaCloud::accessKeyClient(
+ $this->smsConfig['accessKeyId'],
+ $this->smsConfig['accessKeySecret']
+ )
+ ->regionId($this->smsConfig['regionId'])
+ ->asDefaultClient();
+
+ // 发送短信请求
+ $result = AlibabaCloud::rpc()
+ ->product('Dysmsapi')
+ ->version('2017-05-25')
+ ->action('SendSms')
+ ->method('POST')
+ ->host('dysmsapi.aliyuncs.com')
+ ->options([
+ 'query' => [
+ 'RegionId' => $this->smsConfig['regionId'],
+ 'PhoneNumbers' => $phone,
+ 'SignName' => $this->smsConfig['signName'],
+ 'TemplateCode' => $this->smsConfig['templateCode'],
+ 'TemplateParam' => json_encode(['code' => $code]),
+ ],
+ ])
+ ->request();
+
+ $result = $result->toArray();
+ // return $result;
+ if ($result['Code'] == 'OK') {
+ return [
+ 'code' => 0,
+ 'message' => '短信发送成功',
+ 'data' => $result
+ ];
+ } else {
+ return [
+ 'code' => 99999,
+ 'message' => $result['Message'],
+ 'error' => $result
+ ];
+ }
+ } catch (ClientException $e) {
+ return [
+ 'code' => 99998,
+ 'message' => '客户端异常: ' . $e->getErrorMessage(),
+ 'error' => $e->getMessage()
+ ];
+ } catch (ServerException $e) {
+ return [
+ 'code' => 99997,
+ 'message' => '服务端异常: ' . $e->getErrorMessage(),
+ 'error' => $e->getMessage()
+ ];
+ }
+ }
+}
\ No newline at end of file
diff --git a/application/NewReedaw2/controller/app/Wechat.php b/application/NewReedaw2/controller/app/Wechat.php
new file mode 100644
index 0000000..d544794
--- /dev/null
+++ b/application/NewReedaw2/controller/app/Wechat.php
@@ -0,0 +1,119 @@
+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);
+ }
+ }
+
+
+ // 注册
+
+
+
+}
\ No newline at end of file
diff --git a/application/OutsideInterface/controller/ZhiZhaoTuan/ApiJk.php b/application/OutsideInterface/controller/ZhiZhaoTuan/ApiJk.php
new file mode 100644
index 0000000..79cf494
--- /dev/null
+++ b/application/OutsideInterface/controller/ZhiZhaoTuan/ApiJk.php
@@ -0,0 +1,407 @@
+activity_list_action($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'] .= "行号: " . $e->getLine() . "\n";
+ $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
+ // 记录日志
+ $this->record_api_log($data, $logContent, null);
+ return json(['status' => 'error', 'message' => '系统错误']);
+ }
+ }
+ public function details_data(){
+ // 尝试捕获异常
+ try {
+ $data = input('post.');
+ // $data = ['id'=>3];
+ if(!array_key_exists('id', $data)){
+ return $this->msg(10001,'id is miss');
+ }
+
+ if(!$this->verify_data_is_ok($data['id'],'intnum')){
+ return $this->msg(10005,'id type is error');
+ }
+ $return_data = $this->details_data_action($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'] .= "行号: " . $e->getLine() . "\n";
+ $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
+ // 记录日志
+ $this->record_api_log($data, $logContent, null);
+ return json(['status' => 'error', 'message' => '系统错误']);
+ }
+ }
+
+ public function save_activity_data(){
+ // 尝试捕获异常
+ try {
+ $data = input('post.');
+ // $data = '{"id":"3","tel":"13915547489","content":[{"name":"姓名","type":"text","placeholder":"请输入姓名","is_must":"true","value":"大力","error":false},{"name":"电话","type":"text","placeholder":"请输入姓名","is_must":"true","value":"15237988596","error":false},{"name":"性别","type":"select","placeholder":"请选择性别","is_must":"true","options":["男","女"],"value":"男","error":false},{"name":"兴趣","type":"checkbox","placeholder":"请选择兴趣","is_must":"true","options":["跳舞","跳操","跳绳","跳远","跳高"],"value":["跳舞","跳远"],"error":false},{"name":"其他","type":"textarea","placeholder":"","is_must":"false","value":"哈","error":false}],"appid":"wxbbddd1888da43ab0","sessionid":"opv6R67fwcnu7-Rrts_ijylHQLCc"}';
+ // dump($data);
+ // // dump(json_decode($data,true));
+ // die;
+ // $data = json_decode($data,true);
+ if(!array_key_exists('id', $data)){
+ return $this->msg(10001,'id is miss');
+ }
+ if(!array_key_exists('tel', $data)){
+ return $this->msg(10001,'tel is miss');
+ }
+ if(!array_key_exists('content', $data)){
+ return $this->msg(10001,'content is miss');
+ }
+
+ if(!$this->verify_data_is_ok($data['id'],'intnum')){
+ return $this->msg(10005,'id type is error');
+ }
+ // if(!$this->verify_data_is_ok($data['tel'],'intnum')){
+ // return $this->msg(10005,'id type is error');
+ // }
+ $return_data = $this->save_activity_data_action($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'] .= "行号: " . $e->getLine() . "\n";
+ $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
+ // 记录日志
+ $this->record_api_log($data, $logContent, null);
+ return json(['status' => 'error', 'message' => '系统错误']);
+ }
+ }
+
+
+
+
+ ###########################################################################################################################################################
+ ###########################################################################################################################################################
+ ###########################################################################################################################################################
+
+
+ public function activity_list_action($data){
+ $page_now = array_key_exists('page',$data)?$data['page']:1;
+ $page_total = $page_now;
+ $page_num = 20;
+ $zzt_db = Db::connect('zzt_db');
+ $content_num = $zzt_db->table('pc_activity_registration')
+ ->where("is_del = 0")
+ ->count(); // 然后获取结果
+ // dump($content_num);
+ $page_total = ceil($content_num/$page_num);
+
+ $content_list = $zzt_db->table('pc_activity_registration')
+ ->alias('a')
+ ->join('pc_pic_manage b','a.pic = b.id','LEFT')
+ ->where("a.is_del = 0")
+ ->field('a.id,a.title,a.people_num,a.start_time,a.end_time,b.url_data')
+ ->page("$page_now,$page_num")
+ ->select();
+
+ return $this->msg([
+ 'page_now'=>$page_now,
+ 'page_total'=>$page_total,
+ 'content_list'=>$content_list
+ ]);
+
+ }
+
+ public function details_data_action($data){
+
+ $zzt_db = Db::connect('zzt_db');
+ $result = $zzt_db->table('pc_activity_registration')
+ ->alias('a')
+ ->join('pc_pic_manage b','a.pic = b.id','LEFT')
+ ->where(["a.id"=>$data['id']])
+ ->field('a.id,a.title,a.people_num,a.people_num_now,a.start_time,a.end_time,a.text_content,a.form_content,b.url_data as pic')
+ ->find(); // 然后获取结果
+ // dump($result);
+
+ if($result){
+ $result['status'] = 1;
+ // $people_num = $zzt_db->table('pc_activity_registration_log')
+ // ->where(["par_id"=>$data['id']])
+ // ->count();
+
+ if(date('Y-m-d H:i:s') >= $result['end_time']){
+ $result['status'] = 0;
+ }
+ if($result['people_num_now']>=$result['people_num']){
+ $result['status'] = 0;
+ }
+ $result['form_content'] = json_decode($result['form_content'],true);
+ foreach ($result['form_content'] as $key => $value) {
+ if($value['type'] == 'checkbox'){
+ $result['form_content'][$key]['value'] = [];
+ }else{
+ $result['form_content'][$key]['value'] = "";
+ }
+ }
+ unset($result['people_num_now']);
+ return $this->msg($result);
+ }else{
+ return $this->msg(10002);
+ }
+ }
+
+ public function save_activity_data_action($data){
+
+ // $zzt_db = Db::connect('zzt_db');
+
+ // $result = $zzt_db->table('pc_activity_registration')
+ // ->where(["id"=>$data['id']])
+ // ->field('id,people_num,people_num_now,start_time,end_time,form_content')
+ // ->find(); // 然后获取结果
+ // $result['form_content'] = json_decode($result['form_content'],true);
+ // dump($result);
+ // dump($data);
+ // die;
+ // if(!$result){
+ // return $this->msg(10004);
+ // }
+ // if(date('Y-m-d H:i:s') < $result['start_time']){
+ // return $this->msg(10002,'活动还未开始');
+ // }
+ // if(date('Y-m-d H:i:s') > $result['end_time']){
+ // return $this->msg(10002,'活动已经结束');
+ // }
+ // if($result['people_num_now']>=$result['people_num']){
+ // return $this->msg(10002,'名额已报满');
+ // }
+ // $people_log = $zzt_db->table('pc_activity_registration_log')
+ // ->where(["par_id"=>$data['id'],'tel'=>$data['tel']])
+ // ->count(); // 然后获取结果
+ // if($people_log>=1){
+ // return $this->msg(10002,'您已经提交过,请勿重复提交');
+ // }
+
+ // dump();
+ // die;
+
+ if($data['tel'] == ''){
+ $data['tel'] = time();
+ }
+
+
+
+ $zzt_db = Db::connect('zzt_db');
+
+ try {
+ // 开启事务
+ $zzt_db->startTrans();
+
+ // 查询活动基础信息(使用WITH(UPDLOCK)加锁)
+ $result = $zzt_db->table('pc_activity_registration WITH(UPDLOCK)')
+ ->where(["id" => $data['id']])
+ ->field('id,people_num,people_num_now,start_time,end_time,form_content,is_only_once')
+ ->find();
+
+ if (!$result) {
+ return $this->msg(10004);
+ }
+
+ $result['form_content'] = json_decode($result['form_content'], true);
+
+ // 检查活动时间
+ $currentTime = date('Y-m-d H:i:s');
+ if ($currentTime < $result['start_time']) {
+ $zzt_db->rollback();
+ return $this->msg(10002, '活动还未开始');
+ }
+ if ($currentTime > $result['end_time']) {
+ $zzt_db->rollback();
+ return $this->msg(10002, '活动已经结束');
+ }
+
+ // 检查是否可以重复报名
+ if($result['is_only_once'] == 0){ //如果是0不可重复提交
+ $people_log = $zzt_db->table('pc_activity_registration_log')
+ ->where(["par_id" => $data['id'], 'tel' => $data['tel']])
+ ->count();
+
+ if ($people_log >= 1) {
+ $zzt_db->rollback();
+ return $this->msg(10002, '您已经提交过,请勿重复提交');
+ }
+ }
+ // 检查名额
+ if ($result['people_num_now'] >= $result['people_num']) {
+ $zzt_db->rollback();
+ return $this->msg(10002, '名额已报满');
+ }
+
+ // 更新当前人数(SQL Server 语法)
+ $updateResult = $zzt_db->table('pc_activity_registration')
+ ->where(["id" => $data['id']])
+ ->update([
+ "people_num_now" => $zzt_db->raw('people_num_now + 1')
+ ]);
+
+ // 插入报名记录
+ $insertData = [
+ 'par_id' => $data['id'],
+ 'tel' => $data['tel'],
+ 'content' => [],
+ 'create_time' => $currentTime
+ ];
+
+ $tm_data = [];
+ foreach ($data['content'] as $key => $value) {
+ if($value['type'] == 'checkbox'){
+ $tm_data[$value['name']] = implode('CH1',$value['value']);
+ }else{
+ $tm_data[$value['name']] = $value['value'];
+ }
+ }
+
+ // 调试点1:检查数据结构
+ // dump($tm_data);
+ // dump($result['form_content']);
+
+ foreach ($result['form_content'] as $key => $value) {
+
+ if($value['is_must'] == 'true'){// 如果是必填的
+ if(array_key_exists($value['name'],$tm_data)){// 如果包含选项
+ // 这里可能有问题:$tm_data[$value['name']] 可能是字符串,不是数组
+ if(isset($tm_data[$value['name']]) && $tm_data[$value['name']] != ''){// 如果选项有值
+ $insertData['content'][] = ['name'=>$value['name'],'type'=>$value['type'],'value'=>$tm_data[$value['name']]];
+ }else{
+ $zzt_db->rollback();
+ return $this->msg(10002, '必填项目未填('.$value['name'].')');
+ }
+ }else{
+ $zzt_db->rollback();
+ return $this->msg(10002, '项目缺失('.$value['name'].')');
+ }
+
+ }else{
+ if(array_key_exists($value['name'],$tm_data)){// 如果包含选项
+ // 这里可能有问题:$tm_data[$value['name']] 可能是字符串,不是数组
+ if(isset($tm_data[$value['name']]) && $tm_data[$value['name']] != ''){// 如果选项有值
+ $insertData['content'][] = ['name'=>$value['name'],'type'=>$value['type'],'value'=>$tm_data[$value['name']]];
+ }else{
+ $insertData['content'][] = ['name'=>$value['name'],'type'=>$value['type'],'value'=>""];
+ }
+ }else{
+ $insertData['content'][] = ['name'=>$value['name'],'type'=>$value['type'],'value'=>""];
+ }
+
+ }
+ }
+
+ // 调试点2:检查最终的插入数据
+ // dump($insertData);
+ $insertData['content'] = json_encode($insertData['content']);
+ // 检测表单内容是否重复
+ $people_log2 = $zzt_db->table('pc_activity_registration_log')
+ ->where(["content" => $insertData['content']])
+ ->count();
+
+ if ($people_log2 >= 1) {
+ $zzt_db->rollback();
+ return $this->msg(10002, '该表单内容已经提交过,请勿重复提交');
+ }
+
+ $insertResult = $zzt_db->table('pc_activity_registration_log')
+ ->insert($insertData);
+
+ if ($insertResult) {
+ $zzt_db->commit();
+ return $this->msg([]);
+ } else {
+ $zzt_db->rollback();
+ return $this->msg(10002, '报名失败');
+ }
+
+ } catch (\Exception $e) {
+ $zzt_db->rollback();
+
+ // // 输出详细错误信息到日志
+ // \think\Log::error('报名系统错误:' . $e->getMessage());
+ // \think\Log::error('错误文件:' . $e->getFile() . ' 行号:' . $e->getLine());
+ // \think\Log::error('错误追踪:' . $e->getTraceAsString());
+
+ // // 如果是开发环境,直接显示错误详情
+ // if (config('app_debug')) {
+ // return $this->msg(10002, '系统错误:' . $e->getMessage() . ' 在文件:' . $e->getFile() . ' 第' . $e->getLine() . '行');
+ // }
+
+ return $this->msg(10002, '系统繁忙,请重试');
+ }
+
+ // foreach ($variable as $key => $value) {
+ // # code...
+ // }
+ // $data = [
+ // "id"=>1,
+ // "tel"=>15588668888,
+ // "content"=>[
+ // [
+ // 'name'=>'姓名',
+ // 'type'=>'text',
+ // 'value'=>'Jerry',
+ // ],
+ // [
+ // 'name'=>'备注',
+ // 'type'=>'textarea',
+ // 'value'=>'xxxxxxxxxxxxxxxxxxxxxxx',
+ // ],
+ // [
+ // 'name'=>'性别',
+ // 'type'=>'select',
+ // 'value'=>'男',
+ // ],
+ // [
+ // 'name'=>'兴趣',
+ // 'type'=>'checkbox',
+ // 'value'=>['选项1','选项2','选项3'],
+ // ],
+ // ],
+ // ];
+
+ // return $this->msg($data);
+
+ }
+
+
+
+
+
+
+
+}
\ No newline at end of file
diff --git a/application/OutsideInterface/controller/ZhiZhaoTuan/Base.php b/application/OutsideInterface/controller/ZhiZhaoTuan/Base.php
new file mode 100644
index 0000000..b01cc05
--- /dev/null
+++ b/application/OutsideInterface/controller/ZhiZhaoTuan/Base.php
@@ -0,0 +1,302 @@
+'test_app_data_log',
+ ];
+ protected $return_data_all = [
+ '10001'=>'关键参数缺失',
+ '10002'=>'操作失败',
+ '10003'=>'信息核实错误',
+ '10004'=>'未找到有效数据',
+ '10005'=>'参数格式错误',
+ '10006'=>'参数不能为空',
+ '10007'=>'参数错误',
+ '10008'=>'',
+ '10009'=>'',
+ '10010'=>'自定义信息',
+ '20001'=>'登录失效',
+ '99999'=>'网络异常,请稍后重试',
+ ];
+ protected $file_size = 1024*1024*10;//10M
+ // 加 bcadd(,,20)
+ // 减 bcsub(,,20)
+ // 乘 bcmul(,,20)
+ // 除 bcdiv(,,20)
+ ################################################################接口################################################################
+ ################################################################接口################################################################
+ ################################################################接口################################################################
+ // 接口记录
+ public function record_api_log($params, $error = null, $response = null){
+ // dump($params);
+ // dump($error);
+ // die;
+ $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'=>'接口报错','from_user_name'=>'厨房秤(后台)','content'=>$logContent]);
+ }
+ }
+ if ($response) {
+ $logContent .= "返回信息:" . json_encode($response, JSON_UNESCAPED_UNICODE) . PHP_EOL;
+ }
+ // 使用ThinkPHP的日志记录方法
+ Log::record($logContent, 'api_log');
+ }
+ /* 接口说明(发邮件)
+ * $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';
+ }
+ }
+
+ // 验证数据类型
+ public function verify_data_is_ok($data = 2,$type){
+ if($type == 'str'){
+ if (is_string($data)) {
+ return true;
+ } else {
+ $this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为字符串',[]]);
+ return false;
+ }
+ }else if($type == 'num'){
+ if (is_numeric($data)) {
+ return true;
+ } else {
+ $this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为数字',[]]);
+ return false;
+ }
+ }else if($type == 'intnum'){
+ $pattern = '/^\d+$/';
+ // dump($data);
+ if (preg_match($pattern, $data)) {
+ return true; // 匹配成功,返回 true
+ } else {
+ $this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为整数数字',[]]);
+ return false; // 匹配失败,返回 false
+ }
+ }else if($type == '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;
+ }
+ }
+ // 如果所有格式都解析失败,则返回 false
+ $this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为日期格式',[]]);
+ return false;
+ }else if($type == 'other'){
+
+ }
+ }
+
+
+ ####################################################图片选择上传start##############################################################
+ public function pic_upload($page = 1) {
+ $data = input();
+ $pd = true;
+ if(array_key_exists('page',$data)){
+ $page = $data['page'];
+ $pd = false;
+ }
+ $zzt_db = Db::connect('zzt_db');
+
+ $num = $zzt_db->table('pc_pic_manage')->count();
+ $result = $zzt_db->table('pc_pic_manage')->order('id desc')->page($page,20)->select();
+ if(!$pd){
+ $return_result['num'] = $num;
+ $return_result['result'] = $result;
+ return $this->msg(0,'success',$return_result);
+ }
+ $this->assign([
+ 'result' => $result,
+ 'num' => $num,
+ ]);
+ return $this->fetch();
+ }
+ public function pic_upload_action(){
+ // $file1 = request()->file('file');
+ $file = request()->file('cover_image');
+ if($file){
+ $name = $file->getInfo()['name'];
+ // 使用 pathinfo() 函数获取文件名的扩展名
+ $pathinfo = pathinfo($name);
+ $extension = strtolower($pathinfo['extension']); // 转换为小写以进行不区分大小写的比较
+ $file_name = $pathinfo['filename'];
+ // 判断扩展名是否不是 .png 或 .gif
+ if ($extension !== 'png' && $extension !== 'gif') {
+ // 修改文件名,将扩展名改为 .jpg
+ $new_filename = date('YmdHis').$file_name . '.jpg';
+ } else {
+ $new_filename = date('YmdHis').$name;
+ }
+ $info = $file->validate(['size'=>$this->file_size,'ext'=>'jpg,png,gif'])->move(ROOT_PATH . 'public' . DS . 'outside_interface' . DS . 'zzt',$new_filename);
+ if($info){
+ $insert_data = [
+ 'url_data'=>"https://tc.pcxbc.com/outside_interface/zzt/".$new_filename,
+ 'name'=>$new_filename,
+ 'create_time'=>date('Y-m-d H:i:s'),
+ ];
+ $zzt_db = Db::connect('zzt_db');
+ $pic_result = $zzt_db->table('pc_pic_manage')->insertGetId($insert_data);
+ if($pic_result){
+ return $this->msg(['url'=>$insert_data['url_data'],'id'=>$pic_result]);
+ }else{
+ return $this->msg(10002,'图片数据保存失败');
+ }
+ }else{
+ return $this->msg(10002,'图片上传失败');
+ }
+ }
+ }
+
+ ####################################################图片选择上传end##############################################################
+
+ ####################################################富文本编辑器内start##############################################################
+ // 上传图片动作
+ public function upload_pic_action(){
+ // $file1 = request()->file('file');
+ $file = request()->file('wangeditor-uploaded-image');
+
+ if($file){
+ $name = $file->getInfo()['name'];
+ // 使用 pathinfo() 函数获取文件名的扩展名
+ $pathinfo = pathinfo($name);
+ $extension = strtolower($pathinfo['extension']); // 转换为小写以进行不区分大小写的比较
+ // 判断扩展名是否不是 .png 或 .gif
+ if ($extension !== 'png' && $extension !== 'gif') {
+ // 修改文件名,将扩展名改为 .jpg
+ $new_filename = time().$pathinfo['filename'] . '.jpg';
+ } else {
+ $new_filename = time().$name;
+ }
+ $info = $file->move(ROOT_PATH . 'public' . DS . 'outside_interface' . DS . 'zzt' . DS . 'wangeditor' . DS . 'pic',$new_filename);
+ if($info){
+ $return_data = [
+ 'errno'=>0,
+ 'data'=>[
+ 'url'=>'https://tc.pcxbc.com/outside_interface/zzt/wangeditor/pic/'.$new_filename,
+ ]
+ ];
+ return json($return_data);
+ }else{
+ // 上传失败获取错误信息
+ // echo $file->getError();
+ $return_data = [
+ 'errno'=>9999,
+ 'message'=>$file->getError()
+ ];
+ return json($return_data);
+ }
+ }
+ }
+ // 上传视频动作
+ public function upload_video_action(){
+ // $file1 = request()->file('file');
+ $file = request()->file('wangeditor-uploaded-video');
+ // dump($file);
+ // die;
+ if($file){
+ $name = time().$file->getInfo()['name'];
+ $info = $file->move(ROOT_PATH . 'public' . DS . 'outside_interface' . DS . 'zzt' . DS . 'wangeditor' . DS . 'video',$name);
+ if($info){
+ $return_data = [
+ 'errno'=>0,
+ 'data'=>[
+ 'url'=>'https://tc.pcxbc.com/outside_interface/zzt/wangeditor/video/'.$name,
+ ]
+ ];
+ return json($return_data);
+ }else{
+ // 上传失败获取错误信息
+ // echo $file->getError();
+ $return_data = [
+ 'errno'=>9999,
+ 'message'=>$file->getError()
+ ];
+ return json($return_data);
+ }
+ }
+ }
+ ####################################################富文本编辑器内end##############################################################
+
+
+
+
+ #################################################################其他#################################################################
+ 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]);
+ }
+ }
+
+
+
+}
\ No newline at end of file
diff --git a/application/OutsideInterface/controller/ZhiZhaoTuan/Index.php b/application/OutsideInterface/controller/ZhiZhaoTuan/Index.php
new file mode 100644
index 0000000..c5e8172
--- /dev/null
+++ b/application/OutsideInterface/controller/ZhiZhaoTuan/Index.php
@@ -0,0 +1,242 @@
+table('pc_activity_registration')->where($parameter)->count();
+ $result = $zzt_db->table('pc_activity_registration')->where($parameter)->order('id desc')->page($page,$this->page_num)->field('id,title,people_num,people_num_now,pic,is_del,start_time,end_time,create_time')->select();
+
+ if(!$pd){
+ $result['num'] = $num;
+ $result['data'] = $result;
+ return $this->msg($result);
+ }
+ $this->assign([
+ 'result' => $result,
+ 'num' => $num,
+ ]);
+ return $this->fetch();
+ }
+
+
+ public function del_action()
+ {
+ $data = input('post.');
+ $zzt_db = Db::connect('zzt_db');
+ $result = $zzt_db->table('pc_activity_registration')->where(['id'=>$data['id']])->update(['is_del'=>$data['is_del']]);
+ if($result){
+ return $this->msg([]);
+ }else{
+ return $this->msg(10002);
+ }
+
+ }
+
+
+
+ // 智照团添加表单
+ public function add_form2()
+ {
+ return $this->fetch();
+ }
+ // 智照团添加表单
+ public function add_form_action()
+ {
+ $data = input('post.');
+
+ // dump($data);
+ // die;
+ $zzt_db = Db::connect('zzt_db');
+ $result = $zzt_db->table('pc_activity_registration')->insert([
+ 'title'=>$data['title'],
+ 'people_num'=>$data['people_num'],
+ 'start_time'=>$data['s_time'],
+ 'end_time'=>$data['e_time'],
+ 'text_content'=>$data['content'],
+ 'form_content'=>json_encode($data['form_data']),
+ 'pic'=>$data['cover_image'],
+ 'is_only_once'=>$data['is_only_once'],
+ 'create_time'=>date('Y-m-d H:i:s')
+ ]);
+
+ if($result){
+ return $this->msg([]);
+ }else{
+ return $this->msg(10002);
+ }
+ }
+
+
+ // 智照团修改表单
+ public function edit_form()
+ {
+ $data = input();
+ $zzt_db = Db::connect('zzt_db');
+ $result = $zzt_db->table('pc_activity_registration')->where(['id'=>$data['id']])->field('id,title,people_num,start_time,end_time,text_content,form_content,pic,is_only_once')->find();
+ $pic = $zzt_db->table('pc_pic_manage')->where(['id'=>$result['pic']])->field('id,url_data')->find();
+ $result['pic_url'] = $pic['url_data'];
+ // dump($result);
+ // die;
+ $this->assign([
+ 'result' => $result,
+ ]);
+ return $this->fetch();
+ }
+
+ // 智照团修改表单
+ public function edit_form_action()
+ {
+ $data = input('post.');
+
+ // dump($data);
+ // die;
+ $zzt_db = Db::connect('zzt_db');
+
+ $people_num = $zzt_db->table('pc_activity_registration_log')->where(['par_id'=>$data['id']])->count();
+ if($people_num>0){
+ $yz_data = $zzt_db->table('pc_activity_registration')->where(['id'=>$data['id']])->field('id,form_content,people_num')->find();
+ if($yz_data['form_content'] != json_encode($data['form_data'])){
+ return $this->msg(10002,'已有人报名,不可修改表单项目');
+ }
+ if($yz_data['people_num'] > $data['people_num']){
+ return $this->msg(10002,'已有人报名,请不要缩减报名人数');
+ }
+ }
+
+
+ $result = $zzt_db->table('pc_activity_registration')
+ ->where(['id'=>$data['id']])
+ ->update([
+ 'title'=>$data['title'],
+ 'people_num'=>$data['people_num'],
+ 'start_time'=>$data['s_time'],
+ 'end_time'=>$data['e_time'],
+ 'text_content'=>$data['content'],
+ 'form_content'=>json_encode($data['form_data']),
+ 'pic'=>$data['cover_image'],
+ 'is_only_once'=>$data['is_only_once'],
+ ]);
+
+ if($result){
+ return $this->msg([]);
+ }else{
+ return $this->msg(10002);
+ }
+ }
+
+
+ // 下载报名人员
+
+ public function down_data_action(){
+ $data = input();
+ $zzt_db = Db::connect('zzt_db');
+
+ $down_data = $zzt_db->table('pc_activity_registration_log')->where(['par_id'=>$data['id']])->select();
+ $activity_registration_data = $zzt_db->table('pc_activity_registration')->where(['id'=>$data['id']])->field('id,title,form_content')->find();
+
+ if($activity_registration_data){
+ $activity_registration_data['form_content'] = json_decode($activity_registration_data['form_content'],true);
+ }else{
+ return $this->msg(10002,'未找到对应活动');
+ }
+ $config = $activity_registration_data;
+ // 构建表头
+ $header = ['序号', '会员电话'];
+
+ // 添加表单字段名称到表头
+ foreach ($config['form_content'] as $field) {
+ $header[] = $field['name'];
+ }
+
+ if(count($down_data) > 0){
+ foreach ($down_data as $key => $value) {
+ $down_data[$key]['content'] = json_decode($value['content'],true);
+ }
+ $userData = $down_data;
+
+
+ // 初始化结果数组
+ $result = [];
+ $result[] = $header;
+
+ // 处理每条用户数据
+ foreach ($userData as $index => $user) {
+ $row = [];
+
+ // 序号(使用数组索引+1,或者用用户数据中的id)
+ $row[] = $index + 1;
+
+ // 会员电话处理:如果不是手机号格式,显示"非会员用户"
+ $tel = $user['tel'];
+ if (!preg_match('/^1[3-9]\d{9}$/', $tel)) {
+ $row[] = "非会员用户";
+ } else {
+ $row[] = $tel;
+ }
+
+ // 处理每个表单字段的值
+ foreach ($config['form_content'] as $configField) {
+ $fieldName = $configField['name'];
+ $fieldType = $configField['type'];
+ $fieldValue = '';
+
+ // 在用户数据中查找对应的字段值
+ foreach ($user['content'] as $userField) {
+ if ($userField['name'] === $fieldName) {
+ $fieldValue = $userField['value'];
+
+ // 如果是checkbox类型,替换"CH1"为逗号
+ if ($fieldType === 'checkbox') {
+ $fieldValue = str_replace('CH1', ',', $fieldValue);
+ }
+
+ break;
+ }
+ }
+
+ $row[] = $fieldValue;
+ }
+
+ $result[] = $row;
+ }
+ }else{
+ // 初始化结果数组
+ $result = [];
+ $result[] = $header;
+ }
+ $excel = new \app\download\controller\Excel();
+ $excel->export($result, $activity_registration_data['title']);
+ }
+
+
+
+
+
+
+
+
+
+}
\ No newline at end of file
diff --git a/application/OutsideInterface/controller/app/Base.php b/application/OutsideInterface/controller/app/Base.php
new file mode 100644
index 0000000..6da6fc6
--- /dev/null
+++ b/application/OutsideInterface/controller/app/Base.php
@@ -0,0 +1,183 @@
+'关键参数缺失',
+ '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){
+ // dump($params);
+ // dump($error);
+ // die;
+ $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'=>'接口报错','from_user_name'=>'厨房秤(后台)','content'=>$logContent]);
+ }
+ }
+ if ($response) {
+ $logContent .= "返回信息:" . json_encode($response, JSON_UNESCAPED_UNICODE) . PHP_EOL;
+ }
+ // 使用ThinkPHP的日志记录方法
+ Log::record($logContent, 'api_log');
+ }
+
+ /* 接口说明(发邮件)
+ * $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';
+ }
+ }
+
+
+ // 验证
+ public function verify_data_is_ok($data = 2,$type){
+ if($type == 'str'){
+ if (is_string($data)) {
+ return true;
+ } else {
+ $this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为字符串',[]]);
+ return false;
+ }
+ }else if($type == 'num'){
+ if (is_numeric($data)) {
+ return true;
+ } else {
+ $this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为数字',[]]);
+ return false;
+ }
+ }else if($type == 'intnum'){
+ $pattern = '/^\d+$/';
+ // dump($data);
+ if (preg_match($pattern, $data)) {
+ return true; // 匹配成功,返回 true
+ } else {
+ $this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为整数数字',[]]);
+ return false; // 匹配失败,返回 false
+ }
+ }else if($type == '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;
+ }
+ }
+ // 如果所有格式都解析失败,则返回 false
+ $this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为日期格式',[]]);
+ return false;
+ }else if($type == 'num&letter'){
+ if (preg_match('/^[a-zA-Z0-9]+$/', $data)) {
+ return true;
+ } else {
+ return false;
+ }
+ }else if($type == 'other'){
+
+ }
+
+ }
+
+ 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]);
+ }
+ }
+
+ public function generateRandomString($length = 10) {
+ $characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
+ $charactersLength = strlen($characters);
+ $randomString = '';
+ for ($i = 0; $i < $length; $i++) {
+ $randomString .= $characters[rand(0, $charactersLength - 1)];
+ }
+ return $randomString;
+ }
+
+
+
+}
\ No newline at end of file
diff --git a/application/OutsideInterface/controller/app/Savemsg.php b/application/OutsideInterface/controller/app/Savemsg.php
new file mode 100644
index 0000000..b7cea54
--- /dev/null
+++ b/application/OutsideInterface/controller/app/Savemsg.php
@@ -0,0 +1,420 @@
+'LS-2502',
+ 'character_uuid'=>'2A25',
+ 'service_uuid'=>'180A'
+ ],
+
+ ];
+ protected $name_default = 0;
+
+ // 加 bcadd(,,20)
+ // 减 bcsub(,,20)
+ // 乘 bcmul(,,20)
+ // 除 bcdiv(,,20)
+ ################################################################百度接口################################################################
+ ################################################################百度接口################################################################
+ ################################################################百度接口################################################################
+
+ // 获取配置信息
+ public function config_msg(){
+ try {
+ $result = $this->config_msg_action();
+ return $this->msg($result);
+ } 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'] .= "函数名: " . __FUNCTION__ . "\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 save_sn_msg($data = ['sn_code'=>'564654564654654','mac_code'=>'ce:sh:yo:ng:d1','bl_name'=>'bl_5520']){
+ try {
+ // 你的业务逻辑
+ if(count(input('post.')) > 0){
+ $data = input('post.');
+ }
+ if(!array_key_exists('sn_code', $data)){
+ return $this->msg(10001);
+ }
+ if(!array_key_exists('bl_name', $data)){
+ return $this->msg(10001);
+ }
+ if(!array_key_exists('mac_code', $data)){
+ return $this->msg(10001);
+ }
+ if(!$this->verify_data_is_ok($data['sn_code'],'str')){
+ return $this->msg(10005);
+ }
+ if(!$this->verify_data_is_ok($data['bl_name'],'str')){
+ return $this->msg(10005);
+ }
+ if(!$this->verify_data_is_ok($data['mac_code'],'str')){
+ return $this->msg(10005);
+ }
+ $result = $this->save_sn_msg_action($data);
+ return $result;
+ } 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'] .= "函数名: " . __FUNCTION__ . "\n";
+ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
+ $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
+ // dump($data);
+ // die;
+ $this->record_api_log($data, $logContent, null);
+ return $this->msg(99999);
+ }
+
+ }
+
+ public function save_box_msg($data = ['sn_code_all'=>'564654564654654,564654564654654','box_serial_number'=>'996589585']){
+
+ // try {
+ // 你的业务逻辑
+ if(count(input('post.')) > 0){
+ $data = input('post.');
+ }
+ if(!array_key_exists('sn_code_all', $data)){
+ return $this->msg(10001);
+ }
+ if(!array_key_exists('box_serial_number', $data)){
+ return $this->msg(10001);
+ }
+ if(!$this->verify_data_is_ok($data['sn_code_all'],'str')){
+ return $this->msg(10005);
+ }
+ if(!$this->verify_data_is_ok($data['box_serial_number'],'num&letter')){
+ return $this->msg(10005);
+ }
+ $result = $this->save_box_msg_action($data);
+ return $result;
+ // } 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'] .= "函数名: " . __FUNCTION__ . "\n";
+ // $logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
+ // $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
+ // // dump($data);
+ // // die;
+ // $this->record_api_log($data, $logContent, null);
+ // return $this->msg(99999);
+ // }
+
+ }
+
+ public function print_again($data = ['code'=>'564654564654654','type'=>'sn']){
+ try {
+ // 你的业务逻辑
+ if(count(input('post.')) > 0){
+ $data = input('post.');
+ }
+ if(!array_key_exists('code', $data)){
+ return $this->msg(10001);
+ }
+ if(!array_key_exists('type', $data)){
+ return $this->msg(10001);
+ }
+ if(!$this->verify_data_is_ok($data['code'],'str')){
+ return $this->msg(10005);
+ }
+ if(!$this->verify_data_is_ok($data['type'],'str')){
+ return $this->msg(10005);
+ }
+
+ $result = $this->print_again_action($data);
+ return $result;
+ } 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'] .= "函数名: " . __FUNCTION__ . "\n";
+ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
+ $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
+ // dump($data);
+ // die;
+ $this->record_api_log($data, $logContent, null);
+ return $this->msg(99999);
+ }
+
+ }
+
+
+
+
+ ########################################################################action########################################################################
+ ########################################################################action########################################################################
+ ########################################################################action########################################################################
+
+ public function config_msg_action(){
+ // $length = strlen("0065601800007037");
+ // // 生成200个随机数字字符串
+ // $randomStrings = [];
+ // for ($i = 0; $i < 200; $i++) {
+ // $randomString = '';
+ // for ($j = 0; $j < $length; $j++) {
+ // $randomString .= rand(0, 9); // 生成0-9的随机数字
+ // }
+ // $randomStrings[] = [
+ // 'bluetooth_name'=>'bl_5520',
+ // 'sn_code'=>$randomString,
+ // 'create_time'=>date('Y-m-d H:i:s'),
+ // ];
+ // }
+ // $zengjie = Db::connect('zengjie_db');
+ // $result = $zengjie->table('sn_code_all')->insertAll($randomStrings);
+ // dump($result);
+ // die;
+ $data = [
+ 'max_box_num'=>$this->max_box_num,
+ 'name_list'=>$this->name_list,
+ 'name_default_key'=>$this->name_default,
+
+ ];
+ return $data;
+ }
+
+ public function save_sn_msg_action($data){
+ $data = $this->chuli_str_kongbai($data);
+ $zengjie = Db::connect('zengjie_db');
+ $sn_code = $zengjie->table('sn_code_all')->where(['sn_code'=>$data['sn_code']])->count();
+ if($sn_code > 0){
+ return $this->msg(10002,'该码已录入');
+ }
+
+ $result = $zengjie->table('sn_code_all')->insert([
+ 'sn_code'=>$data['sn_code'],
+ 'bluetooth_name'=>$data['bl_name'],
+ 'mac_code'=>$data['mac_code'],
+ 'create_time'=>date('Y-m-d H:i:s'),
+ ]);
+ if($result){
+ return $this->msg([]);
+ }else{
+ return $this->msg(10002,'录入失败');
+ }
+ }
+
+ public function save_box_msg_action($data) {
+ $data = $this->chuli_str_kongbai($data);
+ $zengjie = Db::connect('zengjie_db');
+
+ // 1. 检查sn_code_all中是否有重复数据
+ $snCodes = explode(',', $data['sn_code_all']);
+ $snCodes = $this->chuli_str_kongbai($snCodes);
+ if (count($snCodes) !== count(array_unique($snCodes))) {
+ return $this->msg(10003, 'SN码列表中存在重复数据');
+ }
+
+ // 2. 检查这些SN码是否都存在于sn_code_all表中
+ $existCount = $zengjie->table('sn_code_all')
+ ->where('sn_code', 'in', $snCodes)
+ ->count();
+
+ if ($existCount !== count($snCodes)) {
+ return $this->msg(10004, '存在未登记的SN码');
+ }
+ Db::startTrans();
+ try{
+ $count = $zengjie->table('box_code_all')
+ ->where(['box_code'=>$data['box_serial_number']])
+ ->count();
+ $num = $count + 1;
+
+ $box_id = $zengjie->table('box_code_all')->insertGetId([
+ 'box_code' => $data['box_serial_number'],
+ 'box_num' => $num,
+ 'create_time' => date('Y-m-d H:i:s'),
+ 'content_str' => json_encode($snCodes)
+ ]);
+
+ $affectedRows = $zengjie->table('sn_code_all')
+ ->where('sn_code', 'in', $snCodes)
+ ->update(['batch_id' => $box_id]);
+
+ // 检查更新是否影响了预期的行数
+ if ($affectedRows !== count($snCodes)) {
+ throw new \Exception('更新SN码数量错误,请刷新小程序后重新录入');
+ }
+ Db::commit();
+ return $this->msg(['id'=>$box_id]);
+ } catch (\Exception $e) {
+ // 回滚事务
+ Db::rollback();
+ return $this->msg(10002, '录入失败: ' . $e->getMessage());
+ }
+ // // 显式事务控制
+ // $zengjie->startTrans();
+ // try {
+ // $count = $zengjie->table('box_code_all')
+ // ->where(['box_code'=>$data['box_serial_number']])
+ // ->count();
+ // $num = $count + 1;
+
+ // $box_id = $zengjie->table('box_code_all')->insertGetId([
+ // 'box_code' => $data['box_serial_number'],
+ // 'box_num' => $num,
+ // 'create_time' => date('Y-m-d H:i:s'),
+ // 'content_str' => $data['sn_code_all'],
+ // ]);
+
+ // $affectedRows = $zengjie->table('sn_code_all')
+ // ->where('sn_code', 'in', $snCodes)
+ // ->update(['batch_id' => $box_id]);
+
+ // // 检查更新是否影响了预期的行数
+ // if ($affectedRows !== count($snCodes)) {
+ // throw new \Exception('更新SN码数量不匹配');
+ // }
+
+ // $zengjie->commit();
+ // return $this->msg(['id'=>$box_id]);
+ // } catch (\Exception $e) {
+ // if ($zengjie->getPdo()->inTransaction()) {
+ // $zengjie->rollback();
+ // }
+ // trace('保存盒信息失败: ' . $e->getMessage(), 'error');
+ // return $this->msg(10002, '录入失败: ' . $e->getMessage());
+ // }
+ }
+
+
+ public function print_again_action($data){
+ $zengjie = Db::connect('zengjie_db');
+ if($data['type'] == 'sn'){
+ $result = $zengjie->table('sn_code_all')->where(['sn_code'=>$data['code']])->count();
+ }else{
+ $result = $zengjie->table('box_code_all')->where(['id'=>$data['code']])->count();
+ }
+
+ if($result <= 0){
+ return $this->msg(10002,'未找到该码录入');
+ }
+
+ if($data['type'] == 'sn'){
+ $result2 = $zengjie->table('sn_code_all')->where(['sn_code'=>$data['code']])->update([
+ 'is_print'=>3
+ ]);
+ }else{
+ $result2 = $zengjie->table('box_code_all')->where(['id'=>$data['code']])->update([
+ 'is_print'=>0
+ ]);
+ }
+
+ if($result){
+ return $this->msg([]);
+ }else{
+ return $this->msg(10002,'打印失败');
+ }
+ }
+
+
+ public function chuli_str_kongbai($data){
+ foreach ($data as $key => $value) {
+ // 1. 移除所有空字符和不可见字符
+ $data[$key] = preg_replace('/[\x00-\x1F\x7F]/', '', $value);
+ // 2. 去除首尾空白
+ $data[$key] = trim($value);
+ }
+ return $data;
+ }
+
+ ######################################################测试#########################################################
+ ######################################################测试#########################################################
+ ######################################################测试#########################################################
+
+ public function ceshiyong(){
+ $data = input('post.');
+ dump($data);
+ // // 添加测试一维码数据
+ // $data = [];
+ // for ($i = 0; $i < 500; $i++) {
+ // // 生成15位随机数字作为sn_code
+ // $sn_code = '';
+ // for ($j = 0; $j < 15; $j++) {
+ // $sn_code .= mt_rand(0, 9);
+ // }
+
+ // // 生成随机的MAC地址
+ // $mac_parts = [];
+ // for ($k = 0; $k < 6; $k++) {
+ // $mac_parts[] = sprintf('%02x', mt_rand(0, 255));
+ // }
+ // $mac_code = implode(':', $mac_parts);
+
+ // // 构建数据数组
+ // $data[] = [
+ // 'sn_code' => $sn_code,
+ // 'mac_code' => $mac_code,
+ // 'create_time' => date('Y-m-d H:i:s'),
+ // 'is_print' => 1,
+ // 'bluetooth_name' => 'bl_5520'
+ // ];
+ // }
+ // $zengjie = Db::connect('zengjie_db');
+ // $result = $zengjie->table('sn_code_all')->insertAll($data);
+ // dump($result);
+ // die;
+ // // 添加测试一维码数据
+
+ // 添加测试打包数据
+ // $zengjie = Db::connect('zengjie_db');
+ // $records = $zengjie->table('sn_code_all')
+ // ->where('batch_id', 'null') // 或者使用 ->whereNull('batch_id')
+ // ->orderRaw('NEWID()') // SQL Server的随机排序函数
+ // ->limit(10)
+ // ->select();
+ // $data['sn_code_all'] = [];
+ // $data['box_serial_number'] = '3ST011527003';
+ // for ($i=0; $i < count($records); $i++) {
+ // $data['sn_code_all'][] = $records[$i]['sn_code'];
+ // }
+ // $data['sn_code_all'] = implode(',',$data['sn_code_all']);
+ // $result = $this->save_box_msg_action($data);
+ // dump($result);
+ // dump($data);
+ // 添加测试打包数据
+ // return $data;
+
+
+
+
+ // '0386737300007235,0039376500007203,0059052100007102,0124589700007184,0032838000007113,0170457400007162,0170448500007207,0170466000006965,0426058900007228,0006613600007105'
+ }
+
+}
\ No newline at end of file
diff --git a/application/OutsideInterface/view/admin/printaction/print_device_data_index.html b/application/OutsideInterface/view/admin/printaction/print_device_data_index.html
new file mode 100644
index 0000000..1d10a3c
--- /dev/null
+++ b/application/OutsideInterface/view/admin/printaction/print_device_data_index.html
@@ -0,0 +1,71 @@
+
+
+
+
+
+ 最近一次打印数据
+
+
+
+
+
+
+
+ | MAC地址 |
+ SN码 |
+ 箱号 |
+
+ {volist name="data" id="item"}
+
+ | {$item.mac_code|default='未分配'} |
+ {$item.sn_code} |
+ {$item.box_code}-{$item.box_num} |
+
+ {/volist}
+
+
点击下载
+
+
+
+
\ No newline at end of file
diff --git a/application/OutsideInterface/view/admin/printaction/print_outside_box_index.html b/application/OutsideInterface/view/admin/printaction/print_outside_box_index.html
new file mode 100644
index 0000000..a5c2741
--- /dev/null
+++ b/application/OutsideInterface/view/admin/printaction/print_outside_box_index.html
@@ -0,0 +1,147 @@
+
+
+
+
+
+ 标签打印系统 - 集成码
+
+
+
+
+ 标签打印系统 - 集成码
+ 生成包含二维码和条形码的标签
+
+
+
+
![标签图片]()
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/application/OutsideInterface/view/zhi_zhao_tuan/base/pic_upload.html b/application/OutsideInterface/view/zhi_zhao_tuan/base/pic_upload.html
new file mode 100644
index 0000000..922e741
--- /dev/null
+++ b/application/OutsideInterface/view/zhi_zhao_tuan/base/pic_upload.html
@@ -0,0 +1,199 @@
+
+
+
+
+ 图片管理
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {volist name="result" id="vo"}
+
+ {/volist}
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/application/OutsideInterface/view/zhi_zhao_tuan/index/add_form.html b/application/OutsideInterface/view/zhi_zhao_tuan/index/add_form.html
new file mode 100644
index 0000000..c34bf9c
--- /dev/null
+++ b/application/OutsideInterface/view/zhi_zhao_tuan/index/add_form.html
@@ -0,0 +1,416 @@
+
+
+
+
+ 自定义表单收集
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/application/OutsideInterface/view/zhi_zhao_tuan/index/add_form2.html b/application/OutsideInterface/view/zhi_zhao_tuan/index/add_form2.html
new file mode 100644
index 0000000..c5db0cf
--- /dev/null
+++ b/application/OutsideInterface/view/zhi_zhao_tuan/index/add_form2.html
@@ -0,0 +1,562 @@
+
+
+
+
+
+ 添加活动报名
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/application/OutsideInterface/view/zhi_zhao_tuan/index/edit_form.html b/application/OutsideInterface/view/zhi_zhao_tuan/index/edit_form.html
new file mode 100644
index 0000000..d86e17c
--- /dev/null
+++ b/application/OutsideInterface/view/zhi_zhao_tuan/index/edit_form.html
@@ -0,0 +1,584 @@
+
+
+
+
+
+ 添加活动报名
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/application/OutsideInterface/view/zhi_zhao_tuan/index/index.html b/application/OutsideInterface/view/zhi_zhao_tuan/index/index.html
new file mode 100644
index 0000000..1b0e60a
--- /dev/null
+++ b/application/OutsideInterface/view/zhi_zhao_tuan/index/index.html
@@ -0,0 +1,285 @@
+
+
+
+
+ 表单管理
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/application/app/controller/Index.php b/application/app/controller/Index.php
index e01c8dc..0e62200 100644
--- a/application/app/controller/Index.php
+++ b/application/app/controller/Index.php
@@ -446,12 +446,14 @@ class Index extends Base{
$result['stage'] = $value['value'];
}
}
+
// 从这里开始进入体脂还是体测的判断
$result['card_order'] = $result['card_order'] == ""?[]:explode(',',$result['card_order']);
if($result['measure_model'] == 1){// 这里是体测
$calculation_results = $this->get_user_card_data_list($result,$result['id']);
$result['card_data_list'] = $calculation_results[0];
$result['card_order'] = $calculation_results[1];
+ // dump($result);
}else if($result['measure_model'] == 2){// 这里是体脂
$result['card_data_list'] = [];
@@ -589,17 +591,18 @@ class Index extends Base{
unset($data['token']);
if(!$this->is_num_array(explode(',',$data['card_order']))){
// 失败
+ // dump($data['card_order']);
+ // dump(explode(',',$data['card_order']));
$this->record_api_log($data, null, ['code'=>10001,'msg'=>'数据内参数格式或值错误',[]]);
return $this->msg(10005,'数据内参数格式或值错误');
}
$result = Db::table($this->index_use_db_name['2'])->where(['id'=>$data['aud_id']])->update(['card_order'=>$data['card_order']]);
if($result){
// 成功
- $this->record_api_log($data, null, ['code'=>0,'msg'=>'success',[]]);
return $this->msg([]);
}else{
// 失败
- $this->record_api_log($data, null, ['code'=>10002,'msg'=>'',[]]);
+ // $this->record_api_log($data, null, ['code'=>10002,'msg'=>'',[]]);
return $this->msg(10002);
}
@@ -713,6 +716,7 @@ class Index extends Base{
public function get_user_card_data_list($data,$aud_id){
$result = [];
$db_arr = [];
+
foreach ($data['card_order'] as $key => $value) {
if(in_array($value,$this->default_card)){
// 过滤掉老版本的(268选项卡)
@@ -732,6 +736,7 @@ class Index extends Base{
}
}
}
+ // dump($data);
$data['card_order'] = array_values($data['card_order']);
// 获取卡片背景图,及背景色信息及其他信息
$card_all_data = Db::table($this->index_use_db_name['6'])->where(['is_del'=>0])->field('id,name,page_url_record,page_url_report,page_url_bluetooth,key_word,background_color,background_pic')->select();
diff --git a/application/config.php b/application/config.php
index a1f379c..3e8e50d 100644
--- a/application/config.php
+++ b/application/config.php
@@ -341,4 +341,28 @@ return [
// 数据库调试模式
'debug' => true,
],
+ // 第5个数据库配置(设备录入)
+ 'zzt_db' => [
+ // 数据库类型
+ 'type' => 'sqlsrv',
+ // 服务器地址
+ 'hostname' => '123.60.2.99',
+ // 'hostname' => '127.0.0.1',
+ // 数据库名
+ 'database' => 'jt_shanghui',
+ // 用户名
+ 'username' => 'jutian_user',
+ // 密码
+ 'password' => 'jutian1qaz@WSX',
+ // 端口
+ 'hostport' => '4331',
+ // 数据库连接参数
+ 'params' => [],
+ // 数据库编码默认采用utf8
+ 'charset' => 'utf8',
+ // 数据库表前缀
+ 'prefix' => '',
+ // 数据库调试模式
+ 'debug' => true,
+ ],
];
diff --git a/application/route.php b/application/route.php
index 60382bb..f412950 100644
--- a/application/route.php
+++ b/application/route.php
@@ -458,18 +458,18 @@ Route::any('/open_wechat_content', 'app/Msginformation/open_wechat_content');
#########################################################前端接口############################################################
// 微信小程序快捷登录接口
Route::any('/kitchenscale/wechat_quick_login', 'app/kitchenscale/app.index/wechat_quick_login');
-Route::any('/testedition/kitchenscale/wechat_quick_login', 'app/kitchenscale/app.index/wechat_quick_login');
+Route::any('/kitchenscale2/wechat_quick_login', 'app/kitchenscale2/app.index/wechat_quick_login');
// 公共内容################################################################
// 获取用户上传图片列表
Route::any('/kitchenscale/pic_chose_list', 'app/kitchenscale/app.base/pic_chose_list');
-Route::any('/testedition/kitchenscale/pic_chose_list', 'app/kitchenscale/testapp.base/pic_chose_list');
-// 用户多图上传接口
+Route::any('/kitchenscale2/pic_chose_list', 'app/kitchenscale2/app.base/pic_chose_list');
+// 用户单图上传接口
Route::any('/kitchenscale/pic_upload_one_action', 'app/kitchenscale/app.base/pic_upload_one_action');
-Route::any('/testedition/kitchenscale/pic_upload_one_action', 'app/kitchenscale/testapp.base/pic_upload_one_action');
+Route::any('/kitchenscale2/pic_upload_one_action', 'app/kitchenscale2/app.base/pic_upload_one_action');
// 用户多图上传接口
Route::any('/kitchenscale/pic_upload_action', 'app/kitchenscale/app.base/pic_upload_action');
-Route::any('/testedition/kitchenscale/pic_upload_action', 'app/kitchenscale/testapp.base/pic_upload_action');
+Route::any('/kitchenscale2/pic_upload_action', 'app/kitchenscale2/app.base/pic_upload_action');
@@ -479,92 +479,107 @@ Route::any('/kitchenscale/login_invalid_version', 'app/Kitchenscale/app.Index/lo
Route::any('/testedition/kitchenscale/login_invalid_version', 'app/kitchenscale/testapp.index/login_invalid_version');
// 获取配置类信息
Route::any('/kitchenscale/get_default_config', 'app/Kitchenscale/app.Index/get_default_config');
-Route::any('/testedition/kitchenscale/get_default_config', 'app/kitchenscale/testapp.index/get_default_config');
+Route::any('/kitchenscale2/get_default_config', 'app/Kitchenscale2/app.Index/get_default_config');
// 获取首页页面展示数据
Route::any('/kitchenscale/get_homepage_information', 'app/kitchenscale/app.index/get_homepage_information');
Route::any('/testedition/kitchenscale/get_homepage_information', 'app/kitchenscale/testapp.index/get_homepage_information');
// 首页搜索接口
Route::any('/kitchenscale/search_column', 'app/kitchenscale/app.index/search_column');
-Route::any('/testedition/kitchenscale/search_column', 'app/kitchenscale/testapp.index/search_column');
+Route::any('/kitchenscale2/search_column', 'app/kitchenscale2/app.index/search_column');
// 菜谱内容################################################################
// 添加菜谱
Route::any('/kitchenscale/add_cookbook', 'app/kitchenscale/app.cookbook/add_cookbook');
-Route::any('/testedition/kitchenscale/add_cookbook', 'app/kitchenscale/testapp.cookbook/add_cookbook');
+Route::any('/kitchenscale2/add_cookbook', 'app/kitchenscale2/app.cookbook/add_cookbook');
// 修改菜谱
Route::any('/kitchenscale/update_cookbook', 'app/kitchenscale/app.cookbook/update_cookbook');
-Route::any('/testedition/kitchenscale/update_cookbook', 'app/kitchenscale/testapp.cookbook/update_cookbook');
+Route::any('/kitchenscale2/update_cookbook', 'app/kitchenscale2/app.cookbook/update_cookbook');
// 根据菜谱标签查询列表(首页用)
Route::any('/kitchenscale/find_by_cook_label', 'app/kitchenscale/app.cookbook/find_by_cook_label');
-Route::any('/testedition/kitchenscale/find_by_cook_label', 'app/kitchenscale/testapp.cookbook/find_by_cook_label');
+Route::any('/kitchenscale2/find_by_cook_label', 'app/kitchenscale2/app.cookbook/find_by_cook_label');
// 根据食材详细查找列表
Route::any('/kitchenscale/find_by_food', 'app/kitchenscale/app.cookbook/find_by_food');
-Route::any('/testedition/kitchenscale/find_by_food', 'app/kitchenscale/testapp.cookbook/find_by_food');
+Route::any('/kitchenscale2/find_by_food', 'app/kitchenscale2/app.cookbook/find_by_food');
// 查询食谱的详情
Route::any('/kitchenscale/cookbook_details', 'app/kitchenscale/app.cookbook/cookbook_details');
-Route::any('/testedition/kitchenscale/cookbook_details', 'app/kitchenscale/testapp.cookbook/cookbook_details');
+Route::any('/kitchenscale2/cookbook_details', 'app/kitchenscale2/app.cookbook/cookbook_details');
// 关注菜谱
Route::any('/kitchenscale/cookbook_follow', 'app/kitchenscale/app.cookbook/cookbook_follow');
Route::any('/testedition/kitchenscale/cookbook_follow', 'app/kitchenscale/testapp.cookbook/cookbook_follow');
// 收藏菜谱
Route::any('/kitchenscale/cookbook_like', 'app/kitchenscale/app.cookbook/cookbook_like');
-Route::any('/testedition/kitchenscale/cookbook_like', 'app/kitchenscale/testapp.cookbook/cookbook_like');
+Route::any('/kitchenscale2/cookbook_like', 'app/kitchenscale2/app.cookbook/cookbook_like');
// 获取当前食材重量卡路里
Route::any('/kitchenscale/food_count_kcal', 'app/kitchenscale/app.cookbook/food_count_kcal');
-Route::any('/testedition/kitchenscale/food_count_kcal', 'app/kitchenscale/testapp.cookbook/food_count_kcal');
+Route::any('/kitchenscale2/food_count_kcal', 'app/kitchenscale2/app.cookbook/food_count_kcal');
// 获取当前食材重量卡路里
Route::any('/kitchenscale/find_food', 'app/kitchenscale/app.cookbook/find_food');
-Route::any('/testedition/kitchenscale/find_food', 'app/kitchenscale/testapp.cookbook/find_food');
+Route::any('/kitchenscale2/find_food', 'app/kitchenscale2/app.cookbook/find_food');
// 获取当前食材重量卡路里
Route::any('/kitchenscale/get_food_list', 'app/kitchenscale/app.cookbook/get_food_list');
-Route::any('/testedition/kitchenscale/get_food_list', 'app/kitchenscale/testapp.cookbook/get_food_list');
+Route::any('/kitchenscale2/get_food_list', 'app/kitchenscale2/app.cookbook/get_food_list');
// 获取所有食谱label
Route::any('/kitchenscale/get_cookbook_label_list', 'app/kitchenscale/app.cookbook/get_cookbook_label_list');
Route::any('/testedition/kitchenscale/get_cookbook_label_list', 'app/kitchenscale/testapp.cookbook/get_cookbook_label_list');
// 获取查询页页面导航食材列表
Route::any('/kitchenscale/get_search_food_page_list', 'app/kitchenscale/app.cookbook/get_search_food_page_list');
-Route::any('/testedition/kitchenscale/get_search_food_page_list', 'app/kitchenscale/testapp.cookbook/get_search_food_page_list');
+Route::any('/kitchenscale2/get_search_food_page_list', 'app/kitchenscale2/app.cookbook/get_search_food_page_list');
// 计食器################################################################
// 添加每日摄入记录
Route::any('/kitchenscale/add_intake_food', 'app/kitchenscale/app.countfood/add_intake_food');
-Route::any('/testedition/kitchenscale/add_intake_food', 'app/kitchenscale/testapp.countfood/add_intake_food');
+Route::any('/kitchenscale2/add_intake_food', 'app/kitchenscale2/app.countfood/add_intake_food');
// 获取记食器板块内容
Route::any('/kitchenscale/get_countfoot_content', 'app/kitchenscale/app.countfood/get_countfoot_content');
-Route::any('/testedition/kitchenscale/get_countfoot_content', 'app/kitchenscale/testapp.countfood/get_countfoot_content');
+Route::any('/kitchenscale2/get_countfoot_content', 'app/kitchenscale2/app.countfood/get_countfoot_content');
// 获取记食器记录
Route::any('/kitchenscale/get_log_list', 'app/kitchenscale/app.countfood/get_log_list');
-Route::any('/testedition/kitchenscale/get_log_list', 'app/kitchenscale/testapp.countfood/get_log_list');
+Route::any('/kitchenscale2/get_log_list', 'app/kitchenscale2/app.countfood/get_log_list');
// 计食器板块-设置内容
Route::any('/kitchenscale/set_up_content', 'app/kitchenscale/app.countfood/set_up_content');
-Route::any('/testedition/kitchenscale/set_up_content', 'app/kitchenscale/testapp.countfood/set_up_content');
+Route::any('/kitchenscale2/set_up_content', 'app/kitchenscale2/app.countfood/set_up_content');
// 设置用户的卡路里
Route::any('/kitchenscale/set_user_kcal', 'app/kitchenscale/app.countfood/set_user_kcal');
-Route::any('/testedition/kitchenscale/set_user_kcal', 'app/kitchenscale/testapp.countfood/set_user_kcal');
+Route::any('/kitchenscale2/set_user_kcal', 'app/kitchenscale2/app.countfood/set_user_kcal');
// 删除用户某个饮食记录
Route::any('/kitchenscale/del_user_eat_log', 'app/kitchenscale/app.countfood/del_user_eat_log');
-Route::any('/testedition/kitchenscale/del_user_eat_log', 'app/kitchenscale/testapp.countfood/del_user_eat_log');
+Route::any('/kitchenscale2/del_user_eat_log', 'app/kitchenscale/app.countfood/del_user_eat_log');
+// 删除用户某个饮食记录
+// Route::any('/kitchenscale/del_user_eat_list_log', 'app/kitchenscale/app.countfood/del_user_eat_list_log');
+Route::any('/kitchenscale2/del_user_eat_list_log', 'app/kitchenscale2/app.countfood/del_user_eat_list_log');
+
+
// 我的################################################################
// 获取角色信息
Route::any('/kitchenscale/get_user_msg', 'app/kitchenscale/app.usercenter/get_user_msg');
-Route::any('/testedition/kitchenscale/get_user_msg', 'app/kitchenscale/testapp.usercenter/get_user_msg');
+Route::any('/kitchenscale2/get_user_msg', 'app/kitchenscale2/app.usercenter/get_user_msg');
// 修改角色信息
Route::any('/kitchenscale/update_user_msg', 'app/kitchenscale/app.usercenter/update_user_msg');
-Route::any('/testedition/kitchenscale/update_user_msg', 'app/kitchenscale/testapp.usercenter/update_user_msg');
+Route::any('/kitchenscale2/update_user_msg', 'app/kitchenscale2/app.usercenter/update_user_msg');
// 账号收藏点赞列表
Route::any('/kitchenscale/get_user_collect_list', 'app/kitchenscale/app.usercenter/get_user_collect_list');
-Route::any('/testedition/kitchenscale/get_user_collect_list', 'app/kitchenscale/testapp.usercenter/get_user_collect_list');
+Route::any('/kitchenscale2/get_user_collect_list', 'app/kitchenscale2/app.usercenter/get_user_collect_list');
// 我的菜谱
Route::any('/kitchenscale/get_my_cookbook', 'app/kitchenscale/app.usercenter/get_my_cookbook');
-Route::any('/testedition/kitchenscale/get_my_cookbook', 'app/kitchenscale/testapp.usercenter/get_my_cookbook');
+Route::any('/kitchenscale2/get_my_cookbook', 'app/kitchenscale2/app.usercenter/get_my_cookbook');
// 菜谱删除
Route::any('/kitchenscale/del_my_cookbook', 'app/kitchenscale/app.usercenter/del_my_cookbook');
-Route::any('/testedition/kitchenscale/del_my_cookbook', 'app/kitchenscale/testapp.usercenter/del_my_cookbook');
+Route::any('/kitchenscale2/del_my_cookbook', 'app/kitchenscale2/app.usercenter/del_my_cookbook');
+// 删除用户搜索记录
+Route::any('/kitchenscale/del_search_history', 'app/kitchenscale/app.usercenter/del_search_history');
+Route::any('/kitchenscale2/del_search_history', 'app/kitchenscale2/app.usercenter/del_search_history');
+// 商务合作
+Route::any('/kitchenscale/business_cooperation', 'app/kitchenscale/app.usercenter/business_cooperation');
+Route::any('/kitchenscale2/business_cooperation', 'app/kitchenscale2/app.usercenter/business_cooperation');
+// 商务合作提交
+Route::any('/kitchenscale/business_cooperation_action', 'app/kitchenscale/app.usercenter/business_cooperation_action');
+Route::any('/kitchenscale2/business_cooperation_action', 'app/kitchenscale2/app.usercenter/business_cooperation_action');
+
// 百度图片识别接口################################################################
// 获取AccessToken
@@ -572,6 +587,7 @@ Route::any('/testedition/kitchenscale/del_my_cookbook', 'app/kitchenscale/testap
// Route::any('/testedition/kitchenscale/baidu_get_accesstoken', 'app/kitchenscale/testapp.aipart/baidu_get_accesstoken');
// 识别食材
Route::any('/kitchenscale/baidu_identify_food', 'app/kitchenscale/app.aipart/baidu_identify_food');
+Route::any('/kitchenscale2/baidu_identify_food', 'app/kitchenscale2/app.aipart/baidu_identify_food');
@@ -694,7 +710,43 @@ Route::any('/reedaw/role_list', 'app/NewReedaw/app.role/role_list');
Route::any('/reedaw/body_report', 'app/NewReedaw/app.body/body_report');
+#######################################################################下面是外部接口#######################################################################
+#############################################################################################################################################################
+######################################################################智照团(↓)
+// 智照团选择上传
+Route::any('/oi/zzt/pic_upload', 'app/OutsideInterface/ZhiZhaoTuan.base/pic_upload');
+Route::any('/oi/zzt/pic_upload_action', 'app/OutsideInterface/ZhiZhaoTuan.base/pic_upload_action');
+// 富文本编辑器内上传
+Route::any('/oi/zzt/upload_pic_action', 'app/OutsideInterface/ZhiZhaoTuan.base/upload_pic_action');
+Route::any('/oi/zzt/upload_video_action', 'app/OutsideInterface/ZhiZhaoTuan.base/upload_video_action');
+
+// 智照团form表单列表页
+Route::any('/oi/zzt/form_page', 'app/OutsideInterface/ZhiZhaoTuan.index/index');
+// 智照团form表单添加页
+// Route::any('/oi/zzt/add_form', 'app/OutsideInterface/ZhiZhaoTuan.index/add_form');
+Route::any('/oi/zzt/add_form2', 'app/OutsideInterface/ZhiZhaoTuan.index/add_form2');
+// 智照团form表单添加动作
+Route::any('/oi/zzt/add_form_action', 'app/OutsideInterface/ZhiZhaoTuan.index/add_form_action');
+// 智照团form表单修改页
+Route::any('/oi/zzt/edit_form', 'app/OutsideInterface/ZhiZhaoTuan.index/edit_form');
+// 智照团form表单添加动作
+Route::any('/oi/zzt/edit_form_action', 'app/OutsideInterface/ZhiZhaoTuan.index/edit_form_action');
+// 智照团form表单下架/上架动作
+Route::any('/oi/zzt/del_action', 'app/OutsideInterface/ZhiZhaoTuan.index/del_action');
+// 智照团form表单下载数据动作
+Route::any('/oi/zzt/down_data_action', 'app/OutsideInterface/ZhiZhaoTuan.index/down_data_action');
+
+
+// 智照团活动列表页API
+Route::any('/oi/zzt/activity_list', 'app/OutsideInterface/ZhiZhaoTuan.ApiJk/activity_list');
+// 智照团活动详情页API
+Route::any('/oi/zzt/details_data', 'app/OutsideInterface/ZhiZhaoTuan.ApiJk/details_data');
+// 智照团活动提交API
+Route::any('/oi/zzt/save_activity_data', 'app/OutsideInterface/ZhiZhaoTuan.ApiJk/save_activity_data');
+
+
+######################################################################互抖团(↓)
@@ -715,6 +767,7 @@ Route::any('/ceshiyong', 'app/base/ceshiyong');
Route::any('/testedition/ceshiyong', 'testapp/base/ceshiyong');
Route::any('/kitchenscale/chuli_shuju', 'app/kitchenscale/app.cookbook/chuli_shuju');
+Route::any('/kitchenscale2/chuli_shuju', 'app/kitchenscale2/app.cookbook/chuli_shuju');
// 测试用控制器