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.

128 lines
3.7 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
6 years ago
7 years ago
6 years ago
7 years ago
6 years ago
7 years ago
6 years ago
7 years ago
6 years ago
7 years ago
7 years ago
7 years ago
6 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
  1. <?php
  2. namespace App\Http\Logic;
  3. use App\Common\ReturnData;
  4. use App\Http\Model\GoodsBrand;
  5. use App\Http\Requests\GoodsBrandRequest;
  6. use Validator;
  7. class GoodsBrandLogic extends BaseLogic
  8. {
  9. public function __construct()
  10. {
  11. parent::__construct();
  12. }
  13. public function getModel()
  14. {
  15. return new GoodsBrand();
  16. }
  17. public function getValidate($data, $scene_name)
  18. {
  19. //数据验证
  20. $validate = new GoodsBrandRequest();
  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. return $res;
  41. }
  42. //全部列表
  43. public function getAll($where = array(), $order = '', $field = '*', $limit = '')
  44. {
  45. $res = $this->getModel()->getAll($where, $order, $field, $limit);
  46. /* if($res)
  47. {
  48. foreach($res as $k=>$v)
  49. {
  50. $res[$k] = $this->getDataView($v);
  51. }
  52. } */
  53. return $res;
  54. }
  55. //详情
  56. public function getOne($where = array(), $field = '*')
  57. {
  58. $res = $this->getModel()->getOne($where, $field);
  59. if(!$res){return false;}
  60. $res = $this->getDataView($res);
  61. return $res;
  62. }
  63. //添加
  64. public function add($data = array(), $type=0)
  65. {
  66. if(empty($data)){return ReturnData::create(ReturnData::PARAMS_ERROR);}
  67. $validator = $this->getValidate($data, 'add');
  68. if ($validator->fails()){return ReturnData::create(ReturnData::PARAMS_ERROR, null, $validator->errors()->first());}
  69. $res = $this->getModel()->add($data,$type);
  70. if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);}
  71. return ReturnData::create(ReturnData::SUCCESS,$res);
  72. }
  73. //修改
  74. public function edit($data, $where = array())
  75. {
  76. if(empty($data)){return ReturnData::create(ReturnData::SUCCESS);}
  77. $validator = $this->getValidate($data, 'edit');
  78. if ($validator->fails()){return ReturnData::create(ReturnData::PARAMS_ERROR, null, $validator->errors()->first());}
  79. $res = $this->getModel()->edit($data,$where);
  80. if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);}
  81. return ReturnData::create(ReturnData::SUCCESS,$res);
  82. }
  83. //删除
  84. public function del($where)
  85. {
  86. if(empty($where)){return ReturnData::create(ReturnData::PARAMS_ERROR);}
  87. $validator = $this->getValidate($where,'del');
  88. if ($validator->fails()){return ReturnData::create(ReturnData::PARAMS_ERROR, null, $validator->errors()->first());}
  89. $res = $this->getModel()->del($where);
  90. if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);}
  91. return ReturnData::create(ReturnData::SUCCESS,$res);
  92. }
  93. /**
  94. * 数据获取器
  95. * @param array $data 要转化的数据
  96. * @return array
  97. */
  98. private function getDataView($data = array())
  99. {
  100. return getDataAttr($this->getModel(),$data);
  101. }
  102. }