SaveTopNavForm.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace hd\models\homePageConfig;
  3. use bizHd\homePageConfig\classes\HomePageConfigClass;
  4. use hd\models\BaseForm;
  5. /**
  6. * 保存顶部导航与搜索配置
  7. */
  8. class SaveTopNavForm extends BaseForm
  9. {
  10. public $enabled;
  11. public $placeholder;
  12. public $searchBtnColor;
  13. public $searchFontColor;
  14. public $customerServiceEnabled;
  15. public function rules()
  16. {
  17. $defaults = HomePageConfigClass::getDefaultTopNav();
  18. return [
  19. ['enabled', 'default', 'value' => 0],
  20. ['placeholder', 'default', 'value' => $defaults['placeholder']],
  21. ['searchBtnColor', 'default', 'value' => $defaults['searchBtnColor']],
  22. ['searchFontColor', 'default', 'value' => $defaults['searchFontColor']],
  23. ['customerServiceEnabled', 'default', 'value' => 0],
  24. ['placeholder', 'required', 'message' => '请输入搜索占位文案'],
  25. ['placeholder', 'trim'],
  26. ['placeholder', 'string', 'max' => 50, 'tooLong' => '搜索占位文案不能超过50字'],
  27. [['searchBtnColor', 'searchFontColor'], 'string'],
  28. [['enabled', 'customerServiceEnabled'], 'filter', 'filter' => function ($value) {
  29. return !empty($value) ? 1 : 0;
  30. }],
  31. ];
  32. }
  33. public function attributeLabels()
  34. {
  35. return [
  36. 'enabled' => '开关',
  37. 'placeholder' => '搜索占位文案',
  38. 'searchBtnColor' => '搜索按钮颜色',
  39. 'searchFontColor' => '搜索字体颜色',
  40. 'customerServiceEnabled' => '客服开关',
  41. ];
  42. }
  43. /**
  44. * 写入 Redis 的样式字段(不含模块开关)
  45. * @return array
  46. */
  47. public function getPayload()
  48. {
  49. return [
  50. 'placeholder' => trim(strval($this->placeholder)),
  51. 'searchBtnColor' => strval($this->searchBtnColor),
  52. 'searchFontColor' => strval($this->searchFontColor),
  53. 'customerServiceEnabled' => !empty($this->customerServiceEnabled) ? 1 : 0,
  54. ];
  55. }
  56. /**
  57. * @return int
  58. */
  59. public function getEnabled()
  60. {
  61. return !empty($this->enabled) ? 1 : 0;
  62. }
  63. }