diff --git a/app/Admin/Common/LinkUrl.php b/app/Admin/Common/LinkUrl.php index f3f1fc7..49064ab 100644 --- a/app/Admin/Common/LinkUrl.php +++ b/app/Admin/Common/LinkUrl.php @@ -11,6 +11,7 @@ class LinkUrl */ const VUE_JS = 'https://cdn.jsdelivr.net/npm/vue'; const ELEMENT_UI_JS = 'https://unpkg.com/element-ui/lib/index.js'; + const API_GL_JS = 'https://map.qq.com/api/gljs?v=1.exp&key=7NSBZ-ETU3O-CW6WN-S3YM5-KERR5-RQBHS'; /** diff --git a/app/Admin/Common/Map.php b/app/Admin/Common/Map.php new file mode 100644 index 0000000..6245015 --- /dev/null +++ b/app/Admin/Common/Map.php @@ -0,0 +1,14 @@ +tools(new ShowOrderStateHandle(8)); $grid->tools(new ShowOrderStateHandle()); $grid->paginate(10);//每页展示数据10条 - //$grid->id; - //$grid->user_id('用户信息'); if (!(Admin::user()->isRole('market_service'))){ $marketId = \Request::get('market_id'); if ($marketId){ @@ -78,7 +77,6 @@ class ImsCjdcOrderMainController extends AdminController return date('Y-m-d H:i:s',$time); }); $grid->actions(function (Grid\Displayers\Actions $actions) use ($grid) { - $state = $actions->row->state; $lastUrl = isset($_SERVER['QUERY_STRING'])?base64_encode($_SERVER['QUERY_STRING']):''; $actions->append(new OrderDetail($actions->row->id, $grid->model()->getCurrentPage(),$lastUrl, '
详情
')); @@ -197,5 +195,24 @@ class ImsCjdcOrderMainController extends AdminController return json_encode($result['result']); } + /** + * 地图路线规划 + * @param $m_lat + * @param $m_lng + * @param $u_lat + * @param $u_lng + * @param $type + * @return false|string + */ + public function mapRoute() + { + $params = request()->input(); + $m_lat = $params['m_lat']; + $m_lng = $params['m_lng']; + $u_lat = $params['u_lat']; + $u_lng = $params['u_lng']; + $type = $params['type']; + return Map::routeInfo($m_lat,$m_lng,$u_lat,$u_lng,$type); + } } diff --git a/app/Admin/Extensions/MyDetailPage.php b/app/Admin/Extensions/MyDetailPage.php index 9bc7989..0a2a312 100644 --- a/app/Admin/Extensions/MyDetailPage.php +++ b/app/Admin/Extensions/MyDetailPage.php @@ -15,7 +15,7 @@ use Endroid\QrCode\Exceptions\DataDoesntExistsException; class MyDetailPage extends LazyRenderable { - protected static $js = [LinkUrl::VUE_JS, LinkUrl::ELEMENT_UI_JS]; + protected static $js = [LinkUrl::VUE_JS, LinkUrl::ELEMENT_UI_JS, LinkUrl::API_GL_JS]; protected static $css = [LinkUrl::DETAIL_CSS, LinkUrl::ELEMENT_UI_CSS]; @@ -24,14 +24,14 @@ class MyDetailPage extends LazyRenderable //>>1.主订单数据 $order = ImsCjdcOrderMain::getOrderData($this->order_id); if ($order) { - $search = array(" "," ","\n","\r","\t"); - $replace = array("","","","",""); + $search = array(" ", " ", "\n", "\r", "\t"); + $replace = array("", "", "", "", ""); $order['address'] = str_replace($search, $replace, $order['address']); //>>2.获取子订单 - $result = ImsCjdcOrder::getOrdersData($order['global_order_id'],$order['id']); + $result = ImsCjdcOrder::getOrdersData($order['global_order_id'], $order['id']); $orders = json_encode($result['orders']); $showRefund = json_encode($result['show_refund']); - $path = "order?".$this->last_url; + $path = "order?" . $this->last_url; Admin::script( << { }); - } + }, + showMap() { + this.is_show=true; + if (!this.show_map){ + this.show_map = true; + this.close_map =false; + this.initMap() + } + }, + closeMap() { + this.is_show=false; + this.show_map = false; + this.close_map =true; + }, + + change2D() { + this.map.setViewMode('2D'); + }, + + change3D() { + this.map.setViewMode('3D'); + this.map.setPitch(70); + }, + + initMap() { + var center = new TMap.LatLng(this.market_lat, this.market_lng); + //初始化地图 + this.map = new TMap.Map("container", {rotation: 20,//设置地图旋转角度 + pitch:30, //设置俯仰角度(0~45) + zoom:12,//设置地图缩放级别 + center: center//设置地图中心点坐标 + }); + that = this; + $.ajax({ + url: "map_route", + type: "get", + contentType: "text/html; charset=utf-8", + dataType: "json", + data: { + m_lat:that.market_lat, + m_lng:that.market_lng, + u_lat:that.user_lat, + u_lng:that.user_lng, + type:"bicycling" + }, + success: function (res) { + if (res.status==0){ + that.cb(res); + } + }, + error: function (xhr, err) { + console.log("错误", err) + } + }); + + }, + + + //定义请求回调函数,在此拿到计算得到的路线,并进行绘制 + cb(ret) { + var coords = ret.result.routes[0].polyline, pl = []; + //坐标解压(返回的点串坐标,通过前向差分进行压缩) + var kr = 1000000; + for (var i = 2; i < coords.length; i++) { + coords[i] = Number(coords[i - 2]) + Number(coords[i]) / kr; + } + //将解压后的坐标放入点串数组pl中 + for (var i = 0; i < coords.length; i += 2) { + pl.push(new TMap.LatLng(coords[i], coords[i+1])); + } + + this.display_polyline(pl)//显示路线 + + //标记起终点marker + var marker = new TMap.MultiMarker({ + id: 'marker-layer', + map: this.map, + styles: { + "start": new TMap.MarkerStyle({ + "width": 25, + "height": 35, + "anchor": { x: 16, y: 32 }, + "src": 'https://mapapi.qq.com/web/lbs/javascriptGL/demo/img/start.png' + }), + "end": new TMap.MarkerStyle({ + "width": 25, + "height": 35, + "anchor": { x: 16, y: 32 }, + "src": 'https://mapapi.qq.com/web/lbs/javascriptGL/demo/img/end.png' + }) + }, + geometries: [{ + "id": 'start', + "styleId": 'start', + "position": new TMap.LatLng(that.market_lat,that.market_lng) + }, { + "id": 'end', + "styleId": 'end', + "position": new TMap.LatLng(that.user_lat,that.user_lng) + }] + }); + }, + + display_polyline(pl){ + //创建 MultiPolyline显示折线 + var polylineLayer = new TMap.MultiPolyline({ + id: 'polyline-layer', //图层唯一标识 + map: this.map,//绘制到目标地图 + //折线样式定义 + styles: { + 'style_blue': new TMap.PolylineStyle({ + 'color': '#3777FF', //线填充色 + 'width': 8, //折线宽度 + 'borderWidth': 5, //边线宽度 + 'borderColor': '#FFF', //边线颜色 + 'lineCap': 'round', //线端头方式 + }) + }, + //折线数据定义 + geometries: [ + { + 'id': 'pl_1',//折线唯一标识,删除时使用 + 'styleId': 'style_blue',//绑定样式名 + 'paths': pl + } + ] + }); + }, + mounted: function () { + } + } }); JS ); diff --git a/app/Admin/routes.php b/app/Admin/routes.php index 416b3fe..1585774 100644 --- a/app/Admin/routes.php +++ b/app/Admin/routes.php @@ -69,6 +69,7 @@ Route::group([ $router->resource('/order', 'ImsCjdcOrderMainController'); $router->any('/detail', 'ImsCjdcOrderMainController@orderDetail'); $router->any('/order_goods_refund', 'ImsCjdcOrderMainController@orderGoodsRefund'); + $router->any('/map_route', 'ImsCjdcOrderMainController@mapRoute'); $router->any('ops/files', 'v3\FileController@handle'); diff --git a/app/Http/Controllers/TestController.php b/app/Http/Controllers/TestController.php index 60f4a44..3ba304b 100644 --- a/app/Http/Controllers/TestController.php +++ b/app/Http/Controllers/TestController.php @@ -42,4 +42,10 @@ class TestController extends BaseController } return $response->getBody()->getContents(); } + + public function testMap() + { + $result = file_get_contents("https://apis.map.qq.com/ws/direction/v1/bicycling/?from=39.984042,116.307535&to=39.980869,116.325238&key=7NSBZ-ETU3O-CW6WN-S3YM5-KERR5-RQBHS"); + return $result; + } } diff --git a/app/Models/ImsCjdcOrderMain.php b/app/Models/ImsCjdcOrderMain.php index eaefec5..a1c33d8 100644 --- a/app/Models/ImsCjdcOrderMain.php +++ b/app/Models/ImsCjdcOrderMain.php @@ -99,8 +99,11 @@ class ImsCjdcOrderMain extends Model // 获取市场 $marketId = $order['market_id']?$order['market_id']:0; - $market = MarketModel::getMarketInfo($marketId,'name'); + $market = MarketModel::getMarketInfo($marketId,['name','lat','lng']); + $order['market_name'] = $market?$market['name']:''; + $order['market_lat'] = $market?$market['lat']:''; + $order['market_lng'] = $market?$market['lng']:''; //获取市场经纬度 //$market = LanzuMarket::where('id',$order['market_id'])->first()->toArray(); @@ -110,6 +113,7 @@ class ImsCjdcOrderMain extends Model } else { $order['delivery_distance'] .= '米'; } + return $order; } diff --git a/public/css/detail.css b/public/css/detail.css index e850d1e..833ad16 100644 --- a/public/css/detail.css +++ b/public/css/detail.css @@ -51,3 +51,20 @@ float: left; font-size: 1.4rem; } + + +#container { + width: 100%; + height: 100%; +} +input { + position: absolute; + top: 30px; + z-index: 9999; +} +#btn-2d { + left: 20px; +} +#btn-3d { + left: 80px; +} diff --git a/resources/views/orderdetail.php b/resources/views/orderdetail.php index 917f026..9eba15c 100644 --- a/resources/views/orderdetail.php +++ b/resources/views/orderdetail.php @@ -1,4 +1,12 @@
+
+ + + + +

+
+
@@ -100,6 +108,6 @@ 确 定 - + diff --git a/routes/web.php b/routes/web.php index 1eba8b1..993b7a6 100644 --- a/routes/web.php +++ b/routes/web.php @@ -19,4 +19,5 @@ Route::get('/', function(){ Route::get('/test', 'TestController@Test'); Route::any('/rpc', 'TestController@testRpc'); +Route::any('/map', 'TestController@testMap'); Route::any('/add', 'Salesman@addData');