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.

146 lines
4.1 KiB

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