Storeclass.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  13. * 网站地址: https://www.valimart.net/
  14. * ----------------------------------------------------------------------------
  15. *
  16. * ============================================================================
  17. * 控制器
  18. */
  19. class Storeclass extends AdminControl {
  20. public function initialize() {
  21. parent::initialize();
  22. Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/storeclass.lang.php');
  23. }
  24. /**
  25. * 店铺分类
  26. */
  27. public function store_class() {
  28. $storeclass_model = model('storeclass');
  29. $store_class_list = $storeclass_model->getStoreclassList(array(), 20);
  30. View::assign('class_list', $store_class_list);
  31. View::assign('show_page', $storeclass_model->page_info->render());
  32. $this->setAdminCurItem('store_class');
  33. return View::fetch('index');
  34. }
  35. /**
  36. * 商品分类添加
  37. */
  38. public function store_class_add() {
  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. $storeclass_model = model('storeclass');
  66. if (!request()->isPost()) {
  67. $storeclass = $storeclass_model->getStoreclassInfo(array('storeclass_id' => intval(input('param.storeclass_id'))));
  68. if (empty($storeclass)) {
  69. $this->error(lang('illegal_parameter'));
  70. }
  71. View::assign('storeclass', $storeclass);
  72. $this->setAdminCurItem('store_class_edit');
  73. return View::fetch('form');
  74. } else {
  75. $update_array = array();
  76. $update_array['storeclass_name'] = input('post.storeclass_name');
  77. $update_array['storeclass_bail'] = intval(input('post.storeclass_bail'));
  78. $update_array['storeclass_sort'] = intval(input('post.storeclass_sort'));
  79. $storeclass_validate = ds_validate('storeclass');
  80. if (!$storeclass_validate->scene('store_class_edit')->check($update_array)){
  81. $this->error($storeclass_validate->getError());
  82. }
  83. $result = $storeclass_model->editStoreclass($update_array, array('storeclass_id' => intval(input('param.storeclass_id'))));
  84. if ($result>=0) {
  85. $this->log(lang('ds_edit') . lang('store_class') . '[' . input('post.storeclass_name') . ']', 1);
  86. dsLayerOpenSuccess(lang('ds_common_save_succ'),(string)url('Storeclass/store_class'));
  87. } else {
  88. $this->error(lang('ds_common_save_fail'));
  89. }
  90. }
  91. }
  92. /**
  93. * 删除分类
  94. */
  95. public function store_class_del() {
  96. $storeclass_model = model('storeclass');
  97. $storeclass_id = input('param.storeclass_id');
  98. $storeclass_id_array = ds_delete_param($storeclass_id);
  99. if ($storeclass_id_array === FALSE) {
  100. ds_json_encode('10001', lang('param_error'));
  101. }
  102. $condition = array();
  103. $condition[]=array('storeclass_id','in', $storeclass_id_array);
  104. $result = $storeclass_model->delStoreclass($condition);
  105. if ($result) {
  106. $this->log(lang('ds_del') . lang('store_class') . '[ID:' . $storeclass_id . ']', 1);
  107. ds_json_encode(10000, lang('ds_common_del_succ'));
  108. }
  109. }
  110. /**
  111. * ajax操作
  112. */
  113. public function ajax() {
  114. $storeclass_model = model('storeclass');
  115. $update_array = array();
  116. $branch = input('param.branch');
  117. switch ($branch) {
  118. //分类:验证是否有重复的名称
  119. case 'store_class_name':
  120. $condition = array();
  121. $condition[]=array('storeclass_name','=',input('get.value'));
  122. $condition[]=array('storeclass_id','<>', intval(input('param.id')));
  123. $class_list = $storeclass_model->getStoreclassList($condition);
  124. if (empty($class_list)) {
  125. $update_array['storeclass_name'] = input('get.value');
  126. $update = $storeclass_model->editStoreclass($update_array, array('storeclass_id' => intval(input('param.id'))));
  127. $return = 'true';
  128. } else {
  129. $return = 'false';
  130. }
  131. break;
  132. //分类: 排序 显示 设置
  133. case 'store_class_sort':
  134. $update_array['storeclass_sort'] = intval(input('get.value'));
  135. $result = $storeclass_model->editStoreclass($update_array, array('storeclass_id' => intval(input('param.id'))));
  136. $return = 'true';
  137. break;
  138. //分类:添加、修改操作中 检测类别名称是否有重复
  139. case 'check_class_name':
  140. $condition[]=array('storeclass_name','=',input('get.storeclass_name'));
  141. $class_list = $storeclass_model->getStoreclassList($condition);
  142. $return = empty($class_list) ? 'true' : 'false';
  143. break;
  144. }
  145. exit($return);
  146. }
  147. /**
  148. * 获取卖家栏目列表,针对控制器下的栏目
  149. */
  150. protected function getAdminItemList() {
  151. $menu_array = array(
  152. array(
  153. 'name' => 'store_class',
  154. 'text' => lang('ds_storeclass'),
  155. 'url' => (string)url('Storeclass/store_class')
  156. ),
  157. array(
  158. 'name' => 'store_class_add',
  159. 'text' => lang('ds_new'),
  160. 'url' => "javascript:dsLayerOpen('".(string)url('Storeclass/store_class_add')."','".lang('ds_new')."')"
  161. )
  162. );
  163. return $menu_array;
  164. }
  165. }
  166. ?>