Pointmallvoucher.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. * ============================================================================
  7. * DSMall多用户商城
  8. * ============================================================================
  9. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  10. * 网站地址: http://www.csdeshang.com
  11. * ----------------------------------------------------------------------------
  12. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  13. * 不允许对程序代码以任何形式任何目的的再发布。
  14. * ============================================================================
  15. * 控制器
  16. */
  17. class Pointmallvoucher extends BasePointShop
  18. {
  19. public function initialize()
  20. {
  21. parent::initialize(); // TODO: Change the autogenerated stub
  22. Lang::load(base_path().'home/lang/'.config('lang.default_lang').'/voucher.lang.php');
  23. if (config('ds_config.voucher_allow') != 1){
  24. $this->error(lang('voucher_pointunavailable'),HOME_SITE_URL);
  25. }
  26. }
  27. public function index(){
  28. $this->pointmallvoucher();
  29. return View::fetch($this->template_dir.'pointmallvoucher');
  30. }
  31. /**
  32. * 平台代金券列表
  33. */
  34. public function pointmallvoucher(){
  35. //查询会员及其附属信息
  36. parent::pointshopMInfo();
  37. $mallvouchertemplate_model = model('mallvouchertemplate');
  38. //查询会员信息
  39. $member_info = model('member')->getMemberInfoByID(session('member_id'));
  40. //查询代金券列表
  41. $where = array();
  42. $where[]=array('mallvouchertemplate_startdate','<',TIMESTAMP);
  43. $where[]=array('mallvouchertemplate_enddate','>',TIMESTAMP);
  44. $gc_id = intval(input('gc_id'));
  45. if ($gc_id > 0){
  46. $gc_idarr = array();
  47. $goodsclasslist = model('goodsclass')->getChildClass($gc_id);
  48. foreach($goodsclasslist as $k => $v){
  49. $gc_idarr[] = $v['gc_id'];
  50. }
  51. $gccondition = implode(',',$gc_idarr);
  52. $where[]=array('mallvouchertemplate_gcid','in',$gccondition);
  53. }
  54. if (intval(input('price')) > 0){
  55. $where[]=array('mallvouchertemplate_price','=',intval(input('price')));
  56. }
  57. //查询仅我能兑换和所需积分
  58. $points_filter = array();
  59. if (intval(input('isable')) == 1){
  60. $points_filter['isable'] = $member_info['member_points'];
  61. }
  62. if (intval(input('points_min')) > 0){
  63. $points_filter['min'] = intval(input('points_min'));
  64. }
  65. if (intval(input('points_max')) > 0){
  66. $points_filter['max'] = intval(input('points_max'));
  67. }
  68. if (count($points_filter) > 0){
  69. asort($points_filter);
  70. if (count($points_filter) > 1){
  71. $points_filter = array_values($points_filter);
  72. $where[] = array('mallvouchertemplate_points','between',array($points_filter[0],$points_filter[1]));
  73. } else {
  74. if (isset($points_filter['min'])){
  75. $where[]=array('mallvouchertemplate_points','>=',$points_filter['min']);
  76. } elseif (isset($points_filter['max'])) {
  77. $where[]=array('mallvouchertemplate_points','<=',$points_filter['max']);
  78. } elseif (isset($points_filter['isable'])) {
  79. $where[]=array('mallvouchertemplate_points','<=',$points_filter['isable']);
  80. }
  81. }
  82. }
  83. //排序
  84. switch (input('orderby')){
  85. case 'pointsdesc':
  86. $orderby = 'mallvouchertemplate_points desc,';
  87. break;
  88. case 'pointsasc':
  89. $orderby = 'mallvouchertemplate_points asc,';
  90. break;
  91. default:
  92. $orderby = '';
  93. }
  94. $orderby .= 'mallvouchertemplate_id desc';
  95. $mallvoucherlist = $mallvouchertemplate_model->getMallvouchertemplateList($where, 10, $orderby);
  96. View::assign('mallvoucherlist',$mallvoucherlist);
  97. View::assign('show_page', $mallvouchertemplate_model->page_info->render());
  98. //查询平台分类
  99. $gc_list = model('goodsclass')->getGoodsclassListByParentId(0);
  100. View::assign('gc_list', $gc_list);
  101. //分类导航
  102. $nav_link = array(
  103. 0=>array('title'=>lang('homepage'),'link'=>HOME_SITE_URL),
  104. 1=>array('title'=> lang('integral_center'),'link'=>(string)url('Pointshop/index')),
  105. 2=>array('title'=> lang('mall_voucher'))
  106. );
  107. View::assign('nav_link_list', $nav_link);
  108. }
  109. /**
  110. * 兑换代金券
  111. */
  112. public function mallvoucherexchange(){
  113. $vid = intval(input('param.vid'));
  114. $result = true;
  115. $message = "";
  116. if ($vid <= 0){
  117. $result = false;
  118. }
  119. if ($result){
  120. //查询可兑换代金券模板信息
  121. $template_info = model('mallvouchertemplate')->getCanChangeTemplateInfo($vid,intval(session('member_id')));
  122. if ($template_info['state'] == false){
  123. $result = false;
  124. $message = $template_info['msg'];
  125. }else {
  126. //查询会员信息
  127. $member_info = model('member')->getMemberInfoByID(session('member_id'));
  128. View::assign('member_info',$member_info);
  129. View::assign('template_info',$template_info['info']);
  130. }
  131. }
  132. View::assign('message',$message);
  133. View::assign('result',$result);
  134. echo View::fetch($this->template_dir.'exchange');exit;
  135. }
  136. /**
  137. * 兑换代金券保存信息
  138. *
  139. */
  140. public function mallvoucherexchange_save(){
  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. }