1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Administrator
- * Date: 2017/8/11
- * Time: 14:21
- */
- namespace company\controllers;
- use yii\base\Controller;
- use yii\filters\AccessControl;
- use yii;
- use yii\data\Pagination;
- use common\models\Feedback;
- class FeekbackController extends Controller {
- public $layout = 'iframe';
- const PAGESIZE =10;// 分页条数
- public function behaviors()
- {
- return [
- 'access' => [
- 'class' => AccessControl::className(),
- 'rules' => [
- [
- 'actions' => [],
- 'allow' => true,
- 'roles' => ['@'],
- ],
- ],
- ],
- ];
- }
- public function actionIndex(){
- $models = Feedback::find()->where('uid=:uid and type=:type',[':uid'=>Yii::$app->user->id,':type'=>Feedback::TYPE_COMPANY]);
- $pages = new Pagination(["totalCount"=>$models->count(),"pageSize"=>self::PAGESIZE]);
- $models = $models->offset($pages->offset)->limit($pages->limit)->all();
- return $this->render('index',['models'=>$models,'pages'=>$pages]);
- }
- public function actionCreate(){
- $model = new Feedback();
- $content = Yii::$app->request->get('content');
- $email = Yii::$app->request->get('email');
- $model->uid = Yii::$app->user->id;
- $model->content = isset($content)?$content:"";
- $model->contact = isset($email)?$email:"";
- $model->created_at = time();
- $model->updated_at = time();
- $model->status = Feedback::STATUS_ACTIVE;
- $model->type = Feedback::TYPE_COMPANY;
- $model->state = Feedback::STATE_WAIT;
- if($model->validate()&&$model->save()){
- $result=['sign'=>1,'msg'=>'已经反馈'];
- return json_encode($result);
- }else{
- $result=['sign'=> 4000,'msg'=>'反馈失败'];
- return json_encode($result);
- }
- }
- }
|