| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- <?php
- namespace bizHd\deduct\classes;
- use bizHd\balance\classes\BalanceChangeClass;
- use common\components\dict;
- use common\components\util;
- use Yii;
- use bizHd\base\classes\BaseClass;
- class DeductClass extends BaseClass
- {
- public static $baseFile = '\bizHd\deduct\models\Deduct';
- public static function doDeduct($shop, $custom, $hd, $amount, $params)
- {
- $currentBalance = $custom->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);
- }
- }
|