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.

113 lines
3.3 KiB

7 years ago
4 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
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\Controllers\Api;
  3. use Illuminate\Support\Facades\Log;
  4. use Illuminate\Support\Facades\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 BaseController
  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)->where('status', Bonus::STATUS)->where('start_time', '<', date('Y-m-d H:i:s'))->where('end_time', '>', date('Y-m-d H:i:s'))->where(function ($query2){$query2->where('num', '=', -1)->orWhere('num', '>', 0);});
  30. };
  31. //var_dump(model('Bonus')->where($where)->toSql());exit;
  32. $res = $this->getLogic()->getList($where, '', '*', $offset, $limit);
  33. /* if($res['count']>0)
  34. {
  35. foreach($res['list'] as $k=>$v)
  36. {
  37. }
  38. } */
  39. return ReturnData::create(ReturnData::SUCCESS, $res);
  40. }
  41. public function bonusDetail(Request $request)
  42. {
  43. //参数
  44. if(!checkIsNumber($request->input('id',null))){return ReturnData::create(ReturnData::PARAMS_ERROR);}
  45. $id = $request->input('id');
  46. $where['id'] = $id;
  47. $where['status'] = Bonus::STATUS;
  48. $where['delete_time'] = 0;
  49. $res = $this->getLogic()->getOne($where);
  50. if(!$res)
  51. {
  52. return ReturnData::create(ReturnData::RECORD_NOT_EXIST);
  53. }
  54. return ReturnData::create(ReturnData::SUCCESS,$res);
  55. }
  56. //添加
  57. public function bonusAdd(Request $request)
  58. {
  59. if(Helper::isPostRequest())
  60. {
  61. return $this->getLogic()->add($_POST);
  62. }
  63. }
  64. //修改
  65. public function bonusUpdate(Request $request)
  66. {
  67. if(!checkIsNumber($request->input('id',null))){return ReturnData::create(ReturnData::PARAMS_ERROR);}
  68. $id = $request->input('id');
  69. if(Helper::isPostRequest())
  70. {
  71. unset($_POST['id']);
  72. $where['id'] = $id;
  73. $where['status'] = Bonus::STATUS;
  74. $where['delete_time'] = 0;
  75. //$where['user_id'] = Token::$uid;
  76. if($_POST['start_time'] >= $_POST['end_time'])
  77. {
  78. return ReturnData::create(ReturnData::PARAMS_ERROR,null,'有效期错误');
  79. }
  80. //正则验证时间格式,未作
  81. return $this->getLogic()->edit($_POST,$where);
  82. }
  83. }
  84. //删除
  85. public function bonusDelete(Request $request)
  86. {
  87. if(!checkIsNumber($request->input('id',null))){return ReturnData::create(ReturnData::PARAMS_ERROR);}
  88. $id = $request->input('id');
  89. if(Helper::isPostRequest())
  90. {
  91. $where['id'] = $id;
  92. //$where['user_id'] = Token::$uid;
  93. return $this->getLogic()->del($where);
  94. }
  95. }
  96. }