shopAdmin; if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) { util::fail('无法操作'); } $get = Yii::$app->request->get(); $id = $get['id'] ?? 0; $refund = RefundOrderClass::getById($id, true); RefundOrderClass::valid($refund, $this->mainId); $connection = Yii::$app->db;//事务处理 $transaction = $connection->beginTransaction(); try { RefundOrderService::passRefund($refund); $transaction->commit(); //审核结果通知 $cgRefundId = $refund->cgRefundId ?? 0; $cgRefund = CgRefundClass::getById($cgRefundId, true); $cgShopId = $cgRefund->shopId ?? 0; $cgShop = ShopClass::getById($cgShopId, true); if (!empty($cgRefund) && !empty($cgShop)) { NoticeClass::afterSaleNotice($cgShop, $cgRefund); } util::complete('操作成功'); } catch (\Exception $e) { $transaction->rollBack(); Yii::info("操作失败原因:" . $e->getMessage()); util::fail('操作失败'); } } //驳回 ssh 20230813 public function actionReject() { $shopAdmin = $this->shopAdmin; if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) { util::fail('无法操作'); } $post = Yii::$app->request->post(); $id = $post['id'] ?? 0; $rejectReason = $post['rejectReason'] ?? ''; $refund = RefundOrderClass::getById($id, true); RefundOrderClass::valid($refund, $this->mainId); $connection = Yii::$app->db;//事务处理 $transaction = $connection->beginTransaction(); try { RefundOrderClass::rejectRefund($refund, $rejectReason); $transaction->commit(); //审核结果通知 $cgRefundId = $refund->cgRefundId ?? 0; $cgRefund = CgRefundClass::getById($cgRefundId, true); $cgShopId = $cgRefund->shopId ?? 0; $cgShop = ShopClass::getById($cgShopId, true); if (!empty($cgRefund) && !empty($cgShop)) { NoticeClass::afterSaleNotice($cgShop, $cgRefund); } util::complete('操作成功'); } catch (\Exception $e) { $transaction->rollBack(); Yii::info("操作失败原因:" . $e->getMessage()); util::fail('操作失败'); } } //退款之后报损 ssh 20230409 public function actionRefundWaste() { $shopAdmin = $this->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); if (empty($refund)) { util::fail('没有找到退款信息'); } if (isset($refund['mainId']) == false || $refund['mainId'] != $this->mainId) { util::fail('没有权限'); } $imgString = $refund['imgList'] ?? ''; $relateOrderSn = $refund['relateOrderSn'] ?? ''; $order = OrderClass::getByCondition(['orderSn' => $relateOrderSn], true); if (empty($order)) { util::fail('数据出错了'); } $refund['relateOrderId'] = $order->id; if (!empty($imgString)) { $imgArr = json_decode($imgString, true); $smallImgList = []; $bigImgList = []; if (!empty($imgArr)) { foreach ($imgArr as $image) { $smallImg = imgUtil::groupImg($image) . "?x-oss-process=image/resize,m_fill,h_130,w_130"; $bigImg = imgUtil::groupImg($image) . "?x-oss-process=image/resize,m_fill,h_700,w_700"; $smallImgList[] = $smallImg; $bigImgList[] = $bigImg; } } $refund['imgList'] = $imgArr; $refund['smallImgList'] = $smallImgList; $refund['bigImgList'] = $bigImgList; } $orderSn = $refund['orderSn'] ?? ''; $itemList = RefundOrderItemClass::getOrderItemDetail($orderSn); $staff = $this->shopAdmin; $staffId = $this->shopAdminId; $notify = NotifyClass::getByCondition(['staffId' => $staffId, 'type' => 0, 'targetId' => $id], true); if (!empty($notify)) { if ($notify->read == 0) { $notify->read = 1; $notify->save(); $notifyNum = $staff->notifyNum; if ($notifyNum > 0) { $notifyNum--; $staff->notifyNum = $notifyNum; $staff->save(); } } } 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('超管才能操作退款'); } //国恋只有指定人有退款权限 if ($this->mainId == 7704) { if (in_array($this->shopAdminId, [133727, 133545]) == false) { util::fail('无法操作'); } } $post = Yii::$app->request->post(); $id = isset($post['id']) ? $post['id'] : 0; $refundType = $post['refundType'] ?? 1; //避免网络延迟,暂时重复申请 $cacheKey = 'ghs_order_refund_' . $id; $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]); if (!empty($has)) { util::fail('请10秒之后再提交'); } Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 10, 'has']); $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); try { if ($refundType == RefundOrderClass::REFUND_TYPE_MONEY_GOOD) { //花材列表结构 // [{productId:0,num:1,unitType:0,unitPrice:12,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"); } $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); $refundId = $respond->id; $refundInfo = RefundOrderClass::getById($refundId, true); RefundOrderService::passRefund($refundInfo); $transaction->commit(); util::success($respond); } catch (\Exception $exception) { $transaction->rollBack(); Yii::info("退款出错了,报错信息:" . $exception->getMessage()); util::fail('操作失败'); } } }