Pointmallvoucher.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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 Pointmallvoucher 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->pointmallvoucher();
  28. return View::fetch($this->template_dir.'pointmallvoucher');
  29. }
  30. /**
  31. * 平台代金券列表
  32. */
  33. public function pointmallvoucher(){
  34. //查询会员及其附属信息
  35. parent::pointshopMInfo();
  36. $mallvouchertemplate_model = model('mallvouchertemplate');
  37. //查询会员信息
  38. $member_info = model('member')->getMemberInfoByID(session('member_id'));
  39. //查询代金券列表
  40. $where = array();
  41. $where[]=array('mallvouchertemplate_startdate','<',TIMESTAMP);
  42. $where[]=array('mallvouchertemplate_enddate','>',TIMESTAMP);
  43. $gc_id = intval(input('gc_id'));
  44. if ($gc_id > 0){
  45. $gc_idarr = array();
  46. $goodsclasslist = model('goodsclass')->getChildClass($gc_id);
  47. foreach($goodsclasslist as $k => $v){
  48. $gc_idarr[] = $v['gc_id'];
  49. }
  50. $gccondition = implode(',',$gc_idarr);
  51. $where[]=array('mallvouchertemplate_gcid','in',$gccondition);
  52. }
  53. if (intval(input('price')) > 0){
  54. $where[]=array('mallvouchertemplate_price','=',intval(input('price')));
  55. }
  56. //查询仅我能兑换和所需积分
  57. $points_filter = array();
  58. if (intval(input('isable')) == 1){
  59. $points_filter['isable'] = $member_info['member_points'];
  60. }
  61. if (intval(input('points_min')) > 0){
  62. $points_filter['min'] = intval(input('points_min'));
  63. }
  64. if (intval(input('points_max')) > 0){
  65. $points_filter['max'] = intval(input('points_max'));
  66. }
  67. if (count($points_filter) > 0){
  68. asort($points_filter);
  69. if (count($points_filter) > 1){
  70. $points_filter = array_values($points_filter);
  71. $where[] = array('mallvouchertemplate_points','between',array($points_filter[0],$points_filter[1]));
  72. } else {
  73. if (isset($points_filter['min'])){
  74. $where[]=array('mallvouchertemplate_points','>=',$points_filter['min']);
  75. } elseif (isset($points_filter['max'])) {
  76. $where[]=array('mallvouchertemplate_points','<=',$points_filter['max']);
  77. } elseif (isset($points_filter['isable'])) {
  78. $where[]=array('mallvouchertemplate_points','<=',$points_filter['isable']);
  79. }
  80. }
  81. }
  82. //排序
  83. switch (input('orderby')){
  84. case 'pointsdesc':
  85. $orderby = 'mallvouchertemplate_points desc,';
  86. break;
  87. case 'pointsasc':
  88. $orderby = 'mallvouchertemplate_points asc,';
  89. break;
  90. default:
  91. $orderby = '';
  92. }
  93. $orderby .= 'mallvouchertemplate_id desc';
  94. $mallvoucherlist = $mallvouchertemplate_model->getMallvouchertemplateList($where, 10, $orderby);
  95. View::assign('mallvoucherlist',$mallvoucherlist);
  96. View::assign('show_page', $mallvouchertemplate_model->page_info->render());
  97. //查询平台分类
  98. $gc_list = model('goodsclass')->getGoodsclassListByParentId(0);
  99. View::assign('gc_list', $gc_list);
  100. //分类导航
  101. $nav_link = array(
  102. 0=>array('title'=>lang('homepage'),'link'=>HOME_SITE_URL),
  103. 1=>array('title'=> lang('integral_center'),'link'=>(string)url('Pointshop/index')),
  104. 2=>array('title'=> lang('mall_voucher'))
  105. );
  106. View::assign('nav_link_list', $nav_link);
  107. }
  108. /**
  109. * 兑换代金券
  110. */
  111. public function mallvoucherexchange(){
  112. $vid = intval(input('param.vid'));
  113. $result = true;
  114. $message = "";
  115. if ($vid <= 0){
  116. $result = false;
  117. }
  118. if ($result){
  119. //查询可兑换代金券模板信息
  120. $template_info = model('mallvouchertemplate')->getCanChangeTemplateInfo($vid,intval(session('member_id')));
  121. if ($template_info['state'] == false){
  122. $result = false;
  123. $message = $template_info['msg'];
  124. }else {
  125. //查询会员信息
  126. $member_info = model('member')->getMemberInfoByID(session('member_id'));
  127. View::assign('member_info',$member_info);
  128. View::assign('template_info',$template_info['info']);
  129. }
  130. }
  131. View::assign('message',$message);
  132. View::assign('result',$result);
  133. echo View::fetch($this->template_dir.'exchange');exit;
  134. }
  135. /**
  136. * 兑换代金券保存信息
  137. *
  138. */
  139. public function mallvoucherexchange_save(){
  140. if(session('is_login') != '1'){
  141. ds_json_encode(10001,lang('param_error'));
  142. }
  143. $vid = intval(input('post.vid'));
  144. if ($vid <= 0){
  145. ds_json_encode(10001,lang('param_error'));
  146. }
  147. $mallvouchertemplate_model = model('mallvouchertemplate');
  148. //验证是否可以兑换代金券
  149. $data = $mallvouchertemplate_model->getCanChangeTemplateInfo($vid,intval(session('member_id')));
  150. if ($data['state'] == false){
  151. ds_json_encode(10001,$data['msg']);
  152. }
  153. //添加代金券信息
  154. $data = $mallvouchertemplate_model->exchangeMallvoucher($data['info'],session('member_id'),session('member_name'));
  155. if ($data['state'] == true){
  156. ds_json_encode(10000,$data['msg']);
  157. } else {
  158. ds_json_encode(10001,$data['msg']);
  159. }
  160. }
  161. }