SellerService.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. use think\facade\Db;
  6. /**
  7. * ============================================================================
  8. * DSO2O多用户商城
  9. * ============================================================================
  10. *
  11. * ----------------------------------------------------------------------------
  12. *
  13. * ============================================================================
  14. * 控制器
  15. */
  16. class SellerService extends BaseSeller
  17. {
  18. public function initialize()
  19. {
  20. parent::initialize();
  21. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/seller_service.lang.php');
  22. }
  23. public function index()
  24. {
  25. $store_service_model = model('store_service');
  26. $condition = array();
  27. $condition[] = array('store_id', '=', session('store_id'));
  28. $store_service_list = $store_service_model->getStoreServiceList($condition, '*', 10);
  29. View::assign('store_service_list', $store_service_list);
  30. View::assign('show_page', $store_service_model->page_info->render());
  31. /* 设置卖家当前菜单 */
  32. $this->setSellerCurMenu('seller_service');
  33. /* 设置卖家当前栏目 */
  34. $this->setSellerCurItem('store_service_list');
  35. return View::fetch($this->template_dir . 'index');
  36. }
  37. public function add()
  38. {
  39. if (!request()->isPost()) {
  40. $this->setSellerCurMenu('seller_service');
  41. $this->setSellerCurItem('add');
  42. return View::fetch($this->template_dir . 'form');
  43. } else {
  44. $store_service_model = model('store_service');
  45. //不能添加超过20个
  46. if (Db::name('store_service')->where(array(array('store_id', '=', session('store_id'))))->count() >= 20) {
  47. ds_json_encode(10001, lang('store_service_count_error'));
  48. }
  49. $data = $this->post_data();
  50. $data['store_id'] = session('store_id');
  51. $store_service_validate = ds_validate('store_service');
  52. if (!$store_service_validate->scene('add')->check($data)) {
  53. ds_json_encode(10001, $store_service_validate->getError());
  54. }
  55. $result = $store_service_model->addStoreService($data);
  56. if ($result) {
  57. $this->recordSellerlog(lang('ds_new') . lang('seller_service') . '[' . $data['store_service_title'] . ']', 1);
  58. ds_json_encode(10000, lang('ds_common_save_succ'));
  59. } else {
  60. ds_json_encode(10001, lang('ds_common_save_fail'));
  61. }
  62. }
  63. }
  64. public function edit()
  65. {
  66. $id = intval(input('param.id'));
  67. if (!$id) {
  68. $this->error(lang('param_error'));
  69. }
  70. $store_service_model = model('store_service');
  71. $store_service_info = $store_service_model->getStoreServiceInfo(array('store_service_id' => $id, 'store_id' => session('store_id')));
  72. if (!$store_service_info) {
  73. $this->error(lang('store_service_empty'));
  74. }
  75. if (!request()->isPost()) {
  76. View::assign('store_service_info', $store_service_info);
  77. $this->setSellerCurMenu('seller_service');
  78. $this->setSellerCurItem('edit');
  79. return View::fetch($this->template_dir . 'form');
  80. } else {
  81. $data = $this->post_data();
  82. $store_service_validate = ds_validate('store_service');
  83. if (!$store_service_validate->scene('edit')->check($data)) {
  84. ds_json_encode(10001, $store_service_validate->getError());
  85. }
  86. $result = $store_service_model->editStoreService($data, array('store_service_id' => $id, 'store_id' => session('store_id')));
  87. if ($result) {
  88. $this->recordSellerlog(lang('ds_edit') . lang('seller_service') . '[' . $store_service_info['store_service_title'] . ']', 1);
  89. ds_json_encode(10000, lang('ds_common_save_succ'));
  90. } else {
  91. ds_json_encode(10001, lang('ds_common_save_fail'));
  92. }
  93. }
  94. }
  95. public function del()
  96. {
  97. $id = intval(input('param.id'));
  98. if (!$id) {
  99. ds_json_encode(10001, lang('param_error'));
  100. }
  101. $store_service_model = model('store_service');
  102. $store_service_info = $store_service_model->getStoreServiceInfo(array('store_service_id' => $id, 'store_id' => session('store_id')));
  103. if (!$store_service_info) {
  104. ds_json_encode(10001, lang('store_service_empty'));
  105. }
  106. $result = $store_service_model->delStoreService(array('store_service_id' => $id, 'store_id' => session('store_id')), array($store_service_info));
  107. if (!$result) {
  108. ds_json_encode(10001, lang('ds_common_del_fail'));
  109. } else {
  110. $this->recordSellerlog(lang('ds_del') . lang('seller_service') . '[' . $store_service_info['store_service_title'] . ']', 1);
  111. ds_json_encode(10000, lang('ds_common_del_succ'));
  112. }
  113. }
  114. public function post_data()
  115. {
  116. $data = array(
  117. 'store_service_title' => input('post.store_service_title'),
  118. 'store_service_desc' => input('post.store_service_desc'),
  119. 'store_service_sort' => input('post.store_service_sort'),
  120. );
  121. return $data;
  122. }
  123. /**
  124. * 栏目菜单
  125. */
  126. function getSellerItemList()
  127. {
  128. $menu_array[] = array(
  129. 'name' => 'store_service_list',
  130. 'text' => lang('seller_service'),
  131. 'url' => url('seller_service/index'),
  132. );
  133. return $menu_array;
  134. }
  135. }