diff --git a/application/KitchenScale/controller/app/Aipart.php b/application/KitchenScale/controller/app/Aipart.php new file mode 100644 index 0000000..46c651d --- /dev/null +++ b/application/KitchenScale/controller/app/Aipart.php @@ -0,0 +1,146 @@ +'app_user_cookbook',//菜谱表 + 'foodlist3'=>'app_food_type_three',//食材列表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/KitchenScale/controller/app/Base.php b/application/KitchenScale/controller/app/Base.php index 480f6cb..d690d48 100644 --- a/application/KitchenScale/controller/app/Base.php +++ b/application/KitchenScale/controller/app/Base.php @@ -43,6 +43,9 @@ class Base extends Controller{ ################################################################接口################################################################ // 接口记录 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; @@ -55,9 +58,9 @@ class Base extends Controller{ $logContent .= "返回信息:" . json_encode($response, JSON_UNESCAPED_UNICODE) . PHP_EOL; } // 使用ThinkPHP的日志记录方法 - Log::record($logContent, 'api_log'); - + Log::record($logContent, 'api_log'); } + // 判断token是否过期 public function token_time_validate($token){ diff --git a/application/KitchenScale/controller/app/Cookbook.php b/application/KitchenScale/controller/app/Cookbook.php index d2737ce..78f9301 100644 --- a/application/KitchenScale/controller/app/Cookbook.php +++ b/application/KitchenScale/controller/app/Cookbook.php @@ -16,13 +16,18 @@ class Cookbook extends Base{ ]; 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_food_type_one',//食材列表3 - 'foodlist2'=>'app_food_type_two',//食材列表3 - 'foodlist3'=>'app_food_type_three',//食材列表3 + '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',//banner ]; @@ -85,7 +90,7 @@ class Cookbook extends Base{ return $return_data; // } catch (\Exception $e) { // // 捕获异常 - // $logContent["file"] = $e->getFile(); + // $logContent["flie"] = $e->getFile(); // $logContent["line"] = $e->getLine(); // $logContent['all_content'] = "异常信息:\n"; // $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; @@ -94,14 +99,14 @@ class Cookbook extends Base{ // $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; // $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; // // 记录日志 - // // $this->record_api_log($data, $logContent, null); + // $this->record_api_log($data, $logContent, null); // return json(['status' => 'error', 'message' => '系统错误']); // } } // 修改菜谱(OK) public function update_cookbook(){ // 尝试捕获异常 - // try { + try { if(count(input('post.')) > 0){ $data = input('post.'); } @@ -153,25 +158,25 @@ class Cookbook extends Base{ $return_data = $this->update_cookbook_action($data); return $return_data; - // } catch (\Exception $e) { - // // 捕获异常 - // $logContent["file"] = $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' => '系统错误']); - // } + } 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 { + try { if(count(input('post.')) > 0){ $data = input('post.'); } @@ -179,37 +184,37 @@ class Cookbook extends Base{ 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(!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'); - } + // 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["file"] = $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' => '系统错误']); - // } + } 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'=>'caadd1be045a65f3','food_name'=>'猪肉','page'=>'1']){ + public function find_by_food($data=['token'=>'caadd1be045a65f30b92aa805f1de54a','food_name'=>"2724,2670",'page'=>'1']){ // 尝试捕获异常 - // try { + try { if(count(input('post.')) > 0){ $data = input('post.'); } @@ -219,39 +224,39 @@ class Cookbook extends Base{ 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(!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,'food_name type is error'); - } - if(!$this->verify_data_is_ok($data['page'],'intnum')){ - return $this->msg(10005,'page type is error'); + 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["file"] = $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' => '系统错误']); - // } + } 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'=>'21']){ + public function cookbook_details($data=['token'=>'','cookbook_id'=>'3594']){ // 尝试捕获异常 - // try { + try { if(count(input('post.')) > 0){ $data = input('post.'); } @@ -263,25 +268,25 @@ class Cookbook extends Base{ } $return_data = $this->cookbook_details_action($data); return $return_data; - // } catch (\Exception $e) { - // // 捕获异常 - // $logContent["file"] = $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' => '系统错误']); - // } + } 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 { + try { if(count(input('post.')) > 0){ $data = input('post.'); } @@ -299,25 +304,25 @@ class Cookbook extends Base{ } $return_data = $this->cookbook_follow_action($data); return $return_data; - // } catch (\Exception $e) { - // // 捕获异常 - // $logContent["file"] = $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' => '系统错误']); - // } + } 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 { + try { if(count(input('post.')) > 0){ $data = input('post.'); } @@ -335,25 +340,25 @@ class Cookbook extends Base{ } $return_data = $this->cookbook_like_action($data); return $return_data; - // } catch (\Exception $e) { - // // 捕获异常 - // $logContent["file"] = $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' => '系统错误']); - // } + } 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 { + try { if(count(input('post.')) > 0){ $data = input('post.'); } @@ -372,25 +377,25 @@ class Cookbook extends Base{ $return_data = $this->food_count_kcal_action($data); return $return_data; - // } catch (\Exception $e) { - // // 捕获异常 - // $logContent["file"] = $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' => '系统错误']); - // } + } 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 { + try { if(count(input('post.')) > 0){ $data = input('post.'); } @@ -403,62 +408,62 @@ class Cookbook extends Base{ $return_data = $this->find_food_action($data); return $return_data; - // } catch (\Exception $e) { - // // 捕获异常 - // $logContent["file"] = $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' => '系统错误']); - // } + } 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($data=['food_level2_id'=>'4','search_data'=>'','page'=>1]){ // 尝试捕获异常 - // try { + 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(!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'); - } + // 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["file"] = $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' => '系统错误']); - // } + } 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 { + try { if(count(input('post.')) > 0){ $data = input('post.'); } @@ -471,20 +476,52 @@ class Cookbook extends Base{ $return_data = $this->get_cookbook_label_list_action($data); return $return_data; - // } catch (\Exception $e) { - // // 捕获异常 - // $logContent["file"] = $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' => '系统错误']); - // } + } 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####################################################################### @@ -492,6 +529,7 @@ class Cookbook extends Base{ #######################################################################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){ @@ -507,8 +545,8 @@ class Cookbook extends Base{ $food_type = []; // 检验一下food_list是否合规(食材列表) foreach ($data['food_list'] as $key => $value) { - if (!array_key_exists('name', $value) || !array_key_exists('weight', $value)) { - return $this->msg(10001,'食材缺少名称或者重量'); + 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,'食材名称格式错误'); @@ -516,8 +554,8 @@ class Cookbook extends Base{ if(!$this->verify_data_is_ok($value['weight'],'intnum')){ return $this->msg(10005,'食材重量格式错误,需整数数字'); } - if(!in_array($value['name'], $food_type)){ - array_push($food_type, $value['name']); + if(!in_array($value['id'], $food_type)){ + array_push($food_type, $value['id']); } } // 检验一下step_list是否合规(步骤列表) @@ -534,10 +572,12 @@ class Cookbook extends Base{ } } } + $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; @@ -554,19 +594,36 @@ class Cookbook extends Base{ 'describe_data'=>$data['description'], 'food_data'=>json_encode($data['food_list']), 'step_data'=>json_encode($data['step_list']), - 'food_type'=>implode(',', $food_type), + // 'food_type'=>implode(',', $food_type), 'cook_label'=>$data['cook_label'], 'create_time'=>date('Y-m-d H:i:s') ]; // dump($insert_data); // die; - $cook_book_result = $cfc->table($this->kitchenscale_db_msg['cookbook'])->insert($insert_data); - - if($cook_book_result){ + // 启动事务 + 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([]); - }else{ + } 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){ // 获取账号下信息以及用户信息 @@ -584,8 +641,8 @@ class Cookbook extends Base{ $food_type = []; // 检验一下food_list是否合规(食材列表) foreach ($data['food_list'] as $key => $value) { - if (!array_key_exists('name', $value) || !array_key_exists('weight', $value)) { - return $this->msg(10001,'食材缺少名称或者重量'); + 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,'食材名称格式错误'); @@ -593,8 +650,8 @@ class Cookbook extends Base{ if(!$this->verify_data_is_ok($value['weight'],'intnum')){ return $this->msg(10005,'食材重量格式错误,需整数数字'); } - if(!in_array($value['name'], $food_type)){ - array_push($food_type, $value['name']); + if(!in_array($value['id'], $food_type)){ + array_push($food_type, $value['id']); } } // 检验一下step_list是否合规(步骤列表) @@ -634,12 +691,30 @@ class Cookbook extends Base{ 'describe_data'=>$data['description'], 'food_data'=>json_encode($data['food_list']), 'step_data'=>json_encode($data['step_list']), - 'food_type'=>implode(',', $food_type), + // 'food_type'=>implode(',', $food_type), 'cook_label'=>$data['cook_label'], ]; - $cook_book_result = $cfc->table($this->kitchenscale_db_msg['cookbook'])->where(['id'=>$data['cookbook_id']])->update($insert_data); + + // 启动事务 + 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){ @@ -651,8 +726,8 @@ class Cookbook extends Base{ public function find_by_cook_label_action($data){ - $page_now = $data['page']; - $page_total = $data['page']; + $page_now = array_key_exists('page',$data)?$data['page']:1; + $page_total = $page_now; $page_num = 20; $cook_label = $data['cook_label']; @@ -723,28 +798,61 @@ class Cookbook extends Base{ ]); } 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 = $data['page']; - $page_total = $data['page']; + + $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'); - $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') + + // $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']) @@ -764,7 +872,7 @@ class Cookbook extends Base{ } unset($content_list[$key]['ROW_NUMBER']); } - + return $this->msg([ 'page_now'=>$page_now, 'page_total'=>$page_total, @@ -860,12 +968,51 @@ class Cookbook extends Base{ }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'], + ]); + array_push($cookbook_data['tags'],[ + 'title'=>'能量', + 'desc'=>'含量', + 'list'=>$nutrition, + ]); + array_push($cookbook_data['tags'],[ + 'title'=>'维生素', + 'desc'=>'含量', + 'list'=>$vitamin, + ]); + array_push($cookbook_data['tags'],[ + 'title'=>'矿物质', + 'desc'=>'含量', + 'list'=>$mineral, + ]); + + + // $cookbook_data['nutrition']['list'] = $nutrition; + // // $cookbook_data['nutrition']['title'] = '能量及宏量营养素'; + // $cookbook_data['nutrition']['title'] = '能量'; + // $cookbook_data['nutrition']['desc'] = '含量'; + // $cookbook_data['vitamin']['list'] = $vitamin; + // $cookbook_data['vitamin']['title'] = '维生素'; + // $cookbook_data['vitamin']['desc'] = '含量'; + // $cookbook_data['mineral']['list'] = $mineral; + // $cookbook_data['mineral']['title'] = '矿物质'; + // $cookbook_data['mineral']['desc'] = '含量'; + $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['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']); @@ -1019,13 +1166,13 @@ class Cookbook extends Base{ } public function find_food_action($data){ $cfc = Db::connect('cfc_db'); - $food_data = $cfc->query("select f3.id,f3.name,f3.kcal,f2.id as up_one_level_id,f1.id as up_two_level_id + $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.name like '%".$data['food_name']."%' + where f3.is_del=0 AND f3.food_name like '%".$data['food_name']."%' "); if(count($food_data)>0){ @@ -1035,7 +1182,12 @@ class Cookbook extends Base{ } } public function get_food_list_action($data){ - $cp_page_num = 100; + + if(!array_key_exists('page',$data)){ + $data['page'] = 1; + } + + $cp_page_num = 30; $cfc = Db::connect('cfc_db'); // 获取食材分类列表start // $foodlist1 = $cfc->table($this->kitchenscale_db_msg['foodlist1'])->where("is_del = 0")->field('id,name')->select(); @@ -1068,9 +1220,14 @@ class Cookbook extends Base{ // ->join($this->kitchenscale_db_msg['foodlist2'].' b','a.two_id = b.id','LEFT') // ->join($this->kitchenscale_db_msg['foodlist1'].' c','b.one_id = c.id','LEFT') ->where($search_sql_str) - ->field('id,name,kcal,unit') + ->field('id,food_name as name,pic_url,Calorie_val as kcal,weight_unit as unit') ->page($data['page'],$cp_page_num) ->select(); + + + foreach ($collect_list as $key => $value) { + $collect_list[$key]['pic_url'] = "https://tc.pcxbc.com/kitchenscale_all".$collect_list[$key]['pic_url']; + } // $return_data = []; // $temporary_arr = []; // foreach ($collect_list as $key => $value) { @@ -1121,6 +1278,43 @@ class Cookbook extends Base{ 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,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['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['name']]); + } + } + + return $this->msg($result); + // 获取菜谱分类标签end + } @@ -1132,10 +1326,10 @@ class Cookbook extends Base{ // 处理食材的卡路里 public function count_calorie($data,$step){ - $foot_name = array_column($data, 'name'); + $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("name in ('".implode("','", $foot_name)."')")->field("id,name,kcal")->select(); + $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']]; @@ -1154,19 +1348,6 @@ class Cookbook extends Base{ $data[$key]['unit'] = 'g'; } - - // foreach ($data as $key => $value) { - // if(array_key_exists($value['name'], $foot_kcal2)){ - // // $data[$key]['kcal'] = $this->count_calorie_action($value['weight'],$foot_kcal2[$value['name']]).'kcal'; - // $data[$key]['kcal'] = $this->count_calorie_action($value['weight'],$foot_kcal2[$value['name']]); - // }else{ - // // $data[$key]['kcal'] = '0kcal'; - // $data[$key]['kcal'] = '0'; - // } - // // $data[$key]['weight'] = $data[$key]['weight'].'g'; - // $data[$key]['unit'] = 'g'; - // $data[$key]['id'] = 'g'; - // } return $data; } diff --git a/application/KitchenScale/controller/app/Countfood.php b/application/KitchenScale/controller/app/Countfood.php index c237c9f..c9677dc 100644 --- a/application/KitchenScale/controller/app/Countfood.php +++ b/application/KitchenScale/controller/app/Countfood.php @@ -18,7 +18,7 @@ class Countfood extends Base{ 'uploadimg'=>'app_user_upload_img',//素材表 'followlist'=>'app_user_follow_list',//关注列表 'collect_list'=>'app_user_collect_list',//收藏列表 - 'foodlist3'=>'app_food_type_three',//食材列表3 + 'foodlist3'=>'app_standard_food_type_three',//食材列表3 'eat_log'=>'app_user_kcal_log',//食材列表3 'user'=>'app_user_data',//banner ]; @@ -32,9 +32,9 @@ class Countfood extends Base{ ################################################################接口################################################################ // 添加每日摄入记录 - public function add_intake_food($data=['token'=>'caadd1be045a65f30b92aa805f1de54a','aud_id'=>1,'meals_type'=>'午加餐','food_list'=>[['id'=>1,'weight'=>'150','unit'=>'g'],['id'=>2,'weight'=>'100','unit'=>'g']]]){ + public function add_intake_food($data=['token'=>'3e5876042361c8cb42bd48c46918f737','aud_id'=>6,'meals_type'=>'早餐','food_list'=>[['id'=>2778,'name'=>"啤酒(X)",'weight'=>'150','unit'=>'g']]]){ // 尝试捕获异常 - // try { + try { if(count(input('post.')) > 0){ $data = input('post.'); } @@ -58,25 +58,25 @@ class Countfood extends Base{ } $return_data = $this->add_intake_food_action($data); return $return_data; - // } catch (\Exception $e) { - // // 捕获异常 - // $logContent["file"] = $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' => '系统错误']); - // } + } 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($data=['token'=>'caadd1be045a65f30b92aa805f1de54a','aud_id'=>61,'time'=>'2025-03-17']){ // 尝试捕获异常 - // try { + try { if(count(input('post.')) > 0){ $data = input('post.'); } @@ -101,25 +101,25 @@ class Countfood extends Base{ $return_data = $this->get_countfoot_content_action($data); return $return_data; - // } catch (\Exception $e) { - // // 捕获异常 - // $logContent["file"] = $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' => '系统错误']); - // } + } 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,'s_time'=>'2025-03-15','e_time'=>'2025-03-16']){ // 尝试捕获异常 - // try { + try { if(count(input('post.')) > 0){ $data = input('post.'); } @@ -150,25 +150,25 @@ class Countfood extends Base{ $return_data = $this->get_log_list_action($data); return $return_data; - // } catch (\Exception $e) { - // // 捕获异常 - // $logContent["file"] = $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' => '系统错误']); - // } + } 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 { + try { if(count(input('post.')) > 0){ $data = input('post.'); } @@ -187,25 +187,25 @@ class Countfood extends Base{ $return_data = $this->set_up_content_action($data); return $return_data; - // } catch (\Exception $e) { - // // 捕获异常 - // $logContent["file"] = $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' => '系统错误']); - // } + } 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 { + try { if(count(input('post.')) > 0){ $data = input('post.'); } @@ -230,20 +230,20 @@ class Countfood extends Base{ $return_data = $this->set_user_kcal_action($data); return $return_data; - // } catch (\Exception $e) { - // // 捕获异常 - // $logContent["file"] = $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' => '系统错误']); - // } + } 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####################################################################### @@ -254,6 +254,7 @@ class Countfood extends Base{ // 除 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']]) @@ -262,6 +263,7 @@ class Countfood extends Base{ if(!$user_data){ return $this->msg(10003); } + // 统计食物的id $food_id_arr = []; @@ -286,6 +288,7 @@ class Countfood extends Base{ } 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,name,kcal,carbohydrate,protein,fat') @@ -320,12 +323,13 @@ class Countfood extends Base{ // 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(10001); + return $this->msg(10002,'添加数据错误'); } else { Db::commit(); return $this->msg([]); @@ -335,6 +339,11 @@ class Countfood extends Base{ 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'); diff --git a/application/KitchenScale/controller/app/Index.php b/application/KitchenScale/controller/app/Index.php index 10ff122..1d9b717 100644 --- a/application/KitchenScale/controller/app/Index.php +++ b/application/KitchenScale/controller/app/Index.php @@ -18,9 +18,10 @@ class Index extends Base{ 'cookbook'=>'app_user_cookbook',//菜谱表 'cookbook_label'=>'app_user_cookbook_label',//菜谱标签表 'uploadimg'=>'app_user_upload_img',//图片素材表 - 'foodlist1'=>'app_food_type_one',//食材列表1 - 'foodlist2'=>'app_food_type_two',//食材列表2 - 'foodlist3'=>'app_food_type_three',//食材列表3 + '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',//版本表 @@ -157,7 +158,7 @@ class Index extends Base{ // 获取默认配置信息(包含:食材的分类列表,用户角色信息)(OK) public function get_default_config($data = ['token'=>'']){ - // try { + try { if(count(input('post.')) > 0){ $data = input('post.'); } @@ -169,25 +170,25 @@ class Index extends Base{ // } $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); - // } + } 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'=>'']){ - // try { + public function search_column($data = ['search_data'=>'鱼','token'=>'','page'=>1]){ + try { // 你的业务逻辑 if(count(input('post.')) > 0){ $data = input('post.'); @@ -195,25 +196,31 @@ class Index extends Base{ 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); - // } + } 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####################################################################### @@ -234,9 +241,14 @@ class Index extends Base{ ['name'=>'健康食谱','jump_url'=>'/pages/menu/menu','icon'=>'https://tc.pcxbc.com/kitchenscale_all/vajra4.png'], ], ]; + $cfc = Db::connect('cfc_db'); // // 获取食材分类列表start - $foodlist1 = $cfc->table($this->kitchenscale_db_msg['foodlist1'])->where("is_del = 0")->field('id,name')->select(); + // $foodlist1 = $cfc->table($this->kitchenscale_db_msg['foodlist1'])->where("is_del = 0")->order('sort_num desc')->field('id,name')->select(); + + $foodlist1 = $cfc->query("SELECT id,name FROM ".$this->kitchenscale_db_msg['foodlist1']." WHERE is_del = 0 ORDER BY sort_num"); + // dump($foodlist1); + // die; $foodlist2 = $cfc->table($this->kitchenscale_db_msg['foodlist2'])->where("is_del = 0")->field('id,name,one_id')->select(); // dump($foodlist3); foreach ($foodlist1 as $key => $value) { @@ -314,13 +326,23 @@ class Index extends Base{ // $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([]); } @@ -366,7 +388,12 @@ class Index extends Base{ unset($content_list[$key]['ROW_NUMBER']); } } - return $this->msg($content_list); + + return $this->msg([ + 'page_now'=>$page_now, + 'page_total'=>$page_total, + 'content_list'=>$content_list + ]); } diff --git a/application/KitchenScale/controller/app/Login.php b/application/KitchenScale/controller/app/Login.php new file mode 100644 index 0000000..9130295 --- /dev/null +++ b/application/KitchenScale/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/KitchenScale/controller/app/Usercenter.php b/application/KitchenScale/controller/app/Usercenter.php index 60eea7a..f7eae3d 100644 --- a/application/KitchenScale/controller/app/Usercenter.php +++ b/application/KitchenScale/controller/app/Usercenter.php @@ -37,7 +37,7 @@ class Usercenter extends Base{ // 获取角色信息 public function get_user_msg($data = ['token'=>'caadd1be045a65f30b92aa805f1de54a']){ - // try { + try { if(count(input('post.')) > 0){ $data = input('post.'); } @@ -49,24 +49,24 @@ class Usercenter extends Base{ } $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); - // } + } 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($data = ['token'=>'caadd1be045a65f30b92aa805f1de54a','nickname'=>'测试人员001','gender'=>'1','age'=>'18','height'=>'165.34','weight'=>'55.55']){ - // try { + try { if(count(input('post.')) > 0){ $data = input('post.'); } @@ -108,25 +108,25 @@ class Usercenter extends Base{ } $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); - // } + } 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 { + try { if(count(input('post.')) > 0){ $data = input('post.'); } @@ -144,25 +144,25 @@ class Usercenter extends Base{ } $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); - // } + } 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 { + try { if(count(input('post.')) > 0){ $data = input('post.'); } @@ -180,25 +180,25 @@ class Usercenter extends Base{ } $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); - // } + } 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 { + try { if(count(input('post.')) > 0){ $data = input('post.'); } @@ -222,20 +222,20 @@ class Usercenter extends Base{ } $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); - // } + } 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); + } } diff --git a/application/KitchenScale/controller/app/Wechat.php b/application/KitchenScale/controller/app/Wechat.php index c5ca3b5..c645dd3 100644 --- a/application/KitchenScale/controller/app/Wechat.php +++ b/application/KitchenScale/controller/app/Wechat.php @@ -4,12 +4,13 @@ namespace app\KitchenScale\controller\app; use think\Db; +use PHPMailer\PHPMailer\PHPMailer; class Wechat extends Base{ // reedaw的小程序信息 - private $app_id = 'wx1f32af4f93c913f6'; // 微信小程序的AppID - private $app_secret = '21c6660d94d635cea4831253c60fc6e2'; // 微信小程序的AppSecret + private $app_id = 'wx1f32af4f93c913f6'; // 轻厨记的微信小程序的AppID + private $app_secret = '851f809f6abbbeeeb95d313ada80d025'; // 轻厨记的微信小程序的AppSecret // ed7cda5874f0eef3360e782a3db73c80 diff --git a/application/admin/controller/Appversion.php b/application/admin/controller/Appversion.php index bacad9b..8c813e8 100644 --- a/application/admin/controller/Appversion.php +++ b/application/admin/controller/Appversion.php @@ -38,7 +38,8 @@ class Appversion extends Base{ // if($data['e_time']){ // $parameter['create_time'] = ['<=',$data['e_time']]; // } - } + } + $num = Db::table('app_version_log')->where($parameter)->count(); $result = Db::table('app_version_log')->where($parameter)->order('id desc')->page($page,$this->page_num)->select(); if(!$pd){ diff --git a/application/admin/controller/Editortext.php b/application/admin/controller/Editortext.php index 18c72a0..6759e0f 100644 --- a/application/admin/controller/Editortext.php +++ b/application/admin/controller/Editortext.php @@ -85,6 +85,9 @@ class Editortext extends Base{ if(!$article_data){ return $this->msg(10004); } + if($article_data['scene_id'] == 2){ + header("Location: ".$article_data['content']); + } $result = $article_data; // 处理是否有过点赞 if(array_key_exists('token', $data)){ @@ -155,6 +158,7 @@ class Editortext extends Base{ 'sector'=>implode(',', $data['sector']), 'type'=>implode(',', $data['type']), 'cover_image'=>"upload_pic/".$pic_data['name'], + 'scene_id'=>$data["scene_id"], ]); if($result){ return $this->msg([]); @@ -177,7 +181,8 @@ class Editortext extends Base{ 'update_time'=>date('Y-m-d H:i:s'), 'sector'=>implode(',', $data['sector']), 'type'=>implode(',', $data['type']), - 'cover_image'=>"upload_pic/".$pic_data['name'] + 'cover_image'=>"upload_pic/".$pic_data['name'], + 'scene_id'=>$data["scene_id"], ]); if($result){ return $this->msg([]); diff --git a/application/admin/controller/Notice.php b/application/admin/controller/Notice.php index afeb0ae..f4ebc1d 100644 --- a/application/admin/controller/Notice.php +++ b/application/admin/controller/Notice.php @@ -91,7 +91,7 @@ class Notice extends Base{ 'pic' => $data['banner_img'], 'type' => $data['type'], 'jump_url' => $data['jump_url'], - 'parameter_data' => $data['parameter_data'], + 'parameter_data' => $data['parameter_data'] != '' ? $data['parameter_data'] : 999999, 'create_time' => date('Y-m-d H:i:s'), 'scene_data' => $data['scene_data'], ]; @@ -101,6 +101,8 @@ class Notice extends Base{ $action_data['jump_url'] = "https://tc.pcxbc.com/editortext/model_content"; }else if($action_data['type'] == 2){ $action_data['jump_url'] = "weixin://dl/business/?appid=".$data['parameter_data']."&path=".$data['jump_url']; + }else if($action_data['type'] == 3){ + $action_data['jump_url'] = $data['jump_url']; }else{ return $this->msg(10002,'选择类型错误'); } @@ -108,7 +110,7 @@ class Notice extends Base{ $result = Db::table('admin_notice_banner')->insertGetId($action_data); }else{ unset($action_data['create_time']); - unset($action_data['scene_data']); + // unset($action_data['scene_data']); $result = Db::table('admin_notice_banner')->where(['id'=>$data['id']])->update($action_data); } if($result){ diff --git a/application/admin/view/editortext/add_content.html b/application/admin/view/editortext/add_content.html index 82be58b..847655a 100644 --- a/application/admin/view/editortext/add_content.html +++ b/application/admin/view/editortext/add_content.html @@ -29,7 +29,7 @@
@@ -37,7 +37,7 @@
点击选择
@@ -55,7 +55,7 @@
@@ -76,7 +76,7 @@
@@ -98,9 +98,29 @@
-
+
+ +
+ +
+
+
+ +
+ +
+
+
@@ -186,6 +206,8 @@ var sector_arr = [] var type_arr = [] var pd = true + $('#parameter_data_box').hide(); + $('#editor_wrapper_box').hide(); layui.use(['form'], function () { form = layui.form; form.verify({ @@ -194,6 +216,11 @@ return '请先选择添加标题'; } }, + scene_data: function(value) { + if (value == 0) { + return '请选择场景'; + } + }, }); //监听提交 form.on('submit(add)',function(data) { @@ -267,6 +294,23 @@ } } }); + + form.on('select(scene_data)', function(data){ + var value = data.value; + + // 根据选择的值显示/隐藏对应的元素 + if(value === '1') { + $('#editor_wrapper_box').show(); + $('#parameter_data_box').hide(); + } else if(value === '2') { + $('#parameter_data_box').show(); + $('#editor_wrapper_box').hide(); + } else { + // 值为0或其他时,两个都隐藏 + $('#parameter_data_box').hide(); + $('#editor_wrapper_box').hide(); + } + }); }); @@ -283,6 +327,12 @@ 'sector':sector_arr, 'type':type_arr, 'content':html, + 'scene_id':$('#scene_data').val(), + } + if($('#scene_data').val() == 2){ + data.content = $('#parameter_data').val(); + }else if($('#scene_data').val() == 0){ + return } // var formdata = new FormData(); // formdata.append('cover_image',$('#upload_file_app')[0].files[0]) @@ -290,7 +340,8 @@ // formdata.append('sector',sector_arr) // formdata.append('type',type_arr) // formdata.append('content',html) - // console.log(formdata) + // console.log(data) + // return pd = false load() $.ajax({ diff --git a/application/admin/view/editortext/edit_content.html b/application/admin/view/editortext/edit_content.html index 145c6e2..3f9e129 100644 --- a/application/admin/view/editortext/edit_content.html +++ b/application/admin/view/editortext/edit_content.html @@ -140,7 +140,39 @@
-
+
+ +
+ +
+
+
+ +
+ +
+
+
@@ -169,7 +201,10 @@ $('#banner_img').val(pic_data[0]) } } + + var content_str = '{$result.content}'; + $('#parameter_data').val(content_str) // var content_str = ''; var html const { createEditor, createToolbar } = window.wangEditor @@ -230,8 +265,20 @@ var id = '{$result.id}' var sector_arr = '{$result.sector}'.split(",") var type_arr = '{$result.type}'.split(",") - console.log(sector_arr) + // console.log(sector_arr) + console.log($('#scene_data').val()) var pd = true + if($('#scene_data').val() == 0){ + $('#parameter_data_box').hide(); + $('#editor_wrapper_box').hide(); + }else if($('#scene_data').val() == 1){ + $('#parameter_data_box').hide(); + $('#editor_wrapper_box').show(); + }else if($('#scene_data').val() == 2){ + $('#parameter_data_box').show(); + $('#editor_wrapper_box').hide(); + } + layui.use(['form'], function () { form = layui.form; form.verify({ @@ -240,7 +287,13 @@ return '请先选择添加标题'; } }, + scene_data: function(value) { + if (value == 0) { + return '请选择场景'; + } + }, }); + //监听提交 form.on('submit(add)',function(data) { @@ -313,7 +366,22 @@ } console.log(type_arr) }); - + form.on('select(scene_data)', function(data){ + var value = data.value; + + // 根据选择的值显示/隐藏对应的元素 + if(value === '1') { + $('#editor_wrapper_box').show(); + $('#parameter_data_box').hide(); + } else if(value === '2') { + $('#parameter_data_box').show(); + $('#editor_wrapper_box').hide(); + } else { + // 值为0或其他时,两个都隐藏 + $('#parameter_data_box').hide(); + $('#editor_wrapper_box').hide(); + } + }); }); @@ -333,6 +401,12 @@ 'sector':sector_arr, 'type':type_arr, 'content':html, + 'scene_id':$('#scene_data').val(), + } + if($('#scene_data').val() == 2){ + data.content = $('#parameter_data').val(); + }else if($('#scene_data').val() == 0){ + return } // var formdata = new FormData(); // formdata.append('cover_image',$('#upload_file_app')[0].files[0]) diff --git a/application/admin/view/editortext/index.html b/application/admin/view/editortext/index.html index 36c39be..2441d82 100644 --- a/application/admin/view/editortext/index.html +++ b/application/admin/view/editortext/index.html @@ -171,7 +171,7 @@ } }); }); - + function edit_order_action(e,data,str,id){ if($(e).val() == data){ return diff --git a/application/admin/view/notice/banner_add.html b/application/admin/view/notice/banner_add.html index c2faeed..13c2976 100644 --- a/application/admin/view/notice/banner_add.html +++ b/application/admin/view/notice/banner_add.html @@ -66,10 +66,11 @@ +
-
+
@@ -77,7 +78,7 @@
-
+
@@ -154,8 +155,10 @@ } }, parameter_data: function(value) { - if (value == 0) { - return '请先填写关键参数信息'; + if($('#data_type').val() == '1' || $('#data_type').val() == '2'){ + if (value == 0) { + return '请先填写关键参数信息'; + } } }, jump_url: function(value) { @@ -167,6 +170,20 @@ }, }); + form.on('select(data_type)', function(data){ + $('#parameter_data_box').show(); + $('#jump_url_box').show(); + $('#parameter_data').val(''); + $('#jump_url').val(''); + $('#jump_url').attr('placeholder', ''); + if(data.value == 1){ + // $('#parameter_data_box').hide(); + $('#jump_url_box').hide(); + }else if(data.value == 2){ + }else if(data.value == 3){ + $('#parameter_data_box').hide(); + } + }); //监听提交 form.on('submit(add)',function(data) { //发异步,把数据提交给php diff --git a/application/admin/view/notice/banner_edit.html b/application/admin/view/notice/banner_edit.html index 5be678b..fc4ca48 100644 --- a/application/admin/view/notice/banner_edit.html +++ b/application/admin/view/notice/banner_edit.html @@ -49,17 +49,17 @@
-
- -
- + {if condition="$result.type == 1 or $result.type == 2"} +
+ +
+ +
-
-
+ {else /} + + {/if} + + {if condition="$result.type == 2 or $result.type == 3"} +
@@ -112,6 +133,18 @@
+ {else /} + + {/if} + +
@@ -181,19 +214,37 @@ } }, parameter_data: function(value) { - if (value == 0) { - return '请先填写关键参数信息'; + console.log(value) + if($('#data_type').val() == '1' || $('#data_type').val() == '2'){ + if (value == 0) { + return '请先填写关键参数信息'; + } } }, jump_url: function(value) { - if ($('#data_type').val() == 2) { + + if ($('#data_type').val() == 3) { if($('#jump_url').val() == ''){ - return '请先填写微信小程序页面路径'; + return '请填写公众号文章链接'; } } }, }); + form.on('select(data_type)', function(data){ + $('#parameter_data_box').show(); + $('#jump_url_box').show(); + $('#parameter_data').val(''); + $('#jump_url').val(''); + $('#jump_url').attr('placeholder', ''); + if(data.value == 1){ + // $('#parameter_data_box').hide(); + $('#jump_url_box').hide(); + }else if(data.value == 2){ + }else if(data.value == 3){ + $('#parameter_data_box').hide(); + } + }); //监听提交 form.on('submit(add)',function(data) { //发异步,把数据提交给php diff --git a/application/app/controller/Base.php b/application/app/controller/Base.php index 7138526..b2c3a02 100644 --- a/application/app/controller/Base.php +++ b/application/app/controller/Base.php @@ -712,6 +712,9 @@ class Base extends Controller{ public function ceshiyong($aa = 4,$gd = 0.2){ + + phpinfo(); + die; $token = 'cd3f27cf4c4002170ea7bceeb723ac91'; $data = Db::table('pc_bmistand2')->select(); diff --git a/application/app/controller/Card.php b/application/app/controller/Card.php index 183be18..77faa7c 100644 --- a/application/app/controller/Card.php +++ b/application/app/controller/Card.php @@ -319,7 +319,7 @@ class Card extends Base{ } // 修改初始体重/目标体重 - public function card_modify_weight($data = ['aud_id'=>'11','weight'=>'50','type'=>2,'time'=>'2024-10-01','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ + public function card_modify_weight($data = ['aud_id'=>'3967','weight'=>'124','type'=>1,'time'=>'','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ try { // 你的业务逻辑 if(count(input('post.')) > 0){ @@ -1214,6 +1214,7 @@ class Card extends Base{ where acbd.aud_id = ".$data['aud_id']." order by acbd.record_time desc "); + if($data['type'] == 1){ // 修改目标体重 $bhw_date = ['target_weight'=>$data['weight']]; @@ -1224,13 +1225,13 @@ class Card extends Base{ return $this->msg(10005); } $result_update = Db::table($this->card_use_db_name['2'])->where(['id'=>$data['aud_id']])->update($bhw_date); - + // $result_update = true; if($result_update){ $target_current = $this->base_target_initial_cumulative_weight([ - 'weight'=>$result[0]['weight'], - 'target_weight'=>$data['type'] == 1?$data['weight']:$result[0]['target_weight'], - 'initial_weight'=>$data['type'] == 1?$result[0]['initial_weight']:$data['weight'], - 'initial_date'=>$data['type'] == 1?$result[0]['initial_date']:$data['time'], + 'weight'=>count($result) <= 0?0:$result[0]['weight'], + 'target_weight'=>$data['type'] == 1?$data['weight']:(count($result) <= 0?0:$result[0]['target_weight']), + 'initial_weight'=>$data['type'] == 1?(count($result) <= 0?0:$result[0]['initial_weight']):$data['weight'], + 'initial_date'=>$data['type'] == 1?(count($result) <= 0?'':$result[0]['initial_date']):$data['time'], ]); return $this->msg($target_current); diff --git a/application/app/controller/Login.php b/application/app/controller/Login.php index da24dca..34454ba 100644 --- a/application/app/controller/Login.php +++ b/application/app/controller/Login.php @@ -11,7 +11,7 @@ use app\app\controller\Wechat;// 引入Wechat服务类 class Login extends Base{ protected $code_time = 50; // protected $token_time = 2592000;//30天的秒数 - protected $default_head_pic = 'http://tc.pcxbc.com/tsf/head_pic.png'; + protected $default_head_pic = 'https://tc.pcxbc.com/tsf/head_pic.png'; protected $login_use_db_name = [ '1'=>'app_account_number', ]; @@ -457,7 +457,7 @@ class Login extends Base{ */ public function send_tel_code($tel,$code){ // 初始化cURL会话 - $ch = curl_init(); + $ch = curl_init(); $headers = [ 'Accept: application/json', 'Content-Type: application/json', @@ -472,12 +472,10 @@ class Login extends Base{ // 设置POST数据 $postData = array( 'phone' => $tel, - // 'content' => '您好,欢迎使用Reedaw,您的手机验证码是:'.$code.',验证码三分钟内有效,若非本人操作,请忽略!' - // 'content' => '【Reedaw】您好,欢迎使用Reedaw,您的验证码是:'.$code.',验证码一分钟内有效,若非本人操作,请忽略本短信' - 'content' => '【巨天】您好,欢迎使用Reedaw,您的手机验证码是:'.$code.',验证码一分钟内有效,若非本人操作,请忽略本短信' - // 'content' => '【小白秤】您好,欢迎使用Reedaw,您的手机验证码是:'.$code.',验证码一分钟内有效,若非本人操作,请忽略本短信' - // 'content' => '【品传科技】您好,欢迎使用Reedaw,您的手机验证码是:'.$code.',验证码一分钟内有效,若非本人操作,请忽略本短信' - // 'content' => '【巨天】您好,欢迎使用巨天,您的手机验证码是:'.$code.',验证码一分钟内有效,若非本人操作,请忽略!' + // 'content' => '【巨天】您好,欢迎使用Reedaw,您的手机验证码是:'.$code.',验证码一分钟内有效,若非本人操作,请忽略本短信' + // 'content' => '【郑州品传科技】您好,欢迎使用Reedaw,您的手机验证码是:'.$code.',验证码一分钟内有效,若非本人操作,请忽略本短信' + // 'content' => '【每日一称】您好,欢迎使用Reedaw,您的手机验证码是:'.$code.',验证码一分钟内有效,若非本人操作,请忽略本短信' + 'content' => '【小白健康】您好,欢迎使用Reedaw,您的手机验证码是:'.$code.',验证码一分钟内有效,若非本人操作,请忽略本短信' ); $postData = json_encode($postData); curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); @@ -501,6 +499,31 @@ class Login extends Base{ 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'] diff --git a/application/app/controller/Msginformation.php b/application/app/controller/Msginformation.php index 9139895..b648df5 100644 --- a/application/app/controller/Msginformation.php +++ b/application/app/controller/Msginformation.php @@ -448,7 +448,7 @@ class Msginformation extends Base{ ]; // return $this->msg($return_data); // 所有可用记录. - $all_data = Db::table($this->msginformation_use_db_name['3'])->where("is_del = 0 AND scene_data IN (1,2,3)")->select(); + $all_data = Db::table($this->msginformation_use_db_name['3'])->where("is_del = 0 AND scene_data IN (1,2,3)")->order('sort_num')->select(); // 用户阅读记录 $user_read_log = Db::table($this->msginformation_use_db_name['2'])->where(['token'=>$data['token']])->field('aetc_id')->select(); $user_read_data = []; @@ -460,7 +460,9 @@ class Msginformation extends Base{ foreach ($all_data as $key => $value) { if($value['type'] == '1'){ if(in_array($value['parameter_data'], $user_read_data)){ + // 如果读过 if($value['scene_data'] != 3){ + // 如果不是banner unset($all_data[$key]); }else{ // $all_data[$key]['jump_url'] = $all_data[$key]['jump_url']."&token=".$data['token']; @@ -474,6 +476,10 @@ class Msginformation extends Base{ $all_data[$key]['type'] = 'h5'; $all_data[$key]['id'] = $value['parameter_data']; } + }else if($value['type'] == '3'){ + $all_data[$key]['jump_url'] = $all_data[$key]['jump_url']; + $all_data[$key]['type'] = 'h5'; + $all_data[$key]['id'] = $value['parameter_data']; }else{ $all_data[$key]['type'] = 'wechat'; // 提取查询字符串部分(?后面的部分) @@ -500,12 +506,14 @@ class Msginformation extends Base{ // 分类信息 foreach ($all_data as $key => $value) { // 1:首屏弹窗,2:滚动公告,3:banner + if($value['scene_data'] == '1'){ array_push($return_data['pop'],$value); }else if($value['scene_data'] == '2'){ array_push($return_data['notice'],$value); }else if($value['scene_data'] == '3'){ + array_push($return_data['banner'],$value); } } diff --git a/application/app/controller/Skip.php b/application/app/controller/Skip.php index d5feb2d..b930eba 100644 --- a/application/app/controller/Skip.php +++ b/application/app/controller/Skip.php @@ -64,6 +64,8 @@ class Skip extends Base{ if($this->validate_user_identity($data['aud_id']) === false){ $return_data = $this->msg(10003); } + + $return_data = $this->skip_manual_recording_action($data); // 成功 @@ -251,7 +253,7 @@ class Skip extends Base{ // 分秒转换为秒 $data['time'] = abs($data['time_m'])*60+abs($data['time_s']); $user_msg_content = Db::table($this->skip_use_db_name['2'])->where(['id'=>$data['aud_id']])->count(); - if($user_msg_content<=0){ + if($user_msg_content<=0){ return $this->msg(10004); } if(!array_key_exists('kcal', $data)){ @@ -278,6 +280,7 @@ class Skip extends Base{ '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'], diff --git a/application/code/controller/Qrcode.php b/application/code/controller/Qrcode.php index 704dc34..e26f3fd 100644 --- a/application/code/controller/Qrcode.php +++ b/application/code/controller/Qrcode.php @@ -364,9 +364,29 @@ class Qrcode extends Base{ + ##################################################################儿童膳食食谱文档跳转start################################################################## + ##################################################################儿童膳食食谱文档跳转start################################################################## + ##################################################################儿童膳食食谱文档跳转start################################################################## + + public function children_meals_cookbook(){ + // header("Location: http://121.36.67.254:3000/tiansf/childrens-dietary-recipes"); + header("Location: http://git.ybhdmob.com:3000/tiansf/childrens-dietary-recipes"); + } + ##################################################################儿童膳食食谱文档跳转end################################################################## + ##################################################################儿童膳食食谱文档跳转end################################################################## + ##################################################################儿童膳食食谱文档跳转end################################################################## + ##################################################################二维码-厨房秤小程序跳转start################################################################## + ##################################################################二维码-厨房秤小程序跳转start################################################################## + ##################################################################二维码-厨房秤小程序跳转start################################################################## + public function kitchen_qrcode(){ + return $this->fetch(); + } + ##################################################################二维码-厨房秤小程序跳转end################################################################## + ##################################################################二维码-厨房秤小程序跳转end################################################################## + ##################################################################二维码-厨房秤小程序跳转end################################################################## diff --git a/application/code/view/qrcode/kitchen_qrcode.html b/application/code/view/qrcode/kitchen_qrcode.html new file mode 100644 index 0000000..35f403e --- /dev/null +++ b/application/code/view/qrcode/kitchen_qrcode.html @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + loading... + + + + + + + + + + + diff --git a/application/route.php b/application/route.php index 857f313..7bbbc08 100644 --- a/application/route.php +++ b/application/route.php @@ -45,6 +45,12 @@ Route::any('/little_tips_del_action', 'code/qrcode/little_tips_del_action'); Route::any('/add_label_action', 'code/qrcode/add_label_action'); Route::any('/update_title_action', 'code/qrcode/update_title_action'); +// 儿童膳食食谱 +Route::any('/children_meals_cookbook', 'code/qrcode/children_meals_cookbook'); + +// 厨房秤的二维码 +Route::any('/kitchen_qrcode', 'code/qrcode/kitchen_qrcode'); + @@ -462,7 +468,6 @@ Route::any('/testedition/kitchenscale/pic_upload_action', 'app/kitchenscale/test // 首页内容################################################################ - // 检测版本及判断是否登录失效 Route::any('/kitchenscale/login_invalid_version', 'app/Kitchenscale/app.Index/login_invalid_version'); Route::any('/testedition/kitchenscale/login_invalid_version', 'app/kitchenscale/testapp.index/login_invalid_version'); @@ -512,8 +517,9 @@ Route::any('/testedition/kitchenscale/get_food_list', 'app/kitchenscale/testapp. // 获取所有食谱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'); // 计食器################################################################ @@ -535,8 +541,6 @@ Route::any('/testedition/kitchenscale/set_user_kcal', 'app/kitchenscale/testapp. // 我的################################################################ - - // 获取角色信息 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'); @@ -553,6 +557,13 @@ Route::any('/testedition/kitchenscale/get_my_cookbook', 'app/kitchenscale/testap 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'); +// 百度图片识别接口################################################################ +// 获取AccessToken +// Route::any('/kitchenscale/baidu_get_accesstoken', 'app/kitchenscale/app.aipart/baidu_get_accesstoken'); +// 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'); + // 测试用内容################################################################ @@ -581,6 +592,25 @@ Route::any('/testedition/ceshiyong', 'testapp/base/ceshiyong'); Route::any('/kitchenscale/chuli_shuju', 'app/kitchenscale/app.cookbook/chuli_shuju'); +// 测试用控制器 +Route::any('/readExcelFile_a', 'test/testuse/readExcelFile_a'); +Route::any('/readExcelFile_b', 'test/testuse/readExcelFile_b'); +Route::any('/save_caidan_content', 'test/testuse/save_caidan_content'); +Route::any('/caipu_shuju_chuli', 'test/testuse/caipu_shuju_chuli'); +Route::any('/clean_data_all_page', 'test/testuse/clean_data_all_page'); +Route::any('/clean_data_all', 'test/testuse/clean_data_all'); +Route::any('/download_picture_api', 'test/testuse/download_picture_api'); +Route::any('/update_cookbook_data_api', 'test/testuse/update_cookbook_data_api'); +Route::any('/cun_bendi_pic', 'test/testuse/cun_bendi_pic'); + + + + + + + + + // Route::any('/app_update_file/*', 'app/sportstesting/aaaaaaaaaaaaaaa'); // 处理404错误 z diff --git a/application/test/controller/Testuse.php b/application/test/controller/Testuse.php new file mode 100644 index 0000000..400d47e --- /dev/null +++ b/application/test/controller/Testuse.php @@ -0,0 +1,776 @@ +getSheet(0); + + // 将工作表数据转换为数组 + $data = $sheet->toArray(); + + $temporary_arr_title = $data[0]; + unset($data[0]); + $temporary_arr = []; + $temporary_arr2 = []; + foreach ($data as $key => $value) { + if($value[0] == 112 || $value[0] == 113 || $value[0] == 114 || $value[0] == 115 || $value[0] == 116 || $value[0] == 117 || $value[0] == 118 || $value[0] == 119 || $value[0] == 120 || $value[0] == 121){ + // unset(); + unset($data[$key]); + } + } + foreach ($data as $key => $value) { + $temporary_arr2 = []; + foreach ($temporary_arr_title as $k => $v) { + $temporary_arr2[$v] = $value[$k]; + } + array_push($temporary_arr,$temporary_arr2); + } + + foreach ($temporary_arr as $key => $value) { + $temporary_arr[$key]['record_id'] = $value['id']; + $temporary_arr[$key]['Calorie_name'] = $value['Calorie']; + $temporary_arr[$key]['Protein_name'] = $value['Protein']; + $temporary_arr[$key]['Fat_name'] = $value['Fat']; + $temporary_arr[$key]['Carbohydrate_name'] = $value['Carbohydrate']; + $temporary_arr[$key]['food_name'] = $value['name']; + unset($temporary_arr[$key]['id']); + unset($temporary_arr[$key]['Calorie']); + unset($temporary_arr[$key]['Protein']); + unset($temporary_arr[$key]['Fat']); + unset($temporary_arr[$key]['Carbohydrate']); + unset($temporary_arr[$key]['name']); + + if($value['image'] == ''){ + $temporary_arr[$key]['pic_url'] = '/food_img/none.png'; + }else{ + $result = $this->downloadImageWithName($value['image'], $value['id']); + if($result['success'] == true){ + $temporary_arr[$key]['pic_url'] = '/food_img/'.$result['filename']; + }else{ + $temporary_arr[$key]['pic_url'] = 'error'; + } + } + unset($temporary_arr[$key]['image']); + } + // dump($temporary_arr); + // die; + $cfc = Db::connect('cfc_db'); + // 获取账号下信息以及用户信息 + $user_data = $cfc->table('app_z_national_standard_food_type_3')->insertAll($temporary_arr); + + dump($user_data); + + die; + } catch (\Exception $e) { + // 输出错误信息 + dump(['error' => true, 'message' => $e->getMessage()]); + } + } + // 收集表B + public function readExcelFile_b() { + // Excel文件路径(示例) + $filePath = 'D:\数据\厨房秤\食谱\excelB.xlsx'; + + try { + // 加载Excel文件 + $spreadsheet = IOFactory::load($filePath); + + // 获取第一个工作表(Sheet1) + $sheet = $spreadsheet->getSheet(0); + + // 将工作表数据转换为数组 + $data = $sheet->toArray(); + + $temporary_arr_title = $data[0]; + unset($data[0]); + $temporary_arr = []; + $temporary_arr2 = []; + + foreach ($data as $key => $value) { + if($value[0] == 112 || $value[0] == 113 || $value[0] == 114 || $value[0] == 115 || $value[0] == 116 || $value[0] == 117 || $value[0] == 118 || $value[0] == 119 || $value[0] == 120 || $value[0] == 121){ + // unset(); + unset($data[$key]); + } + } + + foreach ($data as $key => $value) { + $temporary_arr2 = []; + foreach ($temporary_arr_title as $k => $v) { + $temporary_arr2[$v] = $value[$k]; + } + $temporary_arr2['name_ch'] = $temporary_arr2['desc']; + unset($temporary_arr2['desc']); + unset($temporary_arr2['description']); + + array_push($temporary_arr,$temporary_arr2); + } + // dump($temporary_arr); + $cfc = Db::connect('cfc_db'); + // 获取账号下信息以及用户信息 + $user_data = $cfc->table('app_z_national_standard_food_type_4')->insertAll($temporary_arr); + + dump($user_data); + + die; + } catch (\Exception $e) { + // 输出错误信息 + dump(['error' => true, 'message' => $e->getMessage()]); + } + } + + public function downloadImageWithName($remoteUrl, $name, $localDir = '') + { + try { + // 设置默认本地目录 + if (empty($localDir)) { + $localDir = 'D:\phpstudy_pro\WWW\reedaw\SchoolPhysicalExamination\public\food_img'; + // $localDir = 'D:\phpstudy_pro\WWW\reedaw\SchoolPhysicalExamination\public\kitchenscale_all\cook_img'; + + } + + // 检查并创建目录 + if (!is_dir($localDir)) { + mkdir($localDir, 0755, true); + } + + // 从URL中获取文件扩展名 + $urlParts = parse_url($remoteUrl); + $pathInfo = pathinfo($urlParts['path']); + $extension = isset($pathInfo['extension']) ? $pathInfo['extension'] : 'jpg'; + + // 构建完整文件名和路径 + $filename = $name . 'xt' . time() . '.jpg'; + $localPath = rtrim($localDir, '/\\') . DIRECTORY_SEPARATOR . $filename; + + // 使用cURL下载图片 + $ch = curl_init($remoteUrl); + $fp = fopen($localPath, 'wb'); + + curl_setopt($ch, CURLOPT_FILE, $fp); + curl_setopt($ch, CURLOPT_HEADER, 0); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); + curl_setopt($ch, CURLOPT_TIMEOUT, 30); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + + $result = curl_exec($ch); + $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + + curl_close($ch); + fclose($fp); + + // 验证下载结果 + if ($result === false || $httpCode != 200 || !file_exists($localPath)) { + throw new \Exception('图片下载或保存失败'); + } + + // 返回简化结果 + return [ + 'success' => true, + 'filename' => $filename + ]; + + } catch (\Exception $e) { + Log::error('图片下载失败: ' . $e->getMessage() . ' URL: ' . $remoteUrl); + return [ + 'success' => false, + 'filename' => '' + ]; + } + } + + public function downloadImageWithName2($remoteUrl, $name, $localDir = ''){ + try { + // 设置默认本地目录 + if (empty($localDir)) { + // $localDir = 'D:\phpstudy_pro\WWW\reedaw\SchoolPhysicalExamination\public\food_img'; + $localDir = 'D:\phpstudy_pro\WWW\reedaw\SchoolPhysicalExamination\public\kitchenscale_all\cook_img'; + } + // 检查并创建目录 + if (!is_dir($localDir)) { + mkdir($localDir, 0755, true); + } + + // 从URL中获取文件扩展名 + $urlParts = parse_url($remoteUrl); + $pathInfo = pathinfo($urlParts['path']); + $extension = isset($pathInfo['extension']) ? $pathInfo['extension'] : 'jpg'; + + // 构建完整文件名和路径 + $filename = $name . 'cook' . time() . '.jpg'; + $localPath = rtrim($localDir, '/\\') . DIRECTORY_SEPARATOR . $filename; + + // 使用cURL下载图片 + $ch = curl_init($remoteUrl); + $fp = fopen($localPath, 'wb'); + + curl_setopt($ch, CURLOPT_FILE, $fp); + curl_setopt($ch, CURLOPT_HEADER, 0); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); + curl_setopt($ch, CURLOPT_TIMEOUT, 30); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + + $result = curl_exec($ch); + $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + + curl_close($ch); + fclose($fp); + + // 验证下载结果 + if ($result === false || $httpCode != 200 || !file_exists($localPath)) { + return [ + 'success' => false, + 'filename' => '图片下载或保存失败' + ]; + } + + // 返回简化结果 + return [ + 'success' => true, + 'filename' => $filename + ]; + + } catch (\Exception $e) { + Log::error('图片下载失败: ' . $e->getMessage() . ' URL: ' . $remoteUrl); + return [ + 'success' => false, + 'filename' => '图片下载或保存失败' + ]; + } + } + + // + // 偷数据存start######################################################################################################### + public function save_caidan_content(){ + + // 添加CORS响应头(必须放在任何输出之前) + header('Access-Control-Allow-Origin: https://www.nutridata.cn'); + header('Access-Control-Allow-Methods: POST, OPTIONS'); + header('Access-Control-Allow-Headers: Content-Type'); + + // 如果是OPTIONS预检请求,直接返回204 + if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') { + header('HTTP/1.1 204 No Content'); + exit; + } + + + $data = input('post.'); + $pic = 'none_str'; + // if($data['image'] == ''){ + // $pic = '/kitchenscale_all/food_img/none.png'; + // }else{ + // $result = $this->downloadImageWithName2($data['image'], $data['id']); + // if($result['success'] == true){ + // $pic = '/kitchenscale_all/cook_img/'.$result['filename']; + // }else{ + // $pic = 'error'; + // } + // } + + $save_data['content'] = json_encode($data); + // $save_data['pic_url'] = $pic; + + $cfc = Db::connect('cfc_db'); + // 获取账号下信息以及用户信息 + $user_data = $cfc->table('linshi_caidan_biao')->insert($save_data); + + if($user_data){ + return $this->msg(0,'success',[]); + }else{ + return $this->msg(9999,'error',[]); + } + } + // 偷数据存end######################################################################################################### + + + // 处理(洗)偷过来的数据start######################################################################################################### + + public function clean_data_all_page(){ + return $this->fetch(); + } + + public function clean_data_all(){ + + $page = 1; + $ok_num = 0; + $no_num = 0; + $jieshou_data = input(); + + $page = $jieshou_data['page']; + $cfc = Db::connect('cfc_db'); + $cha = $cfc->table('linshi_caidan_biao')->where('is_clean = 0')->page("$page,25")->select(); + + // dump(); + // die; + if(count($cha) <= 0){ + return $this->msg(99999,'失败',[]); + } + + foreach ($cha as $key => $value) { + $cha[$key]['data'] = json_decode($value['content'],true); + } + + $cookbook_arr = []; + $foodlist_arr = []; + + $cookbook_nutrition = [];//营养 + $cookbook_vitamin = [];//维生素 + $cookbook_mineral = [];//矿物质 + $cookbook_quantifier = [];//量词 + + + $foodlist_arr_temporary = []; + foreach ($cha as $key => $value) { + $cookbook_nutrition = [];//营养 + $cookbook_vitamin = [];//维生素 + $cookbook_mineral = [];//矿物质 + $cookbook_quantifier = [];//量词 + $cookbook_arr = []; + $foodlist_arr_temporary = []; + // 处理食谱详情 + $cookbook_arr['title'] = $value['data']['name']; + $cookbook_arr['cover'] = 19; + $cookbook_arr['create_user_token'] = 'caadd1be045a65f30b92aa805f1de54a'; + $cookbook_arr['create_user_head_pic'] = "https://tc.pcxbc.com/tsf/head_pic.png"; + $cookbook_arr['create_user_nickname'] = "clown"; + $cookbook_arr['describe_data'] = ""; + $cookbook_arr['food_data'] = []; + $cookbook_arr['step_data'] = []; + $cookbook_arr['create_time'] = date('Y-m-d H:i:s'); + $cookbook_arr['cook_label'] = 8; + $cookbook_arr['original_cookbook_id'] = $value['data']['id']; + + foreach ($value['data']['major'] as $k1 => $v1) { + $zhao = $cfc->table('app_z_national_standard_food_type_3')->where(['record_id'=>$v1['ingrId']])->select(); + if(count($zhao) > 0){ + array_push($cookbook_arr['food_data'],[ + 'id' => $zhao[0]['id'], + 'name' => $zhao[0]['food_name'], + 'weight' => $v1['note'], + 'kcal' => $zhao[0]['Calorie_val'], + 'unit' => 'g', + ]); + array_push($foodlist_arr_temporary,$zhao[0]['id']); + } + } + + foreach ($value['data']['dishCooksteps'] as $k2 => $v2) { + if($v2['content'] != ''){ + array_push($cookbook_arr['step_data'],[ + 'pic_list' => [], + 'description' => $v2['content'] + ]); + } + } + $cookbook_arr['food_data'] = json_encode($cookbook_arr['food_data']); + $cookbook_arr['step_data'] = json_encode($cookbook_arr['step_data']); + + + + // 处理营养物质 + foreach ($value['data']['nutritionMap']['能量及宏量营养素'] as $nutrition_k => $nutrition_v) { + array_push($cookbook_nutrition,[ + 'name_en'=>$nutrition_v['name'], + 'name_ch'=>$nutrition_v['desc'], + 'unit'=>$nutrition_v['unit'], + 'value'=>$nutrition_v['value'], + 'nrv'=>$nutrition_v['nrv'], + 'nutriSort'=>$nutrition_v['nutriSort'], + 'description'=>$nutrition_v['description'], + ]); + } + // 处理维生素 + foreach ($value['data']['nutritionMap']['维生素'] as $vitamin_k => $vitamin_v) { + array_push($cookbook_vitamin,[ + 'name_en'=>$vitamin_v['name'], + 'name_ch'=>$vitamin_v['desc'], + 'unit'=>$vitamin_v['unit'], + 'value'=>$vitamin_v['value'], + 'nrv'=>$vitamin_v['nrv'], + 'nutriSort'=>$vitamin_v['nutriSort'], + 'description'=>$vitamin_v['description'], + ]); + } + // 处理矿物质 + foreach ($value['data']['nutritionMap']['矿物质'] as $mineral_k => $mineral_v) { + array_push($cookbook_mineral,[ + 'name_en'=>$mineral_v['name'], + 'name_ch'=>$mineral_v['desc'], + 'unit'=>$mineral_v['unit'], + 'value'=>$mineral_v['value'], + 'nrv'=>$mineral_v['nrv'], + 'nutriSort'=>$mineral_v['nutriSort'], + 'description'=>$mineral_v['description'], + ]); + } + // 处理量词 + foreach ($value['data']['unit'] as $quantifier_k => $quantifier_v) { + array_push($cookbook_quantifier,[ + 'name_ch'=>$quantifier_v['unit'], + 'value'=>$quantifier_v['value'], + ]); + } + + + + // 启动事务 + $cfc->startTrans(); + try{ + // 存食谱 + $cook_book_id = $cfc->table('app_user_cookbook')->insertGetId($cookbook_arr); + // 存食谱所含食材 + $foodlist_arr = []; + foreach ($foodlist_arr_temporary as $k3 => $v3) { + array_push($foodlist_arr,['cookbook_id'=>$cook_book_id,'food_id'=>$v3]); + } + $cfc->table('app_user_cookbook_food_relation')->insertAll($foodlist_arr); + //存营养 + foreach ($cookbook_nutrition as $k4 => $v4) { + $cookbook_nutrition[$k4]['cookbook_id'] = $cook_book_id; + } + // dump($cookbook_nutrition); + $cfc->table('app_user_cookbook_nutrition')->insertAll($cookbook_nutrition); + //存维生素 + foreach ($cookbook_vitamin as $k5 => $v5) { + $cookbook_vitamin[$k5]['cookbook_id'] = $cook_book_id; + } + // dump($cookbook_vitamin); + $cfc->table('app_user_cookbook_vitamin')->insertAll($cookbook_vitamin); + //存矿物质 + foreach ($cookbook_mineral as $k6 => $v6) { + $cookbook_mineral[$k6]['cookbook_id'] = $cook_book_id; + } + // dump($cookbook_mineral); + $cfc->table('app_user_cookbook_mineral')->insertAll($cookbook_mineral); + // //存量词 + foreach ($cookbook_quantifier as $k7 => $v7) { + $cookbook_quantifier[$k7]['cookbook_id'] = $cook_book_id; + } + $cfc->table('app_user_cookbook_quantifier')->insertAll($cookbook_quantifier); + + + // 修改原始数据 + $cfc->table('linshi_caidan_biao')->where(['id'=>$value['id']])->update(['is_clean'=>1,'name'=>$value['data']['name'],'yuanshi_id'=>$value['data']['id']]); + // 提交事务 + $cfc->commit(); + $ok_num = $ok_num+1; + } catch (\Exception $e) { + // 回滚事务 + $cfc->rollback(); + $no_num = $no_num+1; + } + } + // dump($ok_num); + // dump($no_num); + // die; + return $this->msg(0,'成功',['ok'=>$ok_num,'no'=>$no_num]); + } + // 处理(洗)偷过来的数据end######################################################################################################### + + + // 获取图片接口start######################################################################################################### + public function download_picture_api(){ + // 添加CORS响应头(必须放在任何输出之前) + header('Access-Control-Allow-Origin: https://www.nutridata.cn'); + header('Access-Control-Allow-Methods: POST, OPTIONS'); + header('Access-Control-Allow-Headers: Content-Type'); + + // 如果是OPTIONS预检请求,直接返回204 + if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') { + header('HTTP/1.1 204 No Content'); + exit; + } + $cfc = Db::connect('cfc_db'); + $result = $cfc->table('linshi_caidan_biao')->where("pic_clean = 0")->field('id,pic_url,is_clean,name,yuanshi_id')->find(); + if($result){ + return $this->msg(0,'成功',$result); + }else{ + return $this->msg(99999,'失败',[]); + } + } + + public function update_cookbook_data_api(){ + // 添加CORS响应头(必须放在任何输出之前) + header('Access-Control-Allow-Origin: https://www.nutridata.cn'); + header('Access-Control-Allow-Methods: POST, OPTIONS'); + header('Access-Control-Allow-Headers: Content-Type'); + + // 如果是OPTIONS预检请求,直接返回204 + if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') { + header('HTTP/1.1 204 No Content'); + exit; + } + $data = input('post.'); + // return $this->msg(0,'成功',$data); + + $cfc = Db::connect('cfc_db'); + $result = $cfc->table('linshi_caidan_biao')->where(["yuanshi_id"=>$data['id']])->update(['category'=>$data['category']]); + if($result){ + return $this->msg(0,'成功',$result); + }else{ + return $this->msg(99999,'失败',[]); + } + } + + public function cun_bendi_pic() + { + // 记录接收到的数据 + // file_put_contents('request_log.txt', date('Y-m-d H:i:s')."\n".json_encode($_POST)."\n\n", FILE_APPEND); + // 强制设置 JSON 响应头 + header('Content-Type: application/json; charset=utf-8'); + header('Access-Control-Allow-Origin: *'); + header('Access-Control-Allow-Methods: POST, OPTIONS'); + header('Access-Control-Allow-Headers: Content-Type'); + + + if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') { + exit; + } + $data = input('post.'); + $cfc = Db::connect('cfc_db'); + $msg_str = '本次存储成功'; + $update_data = [ + 'pic_clean'=>1 + ]; + + if(!array_key_exists('id',$data) || $data['id'] == ''){ + // $update_data['pic_url'] = 'id_miss'; + // $updateResult = $cfc->table('linshi_caidan_biao') + // ->where(["yuanshi_id" => $data['id']]) + // ->update($update_data); + + return $this->msg(0, $msg_str,'id_miss'); + } + if(!array_key_exists('image',$data) || $data['image'] == ''){ + $update_data['pic_url'] = 'no_data'; + $updateResult = $cfc->table('linshi_caidan_biao') + ->where(["yuanshi_id" => $data['id']]) + ->update($update_data); + return $this->msg(0, $msg_str,'no_data'); + } + + $pic_result = $this->downloadImageWithName2($data['image'],$data['id']); + + $update_data['pic_url'] = $pic_result['filename']; + + // 更新数据库 + $cfc = Db::connect('cfc_db'); + $updateResult = $cfc->table('linshi_caidan_biao') + ->where(["yuanshi_id" => $data['id']]) + ->update($update_data); + + return $this->msg(0, $msg_str,$updateResult); + + } + + + // public function cun_bendi_pic() + // { + // // 强制设置 JSON 响应头 + // header('Content-Type: application/json; charset=utf-8'); + // header('Access-Control-Allow-Origin: *'); + // header('Access-Control-Allow-Methods: POST, OPTIONS'); + // header('Access-Control-Allow-Headers: Content-Type'); + + // if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') { + // exit; + // } + + // try { + // // 确保获取原始 POST 数据 + // $rawData = file_get_contents('php://input'); + // $data = json_decode($rawData, true); + + // if (empty($data['id']) || empty($data['image'])) { + // throw new Exception('参数不完整'); + // } + + // // 验证 id 是否为整数 + // if (!is_numeric($data['id'])) { + // throw new Exception('ID 必须为整数'); + // } + + // $id = (int)$data['id']; + // $ossUrl = trim($data['image']); + + // // 验证 OSS 链接 + // if (!filter_var($ossUrl, FILTER_VALIDATE_URL)) { + // throw new Exception('无效的 OSS 链接'); + // } + + // $filename = $id . 'cook' . time() . '.jpg'; + // $savePath = 'D:/phpstudy_pro/WWW/reedaw/SchoolPhysicalExamination/public/kitchenscale_all/cook_img/'; + + // // 创建目录(如果不存在) + // if (!file_exists($savePath)) { + // mkdir($savePath, 0777, true); + // } + + // // 使用 cURL 获取 OSS 图片(更可靠) + // $ch = curl_init(); + // curl_setopt($ch, CURLOPT_URL, $ossUrl); + // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + // curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); + // $imageData = curl_exec($ch); + + // if (curl_errno($ch)) { + // throw new Exception('获取 OSS 图片失败: ' . curl_error($ch)); + // } + + // $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + // curl_close($ch); + + // if ($httpCode !== 200) { + // throw new Exception('OSS 返回错误状态码: ' . $httpCode); + // } + + // // 保存图片 + // $result = file_put_contents($savePath . $filename, $imageData); + // if ($result === false) { + // throw new Exception('写入文件失败'); + // } + + // // 更新数据库 + // $update_data = [ + // 'pic_clean' => 1, + // 'pic_url' => $filename + // ]; + + // $cfc = Db::connect('cfc_db'); + // $updateResult = $cfc->table('linshi_caidan_biao') + // ->where(["yuanshi_id" => $id]) + // ->update($update_data); + + // // 返回成功响应 + // echo json_encode([ + // 'code' => 0, + // 'msg' => '图片保存成功', + // 'data' => [ + // 'filename' => $filename, + // 'db_affected' => $updateResult + // ] + // ], JSON_UNESCAPED_UNICODE); + + // } catch (Exception $e) { + // // 返回错误响应 + // echo json_encode([ + // 'code' => 1, + // 'msg' => $e->getMessage(), + // 'data' => null + // ], JSON_UNESCAPED_UNICODE); + // } + + // exit; // 确保没有其他输出 + // } + + // 获取图片接口end######################################################################################################### + + + public function caipu_shuju_chuli() + { + // 初始化SQL Server数据库连接 + $cfc = Db::connect('cfc_db'); + // 查询需要处理的原始数据 + $yuanshi_data = $cfc->table('linshi_caidan_biao') + ->where(['pic_clean' => 1,'is_move_ok'=>0]) + ->page("1,100") + ->field('id,pic_url,name,yuanshi_id,category,pic_clean') + ->select(); + // dump($yuanshi_data); + // die; + + $yuanshi_mulu = 'D:\phpstudy_pro\WWW\reedaw\SchoolPhysicalExamination\public\kitchenscale_all\cook_img'; + $new_mulu = 'D:\phpstudy_pro\WWW\reedaw\SchoolPhysicalExamination\public\kitchenscale_all\cook_img\linshi'; + + + $result = [ + 'all'=>count($yuanshi_data), + 'ok'=>0, + 'no'=>0, + 'none'=>0, + ]; + + $temporary_arr_data = []; + $temporary_arr_ok = []; + $temporary_arr_none = []; + foreach ($yuanshi_data as $key => $value) { + + // 如果文件不存在这个目录下 + // dump($yuanshi_mulu.DS.$value['pic_url']); + if (!file_exists($yuanshi_mulu.DS.$value['pic_url'])) { + $result['none'] = $result['none']+1; + array_push($temporary_arr_none,$value['yuanshi_id']); + continue; + }else{ + $result['ok'] = $result['ok']+1; + array_push($temporary_arr_data,[ + 'user_token' => 'caadd1be045a65f30b92aa805f1de54a', + 'pic_name' => $value['pic_url'], + 'pic_url' => "https://tc.pcxbc.com/kitchenscale_all/cook_img/".$value['pic_url'], + 'create_time' => date('Y-m-d H:i:s'), + 'special_record_str' => $value['yuanshi_id'] + ]); + } + } + // 启动事务 + $cfc->startTrans(); + try { + + if($result['ok'] > 0){ + $cfc->table('app_user_upload_img')->insertAll($temporary_arr_data); + $cfc->table('linshi_caidan_biao')->where("yuanshi_id in ('".implode("','",$temporary_arr_ok)."')")->update(['is_move_ok'=>1]); + } + if($result['none'] > 0){ + $cfc->table('linshi_caidan_biao')->where("yuanshi_id in ('".implode("','",$temporary_arr_none)."')")->update(['is_move_ok'=>2]); + } + + $cfc->commit(); + dump($result); + } catch (\Exception $e) { + $cfc->rollback(); + dump($e); + } + + + // dump($result); + // dump($temporary_arr_ok); + // dump($temporary_arr_no); + // dump($temporary_arr_none); + // dump($temporary_arr_data); + // die; + + + + + + + } + + ################################################################################################################### + ################################################################################################################### + ################################################################################################################### + + + public function msg($code,$str,$data){ + return json(['code'=>$code,'msg'=>$str,'data'=>$data]); + } +} \ No newline at end of file diff --git a/application/test/controller/Text.php b/application/test/controller/Text.php deleted file mode 100644 index 26ea69a..0000000 --- a/application/test/controller/Text.php +++ /dev/null @@ -1,15 +0,0 @@ - + + + + + 洗数据 + + + +
开始
+
当前第1
+
累积成功0
+
累积失败0
+ + + + + \ No newline at end of file diff --git a/application/testapp/controller/Card.php b/application/testapp/controller/Card.php index 5a37650..5d47b66 100644 --- a/application/testapp/controller/Card.php +++ b/application/testapp/controller/Card.php @@ -319,8 +319,8 @@ class Card extends Base{ } - // 修改初始体重/目标体重 - public function card_modify_weight($data = ['aud_id'=>'11','weight'=>'50','type'=>2,'time'=>'2024-10-01','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ + // 修改初始体重/目标体重{"aud_id":"3967","time":"","weight":"124","type":1,"aan_id":"3475"} + public function card_modify_weight($data = ['aud_id'=>'3967','weight'=>'124','type'=>1,'time'=>'','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ try { // 你的业务逻辑 if(count(input('post.')) > 0){ @@ -1279,6 +1279,7 @@ class Card extends Base{ where acbd.aud_id = ".$data['aud_id']." order by acbd.record_time desc "); + if($data['type'] == 1){ // 修改目标体重 $bhw_date = ['target_weight'=>$data['weight']]; @@ -1289,13 +1290,13 @@ class Card extends Base{ return $this->msg(10005); } $result_update = Db::table($this->card_use_db_name['2'])->where(['id'=>$data['aud_id']])->update($bhw_date); - + // $result_update = true; if($result_update){ $target_current = $this->base_target_initial_cumulative_weight([ - 'weight'=>$result[0]['weight'], - 'target_weight'=>$data['type'] == 1?$data['weight']:$result[0]['target_weight'], - 'initial_weight'=>$data['type'] == 1?$result[0]['initial_weight']:$data['weight'], - 'initial_date'=>$data['type'] == 1?$result[0]['initial_date']:$data['time'], + 'weight'=>count($result) <= 0?0:$result[0]['weight'], + 'target_weight'=>$data['type'] == 1?$data['weight']:(count($result) <= 0?0:$result[0]['target_weight']), + 'initial_weight'=>$data['type'] == 1?(count($result) <= 0?0:$result[0]['initial_weight']):$data['weight'], + 'initial_date'=>$data['type'] == 1?(count($result) <= 0?'':$result[0]['initial_date']):$data['time'], ]); return $this->msg($target_current); diff --git a/public/children_meals_cookbook/12岁以上青少年长高食谱/12岁以上青少年长高食谱.html b/public/children_meals_cookbook/12岁以上青少年长高食谱/12岁以上青少年长高食谱.html new file mode 100644 index 0000000..1561f81 --- /dev/null +++ b/public/children_meals_cookbook/12岁以上青少年长高食谱/12岁以上青少年长高食谱.html @@ -0,0 +1,65 @@ + + + + + + Document + + + + +
+
+
+ +
+
+ + \ No newline at end of file diff --git a/public/children_meals_cookbook/index.html b/public/children_meals_cookbook/index.html new file mode 100644 index 0000000..a6e23a0 --- /dev/null +++ b/public/children_meals_cookbook/index.html @@ -0,0 +1,211 @@ + + + + + + 目录 + + + +
+
+
0~6岁宝宝辅食
+
+
+
01-宝宝辅食(文档)
+
+
1岁3个月宝宝辅食.doc
+
+
+
+
01-宝宝辅食(文档)
+
+
1岁3个月宝宝辅食.doc
+
+
+
+
+
+
0~6岁宝宝辅食
+
+
+
01-宝宝辅食(文档)
+
+
1岁3个月宝宝辅食.doc
+
+
+
+
+
+
0~6岁宝宝辅食
+
+
+
01-宝宝辅食(文档)
+
+
1岁3个月宝宝辅食.doc
+
+
+
+
+
+
0~6岁宝宝辅食
+
+
+
01-宝宝辅食(文档)
+
+
1岁3个月宝宝辅食.doc
+
+
+
+
+
12岁以上青少年长高食谱
+
+ + + + + \ No newline at end of file