Browse Source

Merge branch 'phoenix' of ssh://120.24.33.109:11022/hyzjshwo/lanzu_api_hyperf into phoenix

master
weigang 5 years ago
parent
commit
ec28ea4405
  1. 15
      app/Constants/v3/ErrorCode.php
  2. 23
      app/Controller/v3/OrderOnlineController.php
  3. 9
      app/Controller/v3/UserAddressController.php
  4. 6
      app/Request/EvaluateRequest.php
  5. 14
      app/Service/v3/Implementations/LocationService.php
  6. 60
      app/Service/v3/Implementations/UserAddressService.php
  7. 2
      app/Service/v3/Interfaces/LocationServiceInterface.php
  8. 1
      app/Service/v3/Interfaces/UserAddressServiceInterface.php
  9. 1
      config/routes.php

15
app/Constants/v3/ErrorCode.php

@ -267,4 +267,19 @@ class ErrorCode extends AbstractConstants
* @Message("可提现余额不足")
*/
const STORE_WITHDRAW_INSUFFICIENT_BALANCE = 1252;
/************************************/
/* 定位相关 1301-1350 */
/************************************/
/**
* 定位失败
* @Message("定位失败:")
*/
const LOCATION_ERROR = 1301;
/**
* 定位失败
* @Message("超出配送范围")
*/
const LOCATION_LONG_DISTANCE= 1302;
}

23
app/Controller/v3/OrderOnlineController.php

@ -15,6 +15,7 @@ use App\Service\v3\Implementations\PaymentService;
use App\Service\v3\Interfaces\CouponRecServiceInterface;
use App\Service\v3\Interfaces\SeparateAccountsServiceInterface;
use App\Service\v3\Interfaces\ShopCartServiceInterface;
use App\Service\v3\Interfaces\UserAddressServiceInterface;
use Hyperf\DbConnection\Db;
use Hyperf\Di\Annotation\Inject;
use App\Service\v3\Interfaces\OrderOnlineServiceInterface;
@ -59,6 +60,12 @@ class OrderOnlineController extends BaseController
*/
protected $separateAccountsService;
/**
* @Inject
* @var UserAddressServiceInterface
*/
protected $userAddressService;
/*
* 如果没有绑手机号去绑定页面
* 收货地址接口
@ -74,12 +81,18 @@ class OrderOnlineController extends BaseController
$marketId = $this->request->input('market_id');
$shopcartIds = $this->request->input('shopcart_ids');
//判断用户有没有绑定手机
// $telExists = $this->userBindTelService->check($params['user_id']);
// if(!$telExists){
// throw new ErrorCodeException(ErrorCode::NOT_BIND_TEL_ERROR);
// }
$telExists = $this->userBindTelService->check($userId);
if(!$telExists){
throw new ErrorCodeException(ErrorCode::NOT_BIND_TEL_ERROR);
}
//获取用户收货地址
$res['address'] = UserAddress::query()->find(15);
$address = UserAddress::query()->where([
['user_id','=',$userId],
['is_default','=',1],
])
->select('id')
->first();
$res['location'] = $this->userAddressService->getAddressAndDistributionRrice($address->id,$marketId);
//返回预约送达时间 数组
$res['appointment_time'] = $this->appointmentTimeService->do();
//

9
app/Controller/v3/UserAddressController.php

@ -59,4 +59,13 @@ class UserAddressController extends BaseController
$res = $this->userAddressService->setDefault($userId,$userAddressId);
return $this->success($res);
}
public function getAddressAndDistributionRrice()
{
$userAddressId = $this->request->input('user_address_id');
$marketId = $this->request->input('market_id');
$res = $this->userAddressService->getAddressAndDistributionRrice($userAddressId,$marketId);
return $this->success(['location' => $res]);
}
}

6
app/Request/EvaluateRequest.php

@ -22,9 +22,9 @@ class EvaluateRequest extends FormRequest
public function rules(): array
{
return [
'c_attitude' => 'required|nonempty|integer',
'c_service' => 'required|nonempty|integer',
'c_quality' => 'required|nonempty|integer',
'c_attitude' => 'required|nonempty',
'c_service' => 'required|nonempty',
'c_quality' => 'required|nonempty',
'content' => 'required|nonempty|strlen:15,150',
'user_id' => 'required|nonempty|integer|exists:ims_cjdc_user,id',
'service_personnel_id' => 'required|nonempty|integer|exists_enable:lanzu_service_personnel,id,status=1|not_equal:user_id,lanzu_service_personnel,id,user_id',

14
app/Service/v3/Implementations/LocationService.php

@ -48,7 +48,7 @@ class LocationService implements LocationServiceInterface
return $res;
}
function getDistance($lng1, $lat1, $lng2, $lat2, $unit = 2, $decimal = 2)
public function getDistance($lng1, $lat1, $lng2, $lat2, $unit = 2, $decimal = 2)
{
$EARTH_RADIUS = 6370.996; // 地球半径系数
@ -78,4 +78,16 @@ class LocationService implements LocationServiceInterface
{
return Market::where('status',1)->get();
}
//获取骑行距离
public function getDistanceByTencent($lng1, $lat1, $lng2, $lat2)
{
$url = 'https://apis.map.qq.com/ws/direction/v1/';
/**
* $tyep driving 驾车 walking 步行 bicycling 骑行 transit 公交
*/
$type = 'bicycling';
$key = 'GB3BZ-7W2CU-LW3VH-B7ZIF-XRKSF-D3FOL';
return file_get_contents($url.$type.'/?from='.$lat1.','.$lng1.'&to='.$lat2.','.$lng2.'&output=json&key='.$key);
}
}

