Sellerrefund.php 19 KB

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