SystemConfig.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\model\system\config;
  12. use app\model\store\StoreConfig;
  13. use crmeb\basic\BaseModel;
  14. use crmeb\traits\ModelTrait;
  15. use think\Model;
  16. /**
  17. * 系统配置模型
  18. * Class SystemConfig
  19. * @package app\model\system\config
  20. */
  21. class SystemConfig extends BaseModel
  22. {
  23. use ModelTrait;
  24. /**
  25. * 数据表主键
  26. * @var string
  27. */
  28. protected $pk = 'id';
  29. /**
  30. * 模型名称
  31. * @var string
  32. */
  33. protected $name = 'system_config';
  34. /**
  35. * 一对一关联门店配置表
  36. * @return \think\model\relation\HasOne
  37. */
  38. public function storeConfig()
  39. {
  40. return $this->hasOne(StoreConfig::class, 'key_name', 'menu_name')->field(['key_name', 'type', 'relation_id', 'value'])->bind([
  41. 'store_value' => 'value',
  42. ]);
  43. }
  44. /**
  45. * 菜单名搜索器
  46. * @param Model $query
  47. * @param $value
  48. */
  49. public function searchMenuNameAttr($query, $value)
  50. {
  51. if (is_array($value)) {
  52. $query->whereIn('menu_name', $value);
  53. } else {
  54. $query->where('menu_name', $value);
  55. }
  56. }
  57. /**
  58. * tab id 搜索
  59. * @param Model $query
  60. * @param $value
  61. */
  62. public function searchTabIdAttr($query, $value)
  63. {
  64. $query->where('config_tab_id', $value);
  65. }
  66. /**
  67. * 状态搜索器
  68. * @param Model $query
  69. * @param $value
  70. */
  71. public function searchStatusAttr($query, $value)
  72. {
  73. $query->where('status', $value ?: 1);
  74. }
  75. /**
  76. * value搜索器
  77. * @param Model $query
  78. * @param $value
  79. */
  80. public function searchValueAttr($query, $value)
  81. {
  82. $query->where('value', $value);
  83. }
  84. /**
  85. * is_store 搜索
  86. * @param $query
  87. * @param $value
  88. */
  89. public function searchIsStoreAttr($query, $value)
  90. {
  91. if ($value) {
  92. $query->where('is_store', $value);
  93. }
  94. }
  95. }