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