|
|
@@ -12,7 +12,10 @@
|
|
|
namespace App\Services;
|
|
|
|
|
|
use App\Models\GongdengOrderModel;
|
|
|
+use App\Models\MemberModel;
|
|
|
use App\Models\SignsModel;
|
|
|
+use App\Models\TradeModel;
|
|
|
+use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
/**
|
|
|
* 支付回调管理-服务类
|
|
|
@@ -54,15 +57,23 @@ class NotifyService extends BaseService
|
|
|
* @return false
|
|
|
*/
|
|
|
public function notifyGongdeng($notifyData, $outTradeNo){
|
|
|
-
|
|
|
+ $errorKey = "caches:orders:gongdeng:{$outTradeNo}";
|
|
|
// 验证订单是否存在
|
|
|
$orderInfo = $this->model::where(['order_sn'=> $outTradeNo])
|
|
|
- ->select(['id','source_id','user_id','num','total','status'])
|
|
|
+ ->select(['id','source_id','buy_type','user_id','num','total','status'])
|
|
|
->first();
|
|
|
|
|
|
// 验证参数
|
|
|
$orderStatus = isset($orderInfo['status']) ? intval($orderInfo['status']) : 0;
|
|
|
- if (empty($orderInfo)) {
|
|
|
+ $userId = isset($orderInfo['user_id']) ? intval($orderInfo['user_id']) : 0;
|
|
|
+ if (empty($orderInfo) || $userId<=0) {
|
|
|
+ NotifyService::rebackOk();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 订单用户
|
|
|
+ $memberInfo = MemberModel::where(['id'=> $userId])->select(['id','openid','nickname','coupon','status'])->first();
|
|
|
+ if(!$memberInfo){
|
|
|
NotifyService::rebackOk();
|
|
|
return false;
|
|
|
}
|
|
|
@@ -80,12 +91,39 @@ class NotifyService extends BaseService
|
|
|
$credit = isset($orderInfo['credit']) ? moneyFormat($orderInfo['credit']) : 0.00;
|
|
|
$orderAmount = moneyFormat($orderMoney + $credit);
|
|
|
if (!$payDebug && intval($orderAmount * 100) != intval($payMoney)) {
|
|
|
+ RedisService::set($errorKey.':error_money',['notify'=> $notifyData, 'error'=> '实付金额与订单金额不一致','order'=> $orderInfo
|
|
|
+ ], 3600);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// 更新订单数据
|
|
|
+ DB::beginTransaction();
|
|
|
+ if(!$this->model::where(['order_sn'=> $outTradeNo])->update(['status'=> 2,'pay_money'=> $payMoney,'remark'=> '已支付'])){
|
|
|
+ RedisService::set($errorKey.':error_update',['notify'=> $notifyData, 'error'=> '更新订单信息失败','order'=> $orderInfo
|
|
|
+ ], 3600);
|
|
|
+ DB::rollBack();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
// 处理支付明细
|
|
|
+ $data = [
|
|
|
+ 'user_id'=> $userId,
|
|
|
+ 'type'=> 1,
|
|
|
+ 'coin_type'=> 2,
|
|
|
+ 'pay_type'=> 2,
|
|
|
+ 'money'=> $payMoney,
|
|
|
+ 'change_type'=> 2,
|
|
|
+ 'balance'=> $memberInfo->balance,
|
|
|
+ 'create_time'=> time(),
|
|
|
+ 'remark'=> '供灯订单支付',
|
|
|
+ 'status'=> 1
|
|
|
+ ];
|
|
|
+ if(!TradeModel::insertGetId($data)){
|
|
|
+ RedisService::set($errorKey.':error_account',['notify'=> $notifyData, 'error'=> '处理交易明细失败','order'=> $orderInfo
|
|
|
+ ], 3600);
|
|
|
+ DB::rollBack();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
// 开灯处理
|
|
|
|