Example #1
0
 public function getallProviders($category = null, $name_provider = null, $page)
 {
     $dataProviders = PrProviders::join('pr_types', 'pr_providers.pr_type_id', '=', 'pr_types.id')->leftJoin('pr_pictures', 'pr_pictures.pr_provider_id', '=', 'pr_providers.id')->join('pu_categories as puc', 'pr_providers.pr_type_id', '=', 'puc.id')->select('pr_providers.*', DB::raw('CONCAT("' . asset('') . '", picture_face) AS picture_face'), DB::raw('CONCAT("' . asset('') . '", puc.picture) AS picture_category'), 'pr_types.name_type', 'puc.name_category');
     if ($category != null) {
         $dataProviders = $dataProviders->where('pr_providers.pu_category_id', '=', $category);
     }
     if ($name_provider != null) {
         $dataProviders = $dataProviders->where('pr_providers.name_provider', 'like', '%' . $name_provider . '%');
     }
     $dataProviders = $dataProviders->where('pr_providers.flagactive', '=', 1)->groupby('pr_providers.id')->where('name_type', '!=', PrProviders::Type_Inactivo)->skip($this->perpage * ($page - 1))->orderBy('pr_providers.pr_type_id', 'desc')->orderBy('pr_providers.ranking', 'desc')->orderBy('pr_providers.lastupdate', 'desc')->take($this->perpage)->get();
     $data = $dataProviders == null ? [] : $dataProviders->toArray();
     $newdata = [];
     if ($data) {
         foreach ($data as $row) {
             //                $score =PrScore::wherePrProviderId($row['id'])->select(DB::raw('count(id) as score'))->get();
             $value = $row['name_type'] == PrProviders::Type_Premium ? 'get' : 'first';
             $dataPictureProvider = PrPictures::wherePrProviderId($row['id'])->select('flagactive', 'datecreate', DB::raw('CONCAT("' . asset('') . '", url) AS picture'))->{$value}();
             $total_users = PrComments::wherePrProviderId($row['id'])->whereFlagactive(1)->select(DB::raw('count(id) as total_users'))->get()->first();
             $row["total_users"] = $total_users->total_users;
             $row["friends"] = [['idfacebook' => '10156644988105647'], ['idfacebook' => '620320758106445'], ['idfacebook' => '10153512513095805'], ['idfacebook' => '10156576400725089']];
             if ($dataPictureProvider == null) {
                 $row['picture_provider'] = [];
             } else {
                 $row['picture_provider'] = $value == 'get' ? $dataPictureProvider->toArray() : [$dataPictureProvider->toArray()];
             }
             $newdata[] = $row;
         }
     } else {
         $newdata = [];
     }
     return $newdata;
 }
Example #2
0
 public function postImageProviderPremium(Request $request)
 {
     $result = array('state' => 0, 'msg' => '');
     try {
         $dataImageProvider = $request->all();
         $prPictureTotal = PrPictures::wherePrProviderId($dataImageProvider['pr_provider_id'])->select(DB::raw('COUNT(id) as total'))->first();
         if ($prPictureTotal->total >= 4) {
             $result['msg'] = 'Ya no puede subir más imagenes';
             return response()->json($result);
         }
         if (!$dataImageProvider['pr_provider_id']) {
             throw new \Exception("Id de proveedor vacio");
         }
         if (isset($dataImageProvider['picture_provider'])) {
             $file = base64_decode(preg_replace('#^data:image/\\w+;base64,#i', '', $dataImageProvider['picture_provider']));
             $dataPicture['name_picture'] = date('YmdHis') . rand(1, 1000) . ".jpg";
             $pathrelative = "/dinamic/providers-data/" . $dataPicture['name_picture'];
             $path = App::publicPath() . $pathrelative;
             file_put_contents($path, $file);
             $dataPicture['url'] = $pathrelative;
             $dataPicture['pr_provider_id'] = $dataImageProvider['pr_provider_id'];
             $objImageProvider = PrPictures::create($dataPicture);
         }
         $result['data'] = ['id' => $objImageProvider->id];
         $result['state'] = 1;
     } catch (\Exception $exc) {
         $result['msg'] = $exc->getMessage();
     }
     return response()->json($result);
 }