Membercomplain.php 18 KB

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