Bonus.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Lang;
  4. /**
  5. * 红包控制器
  6. */
  7. class Bonus extends MobileMall
  8. {
  9. public function initialize()
  10. {
  11. parent::initialize();
  12. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/bonus.lang.php');
  13. }
  14. /**
  15. * @api {POST} api/Bonus/detail 活动红包详情
  16. * @apiVersion 1.0.0
  17. * @apiGroup Memberbonus
  18. *
  19. * @apiHeader {String} X-DS-KEY 用户授权token
  20. *
  21. * @apiParam {Int} bonus_id 活动ID
  22. *
  23. * @apiSuccess {String} code 返回码,10000为成功
  24. * @apiSuccess {String} message 返回消息
  25. * @apiSuccess {Object} result 返回数据
  26. */
  27. public function detail()
  28. {
  29. $bonus_id = intval(input('param.bonus_id'));
  30. if ($bonus_id <= 0) {
  31. ds_json_encode(10001, lang('param_error'));
  32. }
  33. $bonus_model = model('bonus');
  34. $condition = array();
  35. $condition[] = array('bonus_id', '=', $bonus_id);
  36. $condition[] = array('bonus_type', '=', 1);
  37. $condition[] = array('bonus_state', '=', 1);
  38. $condition[] = array('bonus_begintime', '<', TIMESTAMP);
  39. $condition[] = array('bonus_endtime', '>', TIMESTAMP);
  40. $bonus = $bonus_model->getOneBonus($condition);
  41. if (!$bonus) {
  42. ds_json_encode(10001, lang('bonus_not_exist'));
  43. }
  44. $bonus['bonus_begintime_text'] = date('Y-m-d H:i:s', $bonus['bonus_begintime']);
  45. $bonus['bonus_endtime_text'] = date('Y-m-d H:i:s', $bonus['bonus_endtime']);
  46. $result['bonus'] = $bonus;
  47. //获取最近10条领取记录
  48. $condition = array();
  49. $condition[] = array('bonus_id', '=', $bonus_id);
  50. $condition[] = array('member_id', '>', 0);
  51. $result['bonusreceive_list'] = $bonus_model->getBonusreceiveList($condition, '', 10);
  52. ds_json_encode(10000, '', $result);
  53. }
  54. }