Mallconsult.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <?php
  2. namespace app\admin\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. * ============================================================================
  7. * DSMall多用户商城
  8. * ============================================================================
  9. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  10. * 网站地址: http://www.csdeshang.com
  11. * ----------------------------------------------------------------------------
  12. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  13. * 不允许对程序代码以任何形式任何目的的再发布。
  14. * ============================================================================
  15. * 控制器
  16. */
  17. class Mallconsult extends AdminControl {
  18. public function initialize() {
  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. $condition = array();
  27. $member_name = trim(input('param.member_name'));
  28. if ($member_name != '') {
  29. $condition[]=array('member_name','like', '%' . $member_name . '%');
  30. View::assign('member_name', $member_name);
  31. }
  32. $mallconsulttype_id = intval(input('param.mctid'));
  33. if ($mallconsulttype_id > 0) {
  34. $condition[]=array('mallconsulttype_id','=',$mallconsulttype_id);
  35. View::assign('mctid', $mallconsulttype_id);
  36. }
  37. $mallconsult_model = model('mallconsult');
  38. $consult_list = $mallconsult_model->getMallconsultList($condition, '*', 10);
  39. View::assign('show_page', $mallconsult_model->page_info->render());
  40. View::assign('consult_list', $consult_list);
  41. // 咨询类型列表
  42. $type_list = model('mallconsulttype')->getMallconsulttypeList(array(), 'mallconsulttype_id,mallconsulttype_name', 'mallconsulttype_id');
  43. View::assign('type_list', $type_list);
  44. // 回复状态
  45. $state = array('0' => lang('state_0'), '1' => lang('state_1'));
  46. View::assign('state', $state);
  47. $this->setAdminCurItem('index');
  48. return View::fetch();
  49. }
  50. /**
  51. * 回复咨询
  52. */
  53. public function consult_reply() {
  54. $mallconsult_model = model('mallconsult');
  55. if (request()->isPost()) {
  56. $mallconsult_id = intval(input('post.mallconsult_id'));
  57. $reply_content = trim(input('post.reply_content'));
  58. if ($mallconsult_id <= 0 || $reply_content == '') {
  59. $this->error(lang('param_error'));
  60. }
  61. $update['mallconsult_isreply'] = 1;
  62. $update['mallconsult_reply_content'] = $reply_content;
  63. $update['mallconsult_replytime'] = TIMESTAMP;
  64. $update['admin_id'] = $this->admin_info['admin_id'];
  65. $update['admin_name'] = $this->admin_info['admin_name'];
  66. $result = $mallconsult_model->editMallconsult(array('mallconsult_id' => $mallconsult_id), $update);
  67. if ($result) {
  68. $consult_info = $mallconsult_model->getMallconsultInfo(array('mallconsult_id' => $mallconsult_id));
  69. // 发送用户消息
  70. $param = array();
  71. $param['code'] = 'consult_mall_reply';
  72. $param['member_id'] = $consult_info['member_id'];
  73. //阿里短信参数
  74. $param['ali_param'] = array();
  75. $param['ten_param'] = array();
  76. $param['param'] = array(
  77. 'consult_url' => HOME_SITE_URL .'/Membermallconsult/mallconsult_info?id='.$mallconsult_id
  78. );
  79. //微信模板消息
  80. $param['weixin_param'] = array(
  81. 'data'=>array(
  82. "keyword1" => array(
  83. "value" => date('Y-m-d', $consult_info['mallconsult_addtime']),
  84. "color" => "#333"
  85. ),
  86. "keyword2" => array(
  87. "value" => $consult_info['mallconsult_content'],
  88. "color" => "#333"
  89. ),
  90. "keyword3" => array(
  91. "value" => $consult_info['mallconsult_reply_content'],
  92. "color" => "#333"
  93. )
  94. ),
  95. );
  96. model('cron')->addCron(array('cron_exetime'=>TIMESTAMP,'cron_type'=>'sendMemberMsg','cron_value'=>serialize($param)));
  97. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  98. } else {
  99. $this->error(lang('ds_common_op_fail'));
  100. }
  101. } else {
  102. $id = intval(input('param.id'));
  103. if ($id <= 0) {
  104. $this->error(lang('param_error'));
  105. }
  106. $consult_info = $mallconsult_model->getMallconsultDetail($id);
  107. View::assign('consult_info', $consult_info);
  108. return View::fetch();
  109. }
  110. }
  111. /**
  112. * 删除平台客服咨询
  113. */
  114. public function del_consult() {
  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. $mallconsulttype_model = model('mallconsulttype');
  135. $type_list = $mallconsulttype_model->getMallconsulttypeList(array(), 'mallconsulttype_id,mallconsulttype_name,mallconsulttype_sort');
  136. View::assign('type_list', $type_list);
  137. $this->setAdminCurItem('type_list');
  138. return View::fetch();
  139. }
  140. /**
  141. * 新增咨询类型
  142. */
  143. public function type_add() {
  144. if (request()->isPost()) {
  145. // 验证
  146. $data = [
  147. 'mallconsulttype_name' => input('post.mallconsulttype_name'),
  148. 'mallconsulttype_sort' => input('post.mallconsulttype_sort')
  149. ];
  150. $mallconsult_validate = ds_validate('mallconsult');
  151. if (!$mallconsult_validate->scene('type_add')->check($data)) {
  152. $this->error(lang('ds_common_op_fail') . $mallconsult_validate->getError());
  153. }
  154. $insert = array();
  155. $insert['mallconsulttype_name'] = trim(input('post.mallconsulttype_name'));
  156. $insert['mallconsulttype_introduce'] = input('post.mallconsulttype_introduce');
  157. $insert['mallconsulttype_sort'] = intval(input('post.mallconsulttype_sort'));
  158. $result = model('mallconsulttype')->addMallconsulttype($insert);
  159. if ($result) {
  160. $this->log('新增咨询类型', 1);
  161. dsLayerOpenSuccess(lang('ds_common_save_succ'));
  162. } else {
  163. $this->log('新增咨询类型', 0);
  164. $this->error(lang('ds_common_save_fail'));
  165. }
  166. }
  167. return View::fetch();
  168. }
  169. /**
  170. * 编辑咨询类型
  171. */
  172. public function type_edit() {
  173. $mallconsulttype_id = intval(input('param.mallconsulttype_id'));
  174. if ($mallconsulttype_id <= 0) {
  175. $this->error(lang('param_error'));
  176. }
  177. $mallconsulttype_model = model('mallconsulttype');
  178. if (request()->isPost()) {
  179. // 验证
  180. $data = [
  181. 'mallconsulttype_name' => input('post.mallconsulttype_name'),
  182. 'mallconsulttype_sort' => input('post.mallconsulttype_sort')
  183. ];
  184. $mallconsult_validate = ds_validate('mallconsult');
  185. if (!$mallconsult_validate->scene('type_edit')->check($data)) {
  186. $this->error(lang('ds_common_op_fail') . $mallconsult_validate->getError());
  187. }
  188. $condition = array();
  189. $condition[] = array('mallconsulttype_id','=',$mallconsulttype_id);
  190. $update = array();
  191. $update['mallconsulttype_name'] = trim(input('post.mallconsulttype_name'));
  192. $update['mallconsulttype_introduce'] = input('post.mallconsulttype_introduce');
  193. $update['mallconsulttype_sort'] = intval(input('post.mallconsulttype_sort'));
  194. $result = $mallconsulttype_model->editMallconsulttype($condition, $update);
  195. if ($result>=0) {
  196. $this->log('编辑平台客服咨询类型 ID:' . $mallconsulttype_id, 1);
  197. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  198. } else {
  199. $this->log('编辑平台客服咨询类型 ID:' . $mallconsulttype_id, 0);
  200. $this->error(lang('ds_common_op_fail'));
  201. }
  202. } else {
  203. $mallconsulttype_info = $mallconsulttype_model->getMallconsulttypeInfo(array('mallconsulttype_id' => $mallconsulttype_id));
  204. View::assign('mallconsulttype_info', $mallconsulttype_info);
  205. return View::fetch();
  206. }
  207. }
  208. /**
  209. * 删除咨询类型
  210. */
  211. public function type_del() {
  212. $mallconsulttype_id = input('param.mallconsulttype_id');
  213. $mallconsulttype_id_array = ds_delete_param($mallconsulttype_id);
  214. if ($mallconsulttype_id_array == FALSE) {
  215. ds_json_encode('10001', lang('param_error'));
  216. }
  217. $condition = array();
  218. $condition[]=array('mallconsulttype_id','in',$mallconsulttype_id_array);
  219. $result = model('mallconsulttype')->delMallconsulttype($condition);
  220. if ($result) {
  221. $this->log('删除平台客服咨询类型 ID:' . $mallconsulttype_id, 1);
  222. ds_json_encode('10000', lang('ds_common_del_succ'));
  223. } else {
  224. $this->log('删除平台客服咨询类型 ID:' . $mallconsulttype_id, 0);
  225. ds_json_encode('10001', lang('ds_common_del_fail'));
  226. }
  227. }
  228. protected function getAdminItemList() {
  229. $menu_array = array(
  230. array(
  231. 'name' => 'index', 'text' => lang('mallconsult_index'), 'url' => (string)url('Mallconsult/index')
  232. ), array(
  233. 'name' => 'type_list', 'text' => lang('mallconsult_type_list'), 'url' => (string)url('Mallconsult/type_list')
  234. ), array(
  235. 'name' => 'type_add', 'text' => lang('mallconsult_type_add'), 'url' =>"javascript:dsLayerOpen('".(string)url('Mallconsult/type_add')."','".lang('mallconsult_type_add')."')"
  236. ),
  237. );
  238. if (request()->action() == 'type_edit')
  239. $menu_array[] = array(
  240. 'name' => 'type_edit', 'text' => lang('mallconsult_type_edit'), 'url' => ''
  241. );
  242. return $menu_array;
  243. }
  244. }