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.

122 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\GoodsBrand;
  6. class GoodsBrandLogic extends BaseLogic
  7. {
  8. protected function initialize()
  9. {
  10. parent::initialize();
  11. }
  12. public function getModel()
  13. {
  14. return new GoodsBrand();
  15. }
  16. public function getValidate()
  17. {
  18. return Loader::validate('GoodsBrand');
  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. return $res;
  59. }
  60. //添加
  61. public function add($data = array(), $type=0)
  62. {
  63. if(empty($data)){return ReturnData::create(ReturnData::PARAMS_ERROR);}
  64. $check = $this->getValidate()->scene('add')->check($data);
  65. if($check === false){return ReturnData::create(ReturnData::PARAMS_ERROR,null,$this->getValidate()->getError());}
  66. $res = $this->getModel()->add($data,$type);
  67. if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);}
  68. return ReturnData::create(ReturnData::SUCCESS,$res);
  69. }
  70. //修改
  71. public function edit($data, $where = array())
  72. {
  73. if(empty($data)){return ReturnData::create(ReturnData::SUCCESS);}
  74. $res = $this->getModel()->edit($data,$where);
  75. if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);}
  76. return ReturnData::create(ReturnData::SUCCESS,$res);
  77. }
  78. //删除
  79. public function del($where)
  80. {
  81. if(empty($where)){return ReturnData::create(ReturnData::PARAMS_ERROR);}
  82. $check = $this->getValidate()->scene('del')->check($where);
  83. if($check === false){return ReturnData::create(ReturnData::PARAMS_ERROR,null,$this->getValidate()->getError());}
  84. $res = $this->getModel()->del($where);
  85. if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);}
  86. return ReturnData::create(ReturnData::SUCCESS,$res);
  87. }
  88. /**
  89. * 数据获取器
  90. * @param array $data 要转化的数据
  91. * @return array
  92. */
  93. private function getDataView($data = array())
  94. {
  95. return getDataAttr($this->getModel(),$data);
  96. }
  97. }