Storeclass.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <?php
  2. /**
  3. * 店铺分类
  4. */
  5. namespace app\admin\controller;
  6. use think\facade\View;
  7. use think\facade\Lang;
  8. /**
  9. * ============================================================================
  10. * DSMall多用户商城
  11. * ============================================================================
  12. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  13. * 网站地址: http://www.csdeshang.com
  14. * ----------------------------------------------------------------------------
  15. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  16. * 不允许对程序代码以任何形式任何目的的再发布。
  17. * ============================================================================
  18. * 控制器
  19. */
  20. class Storeclass extends AdminControl {
  21. public function initialize() {
  22. parent::initialize();
  23. Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/storeclass.lang.php');
  24. }
  25. /**
  26. * 店铺分类
  27. */
  28. public function store_class() {
  29. $storeclass_model = model('storeclass');
  30. $store_class_list = $storeclass_model->getStoreclassList(array(), 20);
  31. View::assign('class_list', $store_class_list);
  32. View::assign('show_page', $storeclass_model->page_info->render());
  33. $this->setAdminCurItem('store_class');
  34. return View::fetch('index');
  35. }
  36. /**
  37. * 商品分类添加
  38. */
  39. public function store_class_add() {
  40. $storeclass_model = model('storeclass');
  41. if (!request()->isPost()) {
  42. $this->setAdminCurItem('store_class_add');
  43. return View::fetch('form');
  44. } else {
  45. $insert_array = array();
  46. $insert_array['storeclass_name'] = input('post.storeclass_name');
  47. $insert_array['storeclass_bail'] = intval(input('post.storeclass_bail'));
  48. $insert_array['storeclass_sort'] = intval(input('post.storeclass_sort'));
  49. $storeclass_validate = ds_validate('storeclass');
  50. if (!$storeclass_validate->scene('store_class_add')->check($insert_array)){
  51. $this->error($storeclass_validate->getError());
  52. }
  53. $result = $storeclass_model->addStoreclass($insert_array);
  54. if ($result) {
  55. $this->log(lang('ds_add') . lang('store_class') . '[' . input('post.storeclass_name') . ']', 1);
  56. dsLayerOpenSuccess(lang('ds_common_save_succ'),(string)url('Storeclass/store_class'));
  57. } else {
  58. $this->error(lang('ds_common_save_fail'));
  59. }
  60. }
  61. }
  62. /**
  63. * 编辑
  64. */
  65. public function store_class_edit() {
  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. $storeclass_model = model('storeclass');
  98. $storeclass_id = input('param.storeclass_id');
  99. $storeclass_id_array = ds_delete_param($storeclass_id);
  100. if ($storeclass_id_array === FALSE) {
  101. ds_json_encode('10001', lang('param_error'));
  102. }
  103. $condition = array();
  104. $condition[]=array('storeclass_id','in', $storeclass_id_array);
  105. $result = $storeclass_model->delStoreclass($condition);
  106. if ($result) {
  107. $this->log(lang('ds_del') . lang('store_class') . '[ID:' . $storeclass_id . ']', 1);
  108. ds_json_encode(10000, lang('ds_common_del_succ'));
  109. }
  110. }
  111. /**
  112. * ajax操作
  113. */
  114. public function ajax() {
  115. $storeclass_model = model('storeclass');
  116. $update_array = array();
  117. $branch = input('param.branch');
  118. switch ($branch) {
  119. //分类:验证是否有重复的名称
  120. case 'store_class_name':
  121. $condition = array();
  122. $condition[]=array('storeclass_name','=',input('get.value'));
  123. $condition[]=array('storeclass_id','<>', intval(input('param.id')));
  124. $class_list = $storeclass_model->getStoreclassList($condition);
  125. if (empty($class_list)) {
  126. $update_array['storeclass_name'] = input('get.value');
  127. $update = $storeclass_model->editStoreclass($update_array, array('storeclass_id' => intval(input('param.id'))));
  128. $return = 'true';
  129. } else {
  130. $return = 'false';
  131. }
  132. break;
  133. //分类: 排序 显示 设置
  134. case 'store_class_sort':
  135. $update_array['storeclass_sort'] = intval(input('get.value'));
  136. $result = $storeclass_model->editStoreclass($update_array, array('storeclass_id' => intval(input('param.id'))));
  137. $return = 'true';
  138. break;
  139. //分类:添加、修改操作中 检测类别名称是否有重复
  140. case 'check_class_name':
  141. $condition[]=array('storeclass_name','=',input('get.storeclass_name'));
  142. $class_list = $storeclass_model->getStoreclassList($condition);
  143. $return = empty($class_list) ? 'true' : 'false';
  144. break;
  145. }
  146. exit($return);
  147. }
  148. /**
  149. * 获取卖家栏目列表,针对控制器下的栏目
  150. */
  151. protected function getAdminItemList() {
  152. $menu_array = array(
  153. array(
  154. 'name' => 'store_class',
  155. 'text' => lang('ds_storeclass'),
  156. 'url' => (string)url('Storeclass/store_class')
  157. ),
  158. array(
  159. 'name' => 'store_class_add',
  160. 'text' => lang('ds_new'),
  161. 'url' => "javascript:dsLayerOpen('".(string)url('Storeclass/store_class_add')."','".lang('ds_new')."')"
  162. )
  163. );
  164. return $menu_array;
  165. }
  166. }
  167. ?>