Sellerrefund.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Lang;
  4. /**
  5. *
  6. *
  7. * ----------------------------------------------------------------------------
  8. *
  9. * 卖家退款控制器
  10. */
  11. class Sellerrefund extends MobileSeller
  12. {
  13. public function initialize()
  14. {
  15. parent::initialize();
  16. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellerrefund.lang.php');
  17. }
  18. /**
  19. * @api {POST} api/Sellerrefund/refund_list 退款记录列表页
  20. * @apiVersion 1.0.0
  21. * @apiGroup Sellerrefund
  22. *
  23. * @apiHeader {String} X-DS-KEY 卖家授权token
  24. *
  25. * @apiParam {Int} refund_type 类型 1退款 2退货
  26. * @apiParam {String} key 搜索关键词
  27. * @apiParam {String} type 搜索字段名 order_sn订单号 refund_sn退款单号 buyer_name买家用户名
  28. * @apiParam {String} add_time_from 开始日期 YYYY-MM-DD
  29. * @apiParam {String} add_time_to 结束日期 YYYY-MM-DD
  30. * @apiParam {Int} state 卖家处理状态:1:待审核,2:同意,3:不同意
  31. * @apiParam {Int} lock 订单锁定类型:1:不用锁定,2:需要锁定
  32. * @apiParam {String} page 页码
  33. * @apiParam {String} pagesize 每页显示数量
  34. *
  35. * @apiSuccess {String} code 返回码,10000为成功
  36. * @apiSuccess {String} message 返回消息
  37. * @apiSuccess {Object} result 返回数据
  38. * @apiSuccess {Object[]} result.refund_list 退款记录列表 (返回字段参考refundreturn表)
  39. * @apiSuccess {Object[]} result.refund_list.goods_list 退款商品列表 (返回字段参考ordergoods表)
  40. * @apiSuccess {String} result.refund_list.goods_list.goods_img_480 商品图片完整路径
  41. * @apiSuccess {String} result.refund_list.seller_state_text 卖家处理状态描述
  42. * @apiSuccess {String} result.refund_list.refund_state_text 管理员处理状态描述
  43. * @apiSuccess {String} result.refund_list.delay_time 延期时间
  44. * @apiSuccess {Int} result.page_total 总页数
  45. * @apiSuccess {Boolean} result.hasmore 是否有更多 true是false否
  46. */
  47. public function refund_list()
  48. {
  49. $refund_type = intval(input('refund_type'));
  50. if (!in_array($refund_type, array(1, 2))) {
  51. $refund_type = 1;
  52. }
  53. $refundreturn_model = model('refundreturn');
  54. $condition = array();
  55. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  56. $condition[] = array('refund_type', '=', $refund_type); //类型:1为退款,2为退货
  57. $keyword_type = array('order_sn', 'refund_sn', 'buyer_name');
  58. $key = input('key');
  59. $type = input('type');
  60. if (trim($key) != '' && in_array($type, $keyword_type)) {
  61. $condition[] = array($type, 'like', '%' . $key . '%');
  62. }
  63. $add_time_from = input('add_time_from');
  64. $add_time_to = input('add_time_to');
  65. if (trim($add_time_from) != '' || trim($add_time_to) != '') {
  66. if ($add_time_from !== false || $add_time_to !== false) {
  67. $condition[] = array('add_time', 'between time', array($add_time_from, $add_time_to));
  68. }
  69. }
  70. $seller_state = intval(input('state'));
  71. if ($seller_state > 0) {
  72. $condition[] = array('seller_state', '=', $seller_state);
  73. }
  74. $order_lock = intval(input('lock'));
  75. if ($order_lock) {
  76. $condition[] = array('order_lock', '=', $order_lock);
  77. }
  78. $refund_list = $refundreturn_model->getRefundList($condition, 10);
  79. $mobile_page = $refundreturn_model->page_info;
  80. $order_model = model('order');
  81. $trade_model = model('trade');
  82. $return_delay = $trade_model->getMaxDay('return_delay'); //发货默认5天后才能选择没收到
  83. foreach ($refund_list as $k => $v) {
  84. $goods_list = array();
  85. if ($v['goods_id'] > 0) {
  86. $goods = array();
  87. $goods['goods_id'] = $v['goods_id'];
  88. $goods['goods_name'] = $v['goods_name'];
  89. $goods['goods_img_480'] = goods_thumb($v, 480);
  90. $goods_list[] = $goods;
  91. } else {
  92. $condition = array();
  93. $condition[] = array('order_id', '=', $v['order_id']);
  94. $order_goods_list = $order_model->getOrdergoodsList($condition);
  95. foreach ($order_goods_list as $key => $value) {
  96. $goods = array();
  97. $goods['goods_id'] = $value['goods_id'];
  98. $goods['goods_name'] = $value['goods_name'];
  99. //$goods['goods_spec'] = $value['goods_spec'];
  100. $goods['goods_img_480'] = goods_thumb($value, 480);
  101. $goods_list[] = $goods;
  102. }
  103. }
  104. $refund_list[$k]['goods_list'] = $goods_list;
  105. $refund_state_array = $this->getRefundStateArray();
  106. $refund_list[$k]['seller_state_text'] = $refund_state_array['state_array'][$v['seller_state']];
  107. $refund_list[$k]['refund_state_text'] = $refund_state_array['admin_array'][$v['refund_state']];
  108. $refund_list[$k]['delay_time'] = TIMESTAMP - $v['delay_time'] - 60 * 60 * 24 * $return_delay;
  109. }
  110. $result = array_merge(array('refund_list' => $refund_list), mobile_page($mobile_page));
  111. ds_json_encode(10000, '', $result);
  112. }
  113. /**
  114. * @api {POST} api/Sellerrefund/edit 退款审核页
  115. * @apiVersion 1.0.0
  116. * @apiGroup Sellerrefund
  117. *
  118. * @apiHeader {String} X-DS-KEY 卖家授权token
  119. *
  120. * @apiParam {Int} refund_id 退款ID
  121. * @apiParam {Int} refund_type 类型 1退款 2退货
  122. * @apiParam {String} seller_message 卖家备注
  123. * @apiParam {Int} seller_state 卖家处理状态:1:待审核,2:同意,3:不同意
  124. *
  125. * @apiSuccess {String} code 返回码,10000为成功
  126. * @apiSuccess {String} message 返回消息
  127. * @apiSuccess {Object} result 返回数据
  128. */
  129. public function edit()
  130. {
  131. $refundreturn_model = model('refundreturn');
  132. $condition = array();
  133. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  134. $condition[] = array('refund_id', '=', intval(input('param.refund_id')));
  135. $refund = $refundreturn_model->getRefundreturnInfo($condition);
  136. if ($refund['seller_state'] != '1') { //检查状态,防止页面刷新不及时造成数据错误
  137. ds_json_encode(10001, lang('param_error'));
  138. }
  139. $order_id = $refund['order_id'];
  140. $refund_array = array();
  141. $refund_array['seller_time'] = TIMESTAMP;
  142. $refund_array['seller_state'] = input('post.seller_state'); //卖家处理状态:1为待审核,2为同意,3为不同意
  143. $refund_array['seller_message'] = input('post.seller_message');
  144. if ($refund_array['seller_state'] == '3') {
  145. $refund_array['refund_state'] = '3'; //状态:1为处理中,2为待管理员处理,3为已完成
  146. } else {
  147. $refund_array['seller_state'] = '2';
  148. $refund_array['refund_state'] = '2';
  149. }
  150. if ($refund['refund_type'] == 2 && $refund_array['seller_state'] == '2') {
  151. $return_type = intval(input('post.return_type'));
  152. $refund_array['return_type'] = $return_type;
  153. if (!in_array($return_type, array(1, 2))) {
  154. $refund_array['return_type'] = 2;
  155. }
  156. }
  157. $state = $refundreturn_model->editRefundreturn($condition, $refund_array);
  158. if ($state) {
  159. if ($refund_array['seller_state'] == '3') {
  160. if ($refund['order_lock'] == '2') {
  161. $refundreturn_model->editOrderUnlock($order_id); //订单解锁
  162. }
  163. //自提点订单解锁
  164. $chain_order_model = model('chain_order');
  165. $chain_order_model->editChainOrderUnlock($order_id);
  166. }
  167. $this->recordSellerlog(lang('refund_processing') . $refund['refund_sn']);
  168. // 发送买家消息
  169. $param = array();
  170. $param['code'] = 'refund_return_notice';
  171. $param['member_id'] = $refund['buyer_id'];
  172. //阿里短信参数
  173. $param['ali_param'] = array(
  174. 'refund_sn' => $refund['refund_sn']
  175. );
  176. $param['ten_param'] = array(
  177. $refund['refund_sn']
  178. );
  179. $param['param'] = array_merge($param['ali_param'], array(
  180. 'refund_url' => HOME_SITE_URL . '/Memberrefund/view/?refund_id=' . $refund['refund_id'],
  181. ));
  182. //微信模板消息
  183. $param['weixin_param'] = array(
  184. 'url' => config('ds_config.h5_site_url') . '/pages/member/' . ($refund['refund_type'] == 1 ? 'refund/RefundView' : 'return/ReturnView') . '?refund_id=' . $refund['refund_id'],
  185. 'data' => array(
  186. "keyword1" => array(
  187. "value" => $refund['order_sn'],
  188. "color" => "#333"
  189. ),
  190. "keyword2" => array(
  191. "value" => $refund['refund_amount'],
  192. "color" => "#333"
  193. )
  194. ),
  195. );
  196. model('cron')->addCron(array('cron_exetime' => TIMESTAMP, 'cron_type' => 'sendMemberMsg', 'cron_value' => serialize($param)));
  197. ds_json_encode(10000, lang('ds_common_op_succ'));
  198. } else {
  199. ds_json_encode(10001, lang('ds_common_op_fail'));
  200. }
  201. }
  202. /**
  203. * @api {POST} api/Sellerrefund/get_refund_info 退款记录查看页
  204. * @apiVersion 1.0.0
  205. * @apiGroup Sellerrefund
  206. *
  207. * @apiHeader {String} X-DS-KEY 卖家授权token
  208. *
  209. * @apiParam {Int} refund_id 退款ID
  210. *
  211. * @apiSuccess {String} code 返回码,10000为成功
  212. * @apiSuccess {String} message 返回消息
  213. * @apiSuccess {Object} result 返回数据
  214. * @apiSuccess {String[]} result.pic_list 退货凭证列表
  215. * @apiSuccess {Object} result.refund 退货信息 (返回字段参考refundreturn)
  216. */
  217. public function get_refund_info()
  218. {
  219. $refundreturn_model = model('refundreturn');
  220. $condition = array();
  221. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  222. $condition[] = array('refund_id', '=', intval(input('param.refund_id')));
  223. $refund = $refundreturn_model->getRefundreturnInfo($condition);
  224. $info['buyer'] = array();
  225. if (!empty($refund['pic_info'])) {
  226. $info = unserialize($refund['pic_info']);
  227. }
  228. $pic_list = array();
  229. if (is_array($info['buyer'])) {
  230. foreach ($info['buyer'] as $k => $v) {
  231. if (!empty($v)) {
  232. $pic_list[] = ds_get_pic(ATTACH_PATH . '/refund', $v);
  233. }
  234. }
  235. }
  236. ds_json_encode(10000, '', array('refund' => $refund, 'pic_list' => $pic_list));
  237. }
  238. /**
  239. * @api {POST} api/Sellerrefund/receive 收货
  240. * @apiVersion 1.0.0
  241. * @apiGroup Sellerrefund
  242. *
  243. * @apiHeader {String} X-DS-KEY 卖家授权token
  244. *
  245. * @apiParam {Int} refund_id 退款ID
  246. * @apiParam {Int} return_type 物流状态 3:延迟收货(发货需要超过5天) 4:已收货
  247. *
  248. * @apiSuccess {String} code 返回码,10000为成功
  249. * @apiSuccess {String} message 返回消息
  250. * @apiSuccess {Object} result 返回数据
  251. */
  252. public function receive()
  253. {
  254. $refundreturn_model = model('refundreturn');
  255. $trade_model = model('trade');
  256. $condition = array();
  257. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  258. $condition[] = array('refund_id', '=', intval(input('param.return_id')));
  259. $return = $refundreturn_model->getRefundreturnInfo($condition);
  260. $return_delay = $trade_model->getMaxDay('return_delay'); //发货默认5天后才能选择没收到
  261. $delay_time = TIMESTAMP - $return['delay_time'] - 60 * 60 * 24 * $return_delay;
  262. if ($return['seller_state'] != '2' || $return['goods_state'] != '2') { //检查状态,防止页面刷新不及时造成数据错误
  263. ds_json_encode(10001, lang('param_error'));
  264. }
  265. $refund_array = array();
  266. if (input('post.return_type') == '3' && $delay_time > 0) {
  267. $refund_array['goods_state'] = '3';
  268. } else {
  269. $refund_array['receive_time'] = TIMESTAMP;
  270. $refund_array['receive_message'] = lang('confirm_receipt_goods_completed');
  271. $refund_array['refund_state'] = '2'; //状态:1为处理中,2为待管理员处理,3为已完成
  272. $refund_array['goods_state'] = '4';
  273. }
  274. $state = $refundreturn_model->editRefundreturn($condition, $refund_array);
  275. if ($state) {
  276. $this->recordSellerlog(lang('confirm_receipt_goods_returned') . $return['refund_sn']);
  277. // 发送买家消息
  278. $param = array();
  279. $param['code'] = 'refund_return_notice';
  280. $param['member_id'] = $return['buyer_id'];
  281. //阿里短信参数
  282. $param['ali_param'] = array(
  283. 'refund_sn' => $return['refund_sn']
  284. );
  285. $param['ten_param'] = array(
  286. $return['refund_sn']
  287. );
  288. $param['param'] = array_merge($param['ali_param'], array(
  289. 'refund_url' => HOME_SITE_URL . '/Memberreturn/view?return_id=' . $return['refund_id'],
  290. ));
  291. //微信模板消息
  292. $param['weixin_param'] = array(
  293. 'url' => config('ds_config.h5_site_url') . '/pages/member/return/ReturnView?refund_id=' . $return['refund_id'],
  294. 'data' => array(
  295. "keyword1" => array(
  296. "value" => $return['order_sn'],
  297. "color" => "#333"
  298. ),
  299. "keyword2" => array(
  300. "value" => $return['refund_amount'],
  301. "color" => "#333"
  302. )
  303. ),
  304. );
  305. model('cron')->addCron(array('cron_exetime' => TIMESTAMP, 'cron_type' => 'sendMemberMsg', 'cron_value' => serialize($param)));
  306. ds_json_encode(10000, lang('ds_common_op_succ'));
  307. } else {
  308. ds_json_encode(10001, lang('ds_common_op_fail'));
  309. }
  310. }
  311. function getRefundStateArray()
  312. {
  313. $state_array = array(
  314. '1' => lang('refund_state_confirm'),
  315. '2' => lang('refund_state_yes'),
  316. '3' => lang('refund_state_no')
  317. ); //卖家处理状态:1为待审核,2为同意,3为不同意
  318. $admin_array = array(
  319. '1' => lang('in_processing'),
  320. '2' => lang('to_processed'),
  321. '3' => lang('has_been_completed'),
  322. '4' => lang('refund_state_no')
  323. ); //确认状态:1为买家或卖家处理中,2为待平台管理员处理,3为退款退货已完成
  324. return array('state_array' => $state_array, 'admin_array' => $admin_array,);
  325. }
  326. /**
  327. * @api {POST} api/Sellerrefund/search_deliver 物流跟踪
  328. * @apiVersion 1.0.0
  329. * @apiGroup Sellerrefund
  330. *
  331. * @apiHeader {String} X-DS-KEY 卖家授权token
  332. *
  333. * @apiParam {String} refund_id 退款id
  334. *
  335. * @apiSuccess {String} code 返回码,10000为成功
  336. * @apiSuccess {String} message 返回消息
  337. * @apiSuccess {Object} result 返回数据
  338. * @apiSuccess {String} result.express_name 物流公司名称
  339. * @apiSuccess {String} result.shipping_code 物流单号
  340. * @apiSuccess {Object[]} result.deliver_info 物流数据
  341. * @apiSuccess {String} result.deliver_info.context 内容
  342. * @apiSuccess {String} result.deliver_info.time 时间
  343. */
  344. public function search_deliver()
  345. {
  346. $refund_id = intval(input('post.refund_id'));
  347. if ($refund_id <= 0) {
  348. ds_json_encode(10001, lang('param_error'));
  349. }
  350. $refundreturn_model = model('refundreturn');
  351. $condition = array();
  352. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  353. $condition[] = array('refund_id', '=', $refund_id);
  354. $return = $refundreturn_model->getRefundreturnInfo($condition);
  355. if (empty($return)) {
  356. ds_json_encode(10001, lang('refund_not_exist'));
  357. }
  358. if (!$return['express_id'] || !$return['invoice_no']) {
  359. ds_json_encode(10001, lang('deliver_not_exist'));
  360. }
  361. $express = rkcache('express', true);
  362. if (isset($express[$return['express_id']])) {
  363. $express_code = $express[$return['express_id']]['express_code'];
  364. $express_name = $express[$return['express_id']]['express_name'];
  365. $deliver_info = $this->_get_express($express_code, $return['invoice_no']);
  366. } else {
  367. $express_code = '';
  368. $express_name = '';
  369. $deliver_info = array();
  370. }
  371. ds_json_encode(10000, '', array('express_name' => $express_name, 'shipping_code' => $return['invoice_no'], 'deliver_info' => $deliver_info));
  372. }
  373. /**
  374. * 从第三方取快递信息
  375. *
  376. */
  377. public function _get_express($express_code, $shipping_code)
  378. {
  379. $result = model('express')->queryExpress($express_code, $shipping_code);
  380. if ($result['Success'] != true) {
  381. ds_json_encode(10001, lang('deliver_search_fail'));
  382. }
  383. $content['Traces'] = array_reverse($result['Traces']);
  384. $output = array();
  385. if (is_array($content['Traces'])) {
  386. foreach ($content['Traces'] as $k => $v) {
  387. if ($v['AcceptTime'] == '')
  388. continue;
  389. //$output[] = $v['time'] . '&nbsp;&nbsp;' . $v['context'];
  390. $output[$k]['AcceptTime'] = $v['AcceptTime'];
  391. $output[$k]['AcceptStation'] = $v['AcceptStation'];
  392. }
  393. }
  394. if (empty($output))
  395. ds_json_encode(10001, lang('deliver_not_exist'));
  396. return $output;
  397. }
  398. }