コード例 #1
0
ファイル: Export.php プロジェクト: mazhuravlev/olx-grabber
 private static function getThumbnail(Offer $offer)
 {
     if ($photo = $offer->photos()->first()) {
         return $photo->url;
     } else {
         return '';
     }
 }
コード例 #2
0
ファイル: OfferController.php プロジェクト: serovvitaly/kotik
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     $model = \App\Models\Offer::findOrFail($id);
     $model->update($request->all());
     $model->catalogs()->sync($request->get('catalogs', []));
     return redirect('/admin/offer');
 }
コード例 #3
0
ファイル: OfferController.php プロジェクト: s-savchenko/aist
 /**
  * Finds the Offer model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Offer the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Offer::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
コード例 #4
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $offer = Offer::where(['olx_id' => $this->argument('id')])->first();
     if (!$offer) {
         $this->error('Offer not found: ' . $this->argument('id'));
         return;
     }
     $job = (new ExportOffer($offer))->onQueue('export_offers');
     $this->dispatch($job);
     $this->info('Export job created');
 }
コード例 #5
0
ファイル: OfferSearch.php プロジェクト: s-savchenko/aist
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Offer::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'is_available' => $this->is_available, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by]);
     $query->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'announcement', $this->announcement])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'title', $this->title]);
     return $dataProvider;
 }
コード例 #6
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Offer::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'email' => $this->email, 'catgry' => $this->catgry, 'priority' => $this->priority, 'expires' => $this->expires, 'added' => $this->added]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'phone', $this->phone])->andFilterWhere(['like', 'website', $this->website])->andFilterWhere(['like', 'image', $this->image])->andFilterWhere(['like', 'location', $this->location])->andFilterWhere(['like', 'descript', $this->descript]);
     return $dataProvider;
 }
コード例 #7
0
 function export(Request $request)
 {
     $regions = $request->get('regions');
     $daysCount = $request->get('day_count');
     $date = Carbon::createFromTimestamp(time() - $daysCount * 86400);
     $offers = Offer::query()->where('created_at', '>', $date)->get();
     echo '<ul>';
     /** @var \Illuminate\Bus\Dispatcher $dispatcher */
     $dispatcher = app('Illuminate\\Bus\\Dispatcher');
     foreach ($offers as $offer) {
         /** @var Offer $offer */
         if ($location = $offer->location and in_array($location->region, $regions, true)) {
             $dispatcher->dispatch((new \App\Jobs\ExportOffer($offer))->onQueue('export_offers'));
             echo "<li>created export job for <a href='/offer/'{$offer->id}'>{$offer->id}</a></li>";
         }
     }
     echo '</ul><p>done</p>';
 }
コード例 #8
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $this->enableInfo = $this->option('info');
     $cache = [];
     $bar = $this->enableInfo ? null : ($bar = $this->output->createProgressBar(Offer::count()));
     $offers = Offer::query()->chunk(100, function (Collection $offers) use($bar, &$cache) {
         $this->info("Got {$offers->count()} offers");
         foreach ($offers as $offer) {
             if ($bar) {
                 $bar->advance();
             }
             foreach ($offer->details as $key => $value) {
                 if (array_key_exists($key, $cache)) {
                     if (array_key_exists($value, $cache[$key])) {
                         $this->info("{$key}:{$value} exists in cache");
                         continue;
                     }
                 } else {
                     $cache[$key] = [];
                 }
                 $detailsParameter = DetailsParameter::firstOrCreate(['parameter' => $key]);
                 try {
                     $detailsValue = $detailsParameter->detailsValues()->firstOrCreate(['value' => $value]);
                     if ($detailsValue->wasRecentlyCreated) {
                         array_push($cache[$key], $value);
                         $this->info("Added {$key}:{$value}");
                     }
                 } catch (QueryException $e) {
                     if (23000 !== intval($e->getCode())) {
                         throw $e;
                     } else {
                         $this->info("Skipped {$key}:{$value}");
                     }
                 }
             }
         }
     });
 }
