request->get('orderId', 0); $order = PurchaseOrderClass::getById($orderId, true); if (empty($order) || intval($order->mainId) !== intval($this->mainId)) { util::fail('没有找到采购单'); } $check = CgPurchaseNextDayClass::checkEligible($order); $check['hasEntryTime'] = CgPurchaseNextDayClass::hasValidEntryTime($order) ? 1 : 0; $check['hasNextDay'] = bccomp((string)($order->nextDayTkPrice ?? '0'), '0', 2) > 0 ? 1 : 0; $check['nextDayTkPrice'] = $order->nextDayTkPrice ?? '0.00'; $check['tkPrice'] = $order->tkPrice ?? '0.00'; $check['actPrice'] = $order->actPrice ?? '0.00'; $check['couldRefundPrice'] = CgPurchaseNextDayClass::mustUseNextDay($order) ? CgPurchaseNextDayClass::getCouldRefundPrice($order) : bcadd((string)($order->realPrice ?? '0'), '0', 2); $check['payWay'] = $order->payWay ?? 0; $check['debt'] = intval($order->debt ?? 0); $check['clearId'] = intval($order->clearId ?? 0); $check['entryTime'] = $order->entryTime ?? ''; util::success($check); } //详情 ssh 20220910 public function actionGetRefundFullInfo() { $get = Yii::$app->request->get(); $id = $get['id'] ?? 0; $refund = CgRefundClass::getById($id, true); CgRefundClass::valid($refund, $this->mainId); $refundSn = $refund->refundSn ?? ''; $itemList = CgRefundItemClass::getAllByCondition(['refundSn' => $refundSn], null, '*'); if (!empty($itemList)) { foreach ($itemList as $key => $item) { $shortCover = $item['cover'] ?? ''; $itemList[$key]['cover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_130,w_130"; } } util::success(['info' => $refund, 'itemList' => $itemList]); } //记录,有重复方法,需要同步修改cg_refund_list ssh 20240817 public function actionGetRefundList() { $get = Yii::$app->request->get(); $where = []; $where['mainId'] = $this->mainId; $relateOrderSn = $get['relateOrderSn'] ?? ''; if (!empty($relateOrderSn)) { $where['relateOrderSn'] = $relateOrderSn; } $list = CgRefundClass::getRefundList($where); util::success($list); } //记录,有重复方法,需要同步修改cg_refund_list ssh 20240817 public function actionList() { $get = Yii::$app->request->get(); $where = []; $where['mainId'] = $this->mainId; $relateOrderSn = $get['relateOrderSn'] ?? ''; if (!empty($relateOrderSn)) { $where['relateOrderSn'] = $relateOrderSn; } $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']]]; } $ghsId = $get['ghsId'] ?? ''; if (!empty($ghsId)) { $where['ghsId'] = $ghsId; } $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 = CgRefundClass::getRefundList($where); if ($export == 1) { CgRefundClass::exportRefundData($respond, $this->mainId); } util::success($respond); } //退款 ssh 20220909;支持隔天售后(sameDay=0,不减 actPrice) public function actionCreateOrder() { $shopAdmin = $this->shopAdmin; if (!isset($shopAdmin['super']) || $shopAdmin['super'] != 1) { util::fail('超管才能操作退款'); } $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); try { $post = Yii::$app->request->post(); $id = $post['id'] ?? 0; $order = PurchaseOrderClass::getLockById($id); if ($order->mainId != $this->mainId) { util::fail('没有权限'); } // 资格、当天/隔天金额上限在 CgRefundService::addRefund 内校验 CgPurchaseNextDayClass::assertCanRefund($order); if (getenv('YII_ENV') == 'production') { if ($this->mainId == 23390) { //小向花卉售后必须备注 $remark = $post['remark'] ?? ''; if (empty($remark)) { util::fail('请填写备注哈'); } } } //退款类型 1退货并退款 2 仅退款 $refundType = $post['refundType'] ?? 1; if ($refundType == CgRefundClass::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('请选择花材2'); } $productList = json_decode($productJson, true); if (!is_array($productList)) { util::fail('请选择花材哦9'); } $post['product'] = $productList; } else { //仅退款花材直接设置为空 $post['product'] = []; } $post['price'] = $post['price'] ?? 0; if ($post['price'] <= 0) { util::fail("退款金额不能小于0"); } $post['shopId'] = $this->shopId; $post['shop'] = $this->shop; $post['sjId'] = $this->sjId; $post['shopAdminId'] = $this->shopAdminId; $post['mainId'] = $this->mainId; $shopAdmin = $this->shopAdmin; $adminName = $shopAdmin['name'] ?? ''; $post['shopAdminName'] = $adminName; $refund = CgRefundService::addRefund($order, $post); $transaction->commit(); util::success([ 'id' => intval($refund->id ?? 0), 'refundSn' => $refund->refundSn ?? '', 'sameDay' => intval($refund->sameDay ?? 1), 'hasReturn' => intval($refund->hasReturn ?? 0), 'couldReturn' => intval($refund->couldReturn ?? 0), 'returnBalance' => intval($refund->returnBalance ?? 0), 'refundPrice' => $refund->refundPrice ?? 0, ]); } catch (\Exception $exception) { if ($transaction->isActive) { $transaction->rollBack(); } Yii::info("退款申请出错了,报错信息:" . $exception->getMessage()); // 透出业务失败原因,便于隔天售后排错 util::fail($exception->getMessage() ?: '操作失败'); } } }