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.

116 lines
3.2 KiB

8 years ago
7 years ago
8 years ago
7 years ago
8 years ago
7 years ago
8 years ago
7 years ago
8 years ago
7 years ago
8 years ago
7 years ago
8 years ago
7 years ago
8 years ago
7 years ago
8 years ago
7 years ago
8 years ago
7 years ago
8 years ago
7 years ago
8 years ago
7 years ago
8 years ago
7 years ago
8 years ago
7 years ago
8 years ago
7 years ago
8 years ago
7 years ago
8 years ago
7 years ago
8 years ago
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use Log;
  4. use DB;
  5. use Illuminate\Http\Request;
  6. use App\Common\ReturnData;
  7. use App\Common\Helper;
  8. use App\Common\Token;
  9. use App\Http\Model\Bonus;
  10. use App\Http\Logic\BonusLogic;
  11. use App\Http\Model\UserBonus;
  12. class BonusController extends CommonController
  13. {
  14. public function __construct()
  15. {
  16. parent::__construct();
  17. }
  18. public function getLogic()
  19. {
  20. return logic('Bonus');
  21. }
  22. //可用获取的优惠券列表
  23. public function bonusList(Request $request)
  24. {
  25. //参数
  26. $limit = $request->input('limit', 10);
  27. $offset = $request->input('offset', 0);
  28. $where = function ($query) use ($request) {
  29. $query->where('delete_time', 0);
  30. $query->where('status', Bonus::STATUS);
  31. $query->where('num', '=', -1)->orWhere('num', '>', 0);
  32. $query->where('start_time', '<', date('Y-m-d H:i:s'))->where('end_time', '>', date('Y-m-d H:i:s'));
  33. };
  34. $res = $this->getLogic()->getList($where, '', '*', $offset, $limit);
  35. /* if($res['count']>0)
  36. {
  37. foreach($res['list'] as $k=>$v)
  38. {
  39. }
  40. } */
  41. return ReturnData::create(ReturnData::SUCCESS, $res);
  42. }
  43. public function bonusDetail(Request $request)
  44. {
  45. //参数
  46. if(!checkIsNumber($request->input('id',null))){return ReturnData::create(ReturnData::PARAMS_ERROR);}
  47. $id = $request->input('id');
  48. $where['id'] = $id;
  49. $where['status'] = Bonus::STATUS;
  50. $where['delete_time'] = 0;
  51. $res = $this->getLogic()->getOne($where);
  52. if(!$res)
  53. {
  54. return ReturnData::create(ReturnData::RECORD_NOT_EXIST);
  55. }
  56. return ReturnData::create(ReturnData::SUCCESS,$res);
  57. }
  58. //添加
  59. public function bonusAdd(Request $request)
  60. {
  61. if(Helper::isPostRequest())
  62. {
  63. return $this->getLogic()->add($_POST);
  64. }
  65. }
  66. //修改
  67. public function bonusUpdate(Request $request)
  68. {
  69. if(!checkIsNumber($request->input('id',null))){return ReturnData::create(ReturnData::PARAMS_ERROR);}
  70. $id = $request->input('id');
  71. if(Helper::isPostRequest())
  72. {
  73. unset($_POST['id']);
  74. $where['id'] = $id;
  75. $where['status'] = Bonus::STATUS;
  76. $where['delete_time'] = 0;
  77. //$where['user_id'] = Token::$uid;
  78. if($_POST['start_time'] >= $_POST['end_time'])
  79. {
  80. return ReturnData::create(ReturnData::PARAMS_ERROR,null,'有效期错误');
  81. }
  82. //正则验证时间格式,未作
  83. return $this->getLogic()->edit($_POST,$where);
  84. }
  85. }
  86. //删除
  87. public function bonusDelete(Request $request)
  88. {
  89. if(!checkIsNumber($request->input('id',null))){return ReturnData::create(ReturnData::PARAMS_ERROR);}
  90. $id = $request->input('id');
  91. if(Helper::isPostRequest())
  92. {
  93. $where['id'] = $id;
  94. //$where['user_id'] = Token::$uid;
  95. return $this->getLogic()->del($where);
  96. }
  97. }
  98. }