Membercomplain.php 18 KB

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