|
|
@@ -36,7 +36,7 @@ class RefundOrderService extends BaseService
|
|
|
|
|
|
$refundPrice = $post['price'] ?? 0;
|
|
|
if ($refundPrice <= 0) {
|
|
|
- util::fail('请输入退款金额');
|
|
|
+ util::fail('请填写退款金额');
|
|
|
}
|
|
|
|
|
|
$data = [];
|
|
|
@@ -44,56 +44,77 @@ class RefundOrderService extends BaseService
|
|
|
$orderSn = orderSn::getGhsRefundSn();
|
|
|
$data['orderSn'] = $orderSn;
|
|
|
$data['relateOrderSn'] = $order->orderSn ?? '';
|
|
|
- $data['sjId'] = $post['sjId'];
|
|
|
- $data['shopId'] = $post['shopId'];
|
|
|
- $data['mainId'] = $post['mainId'];
|
|
|
+ $sjId = $post['sjId'] ?? 0;
|
|
|
+ $shopId = $post['shopId'] ?? 0;
|
|
|
+ $mainId = $post['mainId'] ?? 0;
|
|
|
+ $data['sjId'] = $sjId;
|
|
|
+ $data['shopId'] = $shopId;
|
|
|
+ $data['mainId'] = $mainId;
|
|
|
$data['shopAdminId'] = $post['shopAdminId'] ?? 0;
|
|
|
$data['shopAdminName'] = $post['shopAdminName'] ?? '';
|
|
|
|
|
|
- //花材列表
|
|
|
- $ghsItemInfo = $post['product'] ?? '';
|
|
|
+ //花材列表 [{productId:0,num:1,unitType:0}] productId 花材id num 退货数 unitType 大小单位0大1小
|
|
|
+ $postProduct = $post['product'] ?? '';
|
|
|
|
|
|
-
|
|
|
- $data['itemNum'] = $data['bigNum'];
|
|
|
-
|
|
|
- $data['customId'] = $order->customId ?? 0;
|
|
|
- $data['remark'] = $post['remark'] ?? '';
|
|
|
- $data['refundPrice'] = $refundPrice;
|
|
|
- $data['refundType'] = $post['refundType'] ?? 0;
|
|
|
-
|
|
|
-
|
|
|
- //写入订单表
|
|
|
- $refund = RefundOrderClass::add($data, true);
|
|
|
if ($data['refundType'] == RefundOrderClass::REFUND_TYPE_MONEY_GOOD) {
|
|
|
- //退货,加库存
|
|
|
- foreach ($ghsItemInfo as $k => $v) {
|
|
|
- $stockInfo = ProductClass::addStock($v['productId'], $v['bigNum'], $v['smallNum']);
|
|
|
- $ghsItemInfo[$k]['oldStock'] = $stockInfo['oldStock'];
|
|
|
- $ghsItemInfo[$k]['newStock'] = $stockInfo['newStock'];
|
|
|
+ if (empty($postProduct)) {
|
|
|
+ util::fail('没有退款花材');
|
|
|
}
|
|
|
+ $ids = array_column($postProduct, 'productId');
|
|
|
+ $productInfo = ProductClass::getByids($ids, null, 'id');
|
|
|
|
|
|
- //退款订单花材详情
|
|
|
$saleOrderSn = $order->orderSn ?? '';
|
|
|
$orderItemData = OrderItemClass::getAllByCondition(['orderSn' => $saleOrderSn], null, '*', 'productId');
|
|
|
+ if (empty($orderItemData)) {
|
|
|
+ util::fail('没有找到花材');
|
|
|
+ }
|
|
|
|
|
|
- $batchData = RefundOrderClass::groupOrderItem($ghsItemInfo, $orderSn, $orderItemData);
|
|
|
- RefundOrderItemClass::batchAddOrderItem($batchData);
|
|
|
-
|
|
|
- //花材销量统计变动
|
|
|
- foreach ($batchData as $refundItemInfo) {
|
|
|
- StatItemClass::refundReplace($refundItemInfo);
|
|
|
+ foreach ($postProduct as $currentProduct) {
|
|
|
+ $id = $currentProduct['productId'] ?? 0;
|
|
|
+ $num = $currentProduct['num'] ?? 0;
|
|
|
+ $unitType = $currentProduct['unitType'] ?? 0;
|
|
|
+ $name = $productInfo[$id]['name'] ?? '';
|
|
|
+ $ptItemId = $productInfo[$id]['itemId'] ?? 0;
|
|
|
+ $itemCost = $productInfo[$id]['cost'] ?? 0;
|
|
|
+
|
|
|
+ $xhNum = $orderItemData[$id]['xhNum'] ?? 0;
|
|
|
+ $refundNum = $orderItemData[$id]['refundNum'] ?? 0;
|
|
|
+ $remainNum = bcsub($xhNum, $refundNum);
|
|
|
+ if ($num > $remainNum) {
|
|
|
+ util::fail("{$name}超过可退数量");
|
|
|
+ }
|
|
|
+
|
|
|
+ $thisItemData = [
|
|
|
+ 'sjId' => $sjId,
|
|
|
+ 'shopId' => $shopId,
|
|
|
+ 'orderSn' => $orderSn,
|
|
|
+ 'productId' => $id,
|
|
|
+ 'name' => $name,
|
|
|
+ 'itemId' => $ptItemId,
|
|
|
+ 'itemStock' => 0,
|
|
|
+ 'itemCost' => $itemCost,
|
|
|
+ 'newStock' => 0,
|
|
|
+ 'xhNum' => $xhNum,
|
|
|
+ 'xhUnitName' => $xhUnitName,
|
|
|
+ 'xhUnitType' => $unitType,
|
|
|
+ 'xhUnitPrice' => $xhUnitPrice,
|
|
|
+ 'xhPrice' => $xhPrice,
|
|
|
+ ];
|
|
|
+ RefundOrderItemClass::addData($thisItemData);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
- $orderData = RefundOrderClass::getOrderDetail($orderSn, $refund->shopId);
|
|
|
- $orderData['shopId'] = $data['shopId'];
|
|
|
|
|
|
- //增加库存变动记录
|
|
|
- if ($data['refundType'] == RefundOrderClass::REFUND_TYPE_MONEY_GOOD) {
|
|
|
- $orderData['relateName'] = $order->customName ?? '';
|
|
|
- StockRecordClass::addRecordByOrder($orderData, StockRecordClass::STOCK_RECORD_TYPE_REFUND);
|
|
|
- }
|
|
|
+ $data['customId'] = $order->customId ?? 0;
|
|
|
+ $data['remark'] = $post['remark'] ?? '';
|
|
|
+ $data['refundPrice'] = $refundPrice;
|
|
|
+ $data['refundType'] = $post['refundType'] ?? 0;
|
|
|
+
|
|
|
+
|
|
|
+ //写入订单表
|
|
|
+ $refund = RefundOrderClass::add($data, true);
|
|
|
+
|
|
|
|
|
|
$payWay = $order->payWay;
|
|
|
$shopId = $order->shopId;
|