/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Friends::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, 'myid' => $this->myid, 'friendid' => $this->friendid, 'created_at' => $this->created_at]);
     return $dataProvider;
 }
Exemple #2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getFriends0()
 {
     return $this->hasMany(Friends::className(), ['myid' => 'id']);
 }
 /**
  * Finds the Friends model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Friends the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Friends::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 public function actionDelete()
 {
     $data = Yii::$app->request->post();
     if (isset($data['myphone']) && isset($data['friendphone'])) {
         $u1 = Users::find()->where(['phone' => $data['myphone']])->one();
         $u2 = Users::find()->where(['phone' => $data['friendphone']])->one();
         if (!Friends::findAll(['myid' => $u1['id'], 'friendid' => $u2['id']]) && !Friends::findAll(['myid' => $u2['id'], 'friendid' => $u1['id']])) {
             return array('flag' => 0, 'msg' => 'is already not friend!');
         }
         Friends::deleteAll('myid = :myid and friendid = :friendid or myid = :friendid and friendid = :myid', [':myid' => $u1['id'], ':friendid' => $u2['id']]);
         $easeclient = new Easeapi('YXA6halokJDEEeWMRgvYONLZPQ', 'YXA6pswnZbss8mj351XE3oxuRYm6cek', '13022660999', 'allpeopleleague', 'file');
         $result = json_decode($easeclient->curl('/users/' . $u1->id . '/contacts/users/' . $u2->id, '', 'DELETE'), true);
         return array('flag' => 1, 'msg' => 'delete friend success!');
     } else {
         return array('flag' => 0, 'msg' => 'arg not enough!');
     }
 }