SellerService.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. * 网站地址: http://www.csdeshang.com
  12. * ----------------------------------------------------------------------------
  13. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  14. * 不允许对程序代码以任何形式任何目的的再发布。
  15. * ============================================================================
  16. * 控制器
  17. */
  18. class SellerService extends BaseSeller {
  19. public function initialize() {
  20. parent::initialize();
  21. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/seller_service.lang.php');
  22. }
  23. public function index() {
  24. $store_service_model = model('store_service');
  25. $condition = array();
  26. $condition[] = array('store_id','=',session('store_id'));
  27. $store_service_list = $store_service_model->getStoreServiceList($condition, '*', 10);
  28. View::assign('store_service_list', $store_service_list);
  29. View::assign('show_page', $store_service_model->page_info->render());
  30. /* 设置卖家当前菜单 */
  31. $this->setSellerCurMenu('seller_service');
  32. /* 设置卖家当前栏目 */
  33. $this->setSellerCurItem('store_service_list');
  34. return View::fetch($this->template_dir . 'index');
  35. }
  36. public function add() {
  37. if (!request()->isPost()) {
  38. $this->setSellerCurMenu('seller_service');
  39. $this->setSellerCurItem('add');
  40. return View::fetch($this->template_dir . 'form');
  41. } else {
  42. $store_service_model = model('store_service');
  43. //不能添加超过20个
  44. if(Db::name('store_service')->where(array(array('store_id','=',session('store_id'))))->count()>=20){
  45. ds_json_encode(10001, lang('store_service_count_error'));
  46. }
  47. $data = $this->post_data();
  48. $data['store_id'] = session('store_id');
  49. $store_service_validate = ds_validate('store_service');
  50. if (!$store_service_validate->scene('add')->check($data)) {
  51. ds_json_encode(10001, $store_service_validate->getError());
  52. }
  53. $result = $store_service_model->addStoreService($data);
  54. if ($result) {
  55. $this->recordSellerlog(lang('ds_new') . lang('seller_service') . '[' . $data['store_service_title'] . ']', 1);
  56. ds_json_encode(10000, lang('ds_common_save_succ'));
  57. } else {
  58. ds_json_encode(10001, lang('ds_common_save_fail'));
  59. }
  60. }
  61. }
  62. public function edit() {
  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. $id = intval(input('param.id'));
  94. if (!$id) {
  95. ds_json_encode(10001, lang('param_error'));
  96. }
  97. $store_service_model = model('store_service');
  98. $store_service_info = $store_service_model->getStoreServiceInfo(array('store_service_id' => $id, 'store_id' => session('store_id')));
  99. if (!$store_service_info) {
  100. ds_json_encode(10001, lang('store_service_empty'));
  101. }
  102. $result = $store_service_model->delStoreService(array('store_service_id' => $id, 'store_id' => session('store_id')), array($store_service_info));
  103. if (!$result) {
  104. ds_json_encode(10001, lang('ds_common_del_fail'));
  105. } else {
  106. $this->recordSellerlog(lang('ds_del') . lang('seller_service') . '[' . $store_service_info['store_service_title'] . ']', 1);
  107. ds_json_encode(10000, lang('ds_common_del_succ'));
  108. }
  109. }
  110. public function post_data() {
  111. $data = array(
  112. 'store_service_title' => input('post.store_service_title'),
  113. 'store_service_desc' => input('post.store_service_desc'),
  114. 'store_service_sort' => input('post.store_service_sort'),
  115. );
  116. return $data;
  117. }
  118. /**
  119. * 栏目菜单
  120. */
  121. function getSellerItemList() {
  122. $menu_array[] = array(
  123. 'name' => 'store_service_list',
  124. 'text' => lang('seller_service'),
  125. 'url' => url('seller_service/index'),
  126. );
  127. return $menu_array;
  128. }
  129. }