PaymentTrade.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2024 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\api\model;
  13. use app\common\model\PaymentTrade as PaymentTradeModel;
  14. use app\common\enum\payment\trade\TradeStatus as TradeStatusEnum;
  15. /**
  16. * 模型类:第三方支付交易记录
  17. * Class PaymentTrade
  18. * @package app\api\model
  19. */
  20. class PaymentTrade extends PaymentTradeModel
  21. {
  22. /**
  23. * 隐藏字段
  24. * @var array
  25. */
  26. protected $hidden = [
  27. 'store_id',
  28. 'create_time',
  29. 'update_time'
  30. ];
  31. /**
  32. * 新增第三方交易信息
  33. * @param mixed $orderInfo 订单信息
  34. * @param string $method 支付方式
  35. * @param string $client 指定的客户端
  36. * @param int $orderType 订单类型
  37. * @param array $payment 第三方支付数据
  38. * @return bool
  39. * @throws \cores\exception\BaseException
  40. * @throws \think\db\exception\DataNotFoundException
  41. * @throws \think\db\exception\DbException
  42. * @throws \think\db\exception\ModelNotFoundException
  43. */
  44. public static function record($orderInfo, string $method, string $client, int $orderType, array $payment): bool
  45. {
  46. // 实例化模型
  47. $model = new static;
  48. // 查询是否存在交易记录
  49. $record = $model->detailByOrderId($orderInfo['order_id'], $method, $client, $orderType);
  50. // 新增或者更新记录
  51. return ($record ?: $model)->save([
  52. 'client' => $client,
  53. 'pay_method' => $method,
  54. 'order_type' => $orderType,
  55. 'order_id' => $orderInfo['order_id'],
  56. 'order_no' => $orderInfo['order_no'],
  57. 'user_id' => $orderInfo['user_id'],
  58. 'out_trade_no' => $payment['out_trade_no'] ?? '',
  59. 'prepay_id' => $payment['prepay_id'] ?? '',
  60. 'trade_status' => TradeStatusEnum::NOTPAY,
  61. 'store_id' => self::$storeId,
  62. ]);
  63. }
  64. }