|
|
@@ -13,6 +13,7 @@ namespace App\Services;
|
|
|
|
|
|
use App\Models\GongdengOrderModel;
|
|
|
use App\Models\MemberModel;
|
|
|
+use App\Models\RechargeModel;
|
|
|
use App\Models\SignsModel;
|
|
|
use App\Models\TradeModel;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
@@ -38,6 +39,7 @@ class NotifyService extends BaseService
|
|
|
public function __construct()
|
|
|
{
|
|
|
$this->model = new GongdengOrderModel();
|
|
|
+ $this->rechargeModel = new RechargeModel();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -141,6 +143,85 @@ class NotifyService extends BaseService
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 供灯订单回调处理
|
|
|
+ * @param $notifyData
|
|
|
+ * @param $outTradeNo
|
|
|
+ * @return false
|
|
|
+ */
|
|
|
+ public function notifyRecharge($notifyData, $outTradeNo){
|
|
|
+ $errorKey = "caches:orders:recharge:{$outTradeNo}";
|
|
|
+ // 验证订单是否存在
|
|
|
+ $orderInfo = $this->rechargeModel::where(['order_sn'=> $outTradeNo])
|
|
|
+ ->select(['id','type','user_id','num','money','status'])
|
|
|
+ ->first();
|
|
|
+
|
|
|
+
|
|
|
+ // 验证参数
|
|
|
+ RedisService::set($errorKey.':order',['order'=> $orderInfo,'notify'=> $notifyData], 3600);
|
|
|
+ $orderStatus = isset($orderInfo['status']) ? intval($orderInfo['status']) : 0;
|
|
|
+ $userId = isset($orderInfo['user_id']) ? intval($orderInfo['user_id']) : 0;
|
|
|
+ if (empty($orderInfo) || $userId<=0) {
|
|
|
+ return NotifyService::rebackMsg('订单数据不存在', 'success');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 订单用户
|
|
|
+ $memberInfo = MemberModel::where(['id'=> $userId])->select(['id','openid','nickname','balance','coupon','status'])->first();
|
|
|
+ if(!$memberInfo){
|
|
|
+ return NotifyService::rebackMsg('订单用户不存在', 'success');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 验证订单状态是否可处理
|
|
|
+ if ($orderStatus != 1) {
|
|
|
+ return NotifyService::rebackMsg('订单已处理', 'success');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 验证订单金额是否正确
|
|
|
+ $payDebug = config('weixin.payDebug');
|
|
|
+ $amount = isset($notifyData['amount'])? $notifyData['amount'] : [];
|
|
|
+ $payMoney = isset($amount['total']) ? moneyFormat($amount['total']) : 0;
|
|
|
+ $orderMoney = isset($orderInfo['money']) ? moneyFormat($orderInfo['money']) : 0.00;
|
|
|
+ $orderAmount = moneyFormat($orderMoney);
|
|
|
+ if (!$payDebug && intval($orderAmount * 100) != intval($payMoney)) {
|
|
|
+ RedisService::set($errorKey.':error_money',['notify'=> $notifyData, 'error'=> '实付金额与订单金额不一致','order'=> $orderInfo
|
|
|
+ ], 3600);
|
|
|
+ return NotifyService::rebackMsg('实付金额与订单金额不一致', 'error');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新订单数据
|
|
|
+ DB::beginTransaction();
|
|
|
+ $tradeNo = isset($notifyData['transaction_id'])? $notifyData['transaction_id'] : '';
|
|
|
+ if(!$this->rechargeModel::where(['order_sn'=> $outTradeNo])->update(['status'=> 1,'trade_no'=> $tradeNo,'pay_at'=> date('Y-m-d H:i:s'),'pay_money'=> moneyFormat($payMoney/100),'remark'=> '已支付'])){
|
|
|
+ RedisService::set($errorKey.':error_update',['notify'=> $notifyData, 'error'=> '更新订单信息失败','order'=> $orderInfo
|
|
|
+ ], 3600);
|
|
|
+ DB::rollBack();
|
|
|
+ return NotifyService::rebackMsg('更新订单数据失败', 'error');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理支付明细
|
|
|
+ $data = [
|
|
|
+ 'user_id'=> $userId,
|
|
|
+ 'type'=> 2,
|
|
|
+ 'coin_type'=> 1,
|
|
|
+ 'pay_type'=> 2,
|
|
|
+ 'money'=> moneyFormat($payMoney/100),
|
|
|
+ 'change_type'=> 1,
|
|
|
+ 'balance'=> $memberInfo->coupon? $memberInfo->coupon : 0,
|
|
|
+ 'create_time'=> time(),
|
|
|
+ 'remark'=> '充值订单支付',
|
|
|
+ 'status'=> 1
|
|
|
+ ];
|
|
|
+ if(!TradeModel::insertGetId($data)){
|
|
|
+ RedisService::set($errorKey.':error_account',['notify'=> $notifyData, 'error'=> '处理交易明细失败','order'=> $orderInfo
|
|
|
+ ], 3600);
|
|
|
+ DB::rollBack();
|
|
|
+ return NotifyService::rebackMsg('处理交易明细失败', 'error');
|
|
|
+ }
|
|
|
+
|
|
|
+ DB::commit();
|
|
|
+
|
|
|
+ return NotifyService::rebackMsg('支付处理成功','success');
|
|
|
+ }
|
|
|
+ /**
|
|
|
* 回去回调报文内容
|
|
|
* @param $message
|
|
|
* @return string
|