request->get(); $id = $get['id'] ?? ''; $order = OrderClass::getById($id, true); if (empty($order)) { util::fail('没有找到订单'); } if ($order->mainId != $this->mainId) { util::fail('不是你的订单'); } $addTime = $order->addTime; $addTime = strtotime($addTime); $earTime = strtotime('2025-05-01 00:00:00'); if ($addTime < $earTime) { util::fail('2025.5.1号前的订单,不能退款'); } $shop = $this->shop; $purchaseId = $order->purchaseId ?? 0; $cg = PurchaseClass::getById($purchaseId, true); if (empty($cg)) { util::fail('没有找到订单'); } $staff = $this->shopAdmin; if ($staff->mobile != '15280215347') { util::fail('请联系管理员操作'); } $respond = CgRefundClass::onlyRefundMoney($shop, $cg); $status = $respond['status']; $msg = $respond['msg']; util::success(['status' => $status], $msg); } //修改金额 ssh 20240412 public function actionModifyAmount() { $get = Yii::$app->request->get(); $id = $get['id'] ?? 0; $amount = $get['amount'] ?? 0; $refund = RefundOrderClass::getById($id, true); RefundOrderClass::valid($refund, $this->mainId); if (is_numeric($amount) == false) { util::fail('请填写金额'); } if ($refund->status != 0) { util::fail('待审核订单才能修改'); } $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); try { $refund->refundPrice = $amount; $refund->save(); $cgRefundId = $refund->cgRefundId ?? 0; $cgRefund = CgRefundClass::getById($cgRefundId, true); if (empty($cgRefund)) { util::fail('没有找到退款信息'); } $cgRefund->refundPrice = $amount; $cgRefund->save(); $transaction->commit(); util::complete(); } catch (\Exception $e) { $transaction->rollBack(); Yii::info("操作失败原因:" . $e->getMessage()); util::fail('操作失败'); } } //修改申请原因 ssh 20240302 public function actionModifyCause() { $staff = $this->shopAdmin; if (isset($staff->finance) == false || $staff->finance == 0) { util::fail('请有财务权限的人修改'); } $get = Yii::$app->request->get(); $id = $get['id'] ?? 0; $cause = $get['cause'] ?? 0; $refund = RefundOrderClass::getById($id, true); RefundOrderClass::valid($refund, $this->mainId); $refund->cause = $cause; $refund->save(); $orderSn = $refund->orderSn ?? ''; RefundOrderItemClass::updateByCondition(['orderSn' => $orderSn], ['cause' => $cause]); $cgRefundId = $refund->cgRefundId ?? 0; $cgRefund = CgRefundClass::getById($cgRefundId, true); if (empty($cgRefund)) { util::fail('没有找到退款信息'); } $cgRefund->cause = $cause; $cgRefund->save(); $cgOrderSn = $cgRefund->orderSn ?? ''; CgRefundItemClass::updateByCondition(['orderSn' => $cgOrderSn], ['cause' => $cause]); util::complete('修改成功'); } //审核通过 ssh 20230811 public function actionPass() { $shopAdmin = $this->shopAdmin; if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) { util::fail('无法操作'); } //多处要同步修改ghs_refund ssh 20250331 if (getenv('YII_ENV') == 'production') { //小向花卉售后权限 if ($this->mainId == 23390) { if (!in_array($this->adminId, [23960,77951,4])) { util::fail('你不能售后哦'); } //小向花卉售后必须备注 $remark = $post['remark'] ?? ''; if (empty($remark)) { util::fail('请填写备注007'); } } //国恋只有指定人有退款权限 if ($this->mainId == 7704) { if (in_array($this->shopAdminId, [133727, 133545]) == false) { util::fail('无法操作。。'); } } //小齐出车指定人可以售后 if ($this->mainId == 42680) { if (!in_array($this->adminId, [40144])) { util::fail('你不能售后哦。。'); } } } $get = Yii::$app->request->get(); $id = $get['id'] ?? 0; $version = $get['version'] ?? 0; $confirm = $get['confirm'] ?? 0; $refund = RefundOrderClass::getById($id, true); RefundOrderClass::valid($refund, $this->mainId); $relateOrderSn = $refund->relateOrderSn ?? ''; if (empty($relateOrderSn)) { util::fail('没有订单信息'); } $refundList = RefundOrderClass::getAllByCondition(['relateOrderSn' => $relateOrderSn], null, '*', null, true); $has = false; if (!empty($refundList)) { foreach ($refundList as $single) { if ($single->status == 1) { $has = true; } } } if ($has == true) { if ($version == 0) { util::fail('请先升级系统'); } if ($confirm == 0) { util::success(['error' => 'notFirstApply']); } } $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); try { RefundOrderService::passRefund($refund); $transaction->commit(); $staff = $this->shopAdmin; $staffId = $staff->id; $staffName = $staff->name ?? ''; $refund->shopAdminId = $staffId; $refund->shopAdminName = $staffName; $refund->save(); //审核结果通知 $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('无法操作'); } //多处要同步修改ghs_refund ssh 20250331 if (getenv('YII_ENV') == 'production') { //小向花卉售后权限 if ($this->mainId == 23390) { if (!in_array($this->adminId, [23960,77951,4])) { util::fail('你不能售后哦。。'); } //小向花卉售后必须备注 $remark = $post['remark'] ?? ''; if (empty($remark)) { util::fail('请填写备注007'); } } //国恋只有指定人有退款权限 if ($this->mainId == 7704) { if (in_array($this->shopAdminId, [133727, 133545]) == false) { util::fail('无法操作。。'); } } //小齐出车指定人可以售后 if ($this->mainId == 42680) { if (!in_array($this->adminId, [40144])) { 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(); $staff = $this->shopAdmin; $staffId = $staff->id; $staffName = $staff->name ?? ''; $refund->shopAdminId = $staffId; $refund->shopAdminName = $staffName; $refund->save(); //审核结果通知 $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 20250912 public function actionReduceStock() { $shopAdmin = $this->shopAdmin; if (!isset($shopAdmin->super) || $shopAdmin->super != 1) { util::fail('管理员才能报损'); } $post = Yii::$app->request->post(); $refundItemId = $post['refundItemId'] ?? 0; $refundItem = RefundOrderItemClass::getById($refundItemId, true); if (empty($refundItem)) { util::fail('没有找到退货信息'); } if ($refundItem->mainId != $this->mainId) { util::fail('不是您的退款信息'); } $reduceProductId = $refundItem->productId ?? 0; $reduceNum = $post['reduceNum'] ?? 0; $productInfo = ProductClass::getById($reduceProductId, true); if (empty($productInfo)) { util::fail('没有找到花材'); } if ($productInfo->mainId != $this->mainId) { util::fail('不是你的花材'); } $unitType = $refundItem->xhUnitType ?? 0; if ($unitType == 1) { util::fail('小单位,无法减库存'); } $refundNum = $refundItem->xhNum ?? 0; $hasReduceNum = $refundItem->xhReduceNum ?? 0; $remainNum = bcsub($refundNum, $hasReduceNum); if ($reduceNum > $remainNum) { util::fail('剩余可减数量 ' . $remainNum); } $stock = $productInfo->stock ?? 0; if ($reduceNum > $stock) { util::fail('库存不足了'); } $orderSn = $refundItem->orderSn ?? ''; $bigNum = bcsub($stock, $reduceNum); $refundItem->xhReduceNum = bcadd($refundItem->xhReduceNum, $reduceNum); $refundItem->save(); $shop = $this->shop; $sjId = $shop->sjId ?? 0; $shopId = $shop->id ?? 0; $mainId = $shop->mainId ?? 0; $adminId = $this->adminId; $staff = $this->shopAdmin; $staffName = $staff->name ?? ''; $params = [ 'pdType' => '', 'itemInfo' => [['productId' => $reduceProductId, 'bigNum' => $bigNum, 'smallNum' => '']], 'remark' => '售后' . $orderSn . '直接减少库存', 'sjId' => $sjId, 'shopId' => $shopId, 'adminId' => $adminId, 'mainId' => $mainId, 'staffName' => $staffName, ]; CheckOrderClass::opOrder($params); util::complete('操作成功'); } //退款之后报损 ssh 20230409 public function actionRefundWaste() { $shopAdmin = $this->shopAdmin; if (!isset($shopAdmin->super) || $shopAdmin->super != 1) { util::fail('管理员才能报损'); } $post = Yii::$app->request->post(); $refundItemId = $post['refundItemId'] ?? 0; $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('小单位,无法报损'); } $wasteProductId = $refundItem->productId ?? 0; $wasteNum = $post['wasteNum'] ?? 0; unset($post['refundItemId']); unset($post['wasteNum']); unset($post['wasteProductId']); $productInfo = ProductClass::getById($wasteProductId, true); if (empty($productInfo)) { util::fail('没有找到花材'); } $ptItemId = $productInfo->itemId ?? 0; $ratio = $productInfo->ratio ?? 20; $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; $adminName = $shopAdmin['name'] ?? ''; $post['shopAdminName'] = $adminName; //属于售后报损 $post['saleType'] = 1; $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; } $searchTime = $get['searchTime'] ?? ''; if (!empty($searchTime)) { $startTime = $get['startTime'] ?? ''; $endTime = $get['endTime'] ?? ''; $period = dateUtil::formatTime($searchTime, $startTime, $endTime); $where['orderTime'] = ['between', [$period['startTime'], $period['endTime']]]; } $refundSearchTime = $get['refundSearchTime'] ?? ''; if (!empty($refundSearchTime)) { $startTime = $get['refundStartTime'] ?? ''; $endTime = $get['refundEndTime'] ?? ''; $period = dateUtil::formatTime($refundSearchTime, $startTime, $endTime); $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]]; } $customId = $get['customId'] ?? ''; if (!empty($customId)) { $where['customId'] = $customId; } $shopAdminId = $get['shopAdminId'] ?? 0; if (!empty($shopAdminId)) { $where['shopAdminId'] = $shopAdminId; } $status = $get['status'] ?? -1; if ($status > -1) { $where['status'] = $status; } $export = $get['export'] ?? 0; if ($export == 1) { if (isset($where['orderTime']) == false && isset($where['addTime']) == false) { util::fail('请选时间'); } ini_set('memory_limit', '2045M'); set_time_limit(0); if (isset($where['orderTime'])) { $start = $where['orderTime'][1][0]; $end = $where['orderTime'][1][1]; $monthTime = bcmul(31, 86400); $startArea = strtotime($start); $endArea = strtotime($end); $diff = bcsub($endArea, $startArea); if ($diff > $monthTime) { util::fail('最长可导出一个月'); } } if (isset($where['addTime'])) { $start = $where['addTime'][1][0]; $end = $where['addTime'][1][1]; $monthTime = bcmul(31, 86400); $startArea = strtotime($start); $endArea = strtotime($end); $diff = bcsub($endArea, $startArea); if ($diff > $monthTime) { util::fail('最长可导出一个月'); } } } $respond = RefundOrderClass::getOrderList($where); if ($export == 1) { RefundOrderClass::exportRefundData($respond, $this->mainId); } util::success($respond); } //主要根据花材找退款记录 ssh 20240229 public function actionGetListByItem() { $get = Yii::$app->request->get(); $where = []; $where['mainId'] = $this->mainId; $status = $get['status'] ?? -1; $cause = $get['cause'] ?? -1; if ($status > -1) { $where['status'] = $status; } $string = $get['ids']; $ids = json_decode($string, true); if (!empty($ids)) { $productIds = []; $itemList = ProductClass::getAllByCondition(['mainId' => $this->mainId, 'classId' => ['in', $ids]], null, 'id', 'id'); if (!empty($itemList)) { $productIds = array_keys($itemList); } if (empty($productIds)) { util::success(['list' => [], 'moreData' => 0, 'totalAmount' => 0, 'totalNum' => 0, 'totalPage' => 1]); } $where['productId'] = ['in', $productIds]; } if ($cause > -1) { $where['cause'] = $cause; } $searchTime = isset($get['searchTime']) && !empty($get['searchTime']) ? $get['searchTime'] : 'today'; $startTime = $get['startTime'] ?? ''; $endTime = $get['endTime'] ?? ''; $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true); $start = $period['startTime']; $end = $period['endTime']; $currentStartDate = date('Y-m-d', strtotime($start)); $currentEndDate = date('Y-m-d', strtotime($end)); $currentStartTime = $currentStartDate . ' 00:00:00'; $currentEndTime = $currentEndDate . ' 23:59:59'; $where['addTime'] = ['between', [$currentStartTime, $currentEndTime]]; $list = RefundOrderItemClass::getRefundItemList($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(); } } } $itemRefundOption = dict::getDict('itemRefundOption'); util::success(['info' => $refund, 'itemList' => $itemList, 'itemRefundOption' => $itemRefundOption]); } //退款 lqh 2021.6.25 public function actionCreateOrder() { $post = Yii::$app->request->post(); $shopAdmin = $this->shopAdmin; if (isset($shopAdmin['super']) == false || $shopAdmin['super'] != 1) { util::fail('超管才能操作退款'); } //多处要同步修改ghs_refund ssh 20250331 if (getenv('YII_ENV') == 'production') { //小向花卉售后权限 if ($this->mainId == 23390) { if (!in_array($this->adminId, [23960,77951,4])) { util::fail('你不能售后哈。。'); } //小向花卉售后必须备注 $remark = $post['remark'] ?? ''; if (empty($remark)) { util::fail('请填写备注007'); } } //国恋只有指定人有退款权限 if ($this->mainId == 7704) { if (in_array($this->shopAdminId, [133727, 133545]) == false) { util::fail('无法操作。。'); } } //小齐出车指定人可以售后 if ($this->mainId == 42680) { if (!in_array($this->adminId, [40144])) { util::fail('你不能售后哦。。'); } } } $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('请5秒之后再提交'); } Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 5, 'has']); try { $respond = util::runWithDbConcurrencyRetry(function () use ($post, $id, $refundType) { $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(); return $respond; } catch (\Exception $exception) { if ($transaction->isActive) { $transaction->rollBack(); } throw $exception; } }); util::success($respond); } catch (\Exception $exception) { Yii::info("退款出错了,报错信息:" . $exception->getMessage()); if (util::isDbConcurrencyException($exception)) { util::fail('系统繁忙中,请稍后再试'); } else { util::fail('操作失败'); } } } //修改售后原因 ssh 20250623 public function actionChangeRefundOption() { $post = Yii::$app->request->post(); $id = $post['id'] ?? 0; $sonId = $post['sonId'] ?? 0; $optionId = $post['optionId'] ?? 0; $refund = RefundOrderClass::getById($id, true); if (empty($refund)) { util::fail('没有找到退款信息'); } if ($refund->mainId != $this->mainId) { util::fail('没有权限'); } $orderSn = $refund->orderSn; $son = RefundOrderItemClass::getById($sonId, true); if (empty($son)) { util::fail('没有找到花材信息'); } if ($son->orderSn != $orderSn) { util::fail('退款信息有问题'); } $map = dict::getDict('itemRefundOption'); $info = $map[$optionId] ?? []; $name = $info['name'] ?? '未选'; $son->refundOptionId = $optionId; $son->refundOptionName = $name; $son->save(); util::complete('修改成功'); } }