60
app/Service/v3/Implementations/UserAddressService.php

@ -2,11 +2,21 @@
namespace App\Service\v3\Implementations;
use App\Constants\v3\ErrorCode;
use App\Exception\ErrorCodeException;
use App\Model\v3\Market;
use App\Model\v3\UserAddress;
use App\Service\v3\Interfaces\LocationServiceInterface;
use App\Service\v3\Interfaces\UserAddressServiceInterface;
use Hyperf\Di\Annotation\Inject;
class UserAddressService implements UserAddressServiceInterface
{
/**
* @Inject
* @var LocationServiceInterface
*/
protected $locationService;
public function do($userAddressId,$user_id,$user_name,$address,$doorplate,$gender,$lat,$lng,$tel,$tags)
{
@ -55,4 +65,54 @@ class UserAddressService implements UserAddressServiceInterface
{
return UserAddress::query()->where('user_id',$userId)->get();
}
/**
* @param $userAddressId
* @param $marketId
* @return false|float
*/
public function getAddressAndDistributionRrice($userAddressId,$marketId)
{
$address = $this->get($userAddressId);
$market = Market::query()->select('lng','lat')->find($marketId);
$result = $this->locationService->getDistanceByTencent($address->lng,$address->lat,$market->lng,$market->lat);
$resultArr = json_decode($result,true);
if($resultArr['status'] > 0)
{
throw new ErrorCodeException(ErrorCode::LOCATION_ERROR,$resultArr['message']);
}
$distance = $resultArr['result']['routes'][0]['distance'];
$distributionRrice = $this->calculateDistributionRrice($distance);
$res['address'] = $address;
$res['distribution_price'] = $distributionRrice;
return $res;
}
/**
* @param $distance
* @return false|float
*/
function calculateDistributionRrice($distance)
{
$km = ceil($distance/1000);
switch ($km){
case ($km > 3 && $km < 5) :
$distributionRrice = bcmul(0.70,($km-3),2);
break;
case ($km >= 5 && $km < 7) :
$distributionRrice = bcmul(1.00,($km-3),2);
break;
case ($km >= 7 && $km < 10) :
$distributionRrice = bcmul(1.50,($km-3),2);
break;
case ($km >= 10) :
throw new ErrorCodeException(ErrorCode::LOCATION_LONG_DISTANCE);
break;
default:
$distributionRrice = 0;
break;
}
$distributionRrice = bcadd($distributionRrice,3.50,2);
return $distributionRrice;
}
}

2
app/Service/v3/Interfaces/LocationServiceInterface.php

@ -12,4 +12,6 @@ interface LocationServiceInterface
public function getMarketListByLocation($cityIds);
public function searchMarket($key,$cityId = 2163);
public function getMarketsInfo();
public function getDistance($lng1, $lat1, $lng2, $lat2, $unit = 2, $decimal = 2);
public function getDistanceByTencent($lng1, $lat1, $lng2, $lat2);
}

1
app/Service/v3/Interfaces/UserAddressServiceInterface.php

@ -12,4 +12,5 @@ interface UserAddressServiceInterface
public function get($userAddressId);
public function getList($userId);
public function setDefault($userId,$userAddressId);
public function getAddressAndDistributionRrice($userAddressId,$marketId);
}

1
config/routes.php

@ -138,6 +138,7 @@ Router::addGroup('/v3/', function () {
Router::post('user/oflOrders', 'App\Controller\v3\OrderListController@offlineForUser');
Router::post('shopCart/delete', 'App\Controller\v3\ShopCartUpdateController@delete');
Router::post('withdraw/pageByStore', 'App\Controller\v3\WithdrawController@pageByStore');
Router::post('userAddress/getAddressAndDistributionRrice', 'App\Controller\v3\UserAddressController@getAddressAndDistributionRrice');
Router::post('withdraw/applyByStore', 'App\Controller\v3\WithdrawController@applyByStore');
},['middleware' => [\App\Middleware\Auth\ApiMiddleware::class, \App\Middleware\Auth\UserMiddleware::class]]);

Loading…
Cancel
Save