Browse Source

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

master
liangyuyan 5 years ago
parent
commit
64b69f7573
  1. 60
      app/Controller/CouponController.php
  2. 60
      app/Service/CouponService.php
  3. 2
      app/Service/CouponServiceInterface.php
  4. 15
      app/Service/ShopCarService.php

60
app/Controller/CouponController.php

@ -199,65 +199,9 @@ class CouponController extends BaseController
$type = $this->request->input('type', 1); $type = $this->request->input('type', 1);
# 店铺类型id # 店铺类型id
$storetypeId = $this->request->input('storetype_id', 0); $storetypeId = $this->request->input('storetype_id', 0);
$storetypeIds = explode(',', str_replace(',', ',', $storetypeId));
$available = [];
$notAvailable = [];
if ($this->empty($orderAmount) || $this->empty($userId)) {
return $this->success([
'available' => $available,
'not_available' => array_values($notAvailable)
]);
}
// 获取用户优惠券
$currentTime = time();
$data = Db::table('ims_system_coupon_user_receive as receive')
->select([
'receive.id as receive_id',
'receive.user_id',
'receive.number_remain',
'coupon.id',
'coupon.title',
'coupon.full_amount',
'coupon.discounts',
'coupon.usable_start_time',
'coupon.usable_end_time',
'coupon.discount_type'
])
->join('ims_system_coupon_user as coupon', 'coupon.id', '=', 'receive.system_coupon_user_id')
->where(['receive.user_id' => $userId])
->whereIn('receive.status', [0,1])
->where('receive.number_remain', '>', 0)
->whereIn('coupon.type', [1,$type])
->where('coupon.full_amount', '<=', $orderAmount)
->where('coupon.usable_start_time', '<=', $currentTime)
->where('coupon.usable_end_time', '>=', $currentTime)
->where('coupon.usable_number', '<=', Db::raw('receive.number_remain'))
->where('coupon.market_id', 'in', [0, $marketId])
->whereIn('coupon.storetype_id', $storetypeIds)
->orderByRaw('coupon.discounts DESC, coupon.full_amount DESC')
->get();
// 分离用户今天用过的优惠券种类
$container = ApplicationContext::getContainer();
$redis = $container->get(Redis::class);
$couponIds = $redis->sMembers('coupon_'.date('Ymd').'_used_'.$userId);
foreach ($data as $key => &$item) {
if (in_array($item->id, $couponIds)) {
$notAvailable[$item->id] = $item;
} else {
$available[] = $item;
}
}
return $this->success([
'available' => $available,
'not_available' => array_values($notAvailable)
]);
$res = $this->couponService->getUserAvailableCoupons($orderAmount,$userId,$marketId,$type,$storetypeId);
return $this->success($res);
} }

60
app/Service/CouponService.php

@ -154,9 +154,67 @@ class CouponService implements CouponServiceInterface
* 获取用户当前订单可用的优惠券列表 * 获取用户当前订单可用的优惠券列表
* 按分类(1订单 等优惠)分组返回 * 按分类(1订单 等优惠)分组返回
*/ */
public function getUserAvailableCoupons()
public function getUserAvailableCoupons($orderAmount,$userId,$marketId,$type,$storetypeId)
{ {
$storetypeIds = explode(',', str_replace(',', ',', $storetypeId));
$available = [];
$notAvailable = [];
if ($this->empty($orderAmount) || $this->empty($userId)) {
return $this->success([
'available' => $available,
'not_available' => array_values($notAvailable)
]);
}
// 获取用户优惠券
$currentTime = time();
$data = Db::table('ims_system_coupon_user_receive as receive')
->select([
'receive.id as receive_id',
'receive.user_id',
'receive.number_remain',
'coupon.id',
'coupon.title',
'coupon.full_amount',
'coupon.discounts',
'coupon.usable_start_time',
'coupon.usable_end_time',
'coupon.discount_type'
])
->join('ims_system_coupon_user as coupon', 'coupon.id', '=', 'receive.system_coupon_user_id')
->where(['receive.user_id' => $userId])
->whereIn('receive.status', [0,1])
->where('receive.number_remain', '>', 0)
->whereIn('coupon.type', [1,$type])
->where('coupon.full_amount', '<=', $orderAmount)
->where('coupon.usable_start_time', '<=', $currentTime)
->where('coupon.usable_end_time', '>=', $currentTime)
->where('coupon.usable_number', '<=', Db::raw('receive.number_remain'))
->where('coupon.market_id', 'in', [0, $marketId])
->whereIn('coupon.storetype_id', $storetypeIds)
->orderByRaw('coupon.discounts DESC, coupon.full_amount DESC')
->get();
// 分离用户今天用过的优惠券种类
$container = ApplicationContext::getContainer();
$redis = $container->get(Redis::class);
$couponIds = $redis->sMembers('coupon_'.date('Ymd').'_used_'.$userId);
foreach ($data as $key => &$item) {
if (in_array($item->id, $couponIds)) {
$notAvailable[$item->id] = $item;
} else {
$available[] = $item;
}
}
return [
'available' => $available,
'not_available' => array_values($notAvailable)
];
} }
/** /**

2
app/Service/CouponServiceInterface.php

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

15
app/Service/ShopCarService.php

@ -27,6 +27,21 @@ class ShopCarService implements ShopCarServiceInterface
]; ];
return $error; return $error;
} }
//一个订单只能添加一个特价商品
if($params['money'] == 0.01){
$goods_exists = ShopCar::where([
['money','=',0.01],
['user_id','=',$params['user_id']],
['good_id','=',$params['good_id']]
])
->exists();
if($goods_exists){
$error = [
'error' => '一个订单只能添加一个特价商品'
];
return $error;
}
}
//获取主表商品表信息 //获取主表商品表信息
$goods = Goods::where([ $goods = Goods::where([
['id','=',$params['good_id']], ['id','=',$params['good_id']],

Loading…
Cancel
Save