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