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