RefundLogRepository.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Mead
  5. * Date: 2019/8/6
  6. * Time: 9:16 PM
  7. */
  8. namespace App\Repositories;
  9. use App\Models\RefundLog;
  10. class RefundLogRepository extends BaseRepository
  11. {
  12. protected $model;
  13. public function __construct(RefundLog $model)
  14. {
  15. $this->model = $model;
  16. }
  17. public function byUserIdCheckUserIsRefundOk($user_id)
  18. {
  19. $return = [
  20. 'status' => true,
  21. 'msg' => '退款成功'
  22. ];
  23. $refund = $this->model->where('user_id', $user_id)->where('pay_status', RefundLog::PAY_STATUS_NO)->where('result', '<>', '超期订单不允许退款')->orderBy('id', 'desc')->first();
  24. if ($refund) {
  25. //检查是否退款成功
  26. $payment = app('wechat.payment');
  27. $no = $refund->deposit->no;
  28. $re = $payment->refund->queryByOutTradeNumber($no);
  29. if ($re['return_code'] === 'SUCCESS' && $re['result_code'] === 'SUCCESS') {
  30. switch ($re['refund_status_0']) {
  31. case 'SUCCESS':
  32. //退款成功
  33. $return = [
  34. 'status' => true,
  35. 'msg' => '退款成功'
  36. ];
  37. $refund->pay_time = $re['refund_success_time_0'];
  38. $refund->pay_status = RefundLog::PAY_STATUS_OK;
  39. $refund->save();
  40. //退款成功回调
  41. $refund->refund_order_callback();
  42. break;
  43. case 'REFUNDCLOSE':
  44. //退款关闭
  45. $return = [
  46. 'status' => false,
  47. 'msg' => '退款关闭'
  48. ];
  49. break;
  50. case 'PROCESSING':
  51. //退款处理中
  52. $return = [
  53. 'status' => false,
  54. 'msg' => '退款处理中,请稍后再试。'
  55. ];
  56. break;
  57. case 'CHANGE':
  58. //退款异常
  59. $return = [
  60. 'status' => false,
  61. 'msg' => '退款异常'
  62. ];
  63. $refund->pay_status = RefundLog::PAY_STATUS_ERROR;
  64. $refund->result = $re['err_code_des'];
  65. break;
  66. }
  67. } else {
  68. $return = [
  69. 'status' => false,
  70. 'code' => $re['err_code'],
  71. 'msg' => $re['err_code_des']
  72. ];
  73. }
  74. }
  75. return $return;
  76. }
  77. public function byUserIdUserRefundNoModel($user_id)
  78. {
  79. $refund = $this->model->where('user_id', $user_id)->where('pay_status', RefundLog::PAY_STATUS_NO)->orderBy('id', 'desc')->first();
  80. return $refund;
  81. }
  82. }