FeekbackController.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2017/8/11
  6. * Time: 14:21
  7. */
  8. namespace company\modules\manage\controllers;
  9. use yii\base\Controller;
  10. use company\modules\manage\controllers\LoginverifyController;
  11. use yii\filters\AccessControl;
  12. use yii;
  13. use yii\data\Pagination;
  14. use common\models\Feedback;
  15. class FeekbackController extends LoginverifyController {
  16. public $layout = 'iframe';
  17. const PAGESIZE =10;// 分页条数
  18. public function behaviors()
  19. {
  20. return [
  21. 'access' => [
  22. 'class' => AccessControl::className(),
  23. 'rules' => [
  24. [
  25. 'actions' => [],
  26. 'allow' => true,
  27. 'roles' => ['@'],
  28. ],
  29. ],
  30. ],
  31. ];
  32. }
  33. public function actionIndex(){
  34. $models = Feedback::find()->where('uid=:uid and type=:type',[':uid'=>Yii::$app->user->id,':type'=>Feedback::TYPE_COMPANY]);
  35. $pages = new Pagination(["totalCount"=>$models->count(),"pageSize"=>self::PAGESIZE]);
  36. $models = $models->offset($pages->offset)->limit($pages->limit)->all();
  37. return $this->render('index',['models'=>$models,'pages'=>$pages]);
  38. }
  39. public function actionCreate(){
  40. $model = new Feedback();
  41. $content = Yii::$app->request->get('content');
  42. $email = Yii::$app->request->get('email');
  43. $model->uid = Yii::$app->user->id;
  44. $model->content = isset($content)?$content:"";
  45. $model->contact = isset($email)?$email:"";
  46. $model->created_at = time();
  47. $model->updated_at = time();
  48. $model->status = Feedback::STATUS_ACTIVE;
  49. $model->type = Feedback::TYPE_COMPANY;
  50. $model->state = Feedback::STATE_WAIT;
  51. if($model->validate()&&$model->save()){
  52. $result=['sign'=>1,'msg'=>'已经反馈'];
  53. return json_encode($result);
  54. }else{
  55. $result=['sign'=> 4000,'msg'=>'反馈失败'];
  56. return json_encode($result);
  57. }
  58. }
  59. }