作者 xwp
1 个管道 的构建 通过 耗费 1 秒

最新逻辑

... ... @@ -3,7 +3,9 @@
namespace app\api\controller;
use app\common\controller\Api;
use fast\Tree;
use think\Config;
use think\Db;
use WeMini\Template;
/**
... ... @@ -30,10 +32,38 @@ class Course extends Api
$category = new \app\common\model\Category();
$category = $category->where([])->select();
$tree = Tree::instance();
$tree->init($category, 'pid');
$category = $tree->getTreeArray(0);
$this->success('请求成功',$category);
}
/**
* 获得区域
*
* @ApiTitle (获得区域)
* @ApiSummary (获得区域)
* @ApiMethod (POST)
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturnParams (name="data", type="object", sample="{'prepay_id':'123','options':{},'order':{}}", description="扩展数据返回")
* @ApiReturn ({'code':'1','msg':'返回成功'})
*/
public function get_area()
{
$parentId = $this->request->request('parentId');
$area = DB::table('fa_area')->where([])->field(['id','parentId','areaName'])->select();
$tree = Tree::instance();
$tree->init($area, 'parentId');
$area = $tree->getTreeArray($parentId);
$this->success('请求成功',$area);
}
/**
* 获得课程等级
*
* @ApiTitle (获得课程等级)
... ...
... ... @@ -20,7 +20,8 @@ class Store extends Api
* @ApiMethod (POST)
* @ApiParams (name="lng", type="string", required=true, description="lng")
* @ApiParams (name="lat", type="string", required=true, description="lat")
* @ApiParams (name="distance", type="string", required=true, description="距离")
* @ApiParams (name="value", type="string", required=true, description="地区值")
* @ApiParams (name="type", type="string", required=true, description="地区类型")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturnParams (name="data", type="object", sample="{'prepay_id':'123','options':{},'order':{}}", description="扩展数据返回")
... ... @@ -30,17 +31,12 @@ class Store extends Api
{
$lng = $this->request->request('lng');
$lat = $this->request->request('lat');
$distance = $this->request->request('distance');
$value = $this->request->request('value');
$type = $this->request->request('type');
if(empty($distance)){
$distance = 10;
}
$where = [];
if(!empty($lng)&&!empty($lat)){
$four_point = $this->returnSquarePoint($lng,$lat,$distance);
$this->success('请求成功',$four_point);
$where['lng'] = ['between',[$four_point['left-top']['lng'],$four_point['right-top']['lng']]];
$where['lat'] = ['between',[$four_point['left-bottom']['lat'],$four_point['left-top']['lat']]];
if(!empty($value)&&!empty($type)){
$where[$type] = $value;
}
$store = new \app\admin\model\Store();
... ... @@ -53,12 +49,53 @@ class Store extends Api
}
$k['banner'] = $banner;
$k['cover'] = cdnurl($k['cover'],true);
$k['distance'] = $this->GetDistance($lat,$lng,$k['lat'],$k['lng']);
}
if(!empty($store)){
//排序
foreach ($store as $key => $row) {
$distance[$key] = $row['distance'];
}
array_multisort($distance, SORT_ASC, $store);
}
$this->success('请求成功',$store);
}
/**
* 计算两组经纬度坐标 之间的距离
* $lat1 纬度1; lng1 经度1; lat2 纬度2; lng2 经度2; len_type (1:m or 2:km);
*
* @param $lat1
* @param $lng1
* @param $lat2
* @param $lng2
* @param int $len_type
* @param int $decimal
* @return false|float
*/
private function GetDistance($lat1, $lng1, $lat2, $lng2, $len_type = 2, $decimal = 2)
{
$EARTH_RADIUS = 6378.137;//地球半径
$PI = 3.1415926;
$radLat1 = $lat1 * $PI / 180.0;
$radLat2 = $lat2 * $PI / 180.0;
$a = $radLat1 - $radLat2;
$b = ($lng1 * $PI / 180.0) - ($lng2 * $PI / 180.0);
$s = 2 * asin(sqrt(pow(sin($a/2),2) + cos($radLat1) * cos($radLat2) * pow(sin($b/2),2)));
$s = $s * $EARTH_RADIUS;
$s = round($s * 1000);
if ($len_type > 1)
{
$s /= 1000;
}
return round($s, $decimal);
}
/**
* 获得门店
*
* @ApiTitle (获得门店)
... ...
此 diff 太大无法显示。