|
|
@@ -5,6 +5,7 @@ namespace bizGhs\order\classes;
|
|
|
use biz\ghs\classes\GhsClass;
|
|
|
use biz\shop\classes\ShopClass;
|
|
|
use bizGhs\custom\classes\CustomClass;
|
|
|
+use common\components\dict;
|
|
|
use common\components\orderSn;
|
|
|
use common\components\util;
|
|
|
use bizGhs\base\classes\BaseClass;
|
|
|
@@ -19,7 +20,7 @@ class OrderClearClass extends BaseClass
|
|
|
//订单结算 ssh 2021.3.14
|
|
|
public static function clear($post, $idText, $sjId, $shopId)
|
|
|
{
|
|
|
- $customId = $post['customId'];
|
|
|
+ $customId = $post['customId'] ?? 0;
|
|
|
$data = json_decode($idText, true);
|
|
|
$ids = array_column($data, 'id');
|
|
|
if (empty($ids)) {
|
|
|
@@ -30,6 +31,9 @@ class OrderClearClass extends BaseClass
|
|
|
util::fail('请选择订单');
|
|
|
}
|
|
|
$amount = 0;
|
|
|
+
|
|
|
+ $modifyPrice = $post['modifyPrice'] ?? 0.00;
|
|
|
+
|
|
|
$purchaseArr = [];
|
|
|
foreach ($list as $key => $val) {
|
|
|
if ($val['sjId'] != $sjId) {
|
|
|
@@ -56,6 +60,13 @@ class OrderClearClass extends BaseClass
|
|
|
if (empty($custom)) {
|
|
|
util::fail('没有找到客户');
|
|
|
}
|
|
|
+
|
|
|
+ $ghsId = $custom->ghsId;
|
|
|
+ $ghs = GhsClass::getLockById($ghsId);
|
|
|
+ if (empty($ghs)) {
|
|
|
+ util::fail('没有找到供应商');
|
|
|
+ }
|
|
|
+
|
|
|
$debtAmount = $custom->debtAmount ?? 0.00;
|
|
|
if ($debtAmount < $amount) {
|
|
|
util::fail('客户欠款金额有问题');
|
|
|
@@ -85,8 +96,13 @@ class OrderClearClass extends BaseClass
|
|
|
$orderSn = orderSn::getPurchaseClearSn();
|
|
|
$clearData = [
|
|
|
'prePrice' => $amount,
|
|
|
- 'actPrice' => $amount,
|
|
|
- 'ghsId' => $custom->ghsId,
|
|
|
+ 'actPrice' => $modifyPrice,
|
|
|
+ 'realPrice' => $modifyPrice,
|
|
|
+ 'ghsId' => $ghsId,
|
|
|
+ 'ghsName' => $ghs['name'] ?? '',
|
|
|
+ 'ghsMobile' => $ghs['mobile'] ?? '',
|
|
|
+ 'ghsAvatar' => $ghs['avatar'] ?? '',
|
|
|
+ 'ghsAddress' => $ghs['address'] ?? '',
|
|
|
'ghsShopAdminId' => $post['ghsShopAdminId'],
|
|
|
'ghsShopAdminName' => $post['ghsShopAdminName'],
|
|
|
'sjId' => $sjId,
|
|
|
@@ -96,9 +112,17 @@ class OrderClearClass extends BaseClass
|
|
|
'status' => 2,
|
|
|
'type' => 2,
|
|
|
'customId' => $customId,
|
|
|
+ 'customName' => $custom['name'] ?? '',
|
|
|
+ 'customAvatar' => $custom['avatar'] ?? '',
|
|
|
+ 'customMobile' => $custom['mobile'] ?? '',
|
|
|
+ 'customAddress' => $custom['address'] ?? '',
|
|
|
'deadline' => date("Y-m-d H:i:s"),
|
|
|
'purchaseIds' => $purchaseString,
|
|
|
];
|
|
|
+ if ($modifyPrice < $amount) {
|
|
|
+ $clearData['discountAmount'] = bcsub($amount, $modifyPrice, 2);
|
|
|
+ $clearData['discountType'] = dict::getDict('discountType', 'discount');
|
|
|
+ }
|
|
|
$return = PurchaseClearClass::add($clearData);
|
|
|
$clearId = $return['id'];
|
|
|
|
|
|
@@ -107,11 +131,6 @@ class OrderClearClass extends BaseClass
|
|
|
// 采购单状态变更
|
|
|
PurchaseClass::updateByIds($purchaseArr, ['debt' => 2, 'clearId' => $clearId]);
|
|
|
|
|
|
- $ghsId = $custom->ghsId;
|
|
|
- $ghs = GhsClass::getLockById($ghsId);
|
|
|
- if (empty($ghs)) {
|
|
|
- util::fail('没有找到供应商');
|
|
|
- }
|
|
|
$remainAmount = bcsub($ghs->debtAmount, $amount, 2);
|
|
|
if ($remainAmount < 0) {
|
|
|
util::fail('客户欠款金额有问题!');
|