Vrgroupbuy.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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 Vrgroupbuy 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') . '/vrgroupbuy.lang.php');
  18. }
  19. /*
  20. * 列表分类
  21. */
  22. public function index()
  23. {
  24. $vrgroupbuyclass_model = model('vrgroupbuyclass');
  25. $vrgroupbuyclass_list = $vrgroupbuyclass_model->getVrgroupbuyclassList();
  26. View::assign('vrgroupbuyclass_list', $vrgroupbuyclass_list);
  27. $this->setAdminCurItem('index');
  28. return View::fetch();
  29. }
  30. /*
  31. * 添加分类
  32. */
  33. public function class_add()
  34. {
  35. if (request()->isPost()) { //添加虚拟抢购分类
  36. // 数据验证
  37. $data = [
  38. 'vrgclass_name' => input('post.vrgclass_name'),
  39. 'vrgclass_sort' => input('post.vrgclass_sort'),
  40. ];
  41. $vrgroupbuy_validate = ds_validate('vrgroupbuy');
  42. if (!$vrgroupbuy_validate->scene('class_add')->check($data)) {
  43. $this->error($vrgroupbuy_validate->getError());
  44. }
  45. $params = array();
  46. $params['vrgclass_name'] = trim(input('post.vrgclass_name'));
  47. $params['vrgclass_sort'] = intval(input('post.vrgclass_sort'));
  48. if (intval(input('post.vrgclass_parent_id')) > 0) {
  49. $params['vrgclass_parent_id'] = input('post.vrgclass_parent_id');
  50. } else {
  51. $params['vrgclass_parent_id'] = 0;
  52. }
  53. $vrgroupbuyclass_model = model('vrgroupbuyclass');
  54. $res = $vrgroupbuyclass_model->addVrgroupbuyclass($params); //添加分类
  55. if ($res) {
  56. // 删除虚拟抢购分类缓存
  57. model('groupbuy')->dropCachedData('groupbuyvrclasses');
  58. $this->log('添加虚拟抢购分类[ID:' . $res . ']', 1);
  59. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  60. } else {
  61. $this->error(lang('ds_common_op_fail'));
  62. }
  63. } else {
  64. $vrgroupbuyclass_model = model('vrgroupbuyclass'); //一级分类
  65. $vrgroupbuyclass_list = $vrgroupbuyclass_model->getVrgroupbuyclassList(array('vrgclass_parent_id' => 0));
  66. View::assign('vrgroupbuyclass_list', $vrgroupbuyclass_list);
  67. $this->setAdminCurItem('class_add');
  68. $parent_id = input('param.vrgclass_parent_id');
  69. View::assign('vrgclass_parent_id', !empty($parent_id) ? intval($parent_id) : 0);
  70. return View::fetch('class_form');
  71. }
  72. }
  73. /*
  74. * 编辑分类
  75. */
  76. public function class_edit()
  77. {
  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. {
  126. $vrgclass_id = input('param.vrgclass_id');
  127. $vrgclass_id_array = ds_delete_param($vrgclass_id);
  128. if ($vrgclass_id_array == FALSE) {
  129. ds_json_encode(10001, lang('param_error'));
  130. }
  131. $vrgroupbuy_model = model('vrgroupbuyclass');
  132. foreach ($vrgclass_id_array as $val) {
  133. $class = $vrgroupbuy_model->getVrgroupbuyclassInfo(array('vrgclass_id' => $val));
  134. if ($class['vrgclass_parent_id'] == 0) {
  135. $class = $vrgroupbuy_model->delVrgroupbuyclass(array('vrgclass_parent_id' => $class['vrgclass_id']));
  136. }
  137. $class = $vrgroupbuy_model->delVrgroupbuyclass(array('vrgclass_id' => $val));
  138. }
  139. // 删除虚拟抢购分类缓存
  140. model('groupbuy')->dropCachedData('groupbuy_vr_classes');
  141. $this->log('删除虚拟抢购分类[ID:' . input('post.vrgclass_id') . ']', 1);
  142. ds_json_encode(10000, lang('ds_common_del_succ'));
  143. }
  144. public function ajax()
  145. {
  146. $field = input('param.column');
  147. $id = input('param.id');
  148. $value = input('param.value');
  149. switch (input('param.column')) {
  150. case 'vrgclass_name':
  151. if (mb_strlen((string) $value, 'utf-8') > 10)
  152. return;
  153. break;
  154. case 'vrgclass_sort':
  155. if ($value < 0 || $value > 255)
  156. return;
  157. break;
  158. default:
  159. return;
  160. }
  161. switch (input('param.branch')) {
  162. case 'class':
  163. $vrgroupbuyclass_model = model('vrgroupbuyclass');
  164. $res = $vrgroupbuyclass_model->editVrgroupbuyclass(array('vrgclass_id' => $id), array($field => $value));
  165. if ($res) {
  166. // 删除虚拟抢购分类缓存
  167. model('groupbuy')->dropCachedData('groupbuy_vr_classes');
  168. $this->log('编辑虚拟抢购分类[ID:' . $id . ']', 1);
  169. echo 'true';
  170. } else {
  171. echo 'false';
  172. }
  173. exit;
  174. default:
  175. return;
  176. }
  177. }
  178. protected function getAdminItemList()
  179. {
  180. $menu_array = array(
  181. array(
  182. 'name' => 'index', 'text' => lang('vrgroupbuy_cate_manage'), 'url' => (string)url('Vrgroupbuy/index')
  183. ), array(
  184. 'name' => 'class_add', 'text' => lang('vrgclass_add'), 'url' => "javascript:dsLayerOpen('" . (string)url('Vrgroupbuy/class_add') . "','" . lang('vrgclass_add') . "')"
  185. )
  186. );
  187. return $menu_array;
  188. }
  189. }