| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <?php
- namespace hd\models\homePageConfig;
- use bizHd\homePageConfig\classes\HomePageConfigClass;
- use hd\models\BaseForm;
- /**
- * 保存顶部导航与搜索配置
- */
- class SaveTopNavForm extends BaseForm
- {
- public $enabled;
- public $placeholder;
- public $searchBtnColor;
- public $searchFontColor;
- public $customerServiceEnabled;
- public function rules()
- {
- $defaults = HomePageConfigClass::getDefaultTopNav();
- return [
- ['enabled', 'default', 'value' => 0],
- ['placeholder', 'default', 'value' => $defaults['placeholder']],
- ['searchBtnColor', 'default', 'value' => $defaults['searchBtnColor']],
- ['searchFontColor', 'default', 'value' => $defaults['searchFontColor']],
- ['customerServiceEnabled', 'default', 'value' => 0],
- ['placeholder', 'required', 'message' => '请输入搜索占位文案'],
- ['placeholder', 'trim'],
- ['placeholder', 'string', 'max' => 50, 'tooLong' => '搜索占位文案不能超过50字'],
- [['searchBtnColor', 'searchFontColor'], 'string'],
- [['enabled', 'customerServiceEnabled'], 'filter', 'filter' => function ($value) {
- return !empty($value) ? 1 : 0;
- }],
- ];
- }
- public function attributeLabels()
- {
- return [
- 'enabled' => '开关',
- 'placeholder' => '搜索占位文案',
- 'searchBtnColor' => '搜索按钮颜色',
- 'searchFontColor' => '搜索字体颜色',
- 'customerServiceEnabled' => '客服开关',
- ];
- }
- /**
- * 写入 Redis 的样式字段(不含模块开关)
- * @return array
- */
- public function getPayload()
- {
- return [
- 'placeholder' => trim(strval($this->placeholder)),
- 'searchBtnColor' => strval($this->searchBtnColor),
- 'searchFontColor' => strval($this->searchFontColor),
- 'customerServiceEnabled' => !empty($this->customerServiceEnabled) ? 1 : 0,
- ];
- }
- /**
- * @return int
- */
- public function getEnabled()
- {
- return !empty($this->enabled) ? 1 : 0;
- }
- }
|