コード例 #9
0
 public function actionFeed($type = 'xml')
 {
     Yii::$app->response->format = \yii\web\Response::FORMAT_RAW;
     $headers = Yii::$app->response->headers;
     switch ($type) {
         case 'xml':
             $offers = Offer::find()->all();
             $headers->add('Content-Type', 'text/xml; charset=utf-8');
             $data = '<rss><channel>';
             $data .= '<title> *** GdeZaVikend Ponude *** </title><items>';
             foreach ($offers as $offer) {
                 $data .= '<item><name>' . $offer->name . '</name>' . '<description><![CDATA[' . $offer->descript . ']]></description>' . '<website><![CDATA[' . $offer->website . ']]></website>' . '<published>' . $offer->added . '</published></item>';
             }
             $data .= '</items></channel>';
             $data .= '</rss>';
             echo $data;
             break;
         case 'json':
             $offers = Offer::find()->select('name, descript, website, email')->asArray()->all();
             $headers->add('Content-Type', 'application/json');
             echo json_encode($offers);
             break;
         default:
             echo "Requested data format is unavailible at the moment...";
             break;
     }
 }
コード例 #10
0
 public function SubAudit($audit)
 {
     $audit_obj = array();
     foreach ($audit as $index) {
         $entity_obj = null;
         switch ($index->entity_type) {
             case 'user':
                 if (in_array('VIEW_USER', $this->permission)) {
                     $entity_obj = User::find($index->entity_id);
                 }
                 break;
             case 'company':
                 if (User::isSuperAdmin()) {
                     $entity_obj = \App\Models\Company::find($index->entity_id);
                 }
                 break;
             case 'inventory':
                 if (User::isSuperAdmin()) {
                     $entity_obj = Inventory::find($index->entity_id);
                 }
                 break;
             case 'client':
                 if (in_array('VIEW_CLIENT', $this->permission)) {
                     $entity_obj = Client::find($index->entity_id);
                 }
                 break;
             case 'advertiser':
                 if (in_array('VIEW_ADVERTISER', $this->permission)) {
                     $entity_obj = Advertiser::with('GetClientID')->find($index->entity_id);
                 }
                 break;
             case 'creative':
                 if (in_array('VIEW_CREATIVE', $this->permission)) {
                     $entity_obj = Creative::with(['getAdvertiser' => function ($q) {
                         $q->with('GetClientID');
                     }])->find($index->entity_id);
                 }
                 break;
             case 'campaign':
                 if (in_array('VIEW_CAMPAIGN', $this->permission)) {
                     $entity_obj = Campaign::with(['getAdvertiser' => function ($q) {
                         $q->with('GetClientID');
                     }])->find($index->entity_id);
                 }
                 break;
             case 'offer':
                 if (in_array('VIEW_OFFER', $this->permission)) {
                     $entity_obj = Offer::with(['getAdvertiser' => function ($q) {
                         $q->with('GetClientID');
                     }])->find($index->entity_id);
                 }
                 break;
             case 'pixel':
                 if (in_array('VIEW_PIXEL', $this->permission)) {
                     $entity_obj = Pixel::with(['getAdvertiser' => function ($q) {
                         $q->with('GetClientID');
                     }])->find($index->entity_id);
                 }
                 break;
             case 'targetgroup':
                 if (in_array('VIEW_TARGETGROUP', $this->permission)) {
                     $entity_obj = Targetgroup::find($index->entity_id);
                 }
                 break;
             case 'targetgroup_geolocation_map':
                 if (in_array('VIEW_TARGETGROUP', $this->permission)) {
                     if ($index->audit_type == 'del') {
                         $entity_obj = Geolocation::find($index->after_value);
                     } else {
                         $entity_obj = Geolocation::find($index->entity_id);
                     }
                 }
                 break;
             case 'targetgroup_creative_map':
                 if (in_array('VIEW_TARGETGROUP', $this->permission)) {
                     if ($index->audit_type == 'del') {
                         $entity_obj = Creative::find($index->after_value);
                     } else {
                         $entity_obj = Creative::find($index->entity_id);
                     }
                 }
                 break;
             case 'targetgroup_segment_map':
                 if (in_array('VIEW_TARGETGROUP', $this->permission)) {
                     if ($index->audit_type == 'del') {
                         $entity_obj = Segment::find($index->after_value);
                     } else {
                         $entity_obj = Segment::find($index->entity_id);
                     }
                 }
                 break;
             case 'targetgroup_geosegment_map':
                 if (in_array('VIEW_TARGETGROUP', $this->permission)) {
                     if ($index->audit_type == 'del') {
                         $entity_obj = GeoSegmentList::find($index->after_value);
                     } else {
                         $entity_obj = GeoSegmentList::find($index->entity_id);
                     }
                 }
                 break;
             case 'targetgroup_bwlist_map':
                 if (in_array('VIEW_TARGETGROUP', $this->permission)) {
                     if ($index->audit_type == 'del') {
                         $entity_obj = BWList::find($index->after_value);
                     } else {
                         $entity_obj = BWList::find($index->entity_id);
                     }
                 }
                 break;
             case 'targetgroup_bidprofile_map':
                 if (in_array('VIEW_TARGETGROUP', $this->permission)) {
                     if ($index->audit_type == 'del') {
                         $entity_obj = Bid_Profile::find($index->after_value);
                     } else {
                         $entity_obj = Bid_Profile::find($index->entity_id);
                     }
                 }
                 break;
             case 'geosegment':
                 if (in_array('VIEW_GEOSEGMENTLIST', $this->permission)) {
                     $entity_obj = GeoSegmentList::with(['getAdvertiser' => function ($q) {
                         $q->with('GetClientID');
                     }])->find($index->entity_id);
                 }
                 break;
             case 'geosegmententrie':
                 if (in_array('VIEW_GEOSEGMENTLIST', $this->permission)) {
                     if ($index->audit_type == 'del') {
                         $entity_obj = GeoSegment::find($index->after_value);
                     } else {
                         $entity_obj = GeoSegment::find($index->entity_id);
                     }
                 }
                 break;
             case 'bwlist':
                 if (in_array('VIEW_BWLIST', $this->permission)) {
                     $entity_obj = BWList::with(['getAdvertiser' => function ($q) {
                         $q->with('GetClientID');
                     }])->find($index->entity_id);
                 }
                 break;
             case 'bwlistentrie':
                 if (in_array('VIEW_BWLIST', $this->permission)) {
                     if ($index->audit_type == 'del') {
                         $entity_obj = BWEntries::find($index->after_value);
                     } else {
                         $entity_obj = BWEntries::find($index->entity_id);
                     }
                 }
                 break;
             case 'bid_profile':
                 if (in_array('VIEW_BIDPROFILE', $this->permission)) {
                     $entity_obj = Bid_Profile::with(['getAdvertiser' => function ($q) {
                         $q->with('GetClientID');
                     }])->find($index->entity_id);
                 }
                 break;
             case 'bid_profile_entry':
                 if (in_array('VIEW_BIDPROFILE', $this->permission)) {
                     if ($index->audit_type == 'del') {
                         $entity_obj = Bid_Profile::where('id', $index->after_value)->first();
                     } else {
                         $entity_obj = Bid_Profile_Entry::with('getParent')->find($index->entity_id);
                     }
                 }
                 break;
             case 'modelTable':
                 if (in_array('VIEW_MODEL', $this->permission)) {
                     if ($index->audit_type == 'del') {
                         $entity_obj = BWList::where('id', $index->after_value)->first();
                     } else {
                         $entity_obj = ModelTable::with(['getAdvertiser' => function ($q) {
                             $q->with('GetClientID');
                         }])->find($index->entity_id);
                     }
                 }
                 break;
             case 'offer_pixel_map':
                 if (in_array('VIEW_OFFER', $this->permission)) {
                     $entity_obj = Pixel::with(['getAdvertiser' => function ($q) {
                         $q->with('GetClientID');
                     }])->find($index->entity_id);
                 }
                 break;
             case 'advertiser_model_map':
                 if (in_array('VIEW_ADVERTISER', $this->permission)) {
                     $entity_obj = ModelTable::with(['getAdvertiser' => function ($q) {
                         $q->with('GetClientID');
                     }])->find($index->entity_id);
                 }
                 break;
             case 'positive_offer_model':
                 if (in_array('VIEW_MODEL', $this->permission)) {
                     $entity_obj = Offer::with(['getAdvertiser' => function ($q) {
                         $q->with('GetClientID');
                     }])->find($index->entity_id);
                 }
                 break;
             case 'negative_offer_model':
                 if (in_array('VIEW_MODEL', $this->permission)) {
                     $entity_obj = Offer::with(['getAdvertiser' => function ($q) {
                         $q->with('GetClientID');
                     }])->find($index->entity_id);
                 }
                 break;
         }
         if (!is_null($entity_obj)) {
             array_push($audit_obj, $index);
             array_push($audit_obj, $entity_obj);
         }
     }
     return $audit_obj;
 }
