public function getCompra() { $id = Input::get('id'); $aux = Compras::where('pub_id', '=', $id)->where('user_id', '=', Auth::id())->where(function ($query) { $query->where('valor_vend', '=', 0)->orWhere('fechVal', '=', date('Y-m-d', time() + 172800)); })->first(); if (!empty($aux)) { Session::flash('error', 'Usted ya ha contactado este usuario y aun no se ha valorado'); return Redirect::back(); } $comp = new Compras(); $comp->pub_id = $id; $comp->user_id = Auth::id(); $comp->valor_comp = 0; $comp->valor_vend = 0; $comp->fechVal = date('Y-m-d', time() + 172800); if ($comp->save()) { $pub = Publicaciones::find($id); $user = User::find($pub->user_id); $msg = "Han respondido tu comentario: " . $pub->titulo; $data = array('message' => $msg, 'title' => $msg, 'msgcnt' => null, 'timeToLive' => 3000); /*$gcm = GcmDevices::where('usuario','=',$user->username)->orderBy('id','DESC')->get(array('gcm_regid')); $regId = array(); $i = 0; foreach($gcm as $g) { $regId[$i] = $g['gcm_regid']; $i++; } $doGcm = new Gcm; $response = $doGcm->send_notification($regId,$data);*/ return Redirect::to('usuario/mis-compras'); } }
public function getCompra() { $id = Input::get('id'); $pub_id = Input::get('pub_id'); $aux = Compras::where('pub_id', '=', $pub_id)->where('user_id', '=', $pub_id)->where(function ($query) { $query->where('valor_vend', '=', 0)->orWhere('fechVal', '=', date('Y-m-d', time() + 172800)); })->first(); if (!empty($aux)) { return Response::json(array('type' => 'danger', 'msg' => 'Usted ya ha contactado este usuario y aun no se ha valorado')); } $comp = new Compras(); $comp->pub_id = $pub_id; $comp->user_id = $id; $comp->valor_comp = 0; $comp->valor_vend = 0; $comp->fechVal = date('Y-m-d', time() + 172800); if ($comp->save()) { $pub = Publicaciones::find($pub_id); $user = User::find($pub->user_id); $msg = "Han respondido tu comentario: " . $pub->titulo; $data = array('message' => $msg, 'title' => $msg, 'msgcnt' => null, 'timeToLive' => 3000); return Response::json(array('type' => 'success', 'msg' => 'Se ha generado una compra', 'compra_id' => $comp->id)); } }