/**
  * Test the unsubscribe event
  *
  * @return void
  */
 public function testUnsubscribeOfficialAccount()
 {
     factory(App\Models\Subscriber::class)->create();
     $this->trigger("<xml><ToUserName><![CDATA[toUser]]></ToUserName><FromUserName><![CDATA[1234567]]></FromUserName><CreateTime>123456789</CreateTime><MsgType><![CDATA[event]]></MsgType><Event><![CDATA[unsubscribe]]></Event></xml>");
     $this->assertResponseOk();
     $this->see('success');
     $this->assertFalse(Subscriber::where('openId', 1234567)->first()->subscribed());
 }
 public function postSave(Request $request)
 {
     $mailing = Subscriber::findOrFail($request->input('id'));
     $mailing->name = $request->input('name');
     $mailing->email = $request->input('email');
     $mailing->save();
     return $mailing;
 }
 private function createList()
 {
     DB::transaction(function () {
         $this->mailing->status = 'working';
         $this->mailing->save();
         /** @var ListMailing $list */
         $list = ListMailing::forceCreate(['mailing_id' => $this->mailing->id, 'name' => 'some auto name', 'status' => 'pending']);
         Subscriber::where('status', 'active')->get()->each(function (Subscriber $subscriber) use($list) {
             ListMember::forceCreate(['list_id' => $list->id, 'subscriber_id' => $subscriber->id]);
         });
     });
 }
 /**
  * Handle the event.
  *
  * @param  \App\Events\WechatUserSubscribed  $event
  * @return \App\Models\Message
  */
 public function handle(WechatUserSubscribed $event)
 {
     $m = $event->message;
     /**
      * openId is always unique to our official account, so if user subscribes
      * again, we just need to toggle un-subscribed flag.
      */
     if ($subscriber = Subscriber::where('openId', $m->fromUserName)->where('unsubscribed', true)->first()) {
         $subscriber->unsubscribed = false;
     } else {
         $subscriber = new Subscriber();
         $subscriber->openId = $m->fromUserName;
     }
     $subscriber->save();
     // Link profile with subscriber if subscribe comes from profile page.
     if ($key = $m->messageable->eventKey) {
         Profile::find(Str::substr($key, Str::length('qrscene_')))->update(['weixin' => $m->fromUserName]);
         event(new ChangeSubscriberGroup($subscriber));
     }
     return $this->greetMessage($m->fromUserName, !is_null($key));
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Subscriber::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, 'status' => $this->status]);
     $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'pwd', $this->pwd]);
     return $dataProvider;
 }
 /**
  * Show the application dashboard to the user.
  *
  * @return Response
  */
 public function contact(Request $request)
 {
     $this->validate($request, ['name' => 'required|min:3|max:255', 'email' => 'required|email', 'contact_no' => 'numeric|min:10', 'subject' => 'required', 'message' => 'required']);
     Mail::send('emails.contact_admin', array('input' => Input::get()), function ($message) {
         $message->from(Input::get('email'), Input::get('name'))->to(env('MAIL_FROM_EMAIL'), env('MAIL_FROM_NAME'))->subject('Received new request');
     });
     Mail::send('emails.contact_user', array(), function ($message) {
         $message->to(Input::get('email'), Input::get('name'))->subject('Thanks for contacting us.');
     });
     Contact::create(Input::get());
     if (Input::get('subscribe')) {
         $subscriber = Subscriber::where('email', '=', Input::get('email'))->first();
         if (!isset($subscriber->exists)) {
             $subscriber_create = Subscriber::create(Input::get());
         }
     }
     return response()->json(['message' => 'Thanks for your request. Our representative will contact you soon.']);
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Subscriber::find();
     $query->leftJoin('phone', 'phone.subscriber_id = subscriber.id');
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     /*echo "<pre>";
     print_r($query);
     print_r($dataProvider);
     die;*/
     $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->orFilterWhere(['user_id' => Yii::$app->user->getId(), 'birth_date' => $this->globalSearch]);
     $query->orFilterWhere(["phone.number" => $this->globalSearch]);
     $query->orFilterWhere(['like', 'name', $this->globalSearch])->orFilterWhere(['like', 'notes', $this->globalSearch]);
     return $dataProvider;
 }
Exemple #8
0
 /**
  * Check if user has subscribed to our official account
  * 
  * @return Boolean 
  */
 public function subscribed()
 {
     return !is_null(Subscriber::where('openId', $this->weixin)->first());
 }
 /**
  * Finds the Subscriber model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Subscriber the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Subscriber::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemple #10
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getSubscriber()
 {
     return $this->hasOne(Subscriber::className(), ['id' => 'subscriber_id']);
 }
 public function get($id, $elequent)
 {
     $cacheKey = self::CACHE . $id;
     if ($elequent) {
         return Subscriber::find($id);
     }
     $cachedData = \Cache::has($cacheKey);
     if (empty($cachedData)) {
         $subscriber = Subscriber::find($id);
         if (!empty($subscriber)) {
             $subscriber = $subscriber->toArray();
             $subscriber['updated_at'] = date('Y-m-d', strtotime($subscriber['updated_at']));
             $subscriber['created_at_formatted'] = date('Y-m-d', strtotime($subscriber['created_at']));
             $subscriber['updated_at_formatted'] = date('Y-m-d', strtotime($subscriber['updated_at']));
             // Set data in cache
             \Cache::forever($cacheKey, $subscriber);
             return $subscriber;
         } else {
             return false;
         }
     } else {
         return \Cache::get($cacheKey);
     }
 }
Exemple #12
0
 /**
  * Handle the event.
  *
  * @param  WechatUserUnsubscribed  $event
  * @return void
  */
 public function handle(WechatUserUnsubscribed $event)
 {
     $subscriber = Subscriber::where('openId', $event->message->fromUserName)->first();
     $subscriber->unsubscribed = true;
     $subscriber->save();
 }