/** * scan function. * * @access public * @return void */ public function postScan() { $qr = Input::get('qr', ""); $coupon = Coupon::where("qr", "=", $qr)->first(); if (!$coupon || trim($qr) == "") { return Response::json(array("service" => __FUNCTION__, "status" => true, "error" => true, "message" => "Coupon not found")); } $user_id = Auth::user()->id; $count = Scan::where("user_id", "=", $user_id)->where("created_at", ">", date("Y-m-d", time()))->count(); if ($count > 1) { return Response::json(array("service" => __FUNCTION__, "status" => true, "error" => true, "message" => "Scan error")); } $scan = new Scan(); $scan->user_id = $user_id; $scan->coupon_id = $coupon->id; $scan->value = 5; $scan->save(); $redems = Scan::where("coupon_id", "=", $coupon->id)->count(); //$user->register->scans()->sum("value") $data = array("added" => 5, "total" => 0, "redems" => $redems); return Response::json(array("service" => __FUNCTION__, "status" => true, "data" => $data)); }