|
|
@@ -2,8 +2,12 @@
|
|
|
|
|
|
namespace bizHd\custom\classes;
|
|
|
|
|
|
+use bizGhs\shop\classes\TotalDebtChangeClass;
|
|
|
+use bizHd\shop\classes\MainClass;
|
|
|
use bizMall\user\classes\UserClass;
|
|
|
+use common\components\dict;
|
|
|
use common\components\imgUtil;
|
|
|
+use common\components\noticeUtil;
|
|
|
use common\components\stringUtil;
|
|
|
use common\components\util;
|
|
|
use Yii;
|
|
|
@@ -14,6 +18,102 @@ class CustomClass extends BaseClass
|
|
|
|
|
|
public static $baseFile = '\bizHd\custom\models\Custom';
|
|
|
|
|
|
+ //客户采购欠款金额增加 ssh 20220908
|
|
|
+ public static function cgDebtAmountAdd($custom, $order)
|
|
|
+ {
|
|
|
+ $amount = $order->remainDebtPrice ?? 0;
|
|
|
+ $custom->isDebt = 1;
|
|
|
+ $lastDebt = bcadd($custom->debtAmount, $amount, 2);
|
|
|
+ $custom->debtAmount = $lastDebt;
|
|
|
+ $custom->save();
|
|
|
+
|
|
|
+ $relateId = $order->id ?? 0;
|
|
|
+ $customId = $custom->id ?? 0;
|
|
|
+ $orderSn = $order->orderSn ?? '';
|
|
|
+ $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
|
|
|
+ $event = '购买花材,单号:' . $orderSn;
|
|
|
+
|
|
|
+ $change = [
|
|
|
+ 'relateId' => $relateId,
|
|
|
+ 'customId' => $customId,
|
|
|
+ 'ptStyle' => dict::getDict('ptStyle', 'hd'),
|
|
|
+ 'capitalType' => $capitalType,
|
|
|
+ 'amount' => $amount,
|
|
|
+ 'balance' => $lastDebt,
|
|
|
+ 'io' => 1,
|
|
|
+ 'payWay' => $order->payWay,
|
|
|
+ 'event' => $event,
|
|
|
+ 'sjId' => $order->sjId,
|
|
|
+ 'shopId' => $order->id,
|
|
|
+ 'mainId' => $order->mainId,
|
|
|
+ ];
|
|
|
+ CustomDebtRecordClass::addChange($change);
|
|
|
+
|
|
|
+ $mainId = $order->mainId ?? 0;
|
|
|
+ $main = MainClass::getLockById($mainId);
|
|
|
+ if (empty($main)) {
|
|
|
+ util::fail('没有main信息');
|
|
|
+ }
|
|
|
+ $debt = $main->debt ?? 0;
|
|
|
+ $remain = bcadd($debt, $amount, 2);
|
|
|
+ $main->debt = $remain;
|
|
|
+ $main->save();
|
|
|
+
|
|
|
+ $event = $custom->name . ' 购买花材,单号:' . $orderSn;
|
|
|
+ $change['balance'] = $remain;
|
|
|
+ $change['event'] = $event;
|
|
|
+ TotalDebtChangeClass::addChange($change);
|
|
|
+ }
|
|
|
+
|
|
|
+ //客户结账欠款金额减少 ssh 20220908
|
|
|
+ public static function clearDebtAmountReduce($custom, $amount, $clear)
|
|
|
+ {
|
|
|
+ $debtAmount = $custom->debtAmount ?? 0.00;
|
|
|
+ $remain = bcsub($debtAmount, $amount, 2);
|
|
|
+ if ($remain < 0) {
|
|
|
+ noticeUtil::push("零售客户欠款总金额:{$custom->debtAmount} 本次结账金额:{$amount} 客户ID:{$custom->id}", '15280215347');
|
|
|
+ util::fail('收款失败,结账后欠款金额会出现负数');
|
|
|
+ }
|
|
|
+ $custom->isDebt = $remain <= 0 ? 0 : 1;
|
|
|
+ $custom->debtAmount = $remain;
|
|
|
+ $custom->save();
|
|
|
+ $relateId = $clear->id ?? 0;
|
|
|
+ $customId = $custom->id ?? 0;
|
|
|
+ $capitalType = dict::getDict('capitalType', 'hdXsClear', 'id');
|
|
|
+ $orderSn = $clear->orderSn ?? '';
|
|
|
+
|
|
|
+ $change = [
|
|
|
+ 'relateId' => $relateId,
|
|
|
+ 'customId' => $customId,
|
|
|
+ 'ptStyle' => dict::getDict('ptStyle', 'ghs'),
|
|
|
+ 'capitalType' => $capitalType,
|
|
|
+ 'amount' => $amount,
|
|
|
+ 'balance' => $remain,
|
|
|
+ 'io' => 0,
|
|
|
+ 'payWay' => 0,
|
|
|
+ 'event' => "结账,单号:{$orderSn}",
|
|
|
+ 'sjId' => $clear->sjId,
|
|
|
+ 'shopId' => $clear->id,
|
|
|
+ 'mainId' => $clear->mainId,
|
|
|
+ ];
|
|
|
+ CustomDebtRecordClass::addChange($change);
|
|
|
+
|
|
|
+ $mainId = $clear->mainId ?? 0;
|
|
|
+ $main = MainClass::getLockById($mainId);
|
|
|
+ if (empty($main)) {
|
|
|
+ util::fail('没有main信息');
|
|
|
+ }
|
|
|
+ $debt = $main->debt ?? 0;
|
|
|
+ $remain = bcsub($debt, $amount, 2);
|
|
|
+ $main->debt = $remain;
|
|
|
+ $main->save();
|
|
|
+
|
|
|
+ $event = $custom->name . " 结账,单号:{$orderSn}";
|
|
|
+ $change['balance'] = $remain;
|
|
|
+ $change['event'] = $event;
|
|
|
+ TotalDebtChangeClass::addChange($change);
|
|
|
+ }
|
|
|
+
|
|
|
public static function getCustomCacheKey($sjId, $shopId, $userId)
|
|
|
{
|
|
|
return 'hd_custom_key_' . $sjId . '_' . $shopId . '_' . $userId;
|