Exemplo n.º 1
0
 /**
  * 获取动态
  */
 public function actionGetmomentdata()
 {
     $rightNowUserId = Yii::$app->user->identity->XH_ID;
     $rightNowUserName = Yii::$app->user->identity->Name;
     $moments = new Moments();
     $content = $moments->getPageMomentWithOrder(1, 6);
     $allPage = $moments->getAllPage(6);
     //		$content = Moments::find()->asArray()->join('LEFT JOIN','user_tb','moments.XH_ID=user_tb.XH_ID')->orderBy('Mdate DESC,Time DESC')->all();
     //		$content = Moments::find()->asArray()->orderBy('Mdate DESC,Time DESC')->all();
     $istop = MomentTop::find()->all();
     if (!empty($content)) {
         foreach ($content as $key => $value) {
             foreach ($istop as $key1 => $value1) {
                 if ($value1['moment_id'] == $value['id']) {
                     $content[$key]['status'] = $value1['status'];
                 }
             }
             $name = UserTb::findOne($value['XH_ID']);
             $content[$key]['username'] = $name['Name'];
         }
     }
     $content = '{"moments":' . json_encode($content, JSON_UNESCAPED_UNICODE) . ',"allPage":"' . $allPage . '","userIdNow":"' . $rightNowUserId . '","userName":"******"}';
     echo $content;
 }
Exemplo n.º 2
0
 /**
  * 分页(搜索)
  * @param $input
  * @param $page
  * @param $number
  * @return array|string
  */
 public function getPageMomentWithOrder_2($input, $page, $number)
 {
     $front = ($page - 1) * $number;
     if ($page == 1) {
         //            $sql="SELECT tabbledesc.id,tabbledesc.XH_ID,Content,Mdate FROM (SELECT * FROM moments ORDER BY Mdate DESC,Time desc)AS tabbledesc LEFT JOIN moment_top ON tabbledesc.id=moment_top.moment_id  WHERE tabbledesc.Content like '%$input%' OR tabbledesc.XH_ID like '%$input%' LIMIT $number";
         $sql = "SELECT id,XH_ID,Content,Mdate from moments WHERE Content like '%{$input}%' OR XH_ID like '%{$input}%' ORDER BY Mdate DESC ,TIME DESC LIMIT {$number}";
     } else {
         $sql = "SELECT id,XH_ID,Content,Mdate from moments WHERE Content like '%{$input}%' OR XH_ID like '%{$input}%' ORDER BY Mdate DESC ,TIME DESC LIMIT {$front},{$number}";
         //            $count=Yii::$app->db->createCommand($sql1)->queryAll();
         //            $idcount="";
         //            foreach($count as $key=>$value){
         //                $idcount.=$value['id'].',';
         //            }
         //            $idcount=rtrim($idcount, ",");
         ////                print_r($idcount);
         ////                exit();
         //            $sql="SELECT id,XH_ID,Content,Mdate FROM Moments WHERE id NOT IN($idcount) AND  (Content like '%$input%' OR XH_ID LIKE '%$input%') ORDER BY Mdate DESC,Time DESC LIMIT $number;";
     }
     $result = yii::$app->db->createCommand($sql)->queryAll();
     if (!empty($result)) {
         $istop = MomentTop::find()->all();
         foreach ($result as $key => $value) {
             foreach ($istop as $key1 => $value1) {
                 if ($value1['moment_id'] == $value['id']) {
                     $result[$key]['status'] = $value1['status'];
                 }
             }
             //			$value['username']=UserTb::findOne($value['XH_ID'])->Name;
             $result[$key]['username'] = UserTb::findOne($value['XH_ID'])->Name;
         }
         $allPage = $this->getAllPage_s(6, $input);
         $result = '{"success":true,"moments":' . json_encode($result, JSON_UNESCAPED_UNICODE) . ',"allPage_s":"' . $allPage . '"}';
         return $result;
     } else {
         $result = '{"success":false,"msg":"没有找到相关动态","allPage_s":"1"}';
         return $result;
     }
 }
 public function actionAdminupdatemoment_2()
 {
     //判断信息是否填写完全
     if (empty($_POST["momentid"]) || !isset($_POST["momentid"]) || (empty($_POST["status"]) || !isset($_POST["status"]))) {
         echo '{"success":false,"msg":"选项错误"}';
         return;
     }
     if ($_POST['status'] == "1") {
         if (MomentTop::find()->count() >= 5) {
             echo '{"success":false,"msg":"置顶上限已满!!"}';
             exit;
         }
         $newtop = new MomentTop();
         $newtop->moment_id = $_POST['momentid'];
         $newtop->status = 1;
         $newtop->save();
     } else {
         if ($_POST['status'] == "2") {
             $deltop = MomentTop::find()->where(['moment_id' => $_POST["momentid"]])->one();
             $deltop->delete();
         } else {
             echo '{"success":false,"msg":"出现错误!"}';
         }
     }
     echo '{"success":true,"msg":"添加成功!"}';
 }