Memberbonus.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Db;
  4. use think\facade\Lang;
  5. /**
  6. * ============================================================================
  7. * DSMall多用户商城
  8. * ============================================================================
  9. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  10. * 网站地址: http://www.csdeshang.com
  11. * ----------------------------------------------------------------------------
  12. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  13. * 不允许对程序代码以任何形式任何目的的再发布。
  14. * ============================================================================
  15. * 领取红包控制器
  16. */
  17. class Memberbonus extends MobileMember {
  18. public function initialize() {
  19. parent::initialize();
  20. Lang::load(base_path() . 'home/lang/'.config('lang.default_lang').'/memberbonus.lang.php');
  21. }
  22. /**
  23. * @api {POST} api/Memberbonus/get_receive_list 红包记录
  24. * @apiVersion 1.0.0
  25. * @apiGroup Memberbonus
  26. *
  27. * @apiHeader {String} X-DS-KEY 用户授权token
  28. *
  29. * @apiSuccess {String} code 返回码,10000为成功
  30. * @apiSuccess {String} message 返回消息
  31. * @apiSuccess {Object} result 返回数据
  32. */
  33. public function get_receive_list() {
  34. $bonus_model=model('bonus');
  35. $bonuslog_list=$bonus_model->getBonusreceiveList(array('member_id'=>$this->member_info['member_id']),$this->pagesize);
  36. $result = array_merge(array('log_list' => $bonuslog_list), mobile_page($bonus_model->page_info));
  37. ds_json_encode(10000, '',$result);
  38. }
  39. /**
  40. * @api {POST} api/Memberbonus/receive 活动红包领取
  41. * @apiVersion 1.0.0
  42. * @apiGroup Memberbonus
  43. *
  44. * @apiHeader {String} X-DS-KEY 用户授权token
  45. *
  46. * @apiParam {Int} bonus_id 活动ID
  47. *
  48. * @apiSuccess {String} code 返回码,10000为成功
  49. * @apiSuccess {String} message 返回消息
  50. * @apiSuccess {Object} result 返回数据
  51. */
  52. public function receive() {
  53. $bonus_id = intval(input('param.bonus_id'));
  54. if ($bonus_id < 0) {
  55. ds_json_encode(10001, lang('param_error'));
  56. }
  57. $bonus_model = model('bonus');
  58. $condition = array();
  59. $condition[] = array('bonus_id','=',$bonus_id);
  60. $bonus = $bonus_model->getOneBonus($condition); //获取当前红包的领取金额
  61. if ($bonus['bonus_begintime'] > TIMESTAMP) {
  62. ds_json_encode(10001, lang('bonus_not_begin'));
  63. }
  64. if ($bonus['bonus_type'] != 1) {
  65. ds_json_encode(10001, lang('bonus_type_error'));
  66. }
  67. if ($bonus['bonus_state'] == 2 || TIMESTAMP > $bonus['bonus_endtime']) {
  68. ds_json_encode(10001, lang('bonus_expire'));
  69. }
  70. if ($bonus['bonus_state'] == 3) {
  71. ds_json_encode(10001, lang('bonus_invalid'));
  72. }
  73. //判断当前用户是否领取过
  74. $condition = array();
  75. $condition[] = array('bonus_id','=',$bonus_id);
  76. $condition[] = array('member_id','=',$this->member_info['member_id']);
  77. $bonusreceive = $bonus_model->getOneBonusreceive($condition);
  78. if ($bonusreceive) {
  79. ds_json_encode(10001, sprintf(lang('bonusreceive_info'),date('Y-m-d H:i:s', $bonusreceive['bonusreceive_time']),$bonusreceive['bonusreceive_price']));
  80. }
  81. //获取未领取单个红包
  82. $condition = array();
  83. $condition[] = array('bonus_id','=',$bonus_id);
  84. $condition[] = array('member_id','=',0);
  85. $bonusreceive = $bonus_model->getOneBonusreceive($condition);
  86. if (empty($bonusreceive)) {
  87. ds_json_encode(10001, lang('bonus_send_over'));
  88. }
  89. try {
  90. Db::startTrans();
  91. $res=$bonus_model->receiveBonus($this->member_info,$bonus,$bonusreceive,lang('receive_bonus'));
  92. if(!$res['code']){
  93. throw new \think\Exception($res['msg'], 10006);
  94. }
  95. Db::commit();
  96. ds_json_encode(10000, sprintf(lang('get_bonus_info'),$bonusreceive['bonusreceive_price']));
  97. } catch (Exception $e) {
  98. Db::rollback();
  99. ds_json_encode(10001, $e->getMessage());
  100. }
  101. }
  102. }