diff --git a/app/Model/v3/Coupon.php b/app/Model/v3/Coupon.php index f3df3bf..2af1594 100644 --- a/app/Model/v3/Coupon.php +++ b/app/Model/v3/Coupon.php @@ -13,7 +13,8 @@ class Coupon extends Model protected $appends = [ 'full_amount_text', - 'discounts_text' + 'discounts_text', + 'time_text' ]; 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']); + } + } diff --git a/app/Service/v3/Implementations/CouponRecService.php b/app/Service/v3/Implementations/CouponRecService.php index fe48062..7fe58e6 100644 --- a/app/Service/v3/Implementations/CouponRecService.php +++ b/app/Service/v3/Implementations/CouponRecService.php @@ -103,7 +103,7 @@ class CouponRecService implements CouponRecServiceInterface 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([ ['lanzu_coupon_receive.user_id' ,'=', $userId], ]); @@ -130,32 +130,11 @@ class CouponRecService implements CouponRecServiceInterface break; } $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'); $paginate = $builder->paginate($pagesize); $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']]; } diff --git a/app/Service/v3/Implementations/ShopCartService.php b/app/Service/v3/Implementations/ShopCartService.php index be65d33..6a02069 100644 --- a/app/Service/v3/Implementations/ShopCartService.php +++ b/app/Service/v3/Implementations/ShopCartService.php @@ -174,7 +174,7 @@ class ShopCartService implements ShopCartServiceInterface } if (empty($cart->goods)) { - throw new ErrorCodeException(ErrorCode::GOODS_INVALID); + throw new ErrorCodeException(ErrorCode::GOODS_NOT_EXISTS); continue; } @@ -185,6 +185,7 @@ class ShopCartService implements ShopCartServiceInterface // 商户是否歇业 $checkStore = $this->storeService->check($store['id']); if (!$checkStore) { + throw new ErrorCodeException(ErrorCode::STORE_NOT_AVAILABLE); continue; } @@ -212,7 +213,7 @@ class ShopCartService implements ShopCartServiceInterface $totalAmount = bcadd($totalAmount, bcmul($cart->goods->price, $cart->num)); }else{ - throw new ErrorCodeException(ErrorCode::GOODS_INVALID); + throw new ErrorCodeException($res); } }