$status, 'message' => $message, 'data' => $data]; if ($exceptionData !== false) { trace([$message => $exceptionData], 'error'); } return response()->json($out); } } //统一异常输出格式话的json数据 if (!function_exists('exit_out')) { function exit_out($data = null, $status = 0, $message = 'success', $exceptionData = false) { $out = ['status' => $status, 'message' => $message, 'data' => $data]; if ($exceptionData !== false) { trace([$message => $exceptionData], 'error'); } $json = json_encode($out, JSON_UNESCAPED_UNICODE); throw new ExitOutException($json); } } //日志记录 if (!function_exists('trace')) { function trace($log = '', $level = 'info') { Log::log($level, $log); } } //AES加密 if (!function_exists('aes_encrypt')) { function aes_encrypt($data) { if (is_array($data)) { $data = json_encode($data, JSON_UNESCAPED_UNICODE); } $key = config('config.aes_key'); $iv = config('config.aes_iv'); $cipher_text = openssl_encrypt($data, 'AES-128-CBC', $key, OPENSSL_RAW_DATA, $iv); $cipher_text = base64_encode($cipher_text); return urlencode($cipher_text); } } //AES解密 if (!function_exists('aes_decrypt')) { function aes_decrypt($encryptData) { $encryptData = urldecode($encryptData); $encryptData = base64_decode($encryptData); $key = config('config.aes_key'); $iv = config('config.aes_iv'); $original_plaintext = openssl_decrypt($encryptData, 'AES-128-CBC', $key, OPENSSL_RAW_DATA, $iv); return json_decode($original_plaintext, true); } } //获取distance的sql字段 if (!function_exists('get_distance_field')) { function get_distance_field($latitude, $longitude) { if (empty($latitude) || empty($longitude)) { return '999999999 distance'; } return 'if(longitude=0 and latitude=0,999999999,round(6378.138*2*asin(sqrt(pow(sin( (' . $latitude . '*pi()/180-latitude*pi()/180)/2),2)+cos(' . $latitude . '*pi()/180)*cos(latitude*pi()/180)* pow(sin((' . $longitude . '*pi()/180-longitude*pi()/180)/2),2)))*1000)) distance'; } }