123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- <?php
- namespace app\api\controller;
- use think\facade\Lang;
- /**
-
- *
-
- *
- * ----------------------------------------------------------------------------
- *
-
- * 代金券控制器
- */
- class Membervoucher extends MobileMember
- {
- public function initialize()
- {
- parent::initialize(); // TODO: Change the autogenerated stub
- Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/voucher.lang.php');
- }
- /**
- * @api {POST} api/Membervoucher/voucher_list 代金卷列表
- * @apiVersion 1.0.0
- * @apiGroup MemberVoucher
- *
- * @apiHeader {String} X-DS-KEY 用户授权token
- *
- * @apiSuccess {String} code 返回码,10000为成功
- * @apiSuccess {String} message 返回消息
- * @apiSuccess {Object} result 返回数据
- * @apiSuccess {Object[]} result.voucher_list 代金卷列表 (返回字段参考voucher表、store表、vouchertemplate表)
- * @apiSuccess {Int} result.page_total 总页数
- * @apiSuccess {Boolean} result.hasmore 是否有更多 true是false否
- */
- public function voucher_list()
- {
- $voucher_model = model('voucher');
- $voucher_state = !empty(input('post.voucher_state')) ? input('post.voucher_state') : '';
- $voucher_list = $voucher_model->getMemberVoucherList($this->member_info['member_id'], $voucher_state, $this->pagesize);
- $result = array_merge(array('voucher_list' => $voucher_list), mobile_page($voucher_model->page_info));
- ds_json_encode(10000, '', $result);
- }
- /**
- * @api {POST} api/Membervoucher/voucher_private 私密代金券
- * @apiVersion 1.0.0
- * @apiGroup MemberVoucher
- *
- * @apiHeader {String} X-DS-KEY 用户授权token
- *
- * @apiSuccess {String} code 返回码,10000为成功
- * @apiSuccess {String} message 返回消息
- * @apiSuccess {Object} result 返回数据
- * @apiSuccess {Object[]} result.voucher_private 代金卷列表 (返回字段参考voucher表、store表、vouchertemplate表)
- * @apiSuccess {Int} result.page_total 总页数
- * @apiSuccess {Boolean} result.hasmore 是否有更多 true是false否
- */
- public function voucher_private()
- {
- $voucher_model = model('voucher');
- $condition = array();
- $condition[] = array('vouchertemplate_id', '=', input('post.vouchertemplate_id'));
- $condition[] = array('vouchertemplate_if_private', '=', 1);
- $vouchertemplate_info = $voucher_model->getVouchertemplateInfo($condition);
- if (!empty($vouchertemplate_info)) {
- $vouchertemplate_info['vouchertemplate_startdate'] = date('Y.m.d', $vouchertemplate_info['vouchertemplate_startdate']);
- $vouchertemplate_info['vouchertemplate_enddate'] = date('Y.m.d', $vouchertemplate_info['vouchertemplate_enddate']);
- $result['vouchertemplate_info'] = $vouchertemplate_info;
- ds_json_encode(10000, '', $result);
- } else {
- ds_json_encode(10001, lang('param_error'));
- }
- }
- /**
- * @api {POST} api/Membervoucher/voucher_point 代金券领取
- * @apiVersion 1.0.0
- * @apiGroup MemberVoucher
- *
- * @apiHeader {String} X-DS-KEY 用户授权token
- *
- * @apiParam {String} tid 代金券模板id
- *
- * @apiSuccess {String} code 返回码,10000为成功
- * @apiSuccess {String} message 返回消息
- * @apiSuccess {Object} result 返回数据
- */
- public function voucher_point()
- {
- $vid = intval(input('post.tid'));
- if ($vid <= 0) {
- ds_json_encode(10001, lang('param_error'));
- }
- $voucher_model = model('voucher');
- //验证是否可以兑换代金券
- $data = $voucher_model->getCanChangeTemplateInfo($vid, $this->member_info['member_id'], $this->member_info['store_id']);
- if ($data['state'] == false) {
- ds_json_encode(10001, $data['msg']);
- }
- //添加代金券信息
- $data = $voucher_model->exchangeVoucher($data['info'], $this->member_info['member_id'], $this->member_info['member_name']);
- if ($data['state'] == true) {
- ds_json_encode(10000, $data['msg'], 1);
- } else {
- ds_json_encode(10001, $data['msg']);
- }
- }
- }
|