Membervoucher.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. /**
  3. * 代金券
  4. */
  5. namespace app\home\controller;
  6. use think\facade\View;
  7. use think\facade\Lang;
  8. /**
  9. * ============================================================================
  10. * DSMall多用户商城
  11. * ============================================================================
  12. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  13. * 网站地址: http://www.csdeshang.com
  14. * ----------------------------------------------------------------------------
  15. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  16. * 不允许对程序代码以任何形式任何目的的再发布。
  17. * ============================================================================
  18. * 控制器
  19. */
  20. class Membervoucher extends BaseMember
  21. {
  22. public function initialize()
  23. {
  24. parent::initialize(); // TODO: Change the autogenerated stub
  25. Lang::load(base_path().'home/lang/'.config('lang.default_lang').'/member_voucher.lang.php');
  26. //判断系统是否开启代金券功能
  27. if (intval(config('ds_config.voucher_allow')) !== 1){
  28. $this->error(lang('voucher_unavailable'));
  29. }
  30. }
  31. /*
  32. * 显示店铺代金券模版列表
  33. */
  34. public function storevoucher() {
  35. $voucher_model = model('voucher');
  36. $voucher_list = $voucher_model->getMemberVoucherList(session('member_id'), input('param.select_detail_state'), 10);
  37. //取已经使用过并且未有voucher_order_id的代金券的订单ID
  38. $used_voucher_code = array();
  39. $voucher_order = array();
  40. if (!empty($voucher_list)) {
  41. foreach ($voucher_list as $v) {
  42. if ($v['voucher_state'] == 2 && empty($v['voucher_order_id'])) {
  43. $used_voucher_code[] = $v['voucher_code'];
  44. }
  45. }
  46. }
  47. if (!empty($used_voucher_code)) {
  48. $order_list = model('order')->getOrdercommonList(array(array('voucher_code','in',$used_voucher_code)),'order_id,voucher_code');
  49. if (!empty($order_list)) {
  50. foreach ($order_list as $v) {
  51. $voucher_order[$v['voucher_code']] = $v['order_id'];
  52. $voucher_model->editVoucher(array('voucher_order_id'=>$v['order_id']),array('voucher_code'=>$v['voucher_code']));
  53. }
  54. }
  55. }
  56. View::assign('voucher_list', $voucher_list);
  57. View::assign('voucherstate_arr', $voucher_model->getVoucherStateArray());
  58. View::assign('show_page',$voucher_model->page_info->render()) ;
  59. $this->setMemberCurItem('voucher_list');
  60. $this->setMemberCurMenu('member_voucher');
  61. return View::fetch($this->template_dir.'member_voucher_list');
  62. }
  63. /*
  64. * 显示平台代金券模版列表
  65. */
  66. public function mallvoucher() {
  67. $mallvoucher_model = model('mallvouchertemplate');
  68. $mallvoucher_list = $mallvoucher_model->getMemberMallvoucherList(session('member_id'), input('param.select_detail_state'), 10);
  69. View::assign('mallvoucher_list', $mallvoucher_list);
  70. View::assign('mallvoucherstate_arr', $mallvoucher_model->getVoucherStateArray());
  71. View::assign('show_page',$mallvoucher_model->page_info->render()) ;
  72. $this->setMemberCurItem('mallvoucher_list');
  73. $this->setMemberCurMenu('member_mallvoucher');
  74. return View::fetch($this->template_dir.'member_mallvoucher_list');
  75. }
  76. /**
  77. * 用户中心右边,小导航
  78. *
  79. * @param string $menu_type 导航类型
  80. * @param string $menu_key 当前导航的menu_key
  81. * @param array $array 附加菜单
  82. * @return
  83. */
  84. protected function getMemberItemList()
  85. {
  86. $menu_array=array(
  87. array(
  88. 'name'=>'voucher_list','text'=>lang('ds_storevoucher'),'url'=>(string)url('Membervoucher/storevoucher')
  89. ),
  90. array(
  91. 'name'=>'mallvoucher_list','text'=>lang('ds_mallvoucher'),'url'=>(string)url('Membervoucher/mallvoucher')
  92. )
  93. );
  94. return $menu_array;
  95. }
  96. }