Vrgroupbuy.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <?php
  2. namespace app\admin\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. * ============================================================================
  7. * DSMall多用户商城
  8. * ============================================================================
  9. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  10. * 网站地址: http://www.csdeshang.com
  11. * ----------------------------------------------------------------------------
  12. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  13. * 不允许对程序代码以任何形式任何目的的再发布。
  14. * ============================================================================
  15. * 控制器
  16. */
  17. class Vrgroupbuy extends AdminControl {
  18. public function initialize() {
  19. parent::initialize(); // TODO: Change the autogenerated stub
  20. Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/vrgroupbuy.lang.php');
  21. }
  22. /*
  23. * 列表分类
  24. */
  25. public function index() {
  26. $vrgroupbuyclass_model = model('vrgroupbuyclass');
  27. $vrgroupbuyclass_list = $vrgroupbuyclass_model->getVrgroupbuyclassList();
  28. View::assign('vrgroupbuyclass_list', $vrgroupbuyclass_list);
  29. $this->setAdminCurItem('index');
  30. return View::fetch();
  31. }
  32. /*
  33. * 添加分类
  34. */
  35. public function class_add() {
  36. if (request()->isPost()) { //添加虚拟抢购分类
  37. // 数据验证
  38. $data = [
  39. 'vrgclass_name' => input('post.vrgclass_name'),
  40. 'vrgclass_sort' => input('post.vrgclass_sort'),
  41. ];
  42. $vrgroupbuy_validate = ds_validate('vrgroupbuy');
  43. if (!$vrgroupbuy_validate->scene('class_add')->check($data)) {
  44. $this->error($vrgroupbuy_validate->getError());
  45. }
  46. $params = array();
  47. $params['vrgclass_name'] = trim(input('post.vrgclass_name'));
  48. $params['vrgclass_sort'] = intval(input('post.vrgclass_sort'));
  49. if (intval(input('post.vrgclass_parent_id')) > 0) {
  50. $params['vrgclass_parent_id'] = input('post.vrgclass_parent_id');
  51. } else {
  52. $params['vrgclass_parent_id'] = 0;
  53. }
  54. $vrgroupbuyclass_model = model('vrgroupbuyclass');
  55. $res = $vrgroupbuyclass_model->addVrgroupbuyclass($params); //添加分类
  56. if ($res) {
  57. // 删除虚拟抢购分类缓存
  58. model('groupbuy')->dropCachedData('groupbuyvrclasses');
  59. $this->log('添加虚拟抢购分类[ID:' . $res . ']', 1);
  60. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  61. } else {
  62. $this->error(lang('ds_common_op_fail'));
  63. }
  64. } else {
  65. $vrgroupbuyclass_model = model('vrgroupbuyclass'); //一级分类
  66. $vrgroupbuyclass_list = $vrgroupbuyclass_model->getVrgroupbuyclassList(array('vrgclass_parent_id' => 0));
  67. View::assign('vrgroupbuyclass_list', $vrgroupbuyclass_list);
  68. $this->setAdminCurItem('class_add');
  69. $parent_id = input('param.vrgclass_parent_id');
  70. View::assign('vrgclass_parent_id', !empty($parent_id) ? intval($parent_id) : 0);
  71. return View::fetch('class_form');
  72. }
  73. }
  74. /*
  75. * 编辑分类
  76. */
  77. public function class_edit() {
  78. if (request()->isPost()) {
  79. // 数据验证
  80. $data = [
  81. 'vrgclass_name' => input('post.vrgclass_name'),
  82. 'vrgclass_sort' => input('post.vrgclass_sort'),
  83. ];
  84. $vrgroupbuy_validate = ds_validate('vrgroupbuy');
  85. if (!$vrgroupbuy_validate->scene('class_edit')->check($data)) {
  86. $this->error($vrgroupbuy_validate->getError());
  87. }
  88. $params = array();
  89. $params['vrgclass_name'] = trim(input('post.vrgclass_name'));
  90. $params['vrgclass_sort'] = intval(input('post.vrgclass_sort'));
  91. if (intval(input('post.vrgclass_parent_id')) > 0) {
  92. $params['vrgclass_parent_id'] = input('post.vrgclass_parent_id');
  93. } else {
  94. $params['vrgclass_parent_id'] = 0;
  95. }
  96. $condition = array(); //条件
  97. $condition[] = array('vrgclass_id','=',intval(input('param.vrgclass_id')));
  98. $vrgroupbuyclass_model = model('vrgroupbuyclass');
  99. $result = $vrgroupbuyclass_model->editVrgroupbuyclass($condition, $params);
  100. if ($result >= 0) {
  101. // 删除虚拟抢购分类缓存
  102. model('groupbuy')->dropCachedData('groupbuyvrclasses');
  103. $this->log('编辑虚拟抢购分类[ID:' . intval(input('param.vrgclass_id')) . ']', 1);
  104. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  105. } else {
  106. $this->error(lang('ds_common_op_fail'));
  107. }
  108. } else {
  109. $vrgroupbuyclass_model = model('vrgroupbuyclass'); //分类信息
  110. $class = $vrgroupbuyclass_model->getVrgroupbuyclassInfo(array('vrgclass_id' => intval(input('param.vrgclass_id'))));
  111. if (empty($class)) {
  112. $this->error(lang('vrgclass_not_exist'));
  113. }
  114. View::assign('class', $class);
  115. $vrgroupbuyclass_list = $vrgroupbuyclass_model->getVrgroupbuyclassList(array('vrgclass_parent_id' => 0));
  116. View::assign('vrgroupbuyclass_list', $vrgroupbuyclass_list);
  117. $this->setAdminCurItem('class_edit');
  118. return View::fetch('class_form');
  119. }
  120. }
  121. /*
  122. * 删除分类
  123. */
  124. public function class_del() {
  125. $vrgclass_id = input('param.vrgclass_id');
  126. $vrgclass_id_array = ds_delete_param($vrgclass_id);
  127. if ($vrgclass_id_array == FALSE) {
  128. ds_json_encode(10001, lang('param_error'));
  129. }
  130. $vrgroupbuy_model = model('vrgroupbuyclass');
  131. foreach ($vrgclass_id_array as $val) {
  132. $class = $vrgroupbuy_model->getVrgroupbuyclassInfo(array('vrgclass_id' => $val));
  133. if ($class['vrgclass_parent_id'] == 0) {
  134. $class = $vrgroupbuy_model->delVrgroupbuyclass(array('vrgclass_parent_id' => $class['vrgclass_id']));
  135. }
  136. $class = $vrgroupbuy_model->delVrgroupbuyclass(array('vrgclass_id' => $val));
  137. }
  138. // 删除虚拟抢购分类缓存
  139. model('groupbuy')->dropCachedData('groupbuy_vr_classes');
  140. $this->log('删除虚拟抢购分类[ID:' . input('post.vrgclass_id') . ']', 1);
  141. ds_json_encode(10000, lang('ds_common_del_succ'));
  142. }
  143. public function ajax() {
  144. $field = input('param.column');
  145. $id = input('param.id');
  146. $value = input('param.value');
  147. switch (input('param.column')) {
  148. case 'vrgclass_name':
  149. if (mb_strlen((string) $value, 'utf-8') > 10)
  150. return;
  151. break;
  152. case 'vrgclass_sort':
  153. if ($value < 0 || $value > 255)
  154. return;
  155. break;
  156. default:
  157. return;
  158. }
  159. switch (input('param.branch')) {
  160. case 'class':
  161. $vrgroupbuyclass_model = model('vrgroupbuyclass');
  162. $res = $vrgroupbuyclass_model->editVrgroupbuyclass(array('vrgclass_id' => $id), array($field => $value));
  163. if ($res) {
  164. // 删除虚拟抢购分类缓存
  165. model('groupbuy')->dropCachedData('groupbuy_vr_classes');
  166. $this->log('编辑虚拟抢购分类[ID:' . $id . ']', 1);
  167. echo 'true';
  168. } else {
  169. echo 'false';
  170. }
  171. exit;
  172. default:
  173. return;
  174. }
  175. }
  176. protected function getAdminItemList() {
  177. $menu_array = array(
  178. array(
  179. 'name' => 'index', 'text' => lang('vrgroupbuy_cate_manage'), 'url' => (string)url('Vrgroupbuy/index')
  180. ), array(
  181. 'name' => 'class_add', 'text' => lang('vrgclass_add'), 'url' => "javascript:dsLayerOpen('".(string)url('Vrgroupbuy/class_add')."','".lang('vrgclass_add')."')"
  182. )
  183. );
  184. return $menu_array;
  185. }
  186. }