Membervoucher.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Lang;
  4. /**
  5. *
  6. *
  7. * ----------------------------------------------------------------------------
  8. *
  9. * 代金券控制器
  10. */
  11. class Membervoucher extends MobileMember
  12. {
  13. public function initialize()
  14. {
  15. parent::initialize(); // TODO: Change the autogenerated stub
  16. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/voucher.lang.php');
  17. }
  18. /**
  19. * @api {POST} api/Membervoucher/voucher_list 代金卷列表
  20. * @apiVersion 1.0.0
  21. * @apiGroup MemberVoucher
  22. *
  23. * @apiHeader {String} X-DS-KEY 用户授权token
  24. *
  25. * @apiSuccess {String} code 返回码,10000为成功
  26. * @apiSuccess {String} message 返回消息
  27. * @apiSuccess {Object} result 返回数据
  28. * @apiSuccess {Object[]} result.voucher_list 代金卷列表 (返回字段参考voucher表、store表、vouchertemplate表)
  29. * @apiSuccess {Int} result.page_total 总页数
  30. * @apiSuccess {Boolean} result.hasmore 是否有更多 true是false否
  31. */
  32. public function voucher_list()
  33. {
  34. $voucher_model = model('voucher');
  35. $voucher_state = !empty(input('post.voucher_state')) ? input('post.voucher_state') : '';
  36. $voucher_list = $voucher_model->getMemberVoucherList($this->member_info['member_id'], $voucher_state, $this->pagesize);
  37. $result = array_merge(array('voucher_list' => $voucher_list), mobile_page($voucher_model->page_info));
  38. ds_json_encode(10000, '', $result);
  39. }
  40. /**
  41. * @api {POST} api/Membervoucher/voucher_private 私密代金券
  42. * @apiVersion 1.0.0
  43. * @apiGroup MemberVoucher
  44. *
  45. * @apiHeader {String} X-DS-KEY 用户授权token
  46. *
  47. * @apiSuccess {String} code 返回码,10000为成功
  48. * @apiSuccess {String} message 返回消息
  49. * @apiSuccess {Object} result 返回数据
  50. * @apiSuccess {Object[]} result.voucher_private 代金卷列表 (返回字段参考voucher表、store表、vouchertemplate表)
  51. * @apiSuccess {Int} result.page_total 总页数
  52. * @apiSuccess {Boolean} result.hasmore 是否有更多 true是false否
  53. */
  54. public function voucher_private()
  55. {
  56. $voucher_model = model('voucher');
  57. $condition = array();
  58. $condition[] = array('vouchertemplate_id', '=', input('post.vouchertemplate_id'));
  59. $condition[] = array('vouchertemplate_if_private', '=', 1);
  60. $vouchertemplate_info = $voucher_model->getVouchertemplateInfo($condition);
  61. if (!empty($vouchertemplate_info)) {
  62. $vouchertemplate_info['vouchertemplate_startdate'] = date('Y.m.d', $vouchertemplate_info['vouchertemplate_startdate']);
  63. $vouchertemplate_info['vouchertemplate_enddate'] = date('Y.m.d', $vouchertemplate_info['vouchertemplate_enddate']);
  64. $result['vouchertemplate_info'] = $vouchertemplate_info;
  65. ds_json_encode(10000, '', $result);
  66. } else {
  67. ds_json_encode(10001, lang('param_error'));
  68. }
  69. }
  70. /**
  71. * @api {POST} api/Membervoucher/voucher_point 代金券领取
  72. * @apiVersion 1.0.0
  73. * @apiGroup MemberVoucher
  74. *
  75. * @apiHeader {String} X-DS-KEY 用户授权token
  76. *
  77. * @apiParam {String} tid 代金券模板id
  78. *
  79. * @apiSuccess {String} code 返回码,10000为成功
  80. * @apiSuccess {String} message 返回消息
  81. * @apiSuccess {Object} result 返回数据
  82. */
  83. public function voucher_point()
  84. {
  85. $vid = intval(input('post.tid'));
  86. if ($vid <= 0) {
  87. ds_json_encode(10001, lang('param_error'));
  88. }
  89. $voucher_model = model('voucher');
  90. //验证是否可以兑换代金券
  91. $data = $voucher_model->getCanChangeTemplateInfo($vid, $this->member_info['member_id'], $this->member_info['store_id']);
  92. if ($data['state'] == false) {
  93. ds_json_encode(10001, $data['msg']);
  94. }
  95. //添加代金券信息
  96. $data = $voucher_model->exchangeVoucher($data['info'], $this->member_info['member_id'], $this->member_info['member_name']);
  97. if ($data['state'] == true) {
  98. ds_json_encode(10000, $data['msg'], 1);
  99. } else {
  100. ds_json_encode(10001, $data['msg']);
  101. }
  102. }
  103. }