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