示例#1
0
 public function getUpdateType($id)
 {
     $result = array('state' => 0, 'msg' => '');
     try {
         if (!$id) {
             throw new \Exception("Id de Post vacio");
         }
         $modelAds = new PuAds();
         $modelTypeAds = new PuTypes();
         $dataAds = $modelAds->getAdsType($id, null);
         switch ($dataAds->name_type) {
             case PuTypes::TYPE_PREMIUM:
                 $type = $this->dataPremium($id);
                 break;
             default:
                 $dataPremium = PuAds::wherePuTypeId($modelTypeAds->getIdPuType(PuTypes::TYPE_PREMIUM))->whereFlagactive(1)->first();
                 if ($dataPremium) {
                     $typePremium = $this->dataPremium($dataPremium->id);
                     $adsPremium = PuAds::find($dataPremium->id);
                     $adsPremium->update(['pu_type_id' => $typePremium]);
                 }
                 $type = $modelTypeAds->getIdPuType(PuTypes::TYPE_PREMIUM);
                 break;
         }
         $ads = PuAds::find($id);
         $ads->update(['pu_type_id' => $type]);
         $result['state'] = 1;
     } catch (\Exception $e) {
         $result['msg'] = $e->getMessage();
     }
     return response()->json($result);
 }
示例#2
0
 /**
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     try {
         $request['id'] = $id;
         $v = Validator::make($request, ['id' => 'required|exists:pu_ads,id,datedelete,NULL,flagactive,1']);
         if ($v->fails()) {
             $error = (array) json_decode($v->errors());
             $datError = ['element' => 'id', 'msg' => $error['id'][0]];
             $this->_responseWS->setDataResponse(0, [], [$datError], 'publicacion inválida');
         } else {
             $dataAds = PuAds::whereId($id)->whereUserId($this->_identity->id)->whereFlagactive(1)->first();
             if (isset($dataAds->id)) {
                 $objAds = PuAds::find($id);
                 $objAds->delete();
                 $msg = 'ok';
             } else {
                 $objComplaints = PuComplaints::whereUserId($this->_identity->id)->wherePuAdId($id)->first();
                 if ($objComplaints == null) {
                     PuComplaints::create(['pu_ad_id' => $id, 'user_id' => $this->_identity->id]);
                     $msg = 'ok';
                 } else {
                     $msg = 'Usted ya ha denunciado la publicación';
                 }
             }
             $this->_responseWS->setDataResponse(Response::HTTP_OK, [], [], $msg);
         }
     } catch (Exception $exc) {
         $this->_responseWS->setDataResponse(Response::HTTP_INTERNAL_SERVER_ERROR, [], [], '');
     }
     $this->_responseWS->response();
 }