|
|
@@ -55,6 +55,7 @@ class HdRefundService extends BaseService
|
|
|
$order->realPrice = $currentActPrice;
|
|
|
$order->save();
|
|
|
|
|
|
+ $refundType = $post['refundType'] ?? 1;
|
|
|
$post['orderId'] = $order->id ?? 0;
|
|
|
|
|
|
$data = [];
|
|
|
@@ -76,123 +77,124 @@ class HdRefundService extends BaseService
|
|
|
|
|
|
$postProduct = $post['product'] ?? '';
|
|
|
|
|
|
- //商品花材结构 property 0商品 1花材
|
|
|
- //[{productId:0,num:1,unitType:0,unitPrice:12,unitName:'扎',property:1}]
|
|
|
- if (empty($postProduct)) {
|
|
|
- util::fail('没有退款商品');
|
|
|
- }
|
|
|
- $goodsInfoList = [];
|
|
|
- $itemInfoList = [];
|
|
|
- $calcAmount = 0;
|
|
|
- foreach ($postProduct as $current) {
|
|
|
- $property = $current['property'] ?? 0;
|
|
|
- if ($property == 0) {
|
|
|
- $goodsInfoList[] = $current;
|
|
|
- } else {
|
|
|
- $itemInfoList[] = $current;
|
|
|
- }
|
|
|
- $calcNum = $current['num'] ?? 0;
|
|
|
- $calcUnitPrice = $current['unitPrice'] ?? 0;
|
|
|
- $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');
|
|
|
- $productInfo = ProductClass::getByids($ids, null, 'id');
|
|
|
- $orderItemData = OrderItemClass::getAllByCondition(['orderSn' => $myOrderSn], null, '*', 'itemId', true);
|
|
|
- if (empty($orderItemData)) {
|
|
|
- util::fail('没有找到商品');
|
|
|
+ if ($refundType == 1) {
|
|
|
+ //商品花材结构 property 0商品 1花材
|
|
|
+ //[{productId:0,num:1,unitType:0,unitPrice:12,unitName:'扎',property:1}]
|
|
|
+ if (empty($postProduct)) {
|
|
|
+ util::fail('没有退款商品');
|
|
|
}
|
|
|
- foreach ($itemInfoList as $currentProduct) {
|
|
|
- $id = $currentProduct['productId'] ?? 0;
|
|
|
- $unitPrice = $currentProduct['unitPrice'] ?? 0;
|
|
|
- $unitType = $currentProduct['unitType'] ?? 0;
|
|
|
- $unitName = $currentProduct['unitName'] ?? '';
|
|
|
- $currentRefundNum = $currentProduct['num'] ?? 0;
|
|
|
- $price = bcmul($currentRefundNum, $unitPrice, 2);
|
|
|
- $name = $productInfo[$id]['name'] ?? '';
|
|
|
- $ptItemId = $productInfo[$id]['itemId'] ?? 0;
|
|
|
- $cover = $productInfo[$id]['cover'] ?? '';
|
|
|
- $ratio = $productInfo[$id]['ratio'] ?? '';
|
|
|
- $bigUnit = $productInfo[$id]['bigUnit'] ?? '';
|
|
|
- $smallUnit = $productInfo[$id]['smallUnit'] ?? '';
|
|
|
- $currentOrderItem = $orderItemData[$id] ?? null;
|
|
|
- if (empty($currentOrderItem)) {
|
|
|
- util::fail('没有找到退款的花材');
|
|
|
- }
|
|
|
- $orderItemNum = $currentOrderItem->num ?? 0;
|
|
|
- //已退货数
|
|
|
- $hasRefundNum = $currentOrderItem->refundNum ?? 0;
|
|
|
- $remainNum = bcsub($orderItemNum, $hasRefundNum);
|
|
|
- if ($currentRefundNum > $remainNum) {
|
|
|
- util::fail("{$name}超过可退数量");
|
|
|
+ $goodsInfoList = [];
|
|
|
+ $itemInfoList = [];
|
|
|
+ $calcAmount = 0;
|
|
|
+ foreach ($postProduct as $current) {
|
|
|
+ $property = $current['property'] ?? 0;
|
|
|
+ if ($property == 0) {
|
|
|
+ $goodsInfoList[] = $current;
|
|
|
+ } else {
|
|
|
+ $itemInfoList[] = $current;
|
|
|
}
|
|
|
- $currentOrderItem->refundNum = bcadd($hasRefundNum, $currentRefundNum);
|
|
|
- $currentOrderItem->save();
|
|
|
- $thisItemData = [
|
|
|
- 'refundSn' => $refundSn,
|
|
|
- 'mainId' => $mainId,
|
|
|
- 'sjId' => $sjId,
|
|
|
- 'shopId' => $shopId,
|
|
|
- 'name' => $name,
|
|
|
- 'itemId' => $id,
|
|
|
- 'ptItemId' => $ptItemId,
|
|
|
- 'num' => $currentRefundNum,
|
|
|
- 'unitName' => $unitName,
|
|
|
- 'unitType' => $unitType,
|
|
|
- 'cover' => $cover,
|
|
|
- 'ratio' => $ratio,
|
|
|
- 'bigUnit' => $bigUnit,
|
|
|
- 'smallUnit' => $smallUnit,
|
|
|
- 'unitPrice' => $unitPrice,
|
|
|
- 'price' => $price,
|
|
|
- ];
|
|
|
- HdRefundItemClass::addData($thisItemData, $refundSn, $post);
|
|
|
+ $calcNum = $current['num'] ?? 0;
|
|
|
+ $calcUnitPrice = $current['unitPrice'] ?? 0;
|
|
|
+ $calcPrice = bcmul($calcNum, $calcUnitPrice, 2);
|
|
|
+ $calcAmount = bcadd($calcAmount, $calcPrice, 2);
|
|
|
}
|
|
|
- }
|
|
|
- if (!empty($goodsInfoList)) {
|
|
|
- $ids = array_column($goodsInfoList, 'productId');
|
|
|
- $goodsData = GoodsClass::getByIds($ids, null, 'id');
|
|
|
- $orderGoodsData = OrderGoodsClass::getAllByCondition(['orderSn' => $myOrderSn], null, '*', 'goodsId', true);
|
|
|
- foreach ($goodsInfoList as $currentGoods) {
|
|
|
- $goodsId = $currentGoods['productId'] ?? 0;
|
|
|
- $unitPrice = $currentGoods['unitPrice'] ?? 0;
|
|
|
- $name = $goodsData[$goodsId]['name'] ?? '';
|
|
|
- $currentRefundNum = $currentGoods['num'] ?? 0;
|
|
|
- $price = bcmul($currentRefundNum, $unitPrice, 2);
|
|
|
- $currentOrderGoods = $orderGoodsData[$goodsId] ?? [];
|
|
|
- if (empty($currentOrderGoods)) {
|
|
|
- util::fail('没有找到商品呢');
|
|
|
+ if (floatval($refundPrice) < floatval($calcAmount)) {
|
|
|
+ util::fail('退款金额要大于商品金额总和');
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!empty($itemInfoList)) {
|
|
|
+ $ids = array_column($itemInfoList, 'productId');
|
|
|
+ $productInfo = ProductClass::getByids($ids, null, 'id');
|
|
|
+ $orderItemData = OrderItemClass::getAllByCondition(['orderSn' => $myOrderSn], null, '*', 'itemId', true);
|
|
|
+ if (empty($orderItemData)) {
|
|
|
+ util::fail('没有找到商品');
|
|
|
}
|
|
|
- $totalNum = $currentOrderGoods->num ?? 0;
|
|
|
- $hasRefundNum = $currentOrderGoods->refundNum ?? 0;
|
|
|
- $remainNum = bcsub($totalNum, $hasRefundNum);
|
|
|
- if ($currentRefundNum > $remainNum) {
|
|
|
- util::fail("{$name}超过可退数量");
|
|
|
+ foreach ($itemInfoList as $currentProduct) {
|
|
|
+ $id = $currentProduct['productId'] ?? 0;
|
|
|
+ $unitPrice = $currentProduct['unitPrice'] ?? 0;
|
|
|
+ $unitType = $currentProduct['unitType'] ?? 0;
|
|
|
+ $unitName = $currentProduct['unitName'] ?? '';
|
|
|
+ $currentRefundNum = $currentProduct['num'] ?? 0;
|
|
|
+ $price = bcmul($currentRefundNum, $unitPrice, 2);
|
|
|
+ $name = $productInfo[$id]['name'] ?? '';
|
|
|
+ $ptItemId = $productInfo[$id]['itemId'] ?? 0;
|
|
|
+ $cover = $productInfo[$id]['cover'] ?? '';
|
|
|
+ $ratio = $productInfo[$id]['ratio'] ?? '';
|
|
|
+ $bigUnit = $productInfo[$id]['bigUnit'] ?? '';
|
|
|
+ $smallUnit = $productInfo[$id]['smallUnit'] ?? '';
|
|
|
+ $currentOrderItem = $orderItemData[$id] ?? null;
|
|
|
+ if (empty($currentOrderItem)) {
|
|
|
+ util::fail('没有找到退款的花材');
|
|
|
+ }
|
|
|
+ $orderItemNum = $currentOrderItem->num ?? 0;
|
|
|
+ //已退货数
|
|
|
+ $hasRefundNum = $currentOrderItem->refundNum ?? 0;
|
|
|
+ $remainNum = bcsub($orderItemNum, $hasRefundNum);
|
|
|
+ if ($currentRefundNum > $remainNum) {
|
|
|
+ util::fail("{$name}超过可退数量");
|
|
|
+ }
|
|
|
+ $currentOrderItem->refundNum = bcadd($hasRefundNum, $currentRefundNum);
|
|
|
+ $currentOrderItem->save();
|
|
|
+ $thisItemData = [
|
|
|
+ 'refundSn' => $refundSn,
|
|
|
+ 'mainId' => $mainId,
|
|
|
+ 'sjId' => $sjId,
|
|
|
+ 'shopId' => $shopId,
|
|
|
+ 'name' => $name,
|
|
|
+ 'itemId' => $id,
|
|
|
+ 'ptItemId' => $ptItemId,
|
|
|
+ 'num' => $currentRefundNum,
|
|
|
+ 'unitName' => $unitName,
|
|
|
+ 'unitType' => $unitType,
|
|
|
+ 'cover' => $cover,
|
|
|
+ 'ratio' => $ratio,
|
|
|
+ 'bigUnit' => $bigUnit,
|
|
|
+ 'smallUnit' => $smallUnit,
|
|
|
+ 'unitPrice' => $unitPrice,
|
|
|
+ 'price' => $price,
|
|
|
+ ];
|
|
|
+ HdRefundItemClass::addData($thisItemData, $refundSn, $post);
|
|
|
}
|
|
|
- $currentOrderGoods->refundNum = bcadd($hasRefundNum, $currentRefundNum);
|
|
|
- $currentOrderGoods->save();
|
|
|
+ }
|
|
|
+ if (!empty($goodsInfoList)) {
|
|
|
+ $ids = array_column($goodsInfoList, 'productId');
|
|
|
+ $goodsData = GoodsClass::getByIds($ids, null, 'id');
|
|
|
+ $orderGoodsData = OrderGoodsClass::getAllByCondition(['orderSn' => $myOrderSn], null, '*', 'goodsId', true);
|
|
|
+ foreach ($goodsInfoList as $currentGoods) {
|
|
|
+ $goodsId = $currentGoods['productId'] ?? 0;
|
|
|
+ $unitPrice = $currentGoods['unitPrice'] ?? 0;
|
|
|
+ $name = $goodsData[$goodsId]['name'] ?? '';
|
|
|
+ $currentRefundNum = $currentGoods['num'] ?? 0;
|
|
|
+ $price = bcmul($currentRefundNum, $unitPrice, 2);
|
|
|
+ $currentOrderGoods = $orderGoodsData[$goodsId] ?? [];
|
|
|
+ if (empty($currentOrderGoods)) {
|
|
|
+ util::fail('没有找到商品呢');
|
|
|
+ }
|
|
|
+ $totalNum = $currentOrderGoods->num ?? 0;
|
|
|
+ $hasRefundNum = $currentOrderGoods->refundNum ?? 0;
|
|
|
+ $remainNum = bcsub($totalNum, $hasRefundNum);
|
|
|
+ if ($currentRefundNum > $remainNum) {
|
|
|
+ util::fail("{$name}超过可退数量");
|
|
|
+ }
|
|
|
+ $currentOrderGoods->refundNum = bcadd($hasRefundNum, $currentRefundNum);
|
|
|
+ $currentOrderGoods->save();
|
|
|
|
|
|
- $cover = $goodsData[$goodsId]['cover'] ?? '';
|
|
|
- $num = $currentGoods['num'] ?? 0;
|
|
|
- $saveGoods = [
|
|
|
- 'refundSn' => $refundSn,
|
|
|
- 'mainId' => $mainId,
|
|
|
- 'sjId' => $sjId,
|
|
|
- 'shopId' => $shopId,
|
|
|
- 'name' => $name,
|
|
|
- 'cover' => $cover,
|
|
|
- 'goodsId' => $goodsId,
|
|
|
- 'num' => $num,
|
|
|
- 'unitPrice' => $unitPrice,
|
|
|
- 'price' => $price,
|
|
|
- ];
|
|
|
- HdRefundGoodsClass::addData($saveGoods, $refundSn, $post);
|
|
|
+ $cover = $goodsData[$goodsId]['cover'] ?? '';
|
|
|
+ $num = $currentGoods['num'] ?? 0;
|
|
|
+ $saveGoods = [
|
|
|
+ 'refundSn' => $refundSn,
|
|
|
+ 'mainId' => $mainId,
|
|
|
+ 'sjId' => $sjId,
|
|
|
+ 'shopId' => $shopId,
|
|
|
+ 'name' => $name,
|
|
|
+ 'cover' => $cover,
|
|
|
+ 'goodsId' => $goodsId,
|
|
|
+ 'num' => $num,
|
|
|
+ 'unitPrice' => $unitPrice,
|
|
|
+ 'price' => $price,
|
|
|
+ ];
|
|
|
+ HdRefundGoodsClass::addData($saveGoods, $refundSn, $post);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -296,7 +298,7 @@ class HdRefundService extends BaseService
|
|
|
$order->debt = 0;
|
|
|
}
|
|
|
$order->save();
|
|
|
- CustomClass::skRefundDebtAmountReduce($custom, $refundPrice, $refund,$payWay);
|
|
|
+ CustomClass::skRefundDebtAmountReduce($custom, $refundPrice, $refund, $payWay);
|
|
|
}
|
|
|
if ($payWay == dict::getDict('payWay', 'cash')) {
|
|
|
//如果现金支付
|
|
|
@@ -310,7 +312,7 @@ class HdRefundService extends BaseService
|
|
|
}
|
|
|
if ($payWay == dict::getDict('payWay', 'balancePay')) {
|
|
|
//如果是余额支付,客户的余额要增加
|
|
|
- CustomClass::skRefundDebtAmountReduce($custom, $refundPrice, $refund,$payWay);
|
|
|
+ CustomClass::skRefundDebtAmountReduce($custom, $refundPrice, $refund, $payWay);
|
|
|
}
|
|
|
}
|
|
|
return $refund;
|