Membercomplain.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. <?php
  2. /*
  3. * 交易投诉
  4. */
  5. namespace app\home\controller;
  6. use think\facade\View;
  7. use think\facade\Lang;
  8. /**
  9. *
  10. *
  11. * ----------------------------------------------------------------------------
  12. *
  13. * 控制器
  14. */
  15. class Membercomplain extends BaseMember
  16. {
  17. //定义投诉状态常量
  18. const STATE_NEW = 10;
  19. const STATE_APPEAL = 20;
  20. const STATE_TALK = 30;
  21. const STATE_HANDLE = 40;
  22. const STATE_FINISH = 99;
  23. const STATE_UNACTIVE = 1;
  24. const STATE_ACTIVE = 2;
  25. public function initialize()
  26. {
  27. parent::initialize();
  28. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/membercomplain.lang.php');
  29. }
  30. /*
  31. * 我的投诉页面
  32. */
  33. public function index()
  34. {
  35. /*
  36. * 得到当前用户的投诉列表
  37. */
  38. $complain_model = model('complain');
  39. $condition = array();
  40. $condition[] = array('accuser_id', '=', session('member_id'));
  41. switch (intval(input('param.select_complain_state'))) {
  42. case 1:
  43. $condition[] = array('complain_state', '<', 90);
  44. break;
  45. case 2:
  46. $condition[] = array('complain_state', '=', 99);
  47. break;
  48. }
  49. $complain_list = $complain_model->getComplainList($condition);
  50. /* 设置买家当前菜单 */
  51. $this->setMemberCurMenu('member_complain');
  52. /* 设置买家当前栏目 */
  53. $this->setMemberCurItem('complain_list');
  54. View::assign('complain_list', $complain_list);
  55. View::assign('show_page', '');
  56. $goods_list = $complain_model->getComplainGoodsList($complain_list);
  57. View::assign('goods_list', $goods_list);
  58. return View::fetch($this->template_dir . 'index');
  59. }
  60. /*
  61. * 新投诉
  62. */
  63. public function complain_new()
  64. {
  65. $order_id = intval(input('order_id'));
  66. $goods_id = intval(input('goods_id')); //订单商品表编号
  67. if ($order_id < 1 || $goods_id < 1) { //参数验证
  68. $this->error(lang('param_error'), 'Memberorder/index');
  69. }
  70. $condition = array();
  71. $condition[] = array('buyer_id', '=', session('member_id'));
  72. $condition[] = array('order_id', '=', $order_id);
  73. $refundreturn_model = model('refundreturn');
  74. $order_info = $refundreturn_model->getRightOrderList($condition, $goods_id);
  75. //halt($order_info);
  76. View::assign('return_info', $order_info);
  77. //检查订单是否可以投诉
  78. $order_model = model('order');
  79. $if_complain = $order_model->getOrderOperateState('complain', $order_info);
  80. if ($if_complain < 1) {
  81. $this->error(lang('param_error'));
  82. }
  83. //检查是不是正在进行投诉
  84. if ($this->check_complain_exist($goods_id)) {
  85. $this->error(lang('complain_repeat')); //'您已经投诉了该订单请等待处理'
  86. }
  87. //获取投诉类型
  88. $complainsubject_model = model('complainsubject');
  89. $param = array();
  90. $complain_subject_list = $complainsubject_model->getActiveComplainsubject($param);
  91. if (empty($complain_subject_list)) {
  92. $this->error(lang('complain_subject_error'));
  93. }
  94. $refundreturn_model = model('refundreturn');
  95. $order_info['extend_order_goods'] = $order_info['goods_list'];
  96. $order_list[$order_id] = $order_info;
  97. $order_list = $refundreturn_model->getGoodsRefundList($order_list);
  98. if (isset($order_list[$order_id]['extend_complain'][$goods_id]) && intval($order_list[$order_id]['extend_complain'][$goods_id]) == 1) { //退款投诉
  99. $complainsubject_model = model('complainsubject');
  100. $complain_subject = $complainsubject_model->getComplainsubject(array('complainsubject_id' => 1)); //投诉主题
  101. $complain_subject_list = array_merge($complain_subject, $complain_subject_list);
  102. }
  103. View::assign('subject_list', $complain_subject_list);
  104. View::assign('goods_id', $goods_id);
  105. View::assign('goods_list', $order_info['goods_list']);
  106. /* 设置买家当前菜单 */
  107. $this->setMemberCurMenu('member_complain');
  108. /* 设置买家当前栏目 */
  109. $this->setMemberCurItem('complain_list');
  110. return View::fetch($this->template_dir . 'complain_new');
  111. }
  112. /*
  113. * 处理投诉请求
  114. */
  115. public function complain_show()
  116. {
  117. $complain_id = intval(input('complain_id'));
  118. //获取投诉详细信息
  119. $complain_info = $this->get_complain_info($complain_id);
  120. View::assign('complain_info', $complain_info);
  121. $complain_pic = array();
  122. $appeal_pic = array();
  123. for ($i = 1; $i <= 3; $i++) {
  124. if (!empty($complain_info['complain_pic' . $i])) {
  125. $complain_pic[$i] = $complain_info['complain_pic' . $i];
  126. }
  127. if (!empty($complain_info['appeal_pic' . $i])) {
  128. $appeal_pic[$i] = $complain_info['appeal_pic' . $i];
  129. }
  130. }
  131. View::assign('complain_pic', $complain_pic);
  132. View::assign('appeal_pic', $appeal_pic);
  133. $condition = array();
  134. $condition[] = array('buyer_id', '=', session('member_id'));
  135. $condition[] = array('order_id', '=', $complain_info['order_id']);
  136. $refundreturn_model = model('refundreturn');
  137. $return_info = $refundreturn_model->getRightOrderList($condition, $complain_info['order_goods_id']);
  138. $complain_model = model('complain');
  139. $goods_list = $complain_model->getComplainGoodsList(array($complain_info));
  140. View::assign('goods_list', $goods_list);
  141. View::assign('return_info', $return_info);
  142. /* 设置买家当前菜单 */
  143. $this->setMemberCurMenu('member_complain');
  144. /* 设置买家当前栏目 */
  145. $this->setMemberCurItem('complain_list');
  146. return View::fetch($this->template_dir . 'complain_show');
  147. }
  148. /*
  149. * 保存用户提交的投诉
  150. */
  151. public function complain_save()
  152. {
  153. //获取输入的投诉信息
  154. $input = array();
  155. $input['order_id'] = intval(input('post.input_order_id'));
  156. $input['order_goods_id'] = intval(input('post.input_goods_id'));
  157. $condition = array();
  158. $condition[] = array('buyer_id', '=', session('member_id'));
  159. $condition[] = array('order_id', '=', $input['order_id']);
  160. $order_model = model('order');
  161. $order_info = $order_model->getOrderInfo($condition);
  162. $if_complain = $order_model->getOrderOperateState('complain', $order_info); //检查订单是否可以投诉
  163. if ($if_complain < 1) {
  164. $this->error(lang('param_error'), (string) url('Memberorder/index'));
  165. }
  166. //检查是不是正在进行投诉
  167. if ($this->check_complain_exist($input['order_goods_id'])) {
  168. $this->error(lang('complain_repeat'));
  169. }
  170. list($input['complain_subject_id'], $input['complain_subject_content']) = explode(',', trim(input('post.input_complain_subject')));
  171. $input_complain_content = trim(input('post.input_complain_content'));
  172. $res = word_filter($input_complain_content);
  173. if (!$res['code']) {
  174. $this->error($res['msg']);
  175. }
  176. $input_complain_content = $res['data']['text'];
  177. $input['complain_content'] = $input_complain_content;
  178. $input['accuser_id'] = $order_info['buyer_id'];
  179. $input['accuser_name'] = $order_info['buyer_name'];
  180. $input['accused_id'] = $order_info['store_id'];
  181. $input['accused_name'] = $order_info['store_name'];
  182. $input['complain_datetime'] = TIMESTAMP;
  183. $input['complain_state'] = self::STATE_NEW;
  184. $input['complain_active'] = self::STATE_UNACTIVE;
  185. $pic_name = $this->upload_pic(); //上传图片
  186. $input['complain_pic1'] = isset($pic_name[1]) ? $pic_name[1] : '';
  187. $input['complain_pic2'] = isset($pic_name[2]) ? $pic_name[2] : '';
  188. $input['complain_pic3'] = isset($pic_name[3]) ? $pic_name[3] : '';
  189. $complain_model = model('complain');
  190. $state = $complain_model->addComplain($input); //保存投诉信息
  191. if ($state) {
  192. $this->success(lang('complain_submit_success'), (string) url('Membercomplain/index'));
  193. } else {
  194. $this->error(lang('ds_common_save_fail'));
  195. }
  196. }
  197. /*
  198. * 保存用户提交的补充证据
  199. */
  200. public function complain_add_pic()
  201. {
  202. $complain_id = input('param.complain_id');
  203. //获取投诉详细信息
  204. $complain_info = $this->get_complain_info($complain_id);
  205. if (request()->isPost()) {
  206. $condition = array();
  207. $condition[] = array('complain_id', '=', $complain_id);
  208. //获取输入的投诉信息
  209. $input = array();
  210. $pic_name = $this->upload_pic();
  211. $input['complain_pic1'] = isset($pic_name[1]) ? $pic_name[1] : '';
  212. $input['complain_pic2'] = isset($pic_name[2]) ? $pic_name[2] : '';
  213. $input['complain_pic3'] = isset($pic_name[3]) ? $pic_name[3] : '';
  214. //保存投诉信息
  215. $complain_model = model('complain');
  216. $complain_model->editComplain($input, $condition);
  217. $this->success(lang('ds_common_save_succ'));
  218. }
  219. }
  220. /*
  221. * 取消用户提交的投诉
  222. */
  223. public function complain_cancel()
  224. {
  225. $complain_id = intval(input('param.complain_id'));
  226. $complain_info = $this->get_complain_info($complain_id);
  227. if (intval($complain_info['complain_state']) === 10) {
  228. $pics = array();
  229. if (!empty($complain_info['complain_pic1']))
  230. $pics[] = $complain_info['complain_pic1'];
  231. if (!empty($complain_info['complain_pic2']))
  232. $pics[] = $complain_info['complain_pic2'];
  233. if (!empty($complain_info['complain_pic3']))
  234. $pics[] = $complain_info['complain_pic3'];
  235. if (!empty($pics)) { //删除图片
  236. foreach ($pics as $pic) {
  237. $pic = BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_PATH . DIRECTORY_SEPARATOR . 'complain' . DIRECTORY_SEPARATOR . $pic;
  238. if (file_exists($pic)) {
  239. @unlink($pic);
  240. }
  241. }
  242. }
  243. $complain_model = model('complain');
  244. $complain_model->delComplain(array('complain_id' => $complain_id));
  245. ds_json_encode(10000, lang('complain_cancel_success'));
  246. } else {
  247. ds_json_encode(10001, lang('complain_cancel_fail'));
  248. }
  249. }
  250. /*
  251. * 处理用户申请仲裁
  252. */
  253. public function apply_handle()
  254. {
  255. $complain_id = intval(input('post.input_complain_id'));
  256. //获取投诉详细信息
  257. $complain_info = $this->get_complain_info($complain_id);
  258. $complain_state = intval($complain_info['complain_state']);
  259. //检查当前是不是投诉状态
  260. if ($complain_state < self::STATE_TALK || $complain_state === 99) {
  261. ds_json_encode(10001, lang('param_error'));
  262. }
  263. $update_array = array();
  264. $update_array['complain_state'] = self::STATE_HANDLE;
  265. $condition = array();
  266. $condition[] = array('complain_id', '=', $complain_id);
  267. //保存投诉信息
  268. $complain_model = model('complain');
  269. $complain_model->editComplain($update_array, $condition);
  270. ds_json_encode(10000, lang('handle_submit_success'));
  271. }
  272. /*
  273. * 根据投诉id获取投诉对话
  274. */
  275. public function get_complain_talk()
  276. {
  277. $complain_id = intval(input('post.complain_id'));
  278. $complain_info = $this->get_complain_info($complain_id);
  279. $complaintalk_model = model('complaintalk');
  280. $param = array();
  281. $param['complain_id'] = $complain_id;
  282. $complain_talk_list = $complaintalk_model->getComplaintalkList($param);
  283. $talk_list = array();
  284. $i = 0;
  285. foreach ($complain_talk_list as $talk) {
  286. $talk_list[$i]['css'] = $talk['talk_member_type'];
  287. $talk_list[$i]['talk'] = date("Y-m-d H:i:s", $talk['talk_datetime']);
  288. switch ($talk['talk_member_type']) {
  289. case 'accuser':
  290. $talk_list[$i]['talk'] .= lang('complain_accuser');
  291. break;
  292. case 'accused':
  293. $talk_list[$i]['talk'] .= lang('complain_accused');
  294. break;
  295. case 'admin':
  296. $talk_list[$i]['talk'] .= lang('complain_admin');
  297. break;
  298. default:
  299. $talk_list[$i]['talk'] .= lang('complain_unknow');
  300. }
  301. if (intval($talk['talk_state']) === 2) {
  302. $talk['talk_content'] = lang('talk_forbit_message');
  303. }
  304. $talk_list[$i]['talk'] .= '(' . $talk['talk_member_name'] . ')' . lang('complain_text_say') . ':' . $talk['talk_content'];
  305. $i++;
  306. }
  307. echo json_encode($talk_list);
  308. }
  309. /*
  310. * 根据发布投诉对话
  311. */
  312. public function publish_complain_talk()
  313. {
  314. $complain_id = intval(input('post.complain_id'));
  315. $complain_talk = trim(input('post.complain_talk'));
  316. $talk_len = strlen($complain_talk);
  317. if ($talk_len > 0 && $talk_len < 255) {
  318. $complain_info = $this->get_complain_info($complain_id);
  319. $complain_state = intval($complain_info['complain_state']);
  320. //检查投诉是否是可发布对话状态
  321. if ($complain_state > self::STATE_APPEAL && $complain_state < self::STATE_FINISH) {
  322. $complaintalk_model = model('complaintalk');
  323. $param = array();
  324. $param['complain_id'] = $complain_id;
  325. $param['talk_member_id'] = $complain_info['accuser_id'];
  326. $param['talk_member_name'] = $complain_info['accuser_name'];
  327. $param['talk_member_type'] = $complain_info['member_status'];
  328. $param['talk_content'] = $complain_talk;
  329. $param['talk_state'] = 1;
  330. $param['talk_admin'] = 0;
  331. $param['talk_datetime'] = TIMESTAMP;
  332. if ($complaintalk_model->addComplaintalk($param)) {
  333. echo json_encode('success');
  334. } else {
  335. echo json_encode('error2');
  336. }
  337. } else {
  338. echo json_encode('error');
  339. }
  340. } else {
  341. echo json_encode('error1');
  342. }
  343. }
  344. /*
  345. * 获取投诉信息
  346. */
  347. private function get_complain_info($complain_id)
  348. {
  349. $complain_model = model('complain');
  350. $complain_info = $complain_model->getOneComplain($complain_id);
  351. if ($complain_info['accuser_id'] != session('member_id')) {
  352. $this->error(lang('param_error'));
  353. }
  354. $complain_info['member_status'] = 'accuser';
  355. $complain_info['complain_state_text'] = $this->get_complain_state_text($complain_info['complain_state']);
  356. return $complain_info;
  357. }
  358. /*
  359. * 检查投诉是否已经存在
  360. */
  361. private function check_complain_exist($goods_id)
  362. {
  363. $complain_model = model('complain');
  364. $param = array();
  365. $param[] = array('order_goods_id', '=', $goods_id);
  366. $param[] = array('accuser_id', '=', session('member_id'));
  367. $param[] = array('complain_state', '<', 90);
  368. return $complain_model->isComplainExist($param);
  369. }
  370. /*
  371. * 获得投诉状态文本
  372. */
  373. private function get_complain_state_text($complain_state)
  374. {
  375. switch (intval($complain_state)) {
  376. case self::STATE_NEW:
  377. return lang('complain_state_new');
  378. break;
  379. case self::STATE_APPEAL:
  380. return lang('complain_state_appeal');
  381. break;
  382. case self::STATE_TALK:
  383. return lang('complain_state_talk');
  384. break;
  385. case self::STATE_HANDLE:
  386. return lang('complain_state_handle');
  387. break;
  388. case self::STATE_FINISH:
  389. return lang('complain_state_finish');
  390. break;
  391. default:
  392. $this->error(lang('param_error'));
  393. }
  394. }
  395. private function upload_pic()
  396. {
  397. $complain_pic = array();
  398. $complain_pic[1] = 'input_complain_pic1';
  399. $complain_pic[2] = 'input_complain_pic2';
  400. $complain_pic[3] = 'input_complain_pic3';
  401. $pic_name = array();
  402. $count = 1;
  403. foreach ($complain_pic as $pic) {
  404. if (!empty($_FILES[$pic]['name'])) {
  405. $res = ds_upload_pic(ATTACH_PATH . DIRECTORY_SEPARATOR . 'complain', $pic);
  406. if ($res['code']) {
  407. $pic_name[$count] = $res['data']['file_name'];
  408. } else {
  409. $pic_name[$count] = '';
  410. }
  411. }
  412. $count++;
  413. }
  414. return $pic_name;
  415. }
  416. /**
  417. * 用户中心右边,小导航
  418. *
  419. * @param string $menu_type 导航类型
  420. * @param array $array 附加菜单
  421. * @return
  422. */
  423. public function getMemberItemList()
  424. {
  425. $menu_array = array(
  426. array(
  427. 'name' => 'complain_list',
  428. 'text' => lang('complain_manage_title'),
  429. 'url' => (string) url('Membercomplain/index')
  430. )
  431. );
  432. return $menu_array;
  433. }
  434. }