Sellerrefund.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Lang;
  4. /**
  5. * ============================================================================
  6. * DSMall多用户商城
  7. * ============================================================================
  8. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  9. * 网站地址: http://www.csdeshang.com
  10. * ----------------------------------------------------------------------------
  11. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  12. * 不允许对程序代码以任何形式任何目的的再发布。
  13. * ============================================================================
  14. * 卖家退款控制器
  15. */
  16. class Sellerrefund extends MobileSeller {
  17. public function initialize() {
  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. $refund_type = intval(input('refund_type'));
  52. if (!in_array($refund_type, array(1, 2))) {
  53. $refund_type = 1;
  54. }
  55. $refundreturn_model = model('refundreturn');
  56. $condition = array();
  57. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  58. $condition[] = array('refund_type', '=', $refund_type); //类型:1为退款,2为退货
  59. $keyword_type = array('order_sn', 'refund_sn', 'buyer_name');
  60. $key = input('key');
  61. $type = input('type');
  62. if (trim($key) != '' && in_array($type, $keyword_type)) {
  63. $condition[] = array($type, 'like', '%' . $key . '%');
  64. }
  65. $add_time_from = input('add_time_from');
  66. $add_time_to = input('add_time_to');
  67. if (trim($add_time_from) != '' || trim($add_time_to) != '') {
  68. if ($add_time_from !== false || $add_time_to !== false) {
  69. $condition[] = array('add_time', 'between time', array($add_time_from, $add_time_to));
  70. }
  71. }
  72. $seller_state = intval(input('state'));
  73. if ($seller_state > 0) {
  74. $condition[]=array('seller_state','=',$seller_state);
  75. }
  76. $order_lock = intval(input('lock'));
  77. if ($order_lock) {
  78. $condition[]=array('order_lock','=',$order_lock);
  79. }
  80. $refund_list = $refundreturn_model->getRefundList($condition, 10);
  81. $mobile_page = $refundreturn_model->page_info;
  82. $order_model = model('order');
  83. $trade_model = model('trade');
  84. $return_delay = $trade_model->getMaxDay('return_delay'); //发货默认5天后才能选择没收到
  85. foreach ($refund_list as $k => $v) {
  86. $goods_list = array();
  87. if ($v['goods_id'] > 0) {
  88. $goods = array();
  89. $goods['goods_id'] = $v['goods_id'];
  90. $goods['goods_name'] = $v['goods_name'];
  91. $goods['goods_img_480'] = goods_thumb($v, 480);
  92. $goods_list[] = $goods;
  93. } else {
  94. $condition = array();
  95. $condition[] = array('order_id','=',$v['order_id']);
  96. $order_goods_list = $order_model->getOrdergoodsList($condition);
  97. foreach ($order_goods_list as $key => $value) {
  98. $goods = array();
  99. $goods['goods_id'] = $value['goods_id'];
  100. $goods['goods_name'] = $value['goods_name'];
  101. //$goods['goods_spec'] = $value['goods_spec'];
  102. $goods['goods_img_480'] = goods_thumb($value, 480);
  103. $goods_list[] = $goods;
  104. }
  105. }
  106. $refund_list[$k]['goods_list'] = $goods_list;
  107. $refund_state_array = $this->getRefundStateArray();
  108. $refund_list[$k]['seller_state_text'] = $refund_state_array['state_array'][$v['seller_state']];
  109. $refund_list[$k]['refund_state_text'] = $refund_state_array['admin_array'][$v['refund_state']];
  110. $refund_list[$k]['delay_time'] = TIMESTAMP - $v['delay_time'] - 60 * 60 * 24 * $return_delay;
  111. }
  112. $result = array_merge(array('refund_list' => $refund_list), mobile_page($mobile_page));
  113. ds_json_encode(10000, '', $result);
  114. }
  115. /**
  116. * @api {POST} api/Sellerrefund/edit 退款审核页
  117. * @apiVersion 1.0.0
  118. * @apiGroup Sellerrefund
  119. *
  120. * @apiHeader {String} X-DS-KEY 卖家授权token
  121. *
  122. * @apiParam {Int} refund_id 退款ID
  123. * @apiParam {Int} refund_type 类型 1退款 2退货
  124. * @apiParam {String} seller_message 卖家备注
  125. * @apiParam {Int} seller_state 卖家处理状态:1:待审核,2:同意,3:不同意
  126. *
  127. * @apiSuccess {String} code 返回码,10000为成功
  128. * @apiSuccess {String} message 返回消息
  129. * @apiSuccess {Object} result 返回数据
  130. */
  131. public function edit() {
  132. $refundreturn_model = model('refundreturn');
  133. $condition = array();
  134. $condition[] = array('store_id','=',$this->store_info['store_id']);
  135. $condition[] = array('refund_id','=',intval(input('param.refund_id')));
  136. $refund = $refundreturn_model->getRefundreturnInfo($condition);
  137. if ($refund['seller_state'] != '1') {//检查状态,防止页面刷新不及时造成数据错误
  138. ds_json_encode(10001, lang('param_error'));
  139. }
  140. $order_id = $refund['order_id'];
  141. $refund_array = array();
  142. $refund_array['seller_time'] = TIMESTAMP;
  143. $refund_array['seller_state'] = input('post.seller_state'); //卖家处理状态:1为待审核,2为同意,3为不同意
  144. $refund_array['seller_message'] = input('post.seller_message');
  145. if ($refund_array['seller_state'] == '3') {
  146. $refund_array['refund_state'] = '3'; //状态:1为处理中,2为待管理员处理,3为已完成
  147. } else {
  148. $refund_array['seller_state'] = '2';
  149. $refund_array['refund_state'] = '2';
  150. }
  151. if ($refund['refund_type'] == 2 && $refund_array['seller_state'] == '2') {
  152. $return_type = intval(input('post.return_type'));
  153. $refund_array['return_type'] = $return_type;
  154. if (!in_array($return_type, array(1, 2))) {
  155. $refund_array['return_type'] = 2;
  156. }
  157. }
  158. $state = $refundreturn_model->editRefundreturn($condition, $refund_array);
  159. if ($state) {
  160. if ($refund_array['seller_state'] == '3') {
  161. if($refund['order_lock'] == '2'){
  162. $refundreturn_model->editOrderUnlock($order_id); //订单解锁
  163. }
  164. //自提点订单解锁
  165. $chain_order_model=model('chain_order');
  166. $chain_order_model->editChainOrderUnlock($order_id);
  167. }
  168. $this->recordSellerlog(lang('refund_processing') . $refund['refund_sn']);
  169. // 发送买家消息
  170. $param = array();
  171. $param['code'] = 'refund_return_notice';
  172. $param['member_id'] = $refund['buyer_id'];
  173. //阿里短信参数
  174. $param['ali_param'] = array(
  175. 'refund_sn' => $refund['refund_sn']
  176. );
  177. $param['ten_param'] = array(
  178. $refund['refund_sn']
  179. );
  180. $param['param'] = array_merge($param['ali_param'], array(
  181. 'refund_url' => HOME_SITE_URL .'/Memberrefund/view/?refund_id='.$refund['refund_id'],
  182. ));
  183. //微信模板消息
  184. $param['weixin_param'] = array(
  185. 'url' => config('ds_config.h5_site_url') . '/pages/member/' . ($refund['refund_type'] == 1 ? 'refund/RefundView' : 'return/ReturnView') . '?refund_id=' . $refund['refund_id'],
  186. 'data' => array(
  187. "keyword1" => array(
  188. "value" => $refund['order_sn'],
  189. "color" => "#333"
  190. ),
  191. "keyword2" => array(
  192. "value" => $refund['refund_amount'],
  193. "color" => "#333"
  194. )
  195. ),
  196. );
  197. model('cron')->addCron(array('cron_exetime'=>TIMESTAMP,'cron_type'=>'sendMemberMsg','cron_value'=>serialize($param)));
  198. ds_json_encode(10000, lang('ds_common_op_succ'));
  199. } else {
  200. ds_json_encode(10001, lang('ds_common_op_fail'));
  201. }
  202. }
  203. /**
  204. * @api {POST} api/Sellerrefund/get_refund_info 退款记录查看页
  205. * @apiVersion 1.0.0
  206. * @apiGroup Sellerrefund
  207. *
  208. * @apiHeader {String} X-DS-KEY 卖家授权token
  209. *
  210. * @apiParam {Int} refund_id 退款ID
  211. *
  212. * @apiSuccess {String} code 返回码,10000为成功
  213. * @apiSuccess {String} message 返回消息
  214. * @apiSuccess {Object} result 返回数据
  215. * @apiSuccess {String[]} result.pic_list 退货凭证列表
  216. * @apiSuccess {Object} result.refund 退货信息 (返回字段参考refundreturn)
  217. */
  218. public function get_refund_info() {
  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. $refundreturn_model = model('refundreturn');
  254. $trade_model = model('trade');
  255. $condition = array();
  256. $condition[] = array('store_id','=',$this->store_info['store_id']);
  257. $condition[] = array('refund_id','=',intval(input('param.return_id')));
  258. $return = $refundreturn_model->getRefundreturnInfo($condition);
  259. $return_delay = $trade_model->getMaxDay('return_delay'); //发货默认5天后才能选择没收到
  260. $delay_time = TIMESTAMP - $return['delay_time'] - 60 * 60 * 24 * $return_delay;
  261. if ($return['seller_state'] != '2' || $return['goods_state'] != '2') {//检查状态,防止页面刷新不及时造成数据错误
  262. ds_json_encode(10001, lang('param_error'));
  263. }
  264. $refund_array = array();
  265. if (input('post.return_type') == '3' && $delay_time > 0) {
  266. $refund_array['goods_state'] = '3';
  267. } else {
  268. $refund_array['receive_time'] = TIMESTAMP;
  269. $refund_array['receive_message'] = lang('confirm_receipt_goods_completed');
  270. $refund_array['refund_state'] = '2'; //状态:1为处理中,2为待管理员处理,3为已完成
  271. $refund_array['goods_state'] = '4';
  272. }
  273. $state = $refundreturn_model->editRefundreturn($condition, $refund_array);
  274. if ($state) {
  275. $this->recordSellerlog(lang('confirm_receipt_goods_returned') . $return['refund_sn']);
  276. // 发送买家消息
  277. $param = array();
  278. $param['code'] = 'refund_return_notice';
  279. $param['member_id'] = $return['buyer_id'];
  280. //阿里短信参数
  281. $param['ali_param'] = array(
  282. 'refund_sn' => $return['refund_sn']
  283. );
  284. $param['ten_param'] = array(
  285. $return['refund_sn']
  286. );
  287. $param['param'] = array_merge($param['ali_param'], array(
  288. 'refund_url' => HOME_SITE_URL .'/Memberreturn/view?return_id='.$return['refund_id'],
  289. ));
  290. //微信模板消息
  291. $param['weixin_param'] = array(
  292. 'url' => config('ds_config.h5_site_url') . '/pages/member/return/ReturnView?refund_id=' . $return['refund_id'],
  293. 'data' => array(
  294. "keyword1" => array(
  295. "value" => $return['order_sn'],
  296. "color" => "#333"
  297. ),
  298. "keyword2" => array(
  299. "value" => $return['refund_amount'],
  300. "color" => "#333"
  301. )
  302. ),
  303. );
  304. model('cron')->addCron(array('cron_exetime'=>TIMESTAMP,'cron_type'=>'sendMemberMsg','cron_value'=>serialize($param)));
  305. ds_json_encode(10000, lang('ds_common_op_succ'));
  306. } else {
  307. ds_json_encode(10001, lang('ds_common_op_fail'));
  308. }
  309. }
  310. function getRefundStateArray() {
  311. $state_array = array(
  312. '1' => lang('refund_state_confirm'),
  313. '2' => lang('refund_state_yes'),
  314. '3' => lang('refund_state_no')
  315. ); //卖家处理状态:1为待审核,2为同意,3为不同意
  316. $admin_array = array(
  317. '1' => lang('in_processing'),
  318. '2' => lang('to_processed'),
  319. '3' => lang('has_been_completed'),
  320. '4' => lang('refund_state_no')
  321. ); //确认状态:1为买家或卖家处理中,2为待平台管理员处理,3为退款退货已完成
  322. return array('state_array' => $state_array, 'admin_array' => $admin_array,);
  323. }
  324. /**
  325. * @api {POST} api/Sellerrefund/search_deliver 物流跟踪
  326. * @apiVersion 1.0.0
  327. * @apiGroup Sellerrefund
  328. *
  329. * @apiHeader {String} X-DS-KEY 卖家授权token
  330. *
  331. * @apiParam {String} refund_id 退款id
  332. *
  333. * @apiSuccess {String} code 返回码,10000为成功
  334. * @apiSuccess {String} message 返回消息
  335. * @apiSuccess {Object} result 返回数据
  336. * @apiSuccess {String} result.express_name 物流公司名称
  337. * @apiSuccess {String} result.shipping_code 物流单号
  338. * @apiSuccess {Object[]} result.deliver_info 物流数据
  339. * @apiSuccess {String} result.deliver_info.context 内容
  340. * @apiSuccess {String} result.deliver_info.time 时间
  341. */
  342. public function search_deliver() {
  343. $refund_id = intval(input('post.refund_id'));
  344. if ($refund_id <= 0) {
  345. ds_json_encode(10001, lang('param_error'));
  346. }
  347. $refundreturn_model = model('refundreturn');
  348. $condition = array();
  349. $condition[] = array('store_id','=',$this->store_info['store_id']);
  350. $condition[] = array('refund_id','=',$refund_id);
  351. $return = $refundreturn_model->getRefundreturnInfo($condition);
  352. if (empty($return)) {
  353. ds_json_encode(10001, lang('refund_not_exist'));
  354. }
  355. if (!$return['express_id'] || !$return['invoice_no']) {
  356. ds_json_encode(10001, lang('deliver_not_exist'));
  357. }
  358. $express = rkcache('express', true);
  359. if(isset($express[$return['express_id']])){
  360. $express_code = $express[$return['express_id']]['express_code'];
  361. $express_name = $express[$return['express_id']]['express_name'];
  362. $deliver_info = $this->_get_express($express_code, $return['invoice_no']);
  363. }else{
  364. $express_code = '';
  365. $express_name = '';
  366. $deliver_info = array();
  367. }
  368. ds_json_encode(10000, '', array('express_name' => $express_name, 'shipping_code' => $return['invoice_no'], 'deliver_info' => $deliver_info));
  369. }
  370. /**
  371. * 从第三方取快递信息
  372. *
  373. */
  374. public function _get_express($express_code, $shipping_code) {
  375. $result = model('express')->queryExpress($express_code, $shipping_code);
  376. if ($result['Success'] != true) {
  377. ds_json_encode(10001, lang('deliver_search_fail'));
  378. }
  379. $content['Traces'] = array_reverse($result['Traces']);
  380. $output = array();
  381. if (is_array($content['Traces'])) {
  382. foreach ($content['Traces'] as $k => $v) {
  383. if ($v['AcceptTime'] == '')
  384. continue;
  385. //$output[] = $v['time'] . '&nbsp;&nbsp;' . $v['context'];
  386. $output[$k]['AcceptTime'] = $v['AcceptTime'];
  387. $output[$k]['AcceptStation'] = $v['AcceptStation'];
  388. }
  389. }
  390. if (empty($output))
  391. ds_json_encode(10001, lang('deliver_not_exist'));
  392. return $output;
  393. }
  394. }