Pointvoucher.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 Pointvoucher extends MobileMall
  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. if (config('ds_config.points_isuse') != 1 || config('ds_config.pointprod_isuse') != 1) {
  23. ds_json_encode(10001, lang('pointshop_unavailable'));
  24. }
  25. if (config('ds_config.voucher_allow') != 1){
  26. ds_json_encode(10001,lang('voucher_pointunavailable'));
  27. }
  28. }
  29. public function index(){
  30. $this->pointvoucher();
  31. }
  32. /**
  33. * 代金券列表
  34. */
  35. public function pointvoucher(){
  36. $voucher_model = model('voucher');
  37. //代金券模板状态
  38. $templatestate_arr = $voucher_model->getTemplateState();
  39. //查询会员信息
  40. $member_info = model('member')->getMemberInfoByID(session('member_id'));
  41. //查询代金券列表
  42. $where = array();
  43. $where[]=array('vouchertemplate_if_private','=',0);
  44. $where[]=array('vouchertemplate_state','=',$templatestate_arr['usable'][0]);
  45. $where[]=array('vouchertemplate_enddate','>',TIMESTAMP);
  46. if (intval(input('storeclass_id')) > 0){
  47. $where[]=array('vouchertemplate_sc_id','=',intval(input('storeclass_id')));
  48. }
  49. if (intval(input('price')) > 0){
  50. $where[]=array('vouchertemplate_price','=',intval(input('price')));
  51. }
  52. //查询仅我能兑换和所需积分
  53. $points_filter = array();
  54. if (intval(input('isable')) == 1){
  55. $points_filter['isable'] = $member_info['member_points'];
  56. }
  57. if (intval(input('points_min')) > 0){
  58. $points_filter['min'] = intval(input('points_min'));
  59. }
  60. if (intval(input('points_max')) > 0){
  61. $points_filter['max'] = intval(input('points_max'));
  62. }
  63. if (count($points_filter) > 0){
  64. asort($points_filter);
  65. if (count($points_filter) > 1){
  66. $points_filter = array_values($points_filter);
  67. $where[] = array('vouchertemplate_points','between',array($points_filter[0],$points_filter[1]));
  68. } else {
  69. if ($points_filter['min']){
  70. $where[]=array('vouchertemplate_points','>=',$points_filter['min']);
  71. } elseif ($points_filter['max']) {
  72. $where[]=array('vouchertemplate_points','<=',$points_filter['max']);
  73. } elseif ($points_filter['isable']) {
  74. $where[]=array('vouchertemplate_points','<=',$points_filter['isable']);
  75. }
  76. }
  77. }
  78. //排序
  79. switch (input('orderby')){
  80. case 'exchangenumdesc':
  81. $orderby = 'vouchertemplate_giveout desc,';
  82. break;
  83. case 'exchangenumasc':
  84. $orderby = 'vouchertemplate_giveout asc,';
  85. break;
  86. case 'pointsdesc':
  87. $orderby = 'vouchertemplate_points desc,';
  88. break;
  89. case 'pointsasc':
  90. $orderby = 'vouchertemplate_points asc,';
  91. break;
  92. default:
  93. $orderby = '';
  94. }
  95. $orderby .= 'vouchertemplate_id desc';
  96. $voucherlist = $voucher_model->getVouchertemplateList($where, '*', 0, 18, $orderby);
  97. $page_count = $voucher_model->page_info;
  98. //查询代金券面额
  99. $pricelist = $voucher_model->getVoucherPriceList();
  100. //查询店铺分类
  101. $store_class = rkcache('storeclass', true);
  102. $result = array_merge(array('voucherlist' => $voucherlist, 'pricelist' => $pricelist, 'store_class' => $store_class), mobile_page($page_count));
  103. ds_json_encode(10000, '', $result);
  104. }
  105. /**
  106. * 兑换代金券保存信息
  107. *
  108. */
  109. public function voucherexchange_save(){
  110. $member_id = $this->getMemberIdIfExists();
  111. if(!$member_id){
  112. ds_json_encode(10001,lang('param_error'));
  113. }
  114. $vid = intval(input('post.vid'));
  115. if ($vid <= 0){
  116. ds_json_encode(10001,lang('param_error'));
  117. }
  118. $seller_model = model('seller');
  119. $seller_info = $seller_model->getSellerInfo(array('member_id' => $member_id));
  120. $voucher_model = model('voucher');
  121. //验证是否可以兑换代金券
  122. $data = $voucher_model->getCanChangeTemplateInfo($vid,intval($member_id),$seller_info['store_id']);
  123. if ($data['state'] == false){
  124. ds_json_encode(10001,$data['msg']);
  125. }
  126. //添加代金券信息
  127. $data = $voucher_model->exchangeVoucher($data['info'],$member_id);
  128. if ($data['state'] == true){
  129. ds_json_encode(10000,$data['msg']);
  130. } else {
  131. ds_json_encode(10001,$data['msg']);
  132. }
  133. }
  134. }