Promotionmgdiscount.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. namespace app\admin\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. * ============================================================================
  7. *
  8. * ============================================================================
  9. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  10. * 网站地址: https://www.valimart.net/
  11. * ----------------------------------------------------------------------------
  12. *
  13. * ============================================================================
  14. * 控制器
  15. */
  16. class Promotionmgdiscount extends AdminControl {
  17. public function initialize() {
  18. parent::initialize();
  19. Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/promotionmgdiscount.lang.php');
  20. //自动开启会员等级折扣
  21. if (intval(input('param.mgdiscount_allow')) === 1) {
  22. $config_model = model('config');
  23. $update_array = array();
  24. $update_array['mgdiscount_allow'] = 1;
  25. $config_model->editConfig($update_array);
  26. }
  27. }
  28. /**
  29. * 显示店铺统一设置的 会员等级折扣
  30. */
  31. public function mgdiscount_store() {
  32. $store_model = model('store');
  33. $condition = array();
  34. $condition[]=array('store_name','like', '%' . input('param.store_name') . '%');
  35. $store_list = $store_model->getStoreList($condition, 10, 'store_id desc');
  36. foreach($store_list as $key=>$store){
  37. $store_list[$key]['store_mgdiscount_arr'] = $this->_get_mgdiscount_arr($store['store_mgdiscount']);
  38. }
  39. View::assign('store_list', $store_list);
  40. View::assign('show_page', $store_model->page_info->render());
  41. $this->setAdminCurItem('mgdiscount_store');
  42. return View::fetch();
  43. }
  44. /**
  45. * 显示店铺针对单个商品设置的 会员等级折扣
  46. */
  47. public function mgdiscount_goods() {
  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. if (!(request()->isPost())) {
  82. $setting = rkcache('config', true);
  83. View::assign('setting', $setting);
  84. return View::fetch();
  85. } else {
  86. $mgdiscount_price = intval(input('post.mgdiscount_price'));
  87. if ($mgdiscount_price < 0) {
  88. $this->error(lang('param_error'));
  89. }
  90. $config_model = model('config');
  91. $update_array = array();
  92. $update_array['mgdiscount_price'] = $mgdiscount_price;
  93. $result = $config_model->editConfig($update_array);
  94. if ($result) {
  95. $this->log('修改会员等级折扣价格为' . $mgdiscount_price . '元');
  96. dsLayerOpenSuccess(lang('setting_save_success'));
  97. } else {
  98. $this->error(lang('setting_save_fail'));
  99. }
  100. }
  101. }
  102. /**
  103. * 页面内导航菜单
  104. *
  105. * @param string $menu_key 当前导航的menu_key
  106. * @param array $array 附加菜单
  107. * @return
  108. */
  109. protected function getAdminItemList() {
  110. $menu_array = array(
  111. array(
  112. 'name' => 'mgdiscount_store',
  113. 'text' => lang('mgdiscount_store'),
  114. 'url' => (string)url('Promotionmgdiscount/mgdiscount_store')
  115. ), array(
  116. 'name' => 'mgdiscount_goods',
  117. 'text' => lang('mgdiscount_goods'),
  118. 'url' => (string)url('Promotionmgdiscount/mgdiscount_goods')
  119. ), array(
  120. 'name' => 'mgdiscount_setting',
  121. 'text' => lang('mgdiscount_setting'),
  122. 'url' => "javascript:dsLayerOpen('" . (string)url('Promotionmgdiscount/mgdiscount_setting') . "','" . lang('mgdiscount_setting') . "')"
  123. ),
  124. );
  125. return $menu_array;
  126. }
  127. }