Consulting.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <?php
  2. namespace app\admin\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. * ============================================================================
  7. *
  8. * ============================================================================
  9. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  10. * 网站地址: https://www.valimart.net/
  11. * ----------------------------------------------------------------------------
  12. *
  13. * ============================================================================
  14. * 控制器
  15. */
  16. class Consulting extends AdminControl {
  17. public function initialize() {
  18. parent::initialize(); // TODO: Change the autogenerated stub
  19. Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/consulting.lang.php');
  20. }
  21. /**
  22. * 咨询管理
  23. */
  24. public function consulting() {
  25. $condition = array();
  26. $member_name = trim(input('param.member_name'));
  27. if ($member_name != '') {
  28. $condition[]=array('member_name','like', '%' . $member_name . '%');
  29. View::assign('member_name', $member_name);
  30. }
  31. $consult_content = trim(input('param.consult_content'));
  32. if ($consult_content != '') {
  33. $condition[]=array('consult_content','like', '%' . $consult_content . '%');
  34. View::assign('consult_content', $consult_content);
  35. }
  36. $ctid = intval(input('param.ctid'));
  37. if ($ctid > 0) {
  38. $condition[]=array('consulttype_id','=',$ctid);
  39. View::assign('ctid', $ctid);
  40. }
  41. $consult_model = model('consult');
  42. $consult_list = $consult_model->getConsultList($condition, '*');
  43. View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
  44. View::assign('show_page', $consult_model->page_info->render());
  45. View::assign('consult_list', $consult_list);
  46. // 咨询类型
  47. $consult_type = rkcache('consulttype', true);
  48. View::assign('consult_type', $consult_type);
  49. $this->setAdminCurItem('index');
  50. return View::fetch();
  51. }
  52. public function delete() {
  53. $consult_id = input('param.consult_id');
  54. $consult_id_array = ds_delete_param($consult_id);
  55. if($consult_id_array === FALSE){
  56. $this->error(lang('param_error'));
  57. }
  58. $condition=array();
  59. $condition[] = array('consult_id','in', $consult_id_array);
  60. $consult = model('consult');
  61. if ($consult->delConsult($condition)) {
  62. $this->log(lang('delete_consulting') . '[ID:' . $consult_id . ']', null);
  63. ds_json_encode('10000', lang('ds_common_del_succ'));
  64. } else {
  65. ds_json_encode('10001', lang('ds_common_del_fail'));
  66. }
  67. }
  68. /**
  69. * 咨询类型列表
  70. */
  71. public function type_list() {
  72. $consulttype_model = model('consulttype');
  73. $type_list = $consulttype_model->getConsulttypeList(array(), 'consulttype_id,consulttype_name,consulttype_sort');
  74. View::assign('type_list', $type_list);
  75. $this->setAdminCurItem('type_list');
  76. return View::fetch();
  77. }
  78. /**
  79. * 新增咨询类型
  80. */
  81. public function type_add() {
  82. if (request()->isPost()) {
  83. // 验证
  84. $data = [
  85. 'consulttype_name' => input('post.consulttype_name'),
  86. 'consulttype_sort' => input('post.consulttype_sort'),
  87. ];
  88. $consulting_validate = ds_validate('consulting');
  89. if (!$consulting_validate->scene('type_add')->check($data)) {
  90. $this->error($consulting_validate->getError());
  91. }
  92. $insert = array();
  93. $insert['consulttype_name'] = trim(input('post.consulttype_name'));
  94. $insert['consulttype_sort'] = intval(input('post.consulttype_sort'));
  95. $insert['consulttype_introduce'] = input('post.consulttype_introduce');
  96. $result = model('consulttype')->addConsulttype($insert);
  97. if ($result) {
  98. $this->log(lang('add_consulttype'), 1);
  99. dsLayerOpenSuccess(lang('ds_common_save_succ'));
  100. } else {
  101. $this->log(lang('add_consulttype'), 0);
  102. $this->error(lang('ds_common_save_fail'));
  103. }
  104. }
  105. $consulttype_info = array(
  106. 'consulttype_id' => '',
  107. 'consulttype_name' => '',
  108. 'consulttype_sort' => '',
  109. 'consulttype_introduce' => '',
  110. );
  111. View::assign('build_editor', build_editor(array(
  112. 'name' => 'consulttype_introduce',
  113. )));
  114. View::assign('consulttype_info', $consulttype_info);
  115. return View::fetch('type_edit');
  116. }
  117. /**
  118. * 编辑咨询类型
  119. */
  120. public function type_edit() {
  121. $consulttype_model = model('consulttype');
  122. $consulttype_id = intval(input('param.consulttype_id'));
  123. if ($consulttype_id <= 0) {
  124. $this->error(lang('param_error'));
  125. }
  126. if (request()->isPost()) {
  127. // 验证
  128. $data = [
  129. 'consulttype_name' => input('post.consulttype_name'),
  130. 'consulttype_sort' => input('post.consulttype_sort'),
  131. ];
  132. $consulting_validate = ds_validate('consulting');
  133. if (!$consulting_validate->scene('type_edit')->check($data)) {
  134. $this->error($consulting_validate->getError());
  135. }
  136. $condition = array();
  137. $condition[] = array('consulttype_id','=',$consulttype_id);
  138. $update = array();
  139. $update['consulttype_name'] = trim(input('post.consulttype_name'));
  140. $update['consulttype_sort'] = intval(input('post.consulttype_sort'));
  141. $update['consulttype_introduce'] = input('post.consulttype_introduce');
  142. $result = $consulttype_model->editConsulttype($condition, $update);
  143. if ($result) {
  144. $this->log(lang('edit_consulttype').' ID:' . $consulttype_id, 1);
  145. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  146. } else {
  147. $this->log(lang('edit_consulttype').' ID:' . $consulttype_id, 0);
  148. $this->error(lang('ds_common_op_fail'));
  149. }
  150. }else {
  151. $consulttype_info = $consulttype_model->getConsulttypeInfo(array('consulttype_id' => $consulttype_id));
  152. View::assign('build_editor', build_editor(array(
  153. 'name' => 'consulttype_introduce',
  154. 'content' => htmlspecialchars_decode($consulttype_info['consulttype_introduce']),
  155. )));
  156. $this->setAdminCurItem('type_list');
  157. View::assign('consulttype_info', $consulttype_info);
  158. return View::fetch();
  159. }
  160. }
  161. /**
  162. * 删除咨询类型
  163. */
  164. public function type_del() {
  165. $consulttype_id = input('param.consulttype_id');
  166. $consulttype_id_array = ds_delete_param($consulttype_id);
  167. if ($consulttype_id_array === FALSE) {
  168. ds_json_encode('10001', lang('param_error'));
  169. }
  170. $condition=array();
  171. $condition[]=array('consulttype_id','in',$consulttype_id_array);
  172. $result = model('consulttype')->delConsulttype($condition);
  173. if ($result) {
  174. $this->log(lang('del_consulttype').' ID:' . $consulttype_id, 1);
  175. ds_json_encode('10000', lang('ds_common_op_succ'));
  176. } else {
  177. $this->log(lang('del_consulttype').' ID:' . $consulttype_id, 0);
  178. ds_json_encode('10001', lang('ds_common_op_fail'));
  179. }
  180. }
  181. /**
  182. * 获取卖家栏目列表,针对控制器下的栏目
  183. */
  184. protected function getAdminItemList() {
  185. $menu_array = array(
  186. array(
  187. 'name' => 'index',
  188. 'text' => lang('ds_manage'),
  189. 'url' => (string)url('Consulting/consulting')
  190. ),
  191. array(
  192. 'name' => 'type_list',
  193. 'text' => lang('consulting_index_type'),
  194. 'url' => (string)url('Consulting/type_list')
  195. ),
  196. array(
  197. 'name' => 'type_add',
  198. 'text' => lang('add_consulttype'),
  199. 'url' =>"javascript:dsLayerOpen('".(string)url('Consulting/type_add')."','".lang('add_consulttype')."')"
  200. )
  201. );
  202. return $menu_array;
  203. }
  204. }