Membercomplain.php 18 KB

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