saleRefundId ?? 0; $saleRefund = RefundOrderClass::getById($saleRefundId, true); if (empty($saleRefund)) { util::fail('退款信息缺失'); } RefundOrderClass::cancelRefund($saleRefund); } public static function createOrder($cgData, $cg) { $respond = self::addRefund($cgData, $cg); $saleId = $cg->saleId ?? 0; $order = OrderClass::getById($saleId, true); if (empty($order)) { util::fail('没有订单信息'); } $remark = $cgData['remark'] ?? ''; $price = $cgData['price'] ?? 0; $refundType = $cgData['refundType'] ?? 1; $imgList = $cgData['imgList'] ?? ''; $sjId = $order->sjId ?? 0; $shopId = $order->shopId ?? 0; $mainId = $order->mainId ?? 0; $cgProductList = $cgData['product'] ?? []; $newProductList = []; if (!empty($cgProductList)) { $cgIds = array_column($cgProductList, 'productId'); $cgProductInfo = ProductClass::getAllByCondition(['id' => ['in', $cgIds]], null, 'id,itemId'); if (empty($cgProductInfo)) { util::fail('花材数据有问题'); } $cgMap = []; foreach ($cgProductInfo as $cc) { $ccId = $cc['id'] ?? 0; $ccPtItemId = $cc['itemId'] ?? 0; $cgMap[$ccId] = $ccPtItemId; } $ptItemList = array_column($cgProductInfo, 'itemId'); $saleProductInfo = ProductClass::getAllByCondition(['mainId' => $mainId, 'itemId' => ['in', $ptItemList]], null, 'id,itemId'); if (empty($saleProductInfo)) { util::fail('花材信息有问题'); } $saleMap = []; foreach ($saleProductInfo as $ss) { $ssId = $ss['id'] ?? 0; $ssPtItemId = $ss['itemId'] ?? 0; $saleMap[$ssPtItemId] = $ssId; } foreach ($cgProductList as $cg) { if (isset($cg['productId']) == false) { util::fail('花材有问题呢'); } $productId = $cg['productId']; if (isset($cgMap[$productId]) == false) { util::fail('花材有问题哈'); } $ptItemId = $cgMap[$productId]; if (isset($saleMap[$ptItemId]) == false) { util::fail('花材有问题哦'); } $newProductId = $saleMap[$ptItemId]; $cg['productId'] = $newProductId; $newProductList[] = $cg; } } $orderData = [ 'remark' => $remark, 'price' => $price, 'refundType' => $refundType, 'imgList' => $imgList, 'sjId' => $sjId, 'shopId' => $shopId, 'mainId' => $mainId, 'product' => $newProductList, ]; $cgRefundId = $respond->id ?? 0; $saleRefund = RefundOrderService::addRefund($orderData, $order); $saleRefund->cgRefundId = $cgRefundId; $saleRefund->save(); $saleRefundId = $saleRefund->id ?? 0; $respond->saleRefundId = $saleRefundId; $respond->save(); return $respond; } //新增退款 public static function addRefund($post, $cg) { $mainId = $cg->mainId ?? 0; $shopId = $cg->shopId ?? 0; $sjId = $cg->sjId ?? 0; $cgOrderSn = $cg->orderSn ?? ''; $refundOrderSn = orderSn::getCgRefundSn(); $cause = $post['cause'] ?? 0; $refundPrice = $post['price'] ?? 0; if (is_numeric($refundPrice) == false || $refundPrice < 0) { util::fail('请填写退款金额'); } $shop = ShopClass::getLockById($shopId); if (empty($shop)) { util::fail('没有找到门店47'); } $main = MainClass::getLockById($mainId); if (empty($main)) { util::fail('没有main信息30'); } $data = []; $data['orderSn'] = $refundOrderSn; $data['shopId'] = $shopId; $data['mainId'] = $mainId; $data['sjId'] = $sjId; $data['shopAdminId'] = $cg->shopAdminId; $data['shopAdminName'] = $cg->shopAdminName; $data['cgId'] = $cg->id; $refundType = $post['refundType'] ?? 0; $data['refundType'] = $refundType; $data['refundPrice'] = $refundPrice; $data['remark'] = $post['remark'] ?? ''; $data['imgList'] = $post['imgList'] ?? ''; $data['status'] = CgRefundClass::STATUS_UN_COMPLETE; $refundSendCost = isset($post['refundSendCost']) && is_numeric($post['refundSendCost']) ? $post['refundSendCost'] : 0; $refundPackCost = isset($post['refundPackCost']) && is_numeric($post['refundPackCost']) ? $post['refundPackCost'] : 0; $data['refundSendCost'] = $refundSendCost; $data['refundPackCost'] = $refundPackCost; $cg->refundSendCost = bcadd($refundSendCost, $cg->refundSendCost, 2); $cg->refundPackCost = bcadd($refundPackCost, $cg->refundPackCost, 2); $cg->refundLog = 1; $cg->save(); //花材列表结构 // [{productId:0,num:1,unitType:0,unitPrice:12,unitName:'扎'}] productId 花材id num 退货数 unitType 大小单位0大1小 unitPrice 售价 unitName单位名称 $productList = $post['product'] ?? ''; $bigNum = 0; $smallNum = 0; foreach ($productList as $current) { $unitType = $current['unitType'] ?? dict::getDict('unitType', 'big'); $num = $current['num'] ?? 0; if ($unitType == dict::getDict('unitType', 'big')) { $bigNum = bcadd($bigNum, $num); } else { $smallNum = bcadd($smallNum, $num); } } $data['bigNum'] = $bigNum; $data['smallNum'] = $smallNum; $data['cause'] = $cause; $cgRefund = CgRefundClass::add($data, true); if ($refundType == CgRefundClass::REFUND_TYPE_MONEY_GOOD) { $cgItemInfo = PurchaseItemClass::getAllByCondition(['orderSn' => $cgOrderSn], null, '*', 'productId', true); $originPrice = 0; foreach ($productList as $info) { $productId = $info['productId'] ?? 0; if (isset($cgItemInfo[$productId]) == false) { util::fail('没有找到花材哦!'); } $currentInfo = $cgItemInfo[$productId]; $ptItemId = $currentInfo->itemId; $name = $currentInfo->name; $cover = $currentInfo->cover; $ratio = $currentInfo->ratio; $cgItemId = $currentInfo->id; $unitType = $info['unitType'] ?? 0; $num = $info['num'] ?? 0; $unitPrice = $info['unitPrice'] ?? 0; $unitName = $info['unitName'] ?? ''; $currentPrice = bcmul($num,$unitPrice,2); $originPrice = bcadd($originPrice,$currentPrice,2); $itemNum = $num; if ($unitType == dict::getDict('unitType', 'small')) { $itemNum = bcdiv($num, $ratio, 2); } $refundData = []; $refundData['orderSn'] = $refundOrderSn; $refundData['itemId'] = $ptItemId; $refundData['productId'] = $productId; $refundData['name'] = $name; $refundData['cover'] = $cover; $refundData['itemCost'] = $unitPrice; $refundData['ratio'] = $ratio; $refundData['mainId'] = $mainId; $refundData['shopId'] = $shopId; $refundData['sjId'] = $sjId; $refundData['xhNum'] = $num; $refundData['itemNum'] = $itemNum; $refundData['xhUnitName'] = $unitName; $refundData['xhUnitType'] = $unitType; $refundData['xhUnitPrice'] = $unitPrice; $refundData['xhPrice'] = 0; $refundData['cgItemId'] = $cgItemId; $refundData['cause'] = $cause; CgRefundItemClass::addData($refundData, $cg); } if($refundPrice<$originPrice){ //util::fail('退款金额要等于或大于花材总和'); } } return $cgRefund; } }