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