id; $customId = $ghs->customId; $custom = CustomClass::getById($customId, true); if (empty($custom)) { util::fail('没有找到客户'); } $ghsShopId = $ghs->shopId ?? 0; $ghsShop = ShopClass::getById($ghsShopId, true); $ghsShopName = $ghsShop->shopName ?? ''; $ghsShopName = $ghsShopName == '首店' ? '总店' : $ghsShopName; $orderSn = orderSn::getPurchaseClearSn(); $purchaseIds = $data['purchaseIds']; $arr = explode(',', $purchaseIds); if (empty($arr)) { util::fail('请选择采购单'); } //订单太多数据库会报错 if (count($arr) > 100) { util::fail('订单太多,请选月份再结'); } $purchaseList = PurchaseClass::getAllByCondition(['id' => ['in', $arr]], null, '*', null, true); if (empty($purchaseList)) { util::fail('请选择采购单'); } $totalPrice = 0; $currentGhsId = $data['ghsId'] ?? 0; $saleArr = []; foreach ($purchaseList as $purchase) { if ($purchase->debt != PurchaseClass::DEBT_YES) { util::fail('请选择有欠款的采购单'); } if ($purchase->ghsId != $currentGhsId) { util::fail('请选择同个供货商的订单'); } $totalPrice = bcadd($totalPrice, $purchase->remainDebtPrice, 2); $saleId = $purchase->saleId; $saleArr[] = $saleId; } $saleString = implode(',', $saleArr); $data['saleIds'] = $saleString; $data['prePrice'] = $totalPrice; $data['actPrice'] = $totalPrice; $data['realPrice'] = $totalPrice; $data['orderSn'] = $orderSn; //10个小时 $deadTime = time() + 36000; $data['deadline'] = date("Y-m-d H:i:s", $deadTime); $params = [ 'ghsId' => $ghsId, 'ghsName' => $ghs['name'] ?? '', 'ghsMobile' => $ghs['mobile'] ?? '', 'ghsAvatar' => $ghs['avatar'] ?? '', 'ghsAddress' => $ghs['address'] ?? '', 'customId' => $customId, 'customName' => $custom['name'] ?? '', 'customAvatar' => $custom['avatar'] ?? '', 'customMobile' => $custom['mobile'] ?? '', 'customAddress' => $custom['address'] ?? '', 'num' => count($arr), 'ghsShopName' => $ghsShopName, ]; $data = array_merge($data, $params); return self::add($data); } //第三方支付回调 ssh 2021.4.28 public static function thirdPay($payWay, $orderSn, $totalFee, $attach, $transactionId) { $info = self::getByCondition(['orderSn' => $orderSn], true); if (empty($info)) { $msg = "没有找到清算订单 orderSn:{$orderSn} {$attach}"; noticeUtil::push($msg, '15280215347'); Yii::info($msg); util::fail($msg); } if ($info->actPrice != $totalFee) { $msg = "清算订单金额与回调通知金额不一致 orderSn:{$orderSn} {$info->actPrice} {$totalFee} {$attach}"; noticeUtil::push($msg, '15280215347'); Yii::info($msg); util::fail($msg); } //临时解决微信一秒内通知二次问题 $id = $info->id; $info = self::getLockById($id); $info->payWay = $payWay; $info->onlinePay = dict::getDict('onlinePay', 'yes'); $info->thirdNo = $transactionId; $info->save(); self::complete($info, $payWay); } //支付成功后的流程 ssh 2021.4.28 public static function complete($order, $payWay) { if (empty($order)) { util::fail('没有找到订单'); } if (isset($order->status) && $order->status == self::STATUS_EXPIRE) { if ($order->onlinePay == dict::getDict('onlinePay', 'yes')) { $ghsName = $order->ghsName ?? ''; $customName = $order->customName ?? ''; $orderSn = $order->orderSn ?? ''; noticeUtil::push("花店线上付款结账,但结账单是取消状态。供货商:{$ghsName},客户:{$customName},订单编号:{$orderSn}", '15280215347'); $ghsShopId = $order->ghsShopId; $shop = ShopClass::getById($ghsShopId, true); if (!empty($shop)) { //原路退回给客户 ClearClass::refundMoney($shop, $order); } util::stop("SUCCESS"); } } if (isset($order->status) == false || $order->status != self::STATUS_AWAIT_PAY) { util::fail('订单不是待付款状态'); } $order->status = self::STATUS_HAS_PAY; $order->payTime = date("Y-m-d H:i:s"); $order->save(); $clearId = $order->id; $orderSn = $order->orderSn; $purchaseIds = $order->purchaseIds; $arr = explode(',', $purchaseIds); //供货商欠款变更 $ghsId = $order->ghsId; $ghs = GhsClass::getLockById($ghsId); if (empty($ghs)) { util::fail('没有找到供货商信息'); } $customId = $ghs->customId; $custom = CustomClass::getLockById($customId); if (empty($custom)) { util::fail('没有找到客户信息'); } \bizHd\ghs\classes\GhsClass::clearDebtAmountReduce($ghs, $custom, $order->actPrice, $order); $shopId = $ghs->shopId; $shop = ShopClass::getLockById($shopId); if (empty($shop)) { util::fail('没有找到供货商门店'); } $mainId = $shop->mainId ?? 0; $main = MainClass::getLockById($mainId); if (empty($main)) { util::fail('没有main信息11'); } if ($order->onlinePay == dict::getDict('onlinePay', 'yes')) { //供货商门店余额增加 ShopClass::customClearAddBalance($main, $shop, $order); } //供货商的门店应收客户款减少 $currentGathering = bcsub($main->mayGathering, $order->actPrice, 2); $main->mayGathering = $currentGathering; $main->save(); if (empty($arr)) { $msg = "结算订单 orderSn:{$orderSn} 支付成功,回调处理,没有找到采购订单"; util::fail($msg); } $list = PurchaseClass::getAllByCondition(['id' => ['in', $arr]], null, '*', null, true); if (empty($list)) { $msg = "结算订单 orderSn:{$orderSn} 支付成功,回调处理,没有找到采购订单!"; util::fail($msg); } $clearTime = date("Y-m-d H:i:s"); //采购单状态变更 $saleIds = []; foreach ($list as $purchase) { $purchase->debt = PurchaseClass::DEBT_NO; $purchase->payWay = $payWay; $purchase->clearId = $clearId; $purchase->remainDebtPrice = 0; $purchase->clearTime = $clearTime; $purchase->save(); $saleIds[] = $purchase->saleId; } //销售单状态变化 OrderClass::updateByIds($saleIds, ['debt' => OrderClass::DEBT_NO, 'clearId' => $clearId, 'remainDebtPrice' => 0, 'clearTime' => $clearTime]); //客户付供货商款减少 CustomClass::clearDebtAmountReduce($custom, $ghs, $order->actPrice, $order); } }