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