|
|
@@ -221,6 +221,64 @@ class PayOrdersService extends BaseService
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 已支付充值失败退款失败订单
|
|
|
+ * @return array|mixed
|
|
|
+ */
|
|
|
+ public function getFailedOrderList()
|
|
|
+ {
|
|
|
+ $cacheKey = "caches:orders:failedList";
|
|
|
+ $datas = RedisService::get($cacheKey);
|
|
|
+ if ($datas) {
|
|
|
+ return $datas;
|
|
|
+ }
|
|
|
+
|
|
|
+ $datas = $this->model->where(['refund_status'=>3,'status'=>5,'mark' => 1])
|
|
|
+ ->select(['id', 'order_no', 'transaction_id', 'pay_total as money', 'status'])
|
|
|
+ ->orderBy('id', 'desc')
|
|
|
+ ->limit(500)
|
|
|
+ ->get()
|
|
|
+ ->keyBy('order_no');
|
|
|
+ $datas = $datas ? $datas->toArray() : [];
|
|
|
+ if ($datas) {
|
|
|
+ $datas = array_chunk($datas, 100);
|
|
|
+ RedisService::set($cacheKey, $datas, rand(20, 30));
|
|
|
+ }
|
|
|
+
|
|
|
+ return $datas;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 充值订单退款(补充处理)
|
|
|
+ * @param $orders
|
|
|
+ * @return array
|
|
|
+ * @throws \Yansongda\Pay\Exception\ContainerException
|
|
|
+ * @throws \Yansongda\Pay\Exception\InvalidParamsException
|
|
|
+ * @throws \Yansongda\Pay\Exception\ServiceNotFoundException
|
|
|
+ */
|
|
|
+ public function failedOrderRefund($orders)
|
|
|
+ {
|
|
|
+ $success = [];
|
|
|
+ if ($orders) {
|
|
|
+ foreach ($orders as $order) {
|
|
|
+ $total = isset($order['money']) ? $order['money'] : 0;
|
|
|
+ $refundStatus = PaymentService::make()->refund($order, 'pay');
|
|
|
+ $updateData = ['refund_status' => $refundStatus ? 1 : 3, 'status' => 5, 'failed_remark' => '充值失败原路退款','refund_remark'=>PaymentService::make()->getError(), 'refund_money' => $refundStatus ? $total : 0,'refund_at'=>date('Y-m-d H:i:s'), 'update_time' => time()];
|
|
|
+ if (!PayOrdersModel::where(['id' => $order['id']])->update($updateData)) {
|
|
|
+ $errors[$order['order_no']] = '充值失败退款处理失败';
|
|
|
+ } else {
|
|
|
+ $success[$order['order_no']] = "退款{$total}成功";
|
|
|
+ $errors[$order['order_no']] = $refundStatus ? '充值失败原路退款' : '充值失败退款失败';
|
|
|
+ }
|
|
|
+
|
|
|
+ sleep(2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->error = '充值订单退款处理成功';
|
|
|
+ return ['success' => $success, 'errors' => $errors];
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 验证订单状态
|
|
|
* @param $orders
|
|
|
* @return array
|