|
|
@@ -7,6 +7,7 @@ use biz\common\classes\GhsNotifyClass;
|
|
|
use biz\ghs\classes\GhsClass;
|
|
|
use biz\shop\classes\ShopClass;
|
|
|
use biz\shop\classes\ShopExtClass;
|
|
|
+use bizGhs\custom\classes\AccountMoneyClass;
|
|
|
use bizGhs\custom\classes\CustomClass;
|
|
|
use bizGhs\express\classes\GhsDeliveryOrderClass;
|
|
|
use bizGhs\order\classes\OrderClass;
|
|
|
@@ -976,6 +977,102 @@ class PurchaseController extends BaseController
|
|
|
util::success($info->attributes);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 采购待支付页:客户 xhGhsCustom 净余额支付(并发重试 + 行锁)。
|
|
|
+ */
|
|
|
+ public function actionCustomBalancePay()
|
|
|
+ {
|
|
|
+ $post = Yii::$app->request->post();
|
|
|
+ $orderSn = $post['orderSn'] ?? '';
|
|
|
+ if (empty($orderSn)) {
|
|
|
+ util::fail('订单号无效');
|
|
|
+ }
|
|
|
+
|
|
|
+ $cacheKey = 'hd_custom_balance_pay_' . $orderSn;
|
|
|
+ $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
|
|
|
+ if (!empty($has)) {
|
|
|
+ util::fail('请稍等...');
|
|
|
+ }
|
|
|
+ Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 6, 'has']);
|
|
|
+
|
|
|
+ $info = PurchaseClass::getByCondition(['orderSn' => $orderSn], true);
|
|
|
+ if (empty($info)) {
|
|
|
+ util::fail('没有找到采购单');
|
|
|
+ }
|
|
|
+ PurchaseService::valid($info, $this->shopId);
|
|
|
+
|
|
|
+ $deadline = $info->deadline ?? '';
|
|
|
+ if (!empty($deadline) && time() > strtotime($deadline)) {
|
|
|
+ util::fail('订单已失效了哦');
|
|
|
+ }
|
|
|
+
|
|
|
+ $ghsId = intval($info->ghsId ?? 0);
|
|
|
+ $ghs = GhsClass::getGhsInfo($ghsId);
|
|
|
+
|
|
|
+ try {
|
|
|
+ $result = util::runWithDbConcurrencyRetry(function () use ($orderSn) {
|
|
|
+ $connection = Yii::$app->db;
|
|
|
+ $transaction = $connection->beginTransaction();
|
|
|
+ try {
|
|
|
+ $purchase = PurchaseClass::getByCondition(['orderSn' => $orderSn], true);
|
|
|
+ $respond = PurchaseService::payByGhsCustomBalance($purchase);
|
|
|
+ $transaction->commit();
|
|
|
+ return $respond;
|
|
|
+ } catch (\Exception $exception) {
|
|
|
+ if ($transaction->isActive) {
|
|
|
+ $transaction->rollBack();
|
|
|
+ }
|
|
|
+ throw $exception;
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ $info = $result['purchase'];
|
|
|
+ $order = $result['saleOrder'] ?? null;
|
|
|
+
|
|
|
+ if (!empty($order)) {
|
|
|
+ if (isset($info->book) && $info->book == 0 && !empty($ghs)) {
|
|
|
+ $ghsShopId = $ghs['shopId'] ?? 0;
|
|
|
+ $ext = ShopExtClass::getByCondition(['shopId' => $ghsShopId], true, null, 'id,shopId,orderFlow');
|
|
|
+ if (!empty($ext) && intval($ext->orderFlow ?? 0) === 0) {
|
|
|
+ $cg = PurchaseClass::getByCondition(['orderSn' => $orderSn], true);
|
|
|
+ if (!empty($cg)) {
|
|
|
+ PurchaseClass::confirmTake($cg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $shopId = $order->shopId ?? 0;
|
|
|
+ $shop = ShopClass::getById($shopId, true);
|
|
|
+ if (!empty($shop)) {
|
|
|
+ GhsNotifyClass::newOrderNotify($order->id ?? 0);
|
|
|
+ }
|
|
|
+ if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
|
|
|
+ OrderClass::onlinePrint($order);
|
|
|
+ }
|
|
|
+ GhsDeliveryOrderClass::payAfter($order);
|
|
|
+
|
|
|
+ $customId = $order->customId ?? 0;
|
|
|
+ $custom = CustomClass::getById($customId, true);
|
|
|
+ $date = date('Y-m-d H:i:s');
|
|
|
+ if (!empty($custom)) {
|
|
|
+ $custom->recentExpend = $date;
|
|
|
+ $custom->save();
|
|
|
+ }
|
|
|
+ $orderGhsId = $order->ghsId ?? 0;
|
|
|
+ $orderGhs = GhsClass::getById($orderGhsId, true);
|
|
|
+ if (!empty($orderGhs)) {
|
|
|
+ $orderGhs->recentExpend = $date;
|
|
|
+ $orderGhs->save();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ util::success($info->attributes);
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ Yii::info('客户余额支付失败:' . $e->getMessage());
|
|
|
+ util::fail($e->getMessage() ?: '支付失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
//余额支付 ssh 2021.1.24
|
|
|
public function actionBalancePay()
|
|
|
{
|
|
|
@@ -1008,8 +1105,8 @@ class PurchaseController extends BaseController
|
|
|
$connection = Yii::$app->db;
|
|
|
$transaction = $connection->beginTransaction();
|
|
|
try {
|
|
|
- //余额支付
|
|
|
- purchaseService::balancePay($info);
|
|
|
+ // 余额支付:走 xhGhsCustom,不扣 main.balance
|
|
|
+ $info = PurchaseService::balancePay($info);
|
|
|
$transaction->commit();
|
|
|
} catch (\Exception $e) {
|
|
|
$transaction->rollBack();
|
|
|
@@ -1135,7 +1232,30 @@ class PurchaseController extends BaseController
|
|
|
$shop = $this->shop;
|
|
|
$info['pfShopId'] = $shop->pfShopId ?? 0;
|
|
|
$info['hasDebtPay'] = $hasDebtPay;
|
|
|
- $info['balance'] = $shop->balance ?? 0;
|
|
|
+ // 待支付页展示 xhGhsCustom 净余额(正数=可支付余额),不再使用 main.balance
|
|
|
+ $info['balance'] = 0;
|
|
|
+ $info['customNetBalance'] = '0.00';
|
|
|
+ $info['showBalancePay'] = 0;
|
|
|
+ $info['ghsSalt'] = '';
|
|
|
+ $ghsId = intval($info['ghsId'] ?? 0);
|
|
|
+ if ($ghsId > 0) {
|
|
|
+ $ghsRow = GhsClass::getById($ghsId, true);
|
|
|
+ if (!empty($ghsRow)) {
|
|
|
+ $info['ghsSalt'] = $ghsRow->salt ?? '';
|
|
|
+ $ghsCustomId = intval($ghsRow->customId ?? 0);
|
|
|
+ if ($ghsCustomId > 0) {
|
|
|
+ $ghsCustom = CustomClass::getById($ghsCustomId, true);
|
|
|
+ if (!empty($ghsCustom)) {
|
|
|
+ $net = AccountMoneyClass::getNetBalanceFromRow($ghsCustom);
|
|
|
+ $info['customNetBalance'] = $net;
|
|
|
+ if (bccomp($net, '0', 2) > 0) {
|
|
|
+ $info['balance'] = floatval($net);
|
|
|
+ $info['showBalancePay'] = 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
$getPayType = dict::getDict('getPayType');
|
|
|
$info['getPayType'] = $getPayType;
|
|
|
|