OrderPayException.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Name: 芸众商城系统
  5. * Author: 广州市芸众信息科技有限公司
  6. * Profile: 广州市芸众信息科技有限公司位于国际商贸中心的广州,专注于移动电子商务生态系统打造,拥有芸众社交电商系统、区块链数字资产管理系统、供应链管理系统、电子合同等产品/服务。官网 :www.yunzmall.com www.yunzshop.com
  7. * Date: 2023/2/20
  8. * Time: 15:53
  9. */
  10. namespace app\payment;
  11. use app\common\exceptions\AppException;
  12. use app\common\models\Order;
  13. use app\common\models\OrderGoods;
  14. use app\common\models\OrderPay;
  15. use app\common\models\PayCallbackException;
  16. class OrderPayException
  17. {
  18. protected $resultData;
  19. public function __construct(array $resultData)
  20. {
  21. $this->resultData = $resultData;
  22. }
  23. /**
  24. * @param OrderPay $orderPay
  25. * @return bool true 出现异常 false 无异常
  26. */
  27. public function handle(OrderPay $orderPay)
  28. {
  29. foreach ($orderPay->orders as $order) {
  30. //if ($order->status > Order::WAIT_PAY) {
  31. //throw new AppException('(ID:' . $order->id . ')订单已付款,请勿重复付款');
  32. //return true;
  33. //}
  34. if ($order->status == Order::CLOSE) {
  35. //throw new AppException('(ID:' . $order->id . ')订单已关闭,无法付款');
  36. $orderPay->updatePayStatus($this->resultData['pay_type_id']);
  37. $this->saveErrorException($orderPay->pay_sn, PayCallbackException::ORDER_CLOSE, '(ID:' . $order->id . ')订单已关闭,无法付款');
  38. return true;
  39. }
  40. }
  41. return false;
  42. }
  43. public function saveErrorException($pay_sn,$code,$msg = '')
  44. {
  45. $payError = PayCallbackException::uniacid()->where('pay_sn', $pay_sn)->first();
  46. if (is_null($payError)) {
  47. $payError = new PayCallbackException(['uniacid' => \YunShop::app()->uniacid,'frequency' => 0]);
  48. }
  49. $logData = [
  50. 'frequency' => $payError->frequency + 1,
  51. 'pay_sn' => $pay_sn,
  52. 'pay_type_id' => $this->resultData['pay_type_id'],
  53. 'error_code' => $code,
  54. 'error_msg' => $msg,
  55. 'result' => $this->resultData,
  56. 'response' => request()->input(),
  57. 'record_at' => time(),
  58. ];
  59. $payError->fill($logData);
  60. $bool = $payError->save();
  61. if ($bool) {
  62. return $payError;
  63. }
  64. return $bool;
  65. }
  66. }