Spec.php 5.3 KB

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