Mallconsult.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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 Mallconsult 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') . '/mallconsult.lang.php');
  18. }
  19. /**
  20. * 咨询管理
  21. */
  22. public function index()
  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. $mallconsulttype_id = intval(input('param.mctid'));
  31. if ($mallconsulttype_id > 0) {
  32. $condition[] = array('mallconsulttype_id', '=', $mallconsulttype_id);
  33. View::assign('mctid', $mallconsulttype_id);
  34. }
  35. $mallconsult_model = model('mallconsult');
  36. $consult_list = $mallconsult_model->getMallconsultList($condition, '*', 10);
  37. View::assign('show_page', $mallconsult_model->page_info->render());
  38. View::assign('consult_list', $consult_list);
  39. // 咨询类型列表
  40. $type_list = model('mallconsulttype')->getMallconsulttypeList(array(), 'mallconsulttype_id,mallconsulttype_name', 'mallconsulttype_id');
  41. View::assign('type_list', $type_list);
  42. // 回复状态
  43. $state = array('0' => lang('state_0'), '1' => lang('state_1'));
  44. View::assign('state', $state);
  45. $this->setAdminCurItem('index');
  46. return View::fetch();
  47. }
  48. /**
  49. * 回复咨询
  50. */
  51. public function consult_reply()
  52. {
  53. $mallconsult_model = model('mallconsult');
  54. if (request()->isPost()) {
  55. $mallconsult_id = intval(input('post.mallconsult_id'));
  56. $reply_content = trim(input('post.reply_content'));
  57. if ($mallconsult_id <= 0 || $reply_content == '') {
  58. $this->error(lang('param_error'));
  59. }
  60. $update['mallconsult_isreply'] = 1;
  61. $update['mallconsult_reply_content'] = $reply_content;
  62. $update['mallconsult_replytime'] = TIMESTAMP;
  63. $update['admin_id'] = $this->admin_info['admin_id'];
  64. $update['admin_name'] = $this->admin_info['admin_name'];
  65. $result = $mallconsult_model->editMallconsult(array('mallconsult_id' => $mallconsult_id), $update);
  66. if ($result) {
  67. $consult_info = $mallconsult_model->getMallconsultInfo(array('mallconsult_id' => $mallconsult_id));
  68. // 发送用户消息
  69. $param = array();
  70. $param['code'] = 'consult_mall_reply';
  71. $param['member_id'] = $consult_info['member_id'];
  72. //阿里短信参数
  73. $param['ali_param'] = array();
  74. $param['ten_param'] = array();
  75. $param['param'] = array(
  76. 'consult_url' => HOME_SITE_URL . '/Membermallconsult/mallconsult_info?id=' . $mallconsult_id
  77. );
  78. //微信模板消息
  79. $param['weixin_param'] = array(
  80. 'data' => array(
  81. "keyword1" => array(
  82. "value" => date('Y-m-d', $consult_info['mallconsult_addtime']),
  83. "color" => "#333"
  84. ),
  85. "keyword2" => array(
  86. "value" => $consult_info['mallconsult_content'],
  87. "color" => "#333"
  88. ),
  89. "keyword3" => array(
  90. "value" => $consult_info['mallconsult_reply_content'],
  91. "color" => "#333"
  92. )
  93. ),
  94. );
  95. model('cron')->addCron(array('cron_exetime' => TIMESTAMP, 'cron_type' => 'sendMemberMsg', 'cron_value' => serialize($param)));
  96. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  97. } else {
  98. $this->error(lang('ds_common_op_fail'));
  99. }
  100. } else {
  101. $id = intval(input('param.id'));
  102. if ($id <= 0) {
  103. $this->error(lang('param_error'));
  104. }
  105. $consult_info = $mallconsult_model->getMallconsultDetail($id);
  106. View::assign('consult_info', $consult_info);
  107. return View::fetch();
  108. }
  109. }
  110. /**
  111. * 删除平台客服咨询
  112. */
  113. public function del_consult()
  114. {
  115. $mallconsult_id = input('param.mallconsult_id');
  116. $mallconsult_id_array = ds_delete_param($mallconsult_id);
  117. if ($mallconsult_id_array == FALSE) {
  118. ds_json_encode('10001', lang('param_error'));
  119. }
  120. $condition = array();
  121. $condition[] = array('mallconsult_id', 'in', $mallconsult_id_array);
  122. $result = model('mallconsult')->delMallconsult($condition);
  123. if ($result) {
  124. $this->log('删除平台客服咨询' . '[ID:' . $mallconsult_id . ']');
  125. ds_json_encode('10000', lang('ds_common_del_succ'));
  126. } else {
  127. ds_json_encode('10001', lang('ds_common_del_fail'));
  128. }
  129. }
  130. /**
  131. * 咨询类型列表
  132. */
  133. public function type_list()
  134. {
  135. $mallconsulttype_model = model('mallconsulttype');
  136. $type_list = $mallconsulttype_model->getMallconsulttypeList(array(), 'mallconsulttype_id,mallconsulttype_name,mallconsulttype_sort');
  137. View::assign('type_list', $type_list);
  138. $this->setAdminCurItem('type_list');
  139. return View::fetch();
  140. }
  141. /**
  142. * 新增咨询类型
  143. */
  144. public function type_add()
  145. {
  146. if (request()->isPost()) {
  147. // 验证
  148. $data = [
  149. 'mallconsulttype_name' => input('post.mallconsulttype_name'),
  150. 'mallconsulttype_sort' => input('post.mallconsulttype_sort')
  151. ];
  152. $mallconsult_validate = ds_validate('mallconsult');
  153. if (!$mallconsult_validate->scene('type_add')->check($data)) {
  154. $this->error(lang('ds_common_op_fail') . $mallconsult_validate->getError());
  155. }
  156. $insert = array();
  157. $insert['mallconsulttype_name'] = trim(input('post.mallconsulttype_name'));
  158. $insert['mallconsulttype_introduce'] = input('post.mallconsulttype_introduce');
  159. $insert['mallconsulttype_sort'] = intval(input('post.mallconsulttype_sort'));
  160. $result = model('mallconsulttype')->addMallconsulttype($insert);
  161. if ($result) {
  162. $this->log('新增咨询类型', 1);
  163. dsLayerOpenSuccess(lang('ds_common_save_succ'));
  164. } else {
  165. $this->log('新增咨询类型', 0);
  166. $this->error(lang('ds_common_save_fail'));
  167. }
  168. }
  169. return View::fetch();
  170. }
  171. /**
  172. * 编辑咨询类型
  173. */
  174. public function type_edit()
  175. {
  176. $mallconsulttype_id = intval(input('param.mallconsulttype_id'));
  177. if ($mallconsulttype_id <= 0) {
  178. $this->error(lang('param_error'));
  179. }
  180. $mallconsulttype_model = model('mallconsulttype');
  181. if (request()->isPost()) {
  182. // 验证
  183. $data = [
  184. 'mallconsulttype_name' => input('post.mallconsulttype_name'),
  185. 'mallconsulttype_sort' => input('post.mallconsulttype_sort')
  186. ];
  187. $mallconsult_validate = ds_validate('mallconsult');
  188. if (!$mallconsult_validate->scene('type_edit')->check($data)) {
  189. $this->error(lang('ds_common_op_fail') . $mallconsult_validate->getError());
  190. }
  191. $condition = array();
  192. $condition[] = array('mallconsulttype_id', '=', $mallconsulttype_id);
  193. $update = array();
  194. $update['mallconsulttype_name'] = trim(input('post.mallconsulttype_name'));
  195. $update['mallconsulttype_introduce'] = input('post.mallconsulttype_introduce');
  196. $update['mallconsulttype_sort'] = intval(input('post.mallconsulttype_sort'));
  197. $result = $mallconsulttype_model->editMallconsulttype($condition, $update);
  198. if ($result >= 0) {
  199. $this->log('编辑平台客服咨询类型 ID:' . $mallconsulttype_id, 1);
  200. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  201. } else {
  202. $this->log('编辑平台客服咨询类型 ID:' . $mallconsulttype_id, 0);
  203. $this->error(lang('ds_common_op_fail'));
  204. }
  205. } else {
  206. $mallconsulttype_info = $mallconsulttype_model->getMallconsulttypeInfo(array('mallconsulttype_id' => $mallconsulttype_id));
  207. View::assign('mallconsulttype_info', $mallconsulttype_info);
  208. return View::fetch();
  209. }
  210. }
  211. /**
  212. * 删除咨询类型
  213. */
  214. public function type_del()
  215. {
  216. $mallconsulttype_id = input('param.mallconsulttype_id');
  217. $mallconsulttype_id_array = ds_delete_param($mallconsulttype_id);
  218. if ($mallconsulttype_id_array == FALSE) {
  219. ds_json_encode('10001', lang('param_error'));
  220. }
  221. $condition = array();
  222. $condition[] = array('mallconsulttype_id', 'in', $mallconsulttype_id_array);
  223. $result = model('mallconsulttype')->delMallconsulttype($condition);
  224. if ($result) {
  225. $this->log('删除平台客服咨询类型 ID:' . $mallconsulttype_id, 1);
  226. ds_json_encode('10000', lang('ds_common_del_succ'));
  227. } else {
  228. $this->log('删除平台客服咨询类型 ID:' . $mallconsulttype_id, 0);
  229. ds_json_encode('10001', lang('ds_common_del_fail'));
  230. }
  231. }
  232. protected function getAdminItemList()
  233. {
  234. $menu_array = array(
  235. array(
  236. 'name' => 'index', 'text' => lang('mallconsult_index'), 'url' => (string)url('Mallconsult/index')
  237. ), array(
  238. 'name' => 'type_list', 'text' => lang('mallconsult_type_list'), 'url' => (string)url('Mallconsult/type_list')
  239. ), array(
  240. 'name' => 'type_add', 'text' => lang('mallconsult_type_add'), 'url' => "javascript:dsLayerOpen('" . (string)url('Mallconsult/type_add') . "','" . lang('mallconsult_type_add') . "')"
  241. ),
  242. );
  243. if (request()->action() == 'type_edit')
  244. $menu_array[] = array(
  245. 'name' => 'type_edit', 'text' => lang('mallconsult_type_edit'), 'url' => ''
  246. );
  247. return $menu_array;
  248. }
  249. }