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
767b7eb661
  1. 11
      app/Controller/v3/OrderOnlineController.php
  2. 10
      app/Controller/v3/ShopCartUpdateController.php
  3. 4
      app/Controller/v3/UserAddressController.php
  4. 2
      app/Service/v3/Implementations/ActivityService.php
  5. 24
      app/Service/v3/Implementations/DistributionPriceService.php
  6. 36
      app/Service/v3/Implementations/ShopCartUpdateService.php
  7. 41
      app/Service/v3/Implementations/UserAddressService.php
  8. 2
      app/Service/v3/Interfaces/DistributionPriceServiceInterface.php
  9. 2
      app/Service/v3/Interfaces/ShopCartUpdateServiceInterface.php
  10. 2
      app/Service/v3/Interfaces/UserAddressServiceInterface.php
  11. 2
      config/routes.php

11
app/Controller/v3/OrderOnlineController.php

@ -93,27 +93,26 @@ class OrderOnlineController extends BaseController
]) ])
->select('id') ->select('id')
->first(); ->first();
$res['location'] = $this->userAddressService->getAddressAndDistributionRrice($address->id,$marketId);
$res['location'] = $this->userAddressService->getAddressAndDistributionPrice($address->id,$marketId);
//返回预约送达时间 数组 //返回预约送达时间 数组
$res['appointment_time'] = $this->appointmentTimeService->do(); $res['appointment_time'] = $this->appointmentTimeService->do();
// //
$res['store_list'] = $this->shopCartService->getGoodsByShopcartId($shopcartIds); $res['store_list'] = $this->shopCartService->getGoodsByShopcartId($shopcartIds);
//获取用户优惠券 //获取用户优惠券
$res['coupon'] = $this->couponRecService->allForOnlineOrderAvailable($userId, $marketId); $res['coupon'] = $this->couponRecService->allForOnlineOrderAvailable($userId, $marketId);
//获取配送费
$res['distribution_price'] = '5.0';
//增值服务接口 //增值服务接口
$res['value_added_service'] = [ $res['value_added_service'] = [
'text' => '买鸡买鸭,免费帮杀;买瓜买黇,包熟包甜',
'select' => 1, 'select' => 1,
'price' => 3.50 'price' => 3.50
]; ];
$total = 0; $total = 0;
foreach ($res['store_list'] as $store) foreach ($res['store_list'] as $store)
{ {
$total+= $store['subtotal'];
$total = bcadd($total,$store['subtotal'],2);
} }
$total+= $res['value_added_service']['price'];
$total+= $res['distribution_price'];
$total = bcadd($total,$res['value_added_service']['price'],2);
$total = bcadd($total,$res['location']['distribution_price'],2);
$res['total'] = $total; $res['total'] = $total;
return $this->success($res); return $this->success($res);
} }

10
app/Controller/v3/ShopCartUpdateController.php

@ -15,11 +15,11 @@ class ShopCartUpdateController extends BaseController
protected $shopCarServiceUpdate; protected $shopCarServiceUpdate;
public function update(ShopCartUpdateRequest $request) public function update(ShopCartUpdateRequest $request)
{ {
$user_id = $this->request->input('user_id',0);
$goods_id = $this->request->input('goods_id',0);
$num = $this->request->input('num','');
$activity_type = $this->request->input('activity_type',1);
$res = $this->shopCarServiceUpdate->do($user_id,$goods_id,$num,$activity_type);
$userId = $this->request->input('user_id',0);
$goodsId = $this->request->input('goods_id',0);
$num = $this->request->input('num',0);
$activityType = $this->request->input('activity_type',1);
$res = $this->shopCarServiceUpdate->do($userId,$goodsId,$num,$activityType);
return $this->success($res); return $this->success($res);
} }

4
app/Controller/v3/UserAddressController.php

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

2
app/Service/v3/Implementations/ActivityService.php

@ -31,7 +31,7 @@ class ActivityService implements ActivityServiceInterface
->where(['type' => $type]); ->where(['type' => $type]);
if ($marketId != -1) { if ($marketId != -1) {
$builder = $builder->whereJsonContains('market_ids', [(string)$marketId]);
$builder = $builder->where('market_id', $marketId);
} }
return $builder->get()->toArray(); return $builder->get()->toArray();

24
app/Service/v3/Implementations/DistributionPriceService.php

@ -8,9 +8,29 @@ use App\Service\v3\Interfaces\DistributionPriceServiceInterface;
class DistributionPriceService implements DistributionPriceServiceInterface class DistributionPriceService implements DistributionPriceServiceInterface
{ {
public function do()
public function do($distance)
{ {
return '配送费';
$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) :
$distributionRrice = bcmul(1.50,($km-3),2);
// throw new ErrorCodeException(ErrorCode::LOCATION_LONG_DISTANCE);
break;
default:
$distributionRrice = 0;
break;
}
$distributionRrice = bcadd($distributionRrice,3.50,2);
return $distributionRrice;
} }
public function check() public function check()

36
app/Service/v3/Implementations/ShopCartUpdateService.php

