예제 #1
0
 protected function send()
 {
     $dataSender = null;
     $cutter = new GoogleUrlShortener();
     $searched = Searched::find()->where(['status' => Searched::STATUS_ACTIVE])->andWhere(['!=', 'plan_id', '1'])->all();
     foreach ($searched as $search) {
         $smsActive = Sms::find()->select('item_id')->where(['search_id' => $search->id])->all();
         $data = json_decode($search->url, true);
         $arr = [];
         foreach ($smsActive as $item) {
             $arr[] = $item->item_id;
         }
         $data['exclude_id'] = $arr;
         $count_sms = Yii::$app->db->createCommand('SELECT * FROM sms WHERE search_id = ' . $search->id . ' AND CAST(created_at as DATE) = CAST(NOW() as DATE)')->execute();
         $items = Items::search($data)->limit($search->plan->max_allow_sms - $count_sms)->all();
         foreach ($items as $item) {
             $sms = new SmsClient('0676124113', '0673188966');
             $smsBody = 'Ваш товар найден: ' . $cutter->shorten($item->url) . ($item->phone ? ' Тел. ' . $item->phone : '');
             $id = $sms->sendSMS('Sishik.net', $search->user->phone, $smsBody);
             if ($sms->hasErrors()) {
                 var_dump($sms->getErrors());
             } else {
                 $sms = new Sms();
                 $sms->search_id = $search->id;
                 $sms->text = $smsBody;
                 $sms->status = Sms::STATUS_DELIVERED;
                 $sms->item_id = $item->id;
                 $sms->save();
             }
         }
     }
 }
예제 #2
0
 public function actionIndex()
 {
     $dataSender = null;
     $searched = Searched::find()->where(['status' => Searched::STATUS_ACTIVE])->andWhere(['!=', 'plan_id', '1'])->all();
     foreach ($searched as $search) {
         $items = Items::search(json_decode($search->url, true))->limit($search->plan->max_allow_sms)->all();
         foreach ($items as $item) {
             $sms = new SmsClient('0676124113', '0673188966');
             $id = $sms->sendSMS('Sishik.net', $search->user->phone, 'Ваш товар найден: ' . $item->url);
             if ($sms->hasErrors()) {
                 var_dump($sms->getErrors());
             } else {
                 $sms = new Sms();
                 $sms->search_id = $search->id;
                 $sms->text = 'Ваш товар найден: ' . $item->url;
                 $sms->status = Sms::STATUS_DELIVERED;
                 $sms->save();
             }
         }
     }
 }
예제 #3
0
 /**
  * Удаление поискового запроса из базы
  * @param $id
  * @return \yii\web\Response
  */
 public function actionDelete($id)
 {
     if ($sms = Sms::deleteAll(['search_id' => $id])) {
         if ($model = Searched::deleteAll(['id' => $id, 'user_id' => Yii::$app->user->id])) {
             return $this->redirect('/user/profile');
         } else {
             return $this->redirect('/user/profile');
         }
     } else {
         if ($model = Searched::deleteAll(['id' => $id, 'user_id' => Yii::$app->user->id])) {
             return $this->redirect('/user/profile');
         } else {
             return $this->redirect('/user/profile');
         }
     }
 }