Beispiel #1
0
 /**
  * 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]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['idfriends' => $this->idfriends, 'iduser' => $this->iduser, 'idfriend' => $this->idfriend, 'cdate' => $this->cdate, 'mdate' => $this->mdate]);
     return $dataProvider;
 }
Beispiel #2
0
 /**
  * 获取我加入的代祷列表
  * @param $user_id
  * @param $start_page
  * @param $page_no
  * @throws Exception
  * @return array
  */
 protected function myJoinIntercessionList($user_id, $start_page, $page_no)
 {
     //查询三维内的好友id
     $allIdArray = Friends::findFriendsByUserIdAndDepth($user_id, 3);
     //处理数组
     $handleArray = [];
     foreach ($allIdArray as $v) {
         $handleArray[$v['depth']][] = $v['friend_user_id'];
     }
     $userIdArray = $newArray = [];
     foreach ($handleArray as $k => $handleIdArray) {
         $handleIdArray = array_unique($handleIdArray);
         if (1 != $k) {
             foreach ($handleIdArray as $handleKey => $handleValue) {
                 $handleArray[1] = isset($handleArray[1]) ? $handleArray[1] : [];
                 $handleArray[2] = isset($handleArray[2]) ? $handleArray[2] : [];
                 if (2 == $k && (in_array($handleValue, $handleArray[1]) || $handleValue == $user_id)) {
                     unset($handleIdArray[$handleKey]);
                 }
                 if (3 == $k && (in_array($handleValue, $handleArray[1]) || in_array($handleValue, $handleArray[2]) || $handleValue == $user_id)) {
                     unset($handleIdArray[$handleKey]);
                 }
             }
         }
         $newArray[$k] = $handleIdArray;
         $userIdArray = array_merge($userIdArray, $handleIdArray);
     }
     //查询参与的代祷列表
     $intercessionList = IntercessionJoin::findAllByUserId($user_id, $start_page, $page_no);
     //分类数据
     $data = [];
     if ($intercessionList) {
         foreach ($intercessionList as $v) {
             //代祷人与自己的关系
             $relationship = 0;
             foreach ($newArray as $kUser => $vUser) {
                 if ($user_id == $v['user_id']) {
                     $relationship = 0;
                 }
                 if (in_array($v['user_id'], $vUser)) {
                     $relationship = $kUser;
                 }
             }
             //获取最新头像
             $portraitInfo = Portrait::findByUserId($v['user_id']);
             //获取代祷更新列表
             $updateList = IntercessionUpdate::getListWithIntercessionId($v['id']);
             $resultUpdateList = [];
             foreach ($updateList as $updateInfo) {
                 $resultUpdateList[] = ['content' => $updateInfo['content'], 'create_time' => $updateInfo['created_at'] * 1000];
             }
             $resultUpdateList = array_merge($resultUpdateList, [['content' => $v['content'], 'create_time' => $v['created_at'] * 1000]]);
             //获取代祷勇士
             $intercessorsList = IntercessionJoin::getAllByIntercessionId($v['id']);
             $resultIntercessorsList = [];
             foreach ($intercessorsList as $intercessorsInfo) {
                 $resultIntercessorsList[] = ['user_id' => $intercessorsInfo['id'], 'nick_name' => $intercessorsInfo['nickname']];
             }
             //构造返回数据
             $data[] = ['user_id' => $v['user_id'], 'intercession_id' => $v['id'], 'content_list' => $resultUpdateList, 'intercession_number' => $v['intercessions'], 'avatar' => !$portraitInfo ? '' : yii::$app->qiniu->getDomain() . '/' . $portraitInfo['portrait_name'], 'nick_name' => $v['nickname'], 'time' => $v['created_at'] * 1000, 'relationship' => $relationship, 'position' => $v['position'], 'intercessors_list' => $resultIntercessorsList, 'is_interceded' => true, 'gender' => (int) $v['gender']];
         }
     }
     return $data;
 }
 /**
  * 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.');
     }
 }