Sellernavigation.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?php
  2. /**
  3. * 导航栏
  4. * Date: 2017/6/27
  5. * Time: 17:01
  6. */
  7. namespace app\home\controller;
  8. use think\facade\View;
  9. /**
  10. *
  11. *
  12. * ----------------------------------------------------------------------------
  13. *
  14. * 控制器
  15. */
  16. class Sellernavigation extends BaseSeller
  17. {
  18. public function initialize()
  19. {
  20. parent::initialize(); // TODO: Change the autogenerated stub
  21. }
  22. /**
  23. *导航列表
  24. */
  25. public function index()
  26. {
  27. $storenavigation_model = model('storenavigation');
  28. $navigation_list = $storenavigation_model->getStorenavigationList(array('storenav_store_id' => session('store_id')));
  29. View::assign('navigation_list', $navigation_list);
  30. /* 设置卖家当前菜单 */
  31. $this->setSellerCurMenu('seller_navigation');
  32. /* 设置卖家当前栏目 */
  33. $this->setSellerCurItem('store_navigation');
  34. return View::fetch($this->template_dir . 'index');
  35. }
  36. public function navigation_add()
  37. {
  38. /* 设置卖家当前菜单 */
  39. $this->setSellerCurMenu('seller_navigation');
  40. /* 设置卖家当前栏目 */
  41. $this->setSellerCurItem('navigation_add');
  42. /* 所见即所得编辑器 */
  43. View::assign('build_editor', build_editor(array(
  44. 'name' => 'storenav_content',
  45. )));
  46. $sn_info = array(
  47. 'storenav_id' => '',
  48. 'storenav_title' => '',
  49. 'storenav_sort' => '',
  50. 'storenav_url' => '',
  51. );
  52. View::assign('sn_info', $sn_info);
  53. return View::fetch($this->template_dir . 'navigation_form');
  54. }
  55. public function navigation_edit()
  56. {
  57. $storenav_id = intval(input('param.storenav_id'));
  58. if ($storenav_id <= 0) {
  59. $this->error(lang('param_error'));
  60. }
  61. $storenavigation_model = model('storenavigation');
  62. $sn_info = $storenavigation_model->getStorenavigationInfo(array('storenav_id' => $storenav_id));
  63. if (empty($sn_info) || intval($sn_info['storenav_store_id']) !== intval(session('store_id'))) {
  64. $this->error(lang('param_error'));
  65. }
  66. View::assign('sn_info', $sn_info);
  67. /* 所见即所得编辑器 */
  68. View::assign('build_editor', build_editor(array(
  69. 'name' => 'storenav_content',
  70. 'content' => htmlspecialchars_decode($sn_info['storenav_content']),
  71. )));
  72. $this->setSellerCurMenu('seller_navigation');
  73. /* 设置卖家当前栏目 */
  74. $this->setSellerCurItem('navigation_edit');
  75. return View::fetch($this->template_dir . 'navigation_form');
  76. }
  77. public function navigation_save()
  78. {
  79. $sn_info = array(
  80. 'storenav_title' => input('post.storenav_title'),
  81. 'storenav_content' => input('post.storenav_content'),
  82. 'storenav_sort' => empty(input('post.storenav_sort')) ? 255 : input('post.storenav_sort'),
  83. 'storenav_url' => input('post.storenav_url'),
  84. 'storenav_store_id' => session('store_id'),
  85. );
  86. $storenavigation_model = model('storenavigation');
  87. $storenav_id = input('post.storenav_id');
  88. if (!empty($storenav_id) && intval($storenav_id) > 0) {
  89. $condition = array('storenav_id' => $storenav_id);
  90. $result = $storenavigation_model->editStorenavigation($sn_info, $condition);
  91. } else {
  92. $result = $storenavigation_model->addStorenavigation($sn_info);
  93. }
  94. if ($result) {
  95. ds_json_encode(10000, lang('ds_common_op_succ'));
  96. } else {
  97. ds_json_encode(10001, lang('ds_common_op_fail'));
  98. }
  99. }
  100. public function navigation_del()
  101. {
  102. $storenav_id = intval(input('param.storenav_id'));
  103. if ($storenav_id > 0) {
  104. $condition = array(
  105. 'storenav_id' => $storenav_id,
  106. 'storenav_store_id' => session('store_id'),
  107. );
  108. $storenavigation_model = model('storenavigation');
  109. $storenavigation_model->delStorenavigation($condition);
  110. ds_json_encode(10000, lang('ds_common_op_succ'));
  111. } else {
  112. ds_json_encode(10001, lang('ds_common_op_fail'));
  113. }
  114. }
  115. /**
  116. * 用户中心右边,小导航
  117. *
  118. * @param string $menu_key 当前导航的menu_key
  119. * @return
  120. */
  121. function getSellerItemList()
  122. {
  123. $menu_array = array();
  124. $menu_array[] = array(
  125. 'name' => 'store_navigation',
  126. 'text' => lang('store_navigation'),
  127. 'url' => (string)url('Sellernavigation/index')
  128. );
  129. if (request()->action() == 'navigation_add') {
  130. $menu_array[] = array(
  131. 'name' => 'navigation_add',
  132. 'text' => lang('ds_new'),
  133. 'url' => (string)url('Sellernavigation/navigation_add')
  134. );
  135. }
  136. if (request()->action() == 'navigation_edit') {
  137. $menu_array[] = array(
  138. 'name' => 'navigation_edit',
  139. 'text' => lang('ds_edit'),
  140. 'url' => (string)url('Sellernavigation/navigation_edit')
  141. );
  142. }
  143. return $menu_array;
  144. }
  145. }