123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- <?php
- namespace backend\controllers;
- use backend\models\AdminUser;
- use common\models\Feedback;
- use Yii;
- use yii\data\Pagination;
- /**
- * 意见反馈管理
- * @package backend\controllers
- */
- class FeekbackController extends BaseController
- {
- public $layout = 'iframe';
- const PAGESIZE =20;
- /**
- * 意见反馈列表
- */
- public function actionIndex()
- {
- $datas = Feedback::find()->where( ['status' => Feedback::STATUS_ACTIVE])->orderBy('updated_at DESC');
- $pages=new Pagination(["totalCount"=>$datas->count(),"pageSize"=>self::PAGESIZE]);
- $datas=$datas->offset($pages->offset)->limit($pages->limit)->all();
- return $this->render('feekback',['datas'=>$datas,'pages'=>$pages]);
- }
- /**
- * 意见反馈处理
- */
- public function actionDeal_with()
- {
- $id = Yii::$app->request->post('id');
- $reply = Yii::$app->request->post('reply');
- $reviewerid = Yii::$app->user->id;
- if(!empty($reviewerid)){
- if(!empty($id)){
- $reviewer1 = AdminUser::find()->select('username')->where('id=:id',[':id'=>$reviewerid])->one();
- $reviewer = $reviewer1->username;
- $model = Feedback::find()->where('id=:id',[':id'=>$id])->one();
- $contact = $model->contact;
- if(preg_match("/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/", $contact)){
- if($this->SendEmail($contact,$reply)){
- $model->author = $reviewer;
- $model->remark = $reply;
- $model->updated_at = time();
- $model->state = Feedback::STATE_DEAL;
- if($model->validate() && $model->save()){
- $result=['sign'=>1,'msg'=>'ok','user'=>$reviewer];
- }else{
- $result=['sign'=>0,'msg'=>'修改失败'];
- }
- }else{
- $result=['sign'=>0,'msg'=>'邮箱发送失败'];
- }
- }else{
- $result=['sign'=>0,'msg'=>'邮箱格式不正确'];
- }
- }else{
- $result=['sign'=>0,'msg'=>'该意见id不存在'];
- }
- }else{
- $result=['sign'=>0,'msg'=>'请先登录'];
- }
- return json_encode($result);
- }
- /**
- * 发送邮箱
- * @param $model
- * @param $subject
- * @param $content
- * @return bool
- */
- public static function SendEmail($contact,$reply){
- $subject = '回复您的意见反馈';
- $mail = Yii::$app->mailer->compose();
- $mail->setTo($contact); //要发送给那个人的邮箱
- $mail->setSubject($subject); //邮件主题
- // $mail->setTextBody($content); //发布纯文字文本
- $mail->setHtmlBody($reply); //发布页面文本
- if ($mail->send()) {
- return true;
- }
- return false;
- }
- /**
- * 删除意见
- * @return string
- */
- public function actionDel_feekback(){
- $result=['sign'=>1,'msg'=>'ok'];
- $id = Yii::$app->request->post('id');
- $model = Feedback::find()->where('id=:id',[':id'=>$id])->one();
- if(!empty($model)){
- $model->status = Feedback::STATUS_DELETED;
- $model->updated_at = time();
- if($model->validate() && $model->save()){
- $result=['sign'=>1,'msg'=>'ok'];
- }else{
- // var_dump($model->getErrors());exit;
- $result=['sign'=>0,'msg'=>'error'];
- }
- }else{
- $result=['sign'=>0,'msg'=>'找不到该规格'];
- }
- return json_encode($result);
- }
- }
|