|
@@ -316,31 +316,52 @@ class CouponDetailController extends Curd
|
|
|
public function promotionCoupon(Request $request)
|
|
|
{
|
|
|
$goods = $request->get('goods', []);
|
|
|
- $money = $request->get('money', []);
|
|
|
$goodsIds = array_column($goods, 'goods_id');
|
|
|
- $couponIds = CouponGoods::whereIn('join_coupon_goods_id', $goodsIds)->pluck('join_goods_coupon_id')->toArray();
|
|
|
+ $goods = array_column($goods, null, 'goods_id');
|
|
|
|
|
|
$coupons = Coupon::where('coupon_category', 'PROMOTION')
|
|
|
->where('coupon_status', 'ACTIVED')
|
|
|
- ->whereIn('coupon_id', $couponIds)
|
|
|
- ->where(function ($query) use ($money) {
|
|
|
- $query->where('coupon_minimum_limit', 0)
|
|
|
- ->orWhere('coupon_minimum_limit', '<=', $money);
|
|
|
- })->select('coupon.coupon_id', 'coupon.coupon_name', 'coupon.coupon_minimum_limit', 'coupon.coupon_classify', 'coupon.coupon_value', 'coupon.coupon_category')
|
|
|
+ ->select('coupon_id')
|
|
|
->get()
|
|
|
->toArray();
|
|
|
$data = [];
|
|
|
- foreach ($coupons as $coupon){
|
|
|
- $classify = CouponService::couponClassifyInfo($coupon['coupon_classify'], $coupon['coupon_category'], $coupon['coupon_value'], $coupon['coupon_minimum_limit']);
|
|
|
+ foreach ($coupons as $coupon) {
|
|
|
+ $couponGoods = CouponGoods::whereIn('join_coupon_goods_id', $goodsIds)
|
|
|
+ ->where('join_goods_coupon_id', $coupon['coupon_id'])
|
|
|
+ ->select('join_goods_coupon_id', 'join_coupon_goods_id')
|
|
|
+ ->get()
|
|
|
+ ->toArray();
|
|
|
+ $money = 0;
|
|
|
+ $moneyGoodsIds = [];
|
|
|
+ foreach ($couponGoods as $couponGood) {
|
|
|
+ if (isset($goods[$couponGood['join_coupon_goods_id']]) && !in_array($couponGood['join_coupon_goods_id'], $moneyGoodsIds)) {
|
|
|
+ $good = $goods[$couponGood['join_coupon_goods_id']];
|
|
|
+ $money = $money + ($good['price'] * $good['nbr']);
|
|
|
+ $moneyGoodsIds[] = $couponGood['join_coupon_goods_id'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $promotionCoupon = Coupon::where('coupon_id', $coupon['coupon_id'])
|
|
|
+ ->where(function ($query) use ($money) {
|
|
|
+ $query->where('coupon_minimum_limit', 0)
|
|
|
+ ->orWhere('coupon_minimum_limit', '<=', $money);
|
|
|
+ })->select('coupon_id', 'coupon_name', 'coupon_minimum_limit', 'coupon_classify', 'coupon_value', 'coupon_category')
|
|
|
+ ->first();
|
|
|
+ if (empty($promotionCoupon)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $promotionCoupon = $promotionCoupon->toArray();
|
|
|
+ $classify = CouponService::couponClassifyInfo($promotionCoupon['coupon_classify'], $promotionCoupon['coupon_category'], $promotionCoupon['coupon_value'], $promotionCoupon['coupon_minimum_limit']);
|
|
|
$data[] = [
|
|
|
- 'coupon_id' => $coupon['coupon_id'],
|
|
|
- 'coupon_name' => $coupon['coupon_name'],
|
|
|
+ 'coupon_id' => $promotionCoupon['coupon_id'],
|
|
|
+ 'coupon_name' => $promotionCoupon['coupon_name'],
|
|
|
'classify' => $classify,
|
|
|
'count' => 1,
|
|
|
- 'coupon_classify' => $coupon['coupon_classify'],
|
|
|
- 'coupon_value' => $coupon['coupon_value'] ?? '',
|
|
|
- 'coupon_minimum_limit' => $coupon['coupon_minimum_limit'] ?? '',
|
|
|
+ 'coupon_classify' => $promotionCoupon['coupon_classify'],
|
|
|
+ 'coupon_value' => $promotionCoupon['coupon_value'] ?? '',
|
|
|
+ 'coupon_minimum_limit' => $promotionCoupon['coupon_minimum_limit'] ?? '',
|
|
|
];
|
|
|
+
|
|
|
}
|
|
|
|
|
|
return json_success('', $data);
|