预订单商品添加门店出货

This commit is contained in:
lewis 2025-01-17 16:55:39 +08:00
parent 39796fd908
commit 82edbfd35a
5 changed files with 52 additions and 4 deletions

View File

@ -176,4 +176,11 @@ class BeforehandOrderCartInfoController extends BaseAdminController
return $this->success('操作成功', [], 1, 1);
}
public function setStoreSale()
{
$params = $this->request->post();
BeforehandOrderCartInfoLogic::setStoreSale($params);
return $this->success('操作成功', [], 1, 1);
}
}

View File

@ -77,7 +77,7 @@ class BeforehandOrderCartInfoLists extends BaseAdminDataLists implements ListsSe
}
}
$list = BeforehandOrderCartInfo::where($this->searchWhere)
->field(['id', 'bhoid', 'package', 'store_info', 'marques', 'gross_weight', 'net_weight', 'accept_num', 'after_sales', 'loss', 'uid', 'pay_price', 'is_buyer', 'buyer_uid', 'product_id', 'attr_value_id', 'purchase', 'price', 'total_price', 'cart_num', 'mark','create_time', 'procurement_order_id'])
->field(['id', 'bhoid', 'package', 'store_info', 'marques', 'gross_weight', 'net_weight', 'accept_num', 'after_sales', 'loss', 'uid', 'pay_price', 'is_buyer', 'buyer_uid', 'product_id', 'attr_value_id', 'purchase', 'price', 'total_price', 'cart_num', 'mark','create_time', 'procurement_order_id', 'store_sale'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()->each(function ($item) use ($system_store, $order_mark) {

View File

@ -2,6 +2,7 @@
namespace app\admin\logic\beforehand_order;
use app\admin\logic\store_branch_product\StoreBranchProductLogic;
use app\admin\logic\store_product\StoreProductLogic;
use app\admin\logic\warehouse_product\WarehouseProductLogic;
use app\api\logic\order\CartLogic;
@ -397,6 +398,7 @@ class BeforehandOrderLogic extends BaseLogic
];
$arr['delivery_time'] = strtotime($delivery_time);
$res = WarehouseOrder::create($arr);
$totalPrice = '0.00';
foreach ($info as $key => $arr) {
if ($user_ship == 0) {
$price = 0;
@ -421,11 +423,16 @@ class BeforehandOrderLogic extends BaseLogic
'code' => $res['code'],
'unit' => $arr['unit'] ?? 0,
];
WarehouseProductLogic::setOutbound($data, 1, $admin_id);
$totalPrice = bcadd($totalPrice, $arr['total_price'], 2);
if ($arr['store_sale'] == 1) {
StoreBranchProductLogic::decStock($store_id, $arr['product_id'], $arr['cart_num']);
} else {
WarehouseProductLogic::setOutbound($data, 1, $admin_id);
}
}
$finds = WarehouseProduct::where('oid', $res['id'])->field('sum(nums) as nums,sum(total_price) as total_price')->find();
WarehouseOrder::where('id', $res['id'])->update(['total_price' => $finds['total_price'], 'nums' => $finds['nums']]);
$order->save(['outbound_id' => $res['id'], 'is_outbound' => 1, 'pay_price' => $finds['total_price']]);
WarehouseOrder::where('id', $res['id'])->update(['total_price' => $totalPrice, 'nums' => $finds['nums']]);
$order->save(['outbound_id' => $res['id'], 'is_outbound' => 1, 'pay_price' => $totalPrice]);
BeforehandOrderCartInfo::where('bhoid', $params['bhoid'])->update(['is_buyer' => -1]);
Db::commit();
return true;

View File

@ -339,4 +339,15 @@ class BeforehandOrderCartInfoLogic extends BaseLogic
(new BeforehandOrderCartInfo())->saveAll($update);
}
public static function setStoreSale($params)
{
$cartInfo = BeforehandOrderCartInfo::where('id', $params['id'])->find();
if ($cartInfo['store_sale'] == 1) {
$update = ['store_sale' => 0];
} else {
$update = ['store_sale' => 1];
}
BeforehandOrderCartInfo::where('id', $params['id'])->update($update);
}
}

View File

@ -120,4 +120,27 @@ class StoreBranchProductLogic extends BaseLogic
{
return StoreBranchProduct::findOrEmpty($params['id'])->toArray();
}
public static function decStock($storeId, $productId, $num)
{
$branchProduct = StoreBranchProduct::where('store_id', $storeId)->where('product_id', $productId)->find();
if ($branchProduct) {
$stock = bcsub($branchProduct['stock'], $num, 2);
StoreBranchProduct::update([
'stock' => $stock,
'total_price' => bcmul($stock, $branchProduct['purchase'], 2),
'sales' => bcadd($branchProduct['sales'], $num, 2)
], ['id' => $branchProduct['id']]);
SqlChannelLog('StoreBranchProduct',$branchProduct['id'], $num, -1, Request()->url());
} else {
$storeProduct = StoreProduct::where('id', $productId)->find();
$branchProduct = StoreProductLogic::ordinary(['id' => $productId], $storeId, 0, $storeProduct);
StoreBranchProduct::update([
'stock' => -$num,
'sales' => $num
], ['product_id' => $productId,'store_id'=>$storeId]);
SqlChannelLog('StoreBranchProduct',$branchProduct['id'], $num, -1, Request()->url());
}
}
}