|
|
@@ -16,12 +16,10 @@ use biz\stock\classes\GoodsStockRecordClass;
|
|
|
use biz\wx\classes\WxMessageClass;
|
|
|
use bizGhs\order\classes\CheckOrderClass;
|
|
|
use bizGhs\product\classes\ProductClass;
|
|
|
-use bizGhs\stat\classes\StatYjClass;
|
|
|
use bizGhs\stock\classes\StockRecordClass;
|
|
|
-use bizGhs\ws\services\WsService;
|
|
|
use bizHd\custom\classes\CustomClass;
|
|
|
+use bizHd\item\classes\ItemClass;
|
|
|
use bizHd\merchant\classes\SjClass;
|
|
|
-use bizHd\order\classes\OrderItemClass;
|
|
|
use bizHd\refund\classes\HdRefundClass;
|
|
|
use bizHd\shop\classes\MainClass;
|
|
|
use bizHd\shop\classes\ShopMoneyChangeClass;
|
|
|
@@ -1078,4 +1076,130 @@ class OrderClass extends BaseClass
|
|
|
return $content;
|
|
|
}
|
|
|
|
|
|
-}
|
|
|
+ //扫码收款的,减少库存 ssh 20250822
|
|
|
+ public static function reduceMyStock($data, $shop, $custom)
|
|
|
+ {
|
|
|
+ $mainId = $shop->mainId;
|
|
|
+ $customId = $custom->id;
|
|
|
+ $orderId = $data['orderId'] ?? '';
|
|
|
+ $sjId = $shop->sjId;
|
|
|
+ $hdId = $custom->hdId;
|
|
|
+ $shopId = $shop->id;
|
|
|
+ $order = self::getById($orderId, true);
|
|
|
+ if (empty($order)) {
|
|
|
+ util::fail('没有找到订单');
|
|
|
+ }
|
|
|
+ if ($order->mainId != $shop->mainId) {
|
|
|
+ util::fail('并不是你的订单');
|
|
|
+ }
|
|
|
+ if ($order->repeat == 0) {
|
|
|
+ util::fail('已经扣过了');
|
|
|
+ }
|
|
|
+ if ($order->tkPrice > 0) {
|
|
|
+ util::fail('已经发生退款,无法操作');
|
|
|
+ }
|
|
|
+ $orderSn = $order->orderSn ?? '';
|
|
|
+ $product = $data['product'] ?? [];
|
|
|
+ if (empty($product)) {
|
|
|
+ util::fail('请选择商品呢');
|
|
|
+ }
|
|
|
+ $orderItemList = OrderItemClass::getAllbyCondition(['orderSn' => $orderSn], null, '*', null, true);
|
|
|
+ if (!empty($orderItemList)) {
|
|
|
+ foreach ($orderItemList as $orderItem) {
|
|
|
+ $orderItem->unitPrice = 0;
|
|
|
+ $orderItem->save();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $actPrice = $order->actPrice ?? 0;
|
|
|
+ if ($actPrice <= 0) {
|
|
|
+ util::fail('订单金额为0');
|
|
|
+ }
|
|
|
+
|
|
|
+ $ids = array_column($product, 'productId');
|
|
|
+ $productInfo = ItemClass::getByIds($ids, null, 'id');
|
|
|
+ $goodsPrice = 0;
|
|
|
+ foreach ($product as $key => $val) {
|
|
|
+ $property = $val['property'] ?? 0;
|
|
|
+ if ($property != 1) {
|
|
|
+ util::fail('暂时只支持花材');
|
|
|
+ }
|
|
|
+ $unitPrice = $val['unitPrice'] ?? 0;
|
|
|
+ $unitType = $val['unitType'] ?? 0;
|
|
|
+ $currentId = $val['productId'] ?? 0;
|
|
|
+ $num = $val['num'] ?? 0;
|
|
|
+ $currentInfo = $productInfo[$currentId] ?? [];
|
|
|
+ if (empty($currentInfo)) {
|
|
|
+ util::fail('存在无效花材,编号:' . $currentId);
|
|
|
+ }
|
|
|
+
|
|
|
+ $name = $currentInfo['name'] ?? '';
|
|
|
+ $cover = $currentInfo['cover'] ?? '';
|
|
|
+ $ratio = $currentInfo['ratio'] ?? 20;
|
|
|
+ $itemMainId = $currentInfo['mainId'] ?? 0;
|
|
|
+ if ($itemMainId != $mainId) {
|
|
|
+ util::fail('不是您的花材,请勿使用,编号:' . $mainId . ' ' . $itemMainId);
|
|
|
+ }
|
|
|
+ if ($unitType == 0) {
|
|
|
+ $unitName = $currentInfo['bigUnit'] ?? '';
|
|
|
+ $unitId = $currentInfo['bigUnitId'] ?? 0;
|
|
|
+ $totalNum = $num;
|
|
|
+ } else {
|
|
|
+ $unitName = $currentInfo['smallUnit'] ?? '';
|
|
|
+ $unitId = $currentInfo['smallUnitId'] ?? 0;
|
|
|
+ $totalNum = bcdiv($num, $ratio, 2);
|
|
|
+ }
|
|
|
+ $ptItemId = $currentInfo['itemId'] ?? 0;
|
|
|
+ $classId = $currentInfo['classId'] ?? 0;
|
|
|
+ $belongCost = $currentInfo['belongCost'] ?? 0;
|
|
|
+ $currentPrice = bcmul($unitPrice, $num, 2);
|
|
|
+ $goodsPrice = bcadd($goodsPrice, $currentPrice, 2);
|
|
|
+ $currentItemData = [
|
|
|
+ 'name' => $name,
|
|
|
+ 'cover' => $cover,
|
|
|
+ 'ratio' => $ratio,
|
|
|
+ 'unitType' => $unitType,
|
|
|
+ 'unitName' => $unitName,
|
|
|
+ 'unitId' => $unitId,
|
|
|
+ 'unitPrice' => $unitPrice,
|
|
|
+ 'num' => $num,
|
|
|
+ 'orderSn' => $orderSn,
|
|
|
+ 'itemId' => $currentId,
|
|
|
+ 'ptItemId' => $ptItemId,
|
|
|
+ 'totalNum' => $totalNum,
|
|
|
+ 'totalPrice' => 0,
|
|
|
+ 'customId' => $customId,
|
|
|
+ 'hdId' => $hdId,
|
|
|
+ 'sjId' => $sjId,
|
|
|
+ 'shopId' => $shopId,
|
|
|
+ 'mainId' => $mainId,
|
|
|
+ 'classId' => $classId,
|
|
|
+ 'price' => $currentPrice,
|
|
|
+ 'belongCost' => $belongCost,
|
|
|
+ ];
|
|
|
+ //库存变化在这里
|
|
|
+ OrderItemClass::addData($currentItemData, $custom);
|
|
|
+ }
|
|
|
+ $labourCost = 0;
|
|
|
+ $discountType = 0;
|
|
|
+ $discountAmount = 0;
|
|
|
+ if ($goodsPrice > $actPrice) {
|
|
|
+ $prePrice = $goodsPrice;
|
|
|
+ $discountAmount = bcsub($goodsPrice, $actPrice, 2);
|
|
|
+ if ($discountAmount > 0) {
|
|
|
+ $discountType = 3;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $prePrice = $actPrice;
|
|
|
+ $labourCost = bcsub($actPrice, $goodsPrice, 2);
|
|
|
+ }
|
|
|
+ $order->goodsPrice = $goodsPrice;
|
|
|
+ $order->prePrice = $prePrice;
|
|
|
+ $order->labourCost = $labourCost;
|
|
|
+ $order->discountAmount = $discountAmount;
|
|
|
+ $order->discountType = $discountType;
|
|
|
+ $order->repeat = 0;
|
|
|
+ $order->save();
|
|
|
+ return $order;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|