You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

136 lines
3.8 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
6 years ago
7 years ago
7 years ago
7 years ago
6 years ago
7 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. <?php
  2. namespace App\Http\Logic;
  3. use App\Common\ReturnData;
  4. use App\Http\Model\Sysconfig;
  5. use App\Http\Requests\SysconfigRequest;
  6. use Validator;
  7. class SysconfigLogic extends BaseLogic
  8. {
  9. public function __construct()
  10. {
  11. parent::__construct();
  12. }
  13. public function getModel()
  14. {
  15. return new Sysconfig();
  16. }
  17. public function getValidate($data, $scene_name)
  18. {
  19. //数据验证
  20. $validate = new SysconfigRequest();
  21. return Validator::make($data, $validate->getSceneRules($scene_name), $validate->getSceneRulesMessages());
  22. }
  23. //列表
  24. public function getList($where = array(), $order = '', $field = '*', $offset = '', $limit = '')
  25. {
  26. $res = $this->getModel()->getList($where, $order, $field, $offset, $limit);
  27. if($res['count'] > 0)
  28. {
  29. foreach($res['list'] as $k=>$v)
  30. {
  31. $res['list'][$k] = $this->getDataView($v);
  32. }
  33. }
  34. return $res;
  35. }
  36. //分页html
  37. public function getPaginate($where = array(), $order = '', $field = '*', $limit = '')
  38. {
  39. $res = $this->getModel()->getPaginate($where, $order, $field, $limit);
  40. if($res->count() > 0)
  41. {
  42. foreach($res as $k=>$v)
  43. {
  44. $res[$k] = $this->getDataView($v);
  45. }
  46. }
  47. return $res;
  48. }
  49. //全部列表
  50. public function getAll($where = array(), $order = '', $field = '*', $limit = '')
  51. {
  52. $res = $this->getModel()->getAll($where, $order, $field, $limit);
  53. if($res)
  54. {
  55. foreach($res as $k=>$v)
  56. {
  57. $res[$k] = $this->getDataView($v);
  58. }
  59. }
  60. return $res;
  61. }
  62. //详情
  63. public function getOne($where = array(), $field = '*')
  64. {
  65. $res = $this->getModel()->getOne($where, $field);
  66. if(!$res){return false;}
  67. $res = $this->getDataView($res);
  68. return $res;
  69. }
  70. //添加
  71. public function add($data = array(), $type=0)
  72. {
  73. if(empty($data)){return ReturnData::create(ReturnData::PARAMS_ERROR);}
  74. $validator = $this->getValidate($data, 'add');
  75. if ($validator->fails()){return ReturnData::create(ReturnData::PARAMS_ERROR, null, $validator->errors()->first());}
  76. $res = $this->getModel()->add($data,$type);
  77. if($res){return ReturnData::create(ReturnData::SUCCESS,$res);}
  78. return ReturnData::create(ReturnData::FAIL);
  79. }
  80. //修改
  81. public function edit($data, $where = array())
  82. {
  83. if(empty($data)){return ReturnData::create(ReturnData::SUCCESS);}
  84. $validator = $this->getValidate($data, 'edit');
  85. if ($validator->fails()){return ReturnData::create(ReturnData::PARAMS_ERROR, null, $validator->errors()->first());}
  86. $res = $this->getModel()->edit($data,$where);
  87. if($res){return ReturnData::create(ReturnData::SUCCESS,$res);}
  88. return ReturnData::create(ReturnData::FAIL);
  89. }
  90. //删除
  91. public function del($where)
  92. {
  93. if(empty($where)){return ReturnData::create(ReturnData::PARAMS_ERROR);}
  94. $validator = $this->getValidate($where,'del');
  95. if ($validator->fails()){return ReturnData::create(ReturnData::PARAMS_ERROR, null, $validator->errors()->first());}
  96. $res = $this->getModel()->del($where);
  97. if($res){return ReturnData::create(ReturnData::SUCCESS,$res);}
  98. return ReturnData::create(ReturnData::FAIL);
  99. }
  100. /**
  101. * 数据获取器
  102. * @param array $data 要转化的数据
  103. * @return array
  104. */
  105. private function getDataView($data = array())
  106. {
  107. return getDataAttr($this->getModel(),$data);
  108. }
  109. }