balance; if ($amount > $currentBalance) { util::fail('余额不够扣'); } $custom->balance = bcsub($custom->balance, $amount, 2); $custom->save(); $hd->balance = bcsub($hd->balance, $amount, 2); $hd->save(); if (floatval($hd->balance) != floatval($custom->balance)) { util::fail('余额有问题'); } $remark = $params['remark'] ?? ''; $staffId = $params['staffId'] ?? 0; $staffName = $params['staffName'] ?? ''; $shopId = $shop->id; $mainId = $shop->mainId; $hdId = $hd->id; $hdName = $hd->name; $customId = $custom->id; $customName = $custom->name; $data = [ 'shopId' => $shopId, 'mainId' => $mainId, 'hdId' => $hdId, 'hdName' => $hdName, 'amount' => $amount, 'balance' => $custom->balance, 'customId' => $customId, 'customName' => $customName, 'staffId' => $staffId, 'staffName' => $staffName, 'status' => 1, 'remark' => $remark, ]; $result = self::add($data, true); $relateId = $result->id; $event = '手动减少'; $capitalType = dict::getDict('capitalType', 'deduct', 'id'); $change = [ 'customId' => $customId, 'customName' => $customName, 'hdId' => $hdId, 'hdName' => $hdName, 'relateId' => $relateId, 'onlinePay' => 1, 'capitalType' => $capitalType, 'amount' => $amount, 'balance' => $hd->balance, 'io' => 0, 'side' => 0, 'payWay' => 0, 'event' => $event, 'staffId' => $staffId, 'staffName' => $staffName, 'shopId' => $shopId, 'mainId' => $mainId, 'remark' => $remark, ]; BalanceChangeClass::add($change, true); } }