|
@@ -16,6 +16,7 @@ use App\Models\MemberModel;
|
|
|
use App\Models\OrderModel;
|
|
use App\Models\OrderModel;
|
|
|
use App\Models\PaymentModel;
|
|
use App\Models\PaymentModel;
|
|
|
use App\Models\PayOrdersModel;
|
|
use App\Models\PayOrdersModel;
|
|
|
|
|
+use App\Services\Api\SettleService;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
use Yansongda\Pay\Pay;
|
|
use Yansongda\Pay\Pay;
|
|
|
use Yansongda\Pay\Provider\Wechat;
|
|
use Yansongda\Pay\Provider\Wechat;
|
|
@@ -638,10 +639,13 @@ class PaymentService extends BaseService
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- $orderInfo = PayOrdersModel::where(['order_no'=>$out_trade_num,'mark'=>1])->first();
|
|
|
|
|
|
|
+ $orderInfo = PayOrdersModel::with(['user'])->where(['order_no'=>$out_trade_num,'mark'=>1])->first();
|
|
|
$orderId = isset($orderInfo['id'])? $orderInfo['id'] : 0;
|
|
$orderId = isset($orderInfo['id'])? $orderInfo['id'] : 0;
|
|
|
|
|
+ $orderUserId = isset($orderInfo['user_id'])? $orderInfo['user_id'] : 0;
|
|
|
$status = isset($orderInfo['status'])? $orderInfo['status'] : 0;
|
|
$status = isset($orderInfo['status'])? $orderInfo['status'] : 0;
|
|
|
$total = isset($orderInfo['total'])? $orderInfo['total'] : 0;
|
|
$total = isset($orderInfo['total'])? $orderInfo['total'] : 0;
|
|
|
|
|
+ $userInfo = isset($orderInfo['user'])? $orderInfo['user'] : [];
|
|
|
|
|
+ $parentId = isset($userInfo['parent_id'])?$userInfo['parent_id'] : 0;
|
|
|
if(empty($orderInfo) || $orderId<=0 || $total<=0){
|
|
if(empty($orderInfo) || $orderId<=0 || $total<=0){
|
|
|
$this->error = '充值订单不存在';
|
|
$this->error = '充值订单不存在';
|
|
|
$this->saveLog("caches:payments:payNotify_{$productId}:notify_{$out_trade_num}_error", ['error'=>$this->error,'order' => $orderInfo, 'notify' => $data]);
|
|
$this->saveLog("caches:payments:payNotify_{$productId}:notify_{$out_trade_num}_error", ['error'=>$this->error,'order' => $orderInfo, 'notify' => $data]);
|
|
@@ -674,9 +678,11 @@ class PaymentService extends BaseService
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 更新订单状态
|
|
// 更新订单状态
|
|
|
|
|
+ DB::beginTransaction();
|
|
|
$this->saveLog("caches:payments:payNotify_{$productId}:notify_{$out_trade_num}", ['error'=>$this->error,'order' => $orderInfo, 'notify' => $data]);
|
|
$this->saveLog("caches:payments:payNotify_{$productId}:notify_{$out_trade_num}", ['error'=>$this->error,'order' => $orderInfo, 'notify' => $data]);
|
|
|
if(!PayOrdersModel::where(['id'=>$orderId])->update(['status'=>$status,'charge_kami'=>$charge_kami,'refund_status'=>$status!=4?2:0,'charge_amount'=>$amount,'update_time'=>time()])){
|
|
if(!PayOrdersModel::where(['id'=>$orderId])->update(['status'=>$status,'charge_kami'=>$charge_kami,'refund_status'=>$status!=4?2:0,'charge_amount'=>$amount,'update_time'=>time()])){
|
|
|
$this->error = '更新订单状态错误~';
|
|
$this->error = '更新订单状态错误~';
|
|
|
|
|
+ DB::rollBack();
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -689,16 +695,24 @@ class PaymentService extends BaseService
|
|
|
if(!PayOrdersModel::where(['id'=>$orderId])->update(['refund_status'=> $refundStatus?1:3,'refund_money'=>$refundStatus?$refundAmount:0,'update_time'=>time()])){
|
|
if(!PayOrdersModel::where(['id'=>$orderId])->update(['refund_status'=> $refundStatus?1:3,'refund_money'=>$refundStatus?$refundAmount:0,'update_time'=>time()])){
|
|
|
$this->saveLog("caches:payments:payNotify_{$productId}:notify_{$out_trade_num}_error", ['error'=>$this->error,'order' => $orderInfo, 'notify' => $data]);
|
|
$this->saveLog("caches:payments:payNotify_{$productId}:notify_{$out_trade_num}_error", ['error'=>$this->error,'order' => $orderInfo, 'notify' => $data]);
|
|
|
$this->error = '订单退款状态更新错误~';
|
|
$this->error = '订单退款状态更新错误~';
|
|
|
|
|
+ DB::rollBack();
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if($status == 4)
|
|
|
|
|
|
|
+ // 订单完成,代理收益结算
|
|
|
|
|
+ if($status == 4 && $amount>0)
|
|
|
{
|
|
{
|
|
|
-
|
|
|
|
|
|
|
+ // 代理佣金结算
|
|
|
|
|
+ if (SettleService::make()->agentBonus($orderUserId, $amount, $orderInfo, $parentId) < 0) {
|
|
|
|
|
+ DB::rollBack();
|
|
|
|
|
+ $this->error = SettleService::make()->getError();
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ DB::commit();
|
|
|
$this->error = '充值订单处理成功~';
|
|
$this->error = '充值订单处理成功~';
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|