ScanPayClass.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. namespace bizHd\order\classes;
  3. use biz\goods\classes\GoodsClass;
  4. use biz\goods\models\Goods;
  5. use biz\shop\classes\ShopCapitalClass;
  6. use biz\shop\classes\ShopClass;
  7. use biz\shop\classes\ShopExtClass;
  8. use biz\stat\classes\StatOrderCountClass;
  9. use biz\stock\classes\GoodsStockRecordClass;
  10. use bizGhs\order\classes\CheckOrderClass;
  11. use bizGhs\product\classes\ProductClass;
  12. use bizGhs\stock\classes\StockRecordClass;
  13. use bizHd\custom\classes\CustomClass;
  14. use bizHd\item\classes\ItemClass;
  15. use bizHd\merchant\classes\SjClass;
  16. use bizHd\order\classes\ScanPayRefundClass;
  17. use bizHd\refund\classes\HdRefundClass;
  18. use bizHd\shop\classes\MainClass;
  19. use bizHd\shop\classes\ShopMoneyChangeClass;
  20. use bizHd\user\classes\UserClass;
  21. use bizHd\work\classes\WorkClass;
  22. use common\components\dict;
  23. use common\components\imgUtil;
  24. use common\components\miniUtil;
  25. use common\components\noticeUtil;
  26. use common\components\orderSn;
  27. use common\components\printUtil;
  28. use common\components\stringUtil;
  29. use common\components\util;
  30. use Yii;
  31. use bizHd\base\classes\BaseClass;
  32. use common\components\lakala\Lakala;
  33. class ScanPayClass extends BaseClass
  34. {
  35. public static $baseFile = '\bizHd\order\models\ScanPay';
  36. public static function getPayList($where)
  37. {
  38. return self::getList('*', $where, 'addTime DESC,id DESC');
  39. }
  40. public static function getDetail($id, $mainId)
  41. {
  42. $order = self::getById($id, true);
  43. if (empty($order)) {
  44. util::fail('没有找到流水');
  45. }
  46. if ($order->mainId != $mainId) {
  47. util::fail('没有权限');
  48. }
  49. $actPrice = $order->actPrice ?? 0;
  50. $tkPrice = $order->tkPrice ?? 0;
  51. $canRefundPrice = bcsub($actPrice, $tkPrice, 2);
  52. if ($canRefundPrice < 0) {
  53. $canRefundPrice = 0;
  54. }
  55. $refundList = ScanPayRefundClass::getAllByCondition(['scanPayId' => $id], 'id DESC', '*');
  56. $payWay = $order->payWay ?? 0;
  57. $payWayMap = dict::getDict('payWay');
  58. $payWayName = '未知';
  59. if ($payWay == ($payWayMap['wxPay'] ?? 0)) {
  60. $payWayName = '微信';
  61. } elseif ($payWay == ($payWayMap['alipay'] ?? 1)) {
  62. $payWayName = '支付宝';
  63. }
  64. return [
  65. 'info' => $order,
  66. 'refundList' => $refundList ?: [],
  67. 'canRefundPrice' => floatval($canRefundPrice),
  68. 'payWayName' => $payWayName,
  69. ];
  70. }
  71. public static function addOrder($data)
  72. {
  73. $mainId = $data['mainId'] ?? 0;
  74. $shopId = $data['shopId'] ?? 0;
  75. $hdId = $data['hdId'] ?? 0;
  76. $customId = $data['customId'] ?? 0;
  77. $snData = ['mainId' => $mainId, 'shopId' => $shopId, 'hdId' => $hdId, 'customId' => $customId];
  78. $data['orderSn'] = orderSn::getScanPaySn($snData);
  79. return self::add($data, true);
  80. }
  81. public static function thirdPay($payWay, $orderSn, $totalFee, $attach, $transactionId)
  82. {
  83. $order = self::getByCondition(['orderSn' => $orderSn], true);
  84. if (empty($order)) {
  85. noticeUtil::push('扫码付款成功,支付回调,单号:' . $orderSn . ' 金额:' . $totalFee . ' 回调id:' . $transactionId . ' 附件:' . $attach . ',没有找到单号', '15280215347');
  86. $msg = "没有找到零售订单 orderSn:{$orderSn}";
  87. Yii::info($msg);
  88. util::fail($msg);
  89. }
  90. if ($order->actPrice != $totalFee) {
  91. noticeUtil::push("扫码付款成功,支付回调错误,订单金额与回调通知金额不一致 orderSn:{$orderSn} {$order->actPrice} {$totalFee} 附件:{$attach}", '15280215347');
  92. $msg = "零售订单金额与回调通知金额不一致 orderSn:{$orderSn} {$order->actPrice} {$totalFee}";
  93. Yii::info($msg);
  94. util::fail($msg);
  95. }
  96. $id = $order->id;
  97. $order = self::getLockById($id);
  98. $date = date("Y-m-d H:i:s");
  99. $order->payStatus = 1;
  100. $order->status = 2;
  101. $order->payTime = $date;
  102. $order->returnCode = $transactionId;
  103. $order->save();
  104. self::payAfter($order);
  105. }
  106. public static function payAfter($order)
  107. {
  108. $capitalType = dict::getDict('capitalType', 'scanPay', 'id');
  109. $mainId = $order->mainId;
  110. $shopId = $order->shopId;
  111. $amount = $order->actPrice ?? 0;
  112. $main = MainClass::getById($mainId, true);
  113. $shop = ShopClass::getLockById($shopId);
  114. ShopClass::customScanPayAddBalance($main, $shop, $amount, $order, $capitalType);
  115. }
  116. }