shopAdmin; if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) { util::fail('超管才能报损'); } $post = Yii::$app->request->post(); $refundItemId = $post['refundItemId'] ?? 0; $wasteProductId = $post['wasteProductId'] ?? 0; $wasteNum = $post['wasteNum'] ?? 0; unset($post['refundId']); unset($post['wasteNum']); unset($post['wasteProductId']); $productInfo = ProductClass::getById($wasteProductId, true); if (empty($productInfo)) { util::fail('没有找到花材'); } $ptItemId = $productInfo->itemId ?? 0; $ratio = $productInfo->ratio ?? 20; $refundItem = RefundOrderItemClass::getById($refundItemId, true); if (empty($refundItem)) { util::fail('没有找到退货信息'); } if ($refundItem->mainId != $this->mainId) { util::fail('不是您的退款信息'); } $unitType = $refundItem->xhUnitType ?? 0; if ($unitType == 1) { util::fail('无法报损'); } $refundNum = $refundItem->xhNum ?? 0; $hasWasteNum = $refundItem->xhWasteNum ?? 0; $remainNum = bcsub($refundNum, $hasWasteNum); if ($wasteNum > $remainNum) { util::fail('剩余可报损数量 ' . $remainNum); } $productList = [['productId' => $wasteProductId, 'bigNum' => $wasteNum, 'smallNum' => 0, 'classId' => 0, 'itemId' => $ptItemId, 'ratio' => $ratio]]; $post['shopId'] = $this->shopId; $post['sjId'] = $this->sjId; $post['mainId'] = $this->mainId; $post['shopAdminId'] = $this->shopAdminId; $shopAdmin = $this->shopAdmin; $adminName = $shopAdmin['name'] ?? ''; $post['shopAdminName'] = $adminName; $connection = Yii::$app->db;//事务处理 $transaction = $connection->beginTransaction(); try { $refundItem->xhWasteNum = bcadd($refundItem->xhWasteNum, $wasteNum); $refundItem->save(); $post['product'] = $productList; $return = StockWastageOrderClass::addOrder($post); $transaction->commit(); util::success($return); } catch (\Exception $e) { $transaction->rollBack(); Yii::info("报损失败原因:" . $e->getMessage()); util::fail('报损失败'); } } //列表 public function actionList() { $get = Yii::$app->request->get(); $where = []; $where['mainId'] = $this->mainId; $orderSn = $get['orderSn'] ?? ''; if (!empty($orderSn)) { $where['relateOrderSn'] = $orderSn; } $list = RefundOrderClass::getOrderList($where); util::success($list); } public function actionDetail() { $id = Yii::$app->request->get('id', 0); $refund = RefundOrderClass::getById($id, true); RefundOrderClass::valid($refund, $this->mainId); $orderSn = $refund->orderSn ?? ''; $itemList = RefundOrderItemClass::getOrderItemDetail($orderSn); util::success(['info' => $refund, 'itemList' => $itemList]); } //退款 lqh 2021.6.25 public function actionCreateOrder() { $shopAdmin = $this->shopAdmin; if (isset($shopAdmin['super']) == false || $shopAdmin['super'] != 1) { util::fail('超管才能操作退款'); } $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); try { $post = Yii::$app->request->post(); $id = isset($post['id']) ? $post['id'] : 0; $order = OrderClass::getById($id, true); OrderClass::valid($order, $this->shopId); if ($order->status != OrderClass::ORDER_STATUS_COMPLETE) { util::fail("订单完成了才能发起退款"); } $customId = $order->customId ?? 0; $clearList = PurchaseClearClass::getAllByCondition(['customId' => $customId, 'status' => 1], null, '*', null, true); $orderIds = []; if (!empty($clearList)) { foreach ($clearList as $clear) { $saleStr = $clear->saleIds ?? ''; $deadline = $clear->deadline ?? ''; if ($deadline < date("Y-m-d H:i:s")) { $clear->status = 3; $clear->save(); }else{ if (!empty($saleStr)) { $current = explode(',', $saleStr); $orderIds = array_merge($orderIds, $current); } } } if (!empty($orderIds) && in_array($id, $orderIds)) { util::fail('此客户有结账单未完成'); } } $addTime = $order->addTime ?? ''; $current = time(); if ((strtotime($addTime) + 3 * 30 * 24 * 60 * 60) < $current) { util::fail('历史订单,不能再发起退款'); } if (strtotime($addTime) <= strtotime('2022-03-30 00:00:00')) { util::fail('历史订单,不能发起退款哦'); } //退款类型 1退货并退款 2 仅退款 $refundType = $post['refundType'] ?? 1; if ($refundType == RefundOrderClass::REFUND_TYPE_MONEY_GOOD) { //花材列表结构 // [{productId:0,num:1,unitType:0,unitPrice:12,unitName:'扎'}] productId 花材id num 退货数 unitType 大小单位0大1小 unitPrice 售价 unitName单位名称 $productJson = $post['product'] ?? ''; if (empty($productJson)) { util::fail('请选择花材'); } $productList = json_decode($productJson, true); if (!is_array($productList)) { util::fail('请选择花材哦'); } $post['product'] = $productList; } else { //仅退款花材直接设置为空 $post['product'] = []; } $post['price'] = $post['price'] ?? 0; if ($post['price'] <= 0) { util::fail("退款金额不能小于0"); } if (bccomp($post['price'], $order['realPrice'], 2) == 1) { util::fail("退款金额超过订单金额"); } $post['shopId'] = $this->shopId; $post['sjId'] = $this->sjId; $post['shopAdminId'] = $this->shopAdminId; $post['mainId'] = $this->mainId; $shopAdmin = $this->shopAdmin; $adminName = $shopAdmin['name'] ?? ''; $post['shopAdminName'] = $adminName; $respond = OrderService::refund($id, $post); $transaction->commit(); util::success($respond); } catch (\Exception $exception) { $transaction->rollBack(); Yii::info("退款出错了,报错信息:" . $exception->getMessage()); util::fail('操作失败'); } } }