Browse Source

下单存在特价商品不给用券

master
Lemon 6 years ago
parent
commit
34cc643b66
  1. 6
      app/Controller/CouponController.php
  2. 18
      app/Service/CouponService.php
  3. 2
      app/Service/CouponServiceInterface.php

6
app/Controller/CouponController.php

@ -199,8 +199,10 @@ class CouponController extends BaseController
$type = $this->request->input('type', 1);
# 店铺类型id
$storetypeId = $this->request->input('storetype_id', 0);
$res = $this->couponService->getUserAvailableCoupons($orderAmount,$userId,$marketId,$type,$storetypeId);
# 购物车商品id
$carIds = $this->request->input('car_ids', 0);
$res = $this->couponService->getUserAvailableCoupons($orderAmount,$userId,$marketId,$type,$storetypeId,$carIds);
return $this->success($res);
}

18
app/Service/CouponService.php

@ -3,6 +3,7 @@
namespace App\Service;
use App\Model\OrderMain;
use App\Model\ShopCar;
use Hyperf\Di\Annotation\Inject;
use Hyperf\DbConnection\Db;
use App\Model\CouponUserRecType;
@ -155,12 +156,23 @@ class CouponService implements CouponServiceInterface
* 获取用户当前订单可用的优惠券列表
* 按分类(1订单 等优惠)分组返回
*/
public function getUserAvailableCoupons($orderAmount,$userId,$marketId,$type,$storetypeId)
public function getUserAvailableCoupons($orderAmount,$userId,$marketId,$type,$storetypeId,$carIds)
{
$storetypeIds = explode(',', str_replace(',', ',', $storetypeId));
$available = [];
$notAvailable = [];
//如果存在特价商品 不给用券
$carIdsArr = explode(',',$carIds);
$shopCarExists = ShopCar::whereIn('id',$carIdsArr)
->where('money',0.01)
->exists();
if($shopCarExists){
return [
'available' => $available,
'not_available' => array_values($notAvailable)
];
}
$storetypeIds = explode(',', str_replace(',', ',', $storetypeId));
if (empty($orderAmount) || empty($userId)) {
return [

2
app/Service/CouponServiceInterface.php

@ -13,7 +13,7 @@ interface CouponServiceInterface
public function getUserReceiveCouponList();
public function getUserAvailableCoupons($orderAmount,$userId,$marketId,$type,$storetypeId);
public function getUserAvailableCoupons($orderAmount,$userId,$marketId,$type,$storetypeId,$carIds);
/**
* 当前订单可用优惠券列表

Loading…
Cancel
Save