pointvoucher.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <?php
  2. /**
  3. * 代金券
  4. ***/
  5. defined('InShopNC') or exit('Access Invalid!');
  6. class pointvoucherControl extends BasePointShopControl {
  7. public function __construct() {
  8. parent::__construct();
  9. //读取语言包
  10. Language::read('home_voucher');
  11. //判断系统是否开启代金券功能
  12. if (C('voucher_allow') != 1){
  13. showDialog(L('voucher_pointunavailable'),'index.php','error');
  14. }
  15. }
  16. public function indexOp(){
  17. $this->pointvoucherOp();
  18. }
  19. /**
  20. * 代金券列表
  21. */
  22. public function pointvoucherOp(){
  23. //查询会员及其附属信息
  24. parent::pointshopMInfo();
  25. $model_voucher = Model('voucher');
  26. //代金券模板状态
  27. $templatestate_arr = $model_voucher->getTemplateState();
  28. //查询会员信息
  29. $member_info = Model('member')->getMemberInfoByID($_SESSION['member_id']);
  30. //查询代金券列表
  31. $where = array();
  32. $where['voucher_t_state'] = $templatestate_arr['usable'][0];
  33. $where['voucher_t_end_date'] = array('gt',time());
  34. if (intval($_GET['sc_id']) > 0){
  35. $where['voucher_t_sc_id'] = intval($_GET['sc_id']);
  36. }
  37. if (intval($_GET['price']) > 0){
  38. $where['voucher_t_price'] = intval($_GET['price']);
  39. }
  40. //查询仅我能兑换和所需积分
  41. $points_filter = array();
  42. if (intval($_GET['isable']) == 1){
  43. $points_filter['isable'] = $member_info['member_points'];
  44. }
  45. if (intval($_GET['points_min']) > 0){
  46. $points_filter['min'] = intval($_GET['points_min']);
  47. }
  48. if (intval($_GET['points_max']) > 0){
  49. $points_filter['max'] = intval($_GET['points_max']);
  50. }
  51. if (count($points_filter) > 0){
  52. asort($points_filter);
  53. if (count($points_filter) > 1){
  54. $points_filter = array_values($points_filter);
  55. $where['voucher_t_points'] = array('between',array($points_filter[0],$points_filter[1]));
  56. } else {
  57. if ($points_filter['min']){
  58. $where['voucher_t_points'] = array('egt',$points_filter['min']);
  59. } elseif ($points_filter['max']) {
  60. $where['voucher_t_points'] = array('elt',$points_filter['max']);
  61. } elseif ($points_filter['isable']) {
  62. $where['voucher_t_points'] = array('elt',$points_filter['isable']);
  63. }
  64. }
  65. }
  66. //排序
  67. switch ($_GET['orderby']){
  68. case 'exchangenumdesc':
  69. $orderby = 'voucher_t_giveout desc,';
  70. break;
  71. case 'exchangenumasc':
  72. $orderby = 'voucher_t_giveout asc,';
  73. break;
  74. case 'pointsdesc':
  75. $orderby = 'voucher_t_points desc,';
  76. break;
  77. case 'pointsasc':
  78. $orderby = 'voucher_t_points asc,';
  79. break;
  80. }
  81. $orderby .= 'voucher_t_id desc';
  82. $voucherlist = $model_voucher->getVoucherTemplateList($where, '*', 0, 18, $orderby);
  83. Tpl::output('voucherlist',$voucherlist);
  84. Tpl::output('show_page', $model_voucher->showpage(2));
  85. //查询代金券面额
  86. $pricelist = $model_voucher->getVoucherPriceList();
  87. Tpl::output('pricelist',$pricelist);
  88. //查询店铺分类
  89. $store_class = rkcache('store_class', true);
  90. Tpl::output('store_class', $store_class);
  91. //分类导航
  92. $nav_link = array(
  93. 0=>array('title'=>Language::get('homepage'),'link'=>SHOP_SITE_URL),
  94. 1=>array('title'=>'积分中心','link'=>urlShop('pointshop','index')),
  95. 2=>array('title'=>'代金券列表')
  96. );
  97. Tpl::output('nav_link_list', $nav_link);
  98. Tpl::showpage('pointvoucher');
  99. }
  100. /**
  101. * 兑换代金券
  102. */
  103. public function voucherexchangeOp(){
  104. $vid = intval($_GET['vid']);
  105. if($vid <= 0){
  106. $vid = intval($_POST['vid']);
  107. }
  108. if($_SESSION['is_login'] != '1'){
  109. $js = "login_dialog();";
  110. showDialog('','','js',$js);
  111. }elseif ($_GET['dialog']){
  112. $js = "CUR_DIALOG = ajax_form('vexchange', '".L('home_voucher_exchangtitle')."', 'index.php?act=pointvoucher&op=voucherexchange&vid={$vid}', 550);";
  113. showDialog('','','js',$js);
  114. die;
  115. }
  116. $result = true;
  117. $message = "";
  118. if ($vid <= 0){
  119. $result = false;
  120. L('wrong_argument');
  121. }
  122. if ($result){
  123. //查询可兑换代金券模板信息
  124. $template_info = Model('voucher')->getCanChangeTemplateInfo($vid,intval($_SESSION['member_id']),intval($_SESSION['store_id']));
  125. if ($template_info['state'] == false){
  126. $result = false;
  127. $message = $template_info['msg'];
  128. }else {
  129. //查询会员信息
  130. $member_info = Model('member')->getMemberInfoByID($_SESSION['member_id'],'member_points');
  131. Tpl::output('member_info',$member_info);
  132. Tpl::output('template_info',$template_info['info']);
  133. }
  134. }
  135. Tpl::output('message',$message);
  136. Tpl::output('result',$result);
  137. Tpl::showpage('pointvoucher.exchange','null_layout');
  138. }
  139. /**
  140. * 兑换代金券保存信息
  141. *
  142. */
  143. public function voucherexchange_saveOp(){
  144. if($_SESSION['is_login'] != '1'){
  145. $js = "login_dialog();";
  146. showDialog('','','js',$js);
  147. }
  148. $vid = intval($_POST['vid']);
  149. $js = "DialogManager.close('vexchange');";
  150. if ($vid <= 0){
  151. showDialog(L('wrong_argument'),'','error',$js);
  152. }
  153. $model_voucher = Model('voucher');
  154. //验证是否可以兑换代金券
  155. $data = $model_voucher->getCanChangeTemplateInfo($vid,intval($_SESSION['member_id']),intval($_SESSION['store_id']));
  156. if ($data['state'] == false){
  157. showDialog($data['msg'],'','error',$js);
  158. }
  159. //添加代金券信息
  160. $data = $model_voucher->exchangeVoucher($data['info'],$_SESSION['member_id'],$_SESSION['member_name']);
  161. if ($data['state'] == true){
  162. showDialog($data['msg'],'','succ',$js);
  163. } else {
  164. showDialog($data['msg'],'','error',$js);
  165. }
  166. }
  167. }