Vrgroupbuy.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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 Vrgroupbuy extends AdminControl {
  17. public function initialize() {
  18. parent::initialize(); // TODO: Change the autogenerated stub
  19. Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/vrgroupbuy.lang.php');
  20. }
  21. /*
  22. * 列表分类
  23. */
  24. public function index() {
  25. $vrgroupbuyclass_model = model('vrgroupbuyclass');
  26. $vrgroupbuyclass_list = $vrgroupbuyclass_model->getVrgroupbuyclassList();
  27. View::assign('vrgroupbuyclass_list', $vrgroupbuyclass_list);
  28. $this->setAdminCurItem('index');
  29. return View::fetch();
  30. }
  31. /*
  32. * 添加分类
  33. */
  34. public function class_add() {
  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. if (request()->isPost()) {
  78. // 数据验证
  79. $data = [
  80. 'vrgclass_name' => input('post.vrgclass_name'),
  81. 'vrgclass_sort' => input('post.vrgclass_sort'),
  82. ];
  83. $vrgroupbuy_validate = ds_validate('vrgroupbuy');
  84. if (!$vrgroupbuy_validate->scene('class_edit')->check($data)) {
  85. $this->error($vrgroupbuy_validate->getError());
  86. }
  87. $params = array();
  88. $params['vrgclass_name'] = trim(input('post.vrgclass_name'));
  89. $params['vrgclass_sort'] = intval(input('post.vrgclass_sort'));
  90. if (intval(input('post.vrgclass_parent_id')) > 0) {
  91. $params['vrgclass_parent_id'] = input('post.vrgclass_parent_id');
  92. } else {
  93. $params['vrgclass_parent_id'] = 0;
  94. }
  95. $condition = array(); //条件
  96. $condition[] = array('vrgclass_id','=',intval(input('param.vrgclass_id')));
  97. $vrgroupbuyclass_model = model('vrgroupbuyclass');
  98. $result = $vrgroupbuyclass_model->editVrgroupbuyclass($condition, $params);
  99. if ($result >= 0) {
  100. // 删除虚拟抢购分类缓存
  101. model('groupbuy')->dropCachedData('groupbuyvrclasses');
  102. $this->log('编辑虚拟抢购分类[ID:' . intval(input('param.vrgclass_id')) . ']', 1);
  103. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  104. } else {
  105. $this->error(lang('ds_common_op_fail'));
  106. }
  107. } else {
  108. $vrgroupbuyclass_model = model('vrgroupbuyclass'); //分类信息
  109. $class = $vrgroupbuyclass_model->getVrgroupbuyclassInfo(array('vrgclass_id' => intval(input('param.vrgclass_id'))));
  110. if (empty($class)) {
  111. $this->error(lang('vrgclass_not_exist'));
  112. }
  113. View::assign('class', $class);
  114. $vrgroupbuyclass_list = $vrgroupbuyclass_model->getVrgroupbuyclassList(array('vrgclass_parent_id' => 0));
  115. View::assign('vrgroupbuyclass_list', $vrgroupbuyclass_list);
  116. $this->setAdminCurItem('class_edit');
  117. return View::fetch('class_form');
  118. }
  119. }
  120. /*
  121. * 删除分类
  122. */
  123. public function class_del() {
  124. $vrgclass_id = input('param.vrgclass_id');
  125. $vrgclass_id_array = ds_delete_param($vrgclass_id);
  126. if ($vrgclass_id_array == FALSE) {
  127. ds_json_encode(10001, lang('param_error'));
  128. }
  129. $vrgroupbuy_model = model('vrgroupbuyclass');
  130. foreach ($vrgclass_id_array as $val) {
  131. $class = $vrgroupbuy_model->getVrgroupbuyclassInfo(array('vrgclass_id' => $val));
  132. if ($class['vrgclass_parent_id'] == 0) {
  133. $class = $vrgroupbuy_model->delVrgroupbuyclass(array('vrgclass_parent_id' => $class['vrgclass_id']));
  134. }
  135. $class = $vrgroupbuy_model->delVrgroupbuyclass(array('vrgclass_id' => $val));
  136. }
  137. // 删除虚拟抢购分类缓存
  138. model('groupbuy')->dropCachedData('groupbuy_vr_classes');
  139. $this->log('删除虚拟抢购分类[ID:' . input('post.vrgclass_id') . ']', 1);
  140. ds_json_encode(10000, lang('ds_common_del_succ'));
  141. }
  142. public function ajax() {
  143. $field = input('param.column');
  144. $id = input('param.id');
  145. $value = input('param.value');
  146. switch (input('param.column')) {
  147. case 'vrgclass_name':
  148. if (mb_strlen((string) $value, 'utf-8') > 10)
  149. return;
  150. break;
  151. case 'vrgclass_sort':
  152. if ($value < 0 || $value > 255)
  153. return;
  154. break;
  155. default:
  156. return;
  157. }
  158. switch (input('param.branch')) {
  159. case 'class':
  160. $vrgroupbuyclass_model = model('vrgroupbuyclass');
  161. $res = $vrgroupbuyclass_model->editVrgroupbuyclass(array('vrgclass_id' => $id), array($field => $value));
  162. if ($res) {
  163. // 删除虚拟抢购分类缓存
  164. model('groupbuy')->dropCachedData('groupbuy_vr_classes');
  165. $this->log('编辑虚拟抢购分类[ID:' . $id . ']', 1);
  166. echo 'true';
  167. } else {
  168. echo 'false';
  169. }
  170. exit;
  171. default:
  172. return;
  173. }
  174. }
  175. protected function getAdminItemList() {
  176. $menu_array = array(
  177. array(
  178. 'name' => 'index', 'text' => lang('vrgroupbuy_cate_manage'), 'url' => (string)url('Vrgroupbuy/index')
  179. ), array(
  180. 'name' => 'class_add', 'text' => lang('vrgclass_add'), 'url' => "javascript:dsLayerOpen('".(string)url('Vrgroupbuy/class_add')."','".lang('vrgclass_add')."')"
  181. )
  182. );
  183. return $menu_array;
  184. }
  185. }