Promotionbundling.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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 Promotionbundling 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') . '/promotionbundling.lang.php');
  18. }
  19. /**
  20. * 套餐管理
  21. */
  22. public function bundling_quota()
  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. $pbundling_model = model('pbundling');
  32. // 查询添加
  33. $where = array();
  34. if (input('param.store_name') != '') {
  35. $where[] = array('store_name', 'like', '%' . trim(input('param.store_name')) . '%');
  36. }
  37. if (is_numeric(input('param.state'))) {
  38. $where[] = array('blquota_state', '=', intval(input('param.state')));
  39. }
  40. $bundlingquota_list = $pbundling_model->getBundlingQuotaList($where, 10);
  41. View::assign('show_page', $pbundling_model->page_info->render());
  42. // 状态数组
  43. $state_array = array(0 => lang('bundling_state_0'), 1 => lang('bundling_state_1'));
  44. View::assign('state_array', $state_array);
  45. $this->setAdminCurItem('bundling_quota');
  46. View::assign('bundlingquota_list', $bundlingquota_list);
  47. return View::fetch();
  48. }
  49. /**
  50. * 活动管理
  51. */
  52. public function index()
  53. {
  54. $pbundling_model = model('pbundling');
  55. // 查询添加
  56. $where = '';
  57. if (input('param.bundling_name') != '') {
  58. $where[] = array('bl_name', 'like', '%' . trim(input('param.bundling_name')) . '%');
  59. }
  60. if (input('param.store_name') != '') {
  61. $where[] = array('store_name', 'like', '%' . trim(input('param.store_name')) . '%');
  62. }
  63. if (is_numeric(input('param.state'))) {
  64. $where[] = array('bl_state', '=', input('param.state'));
  65. }
  66. $pbundling_list = $pbundling_model->getBundlingList($where, '*', 'bl_id desc', 10);
  67. $pbundling_list = array_under_reset($pbundling_list, 'bl_id');
  68. View::assign('show_page', $pbundling_model->page_info->render());
  69. if (!empty($pbundling_list)) {
  70. $blid_array = array_keys($pbundling_list);
  71. $bgoods_array = $pbundling_model->getBundlingGoodsList(array(array('bl_id', 'in', $blid_array)), 'bl_id,goods_id,count(*) as count', 'blgoods_appoint desc', 'bl_id');
  72. $bgoods_array = array_under_reset($bgoods_array, 'bl_id');
  73. foreach ($pbundling_list as $key => $val) {
  74. $pbundling_list[$key]['goods_id'] = isset($bgoods_array[$val['bl_id']]['goods_id']) ? $bgoods_array[$val['bl_id']]['goods_id'] : '';
  75. $pbundling_list[$key]['count'] = isset($bgoods_array[$val['bl_id']]['count']) ? $bgoods_array[$val['bl_id']]['count'] : '';
  76. }
  77. }
  78. View::assign('pbundling_list', $pbundling_list);
  79. // 状态数组
  80. $state_array = array(0 => lang('bundling_state_0'), 1 => lang('bundling_state_1'));
  81. View::assign('state_array', $state_array);
  82. // 输出自营店铺IDS
  83. // View::assign('flippedOwnShopIds', array_flip(model('store')->getOwnShopIds()));
  84. View::assign('flippedOwnShopIds', '');
  85. $this->setAdminCurItem('index');
  86. return View::fetch();
  87. }
  88. /**
  89. * 设置
  90. */
  91. public function bundling_setting()
  92. {
  93. // 实例化模型
  94. $config_model = model('config');
  95. if (request()->isPost()) {
  96. // 验证
  97. $data = [
  98. 'promotion_bundling_price' => input('post.promotion_bundling_price'),
  99. 'promotion_bundling_sum' => input('post.promotion_bundling_sum'),
  100. 'promotion_bundling_goods_sum' => input('post.promotion_bundling_goods_sum')
  101. ];
  102. $promotionbundling_validate = ds_validate('promotionbundling');
  103. if (!$promotionbundling_validate->scene('bundling_setting')->check($data)) {
  104. $this->error($promotionbundling_validate->getError());
  105. }
  106. $data['promotion_bundling_price'] = intval(input('post.promotion_bundling_price'));
  107. $data['promotion_bundling_sum'] = intval(input('post.promotion_bundling_sum'));
  108. $data['promotion_bundling_goods_sum'] = intval(input('post.promotion_bundling_goods_sum'));
  109. $return = $config_model->editConfig($data);
  110. if ($return) {
  111. $this->log(lang('ds_set') . lang('ds_promotion_bundling'));
  112. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  113. } else {
  114. $this->error(lang('ds_common_op_fail'));
  115. }
  116. } else {
  117. $this->setAdminCurItem('bundling_setting');
  118. // 查询setting列表
  119. $setting = rkcache('config', true);
  120. View::assign('setting', $setting);
  121. return View::fetch();
  122. }
  123. }
  124. /**
  125. * 删除套餐活动
  126. */
  127. public function del_bundling()
  128. {
  129. $bl_id = intval(input('param.bl_id'));
  130. if ($bl_id <= 0) {
  131. $this->error(lang('param_error'));
  132. }
  133. $rs = model('pbundling')->delBundlingForAdmin(array('bl_id' => $bl_id));
  134. if ($rs) {
  135. ds_json_encode(10000, lang('ds_common_op_succ'));
  136. } else {
  137. ds_json_encode(10001, lang('ds_common_op_fail'));
  138. }
  139. }
  140. protected function getAdminItemList()
  141. {
  142. $menu_array = array(
  143. array(
  144. 'name' => 'index',
  145. 'text' => lang('bundling_list'),
  146. 'url' => (string)url('Promotionbundling/index')
  147. ), array(
  148. 'name' => 'bundling_quota',
  149. 'text' => lang('bundling_quota'),
  150. 'url' => (string)url('Promotionbundling/bundling_quota')
  151. ), array(
  152. 'name' => 'bundling_setting',
  153. 'text' => lang('bundling_setting'),
  154. 'url' => "javascript:dsLayerOpen('" . (string)url('Promotionbundling/bundling_setting') . "','" . lang('bundling_setting') . "')"
  155. ),
  156. );
  157. return $menu_array;
  158. }
  159. }