|
|
@@ -1,5 +1,8 @@
|
|
|
<?php
|
|
|
-
|
|
|
+/**
|
|
|
+ * HD 零售售后服务
|
|
|
+ * 用途:有原单当天/隔天售后、无原单退款;隔天写 nextRefundNum/nextDayTkPrice,对齐资金三态。
|
|
|
+ */
|
|
|
namespace bizHd\refund\services;
|
|
|
|
|
|
use biz\product\classes\ProductClass;
|
|
|
@@ -15,6 +18,7 @@ use bizHd\merchant\classes\ShopClass;
|
|
|
use bizHd\order\classes\OrderClass;
|
|
|
use bizHd\order\classes\OrderGoodsClass;
|
|
|
use bizHd\order\classes\OrderItemClass;
|
|
|
+use bizHd\refund\classes\HdNextDayRefundClass;
|
|
|
use bizHd\refund\classes\HdRefundClass;
|
|
|
use bizHd\refund\classes\HdRefundGoodsClass;
|
|
|
use bizHd\refund\classes\HdRefundItemClass;
|
|
|
@@ -32,29 +36,51 @@ class HdRefundService extends BaseService
|
|
|
|
|
|
public static $baseFile = '\bizHd\refund\classes\HdRefundClass';
|
|
|
|
|
|
- //新增退款
|
|
|
+ /**
|
|
|
+ * 有原单退款(当天或隔天)
|
|
|
+ * 隔天:加 nextRefundNum/nextDayTkPrice,不减 actPrice;资金按快照三态落地。
|
|
|
+ * @return object|\bizHd\refund\models\HdRefund
|
|
|
+ */
|
|
|
public static function addRefund($post, $order)
|
|
|
{
|
|
|
- $refundPrice = $post['price'] ?? 0;
|
|
|
- if ($refundPrice <= 0) {
|
|
|
+ $refundPrice = bcadd((string)($post['price'] ?? '0'), '0', 2);
|
|
|
+ if (bccomp($refundPrice, '0', 2) <= 0) {
|
|
|
util::fail('请填写退款金额');
|
|
|
}
|
|
|
|
|
|
- //记录总的退款金额
|
|
|
- $order->refundPrice = $refundPrice;
|
|
|
- $currentTkPrice = bcadd($order->tkPrice, $refundPrice, 2);
|
|
|
- if ($currentTkPrice > $order->mainPay) {
|
|
|
- util::fail('可退款金额不足');
|
|
|
+ HdNextDayRefundClass::assertCanRefund($order);
|
|
|
+ $sameDay = intval($post['sameDay'] ?? HdRefundClass::SAME_DAY_YES);
|
|
|
+ if (HdNextDayRefundClass::mustUseNextDay($order)) {
|
|
|
+ $sameDay = HdRefundClass::SAME_DAY_NO;
|
|
|
}
|
|
|
- $order->tkPrice = $currentTkPrice;
|
|
|
- $order->refund = OrderClass::REFUND_YES;
|
|
|
- $currentActPrice = bcsub($order->actPrice, $refundPrice, 2);
|
|
|
- if ($currentActPrice < 0) {
|
|
|
- util::fail('可退款金额不足!');
|
|
|
+
|
|
|
+ // 可退金额:当天看 tkPrice;隔天看 tkPrice+nextDayTkPrice 合计不超过 mainPay
|
|
|
+ $mainPay = bcadd((string)($order->mainPay ?? '0'), '0', 2);
|
|
|
+ $alreadyTk = bcadd((string)($order->tkPrice ?? '0'), '0', 2);
|
|
|
+ $alreadyNext = bcadd((string)($order->nextDayTkPrice ?? '0'), '0', 2);
|
|
|
+ if ($sameDay === HdRefundClass::SAME_DAY_YES) {
|
|
|
+ $currentTkPrice = bcadd($alreadyTk, $refundPrice, 2);
|
|
|
+ if (bccomp($currentTkPrice, $mainPay, 2) > 0) {
|
|
|
+ util::fail('可退款金额不足');
|
|
|
+ }
|
|
|
+ $order->tkPrice = $currentTkPrice;
|
|
|
+ $order->refund = OrderClass::REFUND_YES;
|
|
|
+ $currentActPrice = bcsub((string)($order->actPrice ?? '0'), $refundPrice, 2);
|
|
|
+ if (bccomp($currentActPrice, '0', 2) < 0) {
|
|
|
+ util::fail('可退款金额不足!');
|
|
|
+ }
|
|
|
+ $order->actPrice = $currentActPrice;
|
|
|
+ $order->realPrice = $currentActPrice;
|
|
|
+ $order->save();
|
|
|
+ } else {
|
|
|
+ $totalRefunded = bcadd(bcadd($alreadyTk, $alreadyNext, 2), $refundPrice, 2);
|
|
|
+ if (bccomp($totalRefunded, $mainPay, 2) > 0) {
|
|
|
+ util::fail('可退款金额不足');
|
|
|
+ }
|
|
|
+ // 隔天金额在通过资金段 applyHdAmountAndFund 写入 nextDayTkPrice
|
|
|
+ $order->refund = OrderClass::REFUND_YES;
|
|
|
+ $order->save(false, ['refund']);
|
|
|
}
|
|
|
- $order->actPrice = $currentActPrice;
|
|
|
- $order->realPrice = $currentActPrice;
|
|
|
- $order->save();
|
|
|
|
|
|
$refundType = $post['refundType'] ?? 1;
|
|
|
$post['orderId'] = $order->id ?? 0;
|
|
|
@@ -75,12 +101,12 @@ class HdRefundService extends BaseService
|
|
|
$data['mainId'] = $mainId;
|
|
|
$data['shopAdminId'] = $post['shopAdminId'] ?? 0;
|
|
|
$data['shopAdminName'] = $post['shopAdminName'] ?? '';
|
|
|
+ $data['passTime'] = date('Y-m-d H:i:s');
|
|
|
|
|
|
$postProduct = $post['product'] ?? '';
|
|
|
|
|
|
if ($refundType == 1) {
|
|
|
//商品花材结构 property 0商品 1花材
|
|
|
- //[{productId:0,num:1,unitType:0,unitPrice:12,unitName:'扎',property:1}]
|
|
|
if (empty($postProduct)) {
|
|
|
util::fail('没有退款商品');
|
|
|
}
|
|
|
@@ -99,9 +125,6 @@ class HdRefundService extends BaseService
|
|
|
$calcPrice = bcmul($calcNum, $calcUnitPrice, 2);
|
|
|
$calcAmount = bcadd($calcAmount, $calcPrice, 2);
|
|
|
}
|
|
|
- if (floatval($refundPrice) < floatval($calcAmount)) {
|
|
|
- //util::fail('退款金额要大于商品金额总和');
|
|
|
- }
|
|
|
|
|
|
if (!empty($itemInfoList)) {
|
|
|
$ids = array_column($itemInfoList, 'productId');
|
|
|
@@ -128,13 +151,16 @@ class HdRefundService extends BaseService
|
|
|
util::fail('没有找到退款的花材');
|
|
|
}
|
|
|
$orderItemNum = $currentOrderItem->num ?? 0;
|
|
|
- //已退货数
|
|
|
$hasRefundNum = $currentOrderItem->refundNum ?? 0;
|
|
|
$remainNum = bcsub($orderItemNum, $hasRefundNum);
|
|
|
if ($currentRefundNum > $remainNum) {
|
|
|
util::fail("{$name}超过可退数量");
|
|
|
}
|
|
|
+ // refundNum=总已退;隔天另记 nextRefundNum
|
|
|
$currentOrderItem->refundNum = bcadd($hasRefundNum, $currentRefundNum);
|
|
|
+ if ($sameDay === HdRefundClass::SAME_DAY_NO) {
|
|
|
+ $currentOrderItem->nextRefundNum = bcadd($currentOrderItem->nextRefundNum ?? 0, $currentRefundNum);
|
|
|
+ }
|
|
|
$currentOrderItem->save();
|
|
|
$thisItemData = [
|
|
|
'refundSn' => $refundSn,
|
|
|
@@ -178,6 +204,9 @@ class HdRefundService extends BaseService
|
|
|
util::fail("{$name}超过可退数量");
|
|
|
}
|
|
|
$currentOrderGoods->refundNum = bcadd($hasRefundNum, $currentRefundNum);
|
|
|
+ if ($sameDay === HdRefundClass::SAME_DAY_NO) {
|
|
|
+ $currentOrderGoods->nextRefundNum = bcadd($currentOrderGoods->nextRefundNum ?? 0, $currentRefundNum);
|
|
|
+ }
|
|
|
$currentOrderGoods->save();
|
|
|
|
|
|
$cover = $goodsData[$goodsId]['cover'] ?? '';
|
|
|
@@ -195,17 +224,28 @@ class HdRefundService extends BaseService
|
|
|
'price' => $price,
|
|
|
];
|
|
|
HdRefundGoodsClass::addData($saveGoods, $refundSn, $post);
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ $snap = HdNextDayRefundClass::buildRefundPaySnapshot(
|
|
|
+ $order,
|
|
|
+ true,
|
|
|
+ ['payWay' => $post['payWay'] ?? null]
|
|
|
+ );
|
|
|
+
|
|
|
$data['customId'] = $order->customId ?? 0;
|
|
|
+ $data['customName'] = $order->customName ?? '';
|
|
|
$data['remark'] = $post['remark'] ?? '';
|
|
|
$data['refundPrice'] = $refundPrice;
|
|
|
$data['refundType'] = $post['refundType'] ?? 0;
|
|
|
+ $data['sameDay'] = $sameDay;
|
|
|
+ $data['onlinePay'] = $snap['onlinePay'];
|
|
|
+ $data['payWay'] = $snap['payWay'];
|
|
|
+ $data['hasReturn'] = $snap['hasReturn'];
|
|
|
+ $data['couldReturn'] = $snap['couldReturn'];
|
|
|
+ $data['returnBalance'] = $snap['returnBalance'];
|
|
|
|
|
|
- //写入订单表
|
|
|
$refund = HdRefundClass::add($data, true);
|
|
|
|
|
|
$payWay = $order->payWay;
|
|
|
@@ -226,10 +266,8 @@ class HdRefundService extends BaseService
|
|
|
$main->totalRefund = $totalRefund;
|
|
|
$main->save();
|
|
|
|
|
|
- //支出流水
|
|
|
$thisType = dict::getDict('capitalType', 'hdOrderRefund', 'id');
|
|
|
$sjId = $order->sjId ?? 0;
|
|
|
- $event = '销售退款';
|
|
|
$capitalData = [
|
|
|
'capitalType' => $thisType,
|
|
|
'io' => 0,
|
|
|
@@ -238,50 +276,27 @@ class HdRefundService extends BaseService
|
|
|
'amount' => $refundPrice,
|
|
|
'sjId' => $sjId,
|
|
|
'shopId' => $shopId,
|
|
|
- 'event' => $event,
|
|
|
+ 'event' => '销售退款',
|
|
|
'mainId' => $mainId,
|
|
|
];
|
|
|
ShopCapitalClass::addCapital($capitalData);
|
|
|
- //当天和当月支出统计
|
|
|
- //StatOutClass::updateOrInsert($main, $shop, $refundPrice);
|
|
|
- //退款统计
|
|
|
- //StatRefundClass::replace($main, $shop, $payWay, $refundPrice);
|
|
|
|
|
|
+ // 隔天:金额与余额/挂账原路;线下现金等留给成功页
|
|
|
+ if ($sameDay === HdRefundClass::SAME_DAY_NO) {
|
|
|
+ HdNextDayRefundClass::applyHdAmountAndFund($refund, $order);
|
|
|
+ // 线上隔天:仍尝试原路退回通道
|
|
|
+ if (HdNextDayRefundClass::isOnlinePayOrder($refund) || HdNextDayRefundClass::isOnlinePayOrder($order)) {
|
|
|
+ self::doOnlineLakalaRefund($shop, $refund, $refundSn, $myOrderSn, $thirdNo, $refundPrice, $main);
|
|
|
+ HdNextDayRefundClass::syncRefundFundFlags($refund, ['hasReturn' => HdNextDayRefundClass::FLAG_YES]);
|
|
|
+ }
|
|
|
+ return HdRefundClass::getById($refund->id, true);
|
|
|
+ }
|
|
|
+
|
|
|
+ // —— 当天售后资金 ——
|
|
|
if ($onlinePay == dict::getDict('onlinePay', 'yes')) {
|
|
|
- //退款流程
|
|
|
if ($payWay == dict::getDict('payWay', 'wxPay') || $payWay == dict::getDict('payWay', 'alipay')) {
|
|
|
-
|
|
|
- //门店余额减少
|
|
|
- \biz\shop\classes\ShopClass::hdSaleRefundReduceBalance($main, $shop, $refund, $refundPrice);
|
|
|
- $refundFee = bcmul($refundPrice, 100);
|
|
|
- $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
|
|
|
- $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
|
|
|
- $params = [
|
|
|
- 'appid' => 'OP00002119',
|
|
|
- 'serial_no' => '018b08cfddbd',
|
|
|
- 'merchant_no' => $shop->lklSjNo,
|
|
|
- 'term_no' => $shop->lklScanTermNo,
|
|
|
- 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
|
|
|
- 'lklCertificatePath' => $lklCertificatePath,
|
|
|
- ];
|
|
|
- $laResource = new Lakala($params);
|
|
|
- $refundReason = '';
|
|
|
- $refundParams = [
|
|
|
- 'refundSn' => $refundSn,
|
|
|
- 'orderSn' => $myOrderSn,
|
|
|
- 'refundAmount' => $refundFee,
|
|
|
- 'refundReason' => $refundReason,
|
|
|
- 'thirdNo' => $thirdNo,//这个参数必传,不然聚合收银合支付宝付款的退款不会成功
|
|
|
- ];
|
|
|
- $response = $laResource->refund($refundParams);
|
|
|
- if (!isset($response['code']) || $response['code'] != 'BBS00000') {
|
|
|
- $errMsg = $response['msg'] ?? '';
|
|
|
- noticeUtil::push('散客订单,支付宝,退款失败,原因:' . $errMsg . ' refundSn:' . $refundSn . ' orderSn:' . $myOrderSn, '15280215347');
|
|
|
- util::fail('退款失败');
|
|
|
- }
|
|
|
- $wxRefundId = isset($response['resp_data']['trade_no']) ? $response['resp_data']['trade_no'] : '';
|
|
|
- $refund->thirdRefundNo = $wxRefundId;
|
|
|
- $refund->save();
|
|
|
+ self::doOnlineLakalaRefund($shop, $refund, $refundSn, $myOrderSn, $thirdNo, $refundPrice, $main);
|
|
|
+ HdNextDayRefundClass::syncRefundFundFlags($refund, ['hasReturn' => HdNextDayRefundClass::FLAG_YES]);
|
|
|
}
|
|
|
} else {
|
|
|
$customId = $order->customId ?? 0;
|
|
|
@@ -290,7 +305,6 @@ class HdRefundService extends BaseService
|
|
|
util::fail('没有找到客户');
|
|
|
}
|
|
|
if ($payWay == dict::getDict('payWay', 'debtPay')) {
|
|
|
- //如果欠款支付,减掉欠款,其实就是增加余额
|
|
|
$currentRemain = bcsub($order->remainDebtPrice, $refundPrice, 2);
|
|
|
if ($currentRemain < 0) {
|
|
|
util::fail('剩余欠款不足售后金额');
|
|
|
@@ -301,9 +315,9 @@ class HdRefundService extends BaseService
|
|
|
}
|
|
|
$order->save();
|
|
|
CustomClass::skRefundDebtAmountReduce($custom, $refundPrice, $refund, $payWay);
|
|
|
+ HdNextDayRefundClass::syncRefundFundFlags($refund, ['hasReturn' => HdNextDayRefundClass::FLAG_YES]);
|
|
|
}
|
|
|
if ($payWay == dict::getDict('payWay', 'cash')) {
|
|
|
- //如果现金支付
|
|
|
$moneyData = [
|
|
|
'shopId' => $shopId,
|
|
|
'amount' => $refundPrice,
|
|
|
@@ -311,15 +325,222 @@ class HdRefundService extends BaseService
|
|
|
'mainId' => $mainId,
|
|
|
];
|
|
|
ShopMoneyClass::hdRefundSkOutAmount($moneyData, $main);
|
|
|
+ // 现金:需人工确认原路(couldReturn=1),成功页 markHasReturn
|
|
|
}
|
|
|
if ($payWay == dict::getDict('payWay', 'balancePay')) {
|
|
|
- //如果是余额支付,客户的余额要增加
|
|
|
CustomClass::skRefundDebtAmountReduce($custom, $refundPrice, $refund, $payWay);
|
|
|
+ HdNextDayRefundClass::syncRefundFundFlags($refund, ['hasReturn' => HdNextDayRefundClass::FLAG_YES]);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return $refund;
|
|
|
+ return HdRefundClass::getById($refund->id, true);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 拉卡拉线上原路退款
|
|
|
+ */
|
|
|
+ protected static function doOnlineLakalaRefund($shop, $refund, $refundSn, $myOrderSn, $thirdNo, $refundPrice, $main)
|
|
|
+ {
|
|
|
+ \biz\shop\classes\ShopClass::hdSaleRefundReduceBalance($main, $shop, $refund, $refundPrice);
|
|
|
+ $refundFee = bcmul($refundPrice, 100);
|
|
|
+ $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
|
|
|
+ $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
|
|
|
+ $params = [
|
|
|
+ 'appid' => 'OP00002119',
|
|
|
+ 'serial_no' => '018b08cfddbd',
|
|
|
+ 'merchant_no' => $shop->lklSjNo,
|
|
|
+ 'term_no' => $shop->lklScanTermNo,
|
|
|
+ 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
|
|
|
+ 'lklCertificatePath' => $lklCertificatePath,
|
|
|
+ ];
|
|
|
+ $laResource = new Lakala($params);
|
|
|
+ $refundParams = [
|
|
|
+ 'refundSn' => $refundSn,
|
|
|
+ 'orderSn' => $myOrderSn,
|
|
|
+ 'refundAmount' => $refundFee,
|
|
|
+ 'refundReason' => '',
|
|
|
+ 'thirdNo' => $thirdNo,
|
|
|
+ ];
|
|
|
+ $response = $laResource->refund($refundParams);
|
|
|
+ if (!isset($response['code']) || $response['code'] != 'BBS00000') {
|
|
|
+ $errMsg = $response['msg'] ?? '';
|
|
|
+ noticeUtil::push('散客订单,支付宝,退款失败,原因:' . $errMsg . ' refundSn:' . $refundSn . ' orderSn:' . $myOrderSn, '15280215347');
|
|
|
+ util::fail('退款失败');
|
|
|
+ }
|
|
|
+ $wxRefundId = isset($response['resp_data']['trade_no']) ? $response['resp_data']['trade_no'] : '';
|
|
|
+ $refund->thirdRefundNo = $wxRefundId;
|
|
|
+ $refund->save();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 无原单退款(工作台「退款」):orderId=0、sameDay=0,立即完成;资金留给成功页。
|
|
|
+ * @param array $post
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public static function createFreeRefund($post)
|
|
|
+ {
|
|
|
+ $customId = intval($post['customId'] ?? 0);
|
|
|
+ if ($customId <= 0) {
|
|
|
+ util::fail('请选择客户');
|
|
|
+ }
|
|
|
+ $custom = CustomClass::getLockById($customId);
|
|
|
+ if (empty($custom)) {
|
|
|
+ util::fail('没有找到客户');
|
|
|
+ }
|
|
|
+ $mainId = intval($post['mainId'] ?? 0);
|
|
|
+ if ($mainId > 0 && intval($custom->mainId ?? 0) > 0 && intval($custom->mainId) !== $mainId) {
|
|
|
+ // 部分客户用 mainId 归属;无字段则不拦
|
|
|
+ }
|
|
|
+
|
|
|
+ $refundPrice = bcadd((string)($post['price'] ?? '0'), '0', 2);
|
|
|
+ if (bccomp($refundPrice, '0', 2) <= 0) {
|
|
|
+ util::fail('请填写退款金额');
|
|
|
+ }
|
|
|
|
|
|
+ $returnWay = intval($post['returnWay'] ?? -1);
|
|
|
+ if ($returnWay === 0) {
|
|
|
+ $refundType = HdRefundClass::REFUND_TYPE_MONEY;
|
|
|
+ } elseif ($returnWay === 1) {
|
|
|
+ $refundType = HdRefundClass::REFUND_TYPE_MONEY_GOOD;
|
|
|
+ } else {
|
|
|
+ $refundType = intval($post['refundType'] ?? HdRefundClass::REFUND_TYPE_MONEY_GOOD);
|
|
|
+ }
|
|
|
+
|
|
|
+ $snap = HdNextDayRefundClass::buildRefundPaySnapshot(null, false, [
|
|
|
+ 'payWay' => $post['payWay'] ?? null,
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $sjId = intval($post['sjId'] ?? 0);
|
|
|
+ $shopId = intval($post['shopId'] ?? 0);
|
|
|
+ $refundSn = orderSn::getHdRefundSn();
|
|
|
+ $remark = trim((string)($post['remark'] ?? ''));
|
|
|
+
|
|
|
+ $data = [
|
|
|
+ 'status' => HdRefundClass::STATUS_COMPLETE,
|
|
|
+ 'refundSn' => $refundSn,
|
|
|
+ 'orderSn' => '',
|
|
|
+ 'orderId' => 0,
|
|
|
+ 'sjId' => $sjId,
|
|
|
+ 'shopId' => $shopId,
|
|
|
+ 'mainId' => $mainId,
|
|
|
+ 'shopAdminId' => $post['shopAdminId'] ?? 0,
|
|
|
+ 'shopAdminName' => $post['shopAdminName'] ?? '',
|
|
|
+ 'customId' => $customId,
|
|
|
+ 'customName' => $custom->name ?? '',
|
|
|
+ 'remark' => $remark,
|
|
|
+ 'refundPrice' => $refundPrice,
|
|
|
+ 'refundType' => $refundType,
|
|
|
+ 'sameDay' => HdRefundClass::SAME_DAY_NO,
|
|
|
+ 'onlinePay' => $snap['onlinePay'],
|
|
|
+ 'payWay' => $snap['payWay'],
|
|
|
+ 'hasReturn' => $snap['hasReturn'],
|
|
|
+ 'couldReturn' => $snap['couldReturn'],
|
|
|
+ 'returnBalance' => $snap['returnBalance'],
|
|
|
+ 'passTime' => date('Y-m-d H:i:s'),
|
|
|
+ ];
|
|
|
+
|
|
|
+ $postProduct = $post['product'] ?? [];
|
|
|
+ if ($refundType === HdRefundClass::REFUND_TYPE_MONEY_GOOD) {
|
|
|
+ if (empty($postProduct) || !is_array($postProduct)) {
|
|
|
+ util::fail('请选择花材');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $post['refundType'] = $refundType;
|
|
|
+ $post['orderId'] = 0;
|
|
|
+ $refund = HdRefundClass::add($data, true);
|
|
|
+
|
|
|
+ // 有花材则写售后行;是否回库由 refundType 决定(HdRefundItemClass::addData)
|
|
|
+ if (!empty($postProduct) && is_array($postProduct)) {
|
|
|
+ $itemInfoList = [];
|
|
|
+ $goodsInfoList = [];
|
|
|
+ foreach ($postProduct as $current) {
|
|
|
+ $property = intval($current['property'] ?? 1);
|
|
|
+ if ($property === 0) {
|
|
|
+ $goodsInfoList[] = $current;
|
|
|
+ } else {
|
|
|
+ $itemInfoList[] = $current;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!empty($itemInfoList)) {
|
|
|
+ $ids = array_column($itemInfoList, 'productId');
|
|
|
+ $productInfo = ProductClass::getByids($ids, null, 'id');
|
|
|
+ foreach ($itemInfoList as $currentProduct) {
|
|
|
+ $id = intval($currentProduct['productId'] ?? 0);
|
|
|
+ if ($id <= 0 || empty($productInfo[$id])) {
|
|
|
+ util::fail('花材参数错误');
|
|
|
+ }
|
|
|
+ $num = bcadd((string)($currentProduct['num'] ?? '0'), '0', 2);
|
|
|
+ if (bccomp($num, '0', 2) <= 0) {
|
|
|
+ util::fail(($productInfo[$id]['name'] ?? '花材') . '数量必须大于0');
|
|
|
+ }
|
|
|
+ $unitPrice = bcadd((string)($currentProduct['unitPrice'] ?? '0'), '0', 2);
|
|
|
+ $unitType = intval($currentProduct['unitType'] ?? 0);
|
|
|
+ $unitName = $currentProduct['unitName'] ?? '';
|
|
|
+ if ($unitName === '') {
|
|
|
+ $unitName = $unitType === 1
|
|
|
+ ? ($productInfo[$id]['smallUnit'] ?? '支')
|
|
|
+ : ($productInfo[$id]['bigUnit'] ?? '扎');
|
|
|
+ }
|
|
|
+ $thisItemData = [
|
|
|
+ 'refundSn' => $refundSn,
|
|
|
+ 'mainId' => $mainId,
|
|
|
+ 'sjId' => $sjId,
|
|
|
+ 'shopId' => $shopId,
|
|
|
+ 'name' => $productInfo[$id]['name'] ?? '',
|
|
|
+ 'itemId' => $id,
|
|
|
+ 'ptItemId' => $productInfo[$id]['itemId'] ?? 0,
|
|
|
+ 'num' => $num,
|
|
|
+ 'unitName' => $unitName,
|
|
|
+ 'unitType' => $unitType,
|
|
|
+ 'cover' => $productInfo[$id]['cover'] ?? '',
|
|
|
+ 'ratio' => $productInfo[$id]['ratio'] ?? '',
|
|
|
+ 'bigUnit' => $productInfo[$id]['bigUnit'] ?? '',
|
|
|
+ 'smallUnit' => $productInfo[$id]['smallUnit'] ?? '',
|
|
|
+ 'unitPrice' => $unitPrice,
|
|
|
+ 'price' => bcmul($num, $unitPrice, 2),
|
|
|
+ ];
|
|
|
+ HdRefundItemClass::addData($thisItemData, $refundSn, $post);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!empty($goodsInfoList)) {
|
|
|
+ $ids = array_column($goodsInfoList, 'productId');
|
|
|
+ $goodsData = GoodsClass::getByIds($ids, null, 'id');
|
|
|
+ foreach ($goodsInfoList as $currentGoods) {
|
|
|
+ $goodsId = intval($currentGoods['productId'] ?? 0);
|
|
|
+ if ($goodsId <= 0 || empty($goodsData[$goodsId])) {
|
|
|
+ util::fail('商品参数错误');
|
|
|
+ }
|
|
|
+ $num = bcadd((string)($currentGoods['num'] ?? '0'), '0', 2);
|
|
|
+ if (bccomp($num, '0', 2) <= 0) {
|
|
|
+ util::fail(($goodsData[$goodsId]['name'] ?? '商品') . '数量必须大于0');
|
|
|
+ }
|
|
|
+ $unitPrice = bcadd((string)($currentGoods['unitPrice'] ?? '0'), '0', 2);
|
|
|
+ $saveGoods = [
|
|
|
+ 'refundSn' => $refundSn,
|
|
|
+ 'mainId' => $mainId,
|
|
|
+ 'sjId' => $sjId,
|
|
|
+ 'shopId' => $shopId,
|
|
|
+ 'name' => $goodsData[$goodsId]['name'] ?? '',
|
|
|
+ 'cover' => $goodsData[$goodsId]['cover'] ?? '',
|
|
|
+ 'goodsId' => $goodsId,
|
|
|
+ 'num' => $num,
|
|
|
+ 'unitPrice' => $unitPrice,
|
|
|
+ 'price' => bcmul($num, $unitPrice, 2),
|
|
|
+ ];
|
|
|
+ HdRefundGoodsClass::addData($saveGoods, $refundSn, $post);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ HdNextDayRefundClass::addMainExpendForRefund($mainId, $shopId, $sjId, $refundPrice, '无原单退款');
|
|
|
+ HdNextDayRefundClass::applyFreeFund($refund);
|
|
|
+ $refund = HdRefundClass::getById($refund->id, true);
|
|
|
+ $custom = CustomClass::getById($customId, true);
|
|
|
+
|
|
|
+ return HdNextDayRefundClass::buildFundResultPayload($refund, $custom, [
|
|
|
+ 'nextDayTkPrice' => '0.00',
|
|
|
+ 'needFundAction' => 1,
|
|
|
+ ]);
|
|
|
+ }
|
|
|
}
|