Promotionbundling.php 7.0 KB

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