MailForm.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\admin\models;
  8. use yii\base\Model;
  9. use yii\helpers\Json;
  10. /**
  11. * @property \app\models\MailSetting $list;
  12. */
  13. class MailForm extends Model
  14. {
  15. public $store_id;
  16. public $list;
  17. public $send_mail;
  18. public $send_pwd;
  19. public $send_name;
  20. public $receive_mail;
  21. public $status;
  22. public function rules()
  23. {
  24. return [
  25. [['send_mail','send_pwd','send_name','receive_mail'],'required','on'=>'SUCCESS'],
  26. [['send_mail','send_pwd','send_name','receive_mail'],'trim'],
  27. [['send_mail','send_pwd','send_name','receive_mail'],'string'],
  28. [['status'],'in','range'=>[0,1]],
  29. ];
  30. }
  31. public function save()
  32. {
  33. if (!$this->validate()) {
  34. return [
  35. 'code' => 1,
  36. 'msg' => $this->getErrorSummary(false)[0],
  37. ];
  38. }
  39. if ($this->list->isNewRecord) {
  40. $this->list->is_delete = 0;
  41. $this->list->store_id = $this->store_id;
  42. $this->list->created_at = time();
  43. }
  44. $this->list->send_mail = $this->send_mail;
  45. $this->list->send_pwd = $this->send_pwd;
  46. $this->list->send_name = $this->send_name;
  47. $this->receive_mail = str_replace(',', ',', $this->receive_mail);
  48. $this->list->receive_mail = $this->receive_mail;
  49. $this->list->status = $this->status;
  50. if ($this->list->save()) {
  51. return [
  52. 'code'=>0,
  53. 'msg'=>'成功'
  54. ];
  55. } else {
  56. foreach ($this->list->errors as $error) {
  57. return [
  58. 'code' => 1,
  59. 'msg' => $error
  60. ];
  61. }
  62. }
  63. }
  64. }