Storeclass.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <?php
  2. /**
  3. * 店铺分类
  4. */
  5. namespace app\admin\controller;
  6. use think\facade\View;
  7. use think\facade\Lang;
  8. /**
  9. *
  10. *
  11. * ----------------------------------------------------------------------------
  12. *
  13. * 控制器
  14. */
  15. class Storeclass extends AdminControl
  16. {
  17. public function initialize()
  18. {
  19. parent::initialize();
  20. Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/storeclass.lang.php');
  21. }
  22. /**
  23. * 店铺分类
  24. */
  25. public function store_class()
  26. {
  27. $storeclass_model = model('storeclass');
  28. $store_class_list = $storeclass_model->getStoreclassList(array(), 20);
  29. View::assign('class_list', $store_class_list);
  30. View::assign('show_page', $storeclass_model->page_info->render());
  31. $this->setAdminCurItem('store_class');
  32. return View::fetch('index');
  33. }
  34. /**
  35. * 商品分类添加
  36. */
  37. public function store_class_add()
  38. {
  39. $storeclass_model = model('storeclass');
  40. if (!request()->isPost()) {
  41. $this->setAdminCurItem('store_class_add');
  42. return View::fetch('form');
  43. } else {
  44. $insert_array = array();
  45. $insert_array['storeclass_name'] = input('post.storeclass_name');
  46. $insert_array['storeclass_bail'] = intval(input('post.storeclass_bail'));
  47. $insert_array['storeclass_sort'] = intval(input('post.storeclass_sort'));
  48. $storeclass_validate = ds_validate('storeclass');
  49. if (!$storeclass_validate->scene('store_class_add')->check($insert_array)) {
  50. $this->error($storeclass_validate->getError());
  51. }
  52. $result = $storeclass_model->addStoreclass($insert_array);
  53. if ($result) {
  54. $this->log(lang('ds_add') . lang('store_class') . '[' . input('post.storeclass_name') . ']', 1);
  55. dsLayerOpenSuccess(lang('ds_common_save_succ'), (string)url('Storeclass/store_class'));
  56. } else {
  57. $this->error(lang('ds_common_save_fail'));
  58. }
  59. }
  60. }
  61. /**
  62. * 编辑
  63. */
  64. public function store_class_edit()
  65. {
  66. $storeclass_model = model('storeclass');
  67. if (!request()->isPost()) {
  68. $storeclass = $storeclass_model->getStoreclassInfo(array('storeclass_id' => intval(input('param.storeclass_id'))));
  69. if (empty($storeclass)) {
  70. $this->error(lang('illegal_parameter'));
  71. }
  72. View::assign('storeclass', $storeclass);
  73. $this->setAdminCurItem('store_class_edit');
  74. return View::fetch('form');
  75. } else {
  76. $update_array = array();
  77. $update_array['storeclass_name'] = input('post.storeclass_name');
  78. $update_array['storeclass_bail'] = intval(input('post.storeclass_bail'));
  79. $update_array['storeclass_sort'] = intval(input('post.storeclass_sort'));
  80. $storeclass_validate = ds_validate('storeclass');
  81. if (!$storeclass_validate->scene('store_class_edit')->check($update_array)) {
  82. $this->error($storeclass_validate->getError());
  83. }
  84. $result = $storeclass_model->editStoreclass($update_array, array('storeclass_id' => intval(input('param.storeclass_id'))));
  85. if ($result >= 0) {
  86. $this->log(lang('ds_edit') . lang('store_class') . '[' . input('post.storeclass_name') . ']', 1);
  87. dsLayerOpenSuccess(lang('ds_common_save_succ'), (string)url('Storeclass/store_class'));
  88. } else {
  89. $this->error(lang('ds_common_save_fail'));
  90. }
  91. }
  92. }
  93. /**
  94. * 删除分类
  95. */
  96. public function store_class_del()
  97. {
  98. $storeclass_model = model('storeclass');
  99. $storeclass_id = input('param.storeclass_id');
  100. $storeclass_id_array = ds_delete_param($storeclass_id);
  101. if ($storeclass_id_array === FALSE) {
  102. ds_json_encode('10001', lang('param_error'));
  103. }
  104. $condition = array();
  105. $condition[] = array('storeclass_id', 'in', $storeclass_id_array);
  106. $result = $storeclass_model->delStoreclass($condition);
  107. if ($result) {
  108. $this->log(lang('ds_del') . lang('store_class') . '[ID:' . $storeclass_id . ']', 1);
  109. ds_json_encode(10000, lang('ds_common_del_succ'));
  110. }
  111. }
  112. /**
  113. * ajax操作
  114. */
  115. public function ajax()
  116. {
  117. $storeclass_model = model('storeclass');
  118. $update_array = array();
  119. $branch = input('param.branch');
  120. switch ($branch) {
  121. //分类:验证是否有重复的名称
  122. case 'store_class_name':
  123. $condition = array();
  124. $condition[] = array('storeclass_name', '=', input('get.value'));
  125. $condition[] = array('storeclass_id', '<>', intval(input('param.id')));
  126. $class_list = $storeclass_model->getStoreclassList($condition);
  127. if (empty($class_list)) {
  128. $update_array['storeclass_name'] = input('get.value');
  129. $update = $storeclass_model->editStoreclass($update_array, array('storeclass_id' => intval(input('param.id'))));
  130. $return = 'true';
  131. } else {
  132. $return = 'false';
  133. }
  134. break;
  135. //分类: 排序 显示 设置
  136. case 'store_class_sort':
  137. $update_array['storeclass_sort'] = intval(input('get.value'));
  138. $result = $storeclass_model->editStoreclass($update_array, array('storeclass_id' => intval(input('param.id'))));
  139. $return = 'true';
  140. break;
  141. //分类:添加、修改操作中 检测类别名称是否有重复
  142. case 'check_class_name':
  143. $condition[] = array('storeclass_name', '=', input('get.storeclass_name'));
  144. $class_list = $storeclass_model->getStoreclassList($condition);
  145. $return = empty($class_list) ? 'true' : 'false';
  146. break;
  147. }
  148. exit($return);
  149. }
  150. /**
  151. * 获取卖家栏目列表,针对控制器下的栏目
  152. */
  153. protected function getAdminItemList()
  154. {
  155. $menu_array = array(
  156. array(
  157. 'name' => 'store_class',
  158. 'text' => lang('ds_storeclass'),
  159. 'url' => (string)url('Storeclass/store_class')
  160. ),
  161. array(
  162. 'name' => 'store_class_add',
  163. 'text' => lang('ds_new'),
  164. 'url' => "javascript:dsLayerOpen('" . (string)url('Storeclass/store_class_add') . "','" . lang('ds_new') . "')"
  165. )
  166. );
  167. return $menu_array;
  168. }
  169. }