|
|
@@ -11,9 +11,9 @@
|
|
|
|
|
|
namespace App\Services;
|
|
|
|
|
|
+use App\Models\AccountLogModel;
|
|
|
use App\Models\OrderModel;
|
|
|
use App\Models\PaymentModel;
|
|
|
-use App\Models\PayOrdersModel;
|
|
|
use App\Services\Api\SettleService;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
use Yansongda\Pay\Pay;
|
|
|
@@ -496,33 +496,6 @@ class PaymentService extends BaseService
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
- // 生活充值
|
|
|
- else if ($scene == 'pay') {
|
|
|
- $orderInfo = PayOrdersModel::where(['order_no' => $orderNo, 'mark' => 1])
|
|
|
- ->select(['id as order_id', 'user_id','meal_id','product_id', 'order_no','transaction_id','account', 'total as pay_money','area','ytype','city','id_card_no','pay_total', 'pay_at as pay_time', 'remark', 'status'])
|
|
|
- ->first();
|
|
|
- $orderStatus = isset($orderInfo['status']) ? $orderInfo['status'] : 0;
|
|
|
- // 验证订单
|
|
|
- if (empty($orderInfo)) {
|
|
|
- DB::rollBack();
|
|
|
- $this->error = 2629;
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- // 订单状态
|
|
|
- if ($orderStatus != 1) {
|
|
|
- DB::rollBack();
|
|
|
- $this->error = 2630;
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- $updateData = ['pay_at' => $payAt, 'transaction_id' => $transactionId, 'status' => 2, 'update_time' => time()];
|
|
|
- if (!PayOrdersModel::where(['order_no' => $orderNo, 'mark' => 1])->update($updateData)) {
|
|
|
- $this->error = 2633;
|
|
|
- DB::rollBack();
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
// 退款
|
|
|
else if ($scene == 'refund') {
|
|
|
$orderInfo = OrderModel::where(['order_no' => $orderNo, 'mark' => 1])
|
|
|
@@ -564,59 +537,25 @@ class PaymentService extends BaseService
|
|
|
$this->saveLog("caches:payments:notify_{$scene}:catch_{$orderNo}_{$orderUserId}", ['order' => $orderInfo, 'notify' => $data]);
|
|
|
switch ($scene) {
|
|
|
case 'store': //
|
|
|
- break;
|
|
|
- case 'pay': //
|
|
|
- // 调起 接口充值
|
|
|
- $orderId = isset($orderInfo['order_id'])? $orderInfo['order_id'] : 0;
|
|
|
- $productId = isset($orderInfo['product_id'])? $orderInfo['product_id'] : '';
|
|
|
- $orderNo = isset($orderInfo['order_no'])? $orderInfo['order_no'] : '';
|
|
|
- $account = isset($orderInfo['account'])? $orderInfo['account'] : '';
|
|
|
- $total = isset($orderInfo['pay_money'])? $orderInfo['pay_money'] : 0;
|
|
|
- $payTotal = isset($orderInfo['pay_total'])? $orderInfo['pay_total'] : 0;
|
|
|
- $amount = $total;
|
|
|
- $params = [
|
|
|
- 'price'=>$payTotal,
|
|
|
- 'ytype'=>isset($orderInfo['ytype'])?$orderInfo['ytype']:0,
|
|
|
- 'id_card_no'=>isset($orderInfo['id_card_no'])?$orderInfo['id_card_no']:'',
|
|
|
- 'area'=>isset($orderInfo['area'])?$orderInfo['area']:'',
|
|
|
- 'city'=>isset($orderInfo['city'])?$orderInfo['city']:'',
|
|
|
+ $userInfo = isset($orderInfo['user'])?$orderInfo['user']:[];
|
|
|
+ $balance = isset($userInfo['balance'])? $userInfo['balance'] : 0;
|
|
|
+ $data = [
|
|
|
+ 'user_id'=>$orderUserId,
|
|
|
+ 'source_order_no'=>$orderNo,
|
|
|
+ 'type'=> 1,
|
|
|
+ 'money'=> $payTotal,
|
|
|
+ 'after_money'=>$balance,
|
|
|
+ 'date'=>date('Y-m-d'),
|
|
|
+ 'create_time'=>time(),
|
|
|
+ 'remark'=> '订单付款-商品',
|
|
|
+ 'status'=>1,
|
|
|
+ 'mark'=>1
|
|
|
];
|
|
|
-
|
|
|
- $result = DyrPayService::make()->recharge($orderNo, $account, $productId, $amount, $params);
|
|
|
- $errno = isset($result['errno'])?$result['errno'] : -1;
|
|
|
- $errmsg = isset($result['errmsg'])?$result['errmsg'] : '';
|
|
|
- $res = isset($result['data'])?$result['data']:[];
|
|
|
- $order_number = isset($res['order_number'])?$res['order_number']:'';
|
|
|
- $total_price = isset($res['total_price'])?$res['total_price']:'';
|
|
|
- if(empty($result) || $errno != 0 || empty($order_number)){
|
|
|
-
|
|
|
- $this->error = '充值调用失败:'.$errmsg;
|
|
|
-
|
|
|
- // 退款
|
|
|
- $orderInfo['money'] = $payTotal;
|
|
|
- $orderInfo['remark'] = '充值失败退款';
|
|
|
- $refundStatus = PaymentService::make()->refund($orderInfo,'pay');
|
|
|
- $updateData = ['refund_status'=> $refundStatus?1:3,'status'=>5,'result'=>json_encode(['amount'=>$amount,'params'=>$params,'result'=>$result],256),'failed_remark'=> $errmsg,'refund_at'=>date('Y-m-d H:i:s'),'refund_money'=>$refundStatus?$payTotal:0,'update_time'=>time()];
|
|
|
- $this->saveLog("caches:payments:notify_{$scene}:pay_failed_{$orderNo}_{$orderUserId}", ['error'=>$this->error,'update'=>$updateData,'order' => $orderInfo,'result'=>$result, 'notify' => $data]);
|
|
|
- if(!PayOrdersModel::where(['id'=>$orderId])->update($updateData)){
|
|
|
- $this->error = '订单退款状态更新错误~';
|
|
|
- }
|
|
|
-
|
|
|
- DB::commit();
|
|
|
- return false;
|
|
|
+ if(!AccountLogModel::insertGetId($data)){
|
|
|
+ Db::rollBack();
|
|
|
+ $this->error = '付款处理失败';
|
|
|
}
|
|
|
-
|
|
|
- $updateData = ['status'=>3,'result'=>json_encode(['amount'=>$amount,'params'=>$params,'result'=>$result],256),'out_trade_no'=>$order_number,'update_time'=>time()+1];
|
|
|
- $this->saveLog("caches:payments:notify_{$scene}:pay_success_{$orderNo}_{$orderUserId}", ['error'=> '充值调用成功','id'=>$orderId,'update'=>$updateData,'order' => $orderInfo,'result'=>$result, 'notify' => $data]);
|
|
|
- if(!PayOrdersModel::where(['id'=>$orderId])->update($updateData)){
|
|
|
- DB::commit();
|
|
|
- $this->error = '更新充值订单失败';
|
|
|
- $this->saveLog("caches:payments:notify_{$scene}:pay_failed_{$orderNo}_{$orderUserId}", ['error'=>$this->error,'update'=>$updateData,'order' => $orderInfo,'result'=>$result, 'notify' => $data]);
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- DB::commit();
|
|
|
- return true;
|
|
|
+ break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|