Sellercomplain.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. *
  7. *
  8. * ----------------------------------------------------------------------------
  9. *
  10. * 卖家投诉控制器
  11. */
  12. class Sellercomplain extends MobileSeller
  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. * @api {POST} api/Sellercomplain/index 被投诉列表
  29. * @apiVersion 1.0.0
  30. * @apiGroup Sellercomplain
  31. *
  32. * @apiHeader {String} X-DS-KEY 卖家授权token
  33. *
  34. * @apiParam {String} add_time_to 开始时间 YYYY-MM-DD
  35. * @apiParam {String} add_time_from 结束时间 YYYY-MM-DD
  36. * @apiParam {Int} state 投诉状态 1新投诉 2已关闭
  37. * @apiParam {String} type 查询字段 accuser_name原告用户名 complain_subject投诉主题
  38. * @apiParam {String} key 查询关键词
  39. * @apiParam {Int} page 页码
  40. * @apiParam {Int} pagesize 每页显示数量
  41. *
  42. * @apiSuccess {String} code 返回码,10000为成功
  43. * @apiSuccess {String} message 返回消息
  44. * @apiSuccess {Object} result 返回数据
  45. * @apiSuccess {Object[]} result.complaint_list 投诉列表 (返回字段参考complain表)
  46. * @apiSuccess {Object} result.goods_list 投诉商品列表,键为订单商品ID
  47. * @apiSuccess {Int} result.goods_list.buyer_id 买家ID
  48. * @apiSuccess {Float} result.goods_list.commis_rate 商品分类佣金比例
  49. * @apiSuccess {Int} result.goods_list.gc_id 分类ID
  50. * @apiSuccess {Int} result.goods_list.goods_id 商品ID
  51. * @apiSuccess {String} result.goods_list.goods_image 商品图片名称
  52. * @apiSuccess {String} result.goods_list.goods_image_url 商品图片完整地址
  53. * @apiSuccess {String} result.goods_list.goods_name 商品名称
  54. * @apiSuccess {Int} result.goods_list.goods_num 购买数量
  55. * @apiSuccess {Float} result.goods_list.goods_pay_price 商品实际支付金额
  56. * @apiSuccess {Float} result.goods_list.goods_price 商品价格
  57. * @apiSuccess {Int} result.goods_list.goods_type 商品类型 1默认2抢购商品3秒杀商品4组合套装5赠品6拼团7会员等级折扣
  58. * @apiSuccess {Int} result.goods_list.order_id 订单ID
  59. * @apiSuccess {Int} result.goods_list.promotions_id 促销ID
  60. * @apiSuccess {Int} result.goods_list.rec_id 订单商品表自增ID
  61. * @apiSuccess {Int} result.goods_list.store_id 店铺ID
  62. * @apiSuccess {Int} result.page_total 总页数
  63. * @apiSuccess {Boolean} result.hasmore 是否有更多 true是false否
  64. */
  65. public function index()
  66. {
  67. $complain_model = model('complain');
  68. $condition = array();
  69. $condition[] = array('accused_id', '=', $this->store_info['store_id']);
  70. if ((input('param.add_time_to')) != '' && (input('param.add_time_to')) != '') {
  71. $add_time_from = strtotime((input('param.add_time_from')));
  72. $add_time_to = strtotime((input('param.add_time_to')));
  73. $condition[] = array('complain_datetime', 'between', array($add_time_from, $add_time_to));
  74. }
  75. switch (intval(input('param.state'))) {
  76. case 1:
  77. $condition[] = array('complain_state', 'between', array(10, 90));
  78. break;
  79. case 2:
  80. $condition[] = array('complain_state', '=', 99);
  81. break;
  82. default:
  83. }
  84. $condition[] = array('complain_active', '=', 2); //投诉是需要平台审核通过之后 卖家才能看的到
  85. $complain_list = $complain_model->getComplainList($condition, 10);
  86. View::assign('show_page', $complain_model->page_info->render());
  87. $goods_list = $complain_model->getComplainGoodsList($complain_list);
  88. foreach ($goods_list as $key => $val) {
  89. $goods_list[$key]['goods_image_url'] = goods_thumb($val, 240);
  90. }
  91. $result = array_merge(array('complaint_list' => $complain_list, 'goods_list' => $goods_list), mobile_page($complain_model->page_info));
  92. ds_json_encode(10000, '', $result);
  93. }
  94. /**
  95. * @api {POST} api/Sellercomplain/complain_show 处理投诉请求
  96. * @apiVersion 1.0.0
  97. * @apiGroup Sellercomplain
  98. *
  99. * @apiHeader {String} X-DS-KEY 卖家授权token
  100. *
  101. * @apiParam {Int} complain_id 投诉ID
  102. *
  103. * @apiSuccess {String} code 返回码,10000为成功
  104. * @apiSuccess {String} message 返回消息
  105. * @apiSuccess {Object} result 返回数据
  106. * @apiSuccess {String[]} result.appeal_pic 申诉凭证图片列表
  107. * @apiSuccess {String[]} result.complain_pic 投诉凭证图片列表
  108. * @apiSuccess {Object} result.member 用户信息 (参考字段参考member表)
  109. * @apiSuccess {Object} result.return_info 退款信息 退款信息(参考字段参考order表)
  110. * @apiSuccess {Object} result.return_info.extend_order_common 订单其他信息(参考字段参考ordercommon表)
  111. * @apiSuccess {Object} result.return_info.extend_store 店铺信息(参考字段参考store表)
  112. * @apiSuccess {Object[]} result.return_info.goods_list 订单商品表格(参考字段参考ordergoods表)
  113. * @apiSuccess {Object} result.complain_info (参考字段参考complain表)
  114. * @apiSuccess {String} result.complain_info.complain_state_text 投诉状态描述
  115. */
  116. public function complain_show()
  117. {
  118. $complain_id = intval(input('param.complain_id'));
  119. //获取投诉详细信息
  120. $complain_info = $this->get_complain_info($complain_id);
  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[] = ds_get_pic(ATTACH_PATH . DIRECTORY_SEPARATOR . 'complain', $complain_info['complain_pic' . $i]);
  126. }
  127. if (!empty($complain_info['appeal_pic' . $i])) {
  128. $appeal_pic[] = ds_get_pic(ATTACH_PATH . DIRECTORY_SEPARATOR . 'complain', $complain_info['appeal_pic' . $i]);
  129. }
  130. }
  131. $member_model = model('member');
  132. $member = $member_model->getMemberInfoByID($complain_info['accuser_id']);
  133. $refundreturn_model = model('refundreturn');
  134. $condition = array();
  135. $condition[] = array('order_id', '=', $complain_info['order_id']);
  136. $return_info = $refundreturn_model->getRightOrderList($condition, $complain_info['order_goods_id']);
  137. ds_json_encode(10000, '', array('member' => $member, 'return_info' => $return_info, 'complain_info' => $complain_info, 'appeal_pic' => $appeal_pic, 'complain_pic' => $complain_pic));
  138. }
  139. /**
  140. * @api {POST} api/Sellercomplain/appeal_save 保存申诉
  141. * @apiVersion 1.0.0
  142. * @apiGroup Sellercomplain
  143. *
  144. * @apiHeader {String} X-DS-KEY 卖家授权token
  145. *
  146. * @apiParam {Int} input_complain_id 投诉ID
  147. * @apiParam {String} pic_name 投诉凭证 用,分隔多个投诉凭证
  148. * @apiParam {String} input_appeal_message 申诉内容
  149. *
  150. * @apiSuccess {String} code 返回码,10000为成功
  151. * @apiSuccess {String} message 返回消息
  152. * @apiSuccess {Object} result 返回数据
  153. */
  154. public function appeal_save()
  155. {
  156. $complain_id = intval(input('post.input_complain_id'));
  157. $pic_name = input('post.pic_name/a');
  158. //获取投诉详细信息
  159. $complain_info = $this->get_complain_info($complain_id);
  160. //检查当前是不是投诉状态
  161. if (intval($complain_info['complain_state']) !== self::STATE_APPEAL) {
  162. ds_json_encode(10001, lang('param_error'));
  163. }
  164. $input = array();
  165. $input['appeal_message'] = input('post.input_appeal_message');
  166. $sellercomplain_validate = ds_validate('sellercomplain');
  167. if (!$sellercomplain_validate->scene('appeal_save')->check($input)) {
  168. ds_json_encode(10001, $sellercomplain_validate->getError());
  169. }
  170. $input['appeal_pic1'] = isset($pic_name[0]) ? $pic_name[0] : '';
  171. $input['appeal_pic2'] = isset($pic_name[1]) ? $pic_name[1] : '';
  172. $input['appeal_pic3'] = isset($pic_name[2]) ? $pic_name[2] : '';
  173. $input['appeal_datetime'] = TIMESTAMP;
  174. $input['complain_state'] = self::STATE_TALK;
  175. $condition = array();
  176. $condition[] = array('complain_id', '=', $complain_id);
  177. //保存申诉信息
  178. $complain_model = model('complain');
  179. $complain_id = $complain_model->editComplain($input, $condition);
  180. $this->recordSellerlog('投诉申诉处理,投诉编号:' . $complain_id);
  181. ds_json_encode(10000, lang('appeal_submit_success'));
  182. }
  183. /**
  184. * @api {POST} api/Sellercomplain/upload_pic 上传凭证
  185. * @apiVersion 1.0.0
  186. * @apiGroup Sellercomplain
  187. *
  188. * @apiHeader {String} X-DS-KEY 用户授权token
  189. *
  190. * @apiParam {File} complain_pic 投诉凭证
  191. *
  192. * @apiSuccess {String} code 返回码,10000为成功
  193. * @apiSuccess {String} message 返回消息
  194. * @apiSuccess {Object} result 返回数据
  195. * @apiSuccess {String} result.file_name 文件名称
  196. * @apiSuccess {String} result.pic 文件完整路径
  197. */
  198. public function upload_pic()
  199. {
  200. if (!empty($_FILES['complain_pic']['name'])) {
  201. $file_name = $this->member_info['member_id'] . '_' . date('YmdHis') . rand(10000, 99999) . '.png';
  202. $res = ds_upload_pic(ATTACH_PATH . DIRECTORY_SEPARATOR . 'complain', 'complain_pic', $file_name);
  203. if ($res['code']) {
  204. $file_name = $res['data']['file_name'];
  205. } else {
  206. ds_json_encode(10001, $res['msg']);
  207. }
  208. $pic = ds_get_pic(ATTACH_PATH . DIRECTORY_SEPARATOR . 'complain', $file_name);
  209. ds_json_encode(10000, '', array('file_name' => $file_name, 'pic' => $pic));
  210. } else {
  211. ds_json_encode(10001, lang('file_empty'));
  212. }
  213. }
  214. /**
  215. * @api {POST} api/Sellercomplain/apply_handle 申请仲裁
  216. * @apiVersion 1.0.0
  217. * @apiGroup Sellercomplain
  218. *
  219. * @apiHeader {String} X-DS-KEY 卖家授权token
  220. *
  221. * @apiParam {Int} input_complain_id 投诉ID
  222. *
  223. * @apiSuccess {String} code 返回码,10000为成功
  224. * @apiSuccess {String} message 返回消息
  225. * @apiSuccess {Object} result 返回数据
  226. */
  227. public function apply_handle()
  228. {
  229. $complain_id = intval(input('post.input_complain_id'));
  230. //获取投诉详细信息
  231. $complain_info = $this->get_complain_info($complain_id);
  232. $complain_state = intval($complain_info['complain_state']);
  233. //检查当前是不是投诉状态
  234. if ($complain_state < self::STATE_TALK || $complain_state === 99) {
  235. ds_json_encode(10001, lang('param_error'));
  236. }
  237. $update_array = array();
  238. $update_array['complain_state'] = self::STATE_HANDLE;
  239. $condition = array();
  240. $condition[] = array('complain_id', '=', $complain_id);
  241. //保存投诉信息
  242. $complain_model = model('complain');
  243. $complain_id = $complain_model->editComplain($update_array, $condition);
  244. $this->recordSellerlog('投诉申请仲裁,投诉编号:' . $complain_id);
  245. ds_json_encode(10000, lang('handle_submit_success'));
  246. }
  247. /**
  248. * @api {POST} api/Sellercomplain/get_complain_talk 根据投诉id获取投诉对话
  249. * @apiVersion 1.0.0
  250. * @apiGroup Sellercomplain
  251. *
  252. * @apiHeader {String} X-DS-KEY 卖家授权token
  253. *
  254. * @apiParam {Int} input_complain_id 投诉ID
  255. *
  256. * @apiSuccess {String} code 返回码,10000为成功
  257. * @apiSuccess {String} message 返回消息
  258. * @apiSuccess {Object} result 返回数据
  259. * @apiSuccess {Object[]} result.talk_list 对话列表
  260. * @apiSuccess {String} result.talk_list.css 对话类型 admin管理员,accused被告人,accuser原告人
  261. * @apiSuccess {String} result.talk_list.talk 对话内容
  262. */
  263. public function get_complain_talk()
  264. {
  265. $complain_id = intval(input('post.complain_id'));
  266. $complain_info = $this->get_complain_info($complain_id);
  267. $complaintalk_model = model('complaintalk');
  268. $param = array();
  269. $param['complain_id'] = $complain_id;
  270. $complain_talk_list = $complaintalk_model->getComplaintalkList($param);
  271. $talk_list = array();
  272. $i = 0;
  273. if (!empty($complain_talk_list)) {
  274. foreach ($complain_talk_list as $talk) {
  275. $talk_list[$i]['css'] = $talk['talk_member_type'];
  276. $talk_list[$i]['talk'] = date("Y-m-d H:i:s", $talk['talk_datetime']);
  277. switch ($talk['talk_member_type']) {
  278. case 'accuser':
  279. $talk_list[$i]['talk'] .= lang('complain_accuser');
  280. break;
  281. case 'accused':
  282. $talk_list[$i]['talk'] .= lang('complain_accused');
  283. break;
  284. case 'admin':
  285. $talk_list[$i]['talk'] .= lang('complain_admin');
  286. break;
  287. default:
  288. $talk_list[$i]['talk'] .= lang('complain_unknow');
  289. }
  290. if (intval($talk['talk_state']) === 2) {
  291. $talk['talk_content'] = lang('talk_forbit_message');
  292. }
  293. $talk_list[$i]['talk'] .= '(' . $talk['talk_member_name'] . ')' . lang('complain_text_say') . ':' . $talk['talk_content'];
  294. $i++;
  295. }
  296. }
  297. ds_json_encode(10000, '', array('talk_list' => $talk_list));
  298. }
  299. /**
  300. * @api {POST} api/Sellercomplain/publish_complain_talk 根据发布投诉对话
  301. * @apiVersion 1.0.0
  302. * @apiGroup Sellercomplain
  303. *
  304. * @apiHeader {String} X-DS-KEY 卖家授权token
  305. *
  306. * @apiParam {Int} input_complain_id 投诉ID
  307. * @apiParam {String} complain_talk 发言内容
  308. *
  309. * @apiSuccess {String} code 返回码,10000为成功
  310. * @apiSuccess {String} message 返回消息
  311. * @apiSuccess {Object} result 返回数据
  312. */
  313. public function publish_complain_talk()
  314. {
  315. $complain_id = intval(input('post.complain_id'));
  316. $complain_talk = trim(input('post.complain_talk'));
  317. $talk_len = strlen($complain_talk);
  318. if ($talk_len > 0 && $talk_len < 255) {
  319. $complain_info = $this->get_complain_info($complain_id);
  320. $complain_state = intval($complain_info['complain_state']);
  321. //检查投诉是否是可发布对话状态
  322. if ($complain_state > self::STATE_APPEAL && $complain_state < self::STATE_FINISH) {
  323. $complaintalk_model = model('complaintalk');
  324. $param = array();
  325. $param['complain_id'] = $complain_id;
  326. $param['talk_member_id'] = $complain_info['accused_id'];
  327. $param['talk_member_name'] = $complain_info['accused_name'];
  328. $param['talk_member_type'] = $complain_info['member_status'];
  329. $param['talk_content'] = $complain_talk;
  330. $param['talk_state'] = 1;
  331. $param['talk_admin'] = 0;
  332. $param['talk_datetime'] = TIMESTAMP;
  333. if ($complaintalk_model->addComplaintalk($param)) {
  334. ds_json_encode(10000, ('talk_send_success'));
  335. } else {
  336. ds_json_encode(10001, ('talk_send_fail'));
  337. }
  338. } else {
  339. ds_json_encode(10001, lang('talk_state_error'));
  340. }
  341. } else {
  342. ds_json_encode(10001, lang('talk_null'));
  343. }
  344. }
  345. /*
  346. * 获取投诉信息
  347. */
  348. private function get_complain_info($complain_id)
  349. {
  350. if (empty($complain_id)) {
  351. ds_json_encode(10001, lang('param_error'));
  352. }
  353. $complain_model = model('complain');
  354. $complain_info = $complain_model->getOneComplain($complain_id);
  355. if ($complain_info['accused_id'] != $this->store_info['store_id']) {
  356. ds_json_encode(10001, lang('param_error'));
  357. }
  358. $complain_info['member_status'] = 'accused';
  359. $complain_info['complain_state_text'] = $this->get_complain_state_text($complain_info['complain_state']);
  360. return $complain_info;
  361. }
  362. /*
  363. * 获得投诉状态文本
  364. */
  365. private function get_complain_state_text($complain_state)
  366. {
  367. switch (intval($complain_state)) {
  368. case self::STATE_NEW:
  369. return lang('complain_state_new');
  370. break;
  371. case self::STATE_APPEAL:
  372. return lang('complain_state_appeal');
  373. break;
  374. case self::STATE_TALK:
  375. return lang('complain_state_talk');
  376. break;
  377. case self::STATE_HANDLE:
  378. return lang('complain_state_handle');
  379. break;
  380. case self::STATE_FINISH:
  381. return lang('complain_state_finish');
  382. break;
  383. default:
  384. ds_json_encode(10001, lang('param_error'));
  385. }
  386. }
  387. }