FeekbackController.php 1.9 KB

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