コード例 #11
0
 function offer($id)
 {
     return view('offer')->with(['offer' => Offer::findOrFail($id), 'locations' => Location::all()]);
 }
コード例 #12
0
 public function ChangeStatus($id)
 {
     if (Auth::check()) {
         if (in_array('ADD_EDIT_OFFER', $this->permission)) {
             if (User::isSuperAdmin()) {
                 $entity = Offer::find($id);
             } else {
                 $usr_company = $this->user_company();
                 $entity = Offer::whereHas('getAdvertiser', function ($q) use($usr_company) {
                     $q->whereHas('GetClientID', function ($p) use($usr_company) {
                         $p->whereIn('user_id', $usr_company);
                     });
                 })->find($id);
                 if (!$entity) {
                     return 'please Select your Client';
                 }
             }
             if ($entity) {
                 $data = array();
                 $audit = new AuditsController();
                 if ($entity->status == 'Active') {
                     array_push($data, 'status');
                     array_push($data, $entity->status);
                     array_push($data, 'Inactive');
                     $entity->status = 'Inactive';
                     $msg = 'disable';
                 } elseif ($entity->status == 'Inactive') {
                     array_push($data, 'status');
                     array_push($data, $entity->status);
                     array_push($data, 'Active');
                     $entity->status = 'Active';
                     $msg = 'actived';
                 }
                 $audit->store('offer', $id, $data, 'edit');
                 $entity->save();
                 return $msg;
             }
         }
         return "You don't have permission";
     }
     return Redirect::to(url('user/login'));
 }
