Sellercomplain.php 18 KB

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