SmsTemplateForm.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace common\models\forms;
  3. use common\components\Model;
  4. use common\helpers\Form;
  5. use common\models\SmsTemplate;
  6. /**
  7. * Login form
  8. */
  9. class SmsTemplateForm extends Model
  10. {
  11. public $id;
  12. public $content;
  13. /**
  14. * @inheritdoc
  15. */
  16. public function rules()
  17. {
  18. return [
  19. [['id', 'content'], 'trim'],
  20. [['id', 'content'], 'required'],
  21. ];
  22. }
  23. /**
  24. * 指定校验场景
  25. * @return array
  26. */
  27. public function scenarios()
  28. {
  29. $parentScenarios = parent::scenarios();
  30. $customScenarios = [
  31. 'edit' => ['content']
  32. ];
  33. return array_merge($parentScenarios, $customScenarios);
  34. }
  35. public function attributeLabels()
  36. {
  37. return [
  38. 'content' => '模板内容',
  39. ];
  40. }
  41. /**
  42. * 编辑短信模板
  43. * @return null|static
  44. */
  45. public function edit(){
  46. if(!$this->validate()){
  47. return null;
  48. }
  49. $model = SmsTemplate::findOne($this->id);
  50. $model->CONTENT = $this->content;
  51. if(!$model->save()){
  52. $this->addError('edit', Form::formatErrorsForApi($model->getErrors()));
  53. return null;
  54. }
  55. return $model;
  56. }
  57. }