コード例 #13
0
ファイル: Parse.php プロジェクト: mazhuravlev/olx-grabber
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle(ParserLoggerInterface $logger, Client $client)
 {
     $context = ['url' => $this->url->url];
     try {
         $response = $client->get($this->url->url, ['allow_redirects' => false]);
     } catch (ClientException $e) {
         $logger->error('Client error', self::arrayInsert($context, 'exception', $e));
         throw $e;
     }
     if (200 !== ($code = $response->getStatusCode())) {
         switch ($code) {
             case 301:
                 if (preg_match('/from404/', $response->getHeaderLine('Location'))) {
                     $logger->warning('Offer deleted', $context);
                 } else {
                     $grabbedUrl = null;
                     try {
                         $grabbedUrl = GrabbedUrl::create(['url' => $response->getHeaderLine('Location')]);
                     } catch (QueryException $e) {
                         return;
                     }
                     if ($grabbedUrl) {
                         $this->dispatch(new Parse($grabbedUrl));
                         $logger->info('Dispatched new job', self::arrayInsert($context, 'new_url', $response->getHeaderLine('Location')));
                     }
                 }
                 return;
             default:
                 $logger->error('Invalid response code ' . $code, $context);
         }
     }
     $responseHtml = $response->getBody()->getContents();
     $crawler = new Crawler($responseHtml);
     $offer = new Offer();
     $offer->href = $this->url->url;
     $requiredFieldsCommands = ['phones' => function () use($client) {
         return self::getPhones($client, self::getOlxId($this->url->url));
     }, 'cat_path' => function () use($responseHtml) {
         return self::getCatPath($responseHtml);
     }];
     foreach ($requiredFieldsCommands as $field => $command) {
         try {
             $offer->{$field} = $command();
         } catch (\Exception $e) {
             $logger->error('Unable to extract required fields', self::arrayInsert($context, 'required_field', $field));
             throw $e;
         }
     }
     $fieldsCommands = ['price_string' => function () use($crawler) {
         return $crawler->filter('.pricelabel.tcenter')->first()->text();
     }, 'title' => function () use($crawler) {
         return $crawler->filter('.offerheadinner > h1')->text();
     }, 'olx_id' => function () {
         return self::getOlxId($this->url->url);
     }, 'description' => function () use($crawler) {
         return $crawler->filter('#textContent')->text();
     }, 'date_string' => function () use($crawler) {
         return self::getDate($crawler);
     }, 'offer_number' => function () use($crawler) {
         return self::getOfferNumber($crawler);
     }];
     $failedFields = [];
     foreach ($fieldsCommands as $field => $command) {
         try {
             $offer->{$field} = trim($command());
         } catch (\Exception $e) {
             array_push($failedFields, $field);
         }
     }
     $detailsTables = $crawler->filter('table.details table.item');
     $details = [];
     foreach ($detailsTables as $detailsTable) {
         /** @var $detailsTable Crawler */
         try {
             $details[$detailsTable->getElementsByTagName('th')->item(0)->textContent] = preg_replace('/\\t*|\\n*|\\s{2,}/u', '', $detailsTable->getElementsByTagName('td')->item(0)->textContent);
         } catch (\Exception $e) {
             array_push($failedFields, $detailsTable->text());
         }
     }
     if ($details) {
         $offer->details = $details;
     }
     if ($failedFields and $failedFields !== ["price_string"]) {
         // lots of offers don't have assigned price
         $logger->warning('Failed fields', self::arrayInsert($context, 'failed_fields', $failedFields));
     }
     if ($olxTimestamp = self::parseDate($offer->date_string)) {
         $offer->created_at_olx = $olxTimestamp;
     }
     try {
         $offer->save();
     } catch (QueryException $e) {
         if (23000 === intval($e->getCode())) {
             return;
             // duplicate offer, finish job
         }
         $logger->error('', self::arrayInsert($context, 'exception', $e));
         throw $e;
     }
     if ($offer) {
         try {
             $detectPhones = new DetectPhones($offer);
             $detectPhones->handle();
         } catch (\Exception $e) {
             \Log::critical('Failed to detect phones', ['exception' => $e]);
         }
     }
     if ($offer->wasRecentlyCreated) {
         $photos = [];
         try {
             $photos = $crawler->filter('#bigGallery a')->reduce(function (Crawler $node, $i) {
                 return (bool) $node->attr('href');
             })->extract('href');
         } catch (Exception $e) {
             $logger->error('Failed to get photos', self::arrayInsert($context, 'exception', $e));
         }
         if ($photos) {
             foreach ($photos as $photo) {
                 $offer->photos()->create(['url' => $photo]);
             }
         }
         if ($locationString = self::getLocationString($crawler)) {
             if ($location = Location::where('location', $locationString)->first()) {
                 $offer->location()->associate($location);
                 $offer->save();
             } else {
                 try {
                     $location = Location::create(['location' => $locationString]);
                 } catch (QueryException $e) {
                     $logger->error('Unable to create Location', self::arrayInsert($context, 'location', $locationString));
                 }
                 if ($location instanceof Location) {
                     $offer->location()->associate($location);
                     $offer->save();
                 }
             }
         }
     }
     Event::fire(new OfferParsed($offer));
 }
