示例#1
0
文件: AdService.php 项目: zedx/core
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Adtype $adtype, CreateAdUserRequest $request)
 {
     if (($number = $this->numberAdtype($adtype)) <= 0 && $adtype->price > 0) {
         return ['adId' => null];
     }
     if ($this->user->subscription_expired_at) {
         if ($this->user->subscription_expired_at->diffInDays(null, false) >= 0) {
             return ['adId' => null];
         }
     }
     $geo = new GeolocationHelper($request->get('geolocation_data'));
     $adstatus = Adstatus::whereTitle('pending')->first();
     $category = Category::visible()->findOrFail($request->get('category_id'));
     $geolocation = new Geolocation();
     $geolocation->fill($geo->get());
     $content = new Adcontent();
     $content->fill($request->get('content'));
     $ad = new Ad();
     $ad->user()->associate($this->user);
     $ad->adtype()->associate($adtype);
     $ad->adstatus()->associate($adstatus);
     $ad->category()->associate($category);
     $ad->price = $this->getPrice($ad, $request);
     event(new AdWillBeCreated($ad, $content, $geolocation, $this->user));
     $ad->save();
     $ad->geolocation()->save($geolocation);
     $ad->content()->save($content);
     if ($ad->adtype->can_add_pic) {
         $this->syncAdPhotos($ad, $request);
     }
     if ($ad->adtype->can_add_video) {
         $this->syncAdVideos($ad, $request);
     }
     $this->syncAdFields($ad, $request);
     if ($number < 9999 && $number > 0) {
         $this->user->adtypes->find($adtype->id)->pivot->decrement('number');
     }
     event(new AdWasCreated($ad, $this->user));
     return ['adId' => $ad->id];
 }
示例#2
0
 protected function createAd($adtype, $data)
 {
     $geo = new Geolocation($data['geolocation_data']);
     $adstatus = Adstatus::whereTitle('pending')->first();
     $ad = new Ad();
     $ad->user_id = $data['user_id'];
     $ad->category_id = $data['category_id'];
     $ad->adstatus()->associate($adstatus);
     $ad->adtype()->associate($adtype);
     $ad->save();
     $ad->geolocation()->create($geo->get());
     $ad->content()->create($data['content']);
     if ($ad->adtype->can_add_pic) {
         $this->syncAdPhotos($ad, $data);
     }
     if ($ad->adtype->can_add_video) {
         $this->syncAdVideos($ad, $data);
     }
     $this->syncAdFields($ad, $data);
     event(new AdWasCreated($ad, 'ZEDx'));
     $this->validateAd($ad);
 }
示例#3
0
 public function updateAdtype(Ad $ad, Adtype $adtype, AdtypeRequest $request)
 {
     $inputs = $request->all();
     if ($ad->adtype_id != $adtype->id) {
         abort(400);
     }
     if ($adtype->is_customized) {
         unset($inputs['title']);
         $adtype->update($inputs);
     } else {
         $inputs['is_customized'] = 1;
         $adtype = Adtype::create($inputs);
         $ad->adtype()->associate($adtype)->save();
     }
     $nbrDays = $ad->adtype->nbr_days;
     $ad->expired_at = $nbrDays >= 9999 ? null : $ad->published_at->addDays($nbrDays + 1);
     $ad->save();
     return redirect()->route('zxadmin.ad.index');
 }