Storeclass.php 7.0 KB

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