Membervoucher.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. * 代金券
  4. */
  5. namespace app\home\controller;
  6. use think\facade\View;
  7. use think\facade\Lang;
  8. /**
  9. * ============================================================================
  10. *
  11. * ============================================================================
  12. *
  13. * ----------------------------------------------------------------------------
  14. *
  15. * ============================================================================
  16. * 控制器
  17. */
  18. class Membervoucher extends BaseMember
  19. {
  20. public function initialize()
  21. {
  22. parent::initialize(); // TODO: Change the autogenerated stub
  23. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/member_voucher.lang.php');
  24. //判断系统是否开启代金券功能
  25. if (intval(config('ds_config.voucher_allow')) !== 1) {
  26. $this->error(lang('voucher_unavailable'));
  27. }
  28. }
  29. /*
  30. * 显示店铺代金券模版列表
  31. */
  32. public function storevoucher()
  33. {
  34. $voucher_model = model('voucher');
  35. $voucher_list = $voucher_model->getMemberVoucherList(session('member_id'), input('param.select_detail_state'), 10);
  36. //取已经使用过并且未有voucher_order_id的代金券的订单ID
  37. $used_voucher_code = array();
  38. $voucher_order = array();
  39. if (!empty($voucher_list)) {
  40. foreach ($voucher_list as $v) {
  41. if ($v['voucher_state'] == 2 && empty($v['voucher_order_id'])) {
  42. $used_voucher_code[] = $v['voucher_code'];
  43. }
  44. }
  45. }
  46. if (!empty($used_voucher_code)) {
  47. $order_list = model('order')->getOrdercommonList(array(array('voucher_code', 'in', $used_voucher_code)), 'order_id,voucher_code');
  48. if (!empty($order_list)) {
  49. foreach ($order_list as $v) {
  50. $voucher_order[$v['voucher_code']] = $v['order_id'];
  51. $voucher_model->editVoucher(array('voucher_order_id' => $v['order_id']), array('voucher_code' => $v['voucher_code']));
  52. }
  53. }
  54. }
  55. View::assign('voucher_list', $voucher_list);
  56. View::assign('voucherstate_arr', $voucher_model->getVoucherStateArray());
  57. View::assign('show_page', $voucher_model->page_info->render());
  58. $this->setMemberCurItem('voucher_list');
  59. $this->setMemberCurMenu('member_voucher');
  60. return View::fetch($this->template_dir . 'member_voucher_list');
  61. }
  62. /*
  63. * 显示平台代金券模版列表
  64. */
  65. public function mallvoucher()
  66. {
  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. }