Promotionbooth.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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 Promotionbooth extends AdminControl
  13. {
  14. public function initialize()
  15. {
  16. parent::initialize(); // TODO: Change the autogenerated stub
  17. Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/promotionbooth.lang.php');
  18. }
  19. public function index()
  20. {
  21. //自动开启优惠套装
  22. if (intval(input('param.promotion_allow')) === 1) {
  23. $config_model = model('config');
  24. $update_array = array();
  25. $update_array['promotion_allow'] = 1;
  26. $config_model->editConfig($update_array);
  27. }
  28. /**
  29. * 处理商品分类
  30. */
  31. $gcid = intval(input('param.choose_gcid'));
  32. $choose_gcid = $gcid > 0 ? $gcid : 0;
  33. $gccache_arr = model('goodsclass')->getGoodsclassCache($choose_gcid, 3);
  34. View::assign('gc_json', json_encode($gccache_arr['showclass']));
  35. View::assign('gc_choose_json', json_encode($gccache_arr['choose_gcid']));
  36. $pbooth_model = model('pbooth');
  37. $where = array();
  38. if (intval(input('param.choose_gcid')) > 0) {
  39. $where = $pbooth_model->_getRecursiveClass($where, intval(input('param.choose_gcid')));
  40. }
  41. $goods_list = $pbooth_model->getBoothgoodsList($where, 'goods_id', 10);
  42. if (!empty($goods_list)) {
  43. $goodsid_array = array();
  44. foreach ($goods_list as $val) {
  45. $goodsid_array[] = $val['goods_id'];
  46. }
  47. $goods_list = model('goods')->getGoodsList(array(array('goods_id', 'in', $goodsid_array)));
  48. }
  49. View::assign('gc_list', model('goodsclass')->getGoodsclassForCacheModel());
  50. View::assign('goods_list', $goods_list);
  51. View::assign('show_page', $pbooth_model->page_info->render());
  52. $this->setAdminCurItem('index');
  53. // 输出自营店铺IDS
  54. View::assign('flippedOwnShopIds', array_flip(model('store')->getOwnShopIds()));
  55. return View::fetch();
  56. }
  57. /**
  58. * 套餐列表
  59. */
  60. public function booth_quota()
  61. {
  62. $pbooth_model = model('pbooth');
  63. $where = array();
  64. if (input('param.store_name') != '') {
  65. $where[] = array('store_name', 'like', '%' . trim(input('param.store_name')) . '%');
  66. }
  67. $booth_list = $pbooth_model->getBoothquotaList($where, '*', 10);
  68. // 状态数组
  69. $state_array = array(0 => lang('ds_close'), 1 => lang('ds_open'));
  70. View::assign('state_array', $state_array);
  71. $this->setAdminCurItem('booth_quota');
  72. View::assign('booth_list', $booth_list);
  73. View::assign('show_page', $pbooth_model->page_info->render());
  74. return View::fetch();
  75. }
  76. /**
  77. * 删除推荐商品
  78. */
  79. public function del_goods()
  80. {
  81. $where = array();
  82. $goods_id = input('param.goods_id');
  83. $goods_id_array = ds_delete_param($goods_id);
  84. if ($goods_id_array == FALSE) {
  85. ds_json_encode('10001', lang('param_error'));
  86. }
  87. $where[] = array('goods_id', 'in', $goods_id_array);
  88. $rs = model('pbooth')->delBoothgoods($where);
  89. if ($rs) {
  90. ds_json_encode(10000, lang('ds_common_del_succ'));
  91. } else {
  92. ds_json_encode(10001, lang('ds_common_del_fail'));
  93. }
  94. }
  95. /**
  96. * 设置
  97. */
  98. public function booth_setting()
  99. {
  100. // 实例化模型
  101. $config_model = model('config');
  102. if (request()->isPost()) {
  103. // 验证
  104. $data = [
  105. 'promotion_booth_price' => input('post.promotion_booth_price'),
  106. 'promotion_booth_goods_sum' => input('post.promotion_booth_goods_sum'),
  107. ];
  108. $promotionbooth_validate = ds_validate('promotionbooth');
  109. if (!$promotionbooth_validate->scene('booth_setting')->check($data)) {
  110. $this->error($promotionbooth_validate->getError());
  111. }
  112. $data['promotion_booth_price'] = intval(input('post.promotion_booth_price'));
  113. $data['promotion_booth_goods_sum'] = intval(input('post.promotion_booth_goods_sum'));
  114. $return = $config_model->editConfig($data);
  115. if ($return) {
  116. $this->log(lang('ds_set') . ' 推荐展位');
  117. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  118. } else {
  119. $this->error(lang('ds_common_op_fail'));
  120. }
  121. } else {
  122. // 查询setting列表
  123. $setting = rkcache('config', true);
  124. View::assign('setting', $setting);
  125. return View::fetch();
  126. }
  127. }
  128. protected function getAdminItemList()
  129. {
  130. $menu_array = array(
  131. array(
  132. 'name' => 'index',
  133. 'text' => lang('goods_list'),
  134. 'url' => (string)url('Promotionbooth/index')
  135. ), array(
  136. 'name' => 'booth_quota',
  137. 'text' => lang('booth_list'),
  138. 'url' => (string)url('Promotionbooth/booth_quota')
  139. ), array(
  140. 'name' => 'booth_setting',
  141. 'text' => lang('ds_setting'),
  142. 'url' => "javascript:dsLayerOpen('" . (string)url('Promotionbooth/booth_setting') . "','" . lang('ds_setting') . "')"
  143. ),
  144. );
  145. return $menu_array;
  146. }
  147. }