Vrgroupbuy.php 8.2 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. * ============================================================================
  13. * 控制器
  14. */
  15. class Vrgroupbuy 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') . '/vrgroupbuy.lang.php');
  21. }
  22. /*
  23. * 列表分类
  24. */
  25. public function index()
  26. {
  27. $vrgroupbuyclass_model = model('vrgroupbuyclass');
  28. $vrgroupbuyclass_list = $vrgroupbuyclass_model->getVrgroupbuyclassList();
  29. View::assign('vrgroupbuyclass_list', $vrgroupbuyclass_list);
  30. $this->setAdminCurItem('index');
  31. return View::fetch();
  32. }
  33. /*
  34. * 添加分类
  35. */
  36. public function class_add()
  37. {
  38. if (request()->isPost()) { //添加虚拟抢购分类
  39. // 数据验证
  40. $data = [
  41. 'vrgclass_name' => input('post.vrgclass_name'),
  42. 'vrgclass_sort' => input('post.vrgclass_sort'),
  43. ];
  44. $vrgroupbuy_validate = ds_validate('vrgroupbuy');
  45. if (!$vrgroupbuy_validate->scene('class_add')->check($data)) {
  46. $this->error($vrgroupbuy_validate->getError());
  47. }
  48. $params = array();
  49. $params['vrgclass_name'] = trim(input('post.vrgclass_name'));
  50. $params['vrgclass_sort'] = intval(input('post.vrgclass_sort'));
  51. if (intval(input('post.vrgclass_parent_id')) > 0) {
  52. $params['vrgclass_parent_id'] = input('post.vrgclass_parent_id');
  53. } else {
  54. $params['vrgclass_parent_id'] = 0;
  55. }
  56. $vrgroupbuyclass_model = model('vrgroupbuyclass');
  57. $res = $vrgroupbuyclass_model->addVrgroupbuyclass($params); //添加分类
  58. if ($res) {
  59. // 删除虚拟抢购分类缓存
  60. model('groupbuy')->dropCachedData('groupbuyvrclasses');
  61. $this->log('添加虚拟抢购分类[ID:' . $res . ']', 1);
  62. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  63. } else {
  64. $this->error(lang('ds_common_op_fail'));
  65. }
  66. } else {
  67. $vrgroupbuyclass_model = model('vrgroupbuyclass'); //一级分类
  68. $vrgroupbuyclass_list = $vrgroupbuyclass_model->getVrgroupbuyclassList(array('vrgclass_parent_id' => 0));
  69. View::assign('vrgroupbuyclass_list', $vrgroupbuyclass_list);
  70. $this->setAdminCurItem('class_add');
  71. $parent_id = input('param.vrgclass_parent_id');
  72. View::assign('vrgclass_parent_id', !empty($parent_id) ? intval($parent_id) : 0);
  73. return View::fetch('class_form');
  74. }
  75. }
  76. /*
  77. * 编辑分类
  78. */
  79. public function class_edit()
  80. {
  81. if (request()->isPost()) {
  82. // 数据验证
  83. $data = [
  84. 'vrgclass_name' => input('post.vrgclass_name'),
  85. 'vrgclass_sort' => input('post.vrgclass_sort'),
  86. ];
  87. $vrgroupbuy_validate = ds_validate('vrgroupbuy');
  88. if (!$vrgroupbuy_validate->scene('class_edit')->check($data)) {
  89. $this->error($vrgroupbuy_validate->getError());
  90. }
  91. $params = array();
  92. $params['vrgclass_name'] = trim(input('post.vrgclass_name'));
  93. $params['vrgclass_sort'] = intval(input('post.vrgclass_sort'));
  94. if (intval(input('post.vrgclass_parent_id')) > 0) {
  95. $params['vrgclass_parent_id'] = input('post.vrgclass_parent_id');
  96. } else {
  97. $params['vrgclass_parent_id'] = 0;
  98. }
  99. $condition = array(); //条件
  100. $condition[] = array('vrgclass_id', '=', intval(input('param.vrgclass_id')));
  101. $vrgroupbuyclass_model = model('vrgroupbuyclass');
  102. $result = $vrgroupbuyclass_model->editVrgroupbuyclass($condition, $params);
  103. if ($result >= 0) {
  104. // 删除虚拟抢购分类缓存
  105. model('groupbuy')->dropCachedData('groupbuyvrclasses');
  106. $this->log('编辑虚拟抢购分类[ID:' . intval(input('param.vrgclass_id')) . ']', 1);
  107. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  108. } else {
  109. $this->error(lang('ds_common_op_fail'));
  110. }
  111. } else {
  112. $vrgroupbuyclass_model = model('vrgroupbuyclass'); //分类信息
  113. $class = $vrgroupbuyclass_model->getVrgroupbuyclassInfo(array('vrgclass_id' => intval(input('param.vrgclass_id'))));
  114. if (empty($class)) {
  115. $this->error(lang('vrgclass_not_exist'));
  116. }
  117. View::assign('class', $class);
  118. $vrgroupbuyclass_list = $vrgroupbuyclass_model->getVrgroupbuyclassList(array('vrgclass_parent_id' => 0));
  119. View::assign('vrgroupbuyclass_list', $vrgroupbuyclass_list);
  120. $this->setAdminCurItem('class_edit');
  121. return View::fetch('class_form');
  122. }
  123. }
  124. /*
  125. * 删除分类
  126. */
  127. public function class_del()
  128. {
  129. $vrgclass_id = input('param.vrgclass_id');
  130. $vrgclass_id_array = ds_delete_param($vrgclass_id);
  131. if ($vrgclass_id_array == FALSE) {
  132. ds_json_encode(10001, lang('param_error'));
  133. }
  134. $vrgroupbuy_model = model('vrgroupbuyclass');
  135. foreach ($vrgclass_id_array as $val) {
  136. $class = $vrgroupbuy_model->getVrgroupbuyclassInfo(array('vrgclass_id' => $val));
  137. if ($class['vrgclass_parent_id'] == 0) {
  138. $class = $vrgroupbuy_model->delVrgroupbuyclass(array('vrgclass_parent_id' => $class['vrgclass_id']));
  139. }
  140. $class = $vrgroupbuy_model->delVrgroupbuyclass(array('vrgclass_id' => $val));
  141. }
  142. // 删除虚拟抢购分类缓存
  143. model('groupbuy')->dropCachedData('groupbuy_vr_classes');
  144. $this->log('删除虚拟抢购分类[ID:' . input('post.vrgclass_id') . ']', 1);
  145. ds_json_encode(10000, lang('ds_common_del_succ'));
  146. }
  147. public function ajax()
  148. {
  149. $field = input('param.column');
  150. $id = input('param.id');
  151. $value = input('param.value');
  152. switch (input('param.column')) {
  153. case 'vrgclass_name':
  154. if (mb_strlen((string) $value, 'utf-8') > 10)
  155. return;
  156. break;
  157. case 'vrgclass_sort':
  158. if ($value < 0 || $value > 255)
  159. return;
  160. break;
  161. default:
  162. return;
  163. }
  164. switch (input('param.branch')) {
  165. case 'class':
  166. $vrgroupbuyclass_model = model('vrgroupbuyclass');
  167. $res = $vrgroupbuyclass_model->editVrgroupbuyclass(array('vrgclass_id' => $id), array($field => $value));
  168. if ($res) {
  169. // 删除虚拟抢购分类缓存
  170. model('groupbuy')->dropCachedData('groupbuy_vr_classes');
  171. $this->log('编辑虚拟抢购分类[ID:' . $id . ']', 1);
  172. echo 'true';
  173. } else {
  174. echo 'false';
  175. }
  176. exit;
  177. default:
  178. return;
  179. }
  180. }
  181. protected function getAdminItemList()
  182. {
  183. $menu_array = array(
  184. array(
  185. 'name' => 'index', 'text' => lang('vrgroupbuy_cate_manage'), 'url' => (string)url('Vrgroupbuy/index')
  186. ), array(
  187. 'name' => 'class_add', 'text' => lang('vrgclass_add'), 'url' => "javascript:dsLayerOpen('" . (string)url('Vrgroupbuy/class_add') . "','" . lang('vrgclass_add') . "')"
  188. )
  189. );
  190. return $menu_array;
  191. }
  192. }