HdRefundClass.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. namespace bizHd\refund\classes;
  3. use biz\shop\classes\ShopExtClass;
  4. use common\components\noticeUtil;
  5. use common\components\orderSn;
  6. use Yii;
  7. use bizHd\base\classes\BaseClass;
  8. use common\components\lakala\Lakala;
  9. class HdRefundClass extends BaseClass
  10. {
  11. public static $baseFile = '\bizHd\refund\models\HdRefund';
  12. const REFUND_TYPE_MONEY_GOOD = 1; //退款退货
  13. const REFUND_TYPE_MONEY = 2; // 仅退款
  14. const STATUS_UN_COMPLETE = 0; //退款处理中
  15. const STATUS_COMPLETE = 1; //已完成
  16. public static function onlyRefundAmount($shop, $order)
  17. {
  18. $refundSn = orderSn::getHdRefundSn();
  19. $xsOrderSn = $order['orderSn'] ?? '';
  20. $refundPrice = $order['actPrice'] ?? 0;
  21. $refundFee = bcmul($refundPrice, 100);
  22. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  23. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  24. $params = [
  25. 'appid' => 'OP00002119',
  26. 'serial_no' => '018b08cfddbd',
  27. 'merchant_no' => $shop->lklSjNo,
  28. 'term_no' => $shop->lklScanTermNo,
  29. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  30. 'lklCertificatePath' => $lklCertificatePath,
  31. ];
  32. $laResource = new Lakala($params);
  33. $refundReason = '';
  34. $orderSn = '';
  35. $thirdNo = $order['thirdNo'] ?? '';
  36. //竟然会出现thirdNo为空的情况,好像客户付款时有优惠金额时
  37. if (empty($thirdNo)) {
  38. $orderSn = $order['orderSn'] ?? '';
  39. }
  40. $backParams = [
  41. 'refundSn' => $refundSn,
  42. 'thirdNo' => $thirdNo,
  43. 'orderSn' => $orderSn,
  44. 'refundAmount' => $refundFee,
  45. 'refundReason' => $refundReason,
  46. ];
  47. $response = $laResource->refund($backParams);
  48. if (!isset($response['code']) || $response['code'] != 'BBS00000') {
  49. $errMsg = $response['msg'] ?? '';
  50. noticeUtil::push("钱没有退回 {$xsOrderSn} {$errMsg}", '15280215347');
  51. return ['status' => 0, 'msg' => $errMsg];
  52. } else {
  53. $shopId = $shop->id;
  54. ShopExtClass::orderCancelBackMoneyReport($shopId);
  55. $sjName = $shop->merchantName;
  56. $shopName = $shop->shopName;
  57. $name = $shopName == '首店' ? $sjName : $sjName . '-' . $shopName;
  58. noticeUtil::push("钱已经原路退回 success {$xsOrderSn} {$name}", '15280215347');
  59. return ['status' => 1, 'msg' => '退款成功'];
  60. }
  61. }
  62. // 订单列表
  63. public static function getOrderList($where)
  64. {
  65. $data = self::getList('*', $where, 'addTime DESC');
  66. $list = isset($data['list']) && !empty($data['list']) ? $data['list'] : [];
  67. if (empty($list)) {
  68. return $data;
  69. }
  70. $data['list'] = $list;
  71. return $data;
  72. }
  73. //验证信息 ssh 20220401
  74. public static function valid($refund, $mainId)
  75. {
  76. if (empty($refund)) {
  77. util::fail('没有找到退款信息');
  78. }
  79. if (isset($refund->mainId) == false || $refund->mainId != $mainId) {
  80. util::fail('无法操作');
  81. }
  82. return true;
  83. }
  84. }