Sellercomplain.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. *
  7. *
  8. * ----------------------------------------------------------------------------
  9. *
  10. * 控制器
  11. */
  12. class Sellercomplain extends BaseSeller
  13. {
  14. //定义投诉状态常量
  15. const STATE_NEW = 10;
  16. const STATE_APPEAL = 20;
  17. const STATE_TALK = 30;
  18. const STATE_HANDLE = 40;
  19. const STATE_FINISH = 99;
  20. const STATE_UNACTIVE = 1;
  21. const STATE_ACTIVE = 2;
  22. public function initialize()
  23. {
  24. parent::initialize(); // TODO: Change the autogenerated stub
  25. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellercomplain.lang.php');
  26. }
  27. /*
  28. * 被投诉列表
  29. */
  30. public function index()
  31. {
  32. $complain_model = model('complain');
  33. $condition = array();
  34. $condition[] = array('accused_id', '=', session('store_id'));
  35. if ((input('param.add_time_from')) != '') {
  36. $add_time_from = strtotime((input('param.add_time_from')));
  37. $condition[] = array('complain_datetime', '>=', $add_time_from);
  38. }
  39. if ((input('param.add_time_to')) != '') {
  40. $add_time_to = strtotime((input('param.add_time_to'))) + 86399;
  41. $condition[] = array('complain_datetime', '<=', $add_time_to);
  42. }
  43. switch (intval(input('param.state'))) {
  44. case 1:
  45. $condition[] = array('complain_state', 'between', array(10, 90));
  46. break;
  47. case 2:
  48. $condition[] = array('complain_state', '=', 99);
  49. break;
  50. default:
  51. }
  52. $condition[] = array('complain_active', '=', 2); //投诉是需要平台审核通过之后 卖家才能看的到
  53. $complain_list = $complain_model->getComplainList($condition, 10);
  54. /* 设置卖家当前菜单 */
  55. $this->setSellerCurMenu('seller_complain');
  56. /* 设置卖家当前栏目 */
  57. $this->setSellerCurItem('complain_accused_list');
  58. View::assign('complain_list', $complain_list);
  59. View::assign('show_page', $complain_model->page_info->render());
  60. $goods_list = $complain_model->getComplainGoodsList($complain_list);
  61. View::assign('goods_list', $goods_list);
  62. return View::fetch($this->template_dir . 'index');
  63. }
  64. /*
  65. * 处理投诉请求
  66. */
  67. public function complain_show()
  68. {
  69. $complain_id = intval(input('param.complain_id'));
  70. //获取投诉详细信息
  71. $complain_info = $this->get_complain_info($complain_id);
  72. $member_model = model('member');
  73. $member = $member_model->getMemberInfoByID($complain_info['accuser_id']);
  74. View::assign('member', $member);
  75. $refundreturn_model = model('refundreturn');
  76. $condition = array();
  77. $condition[] = array('order_id', '=', $complain_info['order_id']);
  78. $return_info = $refundreturn_model->getRightOrderList($condition, $complain_info['order_goods_id']);
  79. View::assign('return_info', $return_info);
  80. $page_name = '';
  81. switch (intval($complain_info['complain_state'])) {
  82. case self::STATE_APPEAL:
  83. $page_name = 'complain_appeal';
  84. break;
  85. default:
  86. $page_name = 'complain_info';
  87. break;
  88. }
  89. View::assign('complain_info', $complain_info);
  90. /* 设置卖家当前菜单 */
  91. $this->setSellerCurMenu('seller_complain');
  92. /* 设置卖家当前栏目 */
  93. $this->setSellerCurItem('complain_accused_list');
  94. return View::fetch($this->template_dir . $page_name);
  95. }
  96. /*
  97. * 保存申诉
  98. */
  99. public function appeal_save()
  100. {
  101. $complain_id = intval(input('post.input_complain_id'));
  102. //获取投诉详细信息
  103. $complain_info = $this->get_complain_info($complain_id);
  104. //检查当前是不是投诉状态
  105. if (intval($complain_info['complain_state']) !== self::STATE_APPEAL) {
  106. $this->error(lang('param_error'));
  107. }
  108. $input = array();
  109. $input['appeal_message'] = input('post.input_appeal_message');
  110. $sellercomplain_validate = ds_validate('sellercomplain');
  111. if (!$sellercomplain_validate->scene('appeal_save')->check($input)) {
  112. $this->error($sellercomplain_validate->getError());
  113. }
  114. //上传图片
  115. $appeal_pic = array();
  116. $appeal_pic[1] = 'input_appeal_pic1';
  117. $appeal_pic[2] = 'input_appeal_pic2';
  118. $appeal_pic[3] = 'input_appeal_pic3';
  119. $pic_name = array();
  120. $count = 1;
  121. foreach ($appeal_pic as $pic) {
  122. if (!empty($_FILES[$pic]['name'])) {
  123. $file_name = session('member_id') . '_' . date('YmdHis') . rand(10000, 99999) . '.png';
  124. $res = ds_upload_pic('home' . DIRECTORY_SEPARATOR . 'complain', $pic, $file_name);
  125. if ($res['code']) {
  126. $pic_name[$count] = $res['data']['file_name'];
  127. } else {
  128. $pic_name[$count] = '';
  129. }
  130. } else {
  131. $pic_name[$count] = '';
  132. }
  133. $count++;
  134. }
  135. $input['appeal_pic1'] = $pic_name[1];
  136. $input['appeal_pic2'] = $pic_name[2];
  137. $input['appeal_pic3'] = $pic_name[3];
  138. $input['appeal_datetime'] = TIMESTAMP;
  139. $input['complain_state'] = self::STATE_TALK;
  140. $condition = array();
  141. $condition[] = array('complain_id', '=', $complain_id);
  142. //保存申诉信息
  143. $complain_model = model('complain');
  144. $complain_id = $complain_model->editComplain($input, $condition);
  145. $this->recordSellerlog('投诉申诉处理,投诉编号:' . $complain_id);
  146. $this->success(lang('appeal_submit_success'), (string) url('Sellercomplain/index'));
  147. }
  148. /*
  149. * 申请仲裁
  150. */
  151. public function apply_handle()
  152. {
  153. $complain_id = intval(input('post.input_complain_id'));
  154. //获取投诉详细信息
  155. $complain_info = $this->get_complain_info($complain_id);
  156. $complain_state = intval($complain_info['complain_state']);
  157. //检查当前是不是投诉状态
  158. if ($complain_state < self::STATE_TALK || $complain_state === 99) {
  159. $this->error(lang('param_error'));
  160. }
  161. $update_array = array();
  162. $update_array['complain_state'] = self::STATE_HANDLE;
  163. $condition = array();
  164. $condition[] = array('complain_id', '=', $complain_id);
  165. //保存投诉信息
  166. $complain_model = model('complain');
  167. $complain_id = $complain_model->editComplain($update_array, $condition);
  168. $this->recordSellerlog('投诉申请仲裁,投诉编号:' . $complain_id);
  169. $this->success(lang('handle_submit_success'), 'Sellercomplain/index');
  170. }
  171. /*
  172. * 根据投诉id获取投诉对话
  173. */
  174. public function get_complain_talk()
  175. {
  176. $complain_id = intval(input('post.complain_id'));
  177. $complain_info = $this->get_complain_info($complain_id);
  178. $complaintalk_model = model('complaintalk');
  179. $param = array();
  180. $param['complain_id'] = $complain_id;
  181. $complain_talk_list = $complaintalk_model->getComplaintalkList($param);
  182. $talk_list = array();
  183. $i = 0;
  184. if (!empty($complain_talk_list)) {
  185. foreach ($complain_talk_list as $talk) {
  186. $talk_list[$i]['css'] = $talk['talk_member_type'];
  187. $talk_list[$i]['talk'] = date("Y-m-d H:i:s", $talk['talk_datetime']);
  188. switch ($talk['talk_member_type']) {
  189. case 'accuser':
  190. $talk_list[$i]['talk'] .= lang('complain_accuser');
  191. break;
  192. case 'accused':
  193. $talk_list[$i]['talk'] .= lang('complain_accused');
  194. break;
  195. case 'admin':
  196. $talk_list[$i]['talk'] .= lang('complain_admin');
  197. break;
  198. default:
  199. $talk_list[$i]['talk'] .= lang('complain_unknow');
  200. }
  201. if (intval($talk['talk_state']) === 2) {
  202. $talk['talk_content'] = lang('talk_forbit_message');
  203. }
  204. $talk_list[$i]['talk'] .= '(' . $talk['talk_member_name'] . ')' . lang('complain_text_say') . ':' . $talk['talk_content'];
  205. $i++;
  206. }
  207. }
  208. echo json_encode($talk_list);
  209. }
  210. /*
  211. * 根据发布投诉对话
  212. */
  213. public function publish_complain_talk()
  214. {
  215. $complain_id = intval(input('post.complain_id'));
  216. $complain_talk = trim(input('post.complain_talk'));
  217. $talk_len = strlen($complain_talk);
  218. if ($talk_len > 0 && $talk_len < 255) {
  219. $complain_info = $this->get_complain_info($complain_id);
  220. $complain_state = intval($complain_info['complain_state']);
  221. //检查投诉是否是可发布对话状态
  222. if ($complain_state > self::STATE_APPEAL && $complain_state < self::STATE_FINISH) {
  223. $complaintalk_model = model('complaintalk');
  224. $param = array();
  225. $param['complain_id'] = $complain_id;
  226. $param['talk_member_id'] = $complain_info['accused_id'];
  227. $param['talk_member_name'] = $complain_info['accused_name'];
  228. $param['talk_member_type'] = $complain_info['member_status'];
  229. $param['talk_content'] = $complain_talk;
  230. $param['talk_state'] = 1;
  231. $param['talk_admin'] = 0;
  232. $param['talk_datetime'] = TIMESTAMP;
  233. if ($complaintalk_model->addComplaintalk($param)) {
  234. echo json_encode('success');
  235. } else {
  236. echo json_encode('error2');
  237. }
  238. } else {
  239. echo json_encode('error');
  240. }
  241. } else {
  242. echo json_encode('error1');
  243. }
  244. }
  245. /*
  246. * 获取投诉信息
  247. */
  248. private function get_complain_info($complain_id)
  249. {
  250. if (empty($complain_id)) {
  251. $this->error(lang('param_error'));
  252. }
  253. $complain_model = model('complain');
  254. $complain_info = $complain_model->getOneComplain($complain_id);
  255. if ($complain_info['accused_id'] != session('store_id')) {
  256. $this->error(lang('param_error'));
  257. }
  258. $complain_info['member_status'] = 'accused';
  259. $complain_info['complain_state_text'] = $this->get_complain_state_text($complain_info['complain_state']);
  260. return $complain_info;
  261. }
  262. /*
  263. * 获得投诉状态文本
  264. */
  265. private function get_complain_state_text($complain_state)
  266. {
  267. switch (intval($complain_state)) {
  268. case self::STATE_NEW:
  269. return lang('complain_state_new');
  270. break;
  271. case self::STATE_APPEAL:
  272. return lang('complain_state_appeal');
  273. break;
  274. case self::STATE_TALK:
  275. return lang('complain_state_talk');
  276. break;
  277. case self::STATE_HANDLE:
  278. return lang('complain_state_handle');
  279. break;
  280. case self::STATE_FINISH:
  281. return lang('complain_state_finish');
  282. break;
  283. default:
  284. $this->error(lang('param_error'));
  285. }
  286. }
  287. /**
  288. * 用户中心右边,小导航
  289. *
  290. * @param string $menu_type 导航类型
  291. * @param string
  292. * @param array $array 附加菜单
  293. * @return
  294. */
  295. protected function getSellerItemList()
  296. {
  297. $menu_array = array(
  298. array(
  299. 'name' => 'complain_accused_list',
  300. 'text' => lang('complain_manage_title'),
  301. 'url' => (string) url('Sellercomplain/index')
  302. )
  303. );
  304. return $menu_array;
  305. }
  306. }