123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- <?php
- function pocket($total, $num, $min = 0.01){
- for ($i=1; $i<$num; $i++) {
- $safe_total = ($total-($num-$i)*$min)/($num-$i);
- $money = mt_rand($min*100,$safe_total*100)/100;
- $total = $total-$money;
- $arr['res'][$i] = array(
- 'i' => $i,
- 'money' => $money,
- 'total' => $total
- );
- }
- $arr['res'][$num] = array('i'=>$num,'money'=>$total,'total'=>0);
- return $arr['res'][rand(1,$num)]['money'];
- }
- function weekdays(array $days){
- $weekarray = array("星期日","星期一","星期二","星期三","星期四","星期五","星期六");
- $week = [];
- foreach ($days as $value) {
- $week[] = $weekarray[$value];
- }
- return $week;
- }
- function bdMap_to_txMap($lat,$lng){
- $x_pi = 3.14159265358979324 * 3000.0 / 180.0;
- $x = $lng - 0.0065;
- $y = $lat - 0.006;
- $z = sqrt($x * $x + $y * $y) - 0.00002 * sin($y * $x_pi);
- $theta = atan2($y, $x) - 0.000003 * cos($x * $x_pi);
- $lng = $z * cos($theta);
- $lat = $z * sin($theta);
- return array('lng'=>$lng,'lat'=>$lat);
- }
-
- function txMap_to_bdMap($lat,$lng){
- $x_pi = 3.14159265358979324 * 3000.0 / 180.0;
- $x = $lng;
- $y = $lat;
- $z =sqrt($x * $x + $y * $y) + 0.00002 * sin($y * $x_pi);
- $theta = atan2($y, $x) + 0.000003 * cos($x * $x_pi);
- $lng = $z * cos($theta) + 0.0065;
- $lat = $z * sin($theta) + 0.006;
- return array('lng'=>$lng,'lat'=>$lat);
- }
- function getDistance($lng1,$lat1,$lng2,$lat2){
- $earthRadius = 6367000;
- $lat1 = deg2rad($lat1);
- $lng1 = deg2rad($lng1);
- $lat2 = deg2rad($lat2);
- $lng2 = deg2rad($lng2);
- $calcLongitude = $lng2 - $lng1;
- $calcLatitude = $lat2 - $lat1;
- $stepOne = pow(sin($calcLatitude / 2), 2) + cos($lat1) * cos($lat2) * pow(sin($calcLongitude / 2), 2);
- $stepTwo = 2 * asin(min(1, sqrt($stepOne)));
- $calculatedDistance = $earthRadius * $stepTwo;
- $distance = round($calculatedDistance);
- if($distance <= 500){
- return $distance.'m';
- }else{
- return round($distance/1000,1).'km';
- }
- }
- function dataGroup(array $dataArr,string $keyStr){
- $newArr = [];
- foreach ($dataArr as $val) {
- $newArr[$val[$keyStr]][] = $val;
- }
- return $newArr;
- }
- function rate($num = 0,$num_of = 0){
- $rate = floor($num/$num_of*100);
- if($rate > 100){
- $rate = 100;
- }
- return $rate ?: 0;
- }
|