Promotionmgdiscount.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. namespace app\admin\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. * ============================================================================
  7. *
  8. * ============================================================================
  9. *
  10. * ----------------------------------------------------------------------------
  11. *
  12. * ============================================================================
  13. * 控制器
  14. */
  15. class Promotionmgdiscount extends AdminControl
  16. {
  17. public function initialize()
  18. {
  19. parent::initialize();
  20. Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/promotionmgdiscount.lang.php');
  21. //自动开启会员等级折扣
  22. if (intval(input('param.mgdiscount_allow')) === 1) {
  23. $config_model = model('config');
  24. $update_array = array();
  25. $update_array['mgdiscount_allow'] = 1;
  26. $config_model->editConfig($update_array);
  27. }
  28. }
  29. /**
  30. * 显示店铺统一设置的 会员等级折扣
  31. */
  32. public function mgdiscount_store()
  33. {
  34. $store_model = model('store');
  35. $condition = array();
  36. $condition[] = array('store_name', 'like', '%' . input('param.store_name') . '%');
  37. $store_list = $store_model->getStoreList($condition, 10, 'store_id desc');
  38. foreach ($store_list as $key => $store) {
  39. $store_list[$key]['store_mgdiscount_arr'] = $this->_get_mgdiscount_arr($store['store_mgdiscount']);
  40. }
  41. View::assign('store_list', $store_list);
  42. View::assign('show_page', $store_model->page_info->render());
  43. $this->setAdminCurItem('mgdiscount_store');
  44. return View::fetch();
  45. }
  46. /**
  47. * 显示店铺针对单个商品设置的 会员等级折扣
  48. */
  49. public function mgdiscount_goods()
  50. {
  51. $goods_model = model('goods');
  52. $condition[] = array('goods_mgdiscount', '<>', '');
  53. $goods_list = $goods_model->getGoodsCommonOnlineList($condition);
  54. foreach ($goods_list as $key => $goods) {
  55. $goods_list[$key]['goods_mgdiscount_arr'] = $this->_get_mgdiscount_arr($goods['goods_mgdiscount']);
  56. }
  57. View::assign('show_page', $goods_model->page_info->render());
  58. View::assign('goods_list', $goods_list);
  59. $this->setAdminCurItem('mgdiscount_goods');
  60. return View::fetch();
  61. }
  62. /**
  63. * 通过系统会员等级和现有数据比对得出数值
  64. * @param type $mgdiscount_arr_temp
  65. * @return type
  66. */
  67. private function _get_mgdiscount_arr($mgdiscount_arr_temp)
  68. {
  69. $mgdiscount_arr_temp = @unserialize($mgdiscount_arr_temp);
  70. $member_model = model('member');
  71. //系统等级设置
  72. $membergrade_arr = $member_model->getMemberGradeArr();
  73. $mgdiscount_arr = array();
  74. foreach ($membergrade_arr as $key => $value) {
  75. $mgdiscount_arr[$key] = $value;
  76. $mgdiscount_arr[$key]['level_discount'] = isset($mgdiscount_arr_temp[$key]['level_discount']) ? $mgdiscount_arr_temp[$key]['level_discount'] : 10;
  77. }
  78. return $mgdiscount_arr;
  79. }
  80. /**
  81. * 会员等级设置
  82. */
  83. public function mgdiscount_setting()
  84. {
  85. if (!(request()->isPost())) {
  86. $setting = rkcache('config', true);
  87. View::assign('setting', $setting);
  88. return View::fetch();
  89. } else {
  90. $mgdiscount_price = intval(input('post.mgdiscount_price'));
  91. if ($mgdiscount_price < 0) {
  92. $this->error(lang('param_error'));
  93. }
  94. $config_model = model('config');
  95. $update_array = array();
  96. $update_array['mgdiscount_price'] = $mgdiscount_price;
  97. $result = $config_model->editConfig($update_array);
  98. if ($result) {
  99. $this->log('修改会员等级折扣价格为' . $mgdiscount_price . '元');
  100. dsLayerOpenSuccess(lang('setting_save_success'));
  101. } else {
  102. $this->error(lang('setting_save_fail'));
  103. }
  104. }
  105. }
  106. /**
  107. * 页面内导航菜单
  108. *
  109. * @param string $menu_key 当前导航的menu_key
  110. * @param array $array 附加菜单
  111. * @return
  112. */
  113. protected function getAdminItemList()
  114. {
  115. $menu_array = array(
  116. array(
  117. 'name' => 'mgdiscount_store',
  118. 'text' => lang('mgdiscount_store'),
  119. 'url' => (string)url('Promotionmgdiscount/mgdiscount_store')
  120. ), array(
  121. 'name' => 'mgdiscount_goods',
  122. 'text' => lang('mgdiscount_goods'),
  123. 'url' => (string)url('Promotionmgdiscount/mgdiscount_goods')
  124. ), array(
  125. 'name' => 'mgdiscount_setting',
  126. 'text' => lang('mgdiscount_setting'),
  127. 'url' => "javascript:dsLayerOpen('" . (string)url('Promotionmgdiscount/mgdiscount_setting') . "','" . lang('mgdiscount_setting') . "')"
  128. ),
  129. );
  130. return $menu_array;
  131. }
  132. }