Sellercomplain.php 18 KB

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