This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function millitime() { | |
| return round(microtime(true) * 1000); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function genTree($items, $idkey='_id'){ | |
| $tree = array(); | |
| foreach($items as $item){ | |
| if(isset($items[$item['pid']])){ | |
| $items[$item['pid']]['son'][] = &$items[$item[$idkey]]; | |
| }else{ | |
| $tree[] = &$items[$item[$idkey]]; | |
| } | |
| } | |
| return $tree; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function head_value($key) { | |
| $headers = []; | |
| if (!function_exists('getallheaders')) { | |
| foreach ($_SERVER as $name => $value) { | |
| /* RFC2616 (HTTP/1.1) defines header fields as case-insensitive entities. */ | |
| if (strtolower(substr($name, 0, 5)) == 'http_') { | |
| $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value; | |
| } | |
| } | |
| } else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // run below in mongo client shell | |
| db.teacher.createIndex( { "loc": "2d" } ) | |
| // php query | |
| public function test($dis=1) { | |
| $r = D('Teacher')->command([ | |
| 'geoNear'=>'teacher', | |
| 'near'=>[116.32723, 39.977331], | |
| 'maxDistance' => $dis/111, | |
| 'distanceMultiplier' => 111, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function getDistance($lat1, $lng1, $lat2, $lng2) { | |
| $earthRadius = 6367000; //approximate radius of earth in meters | |
| $lat1 = ($lat1 * pi()) / 180; | |
| $lng1 = ($lng1 * pi()) / 180; | |
| $lat2 = ($lat2 * pi()) / 180; | |
| $lng2 = ($lng2 * pi()) / 180; | |
| $calcLongitude = $lng2 - $lng1; | |
| $calcLatitude = $lat2 - $lat1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public function group() | |
| { | |
| $r = D('Charge')->getCollection()->aggregate([ | |
| ['$match'=>['cat'=>'55d17590f7c6d19c1e000039']], | |
| ['$group' => ['_id' => '$cat', 'money' => ['$sum' => '$price'], 'oc' => ['$sum' => 1]]], | |
| ['$sort' => ['money' => -1]] | |
| ]); | |
| json_out($r); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| String.prototype.format = function() | |
| { | |
| var args = arguments; | |
| return this.replace(/\{(\d+)\}/g, | |
| function(m,i){ | |
| return args[i]; | |
| }); | |
| } | |
| // sample |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $(function() { | |
| new AjaxUpload("up_btn", { | |
| action: "/home/api/upload", | |
| autoSubmit: true, | |
| name: "bin", | |
| data: {}, | |
| responseType: 'json', | |
| onChange: function (file, extension) { | |
| }, | |
| onSubmit: function (file, extension) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| worker_processes 1; | |
| events { | |
| multi_accept on; | |
| worker_connections 1024; | |
| } | |
| http { | |
| client_max_body_size 30m; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public function test() | |
| { | |
| $u = D('User')->getCollection()->find(['$or'=>[['mobile'=>'13888888888'], ['name'=>'test1']]]); | |
| foreach ($u as $v) { | |
| json_out($v); | |
| } | |
| $u = D('User')->getCollection()->distinct('name'); | |
| json_out($u); | |
| } |