DetailController.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <?php
  2. namespace app\backend\modules\refund\controllers;
  3. use app\common\exceptions\AppException;
  4. use app\common\models\goods\ReturnAddress;
  5. use Illuminate\Support\Facades\Redis;
  6. use app\common\components\BaseController;
  7. use app\common\models\refund\RefundApply;
  8. /**
  9. * 退款申请详情
  10. * Created by PhpStorm.
  11. * Author: 芸众商城 www.yunzshop.com
  12. * Date: 2017/4/13
  13. * Time: 下午3:04
  14. */
  15. class DetailController extends BaseController
  16. {
  17. protected $refundApply;
  18. public function consultRecord()
  19. {
  20. $order_id = intval(request()->input('order_id'));
  21. }
  22. /**
  23. * @return \Illuminate\Http\JsonResponse
  24. * @throws AppException
  25. */
  26. public function express()
  27. {
  28. //refund.detail.express
  29. $refund_value = request()->input('refund_value');
  30. if ($refund_value == 20) {
  31. return $this->returnLogistics();
  32. } elseif ($refund_value == 30) {
  33. return $this->resendLogistics();
  34. }
  35. return $this->errorJson('不存在物流');
  36. }
  37. public function returnLogistics()
  38. {
  39. $this->refundApply = $refundApply = RefundApply::find(request()->input('refund_id'));
  40. if(!$refundApply){
  41. throw new AppException('未找到该售后信息');
  42. }
  43. if(!$refundApply->returnExpress) {
  44. throw new AppException('未找到该售后快递单号');
  45. }
  46. $cacheKey = 'backend_refundExpressId_'.$refundApply->id.'_' . $refundApply->returnExpress->express_sn;
  47. $result = Redis::get($cacheKey);
  48. if ($result) {
  49. $result = json_decode($result, true);
  50. return $this->successJson('用户发货物流信息Cache', $result);
  51. }
  52. switch ($refundApply->returnExpress->way_id) {
  53. case 1:
  54. if(app('plugins')->isEnabled('jd-take-parts')) {
  55. $dispatch = \Yunshop\JdTakeParts\services\RefundService::receiveTraceGet($refundApply);
  56. break;
  57. }
  58. default:
  59. $dispatch = $this->getLogistics($refundApply->returnExpress);
  60. }
  61. $dispatch['goods'] = [];
  62. $dispatch['thumb'] = $refundApply->returnExpress->images;
  63. $result[] = $dispatch;
  64. Redis::setex($cacheKey, 120, json_encode($result));
  65. return $this->successJson('用户发货物流信息',$result);
  66. }
  67. public function resendLogistics()
  68. {
  69. $this->refundApply = $refundApply = RefundApply::find(request()->input('refund_id'));
  70. if(!$refundApply){
  71. throw new AppException('未找到该售后信息');
  72. }
  73. if($refundApply->hasManyResendExpress->isEmpty()) {
  74. throw new AppException('未找到该售后快递');
  75. }
  76. $cacheKey = 'backend_refundExpressId_'.$refundApply->id.'_' . $refundApply->hasManyResendExpress->count();
  77. $result = Redis::get($cacheKey);
  78. if ($result) {
  79. $result = json_decode($result, true);
  80. return $this->successJson('商户发货物流信息Cache', $result);
  81. }
  82. $result = [];
  83. foreach ($refundApply->hasManyResendExpress as $resendExpress) {
  84. $dispatch = $this->getLogistics($resendExpress);
  85. $dispatch['goods'] = $resendExpress->pack_goods?: [];
  86. $dispatch['thumb'] = $resendExpress->pack_goods?$resendExpress->pack_goods[0]['goods_thumb'] : '';
  87. $result[] = $dispatch;
  88. }
  89. Redis::setex($cacheKey, 120, json_encode($result));
  90. return $this->successJson('商户发货物流信息', $result);
  91. }
  92. protected function getLogistics($expressModel)
  93. {
  94. // return $this->testData($expressModel);
  95. //买家寄回物流信息
  96. $phoneLastFour = '';
  97. if ($expressModel->express_code == 'SF') {
  98. $returnAddress = ReturnAddress::find($this->refundApply->refund_address);
  99. if (empty($returnAddress->mobile)) {
  100. throw new AppException('SF查询物流,联系电话不能为空');
  101. }
  102. $phoneLastFour = substr($returnAddress->mobile,-4);
  103. }
  104. $express = (new \app\common\models\order\Express())->getExpress($expressModel->express_code, $expressModel->express_sn,$phoneLastFour);
  105. $dispatch['express_sn'] = $expressModel->express_sn;
  106. $dispatch['company_name'] = $expressModel->express_company_name;
  107. $dispatch['data'] = $express['data'];
  108. $dispatch['thumb'] = '';
  109. $dispatch['tel'] = '95533';
  110. $dispatch['status_name'] = $express['status_name'];
  111. return $dispatch;
  112. }
  113. protected function testData($expressModel)
  114. {
  115. $dispatch['express_sn'] = $expressModel->express_sn;
  116. $dispatch['company_name'] = $expressModel->express_company_name;
  117. $data = [];
  118. for ($i = rand(8,20);$i > 1; $i--) {
  119. $data[] = [
  120. 'context' => '物流信息到达:'.$i,
  121. 'ftime' => '202111231+'.$i,
  122. ];
  123. }
  124. $dispatch['data'] = $data;
  125. $dispatch['thumb'] = '';
  126. $dispatch['tel'] = '95533';
  127. $dispatch['status_name'] = '测试状态:'.rand(0,100);
  128. return $dispatch;
  129. }
  130. }