コード例 #14
0
 public function offers($timestamp = 0)
 {
     $offers = Offer::whereDate('created_at', '>', Carbon::createFromTimestamp($timestamp))->get();
     return response()->json($offers->toArray(), 200, [], JSON_UNESCAPED_UNICODE);
 }
コード例 #15
0
ファイル: Product.php プロジェクト: serovvitaly/kotik
 /**
  * Возвращает актуальные товарные предложения
  */
 public function getActualProductOffers()
 {
     $sql = "select co.offer_id, po.id as product_offer_id\n                from offers ofr\n                join catalog_offer co on co.offer_id = ofr.id\n                join catalogs ct on co.catalog_id = ct.id\n                join products_offers po on po.catalog_id = ct.id\n                join " . self::TABLE_NAME . " p on po.product_id = p.id\n                where ofr.status = 1 and ct.status = 1 and po.status = 1 and po.product_id = :product_id";
     $result = \DB::select($sql, ['product_id' => $this->id]);
     if (!$result) {
         return [];
     }
     $output_arr = [];
     foreach ($result as $row) {
         $obj = new \stdClass();
         /**
          * @var \App\Models\Offer $offer_model
          * @var \App\Models\ProductOffer $product_offer_model
          */
         $offer_model = \App\Models\Offer::findOrFail($row->offer_id);
         $product_offer_model = \App\Models\ProductOffer::findOrFail($row->product_offer_id);
         $obj->offer = $offer_model;
         $obj->product_offer = $product_offer_model;
         $obj->price = $product_offer_model->getPrice();
         if ($offer_model->margin_percent > 0) {
             $obj->price += $obj->price * $offer_model->margin_percent / 100;
         }
         $obj->price = round($obj->price, 2);
         $output_arr[] = $obj;
     }
     return $output_arr;
 }
