Consulting.php 8.2 KB

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