feat : wechatPay callback
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()));
|
||||
|
||||
@@ -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('传值错误');
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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('此订单回调异常');
|
||||
|
||||
@@ -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('更新充值订单的状态失败');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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('更新充值订单的状态失败');
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user