Pointvoucher.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. * ============================================================================
  7. *
  8. * ============================================================================
  9. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  10. * 网站地址: https://www.valimart.net/
  11. * ----------------------------------------------------------------------------
  12. *
  13. * ============================================================================
  14. * 控制器
  15. */
  16. class Pointvoucher extends BasePointShop
  17. {
  18. public function initialize()
  19. {
  20. parent::initialize(); // TODO: Change the autogenerated stub
  21. Lang::load(base_path().'home/lang/'.config('lang.default_lang').'/voucher.lang.php');
  22. if (config('ds_config.voucher_allow') != 1){
  23. $this->error(lang('voucher_pointunavailable'),HOME_SITE_URL);
  24. }
  25. }
  26. public function index(){
  27. $this->pointvoucher();
  28. return View::fetch($this->template_dir.'pointvoucher');
  29. }
  30. /**
  31. * 代金券列表
  32. */
  33. public function pointvoucher(){
  34. //查询会员及其附属信息
  35. parent::pointshopMInfo();
  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. View::assign('voucherlist',$voucherlist);
  98. View::assign('show_page', $voucher_model->page_info->render());
  99. //查询代金券面额
  100. $pricelist = $voucher_model->getVoucherPriceList();
  101. View::assign('pricelist',$pricelist);
  102. //查询店铺分类
  103. $store_class = rkcache('storeclass', true);
  104. View::assign('store_class', $store_class);
  105. //分类导航
  106. $nav_link = array(
  107. 0=>array('title'=>lang('homepage'),'link'=>HOME_SITE_URL),
  108. 1=>array('title'=> lang('integral_center'),'link'=>(string)url('Pointshop/index')),
  109. 2=>array('title'=> lang('voucher_list'))
  110. );
  111. View::assign('nav_link_list', $nav_link);
  112. }
  113. /**
  114. * 兑换代金券
  115. */
  116. public function voucherexchange(){
  117. $vid = intval(input('param.vid'));
  118. $result = true;
  119. $message = "";
  120. if ($vid <= 0){
  121. $result = false;
  122. }
  123. if ($result){
  124. //查询可兑换代金券模板信息
  125. $template_info = model('voucher')->getCanChangeTemplateInfo($vid,intval(session('member_id')),intval(session('store_id')));
  126. if ($template_info['state'] == false){
  127. $result = false;
  128. $message = $template_info['msg'];
  129. }else {
  130. //查询会员信息
  131. $member_info = model('member')->getMemberInfoByID(session('member_id'));
  132. View::assign('member_info',$member_info);
  133. View::assign('template_info',$template_info['info']);
  134. }
  135. }
  136. View::assign('message',$message);
  137. View::assign('result',$result);
  138. echo View::fetch($this->template_dir.'exchange');exit;
  139. }
  140. /**
  141. * 兑换代金券保存信息
  142. *
  143. */
  144. public function voucherexchange_save(){
  145. if(session('is_login') != '1'){
  146. ds_json_encode(10001,lang('param_error'));
  147. }
  148. $vid = intval(input('post.vid'));
  149. if ($vid <= 0){
  150. ds_json_encode(10001,lang('param_error'));
  151. }
  152. $voucher_model = model('voucher');
  153. //验证是否可以兑换代金券
  154. $data = $voucher_model->getCanChangeTemplateInfo($vid,intval(session('member_id')),intval(session('store_id')));
  155. if ($data['state'] == false){
  156. ds_json_encode(10001,$data['msg']);
  157. }
  158. //添加代金券信息
  159. $data = $voucher_model->exchangeVoucher($data['info'],session('member_id'),session('member_name'));
  160. if ($data['state'] == true){
  161. ds_json_encode(10000,$data['msg']);
  162. } else {
  163. ds_json_encode(10001,$data['msg']);
  164. }
  165. }
  166. }