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');
- }
-
- 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);
- }
-
- 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());
- }
- }
- }
|