123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402 |
- <?php
- use Illuminate\Support\Facades\Redis;
- if (!function_exists('res_422')) {
- function res_422($msg='参数有误!'){
- return json_encode(['code' => 422, 'data' => [], 'count' => 0,'msg'=>$msg]);
- }
- }
- if (!function_exists('opt_return')){
- function opt_return($res,$msg=null){
- if (!$res) {
- if (!$msg){
- $msg = '操作失败';
- }
- die(json_encode(array('status' => 2, 'message' => $msg)));
- }
- die(json_encode(array('status' => 1, 'message' => '操作成功')));
- }
- }
- if (!function_exists('opt_ok')){
- function opt_ok(){
- die(json_encode(array('status' => 1, 'message' => '操作成功'),JSON_UNESCAPED_UNICODE));
- }
- }
- if (!function_exists('opt_error')){
- function opt_error($msg=null){
- if (!empty($msg)){
- die(json_encode(array('status' => 2, 'message' => $msg)));
- }
- die(json_encode(array('status' => 2, 'message' => '操作失败')));
- }
- }
- if (!function_exists('table_error')){
- function table_error($msg=null){
- if (!$msg)
- $msg = '数据查询异常,请检查参数!';
- die(json_encode(['code'=>-1,'msg'=>$msg]));
- }
- }
- if (!function_exists('format_time')){
- function format_time(&$param,$format){
- if (isset($param['stime']))
- $param['stime'][1] = date($format,$param['stime'][1]);
- if (isset($param['etime']))
- $param['etime'][1] = date($format,$param['etime'][1]+86400);
- }
- }
- function nextDay($data)
- {
- return date('Y-m-d',strtotime('+1 day', strtotime($data)));
- }
- function nowDate()
- {
- return date('Y-m-d H:i:s');
- }
- if (!function_exists('getTree')){
- function getTree($data, $pId=0)
- {
- $tree = array();
- foreach ($data as $k => $v) {
- if ($v->parentId == $pId) {
- $v->children = getTree($data, $v->id);
- $tree[] = $v;
-
- }
- }
- return $tree;
- }
- }
- if (!function_exists('numToWord')) {
- function numToWord($num)
- {
- $chiNum = array('零', '一', '二', '三', '四', '五', '六', '七', '八', '九');
- $chiUni = array('','十', '百', '千', '万', '亿', '十', '百', '千');
-
- $chiStr = '';
-
- $num_str = (string)$num;
-
- $count = strlen($num_str);
- $last_flag = true;
- $zero_flag = true;
- $temp_num = null;
-
- $chiStr = '';
- if ($count == 2) {
- $temp_num = $num_str[0];
- $chiStr = $temp_num == 1 ? $chiUni[1] : $chiNum[$temp_num].$chiUni[1];
- $temp_num = $num_str[1];
- $chiStr .= $temp_num == 0 ? '' : $chiNum[$temp_num];
- }else if($count > 2){
- $index = 0;
- for ($i=$count-1; $i >= 0 ; $i--) {
- $temp_num = $num_str[$i];
- if ($temp_num == 0) {
- if (!$zero_flag && !$last_flag ) {
- $chiStr = $chiNum[$temp_num]. $chiStr;
- $last_flag = true;
- }
- }else{
- $chiStr = $chiNum[$temp_num].$chiUni[$index%9] .$chiStr;
- $zero_flag = false;
- $last_flag = false;
- }
- $index ++;
- }
- }else{
- $chiStr = $chiNum[$num_str[0]];
- }
- return $chiStr;
- }
- }
- if (!function_exists('createNo')) {
- function createNo($prefix = '')
- {
- return $prefix . date('YmdHis') . sprintf("%03d", rand(1, 99));
- }
- }
- if (!function_exists('llog')) {
- function llog($content, $channel = '', $level = 'info')
- {
- if ($channel == '') {
- \Log::info($content);
- } else {
- switch ($level) {
- case 'info':
- \Log::channel($channel)->info($content);
- break;
- case 'error':
- \Log::channel($channel)->error($content);
- break;
- }
- }
-
- }
- }
-
- if (!function_exists('complete_pic')) {
- function complete_pic($val) {
-
- if ($val != '' && strpos($val, 'http') === false) {
- return env('OSS_URL') . $val;
- }
- return $val;
- }
- }
- function Get_Curl($url, $data = null, array $heders = [], $time=6)
- {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_TIMEOUT, $time);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
- if(!empty($heders)){
- curl_setopt($ch, CURLOPT_HTTPHEADER, $heders);
- }
- if(!empty($data)){
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
- }
- $content = curl_exec($ch);
- curl_close($ch);
- return $content;
- }
- function curl_post_https($url,$data,$headers=null,$cookie=null){
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_URL, $url);
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
- curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
-
-
-
- if(!empty($headers)){
- curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
- }
- if(!empty($cookie)){
- curl_setopt($curl, CURLOPT_COOKIE, $cookie);
- }
- curl_setopt($curl, CURLOPT_POST, 1);
- curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
- curl_setopt($curl, CURLOPT_TIMEOUT, 10);
- curl_setopt($curl, CURLOPT_HEADER, 0);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
- $tmpInfo = curl_exec($curl);
- curl_close($curl);
- return $tmpInfo;
- }
- function curl_get_https($url,$headers=null,$raw=null,$time=6){
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_URL, $url);
- curl_setopt($curl, CURLOPT_TIMEOUT, $time);
- curl_setopt($curl, CURLOPT_HEADER, 0);
- if(!empty($headers)){
- curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
- }
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
- if($raw){
- curl_setopt($curl, CURLOPT_POSTFIELDS, $raw);
- }
- $tmpInfo = curl_exec($curl);
- curl_close($curl);
- return $tmpInfo;
- }
- function post_multi(string $url, array $data = [],$time_out = 5)
- {
- $headerArray = array("Content-Type: multipart/form-data;charset='utf-8'");
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_URL, $url);
- curl_setopt($curl, CURLOPT_CONNECTTIMEOUT , $time_out);
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
- curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
- curl_setopt($curl, CURLOPT_POST, 1);
- curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
- curl_setopt($curl, CURLOPT_HTTPHEADER, $headerArray);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
- $output = curl_exec($curl);
- curl_close($curl);
- return json_decode($output,true);
- }
- function hexToDec($number)
- {
-
- $number = remove0x(strtolower($number));
- $decvalues = [
- '0' => '0', '1' => '1', '2' => '2',
- '3' => '3', '4' => '4', '5' => '5',
- '6' => '6', '7' => '7', '8' => '8',
- '9' => '9', 'a' => '10', 'b' => '11',
- 'c' => '12', 'd' => '13', 'e' => '14',
- 'f' => '15'];
- $decval = '0';
- $number = strrev($number);
- for($i = 0; $i < strlen($number); $i++) {
- $decval = bcadd(bcmul(bcpow('16', $i, 0), $decvalues[$number[$i]]), $decval);
- }
- return $decval;
- }
- function remove0x($value)
- {
- if (strtolower(substr($value, 0, 2)) == '0x') {
- return substr($value, 2);
- }
- return $value;
- }
- function calculationExcept($price,$number){
- $multiple = 1;
- if($number > 0){
- for ($i=0; $i < $number; $i++) {
- $multiple = $multiple.'0';
- }
- $multiple = (int)$multiple;
- }
- $data = bcdiv($price,$multiple,$number);
- if(strpos(floatval($data),'-') == false){
-
- $data = floatval($data);
- }else{
-
- $data = rtrim(rtrim($data, '0'), '.');
- }
- return $data;
- }
- function getRedis($field){
- $prefix = env('REDIS_PREFIX','sdadmin_');
- return Redis::get($prefix.$field);
- }
- function setRedis($field,$data){
- $prefix = env('REDIS_PREFIX','sdadmin_');
- return Redis::set($prefix.$field,$data);
- }
- function setexRedis($field,$expireSeconds = 60,$data){
- $prefix = env('REDIS_PREFIX','sdadmin_');
- return Redis::setex($prefix.$field,$expireSeconds,$data);
- }
- function deleteRedis($data){
- $prefix = env('REDIS_PREFIX','sdadmin_');
- return Redis::del($prefix.$data);
- }
- function getKeyRedis(){
- return Redis::keys("_*");
- }
- function getClientIP()
- {
- $ip_address = '';
- if(getenv('HTTP_CLIENT_IP'))
- $ip_address = getenv('HTTP_CLIENT_IP');
- else if(getenv('HTTP_X_FORWARDED_FOR'))
- $ip_address = getenv('HTTP_X_FORWARDED_FOR');
- else if(getenv('HTTP_X_FORWARDED'))
- $ip_address = getenv('HTTP_X_FORWARDED');
- else if(getenv('HTTP_FORWARDED_FOR'))
- $ip_address = getenv('HTTP_FORWARDED_FOR');
- else if(getenv('HTTP_FORWARDED'))
- $ip_address = getenv('HTTP_FORWARDED');
- else if(getenv('REMOTE_ADDR'))
- $ip_address = getenv('REMOTE_ADDR');
- else
- $ip_address = 'UNKNOWN';
- return $ip_address;
- }
|