Membervoucher.php 4.5 KB

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