OthermailController.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: xiaofeng
  5. * Date: 2018/4/3
  6. * Time: 下午5:14
  7. * 邮箱设置
  8. */
  9. namespace backend\controllers;
  10. use Yii;
  11. use backend\base\Help;
  12. use backend\base\CommonController;
  13. use common\models\Email;
  14. class OthermailController extends CommonController
  15. {
  16. /*
  17. * 其他管理-邮箱设置-发件人页面
  18. * */
  19. public function actionFhome()
  20. {
  21. $url = Yii::$app->basePath . '/config/email.json';
  22. if (is_file($url)) {
  23. $data = json_decode(file_get_contents($url), true);
  24. return $this->render('fhomesave', ['model' => $data]);
  25. }
  26. return $this->render('fhome');
  27. }
  28. /*
  29. * 其他管理-邮箱设置-修改and添加数据
  30. * */
  31. public function actionHomemailform()
  32. {
  33. $url = Yii::$app->basePath . '/config/email.json';
  34. $input = Yii::$app->request->post('data');
  35. $data = json_encode([
  36. 'class' => 'Swift_SmtpTransport',
  37. 'host' => $input['host'], //每种邮箱的host配置不一样
  38. 'username' => $input['username'],
  39. 'password' => $input['password'],
  40. 'port' => $input['port'],
  41. // 'encryption' => 'tls'
  42. 'encryption' => 'ssl'
  43. ]
  44. );
  45. if (file_put_contents($url, $data) > 0) {
  46. return Help::JsonCode(Help::SUCCESS, '操作成功');
  47. }
  48. }
  49. /*
  50. * 其他管理-邮箱设置-邮件发送测试
  51. * */
  52. public function actionTestemail()
  53. {
  54. $url = Yii::$app->basePath . '/config/email.json';
  55. $input = Yii::$app->request->post('data');
  56. if (is_file($url)) {
  57. $mail = Yii::$app->mailer->compose();
  58. $mail->setTo($input['collect']);
  59. $mail->setSubject($input['title']);
  60. $mail->setTextBody($input['content']);
  61. if ($mail->send() == true) return Help::JsonCode(Help::SUCCESS, '邮件发送成功');
  62. }
  63. return Help::JsonCode(Help::ERROR, '邮件发送失败,请查看邮箱配置是否正确。');
  64. }
  65. public function actionAa()
  66. {
  67. phpinfo();
  68. }
  69. /*
  70. * 其他管理-邮箱设置-收件人首页
  71. * */
  72. public function actionCollecthome()
  73. {
  74. return $this->render('collecthome');
  75. }
  76. /*
  77. * 其他管理-邮箱设置-收件人数据列表
  78. * */
  79. public function actionCollecthomeform()
  80. {
  81. $model = new Email();
  82. $rows = $model->getList(Yii::$app->request->post());
  83. if($rows != null)
  84. {
  85. return Help::JsonData(0,'成功',$model->Total(),$rows);
  86. }
  87. return Help::JsonCode(Help::ERROR,'暂无数据');
  88. }
  89. /*
  90. * 其他管理-邮箱设置-收件人添加页面
  91. * */
  92. public function actionCollectadd()
  93. {
  94. $model = new \common\models\CategoryCity();
  95. $rows = $model->getList([]);
  96. return $this->render('collectadd',['city'=>$rows]);
  97. }
  98. /*
  99. * 其他管理-邮箱设置-收件人添加数据
  100. * */
  101. public function actionCollectaddform()
  102. {
  103. $input = Yii::$app->request->post('data');
  104. $model = new \common\models\Email();
  105. $model->scenario = 'add';
  106. $models = $model->Authenticator($input);
  107. if(is_array($models)) return Help::JsonCode(Help::ERROR,'添加失败',$model->errors);
  108. if($models->save() == true) return Help::JsonCode(Help::SUCCESS,'添加成功');
  109. }
  110. /*
  111. * 其他管理-邮箱设置-收件人删除数据
  112. * */
  113. public function actionCollectdel()
  114. {
  115. $model = new Email();
  116. $row = $model->FindById(Yii::$app->request->post('id'));
  117. if($row != null)
  118. {
  119. $row->del = 2;
  120. if($row->save() == true) return Help::JsonCode(Help::SUCCESS,'操作成功');
  121. }
  122. return Help::JsonCode(Help::ERROR,'操作失败');
  123. }
  124. /*
  125. * 其他管理-邮箱设置-收件人修改页面
  126. * */
  127. public function actionCollectedit()
  128. {
  129. $model = new Email();
  130. $row = $model->FindById(Yii::$app->request->get('id'));
  131. if($row != null)
  132. {
  133. $cityModel = new \common\models\CategoryCity();
  134. $city = $cityModel->getList([]);
  135. return $this->render('collectedit',['model'=>$row,'city'=>$city]);
  136. }
  137. }
  138. /*
  139. * 其他管理-邮箱设置-收件人修改数据
  140. * */
  141. public function actionCollecteditform()
  142. {
  143. $input = Yii::$app->request->post('data');
  144. $model = new Email();
  145. $model->scenario = 'edit';
  146. $model->id = $input['id'];
  147. $auth = $model->Authenticator($input);
  148. if(is_object($auth))
  149. {
  150. $row = $model->FindById($input['id']);
  151. if($row != null)
  152. {
  153. $row = Help::SetAttr($input,$auth,$row);
  154. if($row->save(false) == true) return Help::JsonCode(Help::SUCCESS,'操作成功');
  155. }
  156. }
  157. return Help::JsonCode(Help::ERROR,'操作失败',$auth);
  158. }
  159. }