Spec.php 5.5 KB

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