/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { if ($id) { $coupon = AdminCoupon::find($id); if ($coupon) { $user = AdminUser::where(['coupon_id' => $coupon->id])->first(); if ($user) { $user->coupon_id = 0; $user->save(); } $coupon->delete(); } } return redirect()->back(); }
public function couponUsed() { $data = []; $data['msg'] = '亲~服务器繁忙,现金卷使用失败~请稍后再试。'; $data['code'] = 404; $skuId = Input::get('product_id', 0); $couponId = Input::get('coupon_id', 0); if ($skuId and $couponId) { $sku = PhoneSku::find($skuId); $coupon = AdminCoupon::find($couponId); if ($sku and $coupon) { $couponPrice = floatval($coupon->coupon_price); $skuPrice = floatval($sku->price); $data['code'] = 200; $data['msg'] = "亲~恭喜您,商品总价已经为您减免¥{$couponPrice}元"; $data['ret'] = []; $data['ret']['couponPrice'] = $couponPrice; if ($skuPrice > $couponPrice) { $data['ret']['skuPrice'] = $skuPrice - $couponPrice; } else { $data['ret']['skuPrice'] = 0; } } } $this->response($data); }