Pointmallvoucher.php 6.4 KB

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