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.

124 lines
3.4 KiB

7 years ago
  1. <?php
  2. namespace app\common\logic;
  3. use think\Loader;
  4. use app\common\lib\ReturnData;
  5. use app\common\model\Page;
  6. class PageLogic extends BaseLogic
  7. {
  8. protected function initialize()
  9. {
  10. parent::initialize();
  11. }
  12. public function getModel()
  13. {
  14. return new Page();
  15. }
  16. public function getValidate()
  17. {
  18. return Loader::validate('Page');
  19. }
  20. //列表
  21. public function getList($where = array(), $order = '', $field = '*', $offset = '', $limit = '')
  22. {
  23. $res = $this->getModel()->getList($where, $order, $field, $offset, $limit);
  24. if($res['list'])
  25. {
  26. foreach($res['list'] as $k=>$v)
  27. {
  28. $res['list'][$k] = $this->getDataView($v);
  29. }
  30. }
  31. return $res;
  32. }
  33. //分页html
  34. public function getPaginate($where = array(), $order = '', $field = '*', $limit = '')
  35. {
  36. $res = $this->getModel()->getPaginate($where, $order, $field, $limit);
  37. return $res;
  38. }
  39. //全部列表
  40. public function getAll($where = array(), $order = '', $field = '*', $limit = '')
  41. {
  42. $res = $this->getModel()->getAll($where, $order, $field, $limit);
  43. /* if($res)
  44. {
  45. foreach($res as $k=>$v)
  46. {
  47. $res[$k] = $this->getDataView($v);
  48. }
  49. } */
  50. return $res;
  51. }
  52. //详情
  53. public function getOne($where = array(), $field = '*')
  54. {
  55. $res = $this->getModel()->getOne($where, $field);
  56. if(!$res){return false;}
  57. $res = $this->getDataView($res);
  58. $this->getModel()->getDb()->where($where)->setInc('click', 1);
  59. return $res;
  60. }
  61. //添加
  62. public function add($data = array(), $type=0)
  63. {
  64. if(empty($data)){return ReturnData::create(ReturnData::PARAMS_ERROR);}
  65. $check = $this->getValidate()->scene('add')->check($data);
  66. if($check === false){return ReturnData::create(ReturnData::PARAMS_ERROR,null,$this->getValidate()->getError());}
  67. $res = $this->getModel()->add($data,$type);
  68. if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);}
  69. return ReturnData::create(ReturnData::SUCCESS,$res);
  70. }
  71. //修改
  72. public function edit($data, $where = array())
  73. {
  74. if(empty($data)){return ReturnData::create(ReturnData::SUCCESS);}
  75. $res = $this->getModel()->edit($data,$where);
  76. if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);}
  77. return ReturnData::create(ReturnData::SUCCESS,$res);
  78. }
  79. //删除
  80. public function del($where)
  81. {
  82. if(empty($where)){return ReturnData::create(ReturnData::PARAMS_ERROR);}
  83. $check = $this->getValidate()->scene('del')->check($where);
  84. if($check === false){return ReturnData::create(ReturnData::PARAMS_ERROR,null,$this->getValidate()->getError());}
  85. $res = $this->getModel()->del($where);
  86. if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);}
  87. return ReturnData::create(ReturnData::SUCCESS,$res);
  88. }
  89. /**
  90. * 数据获取器
  91. * @param array $data 要转化的数据
  92. * @return array
  93. */
  94. private function getDataView($data = array())
  95. {
  96. return getDataAttr($this->getModel(),$data);
  97. }
  98. }