promotion_bundling.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <?php
  2. /**
  3. * 优惠套装管理
  4. *
  5. *
  6. *
  7. ***/
  8. defined('InShopNC') or exit('Access Invalid!');
  9. class promotion_bundlingControl extends SystemControl{
  10. public function __construct(){
  11. parent::__construct();
  12. //读取语言包
  13. Language::read('promotion_bundling');
  14. //检查审核功能是否开启
  15. if (intval($_GET['promotion_allow']) !== 1 && intval(C('promotion_allow')) !== 1){
  16. $url = array(
  17. array(
  18. 'url'=>'index.php?act=dashboard&op=welcome',
  19. 'msg'=>Language::get('close'),
  20. ),
  21. array(
  22. 'url'=>'index.php?act=promotion_bundling&promotion_allow=1',
  23. 'msg'=>Language::get('open'),
  24. ),
  25. );
  26. showMessage(Language::get('promotion_unavailable'),$url,'html','succ',1,6000);
  27. }
  28. }
  29. /**
  30. * 默认Op
  31. */
  32. public function indexOp() {
  33. //自动开启优惠套装
  34. if (intval($_GET['promotion_allow']) === 1){
  35. $model_setting = Model('setting');
  36. $update_array = array();
  37. $update_array['promotion_allow'] = 1;
  38. $model_setting->updateSetting($update_array);
  39. }
  40. $this->bundling_listOp();
  41. }
  42. /**
  43. * 套餐管理
  44. */
  45. public function bundling_quotaOp() {
  46. $model_bundling = Model('p_bundling');
  47. // 查询添加
  48. $where = array();
  49. if ($_GET['store_name'] != '') {
  50. $where['store_name'] = array('like', '%'. trim($_GET['store_name']) .'%');
  51. }
  52. if (is_numeric($_GET['state'])) {
  53. $where['bl_state'] = intval($_GET['state']);
  54. }
  55. $bundling_quota_list = $model_bundling->getBundlingQuotaList($where);
  56. $page = $model_bundling->showpage(2);
  57. Tpl::output('show_page', $page);
  58. // 状态数组
  59. $state_array = array(0=>Language::get('bundling_state_0') , 1=>Language::get('bundling_state_1'));
  60. Tpl::output('state_array', $state_array);
  61. Tpl::output('list',$bundling_quota_list);
  62. Tpl::showpage('promotion_bundling_quota.list');
  63. }
  64. /**
  65. * 活动管理
  66. */
  67. public function bundling_listOp() {
  68. $model_bundling = Model('p_bundling');
  69. // 查询添加
  70. $where = '';
  71. if ($_GET['bundling_name'] != '') {
  72. $where['bl_name'] = array('like', '%' . trim($_GET['bundling_name']) . '%');
  73. }
  74. if ($_GET['store_name'] != '') {
  75. $where['store_name'] = array('like', '%'. trim($_GET['store_name']) .'%');
  76. }
  77. if (is_numeric($_GET['state'])) {
  78. $where['bl_state'] = $_GET['state'];
  79. }
  80. $bundling_list = $model_bundling->getBundlingList($where);
  81. $bundling_list = array_under_reset($bundling_list, 'bl_id');
  82. Tpl::output('show_page',$model_bundling->showpage(2));
  83. if (!empty($bundling_list)) {
  84. $blid_array = array_keys($bundling_list);
  85. $bgoods_array = $model_bundling->getBundlingGoodsList(array('bl_id' => array('in', $blid_array)), 'bl_id,goods_id,count(*) as count', 'bl_appoint desc', 'bl_id');
  86. $bgoods_array = array_under_reset($bgoods_array, 'bl_id');
  87. foreach ($bundling_list as $key => $val) {
  88. $bundling_list[$key]['goods_id'] = $bgoods_array[$val['bl_id']]['goods_id'];
  89. $bundling_list[$key]['count'] = $bgoods_array[$val['bl_id']]['count'];
  90. }
  91. }
  92. Tpl::output('list', $bundling_list);
  93. // 状态数组
  94. $state_array = array(0=>Language::get('bundling_state_0') , 1=>Language::get('bundling_state_1'));
  95. Tpl::output('state_array', $state_array);
  96. // 输出自营店铺IDS
  97. Tpl::output('flippedOwnShopIds', array_flip(model('store')->getOwnShopIds()));
  98. Tpl::showpage('promotion_bundling.list');
  99. }
  100. /**
  101. * 设置
  102. */
  103. public function bundling_settingOp() {
  104. // 实例化模型
  105. $model_setting = Model('setting');
  106. if (chksubmit()){
  107. // 验证
  108. $obj_validate = new Validator();
  109. $obj_validate->validateparam = array(
  110. array("input"=>$_POST["promotion_bundling_price"], "require"=>"true", 'validator'=>'Number', "message"=>Language::get('bundling_price_error')),
  111. array("input"=>$_POST["promotion_bundling_sum"], "require"=>"true", 'validator'=>'Number', "message"=>Language::get('bundling_sum_error')),
  112. array("input"=>$_POST["promotion_bundling_goods_sum"], "require"=>"true", 'validator'=>'Number', "message"=>Language::get('bundling_goods_sum_error')),
  113. );
  114. $error = $obj_validate->validate();
  115. if ($error != ''){
  116. showMessage($error);
  117. }
  118. $data['promotion_bundling_price'] = intval($_POST['promotion_bundling_price']);
  119. $data['promotion_bundling_sum'] = intval($_POST['promotion_bundling_sum']);
  120. $data['promotion_bundling_goods_sum'] = intval($_POST['promotion_bundling_goods_sum']);
  121. $return = $model_setting->updateSetting($data);
  122. if($return){
  123. $this->log(L('nc_set,nc_promotion_bundling'));
  124. showMessage(L('nc_common_op_succ'));
  125. }else{
  126. showMessage(L('nc_common_op_fail'));
  127. }
  128. }
  129. // 查询setting列表
  130. $setting = $model_setting->GetListSetting();
  131. Tpl::output('setting',$setting);
  132. Tpl::showpage('promotion_bundling.setting');
  133. }
  134. /**
  135. * 删除套餐活动
  136. */
  137. public function del_bundlingOp() {
  138. $bl_id = intval($_GET['bl_id']);
  139. if ($bl_id <= 0) {
  140. showMessage(L('param_error'), '', 'html', 'error');
  141. }
  142. $rs = Model('p_bundling')->delBundlingForAdmin(array('bl_id' => $bl_id));
  143. if ($rs) {
  144. showMessage(L('nc_common_op_succ'));
  145. } else {
  146. showMessage(L('nc_common_op_fail'), '', 'html', 'error');
  147. }
  148. }
  149. }