<?php use common\z\ZCommonSessionFun; $role = ZCommonSessionFun::get_role(); $data['data'] = ''; if ($pagination->page < $pagination->pageCount) { $data['data'] = ''; } foreach ($a_models as $key => $row) { if ($row->tax == 1) { $url = Yii::$app->urlManager->createUrl(['answer/step1', 'id' => $row->id]); } else { $url = Yii::$app->urlManager->createUrl(['answer/step2-answer2', 'id' => $row->id]); } $image = common\models\Survey::getImageUrl($row); $is_top_text = ''; $is_top_url = ''; $op0 = Yii::$app->urlManager->createUrl(['survey/recommend', 'id' => $row->id, 'op' => 0]); $op1 = Yii::$app->urlManager->createUrl(['survey/recommend', 'id' => $row->id, 'op' => 1]); $is_top = 0; if ($row->is_top > 0) { $is_top_text = '取消推荐'; $is_top = 0; } else { $is_top_text = '推荐'; $is_top = 1; } $str_recommend = ''; if ($role == 1) { $str_recommend = <<<str \t\t\t\t<a
/** * 推荐 * * @return \yii\web\Response */ public function actionRecommend($id, $op) { $this->layout = false; $model = Survey::findOne($id); if (ZCommonSessionFun::get_user_id() < 1) { ZCommonFun::output_json(null, -1, '请登录'); } if (ZCommonSessionFun::get_role() != 1) { ZCommonFun::output_json(null, 2, '管理员才能操作'); } // 没有找到 if (!$model) { ZCommonFun::output_json(null, 1, '测试不存在'); $model = new Survey(); } // 推荐 $model->is_top = $op == 1 ? $_SERVER['REQUEST_TIME'] : 0; if ($model->save()) { ZCommonFun::output_json(null, 0, '操作成功'); } ZCommonFun::output_json(null, -2, '操作失败'); }