123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304 |
- <?php
- namespace app\common\library;
- use app\common\model\Config;
- use app\common\model\OrderStatus;
- use app\common\model\User;
- use think\Hook;
- use think\Request;
- use app\common\library\QRcode;
- class Common
- {
-
- public static function curlRequest($url, $headers = [], $body = [], $method = "GET")
- {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_HTTP_VERSION, 'CURL_HTTP_VERSION_1_1');
- $output = curl_exec($ch);
- curl_close($ch);
- $arr = json_decode($output, true);
- return $arr;
- }
-
- public static function return_success($msg,$data = null){
- $result = [
- 'code' => 1,
- 'msg' => $msg,
- 'data' =>$data
- ];
- return $result;
- die;
- }
-
- public static function return_error($msg,$data = null){
- $result = [
- 'code' => 0,
- 'msg' => $msg,
- 'data' => $data
- ];
- return $result;
- die;
- }
- public static function get_ffid($invite_code){
- $f = \app\common\model\User::where('id',$invite_code)->field('fid')->find();
- if ($f)
- return $f->fid;
- else
- return 0;
- }
-
- public static function generate_qrcode($value){
- $dir = dirname(realpath(dirname($_SERVER['SCRIPT_FILENAME']))) . '/public/verify';
- if(!file_exists($dir)){
-
- mkdir($dir, 0700,true);
- }
- $filename = $dir.'/'.$value.'.png';
- QRcode::png($value,$filename);
- return 'http://'.$_SERVER['SERVER_NAME']."/verify/".$value.'.png';
- }
-
- public static function setqrcode($value,$name){
- $dir = dirname(realpath(dirname($_SERVER['SCRIPT_FILENAME']))) . '/public/user';
- if(!file_exists($dir)){
-
- mkdir($dir, 0700,true);
- }
- $filename = $dir.'/'.$name.'.png';
- QRcode::png($value,$filename,QR_ECLEVEL_L,7);
- return 'http://'.$_SERVER['SERVER_NAME']."/user/".$name.'.png';
- }
- public static function setintivecode($user_id,$type){
- $g = $type==1 ? 'invite' : 'mer';
- $name = $g.$user_id."_".time();
- $address = 'http://'.$_SERVER['SERVER_NAME'].'/build/#/'.$type.'/'.$user_id;
- $url = self::setqrcode($address,$name);
- return $url;
- }
-
- public static function order_status($oid, $change_message)
- {
- OrderStatus::create(['oid' => $oid,'change_message' => $change_message, 'change_time' => time()]);
- }
-
- public static function checkMoneyGrade($money){
- if ($money<50000){
- return false;
- }elseif ($money>=50000 && $money<150000){
- return 50000;
- }elseif ($money>=150000 && $money<450000){
- return 150000;
- }elseif ($money>=450000 && $money<1350000){
- return 450000;
- }elseif ($money>=1350000 && $money<4000000){
- return 1350000;
- }elseif ($money>=4000000 && $money<12000000){
- return 4000000;
- }elseif ($money>=12000000 && $money<36000000){
- return 12000000;
- }elseif ($money>=36000000 && $money<100000000){
- return 36000000;
- }elseif ($money>=100000000 && $money<300000000){
- return 100000000;
- }elseif ($money>=300000000 && $money<600000000){
- return 300000000;
- }elseif ($money>=600000000){
- return 600000000;
- }
- }
-
- public static function getNewOrderId($user_id)
- {
- $str = date('Ymd').$user_id.substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
- return $str;
- }
-
- public static function setCard($card){
- $city = [11=>"北京",12=>"天津",13=>"河北",14=>"山西",15=>"内蒙古",21=>"辽宁",22=>"吉林",23=>"黑龙江 ",31=>"上海",32=>"江苏",33=>"浙江",34=>"安徽",35=>"福建",36=>"江西",37=>"山东",41=>"河南",42=>"湖北 ",43=>"湖南",44=>"广东",45=>"广西",46=>"海南",50=>"重庆",51=>"四川",52=>"贵州",53=>"云南",54=>"西藏 ",61=>"陕西",62=>"甘肃",63=>"青海",64=>"宁夏",65=>"新疆",71=>"台湾",81=>"香港",82=>"澳门",91=>"国外 "];
- $tip = "";
- $match = "/^\d{6}(18|19|20)?\d{2}(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/";
- $pass= true;
- if(!$card || !preg_match($match,$card)){
-
- $pass = false;
- }else if(!$city[substr($card,0,2)]){
-
- $pass = false;
- }else{
-
- if(strlen($card) == 18){
- $card = str_split($card);
-
-
- $factor = [ 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 ];
-
- $parity = [ 1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2 ];
- $sum = 0;
- $ai = 0;
- $wi = 0;
- for ($i = 0; $i < 17; $i++)
- {
- $ai = $card[$i];
- $wi = $factor[$i];
- $sum += $ai * $wi;
- }
- $last = $parity[$sum % 11];
- if($parity[$sum % 11] != $card[17]){
- $pass =false;
- }
- }else{
- $pass =false;
- }
- }
- if(!$pass) return false;
- return true;
- }
-
- public static function gaoDegetAreaToIp(){
- $ip = request()->ip();
- $content = file_get_contents("http://restapi.amap.com/v3/ip?key=7b60be14348558ca73ea081b3e871c6e&ip={$ip}");
- $json = json_decode($content,true);
- return $json;
- }
-
- public static function get_ipjwd(){
- $ip = request()->ip();
-
- $api_key = Config::get_values('baidu_api_server');
- if ($ip=='127.0.0.1') {
- $ip='58.30.228.35';
- }
- $content = file_get_contents("http://api.map.baidu.com/location/ip?ak=$api_key&ip={$ip}&coor=bd09ll");
- $json = json_decode($content);
- $data=array();
- $data['log']=$json->{'content'}->{'point'}->{'x'};
- $data['lat']=$json->{'content'}->{'point'}->{'y'};
- $data['address']=$json->{'content'}->{'address'};
- return $data;
- }
-
- public static function getDistance($lat2,$lng2,$lat='',$log='')
- {
- $user = app()->session->get('us');
- $userinfo = User::get($user['id']);
- if ($lat && $log) {
- $lng1 = $log;
- $lat1 = $lat;
- }elseif ($userinfo && $userinfo['now_lat'] && $userinfo['now_log']){
- $lng1 = $userinfo['now_log'];
- $lat1 = $userinfo['now_lat'];
- }else{
- return "0";
- }
-
- $radLat1 = deg2rad($lat1);
- $radLat2 = deg2rad($lat2);
- $radLng1 = deg2rad($lng1);
- $radLng2 = deg2rad($lng2);
- $a = $radLat1 - $radLat2;
- $b = $radLng1 - $radLng2;
- $s = 2*asin(sqrt(pow(sin($a/2),2)+cos($radLat1)*cos($radLat2)*pow(sin($b/2),2)))*6371;
- return round($s,1);
- }
- }
|