Membervoucher.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  13. * 网站地址: https://www.valimart.net/
  14. * ----------------------------------------------------------------------------
  15. *
  16. * ============================================================================
  17. * 控制器
  18. */
  19. class Membervoucher extends BaseMember
  20. {
  21. public function initialize()
  22. {
  23. parent::initialize(); // TODO: Change the autogenerated stub
  24. Lang::load(base_path().'home/lang/'.config('lang.default_lang').'/member_voucher.lang.php');
  25. //判断系统是否开启代金券功能
  26. if (intval(config('ds_config.voucher_allow')) !== 1){
  27. $this->error(lang('voucher_unavailable'));
  28. }
  29. }
  30. /*
  31. * 显示店铺代金券模版列表
  32. */
  33. public function storevoucher() {
  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. $mallvoucher_model = model('mallvouchertemplate');
  67. $mallvoucher_list = $mallvoucher_model->getMemberMallvoucherList(session('member_id'), input('param.select_detail_state'), 10);
  68. View::assign('mallvoucher_list', $mallvoucher_list);
  69. View::assign('mallvoucherstate_arr', $mallvoucher_model->getVoucherStateArray());
  70. View::assign('show_page',$mallvoucher_model->page_info->render()) ;
  71. $this->setMemberCurItem('mallvoucher_list');
  72. $this->setMemberCurMenu('member_mallvoucher');
  73. return View::fetch($this->template_dir.'member_mallvoucher_list');
  74. }
  75. /**
  76. * 用户中心右边,小导航
  77. *
  78. * @param string $menu_type 导航类型
  79. * @param string $menu_key 当前导航的menu_key
  80. * @param array $array 附加菜单
  81. * @return
  82. */
  83. protected function getMemberItemList()
  84. {
  85. $menu_array=array(
  86. array(
  87. 'name'=>'voucher_list','text'=>lang('ds_storevoucher'),'url'=>(string)url('Membervoucher/storevoucher')
  88. ),
  89. array(
  90. 'name'=>'mallvoucher_list','text'=>lang('ds_mallvoucher'),'url'=>(string)url('Membervoucher/mallvoucher')
  91. )
  92. );
  93. return $menu_array;
  94. }
  95. }