Sellercomplain.php 12 KB

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