| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- <?php
- namespace bizHd\order\classes;
- use bizHd\custom\classes\CustomClass;
- use bizHd\shop\classes\MainClass;
- use bizHd\shop\classes\ShopMoneyChangeClass;
- use bizHd\work\classes\WorkClass;
- use common\components\dict;
- use common\components\orderSn;
- use common\components\util;
- use Yii;
- use bizHd\base\classes\BaseClass;
- class SettleClass extends BaseClass
- {
- public static $baseFile = '\bizHd\order\models\Settle';
- //结清尾款 ssh 20220708
- public static function confirmSettle($order, $payWay, $staff)
- {
- $mainId = $order->mainId ?? 0;
- $orderId = $order->id ?? 0;
- $settleId = $order->settleId ?? 0;
- if (!empty($settleId)) {
- util::fail('已经结过了');
- }
- $remainDebtPrice = $order->remainDebtPrice ?? 0;
- if ($remainDebtPrice <= 0) {
- $orderSn = $order->orderSn ?? '';
- util::fail('已经结过了哦(单号 ' . $orderSn . ')');
- }
- $shopId = $order->shopId ?? 0;
- $settleOrderSn = orderSn::getSettleSn();
- $customId = $order->customId ?? 0;
- $customName = $order->customName ?? '';
- $staffId = $staff->id ?? 0;
- $staffName = $staff->name ?? '';
- $settleData = [
- 'prePrice' => $remainDebtPrice,
- 'actPrice' => $remainDebtPrice,
- 'realPrice' => $remainDebtPrice,
- 'payWay' => $payWay,
- 'hdShopId' => $shopId,
- 'shopId' => $shopId,
- 'mainId' => $mainId,
- 'purchaseIds' => $orderId,
- 'saleIds' => $orderId,
- 'num' => 1,
- 'status' => 2,
- 'customId' => $customId,
- 'customName' => $customName,
- 'payTime' => date("Y-m-d H:i:s"),
- 'hdShopAdminId' => $staffId,
- 'hdShopName' => $staffName,
- 'orderSn' => $settleOrderSn,
- ];
- $settleReturn = self::addData($settleData);
- $settleId = $settleReturn->id ?? 0;
- $order->settleId = $settleId;
- $order->debt = 0;
- $order->remainDebtPrice = 0;
- $order->save();
- if ($payWay == dict::getDict('payWay', 'cash')) {
- $mainId = $order->mainId ?? 0;
- $main = MainClass::getLockById($mainId);
- if (empty($main)) {
- util::fail('门店信息错误');
- }
- $moneyBalance = bcadd($main->money, $remainDebtPrice, 2);
- $main->money = $moneyBalance;
- $main->save();
- $moneyEvent = $customName . "现金结尾款" . floatval($remainDebtPrice) . "元(单号 {$settleOrderSn})";
- $moneyRemark = '';
- $capitalType = dict::getDict('capitalType', 'hdXsClear', 'id');
- $change = [
- 'relateId' => $orderId,
- 'amount' => $remainDebtPrice,
- 'balance' => $moneyBalance,
- 'io' => 1,
- 'mainId' => $mainId,
- 'capitalType' => $capitalType,
- 'ptStyle' => dict::getDict('ptStyle', 'hd'),
- 'event' => $moneyEvent,
- 'remark' => $moneyRemark,
- ];
- ShopMoneyChangeClass::addData($change);
- }
- //客户欠款金额减少
- $custom = CustomClass::getLockById($customId);
- CustomClass::clearDebtAmountReduce($custom, $remainDebtPrice, $settleReturn);
- //制作单上的尾款也去掉
- WorkClass::updateByCondition(['orderId' => $orderId], ['orderDebtPrice' => 0]);
- }
- public static function addData($data)
- {
- return self::add($data, true);
- }
- }
|