|
|
@@ -0,0 +1,56 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace bizHd\deduct\classes;
|
|
|
+
|
|
|
+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,
|
|
|
+ ];
|
|
|
+ self::add($data, true);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|