FeekbackController.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. namespace backend\controllers;
  3. use backend\models\AdminUser;
  4. use common\models\Feedback;
  5. use Yii;
  6. use yii\data\Pagination;
  7. /**
  8. * 意见反馈管理
  9. * @package backend\controllers
  10. */
  11. class FeekbackController extends BaseController
  12. {
  13. public $layout = 'iframe';
  14. const PAGESIZE =20;
  15. /**
  16. * 意见反馈列表
  17. */
  18. public function actionIndex()
  19. {
  20. $datas = Feedback::find()->where( ['status' => Feedback::STATUS_ACTIVE])->orderBy('updated_at DESC');
  21. $pages=new Pagination(["totalCount"=>$datas->count(),"pageSize"=>self::PAGESIZE]);
  22. $datas=$datas->offset($pages->offset)->limit($pages->limit)->all();
  23. return $this->render('feekback',['datas'=>$datas,'pages'=>$pages]);
  24. }
  25. /**
  26. * 意见反馈处理
  27. */
  28. public function actionDeal_with()
  29. {
  30. $id = Yii::$app->request->post('id');
  31. $reply = Yii::$app->request->post('reply');
  32. $reviewerid = Yii::$app->user->id;
  33. if(!empty($reviewerid)){
  34. if(!empty($id)){
  35. $reviewer1 = AdminUser::find()->select('username')->where('id=:id',[':id'=>$reviewerid])->one();
  36. $reviewer = $reviewer1->username;
  37. $model = Feedback::find()->where('id=:id',[':id'=>$id])->one();
  38. $contact = $model->contact;
  39. if(preg_match("/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/", $contact)){
  40. if($this->SendEmail($contact,$reply)){
  41. $model->author = $reviewer;
  42. $model->remark = $reply;
  43. $model->updated_at = time();
  44. $model->state = Feedback::STATE_DEAL;
  45. if($model->validate() && $model->save()){
  46. $result=['sign'=>1,'msg'=>'ok','user'=>$reviewer];
  47. }else{
  48. $result=['sign'=>0,'msg'=>'修改失败'];
  49. }
  50. }else{
  51. $result=['sign'=>0,'msg'=>'邮箱发送失败'];
  52. }
  53. }else{
  54. $result=['sign'=>0,'msg'=>'邮箱格式不正确'];
  55. }
  56. }else{
  57. $result=['sign'=>0,'msg'=>'该意见id不存在'];
  58. }
  59. }else{
  60. $result=['sign'=>0,'msg'=>'请先登录'];
  61. }
  62. return json_encode($result);
  63. }
  64. /**
  65. * 发送邮箱
  66. * @param $model
  67. * @param $subject
  68. * @param $content
  69. * @return bool
  70. */
  71. public static function SendEmail($contact,$reply){
  72. $subject = '回复您的意见反馈';
  73. $mail = Yii::$app->mailer->compose();
  74. $mail->setTo($contact); //要发送给那个人的邮箱
  75. $mail->setSubject($subject); //邮件主题
  76. // $mail->setTextBody($content); //发布纯文字文本
  77. $mail->setHtmlBody($reply); //发布页面文本
  78. if ($mail->send()) {
  79. return true;
  80. }
  81. return false;
  82. }
  83. /**
  84. * 删除意见
  85. * @return string
  86. */
  87. public function actionDel_feekback(){
  88. $result=['sign'=>1,'msg'=>'ok'];
  89. $id = Yii::$app->request->post('id');
  90. $model = Feedback::find()->where('id=:id',[':id'=>$id])->one();
  91. if(!empty($model)){
  92. $model->status = Feedback::STATUS_DELETED;
  93. $model->updated_at = time();
  94. if($model->validate() && $model->save()){
  95. $result=['sign'=>1,'msg'=>'ok'];
  96. }else{
  97. // var_dump($model->getErrors());exit;
  98. $result=['sign'=>0,'msg'=>'error'];
  99. }
  100. }else{
  101. $result=['sign'=>0,'msg'=>'找不到该规格'];
  102. }
  103. return json_encode($result);
  104. }
  105. }