Membervoucher.php 3.7 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. class Membervoucher extends BaseMember
  16. {
  17. public function initialize()
  18. {
  19. parent::initialize(); // TODO: Change the autogenerated stub
  20. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/member_voucher.lang.php');
  21. //判断系统是否开启代金券功能
  22. if (intval(config('ds_config.voucher_allow')) !== 1) {
  23. $this->error(lang('voucher_unavailable'));
  24. }
  25. }
  26. /*
  27. * 显示店铺代金券模版列表
  28. */
  29. public function storevoucher()
  30. {
  31. $voucher_model = model('voucher');
  32. $voucher_list = $voucher_model->getMemberVoucherList(session('member_id'), input('param.select_detail_state'), 10);
  33. //取已经使用过并且未有voucher_order_id的代金券的订单ID
  34. $used_voucher_code = array();
  35. $voucher_order = array();
  36. if (!empty($voucher_list)) {
  37. foreach ($voucher_list as $v) {
  38. if ($v['voucher_state'] == 2 && empty($v['voucher_order_id'])) {
  39. $used_voucher_code[] = $v['voucher_code'];
  40. }
  41. }
  42. }
  43. if (!empty($used_voucher_code)) {
  44. $order_list = model('order')->getOrdercommonList(array(array('voucher_code', 'in', $used_voucher_code)), 'order_id,voucher_code');
  45. if (!empty($order_list)) {
  46. foreach ($order_list as $v) {
  47. $voucher_order[$v['voucher_code']] = $v['order_id'];
  48. $voucher_model->editVoucher(array('voucher_order_id' => $v['order_id']), array('voucher_code' => $v['voucher_code']));
  49. }
  50. }
  51. }
  52. View::assign('voucher_list', $voucher_list);
  53. View::assign('voucherstate_arr', $voucher_model->getVoucherStateArray());
  54. View::assign('show_page', $voucher_model->page_info->render());
  55. $this->setMemberCurItem('voucher_list');
  56. $this->setMemberCurMenu('member_voucher');
  57. return View::fetch($this->template_dir . 'member_voucher_list');
  58. }
  59. /*
  60. * 显示平台代金券模版列表
  61. */
  62. public function mallvoucher()
  63. {
  64. $mallvoucher_model = model('mallvouchertemplate');
  65. $mallvoucher_list = $mallvoucher_model->getMemberMallvoucherList(session('member_id'), input('param.select_detail_state'), 10);
  66. View::assign('mallvoucher_list', $mallvoucher_list);
  67. View::assign('mallvoucherstate_arr', $mallvoucher_model->getVoucherStateArray());
  68. View::assign('show_page', $mallvoucher_model->page_info->render());
  69. $this->setMemberCurItem('mallvoucher_list');
  70. $this->setMemberCurMenu('member_mallvoucher');
  71. return View::fetch($this->template_dir . 'member_mallvoucher_list');
  72. }
  73. /**
  74. * 用户中心右边,小导航
  75. *
  76. * @param string $menu_type 导航类型
  77. * @param string $menu_key 当前导航的menu_key
  78. * @param array $array 附加菜单
  79. * @return
  80. */
  81. protected function getMemberItemList()
  82. {
  83. $menu_array = array(
  84. array(
  85. 'name' => 'voucher_list', 'text' => lang('ds_storevoucher'), 'url' => (string)url('Membervoucher/storevoucher')
  86. ),
  87. array(
  88. 'name' => 'mallvoucher_list', 'text' => lang('ds_mallvoucher'), 'url' => (string)url('Membervoucher/mallvoucher')
  89. )
  90. );
  91. return $menu_array;
  92. }
  93. }