Spec.php 5.0 KB

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