Spec.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 Spec extends AdminControl {
  19. public function initialize() {
  20. parent::initialize();
  21. Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/spec.lang.php');
  22. }
  23. public function index() {
  24. /**
  25. * 查询条件
  26. */
  27. $where = array();
  28. $sp_name = trim(input('param.sp_name'));
  29. if ($sp_name != '') {
  30. $where[]=array('sp_name','like', '%' . $sp_name . '%');
  31. }
  32. $gc_name = trim(input('param.gc_name'));
  33. if ($gc_name != '') {
  34. $where[]=array('gc_name','like', '%' . $gc_name . '%');
  35. }
  36. $spec_model = model('spec');
  37. $spec_list = $spec_model->getSpecList($where, 10);
  38. View::assign('spec_list', $spec_list);
  39. View::assign('show_page', $spec_model->page_info->render());
  40. $this->setAdminCurItem('index');
  41. return View::fetch();
  42. }
  43. public function spec_add() {
  44. if (!(request()->isPost())) {
  45. $spec = [
  46. 'gc_id' => 0,
  47. ];
  48. View::assign('spec', $spec);
  49. $gc_list = model('goodsclass')->getGoodsclassListByParentId(0);
  50. View::assign('gc_list', $gc_list);
  51. return View::fetch('spec_form');
  52. } else {
  53. $data = array(
  54. 'sp_name' => input('post.sp_name'),
  55. 'sp_sort' => input('post.sp_sort'),
  56. 'gc_id' => input('post.gc_id'),
  57. 'gc_name' => input('post.gc_name'),
  58. );
  59. $spec_validate = ds_validate('spec');
  60. if (!$spec_validate->scene('spec_add')->check($data)) {
  61. $this->error($spec_validate->getError());
  62. }
  63. $spec_model= model('spec');
  64. $result=$spec_model->addSpec($data);
  65. if ($result) {
  66. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  67. } else {
  68. $this->error(lang('error'));
  69. }
  70. }
  71. }
  72. public function spec_edit() {
  73. //注:pathinfo地址参数不能通过get方法获取,查看“获取PARAM变量”
  74. $sp_id = input('param.sp_id');
  75. if (empty($sp_id)) {
  76. $this->error(lang('param_error'));
  77. }
  78. if (!request()->isPost()) {
  79. $spec_model= model('spec');
  80. $spec=$spec_model->getSpecInfo($sp_id);
  81. View::assign('spec', $spec);
  82. $gc_list = model('goodsclass')->getGoodsclassListByParentId(0);
  83. View::assign('gc_list', $gc_list);
  84. return View::fetch('spec_form');
  85. } else {
  86. $data = array(
  87. 'sp_name' => input('post.sp_name'),
  88. 'sp_sort' => input('post.sp_sort'),
  89. 'gc_id' => input('post.gc_id'),
  90. 'gc_name' => input('post.gc_name'),
  91. );
  92. $spec_validate = ds_validate('spec');
  93. if (!$spec_validate->scene('spec_edit')->check($data)) {
  94. $this->error($spec_validate->getError());
  95. }
  96. $spec_model= model('spec');
  97. $condition=array();
  98. $condition[] = array('sp_id','=',$sp_id);
  99. $result=$spec_model->editSpec($data, $condition);
  100. if ($result>=0) {
  101. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  102. } else {
  103. $this->error(lang('ds_common_op_fail'));
  104. }
  105. }
  106. }
  107. public function spec_drop() {
  108. //注:pathinfo地址参数不能通过get方法获取,查看“获取PARAM变量”
  109. $sp_id = intval(input('param.sp_id'));
  110. // sp_id 值为1 不能删除,用于处理前台显示图片的规格
  111. if ($sp_id<=1) {
  112. $this->error(lang('param_error'));
  113. }
  114. $spec_model = model('spec');
  115. $result=$spec_model->delSpec(array('sp_id' => $sp_id));
  116. if ($result) {
  117. ds_json_encode(10000, lang('ds_common_del_succ'));
  118. } else {
  119. ds_json_encode(10001, lang('ds_common_del_fail'));
  120. }
  121. }
  122. /**
  123. * 获取卖家栏目列表,针对控制器下的栏目
  124. */
  125. protected function getAdminItemList() {
  126. $menu_array = array(
  127. array(
  128. 'name' => 'index',
  129. 'text' => lang('ds_spec'),
  130. 'url' => (string)url('Spec/index')
  131. ),
  132. array(
  133. 'name' => 'spec_add',
  134. 'text' => lang('ds_new'),
  135. 'url' => "javascript:dsLayerOpen('".(string)url('Spec/spec_add')."','".lang('ds_new')."')"
  136. ),
  137. );
  138. return $menu_array;
  139. }
  140. }