SellerService.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  11. * 网站地址: https://www.valimart.net/
  12. * ----------------------------------------------------------------------------
  13. *
  14. * ============================================================================
  15. * 控制器
  16. */
  17. class SellerService extends BaseSeller {
  18. public function initialize() {
  19. parent::initialize();
  20. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/seller_service.lang.php');
  21. }
  22. public function index() {
  23. $store_service_model = model('store_service');
  24. $condition = array();
  25. $condition[] = array('store_id','=',session('store_id'));
  26. $store_service_list = $store_service_model->getStoreServiceList($condition, '*', 10);
  27. View::assign('store_service_list', $store_service_list);
  28. View::assign('show_page', $store_service_model->page_info->render());
  29. /* 设置卖家当前菜单 */
  30. $this->setSellerCurMenu('seller_service');
  31. /* 设置卖家当前栏目 */
  32. $this->setSellerCurItem('store_service_list');
  33. return View::fetch($this->template_dir . 'index');
  34. }
  35. public function add() {
  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. $id = intval(input('param.id'));
  63. if (!$id) {
  64. $this->error(lang('param_error'));
  65. }
  66. $store_service_model = model('store_service');
  67. $store_service_info = $store_service_model->getStoreServiceInfo(array('store_service_id' => $id, 'store_id' => session('store_id')));
  68. if (!$store_service_info) {
  69. $this->error(lang('store_service_empty'));
  70. }
  71. if (!request()->isPost()) {
  72. View::assign('store_service_info', $store_service_info);
  73. $this->setSellerCurMenu('seller_service');
  74. $this->setSellerCurItem('edit');
  75. return View::fetch($this->template_dir . 'form');
  76. } else {
  77. $data = $this->post_data();
  78. $store_service_validate = ds_validate('store_service');
  79. if (!$store_service_validate->scene('edit')->check($data)) {
  80. ds_json_encode(10001, $store_service_validate->getError());
  81. }
  82. $result = $store_service_model->editStoreService($data, array('store_service_id' => $id, 'store_id' => session('store_id')));
  83. if ($result) {
  84. $this->recordSellerlog(lang('ds_edit') . lang('seller_service') . '[' . $store_service_info['store_service_title'] . ']', 1);
  85. ds_json_encode(10000, lang('ds_common_save_succ'));
  86. } else {
  87. ds_json_encode(10001, lang('ds_common_save_fail'));
  88. }
  89. }
  90. }
  91. public function del() {
  92. $id = intval(input('param.id'));
  93. if (!$id) {
  94. ds_json_encode(10001, lang('param_error'));
  95. }
  96. $store_service_model = model('store_service');
  97. $store_service_info = $store_service_model->getStoreServiceInfo(array('store_service_id' => $id, 'store_id' => session('store_id')));
  98. if (!$store_service_info) {
  99. ds_json_encode(10001, lang('store_service_empty'));
  100. }
  101. $result = $store_service_model->delStoreService(array('store_service_id' => $id, 'store_id' => session('store_id')), array($store_service_info));
  102. if (!$result) {
  103. ds_json_encode(10001, lang('ds_common_del_fail'));
  104. } else {
  105. $this->recordSellerlog(lang('ds_del') . lang('seller_service') . '[' . $store_service_info['store_service_title'] . ']', 1);
  106. ds_json_encode(10000, lang('ds_common_del_succ'));
  107. }
  108. }
  109. public function post_data() {
  110. $data = array(
  111. 'store_service_title' => input('post.store_service_title'),
  112. 'store_service_desc' => input('post.store_service_desc'),
  113. 'store_service_sort' => input('post.store_service_sort'),
  114. );
  115. return $data;
  116. }
  117. /**
  118. * 栏目菜单
  119. */
  120. function getSellerItemList() {
  121. $menu_array[] = array(
  122. 'name' => 'store_service_list',
  123. 'text' => lang('seller_service'),
  124. 'url' => url('seller_service/index'),
  125. );
  126. return $menu_array;
  127. }
  128. }