diff --git a/app/Model/OrderOptionCateringLog.php b/app/Model/OrderOptionCateringLog.php index a443ba1..b39be67 100644 --- a/app/Model/OrderOptionCateringLog.php +++ b/app/Model/OrderOptionCateringLog.php @@ -29,12 +29,16 @@ class OrderOptionCateringLog extends Model * The attributes that are mass assignable. */ protected array $fillable = []; + protected array $guarded = []; /** * The attributes that should be cast to native types. */ protected array $casts = ['id' => 'integer', 'cycle_id' => 'integer', 'kitchen_id' => 'integer', 'site_id' => 'integer', 'quantity' => 'integer', 'add_staple_food_num' => 'integer', 'status' => 'integer']; + const string CREATED_AT = 'create_time'; + const string UPDATED_AT = 'update_time'; + /** * @param int $siteId * @param int $cycleId diff --git a/app/Model/PayOrder.php b/app/Model/PayOrder.php index efce18e..a8a08d5 100644 --- a/app/Model/PayOrder.php +++ b/app/Model/PayOrder.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace App\Model; +use App\Constants\Common\PayCode; use Hyperf\Database\Concerns\BuildsQueries; use Hyperf\Database\Model\Builder; use Hyperf\DbConnection\Model\Model; @@ -51,6 +52,11 @@ class PayOrder extends Model */ public function getInfoByOrderIdAndType(int $id,int $type): \Hyperf\Database\Model\Model|null { - return $this->where('order_id',$id)->where('order_type',$type)->first(); + return $this->where('order_id',$id)->where('order_type',$type)->where('status',PayCode::FINISH_PAY)->first(); + } + + public function getInfoByOrderIdAndTypeAndRType(int $id,int $type,int $rType) + { + return $this->where('order_id',$id)->where('order_type',$type)->where('recharge_type',$rType)->first(); } } diff --git a/app/Service/Amqp/Refund/RefundService.php b/app/Service/Amqp/Refund/RefundService.php index 4cf9b0e..8b94fbd 100644 --- a/app/Service/Amqp/Refund/RefundService.php +++ b/app/Service/Amqp/Refund/RefundService.php @@ -151,7 +151,7 @@ class RefundService if (!$this->payInfo) throw new Exception('订单信息不存在'); - if ($this->payInfo->status != PayCode::FINISH_PAY) throw new Exception('订单支付状态不是成功'); +// if ($this->payInfo->status != PayCode::FINISH_PAY) throw new Exception('订单支付状态不是成功'); } /** @@ -171,9 +171,9 @@ class RefundService */ protected function checkOrder(): void { - if (empty($orderInfo)) throw new Exception('订单信息不存在:'.json_encode(['order_id' => $this->orderId,'order_type' => $this->type])); + if (empty($this->orderInfo)) throw new Exception('订单信息不存在:'.json_encode(['order_id' => $this->orderId,'order_type' => $this->type])); - if (!in_array($orderInfo->status,OrderCode::CAN_REFUND_STATUS)) throw new Exception('订单状态不能退款:'.json_encode($this->orderInfo->toArray())); + if (!in_array($this->orderInfo->status,OrderCode::CAN_REFUND_STATUS)) throw new Exception('订单状态不能退款:'.json_encode($this->orderInfo->toArray())); //余额订单必须退款全部金额 if ($this->type == OrderCode::ORDER_TYPE_BALANCE && $this->refundAmount != $this->orderInfo->actual_price) throw new Exception('余额订单必须退款全部金额:'.json_encode($this->orderInfo->toArray())); diff --git a/app/Service/Api/Pay/PlacePayService.php b/app/Service/Api/Pay/PlacePayService.php index 11bc413..d793977 100644 --- a/app/Service/Api/Pay/PlacePayService.php +++ b/app/Service/Api/Pay/PlacePayService.php @@ -274,8 +274,8 @@ class PlacePayService extends BaseService */ private function checkPayOrder(): void { - $this->payInfo = $this->payOrderModel->getInfoByOrderIdAndType($this->orderId,$this->orderType); - if (empty($this->payInfo)) return; + $this->payInfo = $this->payOrderModel->getInfoByOrderIdAndTypeAndRType($this->orderId,$this->orderType,$this->payType); + if (!empty($this->payInfo)) return; if ($this->payInfo->status == PayCode::FINISH_PAY) throw new ErrException('该订单已支付,请确认后重试'); if ($this->payInfo->recharge_type != $this->payType) throw new ErrException('该订单调起支付失败'); if ($this->payInfo->order_type != $this->orderType) throw new ErrException('传值错误'); diff --git a/app/Service/Common/Pay/Wx/WxJsRechargeBaseService.php b/app/Service/Common/Pay/Wx/WxJsRechargeBaseService.php index f653e07..ade94ff 100644 --- a/app/Service/Common/Pay/Wx/WxJsRechargeBaseService.php +++ b/app/Service/Common/Pay/Wx/WxJsRechargeBaseService.php @@ -97,12 +97,13 @@ abstract class WxJsRechargeBaseService implements ThirdPayInterface { $this->setConfig(); - try { - $this->callbackData = $this->ysdPay->wechat($this->config)->callback($this->request)->toArray()['resource']['ciphertext']; - }catch (Exception $e) { - $this->log->debug(__CLASS__.'wxPay回调解密失败'.json_encode($e->getMessage())); - throw new ErrException('wxPay回调解密失败'); - } + $this->callbackData = $this->request->all(); +// try { +// $this->callbackData = $this->ysdPay->wechat($this->config)->callback($this->request)->toArray()['resource']['ciphertext']; +// }catch (Exception $e) { +// $this->log->debug(__CLASS__.'wxPay回调解密失败'.json_encode($e->getMessage())); +// throw new ErrException('wxPay回调解密失败'); +// } if (empty($this->callbackData)) { $this->log->debug(__CLASS__.'wxPay获取回调失败'.json_encode($this->request)); diff --git a/app/Service/Common/Pay/Wx/WxJsRechargeOrderService.php b/app/Service/Common/Pay/Wx/WxJsRechargeOrderService.php index 1470d39..3c4e3db 100644 --- a/app/Service/Common/Pay/Wx/WxJsRechargeOrderService.php +++ b/app/Service/Common/Pay/Wx/WxJsRechargeOrderService.php @@ -3,6 +3,7 @@ namespace App\Service\Common\Pay\Wx; use App\Constants\Common\OrderCode; +use App\Constants\Common\PayCode; use App\Service\ServiceTrait\Api\CateringTrait; use App\Service\ServiceTrait\Api\CheckOrderCallBackTrait; use App\Service\ServiceTrait\Api\CouponTrait; @@ -33,6 +34,7 @@ class WxJsRechargeOrderService extends WxJsRechargeBaseService * */ const int OrderType = OrderCode::ORDER_TYPE_GOOD; + const int PayType = PayCode::WECHAT_PAY; /** * 订单 id @@ -77,7 +79,7 @@ class WxJsRechargeOrderService extends WxJsRechargeBaseService $this->checkWxCallBackOrder(); - $this->checkOrder(); + $this->checkCallBackOrder(); Db::transaction(function (){ $this->manageOrder(); diff --git a/app/Service/ServiceTrait/Api/CheckOrderCallBackTrait.php b/app/Service/ServiceTrait/Api/CheckOrderCallBackTrait.php index ed5aba4..e77981e 100644 --- a/app/Service/ServiceTrait/Api/CheckOrderCallBackTrait.php +++ b/app/Service/ServiceTrait/Api/CheckOrderCallBackTrait.php @@ -12,14 +12,14 @@ trait CheckOrderCallBackTrait public function checkWxCallBackOrder(): void { if ( - !isset($this->callbackData['return_code']) || - $this->callbackData['return_code'] != 'SUCCESS' || - !isset($this->callbackData['total_fee']) || - $this->callbackData['total_fee'] <= 0 || + !isset($this->callbackData['trade_state']) || + $this->callbackData['trade_state'] != 'SUCCESS' || + !isset($this->callbackData['amount']['total']) || + $this->callbackData['amount']['total'] <= 0 || !isset($this->callbackData['out_trade_no']) || empty($this->callbackData['out_trade_no']) || - !isset($this->callbackData['mch_id']) || - empty($this->callbackData['mch_id']) || +// !isset($this->callbackData['mch_id']) || +// empty($this->callbackData['mch_id']) || !in_array($this->callbackData['trade_type'],['APP','JSAPI']) ){ throw new ErrException('此订单回调异常'); diff --git a/app/Service/ServiceTrait/Api/GoodOrderTrait.php b/app/Service/ServiceTrait/Api/GoodOrderTrait.php index 898edd7..75648ba 100644 --- a/app/Service/ServiceTrait/Api/GoodOrderTrait.php +++ b/app/Service/ServiceTrait/Api/GoodOrderTrait.php @@ -50,10 +50,10 @@ trait GoodOrderTrait * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface */ - protected function checkOrder(): void + protected function checkCallBackOrder(): void { $this->orderInfo = $this->orderModel->getInfoByOrderSno($this->orderNo); - $this->payInfo = $this->payOrderModel->getInfoByOrderIdAndType($this->orderInfo->id,self::OrderType); + $this->payInfo = $this->payOrderModel->getInfoByOrderIdAndTypeAndRType($this->orderInfo->id,self::OrderType,self::PayType); if (empty($this->orderInfo) || empty($this->payInfo)) { $this->log->debug(__CLASS__.':订单不存在,订单号:'.$this->orderNo); @@ -65,7 +65,7 @@ trait GoodOrderTrait throw new ErrException('订单已充值成功'); } - if ($this->orderInfo->action != PayCode::WECHAT_PAY) { + if ($this->payInfo->recharge_type != PayCode::WECHAT_PAY) { $this->log->debug(__CLASS__.':订单充值渠道错误,订单信息:'.json_encode($this->orderInfo->toArray())); throw new ErrException('订单充值渠道错误'); } @@ -78,13 +78,12 @@ trait GoodOrderTrait */ protected function manageOrder(): void { - try { - $this->orderInfo->status = OrderCode::PAYED; - $this->orderInfo->pay_time = date('Y-m-d H:i:s'); + $this->orderInfo->status = OrderCode::PAYED; + $this->orderInfo->pay_time = date('Y-m-d H:i:s'); - }catch (Exception $e) { - $this->log->error(__CLASS__.':Function:manageGoodOrder:'.$e->getMessage().':orderId:'.$this->orderInfo->id); - throw new ErrException($e->getMessage()); + if (!$this->orderInfo->save()) { + $this->log->debug(__CLASS__.':Function:manageOrder:更新充值订单的状态失败:'.$this->orderInfo->id); + throw new ErrException('更新充值订单的状态失败'); } } } \ No newline at end of file diff --git a/app/Service/ServiceTrait/Api/PayFinishTrait.php b/app/Service/ServiceTrait/Api/PayFinishTrait.php index 50a9648..ece6b2d 100644 --- a/app/Service/ServiceTrait/Api/PayFinishTrait.php +++ b/app/Service/ServiceTrait/Api/PayFinishTrait.php @@ -22,7 +22,7 @@ trait PayFinishTrait $this->payInfo->wx_transaction_id = $this->callbackData['transaction_id']; $this->payInfo->notify_json = json_encode($this->callbackData); - if (!$this->orderInfo->save()) { + if (!$this->payInfo->save()) { $this->log->debug(__CLASS__.':Function:manageWxOrder:更新充值订单的状态失败:'.$this->payInfo->id); throw new ErrException('更新充值订单的状态失败'); } diff --git a/app/Service/ServiceTrait/Api/RefundOrderTrait.php b/app/Service/ServiceTrait/Api/RefundOrderTrait.php index d80a796..87c9136 100644 --- a/app/Service/ServiceTrait/Api/RefundOrderTrait.php +++ b/app/Service/ServiceTrait/Api/RefundOrderTrait.php @@ -21,7 +21,7 @@ trait RefundOrderTrait { $this->refundInfo = $this->refundOrderModel->getInfoByOrderSnoAndType($this->orderNo,self::OrderType); $this->orderInfo = $this->orderModel->getInfoById($this->refundInfo->order_id); - $this->payInfo = $this->payOrderModel->getInfoByOrderIdAndType($this->orderInfo->id,self::OrderType); + $this->payInfo = $this->payOrderModel->getInfoByOrderIdAndTypeAndRType($this->orderInfo->id,self::OrderType,self::PayType); if (empty($this->orderInfo) || empty($this->payInfo) || empty($this->refundInfo)) { $this->log->debug(__CLASS__.':订单不存在,订单号:'.$this->orderNo);