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