Promotionmgdiscount.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. namespace app\admin\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. * ============================================================================
  7. * DSMall多用户商城
  8. * ============================================================================
  9. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  10. * 网站地址: http://www.csdeshang.com
  11. * ----------------------------------------------------------------------------
  12. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  13. * 不允许对程序代码以任何形式任何目的的再发布。
  14. * ============================================================================
  15. * 控制器
  16. */
  17. class Promotionmgdiscount extends AdminControl {
  18. public function initialize() {
  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. $store_model = model('store');
  34. $condition = array();
  35. $condition[]=array('store_name','like', '%' . input('param.store_name') . '%');
  36. $store_list = $store_model->getStoreList($condition, 10, 'store_id desc');
  37. foreach($store_list as $key=>$store){
  38. $store_list[$key]['store_mgdiscount_arr'] = $this->_get_mgdiscount_arr($store['store_mgdiscount']);
  39. }
  40. View::assign('store_list', $store_list);
  41. View::assign('show_page', $store_model->page_info->render());
  42. $this->setAdminCurItem('mgdiscount_store');
  43. return View::fetch();
  44. }
  45. /**
  46. * 显示店铺针对单个商品设置的 会员等级折扣
  47. */
  48. public function mgdiscount_goods() {
  49. $goods_model = model('goods');
  50. $condition[]=array('goods_mgdiscount','<>', '');
  51. $goods_list = $goods_model->getGoodsCommonOnlineList($condition);
  52. foreach ($goods_list as $key => $goods) {
  53. $goods_list[$key]['goods_mgdiscount_arr'] = $this->_get_mgdiscount_arr($goods['goods_mgdiscount']);
  54. }
  55. View::assign('show_page', $goods_model->page_info->render());
  56. View::assign('goods_list', $goods_list);
  57. $this->setAdminCurItem('mgdiscount_goods');
  58. return View::fetch();
  59. }
  60. /**
  61. * 通过系统会员等级和现有数据比对得出数值
  62. * @param type $mgdiscount_arr_temp
  63. * @return type
  64. */
  65. private function _get_mgdiscount_arr($mgdiscount_arr_temp)
  66. {
  67. $mgdiscount_arr_temp = @unserialize($mgdiscount_arr_temp);
  68. $member_model = model('member');
  69. //系统等级设置
  70. $membergrade_arr = $member_model->getMemberGradeArr();
  71. $mgdiscount_arr = array();
  72. foreach ($membergrade_arr as $key => $value) {
  73. $mgdiscount_arr[$key] = $value;
  74. $mgdiscount_arr[$key]['level_discount'] = isset($mgdiscount_arr_temp[$key]['level_discount'])?$mgdiscount_arr_temp[$key]['level_discount']:10;
  75. }
  76. return $mgdiscount_arr;
  77. }
  78. /**
  79. * 会员等级设置
  80. */
  81. public function mgdiscount_setting() {
  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. $menu_array = array(
  112. array(
  113. 'name' => 'mgdiscount_store',
  114. 'text' => lang('mgdiscount_store'),
  115. 'url' => (string)url('Promotionmgdiscount/mgdiscount_store')
  116. ), array(
  117. 'name' => 'mgdiscount_goods',
  118. 'text' => lang('mgdiscount_goods'),
  119. 'url' => (string)url('Promotionmgdiscount/mgdiscount_goods')
  120. ), array(
  121. 'name' => 'mgdiscount_setting',
  122. 'text' => lang('mgdiscount_setting'),
  123. 'url' => "javascript:dsLayerOpen('" . (string)url('Promotionmgdiscount/mgdiscount_setting') . "','" . lang('mgdiscount_setting') . "')"
  124. ),
  125. );
  126. return $menu_array;
  127. }
  128. }