Sellercomplain.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. * ============================================================================
  7. * DSMall多用户商城
  8. * ============================================================================
  9. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  10. * 网站地址: http://www.csdeshang.com
  11. * ----------------------------------------------------------------------------
  12. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  13. * 不允许对程序代码以任何形式任何目的的再发布。
  14. * ============================================================================
  15. * 控制器
  16. */
  17. class Sellercomplain extends BaseSeller {
  18. //定义投诉状态常量
  19. const STATE_NEW = 10;
  20. const STATE_APPEAL = 20;
  21. const STATE_TALK = 30;
  22. const STATE_HANDLE = 40;
  23. const STATE_FINISH = 99;
  24. const STATE_UNACTIVE = 1;
  25. const STATE_ACTIVE = 2;
  26. public function initialize() {
  27. parent::initialize(); // TODO: Change the autogenerated stub
  28. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellercomplain.lang.php');
  29. }
  30. /*
  31. * 被投诉列表
  32. */
  33. public function index() {
  34. $complain_model = model('complain');
  35. $condition = array();
  36. $condition[] = array('accused_id', '=', session('store_id'));
  37. if ((input('param.add_time_from')) != '') {
  38. $add_time_from = strtotime((input('param.add_time_from')));
  39. $condition[] = array('complain_datetime', '>=', $add_time_from);
  40. }
  41. if ((input('param.add_time_to')) != '') {
  42. $add_time_to = strtotime((input('param.add_time_to')))+86399;
  43. $condition[] = array('complain_datetime', '<=', $add_time_to);
  44. }
  45. switch (intval(input('param.state'))) {
  46. case 1:
  47. $condition[] = array('complain_state', 'between', array(10, 90));
  48. break;
  49. case 2:
  50. $condition[] = array('complain_state', '=', 99);
  51. break;
  52. default :
  53. }
  54. $condition[] = array('complain_active', '=', 2); //投诉是需要平台审核通过之后 卖家才能看的到
  55. $complain_list = $complain_model->getComplainList($condition, 10);
  56. /* 设置卖家当前菜单 */
  57. $this->setSellerCurMenu('seller_complain');
  58. /* 设置卖家当前栏目 */
  59. $this->setSellerCurItem('complain_accused_list');
  60. View::assign('complain_list', $complain_list);
  61. View::assign('show_page', $complain_model->page_info->render());
  62. $goods_list = $complain_model->getComplainGoodsList($complain_list);
  63. View::assign('goods_list', $goods_list);
  64. return View::fetch($this->template_dir . 'index');
  65. }
  66. /*
  67. * 处理投诉请求
  68. */
  69. public function complain_show() {
  70. $complain_id = intval(input('param.complain_id'));
  71. //获取投诉详细信息
  72. $complain_info = $this->get_complain_info($complain_id);
  73. $member_model = model('member');
  74. $member = $member_model->getMemberInfoByID($complain_info['accuser_id']);
  75. View::assign('member', $member);
  76. $refundreturn_model = model('refundreturn');
  77. $condition = array();
  78. $condition[] = array('order_id', '=', $complain_info['order_id']);
  79. $return_info = $refundreturn_model->getRightOrderList($condition, $complain_info['order_goods_id']);
  80. View::assign('return_info', $return_info);
  81. $page_name = '';
  82. switch (intval($complain_info['complain_state'])) {
  83. case self::STATE_APPEAL:
  84. $page_name = 'complain_appeal';
  85. break;
  86. default:
  87. $page_name = 'complain_info';
  88. break;
  89. }
  90. View::assign('complain_info', $complain_info);
  91. /* 设置卖家当前菜单 */
  92. $this->setSellerCurMenu('seller_complain');
  93. /* 设置卖家当前栏目 */
  94. $this->setSellerCurItem('complain_accused_list');
  95. return View::fetch($this->template_dir . $page_name);
  96. }
  97. /*
  98. * 保存申诉
  99. */
  100. public function appeal_save() {
  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. $complain_id = intval(input('post.input_complain_id'));
  153. //获取投诉详细信息
  154. $complain_info = $this->get_complain_info($complain_id);
  155. $complain_state = intval($complain_info['complain_state']);
  156. //检查当前是不是投诉状态
  157. if ($complain_state < self::STATE_TALK || $complain_state === 99) {
  158. $this->error(lang('param_error'));
  159. }
  160. $update_array = array();
  161. $update_array['complain_state'] = self::STATE_HANDLE;
  162. $condition = array();
  163. $condition[] = array('complain_id','=',$complain_id);
  164. //保存投诉信息
  165. $complain_model = model('complain');
  166. $complain_id = $complain_model->editComplain($update_array, $condition);
  167. $this->recordSellerlog('投诉申请仲裁,投诉编号:' . $complain_id);
  168. $this->success(lang('handle_submit_success'), 'Sellercomplain/index');
  169. }
  170. /*
  171. * 根据投诉id获取投诉对话
  172. */
  173. public function get_complain_talk() {
  174. $complain_id = intval(input('post.complain_id'));
  175. $complain_info = $this->get_complain_info($complain_id);
  176. $complaintalk_model = model('complaintalk');
  177. $param = array();
  178. $param['complain_id'] = $complain_id;
  179. $complain_talk_list = $complaintalk_model->getComplaintalkList($param);
  180. $talk_list = array();
  181. $i = 0;
  182. if (!empty($complain_talk_list)) {
  183. foreach ($complain_talk_list as $talk) {
  184. $talk_list[$i]['css'] = $talk['talk_member_type'];
  185. $talk_list[$i]['talk'] = date("Y-m-d H:i:s", $talk['talk_datetime']);
  186. switch ($talk['talk_member_type']) {
  187. case 'accuser':
  188. $talk_list[$i]['talk'] .= lang('complain_accuser');
  189. break;
  190. case 'accused':
  191. $talk_list[$i]['talk'] .= lang('complain_accused');
  192. break;
  193. case 'admin':
  194. $talk_list[$i]['talk'] .= lang('complain_admin');
  195. break;
  196. default:
  197. $talk_list[$i]['talk'] .= lang('complain_unknow');
  198. }
  199. if (intval($talk['talk_state']) === 2) {
  200. $talk['talk_content'] = lang('talk_forbit_message');
  201. }
  202. $talk_list[$i]['talk'] .= '(' . $talk['talk_member_name'] . ')' . lang('complain_text_say') . ':' . $talk['talk_content'];
  203. $i++;
  204. }
  205. }
  206. echo json_encode($talk_list);
  207. }
  208. /*
  209. * 根据发布投诉对话
  210. */
  211. public function publish_complain_talk() {
  212. $complain_id = intval(input('post.complain_id'));
  213. $complain_talk = trim(input('post.complain_talk'));
  214. $talk_len = strlen($complain_talk);
  215. if ($talk_len > 0 && $talk_len < 255) {
  216. $complain_info = $this->get_complain_info($complain_id);
  217. $complain_state = intval($complain_info['complain_state']);
  218. //检查投诉是否是可发布对话状态
  219. if ($complain_state > self::STATE_APPEAL && $complain_state < self::STATE_FINISH) {
  220. $complaintalk_model = model('complaintalk');
  221. $param = array();
  222. $param['complain_id'] = $complain_id;
  223. $param['talk_member_id'] = $complain_info['accused_id'];
  224. $param['talk_member_name'] = $complain_info['accused_name'];
  225. $param['talk_member_type'] = $complain_info['member_status'];
  226. $param['talk_content'] = $complain_talk;
  227. $param['talk_state'] = 1;
  228. $param['talk_admin'] = 0;
  229. $param['talk_datetime'] = TIMESTAMP;
  230. if ($complaintalk_model->addComplaintalk($param)) {
  231. echo json_encode('success');
  232. } else {
  233. echo json_encode('error2');
  234. }
  235. } else {
  236. echo json_encode('error');
  237. }
  238. } else {
  239. echo json_encode('error1');
  240. }
  241. }
  242. /*
  243. * 获取投诉信息
  244. */
  245. private function get_complain_info($complain_id) {
  246. if (empty($complain_id)) {
  247. $this->error(lang('param_error'));
  248. }
  249. $complain_model = model('complain');
  250. $complain_info = $complain_model->getOneComplain($complain_id);
  251. if ($complain_info['accused_id'] != session('store_id')) {
  252. $this->error(lang('param_error'));
  253. }
  254. $complain_info['member_status'] = 'accused';
  255. $complain_info['complain_state_text'] = $this->get_complain_state_text($complain_info['complain_state']);
  256. return $complain_info;
  257. }
  258. /*
  259. * 获得投诉状态文本
  260. */
  261. private function get_complain_state_text($complain_state) {
  262. switch (intval($complain_state)) {
  263. case self::STATE_NEW:
  264. return lang('complain_state_new');
  265. break;
  266. case self::STATE_APPEAL:
  267. return lang('complain_state_appeal');
  268. break;
  269. case self::STATE_TALK:
  270. return lang('complain_state_talk');
  271. break;
  272. case self::STATE_HANDLE:
  273. return lang('complain_state_handle');
  274. break;
  275. case self::STATE_FINISH:
  276. return lang('complain_state_finish');
  277. break;
  278. default:
  279. $this->error(lang('param_error'));
  280. }
  281. }
  282. /**
  283. * 用户中心右边,小导航
  284. *
  285. * @param string $menu_type 导航类型
  286. * @param string
  287. * @param array $array 附加菜单
  288. * @return
  289. */
  290. protected function getSellerItemList() {
  291. $menu_array = array(
  292. array(
  293. 'name' => 'complain_accused_list',
  294. 'text' => lang('complain_manage_title'),
  295. 'url' => (string) url('Sellercomplain/index')
  296. )
  297. );
  298. return $menu_array;
  299. }
  300. }