123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Mead
- * Date: 2019/8/6
- * Time: 9:16 PM
- */
- namespace App\Repositories;
- use App\Models\RefundLog;
- class RefundLogRepository extends BaseRepository
- {
- protected $model;
- public function __construct(RefundLog $model)
- {
- $this->model = $model;
- }
- public function byUserIdCheckUserIsRefundOk($user_id)
- {
- $return = [
- 'status' => true,
- 'msg' => '退款成功'
- ];
- $refund = $this->model->where('user_id', $user_id)->where('pay_status', RefundLog::PAY_STATUS_NO)->where('result', '<>', '超期订单不允许退款')->orderBy('id', 'desc')->first();
- if ($refund) {
- //检查是否退款成功
- $payment = app('wechat.payment');
- $no = $refund->deposit->no;
- $re = $payment->refund->queryByOutTradeNumber($no);
- if ($re['return_code'] === 'SUCCESS' && $re['result_code'] === 'SUCCESS') {
- switch ($re['refund_status_0']) {
- case 'SUCCESS':
- //退款成功
- $return = [
- 'status' => true,
- 'msg' => '退款成功'
- ];
- $refund->pay_time = $re['refund_success_time_0'];
- $refund->pay_status = RefundLog::PAY_STATUS_OK;
- $refund->save();
- //退款成功回调
- $refund->refund_order_callback();
- break;
- case 'REFUNDCLOSE':
- //退款关闭
- $return = [
- 'status' => false,
- 'msg' => '退款关闭'
- ];
- break;
- case 'PROCESSING':
- //退款处理中
- $return = [
- 'status' => false,
- 'msg' => '退款处理中,请稍后再试。'
- ];
- break;
- case 'CHANGE':
- //退款异常
- $return = [
- 'status' => false,
- 'msg' => '退款异常'
- ];
- $refund->pay_status = RefundLog::PAY_STATUS_ERROR;
- $refund->result = $re['err_code_des'];
- break;
- }
- } else {
- $return = [
- 'status' => false,
- 'code' => $re['err_code'],
- 'msg' => $re['err_code_des']
- ];
- }
- }
- return $return;
- }
- public function byUserIdUserRefundNoModel($user_id)
- {
- $refund = $this->model->where('user_id', $user_id)->where('pay_status', RefundLog::PAY_STATUS_NO)->orderBy('id', 'desc')->first();
- return $refund;
- }
- }
|