@ -4,33 +4,57 @@ namespace App\Service\v3\Implementations;
use App\Constants\v3\ErrorCode; use App\Constants\v3\ErrorCode;
use App\Exception\ErrorCodeException; use App\Exception\ErrorCodeException;
use App\Service\v3\Interfaces\GoodsActivityServiceInterface;
use App\Service\v3\Interfaces\GoodsServiceInterface;
use App\Service\v3\Interfaces\ShopCartUpdateServiceInterface; use App\Service\v3\Interfaces\ShopCartUpdateServiceInterface;
use App\Model\v3\ShoppingCart; use App\Model\v3\ShoppingCart;
use App\Model\v3\Goods; use App\Model\v3\Goods;
use App\Model\v3\GoodsActivity; use App\Model\v3\GoodsActivity;
use App\Constants\v3\Goods as GoodsConstants; use App\Constants\v3\Goods as GoodsConstants;
use Hyperf\Di\Annotation\Inject;
class ShopCartUpdateService implements ShopCartUpdateServiceInterface class ShopCartUpdateService implements ShopCartUpdateServiceInterface
{ {
public function do($user_id,$goods_id,$num,$activity_type)
/**
* @Inject
* @var GoodsServiceInterface
*/
protected $goodsService;
/**
* @Inject
* @var GoodsActivityServiceInterface
*/
protected $goodsActivityService;
public function do($userId,$goodsId,$num,$activityType)
{ {
$goodsType = ''; $goodsType = '';
//判断是普通商品还是特价商品 //判断是普通商品还是特价商品
if($activity_type == GoodsConstants::IS_ACTIVITY){
if($activityType == GoodsConstants::IS_ACTIVITY){
$builder = GoodsActivity::query(); $builder = GoodsActivity::query();
$goodsType = GoodsActivity::class; $goodsType = GoodsActivity::class;
$goodsModel = $builder->find($goodsId);
$goodsCheck = $this->goodsActivityService->check($goodsModel,$num,$userId);
}else{ }else{
$builder = Goods::query(); $builder = Goods::query();
$goodsType = Goods::class; $goodsType = Goods::class;
$goodsModel = $builder->find($goodsId);
$goodsCheck = $this->goodsService->check($goodsModel,$num);
} }
$goods = $builder->select('market_id','store_id')->find($goods_id);
if(empty($goods)){ if(empty($goods)){
throw new ErrorCodeException(ErrorCode::GOODS_NOT_EXISTS); throw new ErrorCodeException(ErrorCode::GOODS_NOT_EXISTS);
} }
if($goodsCheck !== true)
{
throw new ErrorCodeException($goodsCheck);
}
return ShoppingCart::query()->updateOrCreate( return ShoppingCart::query()->updateOrCreate(
[ [
'user_id' => $user_id,
'goods_id' => $goods_id,
'activity_type' => $activity_type
'user_id' => $userId,
'goods_id' => $goodsId,
'activity_type' => $activityType
], ],
[ [
'market_id' => $goods->market_id, 'market_id' => $goods->market_id,

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

@ -6,6 +6,7 @@ use App\Constants\v3\ErrorCode;
use App\Exception\ErrorCodeException; use App\Exception\ErrorCodeException;
use App\Model\v3\Market; use App\Model\v3\Market;
use App\Model\v3\UserAddress; use App\Model\v3\UserAddress;
use App\Service\v3\Interfaces\DistributionPriceServiceInterface;
use App\Service\v3\Interfaces\LocationServiceInterface; use App\Service\v3\Interfaces\LocationServiceInterface;
use App\Service\v3\Interfaces\UserAddressServiceInterface; use App\Service\v3\Interfaces\UserAddressServiceInterface;
use Hyperf\Di\Annotation\Inject; use Hyperf\Di\Annotation\Inject;
@ -18,6 +19,12 @@ class UserAddressService implements UserAddressServiceInterface
*/ */
protected $locationService; protected $locationService;
/**
* @Inject
* @var DistributionPriceServiceInterface
*/
protected $distributionPriceService;
public function do($userAddressId,$user_id,$user_name,$address,$doorplate,$gender,$lat,$lng,$tel,$tags) public function do($userAddressId,$user_id,$user_name,$address,$doorplate,$gender,$lat,$lng,$tel,$tags)
{ {
$userAddress = UserAddress::updateOrCreate(['id' => $userAddressId], $userAddress = UserAddress::updateOrCreate(['id' => $userAddressId],
@ -71,42 +78,16 @@ class UserAddressService implements UserAddressServiceInterface
* @param $marketId * @param $marketId
* @return false|float * @return false|float
*/ */
public function getAddressAndDistributionRrice($userAddressId,$marketId)
public function getAddressAndDistributionPrice($userAddressId,$marketId)
{ {
$address = $this->get($userAddressId); $address = $this->get($userAddressId);
$market = Market::query()->select('lng','lat')->find($marketId); $market = Market::query()->select('lng','lat')->find($marketId);
$distance = $this->locationService->getDistanceByTencent($address->lng,$address->lat,$market->lng,$market->lat); $distance = $this->locationService->getDistanceByTencent($address->lng,$address->lat,$market->lng,$market->lat);
$distributionRrice = $this->calculateDistributionRrice($distance);
$distributionPrice = $this->distributionPriceService->do($distance);
$res['address'] = $address; $res['address'] = $address;
$res['distribution_price'] = $distributionRrice;
$res['distribution_price'] = $distributionPrice;
return $res; 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/DistributionPriceServiceInterface.php

@ -4,7 +4,7 @@ namespace App\Service\v3\Interfaces;
interface DistributionPriceServiceInterface interface DistributionPriceServiceInterface
{ {
public function do();
public function do($distance);
public function check(); public function check();

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

@ -4,7 +4,7 @@ namespace App\Service\v3\Interfaces;
interface ShopCartUpdateServiceInterface interface ShopCartUpdateServiceInterface
{ {
public function do($user_id,$goods_id,$num,$activity_type);
public function do($userId,$goodsId,$num,$activityType);
public function check(); public function check();

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

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

2
config/routes.php

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

Loading…
Cancel
Save