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.

138 lines
3.9 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
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\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. return $res;
  42. }
  43. //全部列表
  44. public function getAll($where = array(), $order = '', $field = '*', $limit = '')
  45. {
  46. $res = $this->getModel()->getAll($where, $order, $field, $limit);
  47. /* if($res)
  48. {
  49. foreach($res as $k=>$v)
  50. {
  51. $res[$k] = $this->getDataView($v);
  52. }
  53. } */
  54. return $res;
  55. }
  56. //详情
  57. public function getOne($where = array(), $field = '*')
  58. {
  59. $res = $this->getModel()->getOne($where, $field);
  60. if(!$res){return false;}
  61. $res = $this->getDataView($res);
  62. return $res;
  63. }
  64. //添加
  65. public function add($data = array(), $type=0)
  66. {
  67. if(empty($data)){return ReturnData::create(ReturnData::PARAMS_ERROR);}
  68. $data['add_time'] = time();
  69. $validator = $this->getValidate($data, 'add');
  70. if ($validator->fails()){return ReturnData::create(ReturnData::PARAMS_ERROR, null, $validator->errors()->first());}
  71. if($data['start_time'] >= $data['end_time'])
  72. {
  73. return ReturnData::create(ReturnData::PARAMS_ERROR,null,'有效期错误');
  74. }
  75. //正则验证时间格式,未作
  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()->edit(['delete_time'=>time()],$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. }