コード例 #16
0
 public function offerCount()
 {
     return Offer::count();
 }
コード例 #17
0
ファイル: edit_form.blade.php プロジェクト: serovvitaly/kotik
@extends('admin.layout')

@section('form_footer')

    <?php 
if (isset($model_id) and $model_id > 0) {
    $use_catalogs_ids_arr = \App\Models\Offer::findOrFail($model_id)->getCatalogsIdsArr();
} else {
    $use_catalogs_ids_arr = [];
}
?>

    <div class="form-group">
        <label>Каталоги</label>
        @foreach(\Auth::user()->catalogs()->get() as $catalog)
            <div class="checkbox">
                <label>
                    <input type="checkbox" name="catalogs[]" value="{{ $catalog->id }}"{{ in_array($catalog->id, $use_catalogs_ids_arr) ? ' checked' : '' }}>
                    {{ $catalog->name }}
                </label>
            </div>
        @endforeach
    </div>

@endsection

@section('content')
    @include('admin.common.edit_form')
@endsection
コード例 #18
0
 public function ModelEditView($clid, $advid, $mdlid)
 {
     if (!is_null($mdlid)) {
         if (Auth::check()) {
             if (in_array('ADD_EDIT_MODEL', $this->permission)) {
                 if (User::isSuperAdmin()) {
                     $offer = Offer::get();
                     $model_obj = ModelTable::with(['getAdvertiser' => function ($q) {
                         $q->with('GetClientID');
                     }])->find($mdlid);
                 } else {
                     $usr_company = $this->user_company();
                     $model_obj = ModelTable::whereHas('getAdvertiser', function ($q) use($usr_company) {
                         $q->whereHas('GetClientID', function ($p) use($usr_company) {
                             $p->whereIn('user_id', $usr_company);
                         });
                     })->find($mdlid);
                     $offer = Offer::whereHas('getAdvertiser', function ($q) use($usr_company) {
                         $q->whereHas('GetClientID', function ($p) use($usr_company) {
                             $p->whereIn('user_id', $usr_company);
                         });
                     })->get();
                 }
                 if (!$model_obj) {
                     return Redirect::back()->withErrors(['success' => false, 'msg' => 'please Select your Client'])->withInput();
                 }
                 $positive_offer_id = array();
                 $negative_offer_id = array();
                 if (!is_null($model_obj->positive_offer_id)) {
                     $positive_offer_id = explode(',', $model_obj->positive_offer_id);
                 }
                 if (!is_null($model_obj->negative_offer_id)) {
                     $negative_offer_id = explode(',', $model_obj->negative_offer_id);
                 }
                 return view('model.edit')->with('offer_obj', $offer)->with('positive_offer_id', $positive_offer_id)->with('negative_offer_id', $negative_offer_id)->with('model_obj', $model_obj);
             }
             return Redirect::back()->withErrors(['success' => false, 'msg' => "You don't have permission"]);
         }
         return Redirect::to(url('/user/login'));
     }
 }