Mallconsult.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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 Mallconsult 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').'/mallconsult.lang.php');
  20. }
  21. /**
  22. * 咨询管理
  23. */
  24. public function index() {
  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. $mallconsulttype_id = intval(input('param.mctid'));
  32. if ($mallconsulttype_id > 0) {
  33. $condition[]=array('mallconsulttype_id','=',$mallconsulttype_id);
  34. View::assign('mctid', $mallconsulttype_id);
  35. }
  36. $mallconsult_model = model('mallconsult');
  37. $consult_list = $mallconsult_model->getMallconsultList($condition, '*', 10);
  38. View::assign('show_page', $mallconsult_model->page_info->render());
  39. View::assign('consult_list', $consult_list);
  40. // 咨询类型列表
  41. $type_list = model('mallconsulttype')->getMallconsulttypeList(array(), 'mallconsulttype_id,mallconsulttype_name', 'mallconsulttype_id');
  42. View::assign('type_list', $type_list);
  43. // 回复状态
  44. $state = array('0' => lang('state_0'), '1' => lang('state_1'));
  45. View::assign('state', $state);
  46. $this->setAdminCurItem('index');
  47. return View::fetch();
  48. }
  49. /**
  50. * 回复咨询
  51. */
  52. public function consult_reply() {
  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. $mallconsult_id = input('param.mallconsult_id');
  115. $mallconsult_id_array = ds_delete_param($mallconsult_id);
  116. if ($mallconsult_id_array == FALSE) {
  117. ds_json_encode('10001', lang('param_error'));
  118. }
  119. $condition = array();
  120. $condition[]=array('mallconsult_id','in',$mallconsult_id_array);
  121. $result = model('mallconsult')->delMallconsult($condition);
  122. if ($result) {
  123. $this->log('删除平台客服咨询' . '[ID:' . $mallconsult_id . ']');
  124. ds_json_encode('10000', lang('ds_common_del_succ'));
  125. } else {
  126. ds_json_encode('10001', lang('ds_common_del_fail'));
  127. }
  128. }
  129. /**
  130. * 咨询类型列表
  131. */
  132. public function type_list() {
  133. $mallconsulttype_model = model('mallconsulttype');
  134. $type_list = $mallconsulttype_model->getMallconsulttypeList(array(), 'mallconsulttype_id,mallconsulttype_name,mallconsulttype_sort');
  135. View::assign('type_list', $type_list);
  136. $this->setAdminCurItem('type_list');
  137. return View::fetch();
  138. }
  139. /**
  140. * 新增咨询类型
  141. */
  142. public function type_add() {
  143. if (request()->isPost()) {
  144. // 验证
  145. $data = [
  146. 'mallconsulttype_name' => input('post.mallconsulttype_name'),
  147. 'mallconsulttype_sort' => input('post.mallconsulttype_sort')
  148. ];
  149. $mallconsult_validate = ds_validate('mallconsult');
  150. if (!$mallconsult_validate->scene('type_add')->check($data)) {
  151. $this->error(lang('ds_common_op_fail') . $mallconsult_validate->getError());
  152. }
  153. $insert = array();
  154. $insert['mallconsulttype_name'] = trim(input('post.mallconsulttype_name'));
  155. $insert['mallconsulttype_introduce'] = input('post.mallconsulttype_introduce');
  156. $insert['mallconsulttype_sort'] = intval(input('post.mallconsulttype_sort'));
  157. $result = model('mallconsulttype')->addMallconsulttype($insert);
  158. if ($result) {
  159. $this->log('新增咨询类型', 1);
  160. dsLayerOpenSuccess(lang('ds_common_save_succ'));
  161. } else {
  162. $this->log('新增咨询类型', 0);
  163. $this->error(lang('ds_common_save_fail'));
  164. }
  165. }
  166. return View::fetch();
  167. }
  168. /**
  169. * 编辑咨询类型
  170. */
  171. public function type_edit() {
  172. $mallconsulttype_id = intval(input('param.mallconsulttype_id'));
  173. if ($mallconsulttype_id <= 0) {
  174. $this->error(lang('param_error'));
  175. }
  176. $mallconsulttype_model = model('mallconsulttype');
  177. if (request()->isPost()) {
  178. // 验证
  179. $data = [
  180. 'mallconsulttype_name' => input('post.mallconsulttype_name'),
  181. 'mallconsulttype_sort' => input('post.mallconsulttype_sort')
  182. ];
  183. $mallconsult_validate = ds_validate('mallconsult');
  184. if (!$mallconsult_validate->scene('type_edit')->check($data)) {
  185. $this->error(lang('ds_common_op_fail') . $mallconsult_validate->getError());
  186. }
  187. $condition = array();
  188. $condition[] = array('mallconsulttype_id','=',$mallconsulttype_id);
  189. $update = array();
  190. $update['mallconsulttype_name'] = trim(input('post.mallconsulttype_name'));
  191. $update['mallconsulttype_introduce'] = input('post.mallconsulttype_introduce');
  192. $update['mallconsulttype_sort'] = intval(input('post.mallconsulttype_sort'));
  193. $result = $mallconsulttype_model->editMallconsulttype($condition, $update);
  194. if ($result>=0) {
  195. $this->log('编辑平台客服咨询类型 ID:' . $mallconsulttype_id, 1);
  196. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  197. } else {
  198. $this->log('编辑平台客服咨询类型 ID:' . $mallconsulttype_id, 0);
  199. $this->error(lang('ds_common_op_fail'));
  200. }
  201. } else {
  202. $mallconsulttype_info = $mallconsulttype_model->getMallconsulttypeInfo(array('mallconsulttype_id' => $mallconsulttype_id));
  203. View::assign('mallconsulttype_info', $mallconsulttype_info);
  204. return View::fetch();
  205. }
  206. }
  207. /**
  208. * 删除咨询类型
  209. */
  210. public function type_del() {
  211. $mallconsulttype_id = input('param.mallconsulttype_id');
  212. $mallconsulttype_id_array = ds_delete_param($mallconsulttype_id);
  213. if ($mallconsulttype_id_array == FALSE) {
  214. ds_json_encode('10001', lang('param_error'));
  215. }
  216. $condition = array();
  217. $condition[]=array('mallconsulttype_id','in',$mallconsulttype_id_array);
  218. $result = model('mallconsulttype')->delMallconsulttype($condition);
  219. if ($result) {
  220. $this->log('删除平台客服咨询类型 ID:' . $mallconsulttype_id, 1);
  221. ds_json_encode('10000', lang('ds_common_del_succ'));
  222. } else {
  223. $this->log('删除平台客服咨询类型 ID:' . $mallconsulttype_id, 0);
  224. ds_json_encode('10001', lang('ds_common_del_fail'));
  225. }
  226. }
  227. protected function getAdminItemList() {
  228. $menu_array = array(
  229. array(
  230. 'name' => 'index', 'text' => lang('mallconsult_index'), 'url' => (string)url('Mallconsult/index')
  231. ), array(
  232. 'name' => 'type_list', 'text' => lang('mallconsult_type_list'), 'url' => (string)url('Mallconsult/type_list')
  233. ), array(
  234. 'name' => 'type_add', 'text' => lang('mallconsult_type_add'), 'url' =>"javascript:dsLayerOpen('".(string)url('Mallconsult/type_add')."','".lang('mallconsult_type_add')."')"
  235. ),
  236. );
  237. if (request()->action() == 'type_edit')
  238. $menu_array[] = array(
  239. 'name' => 'type_edit', 'text' => lang('mallconsult_type_edit'), 'url' => ''
  240. );
  241. return $menu_array;
  242. }
  243. }