本文整理汇总了PHP中Coupon::where方法的典型用法代码示例。如果您正苦于以下问题:PHP Coupon::where方法的具体用法?PHP Coupon::where怎么用?PHP Coupon::where使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Coupon
的用法示例。
在下文中一共展示了Coupon::where方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: postSaveorder
public function postSaveorder()
{
setcookie('orderdetails', json_encode($_POST), time() + 60 * 60 * 24 * 30, '/');
$final_total = "";
$code = $_POST['coupon'];
$response = array('success' => 'true');
if ($code != "") {
$coupon_det = Coupon::where('code', '=', $code)->first()->toArray();
if (strtotime($coupon_det['expiry']) > time() && $coupon_det['status'] == 'activated') {
if ($coupon_det['type'] == 'discount') {
$final_total = intval($_POST['subtotal']) - intval($_POST['subtotal']) * intval($coupon_det['discount']) / 100;
} else {
$final_total = $_POST['subtotal'] - $coupon_det['discount'];
}
if ($coupon_det['batchuniqid'] != "") {
Coupon::where('code', '=', $code)->update(array('status' => 'deactivated'));
}
$response = array('success' => 'true', 'message' => 'Coupon code added.', 'final_total' => $final_total);
} else {
$response = array('success' => 'false', 'message' => 'Coupon code expired.');
}
}
return json_encode($response);
}
示例2: applyCoupon
/**
* Get the new price after applying a group of coupon.
* @author Anyun
* @param int $sale_id
* @param array $promo_codes
* @return object [newPrice,promoCode]
*/
public static function applyCoupon($sale_id, $promo_codes = [])
{
$app = \Slim\Slim::getInstance();
$sale = Price::find($sale_id);
if (!$sale) {
$app->halt(400, 'Invalid Sale Item');
}
$result = array("price" => $sale->price, "coupon" => "");
if (!$sale) {
// this sale not exist
$app->halt('400', $sale_id);
}
//Important Rule:
//Only ONE code will be applied to one item
//If multiply codes effect, chose the lowest one
$prices = Coupon::where('course_sale_id', '=', $sale_id)->whereIn('code', $promo_codes)->valid()->get();
foreach ($prices as $key => $value) {
if ($value->new_price < $result['price']) {
$result['old_price'] = $sale->price;
$result['price'] = $value->new_price;
$result['coupon'] = $value->code;
}
}
return (object) $result;
}
示例3: delete_coupon
public function delete_coupon()
{
$id = Request::segment(4);
$coupon = Coupon::find($id);
Coupon::where('id', $id)->delete();
$message = "Successfully deleted the coupon";
$type = "success";
return Redirect::to('/admin/coupons')->with('type', $type)->with('message', $message);
}
示例4: update_credit
public function update_credit()
{
$user_id = $this->user_id;
$coupon_code = Input::get('coupon_code');
$coupon = Coupon::where('coupon_code', $coupon_code)->first();
if ($coupon) {
$coupon_user = UserCoupon::where('coupon_id', $coupon->id)->where('user_id', $this->user_id)->first();
if (!$coupon_user) {
$amount = $coupon->amount;
$user_credit = UserCredit::where('user_id', $user_id)->first();
$user_credit->earned += $amount;
$user_credit->save();
$coupon_user = new UserCoupon();
$coupon_user->coupon_id = $coupon->id;
$coupon_user->user_id = $this->user_id;
$coupon_user->save();
if (Request::format() == 'html') {
// Redirect to credits page
return Redirect::to('/user');
} else {
$response_array['success'] = 'true';
$response_array['credits'] = $user_credit->toArray();
$response_code = 200;
$response = Response::json($response_array, $response_code);
return $response;
}
} else {
$message = "Coupon code already used";
$error_code = 408;
}
} else {
$message = "Invalid coupon code";
$error_code = 409;
}
if (Request::format() == 'html') {
return Redirect::to('/user')->with('message', $message)->with('type', 'danger');
} else {
$response_array = array('success' => 'false', 'error_code' => '405', 'error' => $message);
$response_code = 200;
$response = Response::json($response_array, $response_code);
return $response;
}
}
示例5: getDownload
public function getDownload()
{
$batchid = $_GET['batchid'];
$all_coupons = Coupon::where('batchuniqid', 'like', '%' . $batchid . '%')->get()->toArray();
// echo "<pre>";print_r($all_coupons);
Excel::create('Coupons-' . date("Y-m-d", time()), function ($excel) use($all_coupons) {
$excel->sheet('Sheetname', function ($sheet) use($all_coupons) {
$sheet->fromArray($all_coupons);
});
})->export('xls')->download('xls');
return Redirect::to('coupons.viewall')->with('coupons', Coupon::orderBy('created_at', 'DESC')->groupBy('batchuniqid')->paginate(10, $fields));
}