123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- <?php
- namespace app\api\controller;
- use think\facade\Db;
- use think\facade\Lang;
- /**
-
- *
-
- *
- * ----------------------------------------------------------------------------
- *
-
- * 领取红包控制器
- */
- class Memberbonus extends MobileMember
- {
- public function initialize()
- {
- parent::initialize();
- Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/memberbonus.lang.php');
- }
- /**
- * @api {POST} api/Memberbonus/get_receive_list 红包记录
- * @apiVersion 1.0.0
- * @apiGroup Memberbonus
- *
- * @apiHeader {String} X-DS-KEY 用户授权token
- *
- * @apiSuccess {String} code 返回码,10000为成功
- * @apiSuccess {String} message 返回消息
- * @apiSuccess {Object} result 返回数据
- */
- public function get_receive_list()
- {
- $bonus_model = model('bonus');
- $bonuslog_list = $bonus_model->getBonusreceiveList(array('member_id' => $this->member_info['member_id']), $this->pagesize);
- $result = array_merge(array('log_list' => $bonuslog_list), mobile_page($bonus_model->page_info));
- ds_json_encode(10000, '', $result);
- }
- /**
- * @api {POST} api/Memberbonus/receive 活动红包领取
- * @apiVersion 1.0.0
- * @apiGroup Memberbonus
- *
- * @apiHeader {String} X-DS-KEY 用户授权token
- *
- * @apiParam {Int} bonus_id 活动ID
- *
- * @apiSuccess {String} code 返回码,10000为成功
- * @apiSuccess {String} message 返回消息
- * @apiSuccess {Object} result 返回数据
- */
- public function receive()
- {
- $bonus_id = intval(input('param.bonus_id'));
- if ($bonus_id < 0) {
- ds_json_encode(10001, lang('param_error'));
- }
- $bonus_model = model('bonus');
- $condition = array();
- $condition[] = array('bonus_id', '=', $bonus_id);
- $bonus = $bonus_model->getOneBonus($condition); //获取当前红包的领取金额
- if ($bonus['bonus_begintime'] > TIMESTAMP) {
- ds_json_encode(10001, lang('bonus_not_begin'));
- }
- if ($bonus['bonus_type'] != 1) {
- ds_json_encode(10001, lang('bonus_type_error'));
- }
- if ($bonus['bonus_state'] == 2 || TIMESTAMP > $bonus['bonus_endtime']) {
- ds_json_encode(10001, lang('bonus_expire'));
- }
- if ($bonus['bonus_state'] == 3) {
- ds_json_encode(10001, lang('bonus_invalid'));
- }
- //判断当前用户是否领取过
- $condition = array();
- $condition[] = array('bonus_id', '=', $bonus_id);
- $condition[] = array('member_id', '=', $this->member_info['member_id']);
- $bonusreceive = $bonus_model->getOneBonusreceive($condition);
- if ($bonusreceive) {
- ds_json_encode(10001, sprintf(lang('bonusreceive_info'), date('Y-m-d H:i:s', $bonusreceive['bonusreceive_time']), $bonusreceive['bonusreceive_price']));
- }
- //获取未领取单个红包
- $condition = array();
- $condition[] = array('bonus_id', '=', $bonus_id);
- $condition[] = array('member_id', '=', 0);
- $bonusreceive = $bonus_model->getOneBonusreceive($condition);
- if (empty($bonusreceive)) {
- ds_json_encode(10001, lang('bonus_send_over'));
- }
- try {
- Db::startTrans();
- $res = $bonus_model->receiveBonus($this->member_info, $bonus, $bonusreceive, lang('receive_bonus'));
- if (!$res['code']) {
- throw new \think\Exception($res['msg'], 10006);
- }
- Db::commit();
- ds_json_encode(10000, sprintf(lang('get_bonus_info'), $bonusreceive['bonusreceive_price']));
- } catch (Exception $e) {
- Db::rollback();
- ds_json_encode(10001, $e->getMessage());
- }
- }
- }
|