Browse Source

优惠券

master
Lemon 5 years ago
parent
commit
ae1cd23c83
  1. 8
      app/Model/v3/Coupon.php
  2. 25
      app/Service/v3/Implementations/CouponRecService.php
  3. 5
      app/Service/v3/Implementations/ShopCartService.php

8
app/Model/v3/Coupon.php

@ -13,7 +13,8 @@ class Coupon extends Model
protected $appends = [ protected $appends = [
'full_amount_text', 'full_amount_text',
'discounts_text'
'discounts_text',
'time_text'
]; ];
protected $casts = [ protected $casts = [
@ -35,4 +36,9 @@ class Coupon extends Model
} }
} }
public function getTimeTextAttribute()
{
return date("Y-m-d H:i:s",$this->attributes['usable_start_time']). ' - ' .date("Y-m-d H:i:s",$this->attributes['usable_end_time']);
}
} }

25
app/Service/v3/Implementations/CouponRecService.php

@ -103,7 +103,7 @@ class CouponRecService implements CouponRecServiceInterface
public function getListByUser($userId,$type,$page = 1,$pagesize = 5) public function getListByUser($userId,$type,$page = 1,$pagesize = 5)
{ {
//查询优惠券 //查询优惠券
$builder = CouponRec::query()->join('lanzu_coupon', 'lanzu_coupon.id', '=', 'lanzu_coupon_receive.coupon_id')
$builder = CouponRec::query()->join('lanzu_coupon', 'lanzu_coupon.id', '=', 'lanzu_coupon_receive.coupon_id')->with('coupon')
->where([ ->where([
['lanzu_coupon_receive.user_id' ,'=', $userId], ['lanzu_coupon_receive.user_id' ,'=', $userId],
]); ]);
@ -130,32 +130,11 @@ class CouponRecService implements CouponRecServiceInterface
break; break;
} }
$builder = $builder->select( $builder = $builder->select(
'lanzu_coupon.title',
'lanzu_coupon.discounts',
'lanzu_coupon.full_amount',
'lanzu_coupon.discount_type',
'lanzu_coupon.introduce',
'lanzu_coupon.tags',
'lanzu_coupon.usable_start_time',
'lanzu_coupon.usable_end_time',
'lanzu_coupon_receive.number',
'lanzu_coupon_receive.number_remain'
'lanzu_coupon_receive.*'
) )
->orderBy('lanzu_coupon.weigh','desc'); ->orderBy('lanzu_coupon.weigh','desc');
$paginate = $builder->paginate($pagesize); $paginate = $builder->paginate($pagesize);
$couponList = $paginate->toArray(); $couponList = $paginate->toArray();
foreach ($couponList['data'] as $key => &$coupon) {
//拼接满减文字提示
$coupon['full_amount_text'] = '满' . $coupon['full_amount'] . "可用";
//判断是折扣优惠券还是满减优惠券
if($coupon['discount_type'] == 1){
$coupon['discounts_text'] = '¥'.$coupon['discounts'];
}elseif($coupon['discount_type'] == 2){
$coupon['discounts_text'] = floatval($coupon['discounts'])."";
}
//拼接时间文字提示
$coupon['time_text'] = date("Y-m-d H:i:s",$coupon['usable_start_time']). ' - ' .date("Y-m-d H:i:s",$coupon['usable_end_time']);
}
return ['has_more_pages' => $paginate->hasMorePages(), 'list' => $couponList['data']]; return ['has_more_pages' => $paginate->hasMorePages(), 'list' => $couponList['data']];
} }

5
app/Service/v3/Implementations/ShopCartService.php

@ -174,7 +174,7 @@ class ShopCartService implements ShopCartServiceInterface
} }
if (empty($cart->goods)) { if (empty($cart->goods)) {
throw new ErrorCodeException(ErrorCode::GOODS_INVALID);
throw new ErrorCodeException(ErrorCode::GOODS_NOT_EXISTS);
continue; continue;
} }
@ -185,6 +185,7 @@ class ShopCartService implements ShopCartServiceInterface
// 商户是否歇业 // 商户是否歇业
$checkStore = $this->storeService->check($store['id']); $checkStore = $this->storeService->check($store['id']);
if (!$checkStore) { if (!$checkStore) {
throw new ErrorCodeException(ErrorCode::STORE_NOT_AVAILABLE);
continue; continue;
} }
@ -212,7 +213,7 @@ class ShopCartService implements ShopCartServiceInterface
$totalAmount = bcadd($totalAmount, bcmul($cart->goods->price, $cart->num)); $totalAmount = bcadd($totalAmount, bcmul($cart->goods->price, $cart->num));
}else{ }else{
throw new ErrorCodeException(ErrorCode::GOODS_INVALID);
throw new ErrorCodeException($res);
} }
} }

Loading…
Cancel
Save